partition_table: Support registering custom subtypes

This commit is contained in:
Shubham Kulkarni 2022-06-21 16:19:26 +05:30 committed by BOT
parent 3e4c0a40c2
commit b6d69840e8
7 changed files with 107 additions and 16 deletions

View File

@ -36,12 +36,22 @@ else()
set(partition_secure_opt "")
endif()
idf_build_get_property(extra_subtypes EXTRA_PARTITION_SUBTYPES)
if(extra_subtypes)
# Remove all white spaces from the string
string(REPLACE " " "" extra_subtypes "${extra_subtypes}")
set(extra_partition_subtypes --extra-partition-subtypes ${extra_subtypes})
else()
set(extra_partition_subtypes "")
endif()
idf_build_get_property(build_dir BUILD_DIR)
idf_build_get_property(python PYTHON)
idf_build_get_property(extra_subtypes EXTRA_PARTITION_SUBTYPES)
set(gen_partition_table "${python}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py" "-q"
"--offset" "${PARTITION_TABLE_OFFSET}" "${md5_opt}" "${flashsize_opt}"
"${partition_secure_opt}")
"${partition_secure_opt}" ${extra_partition_subtypes} "--")
set(partition_table_display
COMMAND ${CMAKE_COMMAND} -E echo "Partition table binary generated. Contents:"
@ -56,8 +66,20 @@ add_custom_command(OUTPUT "${build_dir}/partition_table/${unsigned_partition_bin
DEPENDS ${partition_csv} "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py"
VERBATIM)
if(extra_subtypes)
set(extra_subtypes_h "${build_dir}/config/extra_partition_subtypes.inc")
add_custom_command(OUTPUT ${extra_subtypes_h}
COMMAND ${python} ${CMAKE_CURRENT_SOURCE_DIR}/gen_extra_subtypes_inc.py ${extra_subtypes_h} ${extra_subtypes}
COMMENT "Generating extra partition subtype header file"
)
add_custom_target(extra_subtype_hdr DEPENDS ${extra_subtypes_h})
add_dependencies(${COMPONENT_LIB} extra_subtype_hdr)
endif()
add_custom_target(partition_table_bin DEPENDS "${build_dir}/partition_table/${unsigned_partition_bin}"
"${build_dir}/partition_table/${final_partition_bin}")
"${build_dir}/partition_table/${final_partition_bin}"
)
if(EXISTS ${partition_csv})
add_custom_target(partition-table

View File

@ -92,6 +92,26 @@ def get_alignment_for_type(ptype):
return ALIGNMENT.get(ptype, ALIGNMENT[DATA_TYPE])
def get_partition_type(ptype):
if ptype == 'app':
return APP_TYPE
if ptype == 'data':
return DATA_TYPE
raise InputError('Invalid partition type')
def add_extra_subtypes(csv):
for line_no in csv:
try:
fields = [line.strip() for line in line_no.split(',')]
for subtype, subtype_values in SUBTYPES.items():
if (int(fields[2], 16) in subtype_values.values() and subtype == get_partition_type(fields[0])):
raise ValueError('Found duplicate value in partition subtype')
SUBTYPES[TYPES[fields[0]]][fields[1]] = int(fields[2], 16)
except InputError as err:
raise InputError('Error parsing custom subtypes: %s' % err)
quiet = False
md5sum = True
secure = False
@ -145,7 +165,7 @@ class PartitionTable(list):
try:
res.append(PartitionDefinition.from_csv(line, line_no + 1))
except InputError as err:
raise InputError('Error at line %d: %s' % (line_no + 1, err))
raise InputError('Error at line %d: %s\nPlease check extra_partition_subtypes.inc file in build/config directory' % (line_no + 1, err))
except Exception:
critical('Unexpected error parsing CSV line %d: %s' % (line_no + 1, line))
raise
@ -506,6 +526,7 @@ def main():
parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true')
parser.add_argument('--offset', '-o', help='Set offset partition table', default='0x8000')
parser.add_argument('--secure', help='Require app partitions to be suitable for secure boot', action='store_true')
parser.add_argument('--extra-partition-subtypes', help='Extra partition subtype entries', nargs='*')
parser.add_argument('input', help='Path to CSV or binary file to parse.', type=argparse.FileType('rb'))
parser.add_argument('output', help='Path to output converted binary or CSV file. Will use stdout if omitted.',
nargs='?', default='-')
@ -516,6 +537,9 @@ def main():
md5sum = not args.disable_md5sum
secure = args.secure
offset_part_table = int(args.offset, 0)
if args.extra_partition_subtypes:
add_extra_subtypes(args.extra_partition_subtypes)
table, input_is_binary = PartitionTable.from_file(args.input)
if not args.no_verify:

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import argparse
def gen_header_file(path: str, subtypes: str) -> None:
HDR_MESSAGE = '/* Automatically generated file. DO NOT EDIT. */\n\n'
PARTTOOL_USAGE = 'If you want to use parttool.py manually, please use the following as an extra argument:'
with open(path, 'w') as f:
f.write(HDR_MESSAGE)
if subtypes:
f.write('/*\n\t' + PARTTOOL_USAGE + '\n\t')
f.write('--extra-partition-subtypes ')
for line_no in subtypes:
f.write(line_no + ' ')
f.write('\n*/\n\n')
f.write('#pragma once\n\n')
for line_no in subtypes:
try:
fields = [line.strip() for line in line_no.split(',')]
fields[0] = fields[0].strip()
fields[1] = fields[1].strip()
fields[2] = fields[2].strip()
f.write('ESP_PARTITION_SUBTYPE_%s_%s = %s,\n' % (fields[0].upper(), fields[1].upper(), fields[2]))
except ValueError as err:
raise ValueError('Error parsing custom subtypes: %s' % err)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='ESP32 extra partitions utility')
parser.add_argument('config_dir', help='Path to config directory')
parser.add_argument('extra_partition_subtypes', help='Extra partition subtype entries', nargs='*')
args = parser.parse_args()
gen_header_file(args.config_dir, args.extra_partition_subtypes)

