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 | |
| 8 | COMPATIBLE_MACHINE = "^$" |
| 9 | COMPATIBLE_MACHINE_zynq = ".*" |
| 10 | COMPATIBLE_MACHINE_zynqmp = ".*" |
| 11 | |
| 12 | inherit deploy |
| 13 | |
| 14 | def bootfiles_bitstream(d): |
| 15 | expectedfiles = [("bitstream", True)] |
| 16 | expectedexts = [(".bit", True), (".bin", False)] |
| 17 | # search for bitstream paths, use the renamed file. First matching is used |
| 18 | for f in (d.getVar("IMAGE_BOOT_FILES") or "").split(): |
| 19 | sf, rf = f, f |
| 20 | if ';' in f: |
| 21 | sf, rf = f.split(';') |
| 22 | |
| 23 | # skip boot.bin and u-boot.bin, it is not a bitstream |
| 24 | skip = ["boot.bin", "u-boot.bin"] |
| 25 | if sf in skip or rf in skip: |
| 26 | continue |
| 27 | |
| 28 | for e, t in expectedfiles: |
| 29 | if sf == e or rf == e: |
| 30 | return rf, t |
| 31 | for e, t in expectedexts: |
| 32 | if sf.endswith(e) or rf.endswith(e): |
| 33 | return rf, t |
| 34 | return "", False |
| 35 | |
| 36 | def bootfiles_dtb_filepath(d): |
| 37 | if d.getVar("IMAGE_BOOT_FILES"): |
| 38 | dtbs = d.getVar("IMAGE_BOOT_FILES").split(" ") |
| 39 | # IMAGE_BOOT_FILES has extra renaming info in the format '<source>;<target>' |
| 40 | dtbs = [f.split(";")[0] for f in dtbs] |
| 41 | dtbs = [f for f in dtbs if f.endswith(".dtb")] |
| 42 | if len(dtbs) != 0: |
| 43 | return dtbs[0] |
| 44 | return "" |
| 45 | |
| 46 | def uboot_boot_cmd(d): |
| 47 | if d.getVar("KERNEL_IMAGETYPE") in ["uImage", "fitImage"]: |
| 48 | return "bootm" |
| 49 | if d.getVar("KERNEL_IMAGETYPE") in ["zImage"]: |
| 50 | return "bootz" |
| 51 | if d.getVar("KERNEL_IMAGETYPE") in ["Image"]: |
| 52 | return "booti" |
| 53 | raise bb.parse.SkipRecipe("Unsupport kernel image type") |
| 54 | |
| 55 | def uenv_populate(d): |
| 56 | # populate the environment values |
| 57 | env = {} |
| 58 | |
| 59 | env["machine_name"] = d.getVar("MACHINE") |
| 60 | |
| 61 | env["kernel_image"] = d.getVar("KERNEL_IMAGETYPE") |
| 62 | env["kernel_load_address"] = d.getVar("KERNEL_LOAD_ADDRESS") |
| 63 | |
| 64 | env["devicetree_image"] = bootfiles_dtb_filepath(d) |
| 65 | env["devicetree_load_address"] = d.getVar("DEVICETREE_LOAD_ADDRESS") |
| 66 | |
| 67 | env["bootargs"] = d.getVar("KERNEL_BOOTARGS") |
| 68 | |
| 69 | env["loadkernel"] = "fatload mmc 0 ${kernel_load_address} ${kernel_image}" |
| 70 | env["loaddtb"] = "fatload mmc 0 ${devicetree_load_address} ${devicetree_image}" |
| 71 | env["bootkernel"] = "run loadkernel && run loaddtb && " + uboot_boot_cmd(d) + " ${kernel_load_address} - ${devicetree_load_address}" |
| 72 | |
| 73 | # default uenvcmd does not load bitstream |
| 74 | env["uenvcmd"] = "run bootkernel" |
| 75 | |
| 76 | bitstream, bitstreamtype = bootfiles_bitstream(d) |
| 77 | if bitstream: |
| 78 | env["bitstream_image"] = bitstream |
| 79 | env["bitstream_load_address"] = "0x100000" |
| 80 | |
| 81 | # if bitstream is "bit" format use loadb, otherwise use load |
| 82 | env["bitstream_type"] = "loadb" if bitstreamtype else "load" |
| 83 | |
| 84 | # load bitstream first with loadfpa |
| 85 | env["loadfpga"] = "fatload mmc 0 ${bitstream_load_address} ${bitstream_image} && fpga ${bitstream_type} 0 ${bitstream_load_address} ${filesize}" |
| 86 | env["uenvcmd"] = "run loadfpga && run bootkernel" |
| 87 | |
| 88 | return env |
| 89 | |
| 90 | # bootargs, default to booting with the rootfs device being partition 2 of the first mmc device |
| 91 | KERNEL_BOOTARGS_zynq = "earlyprintk console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait" |
| 92 | KERNEL_BOOTARGS_zynqmp = "earlycon clk_ignore_unused root=/dev/mmcblk0p2 rw rootwait" |
| 93 | |
| 94 | KERNEL_LOAD_ADDRESS_zynq = "0x2080000" |
| 95 | KERNEL_LOAD_ADDRESS_zynqmp = "0x80000" |
| 96 | DEVICETREE_LOAD_ADDRESS_zynq = "0x2000000" |
| 97 | DEVICETREE_LOAD_ADDRESS_zynqmp = "0x4000000" |
| 98 | |
| 99 | python do_compile() { |
| 100 | env = uenv_populate(d) |
| 101 | with open(d.expand("${WORKDIR}/uEnv.txt"), "w") as f: |
| 102 | for k, v in env.items(): |
| 103 | f.write("{0}={1}\n".format(k, v)) |
| 104 | } |
| 105 | |
| 106 | FILES_${PN} += "/boot/uEnv.txt" |
| 107 | |
| 108 | do_install() { |
| 109 | install -Dm 0644 ${WORKDIR}/uEnv.txt ${D}/boot/uEnv.txt |
| 110 | } |
| 111 | |
| 112 | do_deploy() { |
| 113 | install -Dm 0644 ${WORKDIR}/uEnv.txt ${DEPLOYDIR}/uEnv.txt |
| 114 | } |
| 115 | addtask do_deploy after do_compile before do_build |
| 116 | |