Skip to content

Commit eb55993

Browse files
committed
builder:rda8910:use rdautils for darwin system
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent 1dc8012 commit eb55993

File tree

2 files changed

+13
-78
lines changed

2 files changed

+13
-78
lines changed

builder/framework/rda8910/arduino.py

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
http://arduino.cc/en/Reference/HomePage
1414
"""
1515

16-
from os.path import getsize, isdir, join
17-
import json
18-
from zlib import crc32
16+
from os.path import isdir, join
17+
from json import load
18+
from rdautils import mkimage, gen_fota_file
1919
from platformio.util import get_systype
2020

2121
from SCons.Script import DefaultEnvironment
@@ -32,7 +32,7 @@
3232

3333
# Load core configuration
3434
with open(join(LOGICROMSDK_DIR, "lib", "rda8910", "core_config.json")) as f:
35-
core_config = json.load(f)
35+
core_config = load(f)
3636
f.close()
3737

3838
# RDA Tools
@@ -65,44 +65,14 @@
6565
env.Replace(LDSCRIPT_PATH="linkerscript_out.ld")
6666

6767

68-
def gen_img_file(target, source, env):
69-
cmd = ["$OBJCOPY"]
70-
(target_firm, ) = target
71-
(source_elf, ) = source
72-
73-
target_img = join(env.subst("$BUILD_DIR"), env.subst("$PROGNAME") + '.img')
74-
75-
cmd.extend(["-O", "binary"])
76-
cmd.append(source_elf.get_abspath())
77-
cmd.append(target_img)
78-
env.Execute(env.VerboseAction(" ".join(cmd), " "))
79-
80-
# fix bin size to 0x80 boundary
81-
binsz = getsize(target_img)
82-
f_binsz = (binsz + 0x7F) & ~0x7F
83-
print("Binary size: %d" % binsz)
84-
f = open(target_img, "rb")
85-
f_bin = bytearray(f.read())
86-
f.close()
87-
f_bin += bytes(f_binsz - binsz)
88-
# Fix header size
89-
f_bin[4:8] = f_binsz.to_bytes(4, "little")
90-
# Fix checksum
91-
f_bin[8:0xC] = crc32(f_bin).to_bytes(4, "little")
92-
# write final binary
93-
f = open(target_img, "wb")
94-
f.write(f_bin)
95-
f.close()
96-
97-
9868
def gen_pac_file(target, source, env):
9969
(target_firm, ) = target
10070
(source_elf, ) = source
10171

10272
# Generate image file
10373
if "darwin" in get_systype():
10474
print("Generating Firmware Image")
105-
gen_img_file(target, source, env)
75+
mkimage(target, source, env)
10676
else:
10777
env.Execute(
10878
env.VerboseAction("$MKIMAGE " + source_elf.get_abspath() + ' ' + join("$BUILD_DIR", env.subst("$PROGNAME") + '.img'),
@@ -240,10 +210,7 @@ def gen_pac_file(target, source, env):
240210

241211
if "darwin" in get_systype():
242212
env["BUILDERS"]["BinToFOTA"] = Builder(
243-
action=env.VerboseAction(" ".join([
244-
'echo',
245-
'"FOTA file generation is currently not supported. Please use Linux/Windows system."'
246-
]), "Generating FOTA firmware $TARGET"),
213+
action=env.VerboseAction(gen_fota_file, "Generating FOTA firmware $TARGET"),
247214
suffix=".bin"
248215
)
249216

builder/framework/rda8910/logicromsdk.py

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# SPDX-License-Identifier: MIT
44
#
55

6-
from os.path import getsize, isdir, isfile, join
6+
from os.path import isdir, isfile, join
77
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
1010
from platformio.util import get_systype
1111

1212
from SCons.Script import DefaultEnvironment
@@ -20,7 +20,7 @@
2020

2121
# Load core configuration
2222
with open(join(FRAMEWORK_DIR, "lib", "rda8910", "core_config.json")) as f:
23-
core_config = json.load(f)
23+
core_config = load(f)
2424
f.close()
2525

2626
# RDA Tools
@@ -59,44 +59,14 @@
5959
copyfile(join(FRAMEWORK_DIR, "template", "main.c"), main_c)
6060

6161

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-
9262
def gen_pac_file(target, source, env):
9363
(target_firm, ) = target
9464
(source_elf, ) = source
9565

9666
# Generate image file
9767
if "darwin" in get_systype():
9868
print("Generating Firmware Image")
99-
gen_img_file(target, source, env)
69+
mkimage(target, source, env)
10070
else:
10171
env.Execute(
10272
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):
138108
]
139109
env.Execute(env.VerboseAction(" ".join(pac_cmd), " "))
140110

111+
141112
# Setup ENV
142113
env.Append(
143114
ASFLAGS=["-x", "assembler-with-cpp"],
@@ -226,10 +197,7 @@ def gen_pac_file(target, source, env):
226197

227198
if "darwin" in get_systype():
228199
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"),
233201
suffix=".bin"
234202
)
235203

0 commit comments

Comments
 (0)