View File

@ -3,19 +3,8 @@
# parttool is used to perform partition level operations - reading,
# writing, erasing and getting info about the partition.
#
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
from __future__ import division, print_function
import argparse
@ -281,6 +270,7 @@ def main():
print_partition_info_subparser.add_argument('--info', help='type of partition information to get',
choices=['name', 'type', 'subtype', 'offset', 'size', 'encrypted'], default=['offset', 'size'], nargs='+')
print_partition_info_subparser.add_argument('--part_list', help='Get a list of partitions suitable for a given type', action='store_true')
print_partition_info_subparser.add_argument('--extra-partition-subtypes', help='Extra partition subtype entries', nargs='*')
args = parser.parse_args()
quiet = args.quiet
@ -331,6 +321,9 @@ def main():
if args.esptool_erase_args:
target_args['esptool_erase_args'] = args.esptool_erase_args
if args.extra_partition_subtypes:
gen.add_extra_subtypes(args.extra_partition_subtypes)
target = ParttoolTarget(**target_args)
# Create the operation table and execute the operation

View File

@ -39,12 +39,22 @@ endif()
function(partition_table_get_partition_info result get_part_info_args part_info)
idf_build_get_property(python PYTHON)
idf_build_get_property(idf_path IDF_PATH)
idf_build_get_property(extra_subtypes EXTRA_PARTITION_SUBTYPES)
if(extra_subtypes)
# Remove all white spaces from the string
string(REPLACE " " "" extra_subtypes "${extra_subtypes}")
set(extra_partition_subtypes --extra-partition-subtypes ${extra_subtypes})
else()
set(extra_partition_subtypes "")
endif()
separate_arguments(get_part_info_args)
execute_process(COMMAND ${python}
${idf_path}/components/partition_table/parttool.py -q
--partition-table-offset ${PARTITION_TABLE_OFFSET}
--partition-table-file ${PARTITION_CSV_PATH}
get_partition_info ${get_part_info_args} --info ${part_info}
${extra_partition_subtypes}
OUTPUT_VARIABLE info
RESULT_VARIABLE exit_code
OUTPUT_STRIP_TRAILING_WHITESPACE)

View File

@ -84,6 +84,10 @@ typedef enum {
ESP_PARTITION_SUBTYPE_DATA_FAT = 0x81, //!< FAT partition
ESP_PARTITION_SUBTYPE_DATA_SPIFFS = 0x82, //!< SPIFFS partition
#if __has_include("extra_partition_subtypes.inc")
#include "extra_partition_subtypes.inc"
#endif
ESP_PARTITION_SUBTYPE_ANY = 0xff, //!< Used to search for partitions with any subtype
} esp_partition_subtype_t;

View File

@ -20,6 +20,7 @@ components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py
components/partition_table/check_sizes.py
components/partition_table/gen_empty_partition.py
components/partition_table/gen_esp32part.py
components/partition_table/gen_extra_subtypes_inc.py
components/partition_table/parttool.py
components/partition_table/test_gen_esp32part_host/check_sizes_test.py
components/partition_table/test_gen_esp32part_host/gen_esp32part_tests.py