From 5df595134e729bc5c44ff1c0f4332d16e42873e0 Mon Sep 17 00:00:00 2001 From: Lionel VITTE Date: Tue, 16 Nov 2021 11:38:03 +0100 Subject: [PATCH] MACHINE: set partition configuration specific to fstype - Allow specific partition image configuration between 'ext4' and 'ubifs'. - In case ubifs created is larger than max-leb-cnt allocated, mkfs.ubi raise an error that make bitbake exit on error: add test to avoid this unexpected exit. Change-Id: Ib386e703cfb1d0434ea17c279abb31f705514019 Signed-off-by: Romuald JEANNE --- classes/flashlayout-stm32mp.bbclass | 177 ++++++------- classes/image_types-stubi.bbclass | 242 ++++++++++-------- classes/st-partitions-image.bbclass | 115 ++++----- .../include/st-machine-common-stm32mp.inc | 155 +++++++---- ...machine-flashlayout-extensible-stm32mp.inc | 2 +- .../st-machine-flashlayout-stm32mp.inc | 27 +- .../sdcard-raw-tools/sdcard-raw-tools.bb | 12 +- 7 files changed, 404 insertions(+), 326 deletions(-) diff --git a/classes/flashlayout-stm32mp.bbclass b/classes/flashlayout-stm32mp.bbclass index 95008be..b2cb214 100644 --- a/classes/flashlayout-stm32mp.bbclass +++ b/classes/flashlayout-stm32mp.bbclass @@ -169,36 +169,34 @@ python __anonymous () { initramfs = d.getVar('INITRAMFS_IMAGE') or "" # Init INITRD image if any initrd = d.getVar('INITRD_IMAGE_ALL') or d.getVar('INITRD_IMAGE') or "" - # Init partition list from PARTITIONS_CONFIG + # Init partition list from PARTITIONS_IMAGES image_partitions = [] # Append image_partitions list with all configured partition images: - partitionsconfigflags = d.getVarFlags('PARTITIONS_CONFIG') + partitionsconfigflags = d.getVarFlags('PARTITIONS_IMAGES') # The "doc" varflag is special, we don't want to see it here partitionsconfigflags.pop('doc', None) - partitionsconfig = (d.getVar('PARTITIONS_CONFIG') or "").split() + partitionsconfig = (d.getVar('PARTITIONS_IMAGES') or "").split() if len(partitionsconfig) > 0: for config in partitionsconfig: for f, v in partitionsconfigflags.items(): if config == f: items = v.split(',') - # Make sure about PARTITIONS_CONFIG contents - if items[0] and len(items) > 5: - bb.fatal('[PARTITIONS_CONFIG] Only image,label,mountpoint,size,type can be specified!') + # Make sure about PARTITIONS_IMAGES contents + if len(items) > 0 and len(items) != 5: + bb.fatal('[PARTITIONS_IMAGES] Only image,label,mountpoint,size,type can be specified!') # Make sure that we're dealing with partition image and not rootfs image - if len(items) > 2 and items[2]: + if items[2] != '': # Mount point is available, so we're dealing with partition image # Append image to image_partitions list image_partitions.append(d.expand(items[0])) break - # We need to clearly identify ROOTFS build, not InitRAMFS/initRD one (if any), not partition one either if current_image_name not in image_partitions and current_image_name != initramfs and current_image_name not in initrd: # We add the flashlayout file creation task just after the do_image_complete for ROOTFS build bb.build.addtask('do_create_flashlayout_config', 'do_build', 'do_image_complete', d) - # We add also the function that feeds the FLASHLAYOUT_PARTITION_* vars from PARTITIONS_CONFIG + # We add also the function that feeds the FLASHLAYOUT_PARTITION_* vars d.appendVarFlag('do_create_flashlayout_config', 'prefuncs', ' flashlayout_partition_config') - d.appendVarFlag('do_create_flashlayout_config', 'prefuncs', ' flashlayout_partition_image_config') } def expand_var(var, bootscheme, config, partition, d): @@ -342,9 +340,10 @@ def get_offset(new_offset, copy, current_device, bootscheme, config, partition, device_alias = d.getVar('DEVICE_%s' % current_device) or "" # Set offset offset = expand_var('FLASHLAYOUT_PARTITION_OFFSET', bootscheme, config, partition, d) + bb.debug(1, '>>> Selected FLASHLAYOUT_PARTITION_OFFSET: %s' % offset) # Set max offset max_offset = d.getVar('DEVICE_MAX_OFFSET_%s' % device_alias) or "none" - bb.debug(1, '>>> Selected FLASHLAYOUT_PARTITION_OFFSET: %s' % offset) + bb.debug(1, '>>> Selected DEVICE_MAX_OFFSET: %s' % max_offset) if offset == 'none': if new_offset == 'none': bb.debug(1, '>>> No %s partition offset configured (%s device) for %s label for %s bootscheme, so default to default origin device one.' % (partition, current_device, config, bootscheme)) @@ -570,17 +569,6 @@ python do_create_flashlayout_config() { partition_prevdevice = partition_device # Get partition offset partition_offset, partition_nextoffset, partition_maxoffset = get_offset(partition_nextoffset, partition_copy, partition_device, bootscheme, config, partition, d) - - # Check if the size will exceed the mass storage - if partition_maxoffset != "none" : - bb.warn('>>> Cannot generate tsv for %s %s %s %s. The partition end offset %s is higher than max offset %s.' % (partition_device, bootscheme, config, partition, partition_nextoffset, partition_maxoffset)) - # No need to create/keep the tsv because flashlayout indicates the - # computed size exceeds the size of the device. So delete the tsv - fl_file.close() - if os.path.exists(flashlayout_file): - os.remove(flashlayout_file) - break - # Get binary name partition_bin2load = get_binaryname(labeltype, partition_device, bootscheme, config, partition, d) # Be verbose in log file @@ -593,12 +581,38 @@ python do_create_flashlayout_config() { bb.debug(1, '>>> FLASHLAYOUT_PARTITION_OFFSET: %s' % partition_offset) bb.debug(1, '>>> FLASHLAYOUT_PARTITION_BIN2LOAD: %s' % partition_bin2load) bb.debug(1, '>>> done') - # Make sure binary is available in DEPLOY_DIR_IMAGE folder + # Check if the size will exceed the mass storage + if partition_maxoffset != "none" : + bb.warn('>>> Cannot generate %s file: the end offset (%s) for %s partition exceeds the max offset (%s) for %s device.' % (os.path.basename(flashlayout_file), partition_nextoffset, partition, partition_maxoffset, partition_device)) + # Cleanup on-going tsv file + fl_file.close() + if os.path.exists(flashlayout_file): + os.remove(flashlayout_file) + break + # Check if binary is available in deploy folder if partition_bin2load != 'none': - if not os.path.isfile(os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), partition_bin2load)): - # Specific exception for rootfs binary (not yet deployed) - if not os.path.isfile(os.path.join(d.getVar('IMGDEPLOYDIR'), partition_bin2load)): - bb.fatal('Missing %s binary file in deploy folder' % partition_bin2load) + bin2load_fullpath = os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), partition_bin2load) + if not os.path.isfile(bin2load_fullpath): + # Specific case for rootfs binary (not yet deployed) + bin2load_fullpath = os.path.join(d.getVar('IMGDEPLOYDIR'), partition_bin2load) + if not os.path.isfile(bin2load_fullpath): + bb.warn('>>> Cannot generate %s file: the %s binary for %s partition is missing in deploy folder' % (os.path.basename(flashlayout_file), partition_bin2load, partition)) + # Cleanup on-going tsv file + fl_file.close() + if os.path.exists(flashlayout_file): + os.remove(flashlayout_file) + break + # Check if the bin2load size will exceed the partition size + if partition_nextoffset != 'none': + bin2load_size = os.path.getsize(bin2load_fullpath) + partition_size = int(partition_nextoffset, 16) - int(partition_offset, 16) + if bin2load_size > partition_size: + bb.warn('>>> Cannot generate %s file: the %s binary size (%s) for %s partition exceeds the partition size (%s).' % (os.path.basename(flashlayout_file), partition_bin2load, bin2load_size, partition, partition_size)) + # Cleanup on-going tsv file + fl_file.close() + if os.path.exists(flashlayout_file): + os.remove(flashlayout_file) + break # Get the supported labels for current storage device partition_device_alias = d.getVar('DEVICE_%s' % partition_device) or "" partition_type_supported_labels = d.getVar('DEVICE_BOARD_ENABLE_%s' % partition_device_alias) or "none" @@ -665,18 +679,40 @@ python do_create_flashlayout_config_setscene () { } addtask do_create_flashlayout_config_setscene +def partImage2partConfig(config, fstype, d): + """ + Convert PARTTIONS_IMAGES['config'] setting format to format expected to feed + PARTITIONS_CONFIG[xxx]. + Manage update respect to 'fstype' provided and apply the rootfs + namming or standard partition image one. + FROM: ,,,, + TO : ,,, + """ + items = d.getVarFlag('PARTITIONS_IMAGES', config).split(',') or "" + if len(items) != 5: + bb.fatal('Wrong settings for PARTTIONS_IMAGES[%s] : %s' % (config, items)) + if items[2] != '': + bin_name = items[0] + '-${DISTRO}-${MACHINE}' + '.' + fstype + else: + bin_name = items[0] + '-${MACHINE}' + '.' + fstype + # Set string for PARTITIONS_CONFIG item: ,,, + part_format = bin_name + ',' + items[1] + ',' + items[3] + ',' + items[4] + return part_format + python flashlayout_partition_config() { """ Set the different flashlayout partition vars for the configure partition images. - Based on both PARTITIONS_BOOTLOADER_CONFIG and PARTITIONS_OPTEE_CONFIG feed: - FLASHLAYOUT_PARTITION_ENABLE__ - FLASHLAYOUT_PARTITION_SIZE__ - FLASHLAYOUT_PARTITION_COPY__ - FLASHLAYOUT_PARTITION_TYPE__ + Based on PARTITIONS_CONFIG, PARTITIONS_BOOTLOADER_CONFIG and PARTITIONS_OPTEE_CONFIG + feed FLASHLAYOUT_PARTITION_ vars for each 'config' and 'label': + FLASHLAYOUT_PARTITION_ENABLE__