def Makesis(pkgfile, package, installed=None, cert=None, key=None, passwd="", env=None): """ Call makesis command line utility to create a sis package. If cert is given, key must be given. @param installed: Installed files( to be parsed from pkg in the future ) @param cert: Certificate used in signing @param key: Key used in signing @param passwd: Password used in signing """ if env is None: env = DefaultEnvironment() unsigned_package = package if installed is None: installed = [] output_files = [] output_files.append(package) # Always makesis = os.path.join(arguments.EPOC32_TOOLS, MAKESIS_EXECUTABLE) makesis = ("%s %s %s" % (makesis, pkgfile, unsigned_package)) env.Command(unsigned_package, installed + [pkgfile], makesis, ENV=os.environ) return output_files
def SignSis(target, source, cert, key, passwd="", env=None): """ Call signsis command line utility to create a sis package. """ if env is None: env = DefaultEnvironment() signsis = os.path.join(arguments.EPOC32_TOOLS, "signsis.exe") signsis = ("%s %s %s %s %s %s" % (signsis, handle_path(source), handle_path(target), handle_path(cert), handle_path(key), passwd)) env.Command(target, source, signsis, ENV=os.environ) return [target]
if "__pio_env" in config: return config return "" # # Generate final linker script # if not env.BoardConfig().get("build.ldscript", ""): linker_script = env.Command( join("$BUILD_DIR", "esp32_out.ld"), env.BoardConfig().get( "build.esp-idf.ldscript", join(FRAMEWORK_DIR, "components", "esp32", "ld", "esp32.ld"), ), env.VerboseAction( '$CC -I"$BUILD_DIR/config" -C -P -x c -E $SOURCE -o $TARGET', "Generating LD script $TARGET", ), ) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script) env.Replace(LDSCRIPT_PATH="esp32_out.ld") # # Generate partition table # fwpartitions_dir = join(FRAMEWORK_DIR, "components", "partition_table") partitions_csv = env.BoardConfig().get("build.partitions",
) # # Generate linker script # env.Replace( OUTLD_CFLAGS=[ "-DAPP_OFFSET=CONFIG_APP1_OFFSET", "-DAPP_SIZE=CONFIG_APP1_SIZE", ] ) linker_script = env.Command( join("$BUILD_DIR", "esp8266_out.ld"), join(FRAMEWORK_DIR, "components", "esp8266", "ld", "esp8266.ld"), env.VerboseAction( # $(CC) $(OUTLD_CFLAGS) -I ../include -C -P -x c -E $< -o $@ #origin '$CC $OUTLD_CFLAGS -I"$PROJECTSRC_DIR" -P -x c -E $SOURCE -o $TARGET', "Generating LD script $TARGET") ) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script) linker_script = env.Command( join("$BUILD_DIR", "esp8266_common_out.ld"), join(FRAMEWORK_DIR, "components", "esp8266", "ld", "esp8266.common.ld"), env.VerboseAction( # $(CC) -I ../include -C -P -x c -E $< -o $@ #origin '$CC -I"$PROJECTSRC_DIR" -P -x c -E $SOURCE -o $TARGET', "Generating LD script $TARGET") ) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script)
env.Append( LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")], LINKFLAGS=[ "-T", "esp32.common.ld", "-T", "esp32.rom.ld", "-T", "esp32.peripherals.ld" ], ) # # Generate partition table # partition_table = env.Command( join(env.subst("$BUILD_DIR"), "partitions_table.bin"), join("$ESPIDF_DIR", "components", "partition_table", "partitions_singleapp.csv"), '"$PYTHONEXE" "%s" -q $SOURCE $TARGET' % join("$ESPIDF_DIR", "components", "partition_table", "gen_esp32part.py")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table) # # Generate linker script # linker_script = env.Command( join("$BUILD_DIR", "esp32_out.ld"), join("$ESPIDF_DIR", "components", "esp32", "ld", "esp32.ld"), "$CC -I$PROJECTSRC_DIR -C -P -x c -E $SOURCE -o $TARGET") env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script)
UPLOADERFLAGS=[ "0x1000", join("$BUILD_DIR", "bootloader.bin"), "0x8000", join("$BUILD_DIR", "partitions_table.bin"), "0x10000" ] ) # # Generate partition table # partition_table = env.Command( join("$BUILD_DIR", "partitions_table.bin"), join(FRAMEWORK_DIR, "components", "partition_table", "partitions_singleapp.csv"), env.VerboseAction('"$PYTHONEXE" "%s" -q $SOURCE $TARGET' % join( FRAMEWORK_DIR, "components", "partition_table", "gen_esp32part.py"), "Generating partitions $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table) # # Generate linker script # linker_script = env.Command( join("$BUILD_DIR", "esp32_out.ld"), join(FRAMEWORK_DIR, "components", "esp32", "ld", "esp32.ld"), env.VerboseAction(
print("Warning! Detected custom MMU flags. Please use the " "`-D PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM` option to disable " "the default configuration.") assert mmu_flags env.Append(CPPDEFINES=mmu_flags) # Build the eagle.app.v6.common.ld linker file app_ld = env.Command( join("$BUILD_DIR", "ld", "local.eagle.app.v6.common.ld"), join(FRAMEWORK_DIR, "tools", "sdk", "ld", "eagle.app.v6.common.ld.h"), env.VerboseAction( "$CC -CC -E -P -D%s %s %s $SOURCE -o $TARGET" % ( current_vtables, # String representation of MMU flags " ".join([ "-D%s=%s" % f if isinstance(f, (tuple, list)) else "-D" + f for f in mmu_flags ]), fp_in_irom, ), "Generating LD script $TARGET", ), ) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", app_ld) if not env.BoardConfig().get("build.ldscript", ""): env.Replace( LDSCRIPT_PATH=env.BoardConfig().get("build.arduino.ldscript", "")) # # Dynamic core_version.h for staging builds
r"^(?:CODE|GSINIT|GSFINAL|CONST|HOME|RSEG0|SSEG|HEADER1|HEADER3|PREG2)[^=]*\D+(\d+).*", SIZEDATAREGEXP=r"^(?:DATA)[^=]*\D+(\d+).*", PROGNAME="firmware", PROGSUFFIX=".ihx") # # Target: Build executable and linkable firmware # #target_elf = None if "nobuild" in COMMAND_LINE_TARGETS: target_ihx = join("$BUILD_DIR", "${PROGNAME}.elf") target_bin = join("$BUILD_DIR", "${PROGNAME}.bin") else: target_ihx = env.BuildProgram() target_bin = env.Command(join("$BUILD_DIR", "${PROGNAME}.bin"), target_ihx, "$OBJCOPY -p $SOURCES $TARGET") # # Target: Print binary size # target_size = env.AddPlatformTarget( "size", target_bin, sizePrintCMD, "Program Size", "Calculate program size", ) # # Target: Upload firmware
env.BoardConfig().get("build.variant")) ]) libs.append( env.BuildLibrary( join("$BUILD_DIR", "FrameworkArduinoVariant"), join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant")))) envsafe = env.Clone() libs.append( envsafe.BuildLibrary( join("$BUILD_DIR", "FrameworkArduino"), join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")))) env.Prepend(LIBS=libs) # # Generate partition table # partition_table = env.Command( join("$BUILD_DIR", "partitions.bin"), join(FRAMEWORK_DIR, "tools", "partitions", "default.csv"), env.VerboseAction( '"$PYTHONEXE" "%s" -q $SOURCE $TARGET' % join(FRAMEWORK_DIR, "tools", "gen_esp32part.py"), "Generating partitions $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table)
# Allow user to override via pre:script if env.get("PROGNAME", "program") == "program": env.Replace(PROGNAME="firmware") # # Target: Build executable and linkable firmware # target_elf = None if "nobuild" in COMMAND_LINE_TARGETS: target_elf = join("$BUILD_DIR", "${PROGNAME}.elf") target_firm = join("$BUILD_DIR", "${PROGNAME}.ihx") else: target_elf = env.BuildProgram() target_firm = env.Command( join("$BUILD_DIR", "${PROGNAME}.ihx"), env['PIOBUILDFILES'], env['LINKCOM'].replace("$LINKFLAGS", "$ldflags_for_hex")) env.Depends(target_firm, target_elf) AlwaysBuild(env.Alias("nobuild", target_firm)) target_buildprog = env.Alias("buildprog", target_firm, target_firm) # # Target: Print binary size # target_size = env.Alias( "size", target_elf, env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE")) AlwaysBuild(target_size)
# script. We can just use the info here linkerscript_cmd = env.Command( os.path.join("$BUILD_DIR", "memmap_default.ld"), # $TARGET os.path.join(FRAMEWORK_DIR, "lib", "memmap_default.ld"), # $SOURCE env.VerboseAction( " ".join([ '"$PYTHONEXE" "%s"' % os.path.join(FRAMEWORK_DIR, "tools", "simplesub.py"), "--input", "$SOURCE", "--out", "$TARGET", "--sub", "__FLASH_LENGTH__", "$PICO_FLASH_LENGTH", "--sub", "__EEPROM_START__", "$PICO_EEPROM_START", "--sub", "__FS_START__", "$FS_START", "--sub", "__FS_END__", "$FS_END", "--sub", "__RAM_LENGTH__", "%dk" % (ram_size // 1024), ]), "Generating linkerscript $BUILD_DIR/memmap_default.ld")) # if no custom linker script is provided, we use the command that we prepared to generate one.
# # Linker requires preprocessing with link flags # if not board.get("build.ldscript", ""): ldscript = os.path.join(FRAMEWORK_DIR, configuration.get("ldscript", [])[0] or "") if board.get("build.mbed.ldscript", ""): ldscript = env.subst(board.get("build.mbed.ldscript")) if os.path.isfile(ldscript): linker_script = env.Command( os.path.join( "$BUILD_DIR", "%s.link_script.ld" % os.path.basename(ldscript) ), ldscript, env.VerboseAction( "%s -E -P $LINKFLAGS $SOURCE -o $TARGET" % env.subst("$GDB").replace("-gdb", "-cpp"), "Generating LD script $TARGET", ), ) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script) env.Replace(LDSCRIPT_PATH=linker_script) else: print("Warning! Couldn't find linker script file!") # # Compile core part #
print("Warning! Cannot find softdevice binary" "Firmware will be linked without it!") # # Generate linker script # env.Replace(LDSCRIPT_PATH=join(FRAMEWORK_DIR, mbed_config.get("ldscript"))) if not env.get("LDSCRIPT_PATH"): sys.stderr.write("Cannot find linker script for your board!\n") env.Exit(1) linker_script = env.Command( join("$BUILD_DIR", "%s.link_script.ld" % basename(env.get("LDSCRIPT_PATH"))), "$LDSCRIPT_PATH", env.VerboseAction( '%s -E -P $LINKPPFLAGS $SOURCE -o $TARGET' % env.subst("$GDB").replace("-gdb", "-cpp"), "Generating LD script $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script) env.Replace(LDSCRIPT_PATH=linker_script) # # Initialize libraries for LDF # for lib, lib_config in libs.items(): extra_includes = [] if lib == "events" and not MBED_RTOS: # Manually handle dependency on rtos lib
# in a special file "version.h" in the root folder of the package # create_verion_file() # # Generate final linker script # if not board.get("build.ldscript", ""): linker_script = env.Command( os.path.join("$BUILD_DIR", "%s_out.ld" % idf_variant), board.get( "build.esp-idf.ldscript", os.path.join(FRAMEWORK_DIR, "components", idf_variant, "ld", "%s.ld" % idf_variant), ), env.VerboseAction( '$CC -I"$BUILD_DIR/config" -C -P -x c -E $SOURCE -o $TARGET', "Generating LD script $TARGET", ), ) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script) env.Replace(LDSCRIPT_PATH="%s_out.ld" % idf_variant) # # Generate partition table # fwpartitions_dir = os.path.join(FRAMEWORK_DIR, "components", "partition_table") partitions_csv = board.get("build.partitions", "partitions_singleapp.csv")
# VTables # current_vtables = None for d in flatten_cppdefines: if str(d).startswith("VTABLES_IN_"): current_vtables = d if not current_vtables: current_vtables = "VTABLES_IN_FLASH" env.Append(CPPDEFINES=[current_vtables]) assert current_vtables # Build the eagle.app.v6.common.ld linker file app_ld = env.Command( join("$BUILD_DIR", "ld", "eagle.app.v6.common.ld"), join(FRAMEWORK_DIR, "tools", "sdk", "ld", "eagle.app.v6.common.ld.h"), env.VerboseAction( "$CC -CC -E -P -D%s $SOURCE -o $TARGET" % current_vtables, "Generating LD script $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", app_ld) # # Target: Build Core Library # libs = [] if "build.variant" in env.BoardConfig(): env.Append(CPPPATH=[ join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant")) ])
# VTables # current_vtables = None for d in flatten_cppdefines: if str(d).startswith("VTABLES_IN_"): current_vtables = d if not current_vtables: current_vtables = "VTABLES_IN_FLASH" env.Append(CPPDEFINES=[current_vtables]) assert current_vtables # Build the eagle.app.v6.common.ld linker file app_ld = env.Command( join("$BUILD_DIR", "ld", "local.eagle.app.v6.common.ld"), join(FRAMEWORK_DIR, "tools", "sdk", "ld", "eagle.app.v6.common.ld.h"), env.VerboseAction( "$CC -CC -E -P -D%s $SOURCE -o $TARGET" % current_vtables, "Generating LD script $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", app_ld) # # Dynamic core_version.h for staging builds # def platform_txt_version(default): with open(join(FRAMEWORK_DIR, "platform.txt"), "r") as platform_txt: for line in platform_txt: if not line: continue k, delim, v = line.partition("=") if not delim:
# # Generate partition table # fwpartitions_dir = join(FRAMEWORK_DIR, "components", "partition_table") partitions_csv = env.BoardConfig().get("build.partitions", "partitions_singleapp.csv") env.Replace(PARTITIONS_TABLE_CSV=abspath( join(fwpartitions_dir, partitions_csv) if isfile( join(fwpartitions_dir, partitions_csv)) else partitions_csv)) partition_table = env.Command( join("$BUILD_DIR", "partitions.bin"), "$PARTITIONS_TABLE_CSV", env.VerboseAction( '"$PYTHONEXE" "%s" -q --flash-size "%s" $SOURCE $TARGET' % (join(FRAMEWORK_DIR, "components", "partition_table", "gen_esp32part.py"), env.BoardConfig().get( "upload.flash_size", "detect")), "Generating partitions $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table) # # Generate linker script # linker_script = env.Command( join("$BUILD_DIR", "esp32_out.ld"), join(FRAMEWORK_DIR, "components", "esp32", "ld", "esp32.ld"), env.VerboseAction( '$CC -I"$PROJECTSRC_DIR" -C -P -x c -E $SOURCE -o $TARGET',
envsafe = env.Clone() libs.append( envsafe.BuildLibrary( join("$BUILD_DIR", "FrameworkArduino"), join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")))) env.Prepend(LIBS=libs) # # Generate partition table # fwpartitions_dir = join(FRAMEWORK_DIR, "tools", "partitions") partitions_csv = env.BoardConfig().get("build.arduino.partitions", "default.csv") if "build.partitions" in env.BoardConfig(): partitions_csv = env.BoardConfig().get("build.partitions") env.Replace(PARTITIONS_TABLE_CSV=abspath( join(fwpartitions_dir, partitions_csv) if isfile( join(fwpartitions_dir, partitions_csv)) else partitions_csv)) partition_table = env.Command( join("$BUILD_DIR", "partitions.bin"), "$PARTITIONS_TABLE_CSV", env.VerboseAction( '"$PYTHONEXE" "%s" -q $SOURCE $TARGET' % join(FRAMEWORK_DIR, "tools", "gen_esp32part.py"), "Generating partitions $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", partition_table)
if "nordicnrf5" in env.get("PIOPLATFORM"): softdevice_hex_path = join(FRAMEWORK_DIR, mbed_config.get("softdevice_hex", "")) if softdevice_hex_path and isfile(softdevice_hex_path): env.Append(SOFTDEVICEHEX=softdevice_hex_path) else: print("Warning! Cannot find softdevice binary" "Firmware will be linked without it!") # # Generate linker script # env.Replace(LDSCRIPT_PATH=join(FRAMEWORK_DIR, mbed_config.get("ldscript"))) if not env.get("LDSCRIPT_PATH"): sys.stderr.write("Cannot find linker script for your board!\n") env.Exit(1) linker_script = env.Command( join("$BUILD_DIR", "%s.link_script.ld" % basename(env.get("LDSCRIPT_PATH"))), env.get("LDSCRIPT_PATH"), env.VerboseAction( "arm-none-eabi-cpp -E -P %s $SOURCE -o $TARGET" % " ".join(mbed_config.get("build_flags").get("ld")), "Generating LD script $TARGET")) env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", linker_script) env.Replace(LDSCRIPT_PATH=linker_script)