1inherit 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')
13    parser = configparser.SafeConfigParser(strict=False)
14    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"
32HPE_UBOOT_SIGNING_KEY ?= "hpe-uboot-signing-key.pem"
33
34FLASH_SIZE = "31552"
35FLASH_UBOOT_OFFSET = "0"
36FLASH_KERNEL_OFFSET = "512"
37FLASH_ROFS_OFFSET = "5376"
38FLASH_RWFS_OFFSET = "29184"
39FLASH_SECTION_OFFSET = "31552"
40FLASH_SECTION_END = "32768"
41
42UBOOT_IMG_SIZE = "393216"
43
44do_generate_static[depends] += " \
45   		  gxp-bootblock:do_deploy \
46        gxp-bootblock:do_populate_sysroot \
47        "
48
49
50make_image_links:append() {
51    ln -sf ${DEPLOY_DIR_IMAGE}/hpe-section image-section
52}
53
54do_mk_static_symlinks:append() {
55    ln -sf hpe-section image-section
56}
57
58do_generate_static:prepend() {
59    bb.build.exec_func("do_generate_hpe_image", d)
60}
61
62do_generate_static:append() {
63    _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
64                               'hpe-section'),
65                  int(d.getVar('FLASH_SECTION_OFFSET', True)),
66                  int(d.getVar('FLASH_SECTION_END', True)))
67}
68
69do_generate_hpe_image() {
70    # Extract uboot 256K
71    dd if=/dev/zero bs=1k count=256 > ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
72    dd bs=1k conv=notrunc seek=0 count=256\
73            if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
74            of=${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
75
76    # Sign uboot 256K
77    openssl sha256 -sign ${DEPLOY_DIR_IMAGE}/${HPE_UBOOT_SIGNING_KEY} -out ${DEPLOY_DIR_IMAGE}/gxp_tmp.sig \
78            ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
79
80    # Expand (header+signature) to 4K
81    cat ${DEPLOY_DIR_IMAGE}/${HPE_UBOOT_SIGNING_HEADER} ${DEPLOY_DIR_IMAGE}/gxp_tmp.sig \
82         > ${DEPLOY_DIR_IMAGE}/gxp.sig
83
84    # Add Header and Signature to hpe-section (from 60K)
85    dd bs=1k conv=notrunc seek=60 \
86          if=${DEPLOY_DIR_IMAGE}/gxp.sig \
87          of=${DEPLOY_DIR_IMAGE}/hpe-section
88
89    # Add ubb to hpe-section
90    dd bs=1k conv=notrunc seek=64 \
91          if=${DEPLOY_DIR_IMAGE}/${HPE_GXP_BOOTBLOCK_IMAGE} \
92          of=${DEPLOY_DIR_IMAGE}/hpe-section
93
94    # Expand uboot to 384K
95    dd if=/dev/zero bs=1k count=384 > ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
96    dd bs=1k conv=notrunc seek=0 count=384\
97            if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
98            of=${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX}
99
100    # Remove unnecessary files
101    rm ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
102       ${DEPLOY_DIR_IMAGE}/gxp_tmp.sig \
103       ${DEPLOY_DIR_IMAGE}/gxp.sig
104
105    mv ${DEPLOY_DIR_IMAGE}/u-boot-tmp.${UBOOT_SUFFIX} ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX}
106
107    # Check uboot image size equals to 384K
108    size="$(wc -c < "${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX}")"
109    if [ ${size} -ne ${UBOOT_IMG_SIZE} ]
110    then
111      echo "ERROR: STATIC - uBoot image size ${size} incorrect. Please try it again."
112      exit 1
113    fi
114}
115
116make_tar_of_images() {
117  type=$1
118  shift
119  extra_files="$@"
120
121  # Create the tar archive
122  tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \
123    image-u-boot image-kernel image-rofs image-rwfs image-section $extra_files
124
125  cd ${IMGDEPLOYDIR}
126  ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar
127}
128
129do_generate_static_tar[depends] += " obmc-phosphor-image:do_generate_static"
130
131do_generate_static_tar() {
132
133  ln -sf ${S}/MANIFEST MANIFEST
134  ln -sf ${S}/publickey publickey
135  make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE}
136
137  # Check uboot image size equals to 384K
138  size="$(wc -c < "image-u-boot")"
139  if [ ${size} != ${UBOOT_IMG_SIZE} ]
140  then
141    echo "ERROR: TAR - uBoot image size ${size} incorrect. Please try it again."
142    exit 1
143  fi
144
145  make_signatures image-u-boot image-kernel image-rofs image-rwfs image-section MANIFEST publickey
146  make_tar_of_images static MANIFEST publickey ${signature_files}
147
148  # Maintain non-standard legacy link.
149  cd ${IMGDEPLOYDIR}
150  ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
151}
152