From 3749480dd8d9d5d777d4f28ed48bd806d3c89fa7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Apr 2018 18:29:46 +1000 Subject: [PATCH] HAL_ChibiOS: create ap_romfs_embedded.h use ROMFS keywork for romfs files --- .../AP_HAL_ChibiOS/hwdef/fmuv3/hwdef.dat | 6 +++ .../hwdef/scripts/chibios_hwdef.py | 15 +++++- .../AP_HAL_ChibiOS/hwdef/scripts/embed.py | 52 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 libraries/AP_HAL_ChibiOS/hwdef/scripts/embed.py diff --git a/libraries/AP_HAL_ChibiOS/hwdef/fmuv3/hwdef.dat b/libraries/AP_HAL_ChibiOS/hwdef/fmuv3/hwdef.dat index 6b61ceaea6..1facd7796f 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/fmuv3/hwdef.dat +++ b/libraries/AP_HAL_ChibiOS/hwdef/fmuv3/hwdef.dat @@ -487,3 +487,9 @@ define HAL_I2C_MAX_CLOCK 100000 # we can't share IO UART (USART6) DMA_NOSHARE USART6_TX USART6_RX DMA_PRIORITY USART6* TIM* SPI* + +# list of files to put in ROMFS. For fmuv3 we need an IO firmware so +# we can automatically update the IOMCU firmware on boot. The format +# is "ROMFS ROMFS-filename source-filename". Paths are relative to the +# ardupilot root +ROMFS io_firmware.bin Tools/IO_Firmware/fmuv2_IO.bin diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index e54c793b22..baa9d113e4 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -51,6 +51,9 @@ bylabel = {} # list of SPI devices spidev = [] +# list of ROMFS files +romfs = [] + # SPI bus list spi_list = [] @@ -803,6 +806,10 @@ def write_GPIO_config(f): (label, p.port, p.pin)) f.write('\n') +def write_ROMFS(outdir): + '''create ROMFS embedded header''' + from embed import create_embedded_h + create_embedded_h(os.path.join(outdir, 'ap_romfs_embedded.h'), romfs) def write_prototype_file(): '''write the prototype file for apj generation''' @@ -879,6 +886,9 @@ def write_hwdef_header(outfilename): write_UART_config(f) + if len(romfs) > 0: + f.write('#define HAL_HAVE_AP_ROMFS_EMBEDDED_H 1\n') + f.write(''' /* * I/O ports initial setup, this configuration is established soon after reset @@ -1022,6 +1032,8 @@ def process_line(line): p.af = af if a[0] == 'SPIDEV': spidev.append(a[1:]) + if a[0] == 'ROMFS': + romfs.append((a[1],a[2])) if a[0] == 'undef': print("Removing %s" % a[1]) config.pop(a[1], '') @@ -1093,9 +1105,10 @@ write_hwdef_header(os.path.join(outdir, "hwdef.h")) # write out ldscript.ld write_ldscript(os.path.join(outdir, "ldscript.ld")) +write_ROMFS(outdir) + # copy the shared linker script into the build directory; it must # exist in the same directory as the ldscript.ld file we generate. copy_common_linkerscript(outdir, args.hwdef) write_env_py(os.path.join(outdir, "env.py")) - diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/embed.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/embed.py new file mode 100644 index 0000000000..c1aea56b87 --- /dev/null +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/embed.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +''' +script to create embedded.c from a set of static files + +Andrew Tridgell +May 2017 +''' + +import os + +def embed_file(out, f, idx): + '''embed one file''' + contents = open(f).read() + out.write(''' +// %s +static const uint8_t ap_romfs_%u[] = {''' % (f, idx)) + + for c in contents: + out.write('%u,' % ord(c)) + out.write('};\n\n'); + +def create_embedded_h(filename, files): + '''create a ap_romfs_embedded.h file''' + + this_dir = os.path.realpath(__file__) + rootdir = os.path.relpath(os.path.join(this_dir, "../../../../..")) + + out = open(filename, "w") + out.write('''// generated embedded files for AP_ROMFS\n\n''') + + for i in range(len(files)): + (name, filename) = files[i] + filename = os.path.join(rootdir, filename) + embed_file(out, filename, i) + + out.write('''const AP_ROMFS::embedded_file AP_ROMFS::files[] = {\n''') + + for i in range(len(files)): + (name, filename) = files[i] + print("Embedding file %s:%s" % (name, filename)) + out.write('{ "%s", sizeof(ap_romfs_%u), ap_romfs_%u },\n' % (name, i, i)) + out.write('};\n') + out.close() + +if __name__ == '__main__': + import sys + flist = [] + for i in range(1, len(sys.argv)): + f = sys.argv[i] + flist.append((f, f)) + create_embedded_h("/tmp/ap_romfs_embedded.h", flist)