HAL_ChibiOS: create ap_romfs_embedded.h

use ROMFS keywork for romfs files
This commit is contained in:
Andrew Tridgell 2018-04-14 18:29:46 +10:00
parent deae66e645
commit 3749480dd8
3 changed files with 72 additions and 1 deletions

View File

@ -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

View File

@ -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"))

View File

@ -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)