Commit 69c164ae authored by Oliver Horst's avatar Oliver Horst
Browse files

[chg] First working version of an automatic config transfer from the...

[chg] First working version of an automatic config transfer from the JSON-based deployment config to the AppListEntry_t C structure
parent a3dbab0e
......@@ -9,6 +9,11 @@ def get_toki_deployment_config(d):
return config
def get_toki_deployment_config_base64encoded(d):
import base64
return base64.b64encode(d.getVar('TOKI_JSON_CONFIG', True).encode('UTF-8')).decode()
def get_toki_sw_core_config(d):
config = get_toki_deployment_config(d)
......@@ -72,4 +77,4 @@ def get_toki_multiconfig_str(d):
def get_toki_apps(d):
core_sw_config = get_toki_sw_core_config(d)
return " ".join(core_sw_config["apps"])
return " ".join(list(core_sw_config["apps"].keys()))
......@@ -19,7 +19,8 @@ do_compile () {
${THISDIR}/python3/ \
"${WORKDIR}" \
"${B}" \
"${@get_toki_deployment_config_base64encoded(d)}" \
do_install() {
#!/usr/bin/env python3
import base64
import cffi
import json
import os
import sys
apps = []
# Transfer, i.e., sets all the configuration parameters specified in the given (JSON-based) deployment configuration
# within the 'AppListEntry_t' C structure that is used during loading of the application.
def transferconfig(ffi, cdata, struct, config):
for key in config.keys():
if isinstance(config[key], dict):
transferconfig(ffi, cdata, getattr(struct, key), config[key])
setattr(struct, key, cdata.cast(ffi._typeoffsetof(cdata.typeof(struct), *[key])[0], config[key]))
work_dir = sys.argv[1]
build_dir = sys.argv[2]
app_list = str(sys.argv[3]).split(" ")
config = json.loads(base64.b64decode(sys.argv[3]).decode())
core = int(sys.argv[4])
print("work_dir: {}".format(work_dir))
print("build_dir: {}".format(build_dir))
print("app_list: {}".format(app_list))
apps = config['cores'][core]["apps"]
# Parse and load 'freertos+/elfloader/app-config.h'
......@@ -36,17 +44,23 @@ sys.path.append(build_dir)
cdata = __import__("_app_config", fromlist=[]).ffi
# Discover apps and their binary sizes
# Discover the paths to the app binaries and their sizes
total_size = 0
apps_path = {}
for app_name in app_list:
for app_name in apps.keys():
app_path = os.path.join(work_dir, "recipe-sysroot", "usr", "bin", "{}.elf".format(app_name))
app_stat = os.stat(app_path)
app_size = app_stat.st_size
app_name: app_path
"path": app_path,
"size": app_size
......@@ -59,10 +73,10 @@ for app_name in app_list:
block ="uint8_t[]", total_size)
# Iterate through all apps and copy their binary code into our app list structure
# Iterate through all apps, set all given configuration options, and copy their binary code into our app list structure
offset = 0
for app in apps:
for app_name in apps.keys():
current_entry_addr = int(ffi.cast("uintptr_t", block)) + offset
......@@ -71,9 +85,9 @@ for app in apps:
current_entry = cdata.cast("AppListEntry_t *", current_entry_addr)
current_entry.size = app["size"]
transferconfig(ffi, cdata, current_entry, apps[app_name])
with open(app["path"], "rb") as app_binary:
with open(apps_path[app_name], "rb") as app_binary:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment