Skip to content

Commit b3eb591

Browse files
committed
Update Arduino builder script for RDA8910
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent ea21e8a commit b3eb591

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

builder/framework/rda8910/arduino.py

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

16-
from os.path import isdir, join
16+
from os.path import getsize, isdir, join
1717
import json
18+
from zlib import crc32
1819
from platformio.util import get_systype
1920

2021
from SCons.Script import DefaultEnvironment
@@ -64,14 +65,49 @@
6465
env.Replace(LDSCRIPT_PATH="linkerscript_out.ld")
6566

6667

68+
def gen_img_file(target, source, env):
69+
cmd = ["$OBJCOPY"]
70+
(target_firm, ) = target
71+
(source_elf, ) = source
72+
73+
target_img = env.subst("$BUILD_DIR/$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+
6798
def gen_pac_file(target, source, env):
6899
(target_firm, ) = target
69100
(source_elf, ) = source
101+
70102
# Generate image file
71-
env.Execute(
72-
env.VerboseAction("$MKIMAGE " + source_elf.get_abspath() + ' "$BUILD_DIR/$PROGNAME"' + '.img',
73-
"Generating Firmware Image")
74-
)
103+
if "darwin" in get_systype():
104+
print("Generating Firmware Image")
105+
gen_img_file(target, source, env)
106+
else:
107+
env.Execute(
108+
env.VerboseAction("$MKIMAGE " + source_elf.get_abspath() + ' "$BUILD_DIR/$PROGNAME"' + '.img',
109+
"Generating Firmware Image")
110+
)
75111

76112
# Generate pac file
77113
init_fdl = [
@@ -201,6 +237,15 @@ def gen_pac_file(target, source, env):
201237
)
202238
)
203239

240+
if "darwin" in get_systype():
241+
env["BUILDERS"]["BinToFOTA"] = Builder(
242+
action=env.VerboseAction(" ".join([
243+
'echo',
244+
'"FOTA file generation is currently not supported. Please use Linux/Windows system."'
245+
]), "Generating FOTA firmware $TARGET"),
246+
suffix=".bin"
247+
)
248+
204249
# uploader flag update
205250
env.Prepend(
206251
UPLOAD_EXTRA_ARGS=[

0 commit comments

Comments
 (0)