|
13 | 13 | http://arduino.cc/en/Reference/HomePage
|
14 | 14 | """
|
15 | 15 |
|
16 |
| -from os.path import isdir, join |
| 16 | +from os.path import getsize, isdir, join |
17 | 17 | import json
|
| 18 | +from zlib import crc32 |
18 | 19 | from platformio.util import get_systype
|
19 | 20 |
|
20 | 21 | from SCons.Script import DefaultEnvironment
|
|
64 | 65 | env.Replace(LDSCRIPT_PATH="linkerscript_out.ld")
|
65 | 66 |
|
66 | 67 |
|
| 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 | + |
67 | 98 | def gen_pac_file(target, source, env):
|
68 | 99 | (target_firm, ) = target
|
69 | 100 | (source_elf, ) = source
|
| 101 | + |
70 | 102 | # 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 | + ) |
75 | 111 |
|
76 | 112 | # Generate pac file
|
77 | 113 | init_fdl = [
|
@@ -201,6 +237,15 @@ def gen_pac_file(target, source, env):
|
201 | 237 | )
|
202 | 238 | )
|
203 | 239 |
|
| 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 | + |
204 | 249 | # uploader flag update
|
205 | 250 | env.Prepend(
|
206 | 251 | UPLOAD_EXTRA_ARGS=[
|
|
0 commit comments