From 4d81fcac26569c3061e3566c6e3987d9afa9734c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Thu, 13 Jul 2023 17:00:42 +0200 Subject: [PATCH] [realtek-ambz2] Flash bootloader & partition table in UF2 --- builder/family/realtek-ambz2.py | 5 +++++ cores/common/arduino/libraries/common/Update/Update.cpp | 7 ++++++- cores/common/base/api/lt_ota.c | 4 +--- platform.py | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builder/family/realtek-ambz2.py b/builder/family/realtek-ambz2.py index a6786e0..e593bec 100644 --- a/builder/family/realtek-ambz2.py +++ b/builder/family/realtek-ambz2.py @@ -416,6 +416,8 @@ if not isfile(image_ota_clear): queue.BuildLibraries() # Main firmware outputs and actions +image_part_table = "${BUILD_DIR}/image_part_table.${FLASH_PART_TABLE_OFFSET}.bin" +image_bootloader = "${BUILD_DIR}/image_bootloader.${FLASH_BOOT_OFFSET}.bin" image_firmware_is = "${BUILD_DIR}/image_firmware_is.${FLASH_OTA1_OFFSET}.bin" env.Replace( # linker command (dual .bin outputs) @@ -424,6 +426,9 @@ env.Replace( UF2OTA=[ # same OTA images for flasher and device f"{image_firmware_is},{image_firmware_is}=device:ota1,ota2;flasher:ota1,ota2", + # having flashed an application image, update the bootloader and partition table (incl. keys) + f"{image_bootloader}=device:boot;flasher:boot", + f"{image_part_table}=device:part_table;flasher:part_table", # clearing headers of the "other" OTA image (hence the indexes are swapped) f"{image_ota_clear},{image_ota_clear}=device:ota2,ota1;flasher:ota2,ota1", ], diff --git a/cores/common/arduino/libraries/common/Update/Update.cpp b/cores/common/arduino/libraries/common/Update/Update.cpp index 6a2c6cd..8c1ff70 100644 --- a/cores/common/arduino/libraries/common/Update/Update.cpp +++ b/cores/common/arduino/libraries/common/Update/Update.cpp @@ -36,6 +36,11 @@ bool UpdateClass::begin( __attribute__((unused)) uint8_t ledOn, __attribute__((unused)) const char *label ) { +#if !LT_HAS_OTA + LT_E("OTA is not yet supported on this chip!"); + this->errArd = UPDATE_ERROR_BAD_ARGUMENT; + return false; +#endif if (this->ctx) { return false; } @@ -165,7 +170,7 @@ size_t UpdateClass::writeStream(Stream &data) { // read data to fit in the remaining buffer space auto bufSize = this->ctx->buf_pos - this->ctx->buf; - auto read = data.readBytes(this->ctx->buf_pos, UF2_BLOCK_SIZE - bufSize); + auto read = data.readBytes(this->ctx->buf_pos, UF2_BLOCK_SIZE - bufSize); // increment buffer writing head this->ctx->buf_pos += read; // process the block if complete diff --git a/cores/common/base/api/lt_ota.c b/cores/common/base/api/lt_ota.c index e122384..7eb27e2 100644 --- a/cores/common/base/api/lt_ota.c +++ b/cores/common/base/api/lt_ota.c @@ -4,8 +4,6 @@ #include -#define UF2_CTX_SIZE (sizeof(uf2_ota_t) + sizeof(uf2_info_t)) - static inline size_t lt_ota_buf_left(lt_ota_ctx_t *ctx) { return ctx->buf + UF2_BLOCK_SIZE - ctx->buf_pos; } @@ -18,7 +16,7 @@ void lt_ota_begin(lt_ota_ctx_t *ctx, size_t size) { if (!ctx) return; - memset((void *)ctx + UF2_CTX_SIZE, 0, sizeof(lt_ota_ctx_t) - UF2_CTX_SIZE); + memset(ctx, 0, sizeof(lt_ota_ctx_t)); uf2_ctx_init(&ctx->uf2, lt_ota_get_uf2_scheme(), lt_cpu_get_family()); uf2_info_init(&ctx->info); ctx->buf_pos = ctx->buf; diff --git a/platform.py b/platform.py index 2da5b4a..b4f27ab 100644 --- a/platform.py +++ b/platform.py @@ -17,7 +17,7 @@ from platformio.platform.base import PlatformBase from platformio.platform.board import PlatformBoardConfig from semantic_version import SimpleSpec, Version -LTCHIPTOOL_VERSION = "^4.0.1" +LTCHIPTOOL_VERSION = "^4.2.3" # Install & import tools