From 4b050e11cf33145e1520d0c0197008828e9947c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Fri, 27 May 2022 15:29:21 +0200 Subject: [PATCH] [core] Add dynamic FAL_PART_TABLE generation --- arduino/libretuya/port/flashdb/fal_cfg.h | 18 +++++++++--------- builder/main.py | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/arduino/libretuya/port/flashdb/fal_cfg.h b/arduino/libretuya/port/flashdb/fal_cfg.h index a0feee3..7cc3102 100644 --- a/arduino/libretuya/port/flashdb/fal_cfg.h +++ b/arduino/libretuya/port/flashdb/fal_cfg.h @@ -10,16 +10,16 @@ extern const struct fal_flash_dev flash0; #define FAL_FLASH_DEV_TABLE \ { &flash0, } +#define FAL_DEV_NAME_MAX 16 // no need for 24 chars (default) + // Partition table #define FAL_PART_HAS_TABLE_CFG -#define FAL_PART_TABLE \ +#define FAL_PART_TABLE_ITEM(part_lower, part_upper) \ { \ - { \ - .magic_word = FAL_PART_MAGIC_WORD, \ - .name = "userdata", \ - .flash_name = FAL_FLASH_DEV_NAME, \ - .offset = FLASH_USERDATA_OFFSET, \ - .len = 0x4000, \ - }, \ - } + .magic_word = FAL_PART_MAGIC_WORD, /* magic word */ \ + .name = #part_lower, /* lowercase name as string */ \ + .flash_name = FAL_FLASH_DEV_NAME, /* flash device name */ \ + .offset = FLASH_##part_upper##_OFFSET, /* partition offset macro as uppercase string */ \ + .len = FLASH_##part_upper##_LENGTH, /* partition length macro as uppercase string */ \ + }, diff --git a/builder/main.py b/builder/main.py index e95023e..639cb35 100644 --- a/builder/main.py +++ b/builder/main.py @@ -37,13 +37,16 @@ flash_layout: dict = board.get("flash") if flash_layout: defines = {} flash_size = 0 + fal_items = "" for name, layout in flash_layout.items(): name = name.upper() (offset, _, length) = layout.partition("+") defines[f"FLASH_{name}_OFFSET"] = offset defines[f"FLASH_{name}_LENGTH"] = length + fal_items += f"FAL_PART_TABLE_ITEM({name.lower()}, {name})" flash_size = max(flash_size, int(offset, 16) + int(length, 16)) defines["FLASH_LENGTH"] = flash_size + defines["FAL_PART_TABLE"] = "{" + fal_items + "}" env.Append(CPPDEFINES=defines.items()) env.Replace(**defines)