blob: 8789169f1a726412acf83d7258cbc89b17c0dc4a [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001inherit hsm-sign-env
2
3python __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# $1 ... Set compress bin name
10tinysys_prep_image() {
11
12 tinysys_comp=${TINYSYS_COMPRESS}
13
14 if test "${tinysys_comp}" = "lz4"; then
15 tinysys_suffix=".lz4"
16 elif test "${tinysys_comp}" = "gzip"; then
17 tinysys_suffix=".gz"
18 else
19 tinysys_suffix=""
20 fi
21
22 if test "${tinysys_comp}" = "lz4"; then
23 lz4 -l -c1 ${1} > ${1}${tinysys_suffix}
24 # append uncompressed filesize info
25 dec_size=0
26 fsize=$(stat -c "%s" "${1}")
27 dec_size=$(expr $dec_size + $fsize)
28 printf "%08x\n" $dec_size |
29 sed 's/\(..\)/\1 /g' | {
30 read ch0 ch1 ch2 ch3;
31 for ch in $ch3 $ch2 $ch1 $ch0; do
32 printf `printf '%s%03o' '\\' 0x$ch` >> ${1}${tinysys_suffix};
33 done;
34 }
35 elif test "${tinysys_comp}" = "gzip"; then
36 gzip -9 ${1}
37 else
38 echo "For none case or another compressing"
39 fi
40
41 if ! test "${tinysys_comp}" = "none"; then
42 mv -f "${1}${tinysys_suffix}" ${1}
43 else
44 echo "No tinysys compression"
45 fi
46
47 echo "${tinysys_comp}"
48}
49
50
51#
52# Emit the fitImage ITS header
53#
54fitimage_emit_fit_header() {
55 cat << EOF >> ${WORKDIR}/fit-image.its
56/dts-v1/;
57
58/ {
59 description = "scpsys fitImage for fusa";
60 #address-cells = <2>;
61EOF
62}
63
64#
65fitimage_emit_scpdata_fit_header() {
66 cat << EOF >> ${WORKDIR}/fit-image.its
67/dts-v1/;
68
69/ {
70 description = "scpdata fitImage for fusa";
71 #address-cells = <2>;
72EOF
73}
74
75#
76# Emit the fitImage section bits
77#
78# $1 ... Section bit type: imagestart - image section start
79# confstart - configuration section start
80# sectend - section end
81# fitend - fitimage end
82#
83fitimage_emit_section_maint() {
84 case $1 in
85 imagestart)
86 cat << EOF >> ${WORKDIR}/fit-image.its
87
88 images {
89EOF
90 ;;
91 confstart)
92 cat << EOF >> ${WORKDIR}/fit-image.its
93
94 configurations {
95EOF
96 ;;
97 sectend)
98 cat << EOF >> ${WORKDIR}/fit-image.its
99 };
100EOF
101 ;;
102 fitend)
103 cat << EOF >> ${WORKDIR}/fit-image.its
104};
105EOF
106 ;;
107 esac
108}
109
110fitimage_emit_section_scpsys() {
111
112 if [ -n "${IMAGE_HASH_ALGO}" ] ; then
113 tinysys_csum="${IMAGE_HASH_ALGO}"
114 else
115 tinysys_csum="sha256"
116 fi
117
118 cat << EOF >> ${WORKDIR}/fit-image.its
rjw03fe4c02022-02-16 10:40:11 +0800119 ${3}_1 {
120 description = "scp firmware";
xjb04a4022021-11-25 15:01:52 +0800121 data = /incbin/("${1}");
122 type = "${7}";
123 compression = "${2}";
rjw03fe4c02022-02-16 10:40:11 +0800124 load = <0x00 0x130000>;
125 hash {
xjb04a4022021-11-25 15:01:52 +0800126 algo = "sha256";
127 };
128 };
129EOF
130}
131
132fitimage_emit_section_scpdata() {
133
134 if [ -n "${IMAGE_HASH_ALGO}" ] ; then
135 tinysys_csum="${IMAGE_HASH_ALGO}"
136 else
137 tinysys_csum="sha256"
138 fi
139
140 cat << EOF >> ${WORKDIR}/fit-image.its
rjw03fe4c02022-02-16 10:40:11 +0800141 ${3}_1 {
xjb04a4022021-11-25 15:01:52 +0800142 description = "${3}";
143 data = /incbin/("${1}");
144 type = "loadable";
145 compression = "${2}";
rjw03fe4c02022-02-16 10:40:11 +0800146 load = <${4}>;
147 hash {
xjb04a4022021-11-25 15:01:52 +0800148 algo = "sha256";
149 };
150 };
151EOF
152}
153
154#
155# Emit the fitImage ITS configuration section
156#
157fitimage_emit_section_config() {
158
159 if [ -n "${VB_HASH_ALGO}" ] && [ -n "${VB_RSA_ALGO}" ] ; then
160 conf_csum="${VB_HASH_ALGO},${VB_RSA_ALGO}"
161 else
162 conf_csum="sha256,rsa2048"
163 fi
164 conf_key_name="dev"
165
166 conf_desc="${MTK_PROJECT} configuration"
167
168 if [ ! -n "${FUSA_EATURE_ENABLE}" ]; then
169 dram_node="firmware = \"scp_dram@1\";"
170 dram_img_type=",\"firmware\";"
171 else
172 dram_img_type=";"
173 fi
174
175 cat << EOF >> ${WORKDIR}/fit-image.its
rjw03fe4c02022-02-16 10:40:11 +0800176 default = "conf_1";
177 conf_1 {
xjb04a4022021-11-25 15:01:52 +0800178 description = "${conf_desc}";
rjw03fe4c02022-02-16 10:40:11 +0800179 kernel = "scpsys_1";
180 signature {
xjb04a4022021-11-25 15:01:52 +0800181 algo = "${conf_csum}";
182 key-name-hint="${conf_key_name}";
183 sign-images = "kernel"${dram_img_type}
184 };
185 };
186EOF
187}
188
189do_assemble_fitimage() {
190
191 rm -f ${WORKDIR}/fit-image.its
192
193 fitimage_emit_fit_header
194
195 #
196 # Step 1: Prepare a tinysys image section.
197 #
198 fitimage_emit_section_maint imagestart
199
200 # compress scp dram image using lz4
201 ${S}build/lz4_compress.sh ${S}tinysys-scp_out/freertos/source/${TINYSYS_DRAM_BIN} ${TINYSYS_COMPRESS}
202
203 fitimage_emit_section_scpsys ${S}tinysys-scp_out/freertos/source/${TINYSYS_BIN} \
204 none scpsys ${SCP_SRAM_DESCRIPTION} 0 ${SCP_SRAM_LOAD_ADDR} ${SCP_SRAM_TYPE}
205
206 # to decide if dram image need to be load or not
207 if [ ! -n "${FUSA_EATURE_ENABLE}" ]; then
208 if [ -n "${4GB_DRAM_PROJECT}" ]; then
209 fitimage_emit_section_scpsys ${S}tinysys-scp_out/freertos/source/${TINYSYS_DRAM_BIN}.${TINYSYS_COMPRESS} \
210 lz4 scp_dram ${SCP_DRAM_DESCRIPTION} ${SCP_4GB_DRAM_LOAD_ADDR_UPPER_BITS} ${SCP_4GB_DRAM_LOAD_ADDR_LOWER_BITS} ${SCP_DRAM_TYPE}
211 else
212 fitimage_emit_section_scpsys ${S}tinysys-scp_out/freertos/source/${TINYSYS_DRAM_BIN}.${TINYSYS_COMPRESS} \
213 lz4 scp_dram ${SCP_DRAM_DESCRIPTION} ${SCP_NON_4GB_DRAM_LOAD_ADDR_UPPER_BITS} ${SCP_NON_4GB_DRAM_LOAD_ADDR_LOWER_BITS} ${SCP_DRAM_TYPE}
214 fi
215 fi
216
217
218 fitimage_emit_section_maint sectend
219
220 #
221 # Step 2: Prepare a configurations section
222 #
223 fitimage_emit_section_maint confstart
224
225 fitimage_emit_section_config
226
227 fitimage_emit_section_maint sectend
228
229 fitimage_emit_section_maint fitend
230
231 #
232 # Step 3: Assemble the image
233 #
234 mkdir -p ./mykeys
235 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.crt ./mykeys/dev.crt
236 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.pem ./mykeys/dev.key
237 uboot-mkimage -k ./mykeys -f ${WORKDIR}/fit-image.its -r ${WORKDIR}/${TINYSYS_IMAGE}
238 cp ${WORKDIR}/fit-image.its ${WORKDIR}/scpsys-fit-image.its
239
240 # scp_data image
241 if [ ! -n "${FUSA_EATURE_ENABLE}" ]; then
242 rm -f ${WORKDIR}/fit-image.its
243
244 fitimage_emit_scpdata_fit_header
245
246 #
247 # Step 1: Prepare a tinysys image section.
248 #
249 fitimage_emit_section_maint imagestart
250
251 cp -f ${SCP_LOGO_IMAGE} ${S}tinysys-scp_out/scp-logo
252 cp -f ${SCP_WARNING_IMAGE} ${S}tinysys-scp_out/scp-warning
253 cp -f ${SCP_CVBS_IMAGE} ${S}tinysys-scp_out/scp-cvbs
254 cp -f ${SCP_GUIDELING} ${S}tinysys-scp_out/scp-guideline
255 tinysys_prep_image ${S}tinysys-scp_out/scp-logo
256 tinysys_prep_image ${S}tinysys-scp_out/scp-warning
257 tinysys_prep_image ${S}tinysys-scp_out/scp-cvbs
258 tinysys_prep_image ${S}tinysys-scp_out/scp-guideline
259 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-logo ${TINYSYS_COMPRESS} logo 0 ${SCP_LOGO_LOAD_ADDRESS}
260 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-warning ${TINYSYS_COMPRESS} warnmsg 0 ${SCP_WARNMSG_LOAD_ADDRESS}
261 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-cvbs ${TINYSYS_COMPRESS} cvbsimg 0 ${SCP_CVBSIMG_LOAD_ADDRESS}
262 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-guideline ${TINYSYS_COMPRESS} guideline 0 ${SCP_GUILDLINE_LOAD_ADDRESS}
263
264 fitimage_emit_section_maint sectend
265
266 fitimage_emit_section_maint fitend
267
268 #
269 # Step 3: Assemble the image
270 #
271 uboot-mkimage -f ${WORKDIR}/fit-image.its -r ${WORKDIR}/${TINYDATA_IMAGE}
272 cp ${WORKDIR}/fit-image.its ${WORKDIR}/scpdata-fit-image.its
273 fi
274}
275
276addtask assemble_fitimage before do_package after do_install