Skip to content

Commit

Permalink
image_type_tezi_run.bbclass: let the generated artifacts under sstate…
Browse files Browse the repository at this point in the history
… control

The generated artifacts of tezirunimg should be controlled by sstate,
this patch mainly aims to achieve this and do some code cleaning up as
well.

The basic idea is to assemble the fitimage in ${WORKDIR}/tmp-fitimage,
and the kernel images, dtb files, and rootfs would be copied to this
directory before being assembled.

Also clean up some code as follows:
- Drop image_types inheriting, it's deprecated.
- Fix quite some incorrect dependencies.
- Drop duplicated items in TEZI_UBOOT_BINARIES.

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
  • Loading branch information
liuming50 committed Dec 7, 2018
1 parent 856dd9a commit c0892c5
Showing 1 changed file with 38 additions and 55 deletions.
93 changes: 38 additions & 55 deletions classes/image_type_tezi_run.bbclass
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
inherit image_types
python () {
if bb.utils.contains("IMAGE_FSTYPES", "tezirunimg", "1", "0", d) == "1":
bb.build.addtask('do_assemble_tezirunimg', 'do_image_complete', 'do_image_squashfs', d)
}

IMAGE_TYPES_MASKED += "tezirunimg"

do_image_tezirunimg[depends] += "tezi-run-metadata:do_deploy u-boot-mkimage-native:do_install p7zip-native:do_install"
TEZI_DISTRO_BOOT_SCRIPTS ??= "boot-sdp.scr boot.scr"
UBOOT_BINARY ??= "u-boot.${UBOOT_SUFFIX}"
TEZI_UBOOT_BINARY_EMMC ??= "${UBOOT_BINARY}"
TEZI_UBOOT_BINARY_RAWNAND ??= "${UBOOT_BINARY}"
TEZI_UBOOT_BINARY_RECOVERY ??= "${UBOOT_BINARY}"
TEZI_UBOOT_BINARIES ??= "${@' '.join(x for x in sorted(set([bb.utils.contains('TORADEX_FLASH_TYPE', 'emmc', d.getVar('TEZI_UBOOT_BINARY_EMMC', True), '', d), \
bb.utils.contains('TORADEX_FLASH_TYPE', 'rawnand', d.getVar('TEZI_UBOOT_BINARY_RAWNAND', True), '', d), \
d.getVar('TEZI_UBOOT_BINARY_RECOVERY', True)])))}"
TORADEX_FLASH_TYPE ??= "emmc"

def fitimg_get_size(d):
import subprocess
deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)

# Get size of FIT image...
args = ['du', '-kLc', os.path.join(deploydir, 'tezi.itb') ]
args = ['du', '-kLc', os.path.join(d.getVar('WORKDIR', True), 'tmp-tezirunimage', 'tezi.itb')]
output = subprocess.check_output(args)
return int(output.splitlines()[-1].split()[0])

def rootfs_tezi_run_emmc(d):
from collections import OrderedDict
uboot = d.getVar('TEZI_UBOOT_BINARY_EMMC', True)
d.appendVar('TEZI_UBOOT_BINARIES', uboot + ' ')
offset_bootrom = d.getVar('OFFSET_BOOTROM_PAYLOAD', True)
offset_spl = d.getVar('OFFSET_SPL_PAYLOAD', True)

Expand Down Expand Up @@ -67,7 +72,6 @@ def rootfs_tezi_run_rawnand(d):
from collections import OrderedDict
imagename = d.getVar('IMAGE_NAME', True)
uboot = d.getVar('TEZI_UBOOT_BINARY_RAWNAND', True)
d.appendVar('TEZI_UBOOT_BINARIES', uboot + ' ')

