blob: 9b3c8b03de6135cc70c1a8bee059410abe5800ef [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +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
119 ${3}@1 {
120 description = "${4}";
121 data = /incbin/("${1}");
122 type = "${7}";
123 compression = "${2}";
124 load = <${5} ${6}>;
125 hash@1 {
126 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
141 ${3}@1 {
142 description = "${3}";
143 data = /incbin/("${1}");
144 type = "loadable";
145 compression = "${2}";
146 load = <${4} ${5}>;
147 hash@1 {
148 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
176 default = "conf@1";
177 conf@1 {
178 description = "${conf_desc}";
179 kernel = "scpsys@1";
180 ${dram_node}
181 signature@1 {
182 algo = "${conf_csum}";
183 key-name-hint="${conf_key_name}";
184 sign-images = "kernel"${dram_img_type}
185 };
186 };
187EOF
188}
189
190do_assemble_fitimage() {
191
192 rm -f ${WORKDIR}/fit-image.its
193
194 fitimage_emit_fit_header
195
196 #
197 # Step 1: Prepare a tinysys image section.
198 #
199 fitimage_emit_section_maint imagestart
200
201 # compress scp dram image using lz4
202 ${S}build/lz4_compress.sh ${S}tinysys-scp_out/freertos/source/${TINYSYS_DRAM_BIN} ${TINYSYS_COMPRESS}
203
204 fitimage_emit_section_scpsys ${S}tinysys-scp_out/freertos/source/${TINYSYS_BIN} \
205 none scpsys ${SCP_SRAM_DESCRIPTION} 0 ${SCP_SRAM_LOAD_ADDR} ${SCP_SRAM_TYPE}
206
207 # to decide if dram image need to be load or not
208 if [ ! -n "${FUSA_EATURE_ENABLE}" ]; then
209 if [ -n "${4GB_DRAM_PROJECT}" ]; then
210 fitimage_emit_section_scpsys ${S}tinysys-scp_out/freertos/source/${TINYSYS_DRAM_BIN}.${TINYSYS_COMPRESS} \
211 lz4 scp_dram ${SCP_DRAM_DESCRIPTION} ${SCP_4GB_DRAM_LOAD_ADDR_UPPER_BITS} ${SCP_4GB_DRAM_LOAD_ADDR_LOWER_BITS} ${SCP_DRAM_TYPE}
212 else
213 fitimage_emit_section_scpsys ${S}tinysys-scp_out/freertos/source/${TINYSYS_DRAM_BIN}.${TINYSYS_COMPRESS} \
214 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}
215 fi
216 fi
217
218
219 fitimage_emit_section_maint sectend
220
221 #
222 # Step 2: Prepare a configurations section
223 #
224 fitimage_emit_section_maint confstart
225
226 fitimage_emit_section_config
227
228 fitimage_emit_section_maint sectend
229
230 fitimage_emit_section_maint fitend
231
232 #
233 # Step 3: Assemble the image
234 #
235 mkdir -p ./mykeys
236 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.crt ./mykeys/dev.crt
237 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.pem ./mykeys/dev.key
238 uboot-mkimage -k ./mykeys -f ${WORKDIR}/fit-image.its -r ${WORKDIR}/${TINYSYS_IMAGE}
239 cp ${WORKDIR}/fit-image.its ${WORKDIR}/scpsys-fit-image.its
240
241 # scp_data image
242 if [ ! -n "${FUSA_EATURE_ENABLE}" ]; then
243 rm -f ${WORKDIR}/fit-image.its
244
245 fitimage_emit_scpdata_fit_header
246
247 #
248 # Step 1: Prepare a tinysys image section.
249 #
250 fitimage_emit_section_maint imagestart
251
252 cp -f ${SCP_LOGO_IMAGE} ${S}tinysys-scp_out/scp-logo
253 cp -f ${SCP_WARNING_IMAGE} ${S}tinysys-scp_out/scp-warning
254 cp -f ${SCP_CVBS_IMAGE} ${S}tinysys-scp_out/scp-cvbs
255 cp -f ${SCP_GUIDELING} ${S}tinysys-scp_out/scp-guideline
256 tinysys_prep_image ${S}tinysys-scp_out/scp-logo
257 tinysys_prep_image ${S}tinysys-scp_out/scp-warning
258 tinysys_prep_image ${S}tinysys-scp_out/scp-cvbs
259 tinysys_prep_image ${S}tinysys-scp_out/scp-guideline
260 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-logo ${TINYSYS_COMPRESS} logo 0 ${SCP_LOGO_LOAD_ADDRESS}
261 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-warning ${TINYSYS_COMPRESS} warnmsg 0 ${SCP_WARNMSG_LOAD_ADDRESS}
262 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-cvbs ${TINYSYS_COMPRESS} cvbsimg 0 ${SCP_CVBSIMG_LOAD_ADDRESS}
263 fitimage_emit_section_scpdata ${S}tinysys-scp_out/scp-guideline ${TINYSYS_COMPRESS} guideline 0 ${SCP_GUILDLINE_LOAD_ADDRESS}
264
265 fitimage_emit_section_maint sectend
266
267 fitimage_emit_section_maint fitend
268
269 #
270 # Step 3: Assemble the image
271 #
272 uboot-mkimage -f ${WORKDIR}/fit-image.its -r ${WORKDIR}/${TINYDATA_IMAGE}
273 cp ${WORKDIR}/fit-image.its ${WORKDIR}/scpdata-fit-image.its
274 fi
275}
276
277addtask assemble_fitimage before do_package after do_install