build: Generate gps-watch-bootloader-intermediate.frm.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sun, 13 Sep 2020 10:36:40 +0000 (12:36 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sun, 13 Sep 2020 10:36:40 +0000 (12:36 +0200)
This file can be installed on a GPS watch running the vendor firmware.

SConscript.target
SConstruct

index 2da14a42ff3dc1a9005f901816b4bb0cde728252..a927dd7292259df9195a792a06735dd65558e6ea 100644 (file)
@@ -59,6 +59,8 @@ bootloader_source_files = [
     'src/bootloader/flash.rs',
 ]
 
     'src/bootloader/flash.rs',
 ]
 
+bootloader_bins = []
+
 for s in ['intermediate', 'final']:
     bootloader_env = env.Clone()
 
 for s in ['intermediate', 'final']:
     bootloader_env = env.Clone()
 
@@ -82,6 +84,13 @@ for s in ['intermediate', 'final']:
 
     Default(bootloader_bin)
 
 
     Default(bootloader_bin)
 
+    bootloader_bins.append(bootloader_bin)
+
+bootloader_intermediate_frm = \
+    bootloader_env.Frm(bootloader_bins[0])
+
+Default(bootloader_intermediate_frm)
+
 application_source_files = [
     'src/application/main.rs', # Must be listed first (see below).
     'src/application/button.rs',
 application_source_files = [
     'src/application/main.rs', # Must be listed first (see below).
     'src/application/button.rs',
index 4b5a1bc6b3d3d546d9c351ce83be39abc9dda1d9..6823b768066b8f95c4ac6a0947ec3b5ccd720e63 100644 (file)
@@ -11,6 +11,7 @@ if ARGUMENTS.get('V', '0') != '1':
     root_env['ARCOMSTR'] = '    AR $TARGET'
     root_env['RANLIBCOMSTR'] = '    RANLIB $TARGET'
     root_env['OBJCOPYCOMSTR'] = '    OBJCOPY $TARGET'
     root_env['ARCOMSTR'] = '    AR $TARGET'
     root_env['RANLIBCOMSTR'] = '    RANLIB $TARGET'
     root_env['OBJCOPYCOMSTR'] = '    OBJCOPY $TARGET'
+    root_env['FRMCOMSTR'] = '    FRM $TARGET'
 
 # Make colored output of e.g. gcc work.
 root_env['ENV']['TERM'] = os.environ.get('TERM')
 
 # Make colored output of e.g. gcc work.
 root_env['ENV']['TERM'] = os.environ.get('TERM')
@@ -32,6 +33,26 @@ root_env.Append(BUILDERS = { 'Objcopy': Builder(
     suffix='.bin',
     src_suffix='.elf')})
 
     suffix='.bin',
     src_suffix='.elf')})
 
+def xor8(buf):
+    import functools
+
+    return functools.reduce(lambda x, y: (x & 0xff) ^ (y & 0xff), buf)
+
+def build_frm(target, source, env):
+    with open(str(source[0]), 'rb') as f_in:
+        buf = f_in.read()
+
+        with open(str(target[0]), 'wb') as f_out:
+            f_out.write(buf)
+            f_out.write(bytearray([xor8(buf)]))
+
+    return 0
+
+root_env.Append(BUILDERS = { 'Frm': Builder(
+    action=Action(build_frm, '$FRMCOMSTR'),
+    suffix='.frm',
+    src_suffix='.bin')})
+
 env = root_env.Clone()
 env['variant_dir'] = 'build-target'
 env['LIBPATH'] = env['variant_dir']
 env = root_env.Clone()
 env['variant_dir'] = 'build-target'
 env['LIBPATH'] = env['variant_dir']