|
3 | 3 | # SPDX-License-Identifier: MIT
|
4 | 4 | #
|
5 | 5 |
|
6 |
| -from os.path import getsize, isdir, isfile, join |
| 6 | +from os.path import isdir, isfile, join |
7 | 7 | from shutil import copyfile
|
8 |
| -import json |
9 |
| -from zlib import crc32 |
| 8 | +from json import load |
| 9 | +from rdautils import mkimage, gen_fota_file |
10 | 10 | from platformio.util import get_systype
|
11 | 11 |
|
12 | 12 | from SCons.Script import DefaultEnvironment
|
|
20 | 20 |
|
21 | 21 | # Load core configuration
|
22 | 22 | with open(join(FRAMEWORK_DIR, "lib", "rda8910", "core_config.json")) as f:
|
23 |
| - core_config = json.load(f) |
| 23 | + core_config = load(f) |
24 | 24 | f.close()
|
25 | 25 |
|
26 | 26 | # RDA Tools
|
|
59 | 59 | copyfile(join(FRAMEWORK_DIR, "template", "main.c"), main_c)
|
60 | 60 |
|
61 | 61 |
|
62 |
| -def gen_img_file(target, source, env): |
63 |
| - cmd = ["$OBJCOPY"] |
64 |
| - (target_firm, ) = target |
65 |
| - (source_elf, ) = source |
66 |
| - |
67 |
| - target_img = join(env.subst("$BUILD_DIR"), env.subst("$PROGNAME") + '.img') |
68 |
| - |
69 |
| - cmd.extend(["-O", "binary"]) |
70 |
| - cmd.append(source_elf.get_abspath()) |
71 |
| - cmd.append(target_img) |
72 |
| - env.Execute(env.VerboseAction(" ".join(cmd), " ")) |
73 |
| - |
74 |
| - # fix bin size to 0x80 boundary |
75 |
| - binsz = getsize(target_img) |
76 |
| - f_binsz = (binsz + 0x7F) & ~0x7F |
77 |
| - print("Binary size: %d" % binsz) |
78 |
| - f = open(target_img, "rb") |
79 |
| - f_bin = bytearray(f.read()) |
80 |
| - f.close() |
81 |
| - f_bin += bytes(f_binsz - binsz) |
82 |
| - # Fix header size |
83 |
| - f_bin[4:8] = f_binsz.to_bytes(4, "little") |
84 |
| - # Fix checksum |
85 |
| - f_bin[8:0xC] = crc32(f_bin).to_bytes(4, "little") |
86 |
| - # write final binary |
87 |
| - f = open(target_img, "wb") |
88 |
| - f.write(f_bin) |
89 |
| - f.close() |
90 |
| - |
91 |
| - |
92 | 62 | def gen_pac_file(target, source, env):
|
93 | 63 | (target_firm, ) = target
|
94 | 64 | (source_elf, ) = source
|
95 | 65 |
|
96 | 66 | # Generate image file
|
97 | 67 | if "darwin" in get_systype():
|
98 | 68 | print("Generating Firmware Image")
|
99 |
| - gen_img_file(target, source, env) |
| 69 | + mkimage(target, source, env) |
100 | 70 | else:
|
101 | 71 | env.Execute(
|
102 | 72 | env.VerboseAction("$MKIMAGE " + source_elf.get_abspath() + ' ' + join("$BUILD_DIR", env.subst('$PROGNAME') + '.img'),
|
@@ -138,6 +108,7 @@ def gen_pac_file(target, source, env):
|
138 | 108 | ]
|
139 | 109 | env.Execute(env.VerboseAction(" ".join(pac_cmd), " "))
|
140 | 110 |
|
| 111 | + |
141 | 112 | # Setup ENV
|
142 | 113 | env.Append(
|
143 | 114 | ASFLAGS=["-x", "assembler-with-cpp"],
|
@@ -226,10 +197,7 @@ def gen_pac_file(target, source, env):
|
226 | 197 |
|
227 | 198 | if "darwin" in get_systype():
|
228 | 199 | env["BUILDERS"]["BinToFOTA"] = Builder(
|
229 |
| - action=env.VerboseAction(" ".join([ |
230 |
| - 'echo', |
231 |
| - '"FOTA file generation is currently not supported. Please use Linux/Windows system."' |
232 |
| - ]), "Generating FOTA firmware $TARGET"), |
| 200 | + action=env.VerboseAction(gen_fota_file, "Generating FOTA firmware $TARGET"), |
233 | 201 | suffix=".bin"
|
234 | 202 | )
|
235 | 203 |
|
|
0 commit comments