blob: 2175ba28cdbc90878fae9d3c609b9e30adc76ace [file] [log] [blame]
Jorge Cisneros8a445a02020-09-03 21:09:03 +00001inherit image_version
2unset do_get_version[noexec]
3do_get_version[depends] = "os-release"
4
5# do_get_version() is copied from meta-phosphor/classes/image_version.bbclass and
6# modified to append the date and time to the version if a file named "developer"
7# exists in the openbmc/build directory
8def do_get_version(d):
9 import configparser
10 import io
11 path = d.getVar('STAGING_DIR_TARGET', True) + d.getVar('sysconfdir', True)
12 path = os.path.join(path, 'os-release')
Charles Kearney7237a3e2023-04-07 21:15:03 +000013 parser = configparser.SafeConfigParser(strict=False)
Jorge Cisneros8a445a02020-09-03 21:09:03 +000014 parser.optionxform = str
15 version = ''
16 try:
17 with open(path, 'r') as fd:
18 buf = '[root]\n' + fd.read()
19 fd = io.StringIO(buf)
20 parser.readfp(fd)
21 version = parser['root']['VERSION_ID']
22 dev_path = d.getVar('PWD', True)
23 dev_path = os.path.join(dev_path, 'developer')
24 if os.path.isfile(dev_path):
25 version = version[:-1] + str(d.getVar('IMAGE_VERSION_SUFFIX', True)).strip()
26 except:
27 pass
28 return version
29
30HPE_GXP_BOOTBLOCK_IMAGE ?= "gxp-bootblock.bin"
31HPE_UBOOT_SIGNING_HEADER ?= "hpe-uboot-header.section"
Charles Kearney7237a3e2023-04-07 21:15:03 +000032HPE_UBOOT_SIGNING_HEADER_512 ?= "hpe-uboot-header-512.section"
Jorge Cisneros8a445a02020-09-03 21:09:03 +000033HPE_UBOOT_SIGNING_KEY ?= "hpe-uboot-signing-key.pem"
34
Charles Kearney7237a3e2023-04-07 21:15:03 +000035# Offsets that are the same for the standard image and secure boot image
Jorge Cisneros8a445a02020-09-03 21:09:03 +000036FLASH_SIZE = "31552"
37FLASH_UBOOT_OFFSET = "0"
Charles Kearney7237a3e2023-04-07 21:15:03 +000038UBOOT_IMG_SIZE = "393216"
Jorge Cisneros8a445a02020-09-03 21:09:03 +000039FLASH_KERNEL_OFFSET = "512"
40FLASH_ROFS_OFFSET = "5376"
41FLASH_RWFS_OFFSET = "29184"
Charles Kearney7237a3e2023-04-07 21:15:03 +000042
43# Standard image offsets
44FLASH_STANDARD_SECTION_OFFSET = "31552"
45FLASH_STANDARD_SECTION_END = "32768"
46
47# Secure boot offsets
48# offset at 0x01f7_0000 / 1024 = 32192
49FLASH_SECTION_OFFSET = "32192"
50# end is offset + 576
Jorge Cisneros8a445a02020-09-03 21:09:03 +000051FLASH_SECTION_END = "32768"
52
Charles Kearney7237a3e2023-04-07 21:15:03 +000053# offset at 0x01ee_0000 / 1024 = 31616
54FLASH_SECTION2_OFFSET = "31616"
55FLASH_SECTION2_END = "32192"
56
57# offset at 0x01c0_0000 / 1024 = 28672
58FLASH_UBOOT2_OFFSET = "28672"
Jorge Cisneros8a445a02020-09-03 21:09:03 +000059
60do_generate_static[depends] += " \
Charles Kearney7237a3e2023-04-07 21:15:03 +000061 gxp-bootblock:do_deploy \
Jorge Cisneros8a445a02020-09-03 21:09:03 +000062 gxp-bootblock:do_populate_sysroot \
63 "
Mike Garrettab6de742021-08-24 17:56:32 -050064make_image_links:append() {
Jorge Cisneros8a445a02020-09-03 21:09:03 +000065 ln -sf ${DEPLOY_DIR_IMAGE}/hpe-section image-section
Charles Kearney7237a3e2023-04-07 21:15:03 +000066
67 if [ -f ${DEPLOY_DIR_IMAGE}/hpe-section2 ]
68 then
69 ln -sf ${DEPLOY_DIR_IMAGE}/hpe-section2 image-section2
70 fi
Jorge Cisneros8a445a02020-09-03 21:09:03 +000071}
72
Mike Garrettab6de742021-08-24 17:56:32 -050073do_mk_static_symlinks:append() {
Jorge Cisneros8a445a02020-09-03 21:09:03 +000074 ln -sf hpe-section image-section
Charles Kearney7237a3e2023-04-07 21:15:03 +000075
76 if [ -f ${DEPLOY_DIR_IMAGE}/hpe-section2 ]
77 then
78 ln -sf hpe-section2 image-section2
79 fi
Jorge Cisneros8a445a02020-09-03 21:09:03 +000080}
81
Mike Garrettab6de742021-08-24 17:56:32 -050082do_generate_static:prepend() {
Jorge Cisneros8a445a02020-09-03 21:09:03 +000083 bb.build.exec_func("do_generate_hpe_image", d)
84}
85
Mike Garrettab6de742021-08-24 17:56:32 -050086do_generate_static:append() {
Charles Kearney7237a3e2023-04-07 21:15:03 +000087 # hpe-section2 and u-boot2 only exist in the secure boot image.
88 # If hpe-section2 exists, then this is secure boot.
89 if os.path.exists(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 'hpe-section2')):
90 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 'hpe-section'),
91 int(d.getVar('FLASH_SECTION_OFFSET', True)),
92 int(d.getVar('FLASH_SECTION_END', True)))
93
94 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 'hpe-section2'),
95 int(d.getVar('FLASH_SECTION2_OFFSET', True)),
96 int(d.getVar('FLASH_SECTION2_END', True)))
97
98 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)),
99 int(d.getVar('FLASH_UBOOT2_OFFSET', True)),
100 int(d.getVar('FLASH_RWFS_OFFSET', True)))
101 else:
102 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 'hpe-section'),
103 int(d.getVar('FLASH_STANDARD_SECTION_OFFSET', True)),
104 int(d.getVar('FLASH_STANDARD_SECTION_END', True)))
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000105}
106
Charles Kearney7237a3e2023-04-07 21:15:03 +0000107# Generate the secure boot image by default
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000108do_generate_hpe_image() {
109 # Extract uboot 256K
110 dd if=/dev/zero bs=1k count=256 > ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
111 dd bs=1k conv=notrunc seek=0 count=256\
112 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
113 of=${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
114
Charles Kearney80ae01a2023-06-08 14:57:32 -0500115
Charles Kearney7237a3e2023-04-07 21:15:03 +0000116 # TODO - replace this openssl signing command line with whatever command you need to create a
117 # digital signature of ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000118
Charles Kearney80ae01a2023-06-08 14:57:32 -0500119 openssl sha384 -sign ${DEPLOY_DIR_IMAGE}/${HPE_UBOOT_SIGNING_KEY} -out ${DEPLOY_DIR_IMAGE}/gxp_tmp.sig \
120 ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000121
Charles Kearney80ae01a2023-06-08 14:57:32 -0500122 # Cat U-Boot header+signature
123 cat ${DEPLOY_DIR_IMAGE}/${HPE_UBOOT_SIGNING_HEADER_512} ${DEPLOY_DIR_IMAGE}/gxp_tmp.sig \
124 > ${DEPLOY_DIR_IMAGE}/gxp-uboot.sig
125
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000126
Charles Kearney7237a3e2023-04-07 21:15:03 +0000127 # Create hpe-section
128 dd if=/dev/zero bs=1k count=576 > ${DEPLOY_DIR_IMAGE}/hpe-section
129
130 # Add U-Boot Header and Signature to hpe-section
131 dd bs=1k conv=notrunc seek=0 \
132 if=${DEPLOY_DIR_IMAGE}/gxp-uboot.sig \
133 of=${DEPLOY_DIR_IMAGE}/hpe-section
134
135 # Add gxp-bootblock to hpe-section
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000136 dd bs=1k conv=notrunc seek=64 \
Charles Kearney7237a3e2023-04-07 21:15:03 +0000137 if=${DEPLOY_DIR_IMAGE}/${HPE_GXP_BOOTBLOCK_IMAGE} \
138 of=${DEPLOY_DIR_IMAGE}/hpe-section
139
140 # hpe-section2 is the same as hpe-section up to this point
141 cp ${DEPLOY_DIR_IMAGE}/hpe-section ${DEPLOY_DIR_IMAGE}/hpe-section2
142
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000143
144 # Expand uboot to 384K
145 dd if=/dev/zero bs=1k count=384 > ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
Charles Kearney7237a3e2023-04-07 21:15:03 +0000146 dd bs=1k conv=notrunc seek=0 count=384 \
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000147 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
148 of=${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
149
150 # Remove unnecessary files
151 rm ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
152 ${DEPLOY_DIR_IMAGE}/gxp_tmp.sig \
Charles Kearney80ae01a2023-06-08 14:57:32 -0500153 ${DEPLOY_DIR_IMAGE}/gxp-uboot.sig
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000154
155 mv ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX} ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX}
156
Charles Kearney7237a3e2023-04-07 21:15:03 +0000157 # Check uboot image size equals to 384K
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000158 size="$(wc -c < "${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX}")"
159 if [ ${size} -ne ${UBOOT_IMG_SIZE} ]
160 then
161 echo "ERROR: STATIC - uBoot image size ${size} incorrect. Please try it again."
162 exit 1
163 fi
164}
165
166make_tar_of_images() {
167 type=$1
168 shift
169 extra_files="$@"
170
171 # Create the tar archive
172 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \
Charles Kearney7237a3e2023-04-07 21:15:03 +0000173 image-u-boot image-kernel image-rofs image-rwfs image-section* $extra_files
174
175 # Create the min tar archive
176 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.min.tar \
177 image-kernel image-rofs image-rwfs MANIFEST \
178 image-kernel.sig image-rofs.sig image-rwfs.sig MANIFEST.sig publickey
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000179
180 cd ${IMGDEPLOYDIR}
181 ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar
Charles Kearney7237a3e2023-04-07 21:15:03 +0000182 ln -sf ${IMAGE_NAME}.$type.mtd.min.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.min.tar
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000183}
184
185do_generate_static_tar[depends] += " obmc-phosphor-image:do_generate_static"
186
187do_generate_static_tar() {
188
189 ln -sf ${S}/MANIFEST MANIFEST
190 ln -sf ${S}/publickey publickey
191 make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE}
192
193 # Check uboot image size equals to 384K
194 size="$(wc -c < "image-u-boot")"
195 if [ ${size} != ${UBOOT_IMG_SIZE} ]
196 then
197 echo "ERROR: TAR - uBoot image size ${size} incorrect. Please try it again."
198 exit 1
199 fi
200
Charles Kearney7237a3e2023-04-07 21:15:03 +0000201 if [ -f image-section2 ]
202 then
203 make_signatures image-u-boot image-kernel image-rofs image-rwfs image-section image-section2 MANIFEST publickey
204 else
205 make_signatures image-u-boot image-kernel image-rofs image-rwfs image-section MANIFEST publickey
206 fi
207
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000208 make_tar_of_images static MANIFEST publickey ${signature_files}
209
210 # Maintain non-standard legacy link.
211 cd ${IMGDEPLOYDIR}
212 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
Charles Kearney7237a3e2023-04-07 21:15:03 +0000213 ln -sf ${IMAGE_NAME}.static.mtd.min.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.min.tar
Jorge Cisneros8a445a02020-09-03 21:09:03 +0000214}