diff --git a/classes/flashlayout-stm32mp.bbclass b/classes/flashlayout-stm32mp.bbclass index 4c1b9f9..646087c 100644 --- a/classes/flashlayout-stm32mp.bbclass +++ b/classes/flashlayout-stm32mp.bbclass @@ -104,6 +104,8 @@ FLASHLAYOUT_BASENAME ??= "FlashLayout" FLASHLAYOUT_SUFFIX ??= "tsv" # Configure flashlayout file generation for stm32wrapper4dbg ENABLE_FLASHLAYOUT_CONFIG_WRAPPER4DBG ??= "0" +# Configure flashlayout file generation with multiple binary copy within partition +ENABLE_FLASHLAYOUT_PARTITION_BINCOPY ??= "0" # Configure partition file extension PARTITION_SUFFIX ??= ".ext4" @@ -133,6 +135,8 @@ FLASHLAYOUT_PARTITION_OFFSET ??= "" FLASHLAYOUT_PARTITION_BIN2LOAD ??= "" FLASHLAYOUT_PARTITION_SIZE ??= "" FLASHLAYOUT_PARTITION_REPLACE_PATTERNS ??= "" +# Init single partition creation +FLASHLAYOUT_PARTITION_DUPLICATION ??= "1" # The STM32CubeProgrammer supported ID range is: # 0x00 to 0xFF @@ -150,6 +154,9 @@ FLASHLAYOUT_PARTITION_ID_LIMIT_BINARY ??= "0x0F" FLASHLAYOUT_PARTITION_ID_START_OTHERS ??= "0x10" FLASHLAYOUT_PARTITION_ID_LIMIT_OTHERS ??= "0xF0" +# Init default config for empty or used partition for STM32CubeProgrammer +FLASHLAYOUT_PARTITION_ENABLE_PROGRAMM_EMPTY ??= "PED" + python __anonymous () { # ----------------------------------------------------------------------------- # Make sure to add the flashlayout file creation after ROOTFS build @@ -229,6 +236,20 @@ def expand_var(var, bootscheme, config, partition, d): # Return expanded and/or overriden var value return expanded_var +def get_label_list(d, label, duplicate='1'): + """ + Configure the label name list according to the proposed duplicate value + """ + list = [] + if int(duplicate) > 1: + for i in range(1, int(duplicate) + 1): + list.append(label + str(i)) + bb.debug(1,">>> Partition duplication configure for %s with new sub-list: %s" % (label, list)) + else: + list.append(label) + # Return the label list + return list + def get_device(bootscheme, config, partition, d): """ This function returns the device configured from FLASHLAYOUT_PARTITION_DEVICE for @@ -534,96 +555,107 @@ python do_create_flashlayout_config() { partition_nextoffset = "none" # Init partition previous device to 'none' partition_prevdevice = "none" - for partition in partitions.split(): - bb.debug(1, '*** Loop for partition: %s' % partition) - # Init partition settings - partition_enable = expand_var('FLASHLAYOUT_PARTITION_ENABLE', bootscheme, config, partition, d) - partition_name = partition - partition_type = expand_var('FLASHLAYOUT_PARTITION_TYPE', bootscheme, config, partition, d) - partition_id = expand_var('FLASHLAYOUT_PARTITION_ID', bootscheme, config, partition, d) - if partition_id == "none": - # Compute partition_id - if partition_type == 'Binary': - # Make sure we're not getting wrong partition_id - if partition_id_bin > partition_id_binmax: - bb.fatal('Partition ID exceed %s limit for %s type: FLASHLAYOUT_PARTITION_ID = %s (bootscheme: %s, config: %s, partition: %s)' % (d.getVar("FLASHLAYOUT_PARTITION_ID_LIMIT_BINARY"), partition_type, partition_id, bootscheme, config, partition)) - partition_id = '0x{0:0{1}X}'.format(partition_id_bin, 2) - partition_id_bin = partition_id_bin + 1 - else: - # Make sure we're not getting wrong partition_id - if partition_id_oth > partition_id_othmax: - bb.fatal('Partition ID exceed %s limit for %s type: FLASHLAYOUT_PARTITION_ID = %s (bootscheme: %s, config: %s, partition: %s)' % (d.getVar("FLASHLAYOUT_PARTITION_ID_LIMIT_OTHERS"), partition_type, partition_id, bootscheme, config, partition)) - partition_id = '0x{0:0{1}X}'.format(partition_id_oth, 2) - partition_id_oth = partition_id_oth + 1 - partition_copy = expand_var('FLASHLAYOUT_PARTITION_COPY', bootscheme, config, partition, d) - if not partition_copy.isdigit(): - bb.fatal('Wrong configuration for FLASHLAYOUT_PARTITION_COPY: %s (bootscheme: %s, config: %s, partition: %s)' % (partition_copy, bootscheme, config, partition)) - # Update partition type if needed - if partition_copy != "1": - partition_type += '(' + partition_copy + ')' - partition_device = get_device(bootscheme, config, partition, d) - # Reset partition_nextoffset to 'none' in case partition device has changed - if partition_device != partition_prevdevice: - partition_nextoffset = "none" - # Save partition current device to previous one for next loop - 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) - # Get binary name - partition_bin2load = get_binaryname(labeltype, partition_device, bootscheme, config, partition, d) - # Be verbose in log file - bb.debug(1, '>>> Layout inputs: %s' % fl_file.name) - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_ENABLE: %s' % partition_enable) - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_ID: %s' % partition_id) - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_LABEL: %s' % partition_name) - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_TYPE: %s' % partition_type) - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_DEVICE: %s' % partition_device) - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_OFFSET: %s' % partition_offset) - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_BIN2LOAD: %s' % partition_bin2load) - bb.debug(1, '>>> done') - # 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 + for part in partitions.split(): + bb.debug(1, '*** Loop for partition: %s' % part) + # Init break and clean file switch + break_and_clean_file = '0' + # Init partition duplication count + partition_duplication = expand_var('FLASHLAYOUT_PARTITION_DUPLICATION', bootscheme, config, part, d) + if not partition_duplication.isdigit(): + bb.fatal('Wrong configuration for FLASHLAYOUT_PARTITION_DUPLICATION: %s (bootscheme: %s, config: %s, partition: %s)' % (partition_duplication, bootscheme, config, part)) + + for partition in get_label_list(d, part, partition_duplication): + bb.debug(1, '>>> Set partition label name to : %s' % partition) + # Init partition settings + partition_enable = expand_var('FLASHLAYOUT_PARTITION_ENABLE', bootscheme, config, partition, d) + partition_name = partition + partition_type = expand_var('FLASHLAYOUT_PARTITION_TYPE', bootscheme, config, partition, d) + partition_id = expand_var('FLASHLAYOUT_PARTITION_ID', bootscheme, config, partition, d) + if partition_id == "none": + # Compute partition_id + if partition_type == 'Binary' or partition_type == 'FIP': + # Make sure we're not getting wrong partition_id + if partition_id_bin > partition_id_binmax: + bb.fatal('Partition ID exceed %s limit for %s type: FLASHLAYOUT_PARTITION_ID = %s (bootscheme: %s, config: %s, partition: %s)' % (d.getVar("FLASHLAYOUT_PARTITION_ID_LIMIT_BINARY"), partition_type, partition_id, bootscheme, config, partition)) + partition_id = '0x{0:0{1}X}'.format(partition_id_bin, 2) + partition_id_bin = partition_id_bin + 1 + else: + # Make sure we're not getting wrong partition_id + if partition_id_oth > partition_id_othmax: + bb.fatal('Partition ID exceed %s limit for %s type: FLASHLAYOUT_PARTITION_ID = %s (bootscheme: %s, config: %s, partition: %s)' % (d.getVar("FLASHLAYOUT_PARTITION_ID_LIMIT_OTHERS"), partition_type, partition_id, bootscheme, config, partition)) + partition_id = '0x{0:0{1}X}'.format(partition_id_oth, 2) + partition_id_oth = partition_id_oth + 1 + partition_copy = expand_var('FLASHLAYOUT_PARTITION_COPY', bootscheme, config, partition, d) + if not partition_copy.isdigit(): + bb.fatal('Wrong configuration for FLASHLAYOUT_PARTITION_COPY: %s (bootscheme: %s, config: %s, partition: %s)' % (partition_copy, bootscheme, config, partition)) + # Update partition type if needed + if int(partition_copy) > 1: + partition_type += '(' + partition_copy + ')' + partition_device = get_device(bootscheme, config, partition, d) + # Reset partition_nextoffset to 'none' in case partition device has changed + if partition_device != partition_prevdevice: + partition_nextoffset = "none" + # Save partition current device to previous one for next loop + 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) + # Get binary name + partition_bin2load = get_binaryname(labeltype, partition_device, bootscheme, config, partition, d) + # Be verbose in log file + bb.debug(1, '>>> Layout inputs: %s' % fl_file.name) + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_ENABLE: %s' % partition_enable) + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_ID: %s' % partition_id) + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_LABEL: %s' % partition_name) + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_TYPE: %s' % partition_type) + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_DEVICE: %s' % partition_device) + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_OFFSET: %s' % partition_offset) + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_BIN2LOAD: %s' % partition_bin2load) + bb.debug(1, '>>> done') + # 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 + break_and_clean_file = '1' + break + # Check if binary is available in deploy folder + if partition_bin2load != 'none': + 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 + break_and_clean_file = '1' + 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 + break_and_clean_file = '1' + 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" + # Check if partition type is supported for the current label + if partition_device != 'none' and current_label not in partition_type_supported_labels.split(): + bb.debug(1, '>>> FLASHLAYOUT_PARTITION_DEVICE (%s, alias %s) is not supported for current label (%s): partition %s not appended in flashlayout file' % (partition_device, partition_device_alias, current_label, partition_name)) + bb.debug(1, '>>> DEVICE_BOARD_ENABLE:%s: %s' % (partition_device_alias, partition_type_supported_labels)) + continue + # Write to flashlayout file the partition configuration + fl_file.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\n' % + (partition_enable, partition_id, partition_name, partition_type, partition_device, partition_offset, partition_bin2load)) + + # Abort on-going flashlayout file + if break_and_clean_file == "1": + break_and_clean_file = '0' 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': - 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" - # Check if partition type is supported for the current label - if partition_device != 'none' and current_label not in partition_type_supported_labels.split(): - bb.debug(1, '>>> FLASHLAYOUT_PARTITION_DEVICE (%s, alias %s) is not supported for current label (%s): partition %s not appended in flashlayout file' % (partition_device, partition_device_alias, current_label, partition_name)) - bb.debug(1, '>>> DEVICE_BOARD_ENABLE:%s: %s' % (partition_device_alias, partition_type_supported_labels)) - continue - # Write to flashlayout file the partition configuration - fl_file.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\n' % - (partition_enable, partition_id, partition_name, partition_type, partition_device, partition_offset, partition_bin2load)) except OSError: bb.fatal('Unable to open %s' % (fl_file)) @@ -703,16 +735,17 @@ python flashlayout_partition_config() { """ Set the different flashlayout partition vars for the configure partition images. - Based on PARTITIONS_CONFIG, PARTITIONS_BOOTLOADER_CONFIG and PARTITIONS_OPTEE_CONFIG + Based on PARTITIONS_CONFIG and PARTITIONS_BOOTLOADER_CONFIG feed FLASHLAYOUT_PARTITION_ vars for each 'config' and 'label': FLASHLAYOUT_PARTITION_ENABLE::