From 272b03325303f6a949087a2285d293a93d166e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 19 Jun 2022 14:18:13 +0200 Subject: [PATCH] [core] Provide entire flash as "root" partition --- arduino/libretuya/common/main.cpp | 9 +++++++++ arduino/libretuya/port/flashdb/fal_cfg.h | 7 +++++++ builder/utils/flash.py | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/arduino/libretuya/common/main.cpp b/arduino/libretuya/common/main.cpp index e2a11f1..5ec2b76 100644 --- a/arduino/libretuya/common/main.cpp +++ b/arduino/libretuya/common/main.cpp @@ -5,6 +5,11 @@ using namespace arduino; +extern "C" { +#include +fal_partition_t fal_root_part = NULL; +} + // Weak empty variant initialization function. // May be redefined by variant files. void initVariant() __attribute__((weak)); @@ -32,6 +37,10 @@ int main(void) { __libc_init_array(); // optionally initialize per-variant code initVariant(); + // initialize FAL + fal_init(); + // provide root partition + fal_root_part = (fal_partition_t)fal_partition_find("root"); // start the main task and OS kernel startMainTask(); diff --git a/arduino/libretuya/port/flashdb/fal_cfg.h b/arduino/libretuya/port/flashdb/fal_cfg.h index 7cc3102..61836ce 100644 --- a/arduino/libretuya/port/flashdb/fal_cfg.h +++ b/arduino/libretuya/port/flashdb/fal_cfg.h @@ -2,6 +2,8 @@ #pragma once +#include + // Flash device configuration extern const struct fal_flash_dev flash0; @@ -23,3 +25,8 @@ extern const struct fal_flash_dev flash0; .offset = FLASH_##part_upper##_OFFSET, /* partition offset macro as uppercase string */ \ .len = FLASH_##part_upper##_LENGTH, /* partition length macro as uppercase string */ \ }, + +/** + * @brief Root partition table, representing the entire flash. + */ +extern fal_partition_t fal_root_part; diff --git a/builder/utils/flash.py b/builder/utils/flash.py index 5b39f46..546d0b9 100644 --- a/builder/utils/flash.py +++ b/builder/utils/flash.py @@ -11,6 +11,9 @@ def env_add_flash_layout(env, board): defines = {} flash_size = 0 fal_items = "" + # add "root" partition + fal_items += "FAL_PART_TABLE_ITEM(root, ROOT)" + # add all partitions for name, layout in flash_layout.items(): name = name.upper() (offset, _, length) = layout.partition("+") @@ -19,6 +22,10 @@ def env_add_flash_layout(env, board): 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 + # for "root" partition + defines["FLASH_ROOT_OFFSET"] = 0 + defines["FLASH_ROOT_LENGTH"] = flash_size + # add partition table array defines["FAL_PART_TABLE"] = "{" + fal_items + "}" env.Append(CPPDEFINES=list(defines.items())) env.Replace(**defines)