[FL-2733] multitarget support for fbt (#2209)

* First part of multitarget porting
* Delete firmware/targets/f7/Inc directory
* Delete firmware/targets/f7/Src directory
* gpio: cli fixes; about: using version from HAL
* sdk: path fixes
* gui: include fixes
* applications: more include fixes
* gpio: ported to new apis
* hal: introduced furi_hal_target_hw.h; libs: added one_wire
* hal: f18 target
* github: also build f18 by default
* typo fix
* fbt: removed extra checks on app list
* api: explicitly bundling select mlib headers with sdk
* hal: f18: changed INPUT_DEBOUNCE_TICKS to match f7
* cleaned up commented out code
* docs: added info on hw targets
* docs: targets: formatting fixes
* f18: fixed link error
* f18: fixed API version to match f7
* docs: hardware: minor wording fixes
* faploader: added fw target check
* docs: typo fixes
* github: not building komi target by default
* fbt: support for `targets` field for built-in apps
* github: reworked build flow to exclude app_set; fbt: removed komi-specific appset; added additional target buildset check
* github: fixed build; nfc: fixed pvs warnings
* attempt to fix target id
* f7, f18: removed certain HAL function from public API
* apps: debug: enabled bt_debug_app for f18
* Targets: backport input pins configuration routine from F7 to F18

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
hedger
2023-02-07 19:33:05 +03:00
committed by GitHub
parent 1eda913367
commit 224d0aefe4
152 changed files with 4140 additions and 495 deletions

View File

@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import List, Optional, Tuple
from typing import List, Optional, Tuple, Callable
from enum import Enum
import os
@@ -71,6 +71,9 @@ class FlipperApplication:
_appdir: Optional[object] = None
_apppath: Optional[str] = None
def supports_hardware_target(self, target: str):
return target in self.targets or "all" in self.targets
class AppManager:
def __init__(self):
@@ -158,15 +161,26 @@ class AppBuildset:
FlipperAppType.STARTUP,
)
def __init__(self, appmgr: AppManager, appnames: List[str], hw_target: str):
@staticmethod
def print_writer(message):
print(message)
def __init__(
self,
appmgr: AppManager,
appnames: List[str],
hw_target: str,
message_writer: Callable = None,
):
self.appmgr = appmgr
self.appnames = set(appnames)
self.hw_target = hw_target
self._orig_appnames = appnames
self.hw_target = hw_target
self._writer = message_writer if message_writer else self.print_writer
self._process_deps()
self._filter_by_target()
self._check_conflicts()
self._check_unsatisfied() # unneeded?
self._check_target_match()
self.apps = sorted(
list(map(self.appmgr.get, self.appnames)),
key=lambda app: app.appid,
@@ -175,28 +189,32 @@ class AppBuildset:
def _is_missing_dep(self, dep_name: str):
return dep_name not in self.appnames
def _filter_by_target(self):
for appname in self.appnames.copy():
app = self.appmgr.get(appname)
# if app.apptype not in self.BUILTIN_APP_TYPES:
if not any(map(lambda t: t in app.targets, ["all", self.hw_target])):
print(
f"Removing {appname} due to target mismatch (building for {self.hw_target}, app supports {app.targets}"
)
self.appnames.remove(appname)
def _check_if_app_target_supported(self, app_name: str):
return self.appmgr.get(app_name).supports_hardware_target(self.hw_target)
def _get_app_depends(self, app_name: str) -> List[str]:
# Skip app if its target is not supported by the target we are building for
if not self._check_if_app_target_supported(app_name):
self._writer(
f"Skipping {app_name} due to target mismatch (building for {self.hw_target}, app supports {app_def.targets}"
)
return []
app_def = self.appmgr.get(app_name)
return list(
filter(
self._check_if_app_target_supported,
filter(self._is_missing_dep, app_def.provides + app_def.requires),
)
)
def _process_deps(self):
while True:
provided = []
for app in self.appnames:
# print(app)
provided.extend(
filter(
self._is_missing_dep,
self.appmgr.get(app).provides + self.appmgr.get(app).requires,
)
)
# print("provides round", provided)
for app_name in self.appnames:
provided.extend(self._get_app_depends(app_name))
# print("provides round: ", provided)
if len(provided) == 0:
break
self.appnames.update(provided)
@@ -204,7 +222,6 @@ class AppBuildset:
def _check_conflicts(self):
conflicts = []
for app in self.appnames:
# print(app)
if conflict_app_name := list(
filter(
lambda dep_name: dep_name in self.appnames,
@@ -231,6 +248,17 @@ class AppBuildset:
f"Unsatisfied dependencies for {', '.join(f'{missing_dep[0]}: {missing_dep[1]}' for missing_dep in unsatisfied)}"
)
def _check_target_match(self):
incompatible = []
for app in self.appnames:
if not self.appmgr.get(app).supports_hardware_target(self.hw_target):
incompatible.append(app)
if len(incompatible):
raise AppBuilderException(
f"Apps incompatible with target {self.hw_target}: {', '.join(incompatible)}"
)
def get_apps_cdefs(self):
cdefs = set()
for app in self.apps:

View File

@@ -1,5 +1,6 @@
from SCons.Builder import Builder
from SCons.Action import Action
from SCons.Errors import StopError
from SCons.Warnings import warn, WarningOnByDefault
from ansi.color import fg
@@ -32,9 +33,13 @@ def LoadAppManifest(env, entry):
def PrepareApplicationsBuild(env):
appbuild = env["APPBUILD"] = env["APPMGR"].filter_apps(
env["APPS"], env.subst("f${TARGET_HW}")
)
try:
appbuild = env["APPBUILD"] = env["APPMGR"].filter_apps(
env["APPS"], env.subst("f${TARGET_HW}")
)
except Exception as e:
raise StopError(e)
env.Append(
SDK_HEADERS=appbuild.get_sdk_headers(),
)

View File

@@ -0,0 +1,134 @@
from SCons.Builder import Builder
from SCons.Action import Action
import json
class HardwareTargetLoader:
def __init__(self, env, target_scons_dir, target_id):
self.env = env
self.target_scons_dir = target_scons_dir
self.target_dir = self._getTargetDir(target_id)
# self.target_id = target_id
self.layered_target_dirs = []
self.include_paths = []
self.sdk_header_paths = []
self.startup_script = None
self.linker_script_flash = None
self.linker_script_ram = None
self.linker_script_app = None
self.sdk_symbols = None
self.linker_dependencies = []
self.excluded_sources = []
self.excluded_headers = []
self.excluded_modules = []
self._processTargetDefinitions(target_id)
def _getTargetDir(self, target_id):
return self.target_scons_dir.Dir(f"f{target_id}")
def _loadDescription(self, target_id):
target_json_file = self._getTargetDir(target_id).File("target.json")
if not target_json_file.exists():
raise Exception(f"Target file {target_json_file} does not exist")
with open(target_json_file.get_abspath(), "r") as f:
vals = json.load(f)
return vals
def _processTargetDefinitions(self, target_id):
self.layered_target_dirs.append(f"targets/f{target_id}")
config = self._loadDescription(target_id)
for path_list in ("include_paths", "sdk_header_paths"):
getattr(self, path_list).extend(
f"#/firmware/targets/f{target_id}/{p}"
for p in config.get(path_list, [])
)
self.excluded_sources.extend(config.get("excluded_sources", []))
self.excluded_headers.extend(config.get("excluded_headers", []))
self.excluded_modules.extend(config.get("excluded_modules", []))
file_attrs = (
# (name, use_src_node)
("startup_script", False),
("linker_script_flash", True),
("linker_script_ram", True),
("linker_script_app", True),
("sdk_symbols", True),
)
for attr_name, use_src_node in file_attrs:
if (val := config.get(attr_name)) and not getattr(self, attr_name):
node = self.env.File(f"firmware/targets/f{target_id}/{val}")
if use_src_node:
node = node.srcnode()
setattr(self, attr_name, node)
for attr_name in ("linker_dependencies",):
if (val := config.get(attr_name)) and not getattr(self, attr_name):
setattr(self, attr_name, val)
if inherited_target := config.get("inherit", None):
self._processTargetDefinitions(inherited_target)
def gatherSources(self):
sources = [self.startup_script]
seen_filenames = set(self.excluded_sources)
# print("Layers: ", self.layered_target_dirs)
for target_dir in self.layered_target_dirs:
accepted_sources = list(
filter(
lambda f: f.name not in seen_filenames,
self.env.GlobRecursive("*.c", target_dir),
)
)
seen_filenames.update(f.name for f in accepted_sources)
sources.extend(accepted_sources)
# print(f"Found {len(sources)} sources: {list(f.name for f in sources)}")
return sources
def gatherSdkHeaders(self):
sdk_headers = []
seen_sdk_headers = set(self.excluded_headers)
for sdk_path in self.sdk_header_paths:
# dirty, but fast - exclude headers from overlayed targets by name
# proper way would be to use relative paths, but names will do for now
for header in self.env.GlobRecursive("*.h", sdk_path, "*_i.h"):
if header.name not in seen_sdk_headers:
seen_sdk_headers.add(header.name)
sdk_headers.append(header)
return sdk_headers
def ConfigureForTarget(env, target_id):
target_loader = HardwareTargetLoader(env, env.Dir("#/firmware/targets"), target_id)
env.Replace(
TARGET_CFG=target_loader,
SDK_DEFINITION=target_loader.sdk_symbols,
SKIP_MODULES=target_loader.excluded_modules,
)
env.Append(
CPPPATH=target_loader.include_paths,
SDK_HEADERS=target_loader.gatherSdkHeaders(),
)
def ApplyLibFlags(env):
flags_to_apply = env["FW_LIB_OPTS"].get(
env.get("FW_LIB_NAME"),
env["FW_LIB_OPTS"]["Default"],
)
# print("Flags for ", env.get("FW_LIB_NAME", "Default"), flags_to_apply)
env.MergeFlags(flags_to_apply)
def generate(env):
env.AddMethod(ConfigureForTarget)
env.AddMethod(ApplyLibFlags)
def exists(env):
return True

View File

@@ -22,6 +22,8 @@ def BuildModule(env, module):
def BuildModules(env, modules):
result = []
for module in modules:
if module in env.get("SKIP_MODULES", []):
continue
build_res = env.BuildModule(module)
# print("module ", module, build_res)
if build_res is None: