blob: 6e4c3c0b217eef5248defff17b2cf49f2ef2f90b [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
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050040def get_sdbootdev(d):
41 if d.getVar("SOC_FAMILY") in ["zynqmp"]:
42 return "${sdbootdev}"
43 else:
44 return "0"
45
Brad Bishop286d45c2018-10-02 15:21:57 -040046def 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 Bishop1a4b7ee2018-12-16 17:11:34 -080055 env["devicetree_image"] = boot_files_dtb_filepath(d)
Brad Bishop286d45c2018-10-02 15:21:57 -040056 env["devicetree_load_address"] = d.getVar("DEVICETREE_LOAD_ADDRESS")
57
58 env["bootargs"] = d.getVar("KERNEL_BOOTARGS")
59
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050060 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 Bishop286d45c2018-10-02 15:21:57 -040062 env["bootkernel"] = "run loadkernel && run loaddtb && " + uboot_boot_cmd(d) + " ${kernel_load_address} - ${devicetree_load_address}"
63
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050064 if d.getVar("SOC_FAMILY") in ["zynqmp"]:
65 env["bootkernel"] = "setenv bootargs " + d.getVar("KERNEL_BOOTARGS") + " ; " + env["bootkernel"]
66
Brad Bishop286d45c2018-10-02 15:21:57 -040067 # default uenvcmd does not load bitstream
68 env["uenvcmd"] = "run bootkernel"
69
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070 bitstream, bitstreamtype = boot_files_bitstream(d)
Brad Bishop286d45c2018-10-02 15:21:57 -040071 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 Geisslera9ff2b32020-10-16 10:11:54 -050079 env["loadfpga"] = "fatload mmc " + get_sdbootdev(d) + " ${bitstream_load_address} ${bitstream_image} && fpga ${bitstream_type} 0 ${bitstream_load_address} ${filesize}"
Brad Bishop286d45c2018-10-02 15:21:57 -040080 env["uenvcmd"] = "run loadfpga && run bootkernel"
81
82 return env
83
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050084# bootargs, default to booting with the rootfs device being partition 2
Brad Bishop286d45c2018-10-02 15:21:57 -040085KERNEL_BOOTARGS_zynq = "earlyprintk console=ttyPS0,115200 root=/dev/mmcblk0p2 rw rootwait"
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050086KERNEL_BOOTARGS_zynqmp = "earlycon clk_ignore_unused root=/dev/mmcblk${sdbootdev}p2 rw rootwait"
Brad Bishop286d45c2018-10-02 15:21:57 -040087
88KERNEL_LOAD_ADDRESS_zynq = "0x2080000"
89KERNEL_LOAD_ADDRESS_zynqmp = "0x80000"
90DEVICETREE_LOAD_ADDRESS_zynq = "0x2000000"
91DEVICETREE_LOAD_ADDRESS_zynqmp = "0x4000000"
92
93python 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
100FILES_${PN} += "/boot/uEnv.txt"
101
102do_install() {
103 install -Dm 0644 ${WORKDIR}/uEnv.txt ${D}/boot/uEnv.txt
104}
105
106do_deploy() {
107 install -Dm 0644 ${WORKDIR}/uEnv.txt ${DEPLOYDIR}/uEnv.txt
108}
109addtask do_deploy after do_compile before do_build
110