[beken-72xx] Update base core to new structure

This commit is contained in:
Kuba Szczodrzyński
2023-03-04 11:09:27 +01:00
parent c579219427
commit bc328657aa
58 changed files with 510 additions and 392 deletions

View File

@@ -2,7 +2,6 @@
from os.path import join
from ltchiptool.soc.bk72xx.binary import to_offset
from platformio.platform.board import PlatformBoardConfig
from SCons.Script import DefaultEnvironment, Environment
@@ -50,7 +49,6 @@ env.Append(
"-fno-strict-aliasing",
"-fsigned-char",
"-Wno-comment",
"-Werror=implicit-function-declaration",
"-Wno-write-strings",
"-Wno-char-subscripts",
"-Wno-missing-braces",
@@ -78,8 +76,6 @@ 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",
@@ -95,7 +91,6 @@ env.Append(
"-marm",
"-mthumb-interwork",
"-g",
"-nostartfiles",
"--specs=nano.specs",
"-Wl,--gc-sections",
"-Wl,-wrap,_free_r",
@@ -204,9 +199,8 @@ env.AddLibrary(
"+<security/*.c>",
"+<spidma/*.c>",
"+<sys_ctrl/*.c>",
"+<uart/*.c>",
"+<uart/uart.c>",
"+<wdt/*.c>",
"ARDUINO" in env and "-<uart/printf.c>",
],
includes=[
"+<common>",
@@ -543,6 +537,11 @@ env.Replace(
SIZEPRINTCMD="$SIZETOOL -B -d $SOURCES",
)
def to_offset(addr: int) -> int:
return int(addr + (addr // 32) * 2)
# Calculate RBL header offset
app_offs = int(env["FLASH_APP_OFFSET"], 16)
app_size = int(board.get("build.bkrbl_size_app"), 16)

View File

@@ -52,7 +52,6 @@ env.Append(
"-mfpu=fpv4-sp-d16",
"-g",
"--specs=nano.specs",
"-nostartfiles",
"-Os",
"-Wl,--gc-sections",
"-Wl,--cref",

View File

@@ -13,6 +13,28 @@ env["ARDUINO"] = True
# Add base cores' sources first
env.SConscript("base.py")
# 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",
],
)
family: Family = env["FAMILY_OBJ"]
# Add common sources among all families
@@ -52,35 +74,8 @@ env.AddLibrary(
srcs=[
"+<variant.cpp>",
],
includes=[
"!<.>",
],
# not adding includes since they're added in base.py
)
# 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()

View File

@@ -14,55 +14,15 @@ board: PlatformBoardConfig = env.BoardConfig()
platform: PlatformBase = env.PioPlatform()
# Environment variables, include paths, etc.
env.ConfigureEnvironment(platform, board)
family: Family = env["FAMILY_OBJ"]
family: Family = env.ConfigureEnvironment(platform, board)
# 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(
CFLAGS=[
"-Werror=implicit-function-declaration",
],
CPPDEFINES=[
("LIBRETUYA", 1),
("LT_VERSION", env.ReadLTVersion(platform.get_dir(), platform.version)),
@@ -71,6 +31,9 @@ env.Append(
("MCU", "${MCU}"),
("FAMILY", "F_${FAMILY}"),
],
CPPPATH=[
"$BOARD_DIR",
],
LINKFLAGS=[
'"-Wl,-Map=' + join("$BUILD_DIR", "${PROGNAME}.map") + '"',
],
@@ -80,5 +43,46 @@ env.Append(
],
)
# Build a core list to add sources, flags, etc.
cores = {
"common": "$COMMON_DIR",
}
# Configure each family first (add CPP defines)
for f in family.inheritance:
cores[f.code] = env.AddFamily(f)
# Add fixups & config for each core
for name, path in cores.items():
env.AddCoreConfig(path=join(path, "base"))
if "ARDUINO" in env:
env.AddCoreConfig(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 sources & include paths for each core
for name, path in cores.items():
env.AddCoreSources(name=name, path=join(path, "base"))
# Sources - external libraries
env.AddExternalLibrary("ltchiptool") # uf2ota source code
env.AddExternalLibrary("flashdb")
env.AddExternalLibrary("printf")
# Build everything from the base core
env.BuildLibraries()

View File

@@ -11,6 +11,7 @@ def env_load_defines(env: Environment, path: str):
path = env.subst(path)
if not isfile(path):
raise FileNotFoundError(f"Defines file not found ({path})")
config = {}
f = open(path, "r", encoding="utf-8")
for line in f:
line: str
@@ -19,11 +20,16 @@ def env_load_defines(env: Environment, path: str):
line = line[7:].strip()
line = line.split(None, 2)
if len(line) == 1:
env.Append(CPPDEFINES=[(line[0], "1")])
env.Append(CPPDEFINES=[(line[0], 1)])
config[line[0]] = 1
elif len(line) == 2:
env.Append(CPPDEFINES=[(line[0], line[1])])
config[line[0]] = line[1]
else:
raise ValueError(f"Unknown directive: {line}")
env.Append(
CONFIG=config,
)
f.close()

View File

@@ -22,27 +22,23 @@ def env_add_family(env: Environment, family: Family) -> str:
return path
def env_add_core_config(env: Environment, name: str, path: str) -> bool:
def env_add_core_config(env: Environment, path: str) -> bool:
if not isdir(env.subst(path)):
return False
env.Prepend(
CPPPATH=[join(path, "config")],
LIBPATH=[join(path, "fixups")],
CPPPATH=[
join(path, "compat"),
join(path, "config"),
join(path, "fixups"),
],
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
@@ -56,6 +52,8 @@ def env_add_core_sources(env: Environment, name: str, path: str) -> bool:
"+<*.c*>",
"+<common/*.c*>",
"+<compat/*.c*>",
"+<fixups/*.c*>",
"+<port/*.c*>",
"+<posix/*.c>",
"+<wraps/*.c>",
],
@@ -63,6 +61,9 @@ def env_add_core_sources(env: Environment, name: str, path: str) -> bool:
# prepend the paths before SDK directories
"!<.>",
"!<compat>",
"!<config>",
"!<fixups>",
"!<port>",
],
)
return True
@@ -78,7 +79,7 @@ def env_add_arduino_libraries(env: Environment, name: str, path: str) -> bool:
"+<**/*.c*>",
],
includes=[
"!<*>",
"!<*/*>" if name.startswith("common") else "!<*>",
],
)
return True

View File

@@ -50,7 +50,11 @@ def env_read_version(env: Environment, platform_dir: str, version: str):
return f"{version}+{build_str}" if build_str else version
def env_configure(env: Environment, platform: PlatformBase, board: PlatformBoardConfig):
def env_configure(
env: Environment,
platform: PlatformBase,
board: PlatformBoardConfig,
) -> Family:
# Read external libraries list
with open(join(platform.get_dir(), "external-libs.json")) as f:
external_libs = json.load(f)
@@ -84,6 +88,7 @@ def env_configure(env: Environment, platform: PlatformBase, board: PlatformBoard
)
# Store family parameters as environment variables
env.Replace(**dict(family))
return family
env.AddMethod(env_configure, "ConfigureEnvironment")