Skip to content

Commit

Permalink
Fix RDA8910 image generation on MacOS
Browse files Browse the repository at this point in the history
Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
  • Loading branch information
ajaybhargav committed Oct 20, 2021
1 parent 1289d77 commit 7d9d1c2
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions builder/framework/rda8910/logicromsdk.py
Expand Up @@ -3,9 +3,10 @@
# SPDX-License-Identifier: MIT
#

from os.path import isdir, isfile, join
from os.path import getsize, isdir, isfile, join
from shutil import copyfile
import json
from zlib import crc32
from platformio.util import get_systype

from SCons.Script import DefaultEnvironment
Expand Down Expand Up @@ -57,14 +58,49 @@
if (False == isfile(main_c)) and (False == isfile(main_cpp)):
copyfile(join(FRAMEWORK_DIR, "template", "main.c"), main_c)


def gen_img_file(target, source, env):
cmd = ["$OBJCOPY"]
(target_firm, ) = target
(source_elf, ) = source

target_img = env.subst("$BUILD_DIR/$PROGNAME") + '.img'

cmd.extend(["-O", "binary"])
cmd.append(source_elf.get_abspath())
cmd.append(target_img)
env.Execute(env.VerboseAction(" ".join(cmd), " "))

# fix bin size to 0x80 boundary
binsz = getsize(target_img)
f_binsz = (binsz + 0x7F) & ~0x7F
print("Binary size: %d" % binsz)
f = open(target_img, "rb")
f_bin = bytearray(f.read())
f.close()
f_bin += bytes(f_binsz - binsz)
# Fix header size
f_bin[4:8] = f_binsz.to_bytes(4, "little")
# Fix checksum
f_bin[8:0xC] = crc32(f_bin).to_bytes(4, "little")
# write final binary
f = open(target_img, "wb")
f.write(f_bin)
f.close()

def gen_pac_file(target, source, env):
(target_firm, ) = target
(source_elf, ) = source

# Generate image file
env.Execute(
env.VerboseAction("$MKIMAGE " + source_elf.get_abspath() + ' "$BUILD_DIR/$PROGNAME"' + '.img',
"Generating Firmware Image")
)
if "darwin" in get_systype():
print("Generating Firmware Image")
gen_img_file(target, source, env)
else:
env.Execute(
env.VerboseAction("$MKIMAGE " + source_elf.get_abspath() + ' "$BUILD_DIR/$PROGNAME"' + '.img',
"Generating Firmware Image")
)

# Generate pac file
init_fdl = [
Expand Down

0 comments on commit 7d9d1c2

Please sign in to comment.