blob: ffdc1716ca6b38933db0477c4a2beed54ee690b7 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001
2python __anonymous () {
3 depends = d.getVar("DEPENDS", True)
4 depends = "%s u-boot-mkimage-native" % depends
5 d.setVar("DEPENDS", depends)
6}
7
8#
9# Emit the fitImage ITS header
10#
11fitimage_emit_fit_header() {
12 cat << EOF >> ${WORKDIR}/fit-image.its
13/dts-v1/;
14
15/ {
16 description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}";
17 #address-cells = <1>;
18EOF
19}
20
21#
22# Emit the fitImage section bits
23#
24# $1 ... Section bit type: imagestart - image section start
25# confstart - configuration section start
26# sectend - section end
27# fitend - fitimage end
28#
29fitimage_emit_section_maint() {
30 case $1 in
31 imagestart)
32 cat << EOF >> ${WORKDIR}/fit-image.its
33
34 images {
35EOF
36 ;;
37 confstart)
38 cat << EOF >> ${WORKDIR}/fit-image.its
39
40 configurations {
41EOF
42 ;;
43 sectend)
44 cat << EOF >> ${WORKDIR}/fit-image.its
45 };
46EOF
47 ;;
48 fitend)
49 cat << EOF >> ${WORKDIR}/fit-image.its
50};
51EOF
52 ;;
53 esac
54}
55
56#
57# Emit the fitImage ITS u-boot section
58#
59# $1 ... Path to u-boot image
60# $2 ... Compression type
61fitimage_emit_section_uboot() {
62
63 if [ -n "${IMAGE_HASH_ALGO}" ] ; then
64 uboot_csum="${IMAGE_HASH_ALGO}"
65 else
66 uboot_csum="sha256"
67 fi
68
69 cat << EOF >> ${WORKDIR}/fit-image.its
70 kernel@1 {
71 description = "U-Boot";
72 data = /incbin/("${1}");
73 type = "kernel";
74 arch = "arm";
75 os = "linux";
76 compression = "${2}";
77 load = <${UBOOT_FIT_LOADADDRESS}>;
78 entry = <${UBOOT_FIT_ENTRYPOINT}>;
79 hash@1 {
80 algo = "${uboot_csum}";
81 };
82 };
83EOF
84}
85
86#
87# Emit the fitImage ITS DTB section
88#
89# $1 ... Image counter
90# $2 ... Path to DTB image
91fitimage_emit_section_dtb() {
92
93 if [ -n "${IMAGE_HASH_ALGO}" ] ; then
94 dtb_csum="${IMAGE_HASH_ALGO}"
95 else
96 dtb_csum="sha256"
97 fi
98
99 cat << EOF >> ${WORKDIR}/fit-image.its
100 fdt@1 {
101 description = "sig blob for u-boot verified boot";
102 data = /incbin/("${1}");
103 type = "kernel";
104 arch = "arm";
105 os = "linux";
106 compression = "${2}";
107 load = <${UBOOT_DTB_LOADADDRESS}>;
108 entry = <${UBOOT_DTB_LOADADDRESS}>;
109 hash@1 {
110 algo = "${dtb_csum}";
111 };
112 };
113EOF
114}
115
116#
117# Emit the fitImage ITS configuration section
118#
119# $1 ... u-boot image ID
120fitimage_emit_section_config() {
121
122 if [ -n "${VB_HASH_ALGO}" -a -n "${VB_RSA_ALGO}" ] ; then
123 conf_csum="${VB_HASH_ALGO},${VB_RSA_ALGO}"
124 else
125 conf_csum="sha256,rsa2048"
126 fi
127 conf_key_name="dev"
128
129 conf_desc="${MTK_PROJECT} configuration"
130
131 uboot_line="kernel = \"kernel@1\";"
132 if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then
133 fdt_line="fdt = \"fdt@1\";"
134 else
135 fdt_line=""
136 fi
137
138 cat << EOF >> ${WORKDIR}/fit-image.its
139 default = "conf@1";
140 conf@1 {
141 description = "${conf_desc}";
142 ${uboot_line}
143 ${fdt_line}
144 signature@1 {
145 algo = "${conf_csum}";
146 key-name-hint="${conf_key_name}";
147 sign-images="fdt","kernel";
148 };
149 };
150EOF
151}
152
153do_assemble_fitimage() {
154
155 rm -f ${WORKDIR}/fit-image.its
156
157 fitimage_emit_fit_header
158
159 #
160 # Step 1: Prepare a u-boot image section.
161 #
162 fitimage_emit_section_maint imagestart
163
164 fitimage_emit_section_uboot ${UBOOT_OUT}/${UBOOT_BINARY} ${UBOOT_COMPRESS}
165
166 if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then
167 fitimage_emit_section_dtb ${UBOOT_OUT}/sig_blob.dtb none
168 fi
169
170 fitimage_emit_section_maint sectend
171
172 #
173 # Step 2: Prepare a configurations section
174 #
175 fitimage_emit_section_maint confstart
176
177 fitimage_emit_section_config
178
179 fitimage_emit_section_maint sectend
180
181 fitimage_emit_section_maint fitend
182
183 #
184 # Step 3: Assemble the image
185 #
186 dtc -p 0x3ff ${WORKDIR}/u-boot.dts -O dtb -o ${UBOOT_OUT}/sig_blob.dtb
187 uboot-mkimage -f ${WORKDIR}/fit-image.its ${UBOOT_OUT}/${UBOOT_FIT_IMAGE}
188
189 if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then
190 if [ "${STANDALONE_SIGN_PREPARE}" = "yes" ]; then
191 exit 0
192 fi
193 mkdir -p ./mykeys
194 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.crt ./mykeys/dev.crt
195 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.pem ./mykeys/dev.key
196 ${UBOOT_OUT}/tools/mkimage -D "-I dts -O dtb -p 1024" -k ./mykeys -f ${WORKDIR}/fit-image.its -K ${UBOOT_OUT}/sig_blob.dtb -r ${UBOOT_OUT}/${UBOOT_FIT_IMAGE}
197 uboot-mkimage -D "-I dts -O dtb -p 1024" -k ./mykeys -f ${WORKDIR}/fit-image.its -r ${UBOOT_OUT}/${UBOOT_FIT_IMAGE}
198 fi
199}
200
201addtask assemble_fitimage before do_install after do_compile
202