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