Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting: only try loading from ROMFS if scripts exist #26312

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@ def configure_env(self, cfg, env):
env.ROMFS_FILES += [('scripts/'+f,'ROMFS/scripts/'+f)]

if len(env.ROMFS_FILES) > 0:
# Allow lua to load from ROMFS if any lua files are added
for file in env.ROMFS_FILES:
if file[0].startswith("scripts") and file[0].endswith(".lua"):
env.CXXFLAGS += ['-DHAL_HAVE_AP_ROMFS_EMBEDDED_LUA']
break
env.CXXFLAGS += ['-DHAL_HAVE_AP_ROMFS_EMBEDDED_H']

if cfg.options.sitl_rgbled:
Expand Down Expand Up @@ -1343,6 +1348,11 @@ def configure_env(self, cfg, env):
HAL_PARAM_DEFAULTS_PATH='"@ROMFS/defaults.parm"',
)
if len(env.ROMFS_FILES) > 0:
# Allow lua to load from ROMFS if any lua files are added
for file in env.ROMFS_FILES:
if file[0].startswith("scripts") and file[0].endswith(".lua"):
env.CXXFLAGS += ['-DHAL_HAVE_AP_ROMFS_EMBEDDED_LUA']
break
env.CXXFLAGS += ['-DHAL_HAVE_AP_ROMFS_EMBEDDED_H']

def build(self, bld):
Expand Down
12 changes: 9 additions & 3 deletions libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,11 @@ def write_hwdef_header(self, outfilename):
self.embed_bootloader(f)

if len(self.romfs) > 0:
# Allow lua to load from ROMFS if any lua files are added
for file in self.romfs.keys():
if file.startswith("scripts") and file.endswith(".lua"):
f.write('#define HAL_HAVE_AP_ROMFS_EMBEDDED_LUA 1\n')
break
f.write('#define HAL_HAVE_AP_ROMFS_EMBEDDED_H 1\n')

if self.mcu_series.startswith('STM32F1'):
Expand Down Expand Up @@ -3204,15 +3209,16 @@ def run(self):
# write out hw.dat for ROMFS
self.write_all_lines(os.path.join(self.outdir, "hw.dat"))

# Add ROMFS directories
self.romfs_add_dir(['scripts'])
self.romfs_add_dir(['param'])

# write out hwdef.h
self.write_hwdef_header(os.path.join(self.outdir, "hwdef.h"))

# write out ldscript.ld
self.write_ldscript(os.path.join(self.outdir, "ldscript.ld"))

self.romfs_add_dir(['scripts'])
self.romfs_add_dir(['param'])

self.write_ROMFS(self.outdir)

# copy the shared linker script into the build directory; it must
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Scripting/lua_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,12 @@ void lua_scripts::run(void) {
load_all_scripts_in_dir(L, SCRIPTING_DIRECTORY);
loaded = true;
}
#ifdef HAL_HAVE_AP_ROMFS_EMBEDDED_LUA
if ((dir_disable & uint16_t(AP_Scripting::SCR_DIR::ROMFS)) == 0) {
load_all_scripts_in_dir(L, "@ROMFS/scripts");
loaded = true;
}
#endif
if (!loaded) {
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Lua: All directory's disabled see SCR_DIR_DISABLE");
}
Expand Down
Loading