rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | inherit kernel-arch |
| 2 | inherit kernel-uboot-extension |
| 3 | |
| 4 | python __anonymous () { |
| 5 | kerneltype = d.getVar('KERNEL_IMAGETYPE', True) |
| 6 | recoverykerneldevicetree = d.getVar('RECOVERY_KERNEL_DEVICETREE', True) |
| 7 | if kerneltype == 'fitImage' and recoverykerneldevicetree != '' : |
| 8 | depends = d.getVar("DEPENDS", True) |
| 9 | depends = "%s u-boot-mkimage-native lz4-native dtc-native" % depends |
| 10 | d.setVar("DEPENDS", depends) |
| 11 | } |
| 12 | |
| 13 | do_image_complete[postfuncs] += "do_assemble_recovery_ramdisk_fitimage" |
| 14 | |
| 15 | # |
| 16 | # Emit the fitImage ITS header |
| 17 | # |
| 18 | fit_recovery_ramdisk_image_emit_fit_header() { |
| 19 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 20 | /dts-v1/; |
| 21 | |
| 22 | / { |
| 23 | description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"; |
| 24 | #address-cells = <1>; |
| 25 | EOF |
| 26 | } |
| 27 | |
| 28 | # |
| 29 | # Emit the fitImage section bits |
| 30 | # |
| 31 | # $1 ... Section bit type: imagestart - image section start |
| 32 | # confstart - configuration section start |
| 33 | # sectend - section end |
| 34 | # fitend - fitimage end |
| 35 | # |
| 36 | fit_recovery_ramdisk_image_emit_section_maint() { |
| 37 | case $1 in |
| 38 | imagestart) |
| 39 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 40 | |
| 41 | images { |
| 42 | EOF |
| 43 | ;; |
| 44 | confstart) |
| 45 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 46 | |
| 47 | configurations { |
| 48 | EOF |
| 49 | ;; |
| 50 | sectend) |
| 51 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 52 | }; |
| 53 | EOF |
| 54 | ;; |
| 55 | fitend) |
| 56 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 57 | }; |
| 58 | EOF |
| 59 | ;; |
| 60 | esac |
| 61 | } |
| 62 | |
| 63 | # |
| 64 | # Emit the fitImage ITS kernel section |
| 65 | # |
| 66 | # $1 ... Image counter |
| 67 | # $2 ... Path to kernel image |
| 68 | # $3 ... Compression type |
| 69 | fit_recovery_ramdisk_image_emit_section_kernel() { |
| 70 | |
| 71 | if [ -n "${IMAGE_HASH_ALGO}" ] ; then |
| 72 | kernel_csum="${IMAGE_HASH_ALGO}" |
| 73 | else |
| 74 | kernel_csum="sha256" |
| 75 | fi |
| 76 | |
| 77 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 78 | kernel@${1} { |
| 79 | description = "Linux kernel"; |
| 80 | data = /incbin/("${2}"); |
| 81 | type = "kernel"; |
| 82 | arch = "${ARCH}"; |
| 83 | os = "linux"; |
| 84 | compression = "${3}"; |
| 85 | load = <${UBOOT_LOADADDRESS}>; |
| 86 | entry = <${UBOOT_ENTRYPOINT}>; |
| 87 | hash@1 { |
| 88 | algo = "${kernel_csum}"; |
| 89 | }; |
| 90 | }; |
| 91 | EOF |
| 92 | } |
| 93 | |
| 94 | # |
| 95 | # Emit the fitImage ITS recovery ramdisk section |
| 96 | # |
| 97 | # $1 ... Image counter |
| 98 | # $2 ... Path to ramdifk image |
| 99 | fitimage_emit_section_recovery_ramdisk() { |
| 100 | |
| 101 | if [ -n "${IMAGE_HASH_ALGO}" ] ; then |
| 102 | ramdisk_csum="${IMAGE_HASH_ALGO}" |
| 103 | else |
| 104 | ramdisk_csum="sha256" |
| 105 | fi |
| 106 | |
| 107 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 108 | ramdisk@${1} { |
| 109 | description = "Ramdisk Image"; |
| 110 | data = /incbin/("${2}"); |
| 111 | type = "ramdisk"; |
| 112 | arch = "${ARCH}"; |
| 113 | os = "linux"; |
| 114 | compression = "none"; |
| 115 | load = <${RECOVERY_RAMDISK_LOADADDRESS}>; |
| 116 | entry = <${RECOVERY_RAMDISK_LOADADDRESS}>; |
| 117 | hash@1 { |
| 118 | algo = "${ramdisk_csum}"; |
| 119 | }; |
| 120 | }; |
| 121 | EOF |
| 122 | } |
| 123 | |
| 124 | # |
| 125 | # Emit the fitImage ITS DTB section |
| 126 | # |
| 127 | # $1 ... Image counter |
| 128 | # $2 ... Path to DTB image |
| 129 | fit_recovery_ramdisk_image_emit_section_dtb() { |
| 130 | |
| 131 | if [ -n "${IMAGE_HASH_ALGO}" ] ; then |
| 132 | dtb_csum="${IMAGE_HASH_ALGO}" |
| 133 | else |
| 134 | dtb_csum="sha256" |
| 135 | fi |
| 136 | |
| 137 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 138 | fdt@${1} { |
| 139 | description = "Flattened Device Tree blob"; |
| 140 | data = /incbin/("${2}"); |
| 141 | type = "flat_dt"; |
| 142 | arch = "${ARCH}"; |
| 143 | compression = "none"; |
| 144 | load = <${DTB_LOADADDRESS}>; |
| 145 | hash@1 { |
| 146 | algo = "${dtb_csum}"; |
| 147 | }; |
| 148 | }; |
| 149 | EOF |
| 150 | } |
| 151 | |
| 152 | # |
| 153 | # Emit the fitImage ITS configuration section |
| 154 | # |
| 155 | # $1 ... Linux kernel ID |
| 156 | # $2 ... DTB image ID |
| 157 | # $3 ... Ramdisk ID |
| 158 | fit_recovery_ramdisk_image_emit_section_config() { |
| 159 | |
| 160 | if [ -n "${VB_HASH_ALGO}" -a -n "${VB_RSA_ALGO}" ] ; then |
| 161 | conf_csum="${VB_HASH_ALGO},${VB_RSA_ALGO}" |
| 162 | else |
| 163 | conf_csum="sha256,rsa2048" |
| 164 | fi |
| 165 | conf_key_name="dev" |
| 166 | |
| 167 | # Test if we have any DTBs at all |
| 168 | if [ -z "${2}" ] ; then |
| 169 | conf_desc="Boot Linux kernel" |
| 170 | fdt_line="" |
| 171 | else |
| 172 | conf_desc="Boot Linux kernel with FDT blob" |
| 173 | fdt_line="fdt = \"fdt@${2}\";" |
| 174 | fi |
| 175 | kernel_line="kernel = \"kernel@${1}\";" |
| 176 | |
| 177 | # Test if we have ramdisk image |
| 178 | if [ -z "${3}" ] ; then |
| 179 | ramdisk_line="" |
| 180 | else |
| 181 | ramdisk_line="ramdisk = \"ramdisk@${3}\";" |
| 182 | fi |
| 183 | |
| 184 | cat << EOF >> fit-recovery-ramdisk-image.its |
| 185 | default = "conf@1"; |
| 186 | conf@1 { |
| 187 | description = "${conf_desc}"; |
| 188 | ${kernel_line} |
| 189 | ${ramdisk_line} |
| 190 | ${fdt_line} |
| 191 | signature@1 { |
| 192 | algo = "${conf_csum}"; |
| 193 | key-name-hint="${conf_key_name}"; |
| 194 | sign-images="fdt","kernel"; |
| 195 | }; |
| 196 | }; |
| 197 | EOF |
| 198 | } |
| 199 | |
| 200 | do_assemble_recovery_ramdisk_fitimage() { |
| 201 | cd ${B} |
| 202 | if [ "x${KERNEL_IMAGETYPE}" = "xfitImage" -a -n "${RECOVERY_KERNEL_DEVICETREE}" ] ; then |
| 203 | kernelcount=1 |
| 204 | dtbcount=1 |
| 205 | ramdiskcount=1 |
| 206 | rm -f fit-recovery-ramdisk-image.its |
| 207 | |
| 208 | fit_recovery_ramdisk_image_emit_fit_header |
| 209 | |
| 210 | # |
| 211 | # Step 1: Prepare a kernel image section. |
| 212 | # |
| 213 | fit_recovery_ramdisk_image_emit_section_maint imagestart |
| 214 | |
| 215 | fit_recovery_ramdisk_image_emit_section_kernel ${kernelcount} ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-linux.bin-${MACHINE}.bin ${KERNEL_COMPRESS} |
| 216 | |
| 217 | # Step 1.5: Prepare a ramdisk image section. |
| 218 | # |
| 219 | fitimage_emit_section_recovery_ramdisk ${ramdiskcount} ${IMGDEPLOYDIR}/${IMAGE_BASENAME}-${MACHINE}.${IMAGE_FSTYPES} |
| 220 | |
| 221 | # |
| 222 | # Step 2: Prepare a DTB image section |
| 223 | # |
| 224 | if [ -n "${RECOVERY_KERNEL_DEVICETREE}" ] ; then |
| 225 | fit_recovery_ramdisk_image_emit_section_dtb ${dtbcount} ${DEPLOY_DIR_IMAGE}/${RECOVERY_KERNEL_DEVICETREE} |
| 226 | fi |
| 227 | |
| 228 | fit_recovery_ramdisk_image_emit_section_maint sectend |
| 229 | |
| 230 | # |
| 231 | # Step 3: Prepare a configurations section |
| 232 | # |
| 233 | fit_recovery_ramdisk_image_emit_section_maint confstart |
| 234 | |
| 235 | fit_recovery_ramdisk_image_emit_section_config ${kernelcount} ${dtbcount} ${ramdiskcount} |
| 236 | |
| 237 | fit_recovery_ramdisk_image_emit_section_maint sectend |
| 238 | |
| 239 | fit_recovery_ramdisk_image_emit_section_maint fitend |
| 240 | |
| 241 | # |
| 242 | # Step 4: Assemble the image |
| 243 | # |
| 244 | uboot-mkimage -f fit-recovery-ramdisk-image.its recovery.ramdisk.img |
| 245 | |
| 246 | if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then |
| 247 | mkdir -p ./mykeys |
| 248 | cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.crt ./mykeys/dev.crt |
| 249 | cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.pem ./mykeys/dev.key |
| 250 | uboot-mkimage -D "-I dts -O dtb -p 1024" -k ./mykeys -f fit-recovery-ramdisk-image.its -r recovery.ramdisk.img |
| 251 | fi |
| 252 | |
| 253 | # |
| 254 | # Step 5: Install the recovery.ramdisk.img and recovery fit to DEPLOY_DIR_IMAGE folder |
| 255 | # |
| 256 | install -d ${DEPLOY_DIR_IMAGE} |
| 257 | install -m 0644 fit-recovery-ramdisk-image.its recovery.ramdisk.img -t ${DEPLOY_DIR_IMAGE} |
| 258 | |
| 259 | fi |
| 260 | } |