return [
OrderedDict({
Expand Down Expand Up @@ -150,74 +154,53 @@ def rootfs_tezi_run_create_json(d, flash_type, type_specific_name = False):
if type_specific_name:
imagefile = 'image-{0}.json'.format(flash_type)

with open(os.path.join(deploydir, imagefile), 'w') as outfile:
json.dump(data, outfile, indent=4)
d.appendVar('TEZI_IMAGE_FILES', imagefile + ' ')
bb.note("Toradex Easy Installer metadata file {0} written.".format(imagefile))
with open(os.path.join(d.getVar('WORKDIR', True), 'tmp-tezirunimage', imagefile), 'w') as outfile:
json.dump(data, outfile, indent=4)

python rootfs_tezi_run_json() {
if not bb.utils.contains("IMAGE_FSTYPES", "tezirunimg", True, False, d):
return

flash_types = d.getVar('TORADEX_FLASH_TYPE', True)
if flash_types is None:
bb.fatal("Toradex flash type not specified")

flash_types_list = flash_types.split()
for flash_type in flash_types_list:
rootfs_tezi_run_create_json(d, flash_type, len(flash_types_list) > 1)

# We end up having the same binary twice in TEZI_UBOOT_BINARIES in case
# the recovery mode binary is the same as the one which gets flashed.
# This is ok, zip will only add it once below.
d.appendVar('TEZI_UBOOT_BINARIES', d.getVar('TEZI_UBOOT_BINARY_RECOVERY', True) + ' ')
}

do_rootfs[depends] =+ "virtual/bootloader:do_deploy u-boot-distro-boot:do_deploy"

IMAGE_CMD_tezirunimg () {
bbnote "Create Toradex Easy Installer FIT image"
}

build_fitimage () {
# We have to execute this step after any image generation so we have
# squashfs, kernel etc all in DEPLOY_DIR_IMAGE
# We cannot work in IMGDEPLOYDIR since that folder only has the image
# files in it (not kernel etc...). We could probably make this a
# SSTATETASKS similar to how image.class makes do_image_complete...
mkimage -f ${DEPLOY_DIR_IMAGE}/tezi.its ${DEPLOY_DIR_IMAGE}/tezi.itb
}

build_deploytar () {
cd ${DEPLOY_DIR_IMAGE}

# mkdir fails if existing
if [ -e ${IMAGE_NAME} ]; then
rm -r ${IMAGE_NAME}/
fi

mkdir ${IMAGE_NAME}/
cp -L -R ${SPL_BINARY} ${TEZI_UBOOT_BINARIES} tezi.itb wrapup.sh ${TEZI_IMAGE_FILES} tezi.png ${TEZI_DISTRO_BOOT_SCRIPTS} recovery-linux.sh recovery-windows.bat recovery/ ${IMAGE_NAME}/

# zip does update if the file exist, explicitly delete before adding files to the archive
if [ -e ${IMAGE_NAME}.zip ]; then
rm ${IMAGE_NAME}.zip
# Copy kernel image
cp ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ${WORKDIR}/tmp-fitimage

# Copy device tree
for dtb in ${KERNEL_DEVICETREE}; do
cp ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-$dtb ${WORKDIR}/tmp-fitimage
done

# Copy rootfs image
if [ -e ${IMGDEPLOYDIR}/${IMAGE_BASENAME}-${MACHINE}.squashfs ]; then
cp ${IMGDEPLOYDIR}/${IMAGE_BASENAME}-${MACHINE}.squashfs ${WORKDIR}/tmp-fitimage
else
cp ${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.squashfs ${WORKDIR}/tmp-fitimage
fi

zip -r ${IMAGE_NAME}.zip ${IMAGE_NAME}/
rm -r ${IMAGE_NAME}/
cp ${DEPLOY_DIR_IMAGE}/tezi.its ${WORKDIR}/tmp-fitimage
mkimage -f ${WORKDIR}/tmp-fitimage/tezi.its ${WORKDIR}/tmp-tezirunimage/tezi.itb
}

python do_assemble_fitimage() {
if not bb.utils.contains("IMAGE_FSTYPES", "tezirunimg", True, False, d):
return
build_deploytar () {
(cd ${DEPLOY_DIR_IMAGE}; cp -L -R ${SPL_BINARY} ${TEZI_UBOOT_BINARIES} ${TEZI_DISTRO_BOOT_SCRIPTS} wrapup.sh tezi.png recovery-linux.sh recovery-windows.bat recovery/ ${WORKDIR}/tmp-tezirunimage)
zip -r ${IMGDEPLOYDIR}/${IMAGE_NAME}.zip ${WORKDIR}/tmp-tezirunimage
}

python do_assemble_tezirunimg() {
bb.build.exec_func('build_fitimage', d)
bb.build.exec_func('rootfs_tezi_run_json', d)
bb.build.exec_func('build_deploytar', d)
}

addtask do_assemble_fitimage after do_image_complete before do_build
do_assemble_fitimage[depends] = "tezi-run-metadata:do_deploy"

IMAGE_TYPEDEP_tezirunimg += "squashfs"
do_assemble_tezirunimg[dirs] = "${WORKDIR}/tmp-fitimage ${WORKDIR}/tmp-tezirunimage"
do_assemble_tezirunimg[cleandirs] = "${WORKDIR}/tmp-fitimage ${WORKDIR}/tmp-tezirunimage"
do_assemble_tezirunimg[depends] = "virtual/bootloader:do_deploy u-boot-distro-boot:do_deploy virtual/kernel:do_deploy \
tezi-run-metadata:do_deploy u-boot-mkimage-native:do_populate_sysroot \
p7zip-native:do_populate_sysroot zip-native:do_populate_sysroot \
"

0 comments on commit c0892c5

Please sign in to comment.