rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | inherit hsm-sign-env |
| 2 | |
| 3 | python __anonymous () { |
| 4 | depends = d.getVar("DEPENDS", True) |
| 5 | depends = "%s u-boot-mkimage-native lz4-native dtc-native" % depends |
| 6 | d.setVar("DEPENDS", depends) |
| 7 | } |
| 8 | |
| 9 | # |
| 10 | # Emit the fitImage ITS header |
| 11 | # |
| 12 | fitimage_emit_fit_header() { |
| 13 | cat << EOF >> ${WORKDIR}/fit-image.its |
| 14 | /dts-v1/; |
| 15 | |
| 16 | / { |
| 17 | description = "TINYSYS fitImage"; |
| 18 | #address-cells = <1>; |
| 19 | EOF |
| 20 | } |
| 21 | |
| 22 | # |
| 23 | # Emit the fitImage section bits |
| 24 | # |
| 25 | # $1 ... Section bit type: imagestart - image section start |
| 26 | # confstart - configuration section start |
| 27 | # sectend - section end |
| 28 | # fitend - fitimage end |
| 29 | # |
| 30 | fitimage_emit_section_maint() { |
| 31 | case $1 in |
| 32 | imagestart) |
| 33 | cat << EOF >> ${WORKDIR}/fit-image.its |
| 34 | |
| 35 | images { |
| 36 | EOF |
| 37 | ;; |
| 38 | confstart) |
| 39 | cat << EOF >> ${WORKDIR}/fit-image.its |
| 40 | |
| 41 | configurations { |
| 42 | EOF |
| 43 | ;; |
| 44 | sectend) |
| 45 | cat << EOF >> ${WORKDIR}/fit-image.its |
| 46 | }; |
| 47 | EOF |
| 48 | ;; |
| 49 | fitend) |
| 50 | cat << EOF >> ${WORKDIR}/fit-image.its |
| 51 | }; |
| 52 | EOF |
| 53 | ;; |
| 54 | esac |
| 55 | } |
| 56 | |
| 57 | fitimage_emit_section_tinysys() { |
| 58 | |
| 59 | if [ -n "${IMAGE_HASH_ALGO}" ] ; then |
| 60 | tinysys_csum="${IMAGE_HASH_ALGO}" |
| 61 | else |
| 62 | tinysys_csum="sha256" |
| 63 | fi |
| 64 | |
| 65 | cat << EOF >> ${WORKDIR}/fit-image.its |
| 66 | tinysys@1 { |
| 67 | description = "TINYSYS Image"; |
| 68 | data = /incbin/("${1}"); |
| 69 | type = "kernel"; |
| 70 | arch = "arm"; |
| 71 | os = "FreeRTOS"; |
| 72 | compression = "${2}"; |
| 73 | load = <${TINYSYS_LOADADDRESS}>; |
| 74 | entry = <${TINYSYS_ENTRYPOINT}>; |
| 75 | hash@1 { |
| 76 | algo = "${tinysys_csum}"; |
| 77 | }; |
| 78 | }; |
| 79 | EOF |
| 80 | } |
| 81 | |
| 82 | # |
| 83 | # Emit the fitImage ITS configuration section |
| 84 | # |
| 85 | fitimage_emit_section_config() { |
| 86 | |
| 87 | if [ -n "${VB_HASH_ALGO}" ] && [ -n "${VB_RSA_ALGO}" ] ; then |
| 88 | conf_csum="${VB_HASH_ALGO},${VB_RSA_ALGO}" |
| 89 | else |
| 90 | conf_csum="sha256,rsa2048" |
| 91 | fi |
| 92 | conf_key_name="dev" |
| 93 | |
| 94 | conf_desc="${MTK_PROJECT} configuration" |
| 95 | |
| 96 | cat << EOF >> ${WORKDIR}/fit-image.its |
| 97 | default = "conf@1"; |
| 98 | conf@1 { |
| 99 | description = "${conf_desc}"; |
| 100 | kernel = "tinysys@1"; |
| 101 | signature@1 { |
| 102 | algo = "${conf_csum}"; |
| 103 | key-name-hint="${conf_key_name}"; |
| 104 | sign-images = "kernel"; |
| 105 | }; |
| 106 | }; |
| 107 | EOF |
| 108 | } |
| 109 | |
| 110 | do_assemble_fitimage() { |
| 111 | |
| 112 | rm -f ${WORKDIR}/fit-image.its |
| 113 | |
| 114 | fitimage_emit_fit_header |
| 115 | |
| 116 | # |
| 117 | # Step 1: Prepare a tinysys image section. |
| 118 | # |
| 119 | fitimage_emit_section_maint imagestart |
| 120 | |
| 121 | |
| 122 | fitimage_emit_section_tinysys ${TINYSYS_OUT}/${TINYSYS_BIN}.bin ${TINYSYS_COMPRESS} |
| 123 | |
| 124 | fitimage_emit_section_maint sectend |
| 125 | |
| 126 | # |
| 127 | # Step 2: Prepare a configurations section |
| 128 | # |
| 129 | fitimage_emit_section_maint confstart |
| 130 | |
| 131 | fitimage_emit_section_config |
| 132 | |
| 133 | fitimage_emit_section_maint sectend |
| 134 | |
| 135 | fitimage_emit_section_maint fitend |
| 136 | |
| 137 | # |
| 138 | # Step 3: Assemble the image |
| 139 | # |
| 140 | ${HSM_ENV} HSM_KEY_NAME=${VERIFIED_KEY} uboot-mkimage -f ${WORKDIR}/fit-image.its ${WORKDIR}/${TINYSYS_IMAGE} |
| 141 | |
| 142 | if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then |
| 143 | mkdir -p ./mykeys |
| 144 | cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.crt ./mykeys/dev.crt |
| 145 | cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.pem ./mykeys/dev.key |
| 146 | ${HSM_ENV} HSM_KEY_NAME=${VERIFIED_KEY} uboot-mkimage -D "-I dts -O dtb -p 1024" -k ./mykeys -f ${WORKDIR}/fit-image.its -r ${WORKDIR}/${TINYSYS_IMAGE} |
| 147 | fi |
| 148 | } |
| 149 | |
| 150 | addtask assemble_fitimage before do_package after do_install |