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 | |
| 40 | def uenv_populate(d): |
| 41 | # populate the environment values |
| 42 | env = {} |
| 43 | |
| 44 | env["machine_name"] = d.getVar("MACHINE") |
| 45 | |
| 46 | env["kernel_image"] = d.getVar("KERNEL_IMAGETYPE") |
| 47 | env["kernel_load_address"] = d.getVar("KERNEL_LOAD_ADDRESS") |
| 48 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 49 | env["devicetree_image"] = boot_files_dtb_filepath(d) |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 50 | env["devicetree_load_address"] = d.getVar("DEVICETREE_LOAD_ADDRESS") |
| 51 | |
| 52 | env["bootargs"] = d.getVar("KERNEL_BOOTARGS") |
| 53 | |
| 54 | env["loadkernel"] = "fatload mmc 0 ${kernel_load_address} ${kernel_image}" |
| 55 | env["loaddtb"] = "fatload mmc 0 ${devicetree_load_address} ${devicetree_image}" |
| 56 | env["bootkernel"] = "run loadkernel && run loaddtb && " + uboot_boot_cmd(d) + " ${kernel_load_address} - ${devicetree_load_address}" |
| 57 | |
| 58 | # default uenvcmd does not load bitstream |
| 59 | env["uenvcmd"] = "run bootkernel" |
| 60 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 61 | bitstream, bitstreamtype = boot_files_bitstream(d) |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 62 | if bitstream: |
| 63 | env["bitstream_image"] = bitstream |
| 64 | env["bitstream_load_address"] = "0x100000" |
| 65 | |
| 66 | # if bitstream is "bit" format use loadb, otherwise use load |
| 67 | env["bitstream_type"] = "loadb" if bitstreamtype else "load" |
| 68 | |
| 69 | # load bitstream first with loadfpa |
| 70 | env["loadfpga"] = "fatload mmc 0 ${bitstream_load_address} ${bitstream_image} && fpga ${bitstream_type} 0 ${bitstream_load_address} ${filesize}" |
| 71 | env["uenvcmd"] = "run loadfpga && run bootkernel" |
| 72 | |
| 73 | return env |
| 74 | |
| 75 | # bootargs, default to booting with the rootfs device being partition 2 of the first mmc device |
| 76 | KERNEL_BOOTARGS_zynq = "earlyprintk console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait" |
| 77 | KERNEL_BOOTARGS_zynqmp = "earlycon clk_ignore_unused root=/dev/mmcblk0p2 rw rootwait" |
| 78 | |
| 79 | KERNEL_LOAD_ADDRESS_zynq = "0x2080000" |
| 80 | KERNEL_LOAD_ADDRESS_zynqmp = "0x80000" |
| 81 | DEVICETREE_LOAD_ADDRESS_zynq = "0x2000000" |
| 82 | DEVICETREE_LOAD_ADDRESS_zynqmp = "0x4000000" |
| 83 | |
| 84 | python do_compile() { |
| 85 | env = uenv_populate(d) |
| 86 | with open(d.expand("${WORKDIR}/uEnv.txt"), "w") as f: |
| 87 | for k, v in env.items(): |
| 88 | f.write("{0}={1}\n".format(k, v)) |
| 89 | } |
| 90 | |
| 91 | FILES_${PN} += "/boot/uEnv.txt" |
| 92 | |
| 93 | do_install() { |
| 94 | install -Dm 0644 ${WORKDIR}/uEnv.txt ${D}/boot/uEnv.txt |
| 95 | } |
| 96 | |
| 97 | do_deploy() { |
| 98 | install -Dm 0644 ${WORKDIR}/uEnv.txt ${DEPLOYDIR}/uEnv.txt |
| 99 | } |
| 100 | addtask do_deploy after do_compile before do_build |
| 101 | |