blob: 952077d12a9bcf0ec6156490ba685f160dff6135 [file] [log] [blame]
Brad Bishop286d45c2018-10-02 15:21:57 -04001SUMMARY = "U-Boot uEnv.txt SD boot environment generation for Zynq targets"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
4
5INHIBIT_DEFAULT_DEPS = "1"
6PACKAGE_ARCH = "${MACHINE_ARCH}"
7
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008python () {
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 Bishop286d45c2018-10-02 15:21:57 -040025COMPATIBLE_MACHINE = "^$"
26COMPATIBLE_MACHINE_zynq = ".*"
27COMPATIBLE_MACHINE_zynqmp = ".*"
28
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029inherit deploy image-wic-utils
Brad Bishop286d45c2018-10-02 15:21:57 -040030
31def 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
40def 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 Bishop1a4b7ee2018-12-16 17:11:34 -080049 env["devicetree_image"] = boot_files_dtb_filepath(d)
Brad Bishop286d45c2018-10-02 15:21:57 -040050 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 Bishop1a4b7ee2018-12-16 17:11:34 -080061 bitstream, bitstreamtype = boot_files_bitstream(d)
Brad Bishop286d45c2018-10-02 15:21:57 -040062 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
76KERNEL_BOOTARGS_zynq = "earlyprintk console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait"
77KERNEL_BOOTARGS_zynqmp = "earlycon clk_ignore_unused root=/dev/mmcblk0p2 rw rootwait"
78
79KERNEL_LOAD_ADDRESS_zynq = "0x2080000"
80KERNEL_LOAD_ADDRESS_zynqmp = "0x80000"
81DEVICETREE_LOAD_ADDRESS_zynq = "0x2000000"
82DEVICETREE_LOAD_ADDRESS_zynqmp = "0x4000000"
83
84python 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
91FILES_${PN} += "/boot/uEnv.txt"
92
93do_install() {
94 install -Dm 0644 ${WORKDIR}/uEnv.txt ${D}/boot/uEnv.txt
95}
96
97do_deploy() {
98 install -Dm 0644 ${WORKDIR}/uEnv.txt ${DEPLOYDIR}/uEnv.txt
99}
100addtask do_deploy after do_compile before do_build
101