From 9977dbe8e2a2016ee1d0637373b9ba6963405ccc Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Tue, 13 Sep 2022 14:07:14 +0530 Subject: [PATCH 1/2] parttool: fix extra_partition_subtypes attribute parsing --- components/partition_table/gen_extra_subtypes_inc.py | 2 +- components/partition_table/parttool.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/partition_table/gen_extra_subtypes_inc.py b/components/partition_table/gen_extra_subtypes_inc.py index 1bc62734fb..45e4751a47 100755 --- a/components/partition_table/gen_extra_subtypes_inc.py +++ b/components/partition_table/gen_extra_subtypes_inc.py @@ -14,7 +14,7 @@ def gen_header_file(path: str, subtypes: str) -> None: f.write('/*\n\t' + PARTTOOL_USAGE + '\n\t') f.write('--extra-partition-subtypes ') for line_no in subtypes: - f.write(line_no + ' ') + f.write(f'"{line_no}" ') f.write('\n*/\n\n') f.write('#pragma once\n\n') for line_no in subtypes: diff --git a/components/partition_table/parttool.py b/components/partition_table/parttool.py index 847d4bc0a9..3c30d850cc 100755 --- a/components/partition_table/parttool.py +++ b/components/partition_table/parttool.py @@ -252,6 +252,7 @@ def main(): using the same fallback logic as the IDF bootloader', action='store_true') partition_selection_parser.add_argument('--partition-subtype', '-s', help='subtype of the partition') + partition_selection_parser.add_argument('--extra-partition-subtypes', help='Extra partition subtype entries', nargs='*') subparsers = parser.add_subparsers(dest='operation', help='run parttool -h for additional help') @@ -270,7 +271,6 @@ 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 From dd57ba77a3c4f206a1437f76b9acb4e88681dd1c Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Thu, 15 Sep 2022 19:03:11 +0530 Subject: [PATCH 2/2] parttool: added tests to check the external interface (parsing) of the parttool commands The existing tests detect errors in the internal interface (eg. parttool read-write functions) and did not check for any possible breakages in the args parsing of the parttool commands. --- .../storage/parttool/partitions_example.csv | 1 + .../parttool/pytest_parttool_example.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/examples/storage/parttool/partitions_example.csv b/examples/storage/parttool/partitions_example.csv index d39fab4bb2..6c09529c47 100644 --- a/examples/storage/parttool/partitions_example.csv +++ b/examples/storage/parttool/partitions_example.csv @@ -3,4 +3,5 @@ nvs, data, nvs, 0x9000, 0x6000, phy_init, data, phy, 0xf000, 0x1000, factory, app, factory, 0x10000, 1M, +custom, data, nvs, , 0x1000, storage, data, spiffs, , 0x10000, diff --git a/examples/storage/parttool/pytest_parttool_example.py b/examples/storage/parttool/pytest_parttool_example.py index a53ba47103..9f984cfc1a 100644 --- a/examples/storage/parttool/pytest_parttool_example.py +++ b/examples/storage/parttool/pytest_parttool_example.py @@ -26,3 +26,22 @@ def test_examples_parttool(dut: Dut) -> None: script_path = os.path.join(idf_path, 'examples', 'storage', 'parttool', 'parttool_example.py') binary_path = os.path.join(dut.app.binary_path, 'parttool.bin') subprocess.check_call([sys.executable, script_path, '--binary', binary_path, '--port', dut.serial.port]) + + # following tests check the external interface (parsing) of the parttool commands + with open('custom.bin', 'wb') as f: + f.write(b'0' * 1024 * 4) + + PARTTOOL = os.path.join(idf_path, 'components', 'partition_table', 'parttool.py') + BASE_CMD = [sys.executable, PARTTOOL, '--port', dut.serial.port] + + cmds = ['read_partition --partition-type=data --partition-subtype=nvs --output custom1.bin', + 'erase_partition --partition-name=custom', + 'write_partition --partition-name=custom --input custom.bin', + 'get_partition_info --partition-boot-default --info size'] + + for cmd in cmds: + subprocess.check_call(BASE_CMD + cmd.split()) + + clean_files = ['custom.bin', 'custom1.bin'] + for clean_file in clean_files: + os.unlink(clean_file)