diff --git a/builder/frameworks/realtek-ambz-sdk.py b/builder/frameworks/realtek-ambz-sdk.py index 53bfb89..5965189 100644 --- a/builder/frameworks/realtek-ambz-sdk.py +++ b/builder/frameworks/realtek-ambz-sdk.py @@ -20,9 +20,12 @@ assert isdir(env.subst(BOARD_DIR)) assert isdir(env.subst(FIXUPS_DIR)) assert isdir(env.subst(PLATFORM_DIR)) -ota1_offset = board.get("build.amb_ota1_offset") -ota2_offset = board.get("build.amb_ota2_offset") +flash_addr = board.get("build.amb_flash_addr") +flash_ota1_offset = env.subst("$FLASH_OTA1_OFFSET") +flash_ota2_offset = env.subst("$FLASH_OTA2_OFFSET") boot_all = board.get("build.amb_boot_all") +ota1_offset = hex(int(flash_addr, 16) + int(flash_ota1_offset, 16)) +ota2_offset = hex(int(flash_addr, 16) + int(flash_ota2_offset, 16)) # Outputs env.Replace( @@ -543,8 +546,8 @@ actions.append(env.VerboseAction(pick_tool, "Wrapping binary images")) actions.append(env.VerboseAction(concat_xip_ram, "Packaging firmware image - $IMG_FW")) # actions.append(env.VerboseAction(checksum_img, "Generating checksum")) actions.append(env.VerboseAction(package_ota, "Packaging OTA image - $IMG_OTA")) -actions.append(env.VerboseAction("true", f"- OTA1 flash offset: {ota1_offset}")) -actions.append(env.VerboseAction("true", f"- OTA2 flash offset: {ota2_offset}")) +actions.append(env.VerboseAction("true", f"- OTA1 flash offset: {flash_ota1_offset}")) +actions.append(env.VerboseAction("true", f"- OTA2 flash offset: {flash_ota2_offset}")) # Clone env to ignore options from child projects envsdk = env.Clone() diff --git a/builder/main.py b/builder/main.py index a1217b1..7890604 100644 --- a/builder/main.py +++ b/builder/main.py @@ -1,12 +1,14 @@ from SCons.Script import Default, DefaultEnvironment env = DefaultEnvironment() +board = env.BoardConfig() # Firmware name if env.get("PROGNAME", "program") == "program": env.Replace(PROGNAME="firmware") env.Replace(PROGSUFFIX=".elf") +# Toolchain config - TODO multiple arch, specified in board.json env.Replace( AR="arm-none-eabi-gcc-ar", AS="arm-none-eabi-gcc", @@ -21,8 +23,17 @@ env.Replace( SIZETOOL="arm-none-eabi-size", ) -# I have no idea how does PlatformIO work -# env.SConscript("frameworks/realtek-ambz-sdk.py") +# Flash layout defines +flash_layout: dict = board.get("flash") +if flash_layout: + defines = {} + 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 + env.Append(CPPDEFINES=defines.items()) + env.Replace(**defines) target_elf = env.BuildProgram() target_fw = env.DumpFirmwareBinary("firmware.bin", target_elf) diff --git a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1.ld b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1.ld index bbd3930..f8c4f7b 100644 --- a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1.ld +++ b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1.ld @@ -9,11 +9,11 @@ MEMORY ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ - BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x2B000 /* MAIN RAM: 228 */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x2B000 /* MAIN RAM: 172k */ MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ - XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 16k, 32 Bytes resvd for header*/ XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0x75000-0x20 /* XIP1: 468k, 32 Bytes resvd for header */ diff --git a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld index c95cd66..56cb20d 100644 --- a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld +++ b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld @@ -9,15 +9,15 @@ MEMORY ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ - BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x39000 /* MAIN RAM: 228 */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x39000 /* MAIN RAM: 228k */ MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ - XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 16k, 32 Bytes resvd for header*/ XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ - XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 2*468k, 32 Bytes resvd for header */ - XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 2*468k, 32 Bytes resvd for header */ + XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 788k, 32 Bytes resvd for header */ + XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 788k, 32 Bytes resvd for header */ } diff --git a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M_cpp.ld b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M_cpp.ld index 022ce4b..2cdfd46 100644 --- a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M_cpp.ld +++ b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip1_2M_cpp.ld @@ -17,16 +17,16 @@ MEMORY ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ - BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x38000 /* MAIN RAM: 228 */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x38000 /* MAIN RAM: 224k */ ROM_BSS_RAM (rwx) : ORIGIN = 0x1003D000, LENGTH = 0x1000 /* ROM BSS RAM: 4K */ MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ - XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 16k, 32 Bytes resvd for header*/ XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ - XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 2*468k, 32 Bytes resvd for header */ - XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 2*468k, 32 Bytes resvd for header */ + XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 788k, 32 Bytes resvd for header */ + XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 788k, 32 Bytes resvd for header */ } diff --git a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2.ld b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2.ld index 18395ae..f8e2d2b 100644 --- a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2.ld +++ b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2.ld @@ -9,11 +9,11 @@ MEMORY ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ - BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x2B000 /* MAIN RAM: 228 */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x2B000 /* MAIN RAM: 172k */ MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ - XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 16k, 32 Bytes resvd for header*/ XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0x75000-0x20 /* XIP1: 468k, 32 Bytes resvd for header */ diff --git a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld index 8968224..bf396c6 100644 --- a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld +++ b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld @@ -9,15 +9,15 @@ MEMORY ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ - BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x39000 /* MAIN RAM: 228 */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x39000 /* MAIN RAM: 228k */ MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ - XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 16k, 32 Bytes resvd for header*/ XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ - XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 2*468k, 32 Bytes resvd for header */ - XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 2*468k, 32 Bytes resvd for header */ + XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 788k, 32 Bytes resvd for header */ + XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 788k, 32 Bytes resvd for header */ } diff --git a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M_cpp.ld b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M_cpp.ld index 8b92719..35aff74 100644 --- a/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M_cpp.ld +++ b/platform/realtek-ambz/ld/rlx8711B-symbol-v02-img2_xip2_2M_cpp.ld @@ -17,16 +17,16 @@ MEMORY ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ - BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x38000 /* MAIN RAM: 228 */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x38000 /* MAIN RAM: 224k */ ROM_BSS_RAM (rwx) : ORIGIN = 0x1003D000, LENGTH = 0x1000 /* ROM BSS RAM: 4K */ MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ - XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 16k, 32 Bytes resvd for header*/ XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ - XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 2*468k, 32 Bytes resvd for header */ - XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 2*468k, 32 Bytes resvd for header */ + XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 788k, 32 Bytes resvd for header */ + XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 788k, 32 Bytes resvd for header */ }