Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 1 | SUMMARY = "U-Boot uEnv.txt SD boot environment generation for Zynq targets" |
| 2 | LICENSE = "MIT" |
| 3 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" |
| 4 | |
| 5 | INHIBIT_DEFAULT_DEPS = "1" |
| 6 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 7 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 8 | python () { |
| 9 | # The device trees must be populated in the deploy directory to correctly |
| 10 | # detect them and their names. This means that this recipe needs to depend |
| 11 | # on those deployables just like the image recipe does. |
| 12 | deploydeps = ["virtual/kernel"] |
| 13 | for i in (d.getVar("MACHINE_ESSENTIAL_EXTRA_RDEPENDS") or "").split(): |
| 14 | if i != d.getVar("BPN"): |
| 15 | deploydeps.append(i) |
| 16 | for i in (d.getVar("EXTRA_IMAGEDEPENDS") or "").split(): |
| 17 | if i != d.getVar("BPN"): |
| 18 | deploydeps.append(i) |
| 19 | |
| 20 | # add as DEPENDS since the targets might not have do_deploy tasks |
| 21 | if len(deploydeps) != 0: |
| 22 | d.appendVar("DEPENDS", " " + " ".join(deploydeps)) |
| 23 | } |
| 24 | |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 25 | COMPATIBLE_MACHINE = "^$" |
| 26 | COMPATIBLE_MACHINE_zynq = ".*" |
| 27 | COMPATIBLE_MACHINE_zynqmp = ".*" |
| 28 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | inherit deploy image-wic-utils |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 30 | |
| 31 | def uboot_boot_cmd(d): |
| 32 | if d.getVar("KERNEL_IMAGETYPE") in ["uImage", "fitImage"]: |
| 33 | return "bootm" |
| 34 | if d.getVar("KERNEL_IMAGETYPE") in ["zImage"]: |
| 35 | return "bootz" |
| 36 | if d.getVar("KERNEL_IMAGETYPE") in ["Image"]: |
| 37 | return "booti" |
| 38 | raise bb.parse.SkipRecipe("Unsupport kernel image type") |
| 39 | |
Andrew Geissler | a9ff2b3 | 2020-10-16 10:11:54 -0500 | [diff] [blame] | 40 | def get_sdbootdev(d): |
| 41 | if d.getVar("SOC_FAMILY") in ["zynqmp"]: |
| 42 | return "${sdbootdev}" |
| 43 | else: |
| 44 | return "0" |
| 45 | |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 46 | def uenv_populate(d): |
| 47 | # populate the environment values |
| 48 | env = {} |
| 49 | |
| 50 | env["machine_name"] = d.getVar("MACHINE") |
| 51 | |
| 52 | env["kernel_image"] = d.getVar("KERNEL_IMAGETYPE") |
| 53 | env["kernel_load_address"] = d.getVar("KERNEL_LOAD_ADDRESS") |
| 54 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 55 | env["devicetree_image"] = boot_files_dtb_filepath(d) |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 56 | env["devicetree_load_address"] = d.getVar("DEVICETREE_LOAD_ADDRESS") |
| 57 | |
| 58 | env["bootargs"] = d.getVar("KERNEL_BOOTARGS") |
| 59 | |
Andrew Geissler | a9ff2b3 | 2020-10-16 10:11:54 -0500 | [diff] [blame] | 60 | env["loadkernel"] = "fatload mmc " + get_sdbootdev(d) + " ${kernel_load_address} ${kernel_image}" |
| 61 | env["loaddtb"] = "fatload mmc " + get_sdbootdev(d) + " ${devicetree_load_address} ${devicetree_image}" |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 62 | env["bootkernel"] = "run loadkernel && run loaddtb && " + uboot_boot_cmd(d) + " ${kernel_load_address} - ${devicetree_load_address}" |
| 63 | |
Andrew Geissler | a9ff2b3 | 2020-10-16 10:11:54 -0500 | [diff] [blame] | 64 | if d.getVar("SOC_FAMILY") in ["zynqmp"]: |
| 65 | env["bootkernel"] = "setenv bootargs " + d.getVar("KERNEL_BOOTARGS") + " ; " + env["bootkernel"] |
| 66 | |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 67 | # default uenvcmd does not load bitstream |
| 68 | env["uenvcmd"] = "run bootkernel" |
| 69 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 70 | bitstream, bitstreamtype = boot_files_bitstream(d) |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 71 | if bitstream: |
| 72 | env["bitstream_image"] = bitstream |
| 73 | env["bitstream_load_address"] = "0x100000" |
| 74 | |
| 75 | # if bitstream is "bit" format use loadb, otherwise use load |
| 76 | env["bitstream_type"] = "loadb" if bitstreamtype else "load" |
| 77 | |
| 78 | # load bitstream first with loadfpa |
Andrew Geissler | a9ff2b3 | 2020-10-16 10:11:54 -0500 | [diff] [blame] | 79 | env["loadfpga"] = "fatload mmc " + get_sdbootdev(d) + " ${bitstream_load_address} ${bitstream_image} && fpga ${bitstream_type} 0 ${bitstream_load_address} ${filesize}" |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 80 | env["uenvcmd"] = "run loadfpga && run bootkernel" |
| 81 | |
| 82 | return env |
| 83 | |
Andrew Geissler | a9ff2b3 | 2020-10-16 10:11:54 -0500 | [diff] [blame] | 84 | # bootargs, default to booting with the rootfs device being partition 2 |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 85 | KERNEL_BOOTARGS_zynq = "earlyprintk console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait" |
Andrew Geissler | a9ff2b3 | 2020-10-16 10:11:54 -0500 | [diff] [blame] | 86 | KERNEL_BOOTARGS_zynqmp = "earlycon clk_ignore_unused root=/dev/mmcblk${sdbootdev}p2 rw rootwait" |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 87 | |
| 88 | KERNEL_LOAD_ADDRESS_zynq = "0x2080000" |
| 89 | KERNEL_LOAD_ADDRESS_zynqmp = "0x80000" |
| 90 | DEVICETREE_LOAD_ADDRESS_zynq = "0x2000000" |
| 91 | DEVICETREE_LOAD_ADDRESS_zynqmp = "0x4000000" |
| 92 | |
| 93 | python do_compile() { |
| 94 | env = uenv_populate(d) |
| 95 | with open(d.expand("${WORKDIR}/uEnv.txt"), "w") as f: |
| 96 | for k, v in env.items(): |
| 97 | f.write("{0}={1}\n".format(k, v)) |
| 98 | } |
| 99 | |
| 100 | FILES_${PN} += "/boot/uEnv.txt" |
| 101 | |
| 102 | do_install() { |
| 103 | install -Dm 0644 ${WORKDIR}/uEnv.txt ${D}/boot/uEnv.txt |
| 104 | } |
| 105 | |
| 106 | do_deploy() { |
| 107 | install -Dm 0644 ${WORKDIR}/uEnv.txt ${DEPLOYDIR}/uEnv.txt |
| 108 | } |
| 109 | addtask do_deploy after do_compile before do_build |
| 110 | |