rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | inherit kernel-uboot-extension |
| 2 | |
| 3 | python __anonymous () { |
| 4 | kerneltype = d.getVar('KERNEL_IMAGETYPE', True) |
| 5 | if kerneltype == 'fitImage': |
| 6 | depends = d.getVar("DEPENDS", True) |
| 7 | depends = "%s u-boot-mkimage-native lz4-native dtc-native" % depends |
| 8 | d.setVar("DEPENDS", depends) |
| 9 | |
| 10 | # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal |
| 11 | # to kernel.bbclass . We have to override it, since we pack zImage |
| 12 | # (at least for now) into the fitImage . |
| 13 | kernelarch = d.getVar('KERNEL_ARCH', True) |
| 14 | if kernelarch == 'arm': |
| 15 | d.setVar("KERNEL_IMAGETYPE_FOR_MAKE", "zImage") |
| 16 | elif kernelarch == 'arm64': |
| 17 | d.setVar("KERNEL_IMAGETYPE_FOR_MAKE", "Image") |
| 18 | else: |
| 19 | print("please set KERNEL_ARCH variable.") |
| 20 | sys.exit(1) |
| 21 | |
| 22 | image = d.getVar('INITRAMFS_IMAGE', True) |
| 23 | if image: |
| 24 | d.appendVarFlag('do_assemble_fitimage', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
| 25 | d.appendVarFlag('do_assemble_fitimage_ramdisk', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
| 26 | } |
| 27 | |
| 28 | # |
| 29 | # Emit the fitImage ITS header |
| 30 | # |
| 31 | fitimage_emit_fit_header() { |
| 32 | cat << EOF >> fit-image.its |
| 33 | /dts-v1/; |
| 34 | |
| 35 | / { |
| 36 | description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"; |
| 37 | #address-cells = <1>; |
| 38 | EOF |
| 39 | } |
| 40 | |
| 41 | # |
| 42 | # Emit the fitImage section bits |
| 43 | # |
| 44 | # $1 ... Section bit type: imagestart - image section start |
| 45 | # confstart - configuration section start |
| 46 | # sectend - section end |
| 47 | # fitend - fitimage end |
| 48 | # |
| 49 | fitimage_emit_section_maint() { |
| 50 | case $1 in |
| 51 | imagestart) |
| 52 | cat << EOF >> fit-image.its |
| 53 | |
| 54 | images { |
| 55 | EOF |
| 56 | ;; |
| 57 | confstart) |
| 58 | cat << EOF >> fit-image.its |
| 59 | |
| 60 | configurations { |
| 61 | EOF |
| 62 | ;; |
| 63 | sectend) |
| 64 | cat << EOF >> fit-image.its |
| 65 | }; |
| 66 | EOF |
| 67 | ;; |
| 68 | fitend) |
| 69 | cat << EOF >> fit-image.its |
| 70 | }; |
| 71 | EOF |
| 72 | ;; |
| 73 | esac |
| 74 | } |
| 75 | |
| 76 | # |
| 77 | # Emit the fitImage ITS kernel section |
| 78 | # |
| 79 | # $1 ... Image counter |
| 80 | # $2 ... Path to kernel image |
| 81 | # $3 ... Compression type |
| 82 | fitimage_emit_section_kernel() { |
| 83 | |
| 84 | if [ -n "${IMAGE_HASH_ALGO}" ] ; then |
| 85 | kernel_csum="${IMAGE_HASH_ALGO}" |
| 86 | else |
| 87 | kernel_csum="sha256" |
| 88 | fi |
| 89 | |
| 90 | ENTRYPOINT=${UBOOT_ENTRYPOINT} |
| 91 | if [ -n "${UBOOT_ENTRYSYMBOL}" ] ; then |
| 92 | ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \ |
| 93 | awk '$3=="${UBOOT_ENTRYSYMBOL}" {print $1}'` |
| 94 | fi |
| 95 | |
| 96 | cat << EOF >> fit-image.its |
| 97 | kernel@${1} { |
| 98 | description = "Linux kernel"; |
| 99 | data = /incbin/("${2}"); |
| 100 | type = "kernel"; |
| 101 | arch = "${UBOOT_ARCH}"; |
| 102 | os = "linux"; |
| 103 | compression = "${3}"; |
| 104 | load = <${UBOOT_LOADADDRESS}>; |
| 105 | entry = <${ENTRYPOINT}>; |
| 106 | hash@1 { |
| 107 | algo = "${kernel_csum}"; |
| 108 | }; |
| 109 | }; |
| 110 | EOF |
| 111 | } |
| 112 | |
| 113 | # |
| 114 | # Emit the fitImage ITS ramdisk section |
| 115 | # |
| 116 | # $1 ... Image counter |
| 117 | # $2 ... Path to ramdifk image |
| 118 | fitimage_emit_section_ramdisk() { |
| 119 | |
| 120 | if [ -n "${IMAGE_HASH_ALGO}" ] ; then |
| 121 | ramdisk_csum="${IMAGE_HASH_ALGO}" |
| 122 | else |
| 123 | ramdisk_csum="sha256" |
| 124 | fi |
| 125 | |
| 126 | cat << EOF >> fit-image.its |
| 127 | ramdisk@${1} { |
| 128 | description = "Ramdisk Image"; |
| 129 | data = /incbin/("${2}"); |
| 130 | type = "ramdisk"; |
| 131 | arch = "${UBOOT_ARCH}"; |
| 132 | os = "linux"; |
| 133 | compression = "none"; |
| 134 | load = <${RAMDISK_LOADADDRESS}>; |
| 135 | entry = <${RAMDISK_LOADADDRESS}>; |
| 136 | hash@1 { |
| 137 | algo = "${ramdisk_csum}"; |
| 138 | }; |
| 139 | }; |
| 140 | EOF |
| 141 | } |
| 142 | |
| 143 | # |
| 144 | # Emit the fitImage ITS DTB section |
| 145 | # |
| 146 | # $1 ... Image counter |
| 147 | # $2 ... Path to DTB image |
| 148 | fitimage_emit_section_dtb() { |
| 149 | |
| 150 | if [ -n "${IMAGE_HASH_ALGO}" ] ; then |
| 151 | dtb_csum="${IMAGE_HASH_ALGO}" |
| 152 | else |
| 153 | dtb_csum="sha256" |
| 154 | fi |
| 155 | |
| 156 | cat << EOF >> fit-image.its |
| 157 | fdt@${1} { |
| 158 | description = "Flattened Device Tree blob"; |
| 159 | data = /incbin/("${2}"); |
| 160 | type = "flat_dt"; |
| 161 | arch = "${UBOOT_ARCH}"; |
| 162 | compression = "none"; |
| 163 | load = <${DTB_LOADADDRESS}>; |
| 164 | hash@1 { |
| 165 | algo = "${dtb_csum}"; |
| 166 | }; |
| 167 | }; |
| 168 | EOF |
| 169 | } |
| 170 | |
| 171 | # |
| 172 | # Emit the fitImage ITS configuration section |
| 173 | # |
| 174 | # $1 ... Linux kernel ID |
| 175 | # $2 ... DTB image ID |
| 176 | # $3 ... Ramdisk ID |
| 177 | fitimage_emit_section_config() { |
| 178 | |
| 179 | if [ -n "${VB_HASH_ALGO}" -a -n "${VB_RSA_ALGO}" ] ; then |
| 180 | conf_csum="${VB_HASH_ALGO},${VB_RSA_ALGO}" |
| 181 | else |
| 182 | conf_csum="sha256,rsa2048" |
| 183 | fi |
| 184 | conf_key_name="dev" |
| 185 | |
| 186 | # Test if we have any DTBs at all |
| 187 | if [ -z "${2}" ] ; then |
| 188 | conf_desc="Boot Linux kernel" |
| 189 | fdt_line="" |
| 190 | else |
| 191 | conf_desc="Boot Linux kernel with FDT blob" |
| 192 | fdt_line="fdt = \"fdt@${2}\";" |
| 193 | fi |
| 194 | kernel_line="kernel = \"kernel@${1}\";" |
| 195 | |
| 196 | # Test if we have ramdisk image |
| 197 | if [ -z "${3}" ] ; then |
| 198 | ramdisk_line="" |
| 199 | else |
| 200 | ramdisk_line="ramdisk = \"ramdisk@${3}\";" |
| 201 | fi |
| 202 | |
| 203 | cat << EOF >> fit-image.its |
| 204 | default = "conf@1"; |
| 205 | conf@1 { |
| 206 | description = "${conf_desc}"; |
| 207 | ${kernel_line} |
| 208 | ${ramdisk_line} |
| 209 | ${fdt_line} |
| 210 | signature@1 { |
| 211 | algo = "${conf_csum}"; |
| 212 | key-name-hint="${conf_key_name}"; |
| 213 | sign-images="fdt","kernel"; |
| 214 | }; |
| 215 | }; |
| 216 | EOF |
| 217 | } |
| 218 | |
| 219 | # |
| 220 | # Assemble the ITS format |
| 221 | # |
| 222 | # $1 ... Ramdisk ID |
| 223 | do_assemble_fitimage() { |
| 224 | cd ${B} |
| 225 | if [ "x${KERNEL_IMAGETYPE}" = "xfitImage" ] ; then |
| 226 | kernelcount=1 |
| 227 | dtbcount="" |
| 228 | ramdiskcount="${1}" |
| 229 | rm -f fit-image.its |
| 230 | |
| 231 | fitimage_emit_fit_header |
| 232 | |
| 233 | # |
| 234 | # Step 1: Prepare a kernel image section. |
| 235 | # |
| 236 | fitimage_emit_section_maint imagestart |
| 237 | |
| 238 | uboot_prep_kimage |
| 239 | fitimage_emit_section_kernel "${kernelcount}" linux.bin "${linux_comp}" |
| 240 | |
| 241 | # Step 1.5: Prepare a ramdisk image section. |
| 242 | # |
| 243 | if [ "x${ramdiskcount}" = "x1" ] ; then |
| 244 | fitimage_emit_section_ramdisk ${ramdiskcount} ${RAMDISK_PATH} |
| 245 | fi |
| 246 | |
| 247 | # |
| 248 | # Step 2: Prepare a DTB image section |
| 249 | # |
| 250 | if [ -n "${KERNEL_DEVICETREE}" ] ; then |
| 251 | dtbcount=1 |
| 252 | for DTB in ${KERNEL_DEVICETREE}; do |
| 253 | if echo ${DTB} | grep -q '/dts/'; then |
| 254 | bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used." |
| 255 | DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'` |
| 256 | fi |
| 257 | |
| 258 | # go through device tree blob dir for 32/64 bits kernel |
| 259 | DTB_PATH="arch/${ARCH}/boot/dts/mediatek/${DTB}" |
| 260 | if [ ! -e "${DTB_PATH}" ]; then |
| 261 | DTB_PATH="arch/${ARCH}/boot/dts/${DTB}" |
| 262 | if [ ! -e "${DTB_PATH}" ]; then |
| 263 | DTB_PATH="arch/${ARCH}/boot/${DTB}" |
| 264 | fi |
| 265 | fi |
| 266 | |
| 267 | fitimage_emit_section_dtb ${dtbcount} ${DTB_PATH} |
| 268 | dtbcount=`expr ${dtbcount} + 1` |
| 269 | done |
| 270 | fi |
| 271 | |
| 272 | fitimage_emit_section_maint sectend |
| 273 | |
| 274 | # Force the first Kernel and DTB in the default config |
| 275 | kernelcount=1 |
| 276 | dtbcount=1 |
| 277 | |
| 278 | # |
| 279 | # Step 3: Prepare a configurations section |
| 280 | # |
| 281 | fitimage_emit_section_maint confstart |
| 282 | |
| 283 | fitimage_emit_section_config ${kernelcount} ${dtbcount} ${ramdiskcount} |
| 284 | |
| 285 | fitimage_emit_section_maint sectend |
| 286 | |
| 287 | fitimage_emit_section_maint fitend |
| 288 | |
| 289 | # |
| 290 | # Step 4: Assemble the image |
| 291 | # |
| 292 | |
| 293 | uboot-mkimage -f fit-image.its arch/${ARCH}/boot/fitImage |
| 294 | |
| 295 | if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then |
| 296 | mkdir -p ./mykeys |
| 297 | cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.crt ./mykeys/dev.crt |
| 298 | cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.pem ./mykeys/dev.key |
| 299 | uboot-mkimage -D "-I dts -O dtb -p 1024" -k ./mykeys -f fit-image.its -r arch/${ARCH}/boot/fitImage |
| 300 | fi |
| 301 | fi |
| 302 | } |
| 303 | |
| 304 | do_assemble_fitimage_kernel() { |
| 305 | if [ "x${KERNEL_IMAGETYPE}" = "xfitImage" ] ; then |
| 306 | do_assemble_fitimage |
| 307 | fi |
| 308 | } |
| 309 | |
| 310 | do_assemble_fitimage_ramdisk() { |
| 311 | if [ "x${KERNEL_IMAGETYPE}" = "xfitImage" -a -n "${INITRAMFS_IMAGE}" ] ; then |
| 312 | do_assemble_fitimage 1 |
| 313 | fi |
| 314 | } |
| 315 | |
| 316 | addtask assemble_fitimage_kernel before do_install after do_compile |
| 317 | addtask assemble_fitimage_ramdisk before do_deploy after do_install |
| 318 | |
| 319 | kernel_do_deploy[vardepsexclude] = "DATETIME" |
| 320 | kernel_do_deploy_append() { |
| 321 | # Update deploy directory |
| 322 | if [ "x${KERNEL_IMAGETYPE}" = "xfitImage" ] ; then |
| 323 | cd ${B} |
| 324 | echo "Copying fit-image.its source file..." |
| 325 | its_base_name="${KERNEL_IMAGETYPE}-its-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 326 | its_symlink_name=${KERNEL_IMAGETYPE}-its-${MACHINE} |
| 327 | install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its |
| 328 | linux_bin_base_name="${KERNEL_IMAGETYPE}-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 329 | linux_bin_symlink_name=${KERNEL_IMAGETYPE}-linux.bin-${MACHINE} |
| 330 | install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin |
| 331 | if [ -n "${RECOVERY_KERNEL_DEVICETREE}" ] ; then |
| 332 | find arch/${ARCH}/boot/dts -name "${RECOVERY_KERNEL_DEVICETREE}" -exec install -m 0644 {} ${DEPLOYDIR}/${RECOVERY_KERNEL_DEVICETREE} \; |
| 333 | fi |
| 334 | |
| 335 | cd ${DEPLOYDIR} |
| 336 | ln -sf ${its_base_name}.its ${its_symlink_name}.its |
| 337 | ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin |
| 338 | ln -nfs ${KERNEL_IMAGETYPE}-${KERNEL_IMAGE_NAME}.bin boot.img |
| 339 | fi |
| 340 | } |
| 341 | |
| 342 | do_bundle_initramfs() { |
| 343 | : |
| 344 | } |