diff options
Diffstat (limited to 'meta/classes-recipe/kernel-fit-image.bbclass')
-rw-r--r-- | meta/classes-recipe/kernel-fit-image.bbclass | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/meta/classes-recipe/kernel-fit-image.bbclass b/meta/classes-recipe/kernel-fit-image.bbclass new file mode 100644 index 0000000000..39845997ed --- /dev/null +++ b/meta/classes-recipe/kernel-fit-image.bbclass | |||
@@ -0,0 +1,189 @@ | |||
1 | |||
2 | inherit kernel-arch kernel-artifact-names uboot-config deploy | ||
3 | require conf/image-fitimage.conf | ||
4 | |||
5 | S = "${UNPACKDIR}" | ||
6 | |||
7 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
8 | |||
9 | # This bbclass requires KERNEL_CLASSES += "kernel-fit-extra-artifacts" | ||
10 | EXCLUDE_FROM_WORLD = "1" | ||
11 | |||
12 | DEPENDS += "\ | ||
13 | u-boot-tools-native dtc-native \ | ||
14 | ${@'kernel-signing-keys-native' if d.getVar('FIT_GENERATE_KEYS') == '1' else ''} \ | ||
15 | " | ||
16 | |||
17 | python () { | ||
18 | image = d.getVar('INITRAMFS_IMAGE') | ||
19 | if image and d.getVar('INITRAMFS_IMAGE_BUNDLE') != '1': | ||
20 | if d.getVar('INITRAMFS_MULTICONFIG'): | ||
21 | mc = d.getVar('BB_CURRENT_MC') | ||
22 | d.appendVarFlag('do_compile', 'mcdepends', ' mc:' + mc + ':${INITRAMFS_MULTICONFIG}:${INITRAMFS_IMAGE}:do_image_complete') | ||
23 | else: | ||
24 | d.appendVarFlag('do_compile', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') | ||
25 | |||
26 | #check if there are any dtb providers | ||
27 | providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb") | ||
28 | if providerdtb: | ||
29 | d.appendVarFlag('do_compile', 'depends', ' virtual/dtb:do_populate_sysroot') | ||
30 | d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree") | ||
31 | } | ||
32 | |||
33 | do_configure[noexec] = "1" | ||
34 | |||
35 | UBOOT_MKIMAGE_KERNEL_TYPE ?= "kernel" | ||
36 | KERNEL_IMAGEDEST ?= "/boot" | ||
37 | |||
38 | python do_compile() { | ||
39 | import shutil | ||
40 | import oe.fitimage | ||
41 | |||
42 | itsfile = "fit-image.its" | ||
43 | fitname = "fitImage" | ||
44 | kernel_deploydir = d.getVar('DEPLOY_DIR_IMAGE') | ||
45 | kernel_deploysubdir = d.getVar('KERNEL_DEPLOYSUBDIR') | ||
46 | if kernel_deploysubdir: | ||
47 | kernel_deploydir = os.path.join(kernel_deploydir, kernel_deploysubdir) | ||
48 | |||
49 | # Collect all the its nodes before the its file is generated and mkimage gets executed | ||
50 | root_node = oe.fitimage.ItsNodeRootKernel( | ||
51 | d.getVar("FIT_DESC"), d.getVar("FIT_ADDRESS_CELLS"), | ||
52 | d.getVar('HOST_PREFIX'), d.getVar('UBOOT_ARCH'), d.getVar("FIT_CONF_PREFIX"), | ||
53 | oe.types.boolean(d.getVar('UBOOT_SIGN_ENABLE')), d.getVar("UBOOT_SIGN_KEYDIR"), | ||
54 | d.getVar("UBOOT_MKIMAGE"), d.getVar("UBOOT_MKIMAGE_DTCOPTS"), | ||
55 | d.getVar("UBOOT_MKIMAGE_SIGN"), d.getVar("UBOOT_MKIMAGE_SIGN_ARGS"), | ||
56 | d.getVar('FIT_HASH_ALG'), d.getVar('FIT_SIGN_ALG'), d.getVar('FIT_PAD_ALG'), | ||
57 | d.getVar('UBOOT_SIGN_KEYNAME'), | ||
58 | oe.types.boolean(d.getVar('FIT_SIGN_INDIVIDUAL')), d.getVar('UBOOT_SIGN_IMG_KEYNAME') | ||
59 | ) | ||
60 | |||
61 | # Prepare a kernel image section. | ||
62 | shutil.copyfile(os.path.join(kernel_deploydir, "linux.bin"), "linux.bin") | ||
63 | with open(os.path.join(kernel_deploydir, "linux_comp")) as linux_comp_f: | ||
64 | linux_comp = linux_comp_f.read() | ||
65 | root_node.fitimage_emit_section_kernel("kernel-1", "linux.bin", linux_comp, | ||
66 | d.getVar('UBOOT_LOADADDRESS'), d.getVar('UBOOT_ENTRYPOINT'), | ||
67 | d.getVar('UBOOT_MKIMAGE_KERNEL_TYPE'), d.getVar("UBOOT_ENTRYSYMBOL")) | ||
68 | |||
69 | # Prepare a DTB image section | ||
70 | kernel_devicetree = d.getVar('KERNEL_DEVICETREE') | ||
71 | external_kernel_devicetree = d.getVar("EXTERNAL_KERNEL_DEVICETREE") | ||
72 | if kernel_devicetree: | ||
73 | for dtb in kernel_devicetree.split(): | ||
74 | # In deploy_dir the DTBs are without sub-directories also with KERNEL_DTBVENDORED = "1" | ||
75 | dtb_name = os.path.basename(dtb) | ||
76 | |||
77 | # Skip DTB if it's also provided in EXTERNAL_KERNEL_DEVICETREE directory | ||
78 | if external_kernel_devicetree: | ||
79 | ext_dtb_path = os.path.join(external_kernel_devicetree, dtb_name) | ||
80 | if os.path.exists(ext_dtb_path) and os.path.getsize(ext_dtb_path) > 0: | ||
81 | continue | ||
82 | |||
83 | # Copy the dtb or dtbo file into the FIT image assembly directory | ||
84 | shutil.copyfile(os.path.join(kernel_deploydir, dtb_name), dtb_name) | ||
85 | root_node.fitimage_emit_section_dtb(dtb_name, dtb_name, | ||
86 | d.getVar("UBOOT_DTB_LOADADDRESS"), d.getVar("UBOOT_DTBO_LOADADDRESS")) | ||
87 | |||
88 | if external_kernel_devicetree: | ||
89 | # iterate over all .dtb and .dtbo files in the external kernel devicetree directory | ||
90 | # and copy them to the FIT image assembly directory | ||
91 | for dtb_name in sorted(os.listdir(external_kernel_devicetree)): | ||
92 | if dtb_name.endswith('.dtb') or dtb_name.endswith('.dtbo'): | ||
93 | dtb_path = os.path.join(external_kernel_devicetree, dtb_name) | ||
94 | |||
95 | # For symlinks, add a configuration node that refers to the DTB image node to which the symlink points | ||
96 | symlink_target = oe.fitimage.symlink_points_below(dtb_name, external_kernel_devicetree) | ||
97 | if symlink_target: | ||
98 | root_node.fitimage_emit_section_dtb_alias(dtb_name, symlink_target, True) | ||
99 | # For real DTB files add an image node and a configuration node | ||
100 | else: | ||
101 | shutil.copyfile(dtb_path, dtb_name) | ||
102 | root_node.fitimage_emit_section_dtb(dtb_name, dtb_name, | ||
103 | d.getVar("UBOOT_DTB_LOADADDRESS"), d.getVar("UBOOT_DTBO_LOADADDRESS"), True) | ||
104 | |||
105 | # Prepare a u-boot script section | ||
106 | fit_uboot_env = d.getVar("FIT_UBOOT_ENV") | ||
107 | if fit_uboot_env: | ||
108 | root_node.fitimage_emit_section_boot_script("bootscr-"+fit_uboot_env , fit_uboot_env) | ||
109 | |||
110 | # Prepare a setup section (For x86) | ||
111 | setup_bin_path = os.path.join(kernel_deploydir, "setup.bin") | ||
112 | if os.path.exists(setup_bin_path): | ||
113 | shutil.copyfile(setup_bin_path, "setup.bin") | ||
114 | root_node.fitimage_emit_section_setup("setup-1", "setup.bin") | ||
115 | |||
116 | # Prepare a ramdisk section. | ||
117 | initramfs_image = d.getVar('INITRAMFS_IMAGE') | ||
118 | if initramfs_image and d.getVar("INITRAMFS_IMAGE_BUNDLE") != '1': | ||
119 | # Find and use the first initramfs image archive type we find | ||
120 | found = False | ||
121 | for img in d.getVar("FIT_SUPPORTED_INITRAMFS_FSTYPES").split(): | ||
122 | initramfs_path = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), "%s.%s" % (d.getVar('INITRAMFS_IMAGE_NAME'), img)) | ||
123 | if os.path.exists(initramfs_path): | ||
124 | bb.note("Found initramfs image: " + initramfs_path) | ||
125 | found = True | ||
126 | root_node.fitimage_emit_section_ramdisk("ramdisk-1", initramfs_path, | ||
127 | initramfs_image, | ||
128 | d.getVar("UBOOT_RD_LOADADDRESS"), | ||
129 | d.getVar("UBOOT_RD_ENTRYPOINT")) | ||
130 | break | ||
131 | else: | ||
132 | bb.note("Did not find initramfs image: " + initramfs_path) | ||
133 | |||
134 | if not found: | ||
135 | bb.fatal("Could not find a valid initramfs type for %s, the supported types are: %s" % (d.getVar('INITRAMFS_IMAGE_NAME'), d.getVar('FIT_SUPPORTED_INITRAMFS_FSTYPES'))) | ||
136 | |||
137 | # Generate the configuration section | ||
138 | root_node.fitimage_emit_section_config(d.getVar("FIT_CONF_DEFAULT_DTB")) | ||
139 | |||
140 | # Write the its file | ||
141 | root_node.write_its_file(itsfile) | ||
142 | |||
143 | # Assemble the FIT image | ||
144 | root_node.run_mkimage_assemble(itsfile, fitname) | ||
145 | |||
146 | # Sign the FIT image if required | ||
147 | root_node.run_mkimage_sign(fitname) | ||
148 | } | ||
149 | do_compile[depends] += "virtual/kernel:do_deploy" | ||
150 | |||
151 | do_install() { | ||
152 | install -d "${D}/${KERNEL_IMAGEDEST}" | ||
153 | install -m 0644 "${B}/fitImage" "${D}/${KERNEL_IMAGEDEST}/fitImage" | ||
154 | } | ||
155 | |||
156 | FILES:${PN} = "${KERNEL_IMAGEDEST}" | ||
157 | |||
158 | |||
159 | do_deploy() { | ||
160 | deploy_dir="${DEPLOYDIR}" | ||
161 | if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then | ||
162 | deploy_dir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}" | ||
163 | fi | ||
164 | install -d "$deploy_dir" | ||
165 | install -m 0644 "${B}/fitImage" "$deploy_dir/fitImage" | ||
166 | install -m 0644 "${B}/fit-image.its" "$deploy_dir/fit-image.its" | ||
167 | |||
168 | if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then | ||
169 | ln -snf fit-image.its "$deploy_dir/fitImage-its-${KERNEL_FIT_NAME}.its" | ||
170 | if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then | ||
171 | ln -snf fit-image.its "$deploy_dir/fitImage-its-${KERNEL_FIT_LINK_NAME}" | ||
172 | fi | ||
173 | fi | ||
174 | |||
175 | if [ -n "${INITRAMFS_IMAGE}" ]; then | ||
176 | ln -snf fit-image-its "$deploy_dir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its" | ||
177 | if [ -n "${KERNEL_FIT_LINK_NAME}" ]; then | ||
178 | ln -snf fit-image.its "$deploy_dir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" | ||
179 | fi | ||
180 | |||
181 | if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then | ||
182 | ln -snf fitImage "$deploy_dir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT}" | ||
183 | if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then | ||
184 | ln -snf fitImage "$deploy_dir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" | ||
185 | fi | ||
186 | fi | ||
187 | fi | ||
188 | } | ||
189 | addtask deploy after do_compile before do_build | ||