[core] Print platform versions, add GCC version to startup banner

This commit is contained in:
Kuba Szczodrzyński
2023-03-17 17:32:28 +01:00
parent 8faffedddc
commit 2882eaa0c2
3 changed files with 30 additions and 25 deletions

View File

@@ -3,7 +3,7 @@
from os.path import join from os.path import join
import click import click
from ltchiptool import Family from ltchiptool import Family, get_version
from platformio.platform.base import PlatformBase from platformio.platform.base import PlatformBase
from platformio.platform.board import PlatformBoardConfig from platformio.platform.board import PlatformBoardConfig
from SCons.Errors import UserError from SCons.Errors import UserError
@@ -14,6 +14,12 @@ board: PlatformBoardConfig = env.BoardConfig()
platform: PlatformBase = env.PioPlatform() platform: PlatformBase = env.PioPlatform()
family: Family = env["FAMILY_OBJ"] family: Family = env["FAMILY_OBJ"]
# Print information about installed core versions
lt_version: str = env.ReadLTVersion(platform.get_dir(), platform.version)
print("PLATFORM VERSIONS:")
print(" - libretuya @", lt_version)
print(" - ltchiptool @", get_version())
# TODO remove include path prepending ("!<...>") # TODO remove include path prepending ("!<...>")
# Move common core sources (env.AddCoreSources()) and Arduino libs # Move common core sources (env.AddCoreSources()) and Arduino libs
# below per-family sources (to maintain child families taking precedence) # below per-family sources (to maintain child families taking precedence)
@@ -86,6 +92,12 @@ queue.AddExternalLibrary("ltchiptool") # uf2ota source code
queue.AddExternalLibrary("flashdb") queue.AddExternalLibrary("flashdb")
queue.AddExternalLibrary("printf") queue.AddExternalLibrary("printf")
# Find optimization level and add __OPTIMIZE_LEVEL__ macro
for flag in env["CCFLAGS"]:
if not flag.startswith("-O"):
continue
env.Append(CPPDEFINES=[("__OPTIMIZE_LEVEL__", flag[2])])
# Non-SDK defines & linker options # Non-SDK defines & linker options
queue.AppendPublic( queue.AppendPublic(
CCFLAGS=[ CCFLAGS=[
@@ -102,13 +114,13 @@ queue.AppendPublic(
], ],
CPPDEFINES=[ CPPDEFINES=[
("LIBRETUYA", 1), ("LIBRETUYA", 1),
("LT_VERSION", env.ReadLTVersion(platform.get_dir(), platform.version)), ("LT_VERSION", lt_version),
("LT_BOARD", "${VARIANT}"), ("LT_BOARD", "${VARIANT}"),
("LT_VARIANT_H", r"\"${VARIANT}.h\""), ("LT_VARIANT_H", r"\"${VARIANT}.h\""),
("F_CPU", board.get("build.f_cpu")), ("F_CPU", board.get("build.f_cpu")),
("MCU", "${MCU}"), ("MCU", "${MCU}"),
("MCULC", "${MCULC}"), ("MCULC", "${MCULC}"),
("FAMILY", "F_${FAMILY}"), ("FAMILY", "F_${FAMILY_SHORT_NAME}"),
# Add flash layout defines created in env.AddFlashLayout() # Add flash layout defines created in env.AddFlashLayout()
*env["FLASH_DEFINES"].items(), *env["FLASH_DEFINES"].items(),
], ],

View File

@@ -26,26 +26,24 @@ def env_uf2ota(env: Environment, *args, **kwargs):
project_name, project_name,
project_version, project_version,
"${VARIANT}", "${VARIANT}",
"${FAMILY}", "${MCULC}",
f"lt{lt_version}", f"lt{lt_version}",
] ]
output = "_".join(output) + ".uf2" output = "_".join(output) + ".uf2"
if platform.custom("fw_output"): if platform.custom("fw_output"):
output = platform.custom("fw_output") output = platform.custom("fw_output")
output = join("${BUILD_DIR}", output) outputs = [
output_copy_1 = join("${BUILD_DIR}", "firmware.uf2") join("${BUILD_DIR}", output),
output_copy_2 = join("${BUILD_DIR}", "firmware.bin") join("${BUILD_DIR}", "firmware.uf2"),
join("${BUILD_DIR}", "firmware.bin"),
env["UF2OUT"] = output ]
env["UF2OUT_BASE"] = basename(output) output_opts = [f'--output "{output}"' for output in outputs]
cmd = [ cmd = [
"@${LTCHIPTOOL} uf2 write", "@${LTCHIPTOOL} uf2 write",
f'--output "{output}"', *output_opts,
f'--output-copy "{output_copy_1}"', "--family ${FAMILY_SHORT_NAME}",
f'--output-copy "{output_copy_2}"',
"--family ${FAMILY}",
"--board ${VARIANT}", "--board ${VARIANT}",
f"--lt-version {lt_version}", f"--lt-version {lt_version}",
f'--fw "{project_name}:{project_version}"', f'--fw "{project_name}:{project_version}"',
@@ -53,10 +51,9 @@ def env_uf2ota(env: Environment, *args, **kwargs):
*env["UF2OTA"], *env["UF2OTA"],
] ]
print(f"|-- {basename(env.subst(output))}") for output in outputs:
print(f"|-- {basename(env.subst(output))}")
env.Execute(" ".join(cmd)) env.Execute(" ".join(cmd))
print(f"|-- {basename(env.subst(output_copy_1))}")
print(f"|-- {basename(env.subst(output_copy_2))}")
def env_flash_write(env: Environment): def env_flash_write(env: Environment):

View File

@@ -27,16 +27,12 @@
#define LT_BOARD_STR STRINGIFY_MACRO(LT_BOARD) #define LT_BOARD_STR STRINGIFY_MACRO(LT_BOARD)
#define GCC_VERSION_STR \ #define GCC_VERSION_STR \
STRINGIFY_MACRO(__GNUC__) "." STRINGIFY_MACRO(__GNUC_MINOR__) "." STRINGIFY_MACRO(__GNUC_PATCHLEVEL__) STRINGIFY_MACRO(__GNUC__) "." STRINGIFY_MACRO(__GNUC_MINOR__) "." STRINGIFY_MACRO(__GNUC_PATCHLEVEL__)
#define LT_BANNER_STR \
"LibreTuya v" LT_VERSION_STR " on " LT_BOARD_STR ", compiled at " __DATE__ " " __TIME__ ", GCC " GCC_VERSION_STR \
" (-O" STRINGIFY_MACRO(__OPTIMIZE_LEVEL__) ")"
// Functional macros // Functional macros
#define LT_BANNER() \ #define LT_BANNER() LT_LOG(LT_LEVEL_INFO, __FUNCTION__, __LINE__, LT_BANNER_STR)
LT_LOG( \
LT_LEVEL_INFO, \
__FUNCTION__, \
__LINE__, \
"LibreTuya v" LT_VERSION_STR " on " LT_BOARD_STR ", compiled at " __DATE__ " " __TIME__ \
", GCC " GCC_VERSION_STR \
)
// Types & macros // Types & macros
#include "lt_config.h" // platform configuration options #include "lt_config.h" // platform configuration options