blob: 66fc82a650926bde29c7f22634fcc852de4bd87d [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 uboot_csum="sha256"
64
65 cat << EOF >> ${WORKDIR}/fit-image.its
66 uboot@1 {
67 description = "U-Boot";
68 data = /incbin/("${1}");
69 type = "uboot";
70 arch = "arm";
71 os = "linux";
72 compression = "${2}";
73 load = <${UBOOT_FIT_LOADADDRESS}>;
74 entry = <${UBOOT_FIT_ENTRYPOINT}>;
75 hash@1 {
76 algo = "${uboot_csum}";
77 };
78 };
79EOF
80}
81
82#
83# Emit the fitImage ITS DTB section
84#
85# $1 ... Image counter
86# $2 ... Path to DTB image
87fitimage_emit_section_dtb() {
88
89 dtb_csum="sha256"
90
91 cat << EOF >> ${WORKDIR}/fit-image.its
92 fdt@1 {
93 description = "sig blob for u-boot verified boot";
94 data = /incbin/("${1}");
95 type = "uboot";
96 arch = "arm";
97 os = "linux";
98 compression = "${2}";
99 load = <${UBOOT_DTB_LOADADDRESS}>;
100 entry = <${UBOOT_DTB_LOADADDRESS}>;
101 hash@1 {
102 algo = "${dtb_csum}";
103 };
104 };
105EOF
106}
107
108#
109# Emit the fitImage ITS configuration section
110#
111# $1 ... u-boot image ID
112fitimage_emit_section_config() {
113
114 conf_csum="sha256,rsa2048"
115 conf_key_name="dev"
116
117 conf_desc="${MTK_PROJECT} configuration"
118
119 uboot_line="uboot = \"uboot@1\";"
120 if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then
121 fdt_line="fdt = \"fdt@1\";"
122 else
123 fdt_line=""
124 fi
125
126 cat << EOF >> ${WORKDIR}/fit-image.its
127 default = "conf@1";
128 conf@1 {
129 description = "${conf_desc}";
130 ${uboot_line}
131 ${fdt_line}
132 signature@1 {
133 algo = "${conf_csum}";
134 key-name-hint="${conf_key_name}";
135 sign-images="fdt","uboot";
136 };
137 };
138EOF
139}
140
141do_assemble_fitimage() {
142
143 rm -f ${WORKDIR}/fit-image.its
144
145 fitimage_emit_fit_header
146
147 #
148 # Step 1: Prepare a u-boot image section.
149 #
150 fitimage_emit_section_maint imagestart
151
152 fitimage_emit_section_uboot ${UBOOT_OUT}/${UBOOT_BINARY} ${UBOOT_COMPRESS}
153
154 if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then
155 fitimage_emit_section_dtb ${UBOOT_OUT}/sig_blob.dtb none
156 fi
157
158 fitimage_emit_section_maint sectend
159
160 #
161 # Step 2: Prepare a configurations section
162 #
163 fitimage_emit_section_maint confstart
164
165 fitimage_emit_section_config
166
167 fitimage_emit_section_maint sectend
168
169 fitimage_emit_section_maint fitend
170
171 #
172 # Step 3: Assemble the image
173 #
174 uboot-mkimage -f ${WORKDIR}/fit-image.its ${UBOOT_OUT}/${UBOOT_FIT_IMAGE}
175
176 if [ "${SECURE_BOOT_ENABLE}" = "yes" ]; then
177 mkdir -p ./mykeys
178 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.crt ./mykeys/dev.crt
179 cp ${MTK_KEY_DIR}/${VERIFIED_KEY}.pem ./mykeys/dev.key
180 uboot-mkimage -D "-I dts -O dtb -p 1024" -k ./mykeys -f ${WORKDIR}/fit-image.its -r ${UBOOT_OUT}/${UBOOT_FIT_IMAGE}
181 fi
182}
183
184addtask assemble_fitimage before do_install after do_compile
185