[core] Update PIO builders to new structure
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"family": "BK7231N",
|
||||
"ldscript_sdk": "bk7231n_bsp.ld",
|
||||
"ldscript_arduino": "bk7231n_bsp.ld",
|
||||
"ldscript": "bk7231n_bsp.ld",
|
||||
"bkboot_version": "1.0.1-bk7231n",
|
||||
"bkrbl_size_app": "0x108700"
|
||||
},
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"family": "BK7231U",
|
||||
"ldscript_sdk": "bk7231_bsp.ld",
|
||||
"ldscript_arduino": "bk7231_bsp.ld",
|
||||
"ldscript": "bk7231_bsp.ld",
|
||||
"bkboot_version": "1.0.8-bk7231u",
|
||||
"bkrbl_size_app": "0x108700"
|
||||
},
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
"build": {
|
||||
"family": "BK7251",
|
||||
"f_cpu": "180000000L",
|
||||
"ldscript_sdk": "bk7231_bsp.ld",
|
||||
"ldscript_arduino": "bk7231_bsp.ld",
|
||||
"ldscript": "bk7231_bsp.ld",
|
||||
"bkboot_version": "0.1.3-bk7252",
|
||||
"bkrbl_size_app": "0x1A0000"
|
||||
},
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
"mem 0x000000 0x200000 ro"
|
||||
]
|
||||
},
|
||||
"frameworks": [
|
||||
"beken-72xx-sdk",
|
||||
"beken-72xx-arduino"
|
||||
],
|
||||
"upload": {
|
||||
"maximum_ram_size": 262144,
|
||||
"flash_size": 2097152,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"build": {
|
||||
"ldscript_sdk": "rlx8711B-symbol-v02-img2_xip1_2M_468k_cpp.ld",
|
||||
"ldscript_arduino": "rlx8711B-symbol-v02-img2_xip1_2M_468k_cpp.ld",
|
||||
"ldscript": "rlx8711B-symbol-v02-img2_xip1_2M_468k_cpp.ld",
|
||||
"amb_boot_all": "boot_all_77F7.bin"
|
||||
},
|
||||
"flash": {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"build": {
|
||||
"ldscript_sdk": "rlx8711B-symbol-v02-img2_xip1_2M_cpp.ld",
|
||||
"ldscript_arduino": "rlx8711B-symbol-v02-img2_xip1_2M_cpp.ld",
|
||||
"ldscript": "rlx8711B-symbol-v02-img2_xip1_2M_cpp.ld",
|
||||
"amb_boot_all": "boot_all_77F7.bin"
|
||||
},
|
||||
"flash": {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"build": {
|
||||
"ldscript_sdk": "rlx8711B-symbol-v02-img2_xip1_4M_980k_cpp.ld",
|
||||
"ldscript_arduino": "rlx8711B-symbol-v02-img2_xip1_4M_980k_cpp.ld",
|
||||
"ldscript": "rlx8711B-symbol-v02-img2_xip1_4M_980k_cpp.ld",
|
||||
"amb_boot_all": "boot_all_C556.bin"
|
||||
},
|
||||
"flash": {
|
||||
|
||||
@@ -24,10 +24,6 @@
|
||||
"mem 0x8000000 0x8200000 ro"
|
||||
]
|
||||
},
|
||||
"frameworks": [
|
||||
"realtek-ambz-sdk",
|
||||
"realtek-ambz-arduino"
|
||||
],
|
||||
"upload": {
|
||||
"maximum_ram_size": 262144,
|
||||
"require_upload_port": true,
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
"family": "RTL8720C",
|
||||
"f_cpu": "100000000L",
|
||||
"prefix": "arm-none-eabi-",
|
||||
"ldscript_sdk": "rtl8710c_ram.ld",
|
||||
"ldscript_arduino": "rtl8710c_ram.ld"
|
||||
"ldscript": "rtl8710c_ram.ld"
|
||||
},
|
||||
"flash": {
|
||||
"part_table": "0x000000+0x1000",
|
||||
@@ -16,9 +15,6 @@
|
||||
"protocol": "openocd",
|
||||
"protocols": []
|
||||
},
|
||||
"frameworks": [
|
||||
"realtek-ambz2-sdk"
|
||||
],
|
||||
"upload": {
|
||||
"maximum_ram_size": 262144
|
||||
},
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-04-23.
|
||||
|
||||
from os.path import isdir, join
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
|
||||
API_DIR = platform.get_package_dir("framework-arduino-api")
|
||||
LT_ARDUINO_DIR = join(platform.get_dir(), "arduino", "libretuya")
|
||||
assert isdir(API_DIR)
|
||||
assert isdir(LT_ARDUINO_DIR)
|
||||
|
||||
# Flags
|
||||
env.Append(
|
||||
CPPDEFINES=[
|
||||
("LIBRETUYA_ARDUINO", "1"),
|
||||
("ARDUINO", 10812),
|
||||
"ARDUINO_SDK",
|
||||
],
|
||||
LINKFLAGS=[
|
||||
"--specs=nosys.specs",
|
||||
"-Wl,--as-needed",
|
||||
"-Wl,--build-id=none",
|
||||
"-Wl,--cref",
|
||||
"-Wl,--no-enum-size-warning",
|
||||
"-Wl,--no-undefined",
|
||||
"-Wl,--warn-common",
|
||||
# wrappers from port/printf/
|
||||
"-Wl,-wrap,putchar",
|
||||
"-Wl,-wrap,puts",
|
||||
# wrappers from posix/time.c
|
||||
"-Wl,-wrap,gettimeofday",
|
||||
"-Wl,-wrap,settimeofday",
|
||||
],
|
||||
)
|
||||
# Arduino core uses __libc_init_array
|
||||
if "-nostartfiles" in env["LINKFLAGS"]:
|
||||
env["LINKFLAGS"].remove("-nostartfiles")
|
||||
|
||||
# Sources - ArduinoCore-API
|
||||
env.AddLibrary(
|
||||
name="arduino_api",
|
||||
base_dir=API_DIR,
|
||||
srcs=[
|
||||
"+<api/Common.cpp>",
|
||||
"+<api/IPAddress.cpp>",
|
||||
"+<api/PluggableUSB.cpp>",
|
||||
"+<api/Print.cpp>",
|
||||
"+<api/Stream.cpp>",
|
||||
"+<api/String.cpp>",
|
||||
],
|
||||
includes=[
|
||||
"!<.>",
|
||||
"!<api/deprecated>",
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - LibreTuya API
|
||||
env.AddLibrary(
|
||||
name="libretuya_api",
|
||||
base_dir=LT_ARDUINO_DIR,
|
||||
srcs=[
|
||||
"+<api/**/*.c*>",
|
||||
"+<common/*.c*>",
|
||||
"+<core/*.c*>",
|
||||
"+<libraries/**/*.c*>",
|
||||
"+<port/**/*.c*>",
|
||||
"+<posix/*.c>",
|
||||
],
|
||||
includes=[
|
||||
"!<.>",
|
||||
"!<compat>",
|
||||
"!<core>",
|
||||
"!<libraries/*>",
|
||||
"!<port/*>",
|
||||
"!<posix>",
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - uf2ota library
|
||||
ltchiptool_dir = platform.get_package_dir(f"tool-ltchiptool")
|
||||
env.AddLibrary(
|
||||
name="uf2ota",
|
||||
base_dir=ltchiptool_dir,
|
||||
srcs=[
|
||||
"+<uf2ota/*.c>",
|
||||
],
|
||||
includes=[
|
||||
"+<.>",
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - board variant
|
||||
env.AddLibrary(
|
||||
name="board_${VARIANT}",
|
||||
base_dir="$BOARD_DIR",
|
||||
srcs=[
|
||||
"+<variant.cpp>",
|
||||
],
|
||||
)
|
||||
|
||||
for code, base_dir in env["ARDUINO_DIRS"].items():
|
||||
code = env.subst(code)
|
||||
base_dir = env.subst(base_dir)
|
||||
if not code or not isdir(base_dir):
|
||||
# Skip unused paths
|
||||
continue
|
||||
|
||||
# Sources - Arduino Core
|
||||
env.AddLibrary(
|
||||
name=f"{code}_arduino_core",
|
||||
base_dir=base_dir,
|
||||
srcs=[
|
||||
# Wiring core
|
||||
"+<cores/arduino/*.c>",
|
||||
"+<cores/arduino/*.cpp>",
|
||||
],
|
||||
includes=[
|
||||
# prepend these as the Arduino core may be incorrectly picking some includes from SDKs
|
||||
"!<cores/arduino>",
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - Arduino libraries
|
||||
env.AddLibrary(
|
||||
name=f"{code}_arduino_libs",
|
||||
base_dir=base_dir,
|
||||
srcs=[
|
||||
"+<libraries/*/*.cpp>",
|
||||
],
|
||||
includes=[
|
||||
"+<libraries/*>",
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - external library ports
|
||||
env.AddLibrary(
|
||||
name=f"{code}_arduino_port",
|
||||
base_dir=base_dir,
|
||||
srcs=[
|
||||
"+<port/**/*.c*>",
|
||||
],
|
||||
includes=[
|
||||
"+<port/*>",
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - external library ports
|
||||
env.AddLibraryFlashDB(version="03500fa")
|
||||
env.AddLibraryPrintf(version="6.0.0")
|
||||
|
||||
# Libs & linker config
|
||||
env.Append(
|
||||
LIBS=[
|
||||
"stdc++",
|
||||
"supc++",
|
||||
],
|
||||
)
|
||||
env.Replace(
|
||||
# Change to Arduino linker script
|
||||
LDSCRIPT_PATH=["${LDSCRIPT_ARDUINO}"],
|
||||
)
|
||||
|
||||
# Build all libraries
|
||||
env.BuildLibraries(safe=False)
|
||||
@@ -3,10 +3,11 @@
|
||||
from os.path import join
|
||||
|
||||
from ltchiptool.soc.bk72xx.binary import to_offset
|
||||
from SCons.Script import Builder, DefaultEnvironment
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
board = env.BoardConfig()
|
||||
env: Environment = DefaultEnvironment()
|
||||
board: PlatformBoardConfig = env.BoardConfig()
|
||||
|
||||
ROOT_DIR = join("$SDK_DIR", "beken378")
|
||||
APP_DIR = join(ROOT_DIR, "app")
|
||||
@@ -14,7 +15,7 @@ DRIVER_DIR = join(ROOT_DIR, "driver")
|
||||
FUNC_DIR = join(ROOT_DIR, "func")
|
||||
|
||||
# Load sys_config.h into env
|
||||
env.LoadConfig(join("$FAMILY_DIR", "config", "sys_config.h"))
|
||||
env.LoadConfig(join("$FAMILY_DIR", "base", "config", "sys_config.h"))
|
||||
|
||||
# Define vars used during build
|
||||
SOC_BK7231 = 1
|
||||
@@ -50,6 +51,10 @@ env.Append(
|
||||
"-fsigned-char",
|
||||
"-Wno-comment",
|
||||
"-Werror=implicit-function-declaration",
|
||||
"-Wno-write-strings",
|
||||
"-Wno-char-subscripts",
|
||||
"-Wno-missing-braces",
|
||||
"-Wno-attributes",
|
||||
],
|
||||
CFLAGS=[
|
||||
"-std=gnu99",
|
||||
@@ -66,11 +71,6 @@ env.Append(
|
||||
"-Wno-literal-suffix",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
# LibreTuya configuration
|
||||
("LT_HAS_LWIP", "1"),
|
||||
("LT_HAS_LWIP2", "1"),
|
||||
("LT_HAS_FREERTOS", "1"),
|
||||
("LT_HAS_MBEDTLS", "1"),
|
||||
# SDK options
|
||||
("CFG_OS_FREERTOS", "1"),
|
||||
("MBEDTLS_CONFIG_FILE", r"\"tls_config.h\""),
|
||||
@@ -78,6 +78,8 @@ env.Append(
|
||||
("WOLFSSL_BEKEN", env.Cfg("CFG_WPA3")),
|
||||
"MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED",
|
||||
("INCLUDE_xTaskGetHandle", "1"),
|
||||
# mbedtls_net_set_nonblock is commented out in tls_net.c
|
||||
("mbedtls_net_set_nonblock", "net_set_nonblock"),
|
||||
],
|
||||
ASFLAGS=[
|
||||
"-mcpu=arm968e-s",
|
||||
@@ -113,16 +115,21 @@ env.Append(
|
||||
"-Wl,-wrap,bk_flash_erase",
|
||||
"-Wl,-wrap,bk_flash_write",
|
||||
"-Wl,-wrap,bk_flash_read",
|
||||
# stdio wrappers (base/port/printf.c)
|
||||
"-Wl,-wrap,bk_printf",
|
||||
],
|
||||
)
|
||||
|
||||
srcs_core = []
|
||||
srcs_fixups = []
|
||||
|
||||
# Fix for BK7231T's bootloader compatibility
|
||||
if board.get("build.bkboot_version") == "1.0.5-bk7231s":
|
||||
env.Append(CPPDEFINES=[("CFG_SUPPORT_BOOTLOADER", "1")])
|
||||
srcs_fixups.append("+<boot_handlers_105_bk7231s.S>")
|
||||
env.AddLibrary(
|
||||
name="bdk_boot",
|
||||
base_dir="$FAMILY_DIR/base/fixups",
|
||||
srcs=["+<boot_handlers_105_bk7231s.S>"],
|
||||
)
|
||||
else:
|
||||
srcs_core.append("+<driver/entry/boot_handlers.S>")
|
||||
|
||||
@@ -148,30 +155,6 @@ env.AddLibrary(
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - parent family fixups
|
||||
env.AddLibrary(
|
||||
name="${FAMILY_PARENT_CODE}_fixups",
|
||||
base_dir="$PARENT_DIR/fixups",
|
||||
srcs=[
|
||||
"+<arch_main.c>",
|
||||
"+<ate_app.c>",
|
||||
"+<clock_cal.c>",
|
||||
"+<clock_rtos.c>",
|
||||
"+<intc.c>",
|
||||
"+<wrap_BkDriverFlash.c>",
|
||||
*srcs_fixups,
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - family fixups
|
||||
env.AddLibrary(
|
||||
name="${FAMILY_CODE}_fixups",
|
||||
base_dir="$FAMILY_DIR/fixups",
|
||||
srcs=[
|
||||
"+<temp_detect.c>",
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - app module
|
||||
env.AddLibrary(
|
||||
name="bdk_app",
|
||||
@@ -223,6 +206,7 @@ env.AddLibrary(
|
||||
"+<sys_ctrl/*.c>",
|
||||
"+<uart/*.c>",
|
||||
"+<wdt/*.c>",
|
||||
"ARDUINO" in env and "-<uart/printf.c>",
|
||||
],
|
||||
includes=[
|
||||
"+<common>",
|
||||
@@ -343,8 +327,8 @@ env.AddLibrary(
|
||||
),
|
||||
)
|
||||
|
||||
# Sources - lwIP 2.1.3
|
||||
env.AddLibraryLwIP(version="2.1.3", port="bdk")
|
||||
# Sources - lwIP
|
||||
env.AddExternalLibrary("lwip", port="bdk")
|
||||
|
||||
# Sources - mbedTLS 2.6.0
|
||||
env.AddLibrary(
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from os.path import join
|
||||
|
||||
from SCons.Script import Builder, DefaultEnvironment
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from SCons.Script import Builder, DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
board = env.BoardConfig()
|
||||
env: Environment = DefaultEnvironment()
|
||||
board: PlatformBoardConfig = env.BoardConfig()
|
||||
|
||||
# Flags
|
||||
env.Append(
|
||||
@@ -37,12 +38,6 @@ env.Append(
|
||||
"-fno-rtti",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
# LibreTuya configuration
|
||||
("LT_HAS_LWIP", "1"),
|
||||
("LT_HAS_LWIP2", "1"),
|
||||
("LT_HAS_FREERTOS", "1"),
|
||||
("LT_HAS_MBEDTLS", "1"),
|
||||
("LT_PRINTF_BROKEN", "1"), # printf does not handle %.3f properly
|
||||
# other options
|
||||
"M3",
|
||||
"CONFIG_PLATFORM_8711B",
|
||||
@@ -74,6 +69,24 @@ env.Append(
|
||||
"-Wl,-wrap,aes_80211_encrypt",
|
||||
"-Wl,-wrap,aes_80211_decrypt",
|
||||
"-Wl,-wrap,DecGTK",
|
||||
# TODO what is this and is this needed?
|
||||
"-Wl,--undefined=InfraStart",
|
||||
# stdio wrappers (base/port/printf.c)
|
||||
"-Wl,-wrap,rtl_printf",
|
||||
"-Wl,-wrap,rtl_sprintf",
|
||||
"-Wl,-wrap,rtl_snprintf",
|
||||
"-Wl,-wrap,rtl_vsnprintf",
|
||||
"-Wl,-wrap,rtl_vsnprintf_r",
|
||||
"-Wl,-wrap,rtl_vprintf",
|
||||
"-Wl,-wrap,rtl_vfprintf",
|
||||
"-Wl,-wrap,DiagPrintf",
|
||||
"-Wl,-wrap,DiagSPrintf",
|
||||
"-Wl,-wrap,DiagSnPrintf",
|
||||
"-Wl,-wrap,prvDiagPrintf",
|
||||
"-Wl,-wrap,prvDiagSPrintf",
|
||||
"-Wl,-wrap,VSprintf",
|
||||
"-Wl,-wrap,LOG_PRINTF",
|
||||
"-Wl,-wrap,__rtl_vfprintf_r_v1_00",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -93,7 +106,7 @@ env.AddLibrary(
|
||||
"+<component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_p2p_config.c>",
|
||||
"+<component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_wps_config.c>",
|
||||
"+<component/common/api/wifi/wifi_conf.c>",
|
||||
"+<component/common/api/wifi/wifi_ind.c>",
|
||||
"ARDUINO" not in "ENV" and "+<component/common/api/wifi/wifi_ind.c>",
|
||||
"+<component/common/api/wifi/wifi_promisc.c>",
|
||||
"+<component/common/api/wifi/wifi_simple_config.c>",
|
||||
"+<component/common/api/wifi/wifi_util.c>",
|
||||
@@ -193,8 +206,8 @@ env.AddLibrary(
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - lwIP 2.1.3
|
||||
env.AddLibraryLwIP(version="2.1.3", port="amb1")
|
||||
# Sources - lwIP
|
||||
env.AddExternalLibrary("lwip", port="amb1")
|
||||
|
||||
# Sources - mbedTLS
|
||||
env.AddLibrary(
|
||||
@@ -212,20 +225,6 @@ env.AddLibrary(
|
||||
],
|
||||
)
|
||||
|
||||
# Sources - family fixups
|
||||
env.AddLibrary(
|
||||
name="ambz_fixups",
|
||||
base_dir="$FAMILY_DIR/fixups",
|
||||
srcs=[
|
||||
"+<app_start_patch.c>",
|
||||
"+<cmsis_ipsr.c>",
|
||||
"+<log_uart.c>",
|
||||
"+<net_sockets.c>", # fix non-blocking sockets (Realtek disabled this for unknown reason)
|
||||
"+<ssl_tls.c>", # rtl sdk defines S1 and S2 which conflicts here
|
||||
"+<wifi_mode.c>",
|
||||
],
|
||||
)
|
||||
|
||||
# Libs & linker config
|
||||
env.Append(
|
||||
LIBPATH=[
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from os.path import join
|
||||
|
||||
from SCons.Script import Builder, DefaultEnvironment
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
board = env.BoardConfig()
|
||||
env: Environment = DefaultEnvironment()
|
||||
board: PlatformBoardConfig = env.BoardConfig()
|
||||
|
||||
COMPONENT_DIR = join("$SDK_DIR", "component")
|
||||
|
||||
@@ -44,11 +45,6 @@ env.Append(
|
||||
"-fno-use-cxa-atexit",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
# LibreTuya configuration
|
||||
("LT_HAS_LWIP", "1"),
|
||||
("LT_HAS_LWIP2", "1"),
|
||||
("LT_HAS_FREERTOS", "1"),
|
||||
("LT_HAS_MBEDTLS", "1"),
|
||||
# other options
|
||||
"__thumb2__",
|
||||
"CONFIG_PLATFORM_8710C",
|
||||
@@ -1,14 +1,86 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-05-16.
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-04-23.
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
from os.path import join
|
||||
|
||||
env = DefaultEnvironment()
|
||||
board = env.BoardConfig()
|
||||
platform = env.PioPlatform()
|
||||
import click
|
||||
from ltchiptool import Family
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
# support passing "arduino" as framework
|
||||
frameworks = board.get("frameworks")
|
||||
framework = next(fw for fw in frameworks if "arduino" in fw)
|
||||
builder = platform.frameworks[framework]["script"]
|
||||
builder = builder.rpartition("/")[2]
|
||||
env.SConscript(builder, exports="env")
|
||||
# Let everyone know we're using the Arduino framework
|
||||
env: Environment = DefaultEnvironment()
|
||||
env["ARDUINO"] = True
|
||||
|
||||
# Add base cores' sources first
|
||||
env.SConscript("base.py")
|
||||
|
||||
family: Family = env["FAMILY_OBJ"]
|
||||
|
||||
# Add common sources among all families
|
||||
env.AddCoreSources(
|
||||
name="common_arduino",
|
||||
path=join("$COMMON_DIR", "arduino", "src"),
|
||||
)
|
||||
env.AddArduinoLibraries(
|
||||
name="common_arduino",
|
||||
path=join("$COMMON_DIR", "arduino", "libraries"),
|
||||
)
|
||||
# Add sources for this family and each parent
|
||||
found = False
|
||||
for f in family.inheritance:
|
||||
code = f"{f.code}_arduino"
|
||||
path = join("$CORES_DIR", f.name, "arduino")
|
||||
# Add libraries first, to put the include paths after core sources
|
||||
env.AddArduinoLibraries(name=code, path=join(path, "libraries"))
|
||||
found = found or env.AddCoreSources(name=code, path=join(path, "src"))
|
||||
|
||||
# Fail if Arduino core wasn't found
|
||||
if not found:
|
||||
click.secho(
|
||||
f"Platform '{family.name}' doesn't support Arduino framework - "
|
||||
"the Arduino core source files are absent.",
|
||||
fg="red",
|
||||
)
|
||||
exit(1)
|
||||
|
||||
# Sources - ArduinoCore-API
|
||||
env.AddExternalLibrary("arduino_api")
|
||||
|
||||
# Sources - board variant
|
||||
env.AddLibrary(
|
||||
name="board_${VARIANT}",
|
||||
base_dir="$BOARD_DIR",
|
||||
srcs=[
|
||||
"+<variant.cpp>",
|
||||
],
|
||||
includes=[
|
||||
"!<.>",
|
||||
],
|
||||
)
|
||||
|
||||
# Flags & linker options
|
||||
env.Append(
|
||||
CPPDEFINES=[
|
||||
("LIBRETUYA_ARDUINO", 1),
|
||||
("ARDUINO", 10812),
|
||||
("ARDUINO_SDK", 1),
|
||||
("ARDUINO_ARCH_${FAMILY_CODE}", 1),
|
||||
],
|
||||
LINKFLAGS=[
|
||||
"--specs=nosys.specs",
|
||||
"-Wl,--as-needed",
|
||||
"-Wl,--build-id=none",
|
||||
"-Wl,--cref",
|
||||
"-Wl,--no-enum-size-warning",
|
||||
"-Wl,--no-undefined",
|
||||
"-Wl,--warn-common",
|
||||
# wrappers from posix/time.c
|
||||
"-Wl,-wrap,gettimeofday",
|
||||
"-Wl,-wrap,settimeofday",
|
||||
],
|
||||
)
|
||||
# Arduino core uses __libc_init_array
|
||||
if "-nostartfiles" in env["LINKFLAGS"]:
|
||||
env["LINKFLAGS"].remove("-nostartfiles")
|
||||
|
||||
# Build all libraries
|
||||
env.BuildLibraries()
|
||||
|
||||
84
builder/frameworks/base.py
Normal file
84
builder/frameworks/base.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2023-02-26.
|
||||
|
||||
from os.path import join
|
||||
|
||||
import click
|
||||
from ltchiptool import Family
|
||||
from platformio.platform.base import PlatformBase
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from SCons.Errors import UserError
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env: Environment = DefaultEnvironment()
|
||||
board: PlatformBoardConfig = env.BoardConfig()
|
||||
platform: PlatformBase = env.PioPlatform()
|
||||
|
||||
# Environment variables, include paths, etc.
|
||||
env.ConfigureEnvironment(platform, board)
|
||||
family: Family = env["FAMILY_OBJ"]
|
||||
|
||||
# Flash layout defines
|
||||
env.AddFlashLayout(board)
|
||||
|
||||
# Configure each family first (add CPP defines, prepend fixups' paths)
|
||||
for f in family.inheritance:
|
||||
path = env.AddFamily(f)
|
||||
env.AddCoreConfig(name=f.code, path=join(path, "base"))
|
||||
if "ARDUINO" in env:
|
||||
env.AddCoreConfig(name=f"{f.code}_arduino", path=join(path, "arduino", "src"))
|
||||
|
||||
# Include SDK builder scripts
|
||||
# The script will call BuildLibraries(safe=True) to secure the include paths
|
||||
found = False
|
||||
for f in family.inheritance:
|
||||
try:
|
||||
env.SConscript(f"../family/{f.name}.py", must_exist=True)
|
||||
found = True
|
||||
except UserError:
|
||||
pass
|
||||
|
||||
# Fail if no SDK builder was found
|
||||
if not found:
|
||||
click.secho(
|
||||
f"Platform '{family.name}' is currently not supported - "
|
||||
"no SDK builder script could be found.",
|
||||
fg="red",
|
||||
)
|
||||
exit(1)
|
||||
|
||||
# Add common sources among all families
|
||||
env.AddCoreSources(
|
||||
name="common",
|
||||
path=join("$COMMON_DIR", "base"),
|
||||
)
|
||||
# Add sources for this family and each parent
|
||||
for f in family.inheritance:
|
||||
path = join("$CORES_DIR", f.name, "base")
|
||||
env.AddCoreSources(name=f.code, path=path)
|
||||
|
||||
# Sources - external libraries
|
||||
env.AddExternalLibrary("ltchiptool") # uf2ota source code
|
||||
env.AddExternalLibrary("flashdb")
|
||||
env.AddExternalLibrary("printf")
|
||||
|
||||
# Flags & linker options
|
||||
env.Append(
|
||||
CPPDEFINES=[
|
||||
("LIBRETUYA", 1),
|
||||
("LT_VERSION", env.ReadLTVersion(platform.get_dir(), platform.version)),
|
||||
("LT_BOARD", "${VARIANT}"),
|
||||
("F_CPU", board.get("build.f_cpu")),
|
||||
("MCU", "${MCU}"),
|
||||
("FAMILY", "F_${FAMILY}"),
|
||||
],
|
||||
LINKFLAGS=[
|
||||
'"-Wl,-Map=' + join("$BUILD_DIR", "${PROGNAME}.map") + '"',
|
||||
],
|
||||
LIBS=[
|
||||
"stdc++",
|
||||
"supc++",
|
||||
],
|
||||
)
|
||||
|
||||
# Build everything from the base core
|
||||
env.BuildLibraries()
|
||||
@@ -1,41 +0,0 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-06-14.
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
|
||||
# SDK options
|
||||
env.Replace(
|
||||
LIB_BDK_DRIVER_SKIP=[
|
||||
# using printf library wrappers instead
|
||||
"uart/printf.c",
|
||||
]
|
||||
)
|
||||
|
||||
env.SConscript("beken-72xx-sdk.py", exports="env")
|
||||
env.SConscript("../arduino-common.py", exports="env")
|
||||
|
||||
# Flags
|
||||
env.Append(
|
||||
CCFLAGS=[
|
||||
"-Wno-write-strings",
|
||||
"-Wno-char-subscripts",
|
||||
"-Wno-missing-braces",
|
||||
"-Wno-attributes",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
# LibreTuya configuration
|
||||
("LT_ARD_HAS_WIFI", "1"),
|
||||
("LT_ARD_HAS_MD5", "1"),
|
||||
# macros
|
||||
# mbedtls_net_set_nonblock is commented out in tls_net.c
|
||||
("mbedtls_net_set_nonblock", "net_set_nonblock"),
|
||||
],
|
||||
LINKFLAGS=[
|
||||
# stdio wrappers (port/printf/printf.c)
|
||||
"-Wl,-wrap,bk_printf",
|
||||
],
|
||||
)
|
||||
|
||||
# Build all libraries
|
||||
env.BuildLibraries()
|
||||
@@ -1,56 +0,0 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-04-22.
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
|
||||
# SDK options
|
||||
env.Replace(AMBZ_NO_POLARSSL=True)
|
||||
env.Replace(
|
||||
LIB_AMBZ_SDK_SKIP=[
|
||||
"component/common/api/wifi/wifi_ind.c",
|
||||
]
|
||||
)
|
||||
|
||||
env.SConscript("realtek-ambz-sdk.py", exports="env")
|
||||
env.SConscript("../arduino-common.py", exports="env")
|
||||
|
||||
# Flags
|
||||
env.Append(
|
||||
CPPDEFINES=[
|
||||
"ARDUINO_AMEBA",
|
||||
"ARDUINO_ARCH_AMBZ",
|
||||
# the SDK declares bool if not defined before
|
||||
# which conflicts with C++ built-in bool
|
||||
# so it's either -fpermissive or this:
|
||||
("bool", "bool"),
|
||||
# LibreTuya configuration
|
||||
("LT_ARD_HAS_WIFI", "1"),
|
||||
("LT_ARD_HAS_MD5", "1"),
|
||||
("LT_ARD_HAS_SOFTSERIAL", "1"),
|
||||
# not broken anymore with printf() library
|
||||
("LT_PRINTF_BROKEN", "0"),
|
||||
],
|
||||
LINKFLAGS=[
|
||||
"-Wl,--undefined=InfraStart",
|
||||
# stdio wrappers (port/printf/printf.c)
|
||||
"-Wl,-wrap,rtl_printf",
|
||||
"-Wl,-wrap,rtl_sprintf",
|
||||
"-Wl,-wrap,rtl_snprintf",
|
||||
"-Wl,-wrap,rtl_vsnprintf",
|
||||
"-Wl,-wrap,rtl_vsnprintf_r",
|
||||
"-Wl,-wrap,rtl_vprintf",
|
||||
"-Wl,-wrap,rtl_vfprintf",
|
||||
"-Wl,-wrap,DiagPrintf",
|
||||
"-Wl,-wrap,DiagSPrintf",
|
||||
"-Wl,-wrap,DiagSnPrintf",
|
||||
"-Wl,-wrap,prvDiagPrintf",
|
||||
"-Wl,-wrap,prvDiagSPrintf",
|
||||
"-Wl,-wrap,VSprintf",
|
||||
"-Wl,-wrap,LOG_PRINTF",
|
||||
"-Wl,-wrap,__rtl_vfprintf_r_v1_00",
|
||||
],
|
||||
)
|
||||
|
||||
# Build all libraries
|
||||
env.BuildLibraries()
|
||||
@@ -1,29 +0,0 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-05-24.
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
|
||||
|
||||
def env_add_flashdb(
|
||||
env,
|
||||
version: str,
|
||||
):
|
||||
package_dir = platform.get_package_dir(f"library-flashdb@{version}")
|
||||
|
||||
env.AddLibrary(
|
||||
name=f"flashdb{version}",
|
||||
base_dir=package_dir,
|
||||
srcs=[
|
||||
"+<src/*.c>",
|
||||
"+<port/fal/src/*.c>",
|
||||
],
|
||||
includes=[
|
||||
"+<inc>",
|
||||
"+<port/fal/inc>",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
env.AddMethod(env_add_flashdb, "AddLibraryFlashDB")
|
||||
@@ -1,57 +0,0 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-05-18.
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
|
||||
|
||||
def env_add_lwip(
|
||||
env,
|
||||
version: str,
|
||||
port: str,
|
||||
):
|
||||
# version = env["LIB_LWIP_VERSION"] if "LIB_LWIP_VERSION" in env else version_default
|
||||
package_dir = platform.get_package_dir(f"library-lwip@{version}-{port}")
|
||||
port_srcs = []
|
||||
port_includes = []
|
||||
|
||||
if port in ["amb1"]:
|
||||
port_srcs = [
|
||||
"+<port/realtek/freertos/ethernetif.c>",
|
||||
"+<port/realtek/freertos/sys_arch.c>",
|
||||
]
|
||||
port_includes = [
|
||||
"+<port/realtek>",
|
||||
"+<port/realtek/freertos>",
|
||||
]
|
||||
elif port in ["bdk"]:
|
||||
port_srcs = [
|
||||
"+<port/*.c>",
|
||||
]
|
||||
port_includes = [
|
||||
"+<port>",
|
||||
]
|
||||
|
||||
env.AddLibrary(
|
||||
name=f"lwip{version}_{port}",
|
||||
base_dir=package_dir,
|
||||
srcs=[
|
||||
"+<src/api/*.c>",
|
||||
"+<src/core/*.c>",
|
||||
"+<src/core/ipv4/*.c>",
|
||||
"+<src/netif/ethernet.c>", # 2.0.x
|
||||
"+<src/netif/etharp.c>", # 1.4.x
|
||||
"+<src/apps/mdns/mdns.c>",
|
||||
"+<src/apps/sntp/sntp.c>",
|
||||
*port_srcs,
|
||||
],
|
||||
includes=[
|
||||
"+<src/include>",
|
||||
"+<src/include/ipv4>",
|
||||
*port_includes,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
env.AddMethod(env_add_lwip, "AddLibraryLwIP")
|
||||
@@ -1,41 +0,0 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-06-19.
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
|
||||
|
||||
def env_add_printf(
|
||||
env,
|
||||
version: str,
|
||||
):
|
||||
package_dir = platform.get_package_dir(f"library-printf@{version}")
|
||||
|
||||
env.AddLibrary(
|
||||
name=f"printf{version}",
|
||||
base_dir=package_dir,
|
||||
srcs=[
|
||||
"+<src/printf/printf.c>",
|
||||
],
|
||||
includes=[
|
||||
"+<src>",
|
||||
],
|
||||
options=dict(
|
||||
CFLAGS=["-Wno-maybe-uninitialized"],
|
||||
CPPDEFINES=[("PRINTF_INCLUDE_CONFIG_H", "1")],
|
||||
LINKFLAGS=[
|
||||
"-Wl,-wrap,printf",
|
||||
"-Wl,-wrap,sprintf",
|
||||
"-Wl,-wrap,vsprintf",
|
||||
"-Wl,-wrap,snprintf",
|
||||
"-Wl,-wrap,vsnprintf",
|
||||
"-Wl,-wrap,vprintf",
|
||||
"-Wl,-wrap,puts",
|
||||
"-Wl,-wrap,putchar",
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
env.AddMethod(env_add_printf, "AddLibraryPrintf")
|
||||
@@ -2,31 +2,27 @@
|
||||
|
||||
import sys
|
||||
|
||||
from SCons.Script import Default, DefaultEnvironment
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from SCons.Script import Default, DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
board = env.BoardConfig()
|
||||
|
||||
# Make tools available
|
||||
sys.path.insert(0, platform.get_dir())
|
||||
env: Environment = DefaultEnvironment()
|
||||
board: PlatformBoardConfig = env.BoardConfig()
|
||||
|
||||
# Utilities
|
||||
env.SConscript("utils/config.py", exports="env")
|
||||
env.SConscript("utils/cores.py", exports="env")
|
||||
env.SConscript("utils/env.py", exports="env")
|
||||
env.SConscript("utils/flash.py", exports="env")
|
||||
env.SConscript("utils/libs-external.py", exports="env")
|
||||
env.SConscript("utils/libs.py", exports="env")
|
||||
env.SConscript("utils/ltchiptool.py", exports="env")
|
||||
# Vendor-specific library ports
|
||||
env.SConscript("libs/flashdb.py", exports="env")
|
||||
env.SConscript("libs/lwip.py", exports="env")
|
||||
env.SConscript("libs/printf.py", exports="env")
|
||||
|
||||
# Firmware name
|
||||
if env.get("PROGNAME", "program") == "program":
|
||||
env.Replace(PROGNAME="firmware")
|
||||
env.Replace(PROGSUFFIX=".elf")
|
||||
|
||||
# Configure the toolchain
|
||||
prefix = board.get("build.prefix", "")
|
||||
env.Replace(
|
||||
AR=prefix + "gcc-ar",
|
||||
@@ -42,11 +38,6 @@ env.Replace(
|
||||
SIZETOOL=prefix + "size",
|
||||
)
|
||||
|
||||
# Default environment options
|
||||
env.AddDefaults(platform, board)
|
||||
# Flash layout defines
|
||||
env.AddFlashLayout(board)
|
||||
|
||||
# Family builders details:
|
||||
# - call env.AddLibrary("lib name", "base dir", [sources]) to add lib sources
|
||||
# - call env.BuildLibraries() to build lib targets with safe envs
|
||||
@@ -63,6 +54,7 @@ env.AddFlashLayout(board)
|
||||
# - env.BuildLibraries()
|
||||
# - # Main firmware outputs and actions
|
||||
|
||||
# Framework builder (base.py/arduino.py) is executed in BuildProgram()
|
||||
target_elf = env.BuildProgram()
|
||||
targets = [target_elf]
|
||||
|
||||
|
||||
@@ -2,12 +2,32 @@
|
||||
|
||||
from os.path import isfile
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
env: Environment = DefaultEnvironment()
|
||||
|
||||
|
||||
def env_load_config(env, path):
|
||||
def env_load_defines(env: Environment, path: str):
|
||||
path = env.subst(path)
|
||||
if not isfile(path):
|
||||
raise FileNotFoundError(f"Defines file not found ({path})")
|
||||
f = open(path, "r", encoding="utf-8")
|
||||
for line in f:
|
||||
line: str
|
||||
if not line.startswith("#define"):
|
||||
continue
|
||||
line = line[7:].strip()
|
||||
line = line.split(None, 2)
|
||||
if len(line) == 1:
|
||||
env.Append(CPPDEFINES=[(line[0], "1")])
|
||||
elif len(line) == 2:
|
||||
env.Append(CPPDEFINES=[(line[0], line[1])])
|
||||
else:
|
||||
raise ValueError(f"Unknown directive: {line}")
|
||||
f.close()
|
||||
|
||||
|
||||
def env_load_config(env: Environment, path: str):
|
||||
path = env.subst(path)
|
||||
if not isfile(path):
|
||||
raise FileNotFoundError(f"Config file not found ({path})")
|
||||
@@ -35,7 +55,7 @@ def env_load_config(env, path):
|
||||
f.close()
|
||||
|
||||
|
||||
def env_get_config(env, key):
|
||||
def env_get_config(env: Environment, key: str):
|
||||
config: dict = env["CONFIG"]
|
||||
if not config:
|
||||
return None
|
||||
@@ -45,6 +65,7 @@ def env_get_config(env, key):
|
||||
return value
|
||||
|
||||
|
||||
env.AddMethod(env_load_defines, "LoadDefines")
|
||||
env.AddMethod(env_load_config, "LoadConfig")
|
||||
env.AddMethod(env_get_config, "Cfg")
|
||||
env.AddMethod(env_get_config, "GetConfig")
|
||||
|
||||
90
builder/utils/cores.py
Normal file
90
builder/utils/cores.py
Normal file
@@ -0,0 +1,90 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2023-02-26.
|
||||
|
||||
from os.path import isdir, join
|
||||
|
||||
from ltchiptool import Family
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env: Environment = DefaultEnvironment()
|
||||
|
||||
|
||||
def env_add_family(env: Environment, family: Family) -> str:
|
||||
if family.short_name:
|
||||
env.Prepend(CPPDEFINES=[(f"LT_{family.short_name}", "1")])
|
||||
if family.code:
|
||||
env.Prepend(CPPDEFINES=[(f"LT_{family.code.upper()}", "1")])
|
||||
path = join("$CORES_DIR", family.name)
|
||||
if not isdir(env.subst(path)):
|
||||
return path
|
||||
env.Prepend(
|
||||
LIBPATH=[join(path, "misc")],
|
||||
)
|
||||
return path
|
||||
|
||||
|
||||
def env_add_core_config(env: Environment, name: str, path: str) -> bool:
|
||||
if not isdir(env.subst(path)):
|
||||
return False
|
||||
env.Prepend(
|
||||
CPPPATH=[join(path, "config")],
|
||||
LIBPATH=[join(path, "fixups")],
|
||||
)
|
||||
try:
|
||||
env.LoadDefines(join(path, "lt_defs.h"))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
env.AddLibrary(
|
||||
name=f"core_{name}_fixups",
|
||||
base_dir=path,
|
||||
srcs=[
|
||||
"+<fixups/*.c*>",
|
||||
],
|
||||
includes=[
|
||||
"!<fixups>",
|
||||
],
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def env_add_core_sources(env: Environment, name: str, path: str) -> bool:
|
||||
if not isdir(env.subst(path)):
|
||||
return False
|
||||
env.AddLibrary(
|
||||
name=f"core_{name}",
|
||||
base_dir=path,
|
||||
srcs=[
|
||||
"+<*.c*>",
|
||||
"+<common/*.c*>",
|
||||
"+<compat/*.c*>",
|
||||
"+<posix/*.c>",
|
||||
"+<wraps/*.c>",
|
||||
],
|
||||
includes=[
|
||||
# prepend the paths before SDK directories
|
||||
"!<.>",
|
||||
"!<compat>",
|
||||
],
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def env_add_arduino_libraries(env: Environment, name: str, path: str) -> bool:
|
||||
if not isdir(env.subst(path)):
|
||||
return False
|
||||
env.AddLibrary(
|
||||
name=f"core_{name}_libraries",
|
||||
base_dir=path,
|
||||
srcs=[
|
||||
"+<**/*.c*>",
|
||||
],
|
||||
includes=[
|
||||
"!<*>",
|
||||
],
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
env.AddMethod(env_add_family, "AddFamily")
|
||||
env.AddMethod(env_add_core_config, "AddCoreConfig")
|
||||
env.AddMethod(env_add_core_sources, "AddCoreSources")
|
||||
env.AddMethod(env_add_arduino_libraries, "AddArduinoLibraries")
|
||||
@@ -1,16 +1,19 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-05-04.
|
||||
|
||||
import json
|
||||
import sys
|
||||
from os.path import isdir, join
|
||||
from subprocess import PIPE, Popen
|
||||
|
||||
from ltchiptool import Family
|
||||
from SCons.Script import DefaultEnvironment
|
||||
from platformio.platform.base import PlatformBase
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
env: Environment = DefaultEnvironment()
|
||||
|
||||
|
||||
def read_version(platform_dir: str, version: str):
|
||||
def env_read_version(env: Environment, platform_dir: str, version: str):
|
||||
if not isdir(join(platform_dir, ".git")):
|
||||
sys.stderr.write("Warning! Non-Git installations are NOT SUPPORTED.\n")
|
||||
return version
|
||||
@@ -47,33 +50,27 @@ def read_version(platform_dir: str, version: str):
|
||||
return f"{version}+{build_str}" if build_str else version
|
||||
|
||||
|
||||
def env_add_defaults(env, platform, board):
|
||||
def env_configure(env: Environment, platform: PlatformBase, board: PlatformBoardConfig):
|
||||
# Read external libraries list
|
||||
with open(join(platform.get_dir(), "external-libs.json")) as f:
|
||||
external_libs = json.load(f)
|
||||
# Get Family object for this board
|
||||
family = Family.get(short_name=board.get("build.family"))
|
||||
# Default environment variables
|
||||
vars = dict(
|
||||
SDK_DIR=platform.get_package_dir(family.framework),
|
||||
env.Replace(
|
||||
SDK_DIR=platform.get_package_dir(board.get("package")),
|
||||
LT_DIR=platform.get_dir(),
|
||||
# Root dirs
|
||||
CORES_DIR=join("${LT_DIR}", "cores"),
|
||||
COMMON_DIR=join("${LT_DIR}", "cores", "common"),
|
||||
# Build directories & paths
|
||||
BOARD_DIR=join("${LT_DIR}", "boards", "${VARIANT}"),
|
||||
ARDUINO_DIRS={
|
||||
"$FAMILY_CODE": join("${LT_DIR}", "arduino", "${FAMILY_NAME}"),
|
||||
"$FAMILY_PARENT_CODE": join("${LT_DIR}", "arduino", "${FAMILY_PARENT}"),
|
||||
},
|
||||
FAMILY_DIR=join("${LT_DIR}", "platform", "${FAMILY_NAME}"),
|
||||
PARENT_DIR=join("${LT_DIR}", "platform", "${FAMILY_PARENT}"),
|
||||
TOOLS_DIR=join("${LT_DIR}", "tools"),
|
||||
# Family-specific paths
|
||||
BIN_DIR=join("${FAMILY_DIR}", "bin"),
|
||||
OPENOCD_DIR=join("${FAMILY_DIR}", "openocd"),
|
||||
# Use SDK linker script by default
|
||||
LDSCRIPT_PATH=["${LDSCRIPT_SDK}"],
|
||||
FAMILY_DIR=join("${LT_DIR}", "cores", "${FAMILY_NAME}"),
|
||||
MISC_DIR=join("${FAMILY_DIR}", "misc"),
|
||||
LDSCRIPT_PATH=[board.get("build.ldscript")],
|
||||
# Board config variables
|
||||
MCU=board.get("build.mcu").upper(),
|
||||
MCULC=board.get("build.mcu"),
|
||||
MCULC=board.get("build.mcu").lower(),
|
||||
VARIANT=board.get("build.variant"),
|
||||
LDSCRIPT_SDK=board.get("build.ldscript_sdk"),
|
||||
LDSCRIPT_ARDUINO=board.get("build.ldscript_arduino"),
|
||||
# ltchiptool config:
|
||||
# -r output raw log messages
|
||||
# -i 1 indent log messages
|
||||
@@ -81,42 +78,13 @@ def env_add_defaults(env, platform, board):
|
||||
# Fix for link2bin to get tmpfile name in argv
|
||||
LINKCOM="${LINK} ${LINKARGS}",
|
||||
LINKARGS="${TEMPFILE('-o $TARGET $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS', '$LINKCOMSTR')}",
|
||||
# Store the family object
|
||||
FAMILY_OBJ=family,
|
||||
EXTERNAL_LIBS=external_libs,
|
||||
)
|
||||
env.Replace(**vars)
|
||||
# Store family parameters as environment variables
|
||||
env.Replace(**dict(family))
|
||||
# Default build options
|
||||
env.Prepend(
|
||||
CPPPATH=[
|
||||
"$LT_DIR/platform/common/config",
|
||||
"$LT_DIR/platform/common/fixups",
|
||||
"$LT_DIR/platform/common/fixups/lib_inc",
|
||||
"$BOARD_DIR",
|
||||
"$FAMILY_DIR/config",
|
||||
"$PARENT_DIR/config",
|
||||
"$FAMILY_DIR/fixups",
|
||||
"$PARENT_DIR/fixups",
|
||||
"$FAMILY_DIR/fixups/inc",
|
||||
"$PARENT_DIR/fixups/inc",
|
||||
],
|
||||
LIBPATH=[
|
||||
"$FAMILY_DIR/ld",
|
||||
"$PARENT_DIR/ld",
|
||||
"$FAMILY_DIR/fixups",
|
||||
"$PARENT_DIR/fixups",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
("LIBRETUYA", "1"),
|
||||
("LT_VERSION", read_version(platform.get_dir(), platform.version)),
|
||||
("LT_BOARD", "${VARIANT}"),
|
||||
("F_CPU", board.get("build.f_cpu")),
|
||||
("MCU", "${MCU}"),
|
||||
("FAMILY", "F_${FAMILY}"),
|
||||
],
|
||||
LINKFLAGS=[
|
||||
'"-Wl,-Map=' + join("$BUILD_DIR", "${PROGNAME}.map") + '"',
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
env.AddMethod(env_add_defaults, "AddDefaults")
|
||||
env.AddMethod(env_configure, "ConfigureEnvironment")
|
||||
env.AddMethod(env_read_version, "ReadLTVersion")
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-06-12.
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
env: Environment = DefaultEnvironment()
|
||||
|
||||
|
||||
def env_add_flash_layout(env, board):
|
||||
def env_add_flash_layout(env: Environment, board):
|
||||
flash_layout: dict = board.get("flash")
|
||||
if flash_layout:
|
||||
defines = {}
|
||||
|
||||
61
builder/utils/libs-external.py
Normal file
61
builder/utils/libs-external.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2023-02-26.
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Optional, Union
|
||||
|
||||
from platformio.package.meta import PackageItem
|
||||
from platformio.platform.base import PlatformBase
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env: Environment = DefaultEnvironment()
|
||||
platform: PlatformBase = env.PioPlatform()
|
||||
|
||||
|
||||
@dataclass
|
||||
class Library:
|
||||
package: str
|
||||
sources: List[str]
|
||||
includes: List[str]
|
||||
flags: List[str] = None
|
||||
linkflags: List[str] = None
|
||||
defines: Dict[str, Union[str, int]] = None
|
||||
|
||||
def __post_init__(self):
|
||||
self.flags = self.flags or []
|
||||
self.linkflags = self.linkflags or []
|
||||
self.defines = self.defines or {}
|
||||
|
||||
|
||||
def env_add_external_library(
|
||||
env: Environment,
|
||||
name: str,
|
||||
port: Optional[str] = None,
|
||||
):
|
||||
if port:
|
||||
name += f"-{port}"
|
||||
external_libs = env["EXTERNAL_LIBS"]
|
||||
lib = Library(**external_libs[name])
|
||||
version = platform.versions.get(lib.package, None)
|
||||
|
||||
package: PackageItem = platform.pm.get_package(
|
||||
platform.get_package_spec(lib.package, version)
|
||||
)
|
||||
if not package:
|
||||
raise ValueError(
|
||||
f"Version '{version}' of library '{name}' ({lib.package}) is not installed"
|
||||
)
|
||||
|
||||
env.AddLibrary(
|
||||
name=name.replace("-", "_"),
|
||||
base_dir=package.path,
|
||||
srcs=lib.sources,
|
||||
includes=lib.includes,
|
||||
options=dict(
|
||||
CFLAGS=lib.flags,
|
||||
CPPDEFINES=[(k, v) for k, v in lib.defines.items()],
|
||||
LINKFLAGS=lib.linkflags,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
env.AddMethod(env_add_external_library, "AddExternalLibrary")
|
||||
@@ -5,14 +5,22 @@ from glob import glob
|
||||
from os.path import isdir, join
|
||||
from typing import Dict, Generator, List, Tuple
|
||||
|
||||
from SCons.Script import DefaultEnvironment
|
||||
from SCons.Script import DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
env: Environment = DefaultEnvironment()
|
||||
|
||||
|
||||
def add_base_dir(env, base_dir: str, expressions: List[str], subst: bool = False):
|
||||
def add_base_dir(
|
||||
env: Environment,
|
||||
base_dir: str,
|
||||
expressions: List[str],
|
||||
subst: bool = False,
|
||||
):
|
||||
out = []
|
||||
for expr in expressions:
|
||||
if expr == False:
|
||||
# support '[cond] and [path]' logical expressions
|
||||
continue
|
||||
if expr[1] != "<" or expr[-1] != ">":
|
||||
raise ValueError(f"Not a valid glob: {expr}")
|
||||
if expr[2] == "$":
|
||||
@@ -35,7 +43,7 @@ def iter_expressions(expressions: List[str]) -> Generator[Tuple[str, str], None,
|
||||
|
||||
|
||||
def env_add_library(
|
||||
env,
|
||||
env: Environment,
|
||||
name: str,
|
||||
base_dir: str,
|
||||
srcs: List[str],
|
||||
@@ -77,7 +85,7 @@ def env_add_library(
|
||||
env.Append(CPPPATH=[item])
|
||||
|
||||
|
||||
def env_build_libraries(env, safe: bool = True):
|
||||
def env_build_libraries(env: Environment, safe: bool = True):
|
||||
# add lib targets and clone safe envs
|
||||
if not "LIBQUEUE" in env:
|
||||
return
|
||||
|
||||
@@ -4,13 +4,14 @@ import sys
|
||||
from datetime import datetime
|
||||
from os.path import basename, join, normpath
|
||||
|
||||
from SCons.Script import Builder, DefaultEnvironment
|
||||
from platformio.platform.base import PlatformBase
|
||||
from SCons.Script import Builder, DefaultEnvironment, Environment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
env: Environment = DefaultEnvironment()
|
||||
platform: PlatformBase = env.PioPlatform()
|
||||
|
||||
|
||||
def env_uf2ota(env, *args, **kwargs):
|
||||
def env_uf2ota(env: Environment, *args, **kwargs):
|
||||
now = datetime.now()
|
||||
project_dir = env.subst("$PROJECT_DIR")
|
||||
project_name = basename(normpath(project_dir))
|
||||
@@ -53,7 +54,7 @@ def env_uf2ota(env, *args, **kwargs):
|
||||
env.Execute(" ".join(cmd))
|
||||
|
||||
|
||||
def env_flash_write(env, target):
|
||||
def env_flash_write(env: Environment, target):
|
||||
protocol = env.subst("${UPLOAD_PROTOCOL}")
|
||||
actions = []
|
||||
# from platform-espressif32/builder/main.py
|
||||
|
||||
6
cores/beken-72xx/arduino/src/lt_defs.h
Normal file
6
cores/beken-72xx/arduino/src/lt_defs.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#error "Don't include this file directly"
|
||||
|
||||
#define LT_ARD_HAS_WIFI 1
|
||||
#define LT_ARD_HAS_MD5 1
|
||||
8
cores/beken-72xx/base/lt_defs.h
Normal file
8
cores/beken-72xx/base/lt_defs.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#error "Don't include this file directly"
|
||||
|
||||
#define LT_HAS_LWIP 1
|
||||
#define LT_HAS_LWIP2 1
|
||||
#define LT_HAS_FREERTOS 1
|
||||
#define LT_HAS_MBEDTLS 1
|
||||
@@ -1,5 +1,7 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2022-07-01. */
|
||||
|
||||
#if 0
|
||||
|
||||
#include <param_config.h>
|
||||
#include <wlan_ui_pub.h>
|
||||
|
||||
@@ -26,3 +28,5 @@ void __wrap_bk_wlan_sta_init_adv(network_InitTypeDef_adv_st *inNetworkInitParaAd
|
||||
}
|
||||
g_sta_param_ptr->fast_connect_set = fast_connect;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
15
cores/realtek-amb/arduino/src/lt_defs.h
Normal file
15
cores/realtek-amb/arduino/src/lt_defs.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#error "Don't include this file directly"
|
||||
|
||||
#define LT_ARD_HAS_WIFI 1
|
||||
#define LT_ARD_HAS_MD5 1
|
||||
#define LT_ARD_HAS_SOFTSERIAL 1
|
||||
|
||||
#define ARDUINO_AMEBA
|
||||
#define ARDUINO_ARCH_AMBZ
|
||||
|
||||
// the SDK declares bool if not defined before
|
||||
// which conflicts with C++ built-in bool
|
||||
// so it's either -fpermissive or this:
|
||||
#define bool bool
|
||||
8
cores/realtek-ambz/base/lt_defs.h
Normal file
8
cores/realtek-ambz/base/lt_defs.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#error "Don't include this file directly"
|
||||
|
||||
#define LT_HAS_LWIP 1
|
||||
#define LT_HAS_LWIP2 1
|
||||
#define LT_HAS_FREERTOS 1
|
||||
#define LT_HAS_MBEDTLS 1
|
||||
8
cores/realtek-ambz2/base/lt_defs.h
Normal file
8
cores/realtek-ambz2/base/lt_defs.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#error "Don't include this file directly"
|
||||
|
||||
#define LT_HAS_LWIP 1
|
||||
#define LT_HAS_LWIP2 1
|
||||
#define LT_HAS_FREERTOS 1
|
||||
#define LT_HAS_MBEDTLS 1
|
||||
101
external-libs.json
Normal file
101
external-libs.json
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"$schema": "./external-libs.schema.json",
|
||||
"flashdb": {
|
||||
"package": "library-flashdb",
|
||||
"sources": [
|
||||
"+<src/*.c>",
|
||||
"+<port/fal/src/*.c>"
|
||||
],
|
||||
"includes": [
|
||||
"+<inc>",
|
||||
"+<port/fal/inc>"
|
||||
]
|
||||
},
|
||||
"printf": {
|
||||
"package": "library-printf",
|
||||
"sources": [
|
||||
"+<src/printf/printf.c>"
|
||||
],
|
||||
"includes": [
|
||||
"+<src>"
|
||||
],
|
||||
"flags": [
|
||||
"-Wno-maybe-uninitialized"
|
||||
],
|
||||
"linkflags": [
|
||||
"-Wl,-wrap,printf",
|
||||
"-Wl,-wrap,sprintf",
|
||||
"-Wl,-wrap,vsprintf",
|
||||
"-Wl,-wrap,snprintf",
|
||||
"-Wl,-wrap,vsnprintf",
|
||||
"-Wl,-wrap,vprintf",
|
||||
"-Wl,-wrap,puts",
|
||||
"-Wl,-wrap,putchar"
|
||||
],
|
||||
"defines": {
|
||||
"PRINTF_INCLUDE_CONFIG_H": "1"
|
||||
}
|
||||
},
|
||||
"ltchiptool": {
|
||||
"package": "tool-ltchiptool",
|
||||
"sources": [
|
||||
"+<uf2ota/*.c>"
|
||||
],
|
||||
"includes": [
|
||||
"+<.>"
|
||||
]
|
||||
},
|
||||
"arduino_api": {
|
||||
"package": "framework-arduino-api",
|
||||
"sources": [
|
||||
"+<api/Common.cpp>",
|
||||
"+<api/IPAddress.cpp>",
|
||||
"+<api/PluggableUSB.cpp>",
|
||||
"+<api/Print.cpp>",
|
||||
"+<api/Stream.cpp>",
|
||||
"+<api/String.cpp>"
|
||||
],
|
||||
"includes": [
|
||||
"+<.>",
|
||||
"+<api/deprecated>"
|
||||
]
|
||||
},
|
||||
"lwip-amb1": {
|
||||
"package": "library-lwip",
|
||||
"sources": [
|
||||
"+<src/api/*.c>",
|
||||
"+<src/core/*.c>",
|
||||
"+<src/core/ipv4/*.c>",
|
||||
"+<src/netif/ethernet.c>",
|
||||
"+<src/netif/etharp.c>",
|
||||
"+<src/apps/mdns/mdns.c>",
|
||||
"+<src/apps/sntp/sntp.c>",
|
||||
"+<port/realtek/freertos/ethernetif.c>",
|
||||
"+<port/realtek/freertos/sys_arch.c>"
|
||||
],
|
||||
"includes": [
|
||||
"+<src/include>",
|
||||
"+<src/include/ipv4>",
|
||||
"+<port/realtek>",
|
||||
"+<port/realtek/freertos>"
|
||||
]
|
||||
},
|
||||
"lwip-bdk": {
|
||||
"package": "library-lwip",
|
||||
"sources": [
|
||||
"+<src/api/*.c>",
|
||||
"+<src/core/*.c>",
|
||||
"+<src/core/ipv4/*.c>",
|
||||
"+<src/netif/ethernet.c>",
|
||||
"+<src/netif/etharp.c>",
|
||||
"+<src/apps/mdns/mdns.c>",
|
||||
"+<src/apps/sntp/sntp.c>",
|
||||
"+<port/*.c>"
|
||||
],
|
||||
"includes": [
|
||||
"+<src/include>",
|
||||
"+<src/include/ipv4>",
|
||||
"+<port>"
|
||||
]
|
||||
}
|
||||
}
|
||||
65
external-libs.schema.json
Normal file
65
external-libs.schema.json
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"$schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"patternProperties": {
|
||||
"^[a-z0-9-_]+$": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"package": {
|
||||
"type": "string",
|
||||
"pattern": "^(tool|library|framework)-[a-z0-9-]+$"
|
||||
},
|
||||
"sources": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"pattern": "^[!+-]<[\\w/*.]+>$"
|
||||
}
|
||||
},
|
||||
"includes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"pattern": "^[!+-]<[\\w/*.]+>$"
|
||||
}
|
||||
},
|
||||
"flags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"pattern": "^[^\\s]+$"
|
||||
}
|
||||
},
|
||||
"linkflags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"pattern": "^[^\\s]+$"
|
||||
}
|
||||
},
|
||||
"defines": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[A-Za-z0-9_]+$": {
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"package",
|
||||
"sources",
|
||||
"includes"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
"description": "Realtek AmebaZ",
|
||||
"id": "0x22E0D6FC",
|
||||
"short_name": "RTL8710B",
|
||||
"package": "framework-realtek-amb1",
|
||||
"mcus": [
|
||||
"RTL8710BN",
|
||||
"RTL8710BX"
|
||||
@@ -30,6 +31,7 @@
|
||||
"description": "Realtek AmebaZ2",
|
||||
"id": "0xE08F7564",
|
||||
"short_name": "RTL8720C",
|
||||
"package": "framework-realtek-ambz2",
|
||||
"mcus": [
|
||||
"RTL8720CF"
|
||||
]
|
||||
@@ -50,7 +52,8 @@
|
||||
"beken-72xx-gen1": {
|
||||
"parent": "beken-72xx",
|
||||
"code": "bk72xxgen1",
|
||||
"description": "Beken 72xx (ARM)"
|
||||
"description": "Beken 72xx (ARM)",
|
||||
"package": "framework-beken-bdk"
|
||||
},
|
||||
"beken-72xx-gen2": {
|
||||
"parent": "beken-72xx",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
},
|
||||
"patternProperties": {
|
||||
"^[a-z0-9-]+$": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"parent": {
|
||||
"type": [
|
||||
@@ -30,6 +31,10 @@
|
||||
"type": "string",
|
||||
"pattern": "^[A-Z0-9]+$"
|
||||
},
|
||||
"package": {
|
||||
"type": "string",
|
||||
"pattern": "^framework-[a-z0-9-]+$"
|
||||
},
|
||||
"mcus": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -8,34 +8,13 @@
|
||||
},
|
||||
"version": "0.12.6",
|
||||
"frameworks": {
|
||||
"base": {
|
||||
"title": "Base Framework (SDK only)",
|
||||
"script": "builder/frameworks/base.py"
|
||||
},
|
||||
"arduino": {
|
||||
"title": "Generic Arduino framework",
|
||||
"title": "Arduino Framework",
|
||||
"script": "builder/frameworks/arduino.py"
|
||||
},
|
||||
"realtek-ambz-sdk": {
|
||||
"tilte": "Realtek AmebaZ - SDK",
|
||||
"package": "framework-realtek-amb1",
|
||||
"script": "builder/frameworks/realtek-ambz-sdk.py"
|
||||
},
|
||||
"realtek-ambz-arduino": {
|
||||
"tilte": "Realtek AmebaZ - Arduino",
|
||||
"package": "framework-realtek-amb1",
|
||||
"script": "builder/frameworks/realtek-ambz-arduino.py"
|
||||
},
|
||||
"realtek-ambz2-sdk": {
|
||||
"tilte": "Realtek AmebaZ2 - SDK",
|
||||
"package": "framework-realtek-ambz2",
|
||||
"script": "builder/frameworks/realtek-ambz2-sdk.py"
|
||||
},
|
||||
"beken-72xx-sdk": {
|
||||
"title": "Beken 72XX - SDK",
|
||||
"package": "framework-beken-bdk",
|
||||
"script": "builder/frameworks/beken-72xx-sdk.py"
|
||||
},
|
||||
"beken-72xx-arduino": {
|
||||
"title": "Beken 72XX - Arduino",
|
||||
"package": "framework-beken-bdk",
|
||||
"script": "builder/frameworks/beken-72xx-arduino.py"
|
||||
}
|
||||
},
|
||||
"packages": {
|
||||
@@ -43,21 +22,26 @@
|
||||
"type": "framework",
|
||||
"optional": true,
|
||||
"version": "https://github.com/libretuya/framework-realtek-amb1#v2022.06.21",
|
||||
"version_prefix": true,
|
||||
"toolchains": {
|
||||
"x86_64": "gccarmnoneeabi@~1.50201.0",
|
||||
"arm": "gccarmnoneeabi@~1.50401.211104",
|
||||
"arm64": "gccarmnoneeabi@~1.50401.210715"
|
||||
},
|
||||
"libraries": {
|
||||
"lwip": [
|
||||
"v2.1.3-amb1"
|
||||
]
|
||||
"lwip": {
|
||||
"1.4.1": "1.4.1-amb1",
|
||||
"2.0.0": "2.0.0-amb1",
|
||||
"2.1.3": "2.1.3-amb1",
|
||||
"default": "2.1.3-amb1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"framework-realtek-ambz2": {
|
||||
"type": "framework",
|
||||
"optional": true,
|
||||
"version": "https://github.com/libretuya/framework-realtek-ambz2#v2022.11.17",
|
||||
"version_prefix": true,
|
||||
"toolchains": {
|
||||
"x86_64": "gccarmnoneeabi@~1.100301.0",
|
||||
"arm": "gccarmnoneeabi@~1.100301.0",
|
||||
@@ -68,56 +52,39 @@
|
||||
"type": "framework",
|
||||
"optional": true,
|
||||
"version": "https://github.com/libretuya/framework-beken-bdk#v2021.06.07",
|
||||
"version_prefix": true,
|
||||
"toolchains": {
|
||||
"x86_64":"gccarmnoneeabi@~1.40804.0",
|
||||
"x86_64": "gccarmnoneeabi@~1.40804.0",
|
||||
"arm": "gccarmnoneeabi@~1.40803.0",
|
||||
"arm64": "gccarmnoneeabi@~1.40803.0"
|
||||
},
|
||||
"libraries": {
|
||||
"lwip": [
|
||||
"v2.1.3-bdk"
|
||||
]
|
||||
"lwip": {
|
||||
"2.0.2": "2.0.2-bdk",
|
||||
"2.1.0": "2.1.0-bdk",
|
||||
"2.1.3": "2.1.3-bdk",
|
||||
"default": "2.1.3-bdk"
|
||||
}
|
||||
}
|
||||
},
|
||||
"framework-arduino-api": {
|
||||
"type": "framework",
|
||||
"optional": true,
|
||||
"version": "https://github.com/libretuya/ArduinoCore-API#3a4cbfc",
|
||||
"manifest": {
|
||||
"description": "Hardware independent layer of the Arduino cores"
|
||||
},
|
||||
"libraries": {
|
||||
"flashdb": [
|
||||
"03500fa"
|
||||
],
|
||||
"printf": [
|
||||
"v6.0.0"
|
||||
]
|
||||
}
|
||||
"version": "https://github.com/libretuya/ArduinoCore-API#2022.08.24"
|
||||
},
|
||||
"library-lwip": {
|
||||
"type": "framework",
|
||||
"optional": true,
|
||||
"base_url": "https://github.com/libretuya/lwip",
|
||||
"manifest": {
|
||||
"description": "lwIP - A Lightweight TCPIP stack"
|
||||
}
|
||||
"version_prefix": true
|
||||
},
|
||||
"library-flashdb": {
|
||||
"type": "framework",
|
||||
"optional": true,
|
||||
"base_url": "https://github.com/armink/FlashDB",
|
||||
"manifest": {
|
||||
"description": "An ultra-lightweight database that supports key-value and time series data"
|
||||
}
|
||||
"version": "https://github.com/libretuya/library-flashdb#1.2.0"
|
||||
},
|
||||
"library-printf": {
|
||||
"type": "framework",
|
||||
"optional": true,
|
||||
"base_url": "https://github.com/eyalroz/printf",
|
||||
"manifest": {
|
||||
"description": "Tiny, fast(ish), self-contained and fully loaded printf, sprinf etc. implementation, mainly for embedded systems."
|
||||
}
|
||||
"version": "https://github.com/libretuya/library-printf#6.1.0"
|
||||
},
|
||||
"toolchain-gccarmnoneeabi": {
|
||||
"type": "toolchain",
|
||||
@@ -131,6 +98,7 @@
|
||||
"tool-ltchiptool": {
|
||||
"type": "uploader",
|
||||
"version": "https://github.com/libretuya/ltchiptool#v2.0.2",
|
||||
"version_prefix": true,
|
||||
"note": "This is used only for C/C++ code from ltchiptool."
|
||||
},
|
||||
"tool-openocd": {
|
||||
|
||||
233
platform.py
233
platform.py
@@ -1,18 +1,16 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-04-20.
|
||||
|
||||
import importlib
|
||||
import json
|
||||
import platform
|
||||
import sys
|
||||
from os import system
|
||||
from os.path import dirname, join
|
||||
from os.path import dirname
|
||||
from typing import Dict
|
||||
|
||||
import click
|
||||
from platformio.debug.config.base import DebugConfigBase
|
||||
from platformio.debug.exception import DebugInvalidOptionsError
|
||||
from platformio.package.exception import MissingPackageManifestError
|
||||
from platformio.package.manager.base import BasePackageManager
|
||||
from platformio.package.meta import PackageItem, PackageSpec
|
||||
from platformio.package.meta import PackageItem
|
||||
from platformio.platform.base import PlatformBase
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
from semantic_version import SimpleSpec, Version
|
||||
@@ -75,103 +73,61 @@ if dirname(__file__) in sys.path:
|
||||
# Let ltchiptool know about LT's location
|
||||
ltchiptool.lt_set_path(dirname(__file__))
|
||||
|
||||
libretuya_packages = None
|
||||
manifest_default = {"version": "0.0.0", "description": "", "keywords": []}
|
||||
|
||||
|
||||
def load_manifest(self, src):
|
||||
try:
|
||||
return BasePackageManager._load_manifest(self, src)
|
||||
except MissingPackageManifestError:
|
||||
# ignore all exceptions
|
||||
pass
|
||||
# get the installation temporary path
|
||||
path = src.path if isinstance(src, PackageItem) else src
|
||||
# raise the exception if this package is not from libretuya
|
||||
if (
|
||||
not hasattr(self, "spec_map")
|
||||
or path not in self.spec_map
|
||||
or not libretuya_packages
|
||||
):
|
||||
raise MissingPackageManifestError(", ".join(self.manifest_names))
|
||||
# get the saved spec
|
||||
spec: PackageSpec = self.spec_map[path]
|
||||
# read package data from platform.json
|
||||
manifest: dict = libretuya_packages[spec.name]
|
||||
# find additional manifest info
|
||||
manifest = manifest.get("manifest", manifest_default)
|
||||
# extract tag version
|
||||
url = getattr(spec, "url", None) or getattr(spec, "uri", None) or ""
|
||||
if "#" in url:
|
||||
manifest["version"] = url.rpartition("#")[2].lstrip("v")
|
||||
# put info from spec
|
||||
manifest.update(
|
||||
{
|
||||
"name": spec.name,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": url,
|
||||
},
|
||||
}
|
||||
)
|
||||
# save in cache
|
||||
cache_key = "load_manifest-%s" % path
|
||||
self.memcache_set(cache_key, manifest)
|
||||
# result = ManifestParserFactory.new(json.dumps(manifest), ManifestFileType.PACKAGE_JSON).as_dict()
|
||||
with open(join(path, self.manifest_names[0]), "w") as f:
|
||||
json.dump(manifest, f)
|
||||
return manifest
|
||||
|
||||
|
||||
def find_pkg_root(self, path: str, spec: PackageSpec):
|
||||
try:
|
||||
return BasePackageManager._find_pkg_root(self, path, spec)
|
||||
except MissingPackageManifestError as e:
|
||||
# raise the exception if this package is not from libretuya
|
||||
if not libretuya_packages or spec.name not in libretuya_packages:
|
||||
raise e
|
||||
# save the spec for later
|
||||
if not hasattr(self, "spec_map"):
|
||||
self.spec_map = {}
|
||||
self.spec_map[path] = spec
|
||||
return path
|
||||
|
||||
|
||||
class LibretuyaPlatform(PlatformBase):
|
||||
boards_base: Dict[str, dict] = {}
|
||||
custom_opts: Dict[str, object] = {}
|
||||
custom_opts: Dict[str, object] = None
|
||||
versions: Dict[str, str] = None
|
||||
|
||||
def __init__(self, manifest_path):
|
||||
super().__init__(manifest_path)
|
||||
self.custom_opts = {}
|
||||
self.versions = {}
|
||||
|
||||
def configure_default_packages(self, options, targets):
|
||||
# patch find_pkg root to ignore missing manifests and save PackageSpec
|
||||
if not hasattr(BasePackageManager, "_find_pkg_root"):
|
||||
BasePackageManager._find_pkg_root = BasePackageManager.find_pkg_root
|
||||
BasePackageManager.find_pkg_root = find_pkg_root
|
||||
# patch load_manifest to generate manifests from PackageSpec
|
||||
if not hasattr(BasePackageManager, "_load_manifest"):
|
||||
BasePackageManager._load_manifest = BasePackageManager.load_manifest
|
||||
BasePackageManager.load_manifest = load_manifest
|
||||
from ltchiptool.util.dict import RecursiveDict
|
||||
|
||||
pioframework = options.get("pioframework")
|
||||
if not pioframework:
|
||||
return
|
||||
framework = pioframework[0]
|
||||
framework: str = pioframework[0]
|
||||
|
||||
# allow using "arduino" as framework
|
||||
if framework == "arduino":
|
||||
board = self.get_boards(options.get("board"))
|
||||
frameworks = board.get("frameworks")
|
||||
framework = next(fw for fw in frameworks if framework in fw)
|
||||
options.get("pioframework")[0] = framework
|
||||
# save custom options from env
|
||||
self.custom_opts = RecursiveDict()
|
||||
for key, value in options.items():
|
||||
if not key.startswith("custom_"):
|
||||
continue
|
||||
self.custom_opts[key[7:]] = value
|
||||
|
||||
# update framework names to their new values since v1.0.0
|
||||
if framework.endswith("-sdk"):
|
||||
click.secho(
|
||||
f"Framework '{framework}' is now named 'base'. "
|
||||
"Update your platformio.ini to use the new name, then try again.",
|
||||
fg="red",
|
||||
)
|
||||
exit(1)
|
||||
if framework.endswith("-arduino"):
|
||||
click.secho(
|
||||
f"Framework '{framework}' is now named 'arduino'. "
|
||||
"Update your platformio.ini to use the new name, then try again.",
|
||||
fg="red",
|
||||
)
|
||||
exit(1)
|
||||
options.get("pioframework")[0] = framework
|
||||
|
||||
# make ArduinoCore-API required
|
||||
if "arduino" in framework:
|
||||
if framework == "arduino":
|
||||
self.packages["framework-arduino-api"]["optional"] = False
|
||||
|
||||
framework_obj = self.frameworks[framework]
|
||||
if "package" in framework_obj:
|
||||
package_obj = self.packages[framework_obj["package"]]
|
||||
else:
|
||||
package_obj = {}
|
||||
# get framework SDK package
|
||||
board = self.get_boards(options.get("board"))
|
||||
package = board.get("package")
|
||||
package_obj = self.packages.get(package, {})
|
||||
# mark framework SDK as required
|
||||
package_obj["optional"] = False
|
||||
|
||||
# get user-chosen versions of libraries/toolchains
|
||||
versions: RecursiveDict = self.custom("versions") or {}
|
||||
|
||||
# set specific compiler versions
|
||||
if "toolchains" in package_obj:
|
||||
@@ -182,49 +138,75 @@ class LibretuyaPlatform(PlatformBase):
|
||||
(toolchain, version) = toolchains["arm64"].split("@")
|
||||
else:
|
||||
(toolchain, version) = toolchains["x86_64"].split("@")
|
||||
version = versions.get("toolchain") or version
|
||||
self.packages[f"toolchain-{toolchain}"]["version"] = version
|
||||
|
||||
# mark framework SDK as required
|
||||
package_obj["optional"] = False
|
||||
|
||||
# gather library dependencies
|
||||
libraries = package_obj["libraries"] if "libraries" in package_obj else {}
|
||||
for name, package in self.packages.items():
|
||||
pkg_versions = {}
|
||||
for package in self.packages.values():
|
||||
if "optional" in package and package["optional"]:
|
||||
continue
|
||||
if "libraries" not in package:
|
||||
continue
|
||||
libraries.update(package["libraries"])
|
||||
for name, lib_versions in package["libraries"].items():
|
||||
package = f"library-{name}"
|
||||
if name in versions and versions[name] in lib_versions:
|
||||
pkg_versions[package] = lib_versions[versions[name]]
|
||||
continue
|
||||
if "default" in lib_versions:
|
||||
pkg_versions[package] = lib_versions["default"]
|
||||
|
||||
# use appropriate vendor library versions
|
||||
packages_new = {}
|
||||
for name, package in self.packages.items():
|
||||
if not name.startswith("library-"):
|
||||
# gather custom versions of other libraries
|
||||
for name, version in versions.items():
|
||||
if name == "toolchain":
|
||||
continue
|
||||
name = name[8:] # strip "library-"
|
||||
if name not in libraries:
|
||||
name = name.replace("_", "-")
|
||||
version = version.lstrip("v")
|
||||
# find the package by "library-xxx", "framework-xxx" or "tool-xxx"
|
||||
package = f"library-{name}"
|
||||
if package not in self.packages:
|
||||
package = f"framework-{name}"
|
||||
if package not in self.packages:
|
||||
package = f"tool-{name}"
|
||||
if package not in self.packages:
|
||||
click.secho(
|
||||
f"Library '{name}' couldn't be found. "
|
||||
f"Remove 'custom_versions.{name}' from platformio.ini and try again.",
|
||||
fg="red",
|
||||
)
|
||||
exit(1)
|
||||
if package in pkg_versions:
|
||||
# skip already added libs
|
||||
continue
|
||||
lib_version = libraries[name][-1] # get latest version tag
|
||||
package = dict(**package) # clone the base package
|
||||
package["version"] = (
|
||||
package["base_url"] + "#" + lib_version
|
||||
) # use the specific version
|
||||
package["optional"] = False # make it required
|
||||
lib_version = lib_version.lstrip("v") # strip "v" in target name
|
||||
name = f"library-{name}@{lib_version}"
|
||||
packages_new[name] = package # put the package under a new name
|
||||
self.packages.update(packages_new)
|
||||
pkg_versions[package] = version
|
||||
|
||||
# save platform packages for later
|
||||
global libretuya_packages
|
||||
libretuya_packages = self.packages
|
||||
# enable packages required for framework libraries
|
||||
for name, version in pkg_versions.items():
|
||||
if name not in self.packages:
|
||||
raise ValueError(f"Library '{name}' doesn't exist")
|
||||
package = self.packages[name]
|
||||
if "base_url" not in package:
|
||||
if "#" not in package.get("version", ""):
|
||||
click.secho(
|
||||
f"Property 'base_url' is missing for '{name}'. "
|
||||
"The version of this package can't be changed by the user.",
|
||||
fg="red",
|
||||
)
|
||||
exit(1)
|
||||
package["base_url"] = package["version"].partition("#")[0]
|
||||
if package.get("version_prefix", False):
|
||||
version = "v" + version
|
||||
package["optional"] = False
|
||||
package["version"] = package["base_url"] + "#" + version
|
||||
|
||||
# save custom options from env
|
||||
self.custom_opts = {}
|
||||
for key, value in options.items():
|
||||
if not key.startswith("custom_"):
|
||||
continue
|
||||
self.custom_opts[key[7:]] = value
|
||||
# store version numbers of all used packages
|
||||
for package in self.get_installed_packages(with_optional=False):
|
||||
package: PackageItem
|
||||
version = package.metadata.version
|
||||
version = str(version).partition("sha.")[0]
|
||||
version = version.strip("+.")
|
||||
version = version.rpartition("+")[2]
|
||||
self.versions[package.metadata.name] = version
|
||||
|
||||
return super().configure_default_packages(options, targets)
|
||||
|
||||
@@ -246,10 +228,15 @@ class LibretuyaPlatform(PlatformBase):
|
||||
if "_base" in board:
|
||||
board._manifest = ltchiptool.Board.get_data(board._manifest)
|
||||
|
||||
# add "arduino" framework
|
||||
has_arduino = any("arduino" in fw for fw in board.manifest["frameworks"])
|
||||
if has_arduino:
|
||||
family = board.get("build.family")
|
||||
family = ltchiptool.Family.get(short_name=family)
|
||||
# add "frameworks" key with the default "base"
|
||||
board.manifest["frameworks"] = ["base"]
|
||||
# add "arduino" framework if supported
|
||||
if family.has_arduino_core:
|
||||
board.manifest["frameworks"].append("arduino")
|
||||
# add SDK package name
|
||||
board.manifest["package"] = family.target_package
|
||||
|
||||
# inspired by platform-ststm32/platform.py
|
||||
debug = board.manifest.get("debug", {})
|
||||
|
||||
Reference in New Issue
Block a user