1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 04:41:26 +04:00

[FL-2627] Flipper applications: SDK, build and debug system (#1387)

* Added support for running applications from SD card (FAPs - Flipper Application Packages)
* Added plugin_dist target for fbt to build FAPs
* All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default
* Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them
* Added debugging support for FAPs with fbt debug & VSCode
* Added public firmware API with automated versioning

Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
SG
2022-09-15 02:11:38 +10:00
committed by Aleksandr Kutuzov
parent 0f6f9ad52e
commit b9a766d909
895 changed files with 8862 additions and 1465 deletions

View File

@@ -1,6 +1,6 @@
Import("ENV", "fw_build_meta")
import os
import itertools
from fbt.util import (
should_gen_cdb_and_link_dir,
@@ -13,6 +13,7 @@ env = ENV.Clone(
("compilation_db", {"COMPILATIONDB_COMSTR": "\tCDB\t${TARGET}"}),
"fwbin",
"fbt_apps",
"fbt_sdk",
],
COMPILATIONDB_USE_ABSPATH=False,
BUILD_DIR=fw_build_meta["build_dir"],
@@ -28,7 +29,7 @@ env = ENV.Clone(
],
CPPPATH=[
"#/furi",
"#/applications",
*(f"#/{app_dir[0]}" for app_dir in ENV["APPDIRS"] if app_dir[1]),
"#/firmware/targets/f${TARGET_HW}/ble_glue",
"#/firmware/targets/f${TARGET_HW}/fatfs",
"#/firmware/targets/f${TARGET_HW}/furi_hal",
@@ -58,6 +59,15 @@ env = ENV.Clone(
"FURI_DEBUG" if ENV["DEBUG"] else "FURI_NDEBUG",
],
},
"flipper_application": {
"CCFLAGS": [
"-Og",
],
"CPPDEFINES": [
"NDEBUG",
"FURI_DEBUG" if ENV["DEBUG"] else "FURI_NDEBUG",
],
},
},
)
@@ -80,6 +90,12 @@ if not env["VERBOSE"]:
HEXCOMSTR="\tHEX\t${TARGET}",
BINCOMSTR="\tBIN\t${TARGET}",
DFUCOMSTR="\tDFU\t${TARGET}",
SDK_PREGEN_COMSTR="\tPREGEN\t${TARGET}",
SDK_COMSTR="\tSDKSRC\t${TARGET}",
SDKSYM_UPDATER_COMSTR="\tSDKCHK\t${TARGET}",
SDKSYM_GENERATOR_COMSTR="\tSDKSYM\t${TARGET}",
APPMETA_COMSTR="\tAPPMETA\t${TARGET}",
APPMETAEMBED_COMSTR="\tFAP\t${TARGET}",
)
@@ -127,11 +143,13 @@ fwenv.LoadApplicationManifests()
fwenv.PrepareApplicationsBuild()
# Build external apps
extapps = SConscript("applications/extapps.scons", exports={"ENV": fwenv})
extapps = fwenv["FW_EXTAPPS"] = SConscript(
"site_scons/extapps.scons", exports={"ENV": fwenv}
)
# Add preprocessor definitions for current set of apps
fwenv.AppendUnique(
fwenv.Append(
CPPDEFINES=fwenv["APPBUILD"].get_apps_cdefs(),
)
@@ -141,23 +159,26 @@ apps_c = fwenv.ApplicationsC(
"applications/applications.c",
[Value(fwenv["APPS"]), Value(fwenv["LOADER_AUTOSTART"])],
)
# Adding dependency on manifest files so apps.c is rebuilt when any manifest is changed
fwenv.Depends(apps_c, fwenv.GlobRecursive("*.fam", "#/applications"))
for app_dir, _ in env["APPDIRS"]:
app_dir_node = env.Dir("#").Dir(app_dir)
fwenv.Depends(apps_c, fwenv.GlobRecursive("*.fam", app_dir_node))
sources = [apps_c]
# Gather sources only from app folders in current configuration
for app_folder in fwenv["APPBUILD"].get_builtin_app_folders():
sources += fwenv.GlobRecursive("*.c*", os.path.join("applications", app_folder))
sources.extend(
itertools.chain.from_iterable(
fwenv.GlobRecursive(source_type, appdir.relpath)
for appdir, source_type in fwenv["APPBUILD"].get_builtin_app_folders()
)
)
fwenv.AppendUnique(
LINKFLAGS=[
"-specs=nano.specs",
"-specs=nosys.specs",
"-Wl,--start-group",
"-lstdc++",
"-lsupc++",
"-Wl,--end-group",
"-Wl,--gc-sections",
"-Wl,--undefined=uxTopUsedPriority",
"-Wl,--wrap,_malloc_r",
@@ -174,7 +195,6 @@ fwenv.AppendUnique(
# print(fwenv.Dump())
# Full firmware definition
fwelf = fwenv["FW_ELF"] = fwenv.Program(
"${FIRMWARE_BUILD_CFG}",
sources,
@@ -199,8 +219,8 @@ fwelf = fwenv["FW_ELF"] = fwenv.Program(
"assets",
"misc",
"mbedtls",
"loclass",
"lfrfid",
"flipper_application",
# 2nd round
"flipperformat",
"toolbox",
@@ -248,6 +268,8 @@ if should_gen_cdb_and_link_dir(fwenv, BUILD_TARGETS):
Precious(fwcdb)
NoClean(fwcdb)
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_cdb", fwcdb)
AlwaysBuild(fwenv["FIRMWARE_BUILD_CFG"] + "_cdb", fwcdb)
Alias(fwcdb, "")
fw_artifacts.append(fwcdb)
# Adding as a phony target, so folder link is updated even if elf didn't change
@@ -263,5 +285,42 @@ if should_gen_cdb_and_link_dir(fwenv, BUILD_TARGETS):
Alias(fwenv["FIRMWARE_BUILD_CFG"] + "_all", fw_artifacts)
if fwenv["IS_BASE_FIRMWARE"]:
sdk_source = fwenv.SDKPrebuilder(
"sdk_origin",
[],
# Filtering out things cxxheaderparser cannot handle
SDK_PP_FLAGS=[
'-D"_Static_assert(x,y)="',
'-D"__asm__(x)="',
'-D"__attribute__(x)="',
"-Drestrict=",
"-D_Noreturn=",
"-D__restrict=",
"-D__extension__=",
"-D__inline=inline",
"-D__inline__=inline",
],
)
Depends(sdk_source, fwenv["SDK_HEADERS"])
sdk_tree = fwenv.SDKTree("sdk/sdk.opts", "sdk_origin")
AlwaysBuild(sdk_tree)
Alias("sdk_tree", sdk_tree)
sdk_apicheck = fwenv.SDKSymUpdater(fwenv.subst("$SDK_DEFINITION"), "sdk_origin")
Precious(sdk_apicheck)
NoClean(sdk_apicheck)
AlwaysBuild(sdk_apicheck)
Alias("sdk_check", sdk_apicheck)
sdk_apisyms = fwenv.SDKSymGenerator(
"assets/compiled/symbols.h", fwenv.subst("$SDK_DEFINITION")
)
Alias("api_syms", sdk_apisyms)
if fwenv["FORCE"]:
fwenv.AlwaysBuild(sdk_source, sdk_tree, sdk_apicheck, sdk_apisyms)
Return("fwenv")