Ejemplo n.º 1
0
    Default(_new_targets)
    Default("checkprogsize")

if "compiledb" in COMMAND_LINE_TARGETS:
    env.Alias("compiledb", env.CompilationDatabase("$COMPILATIONDB_PATH"))

# Print configured protocols
env.AddPreAction(
    ["upload", "program"],
    env.VerboseAction(
        lambda source, target, env: env.PrintUploadInfo(),
        "Configuring upload protocol...",
    ),
)

AlwaysBuild(env.Alias("debug", DEFAULT_TARGETS))
AlwaysBuild(env.Alias("__test", DEFAULT_TARGETS))

##############################################################################

if "envdump" in COMMAND_LINE_TARGETS:
    click.echo(env.Dump())
    env.Exit(0)

if "idedata" in COMMAND_LINE_TARGETS:
    try:
        Import("projenv")
    except:  # pylint: disable=bare-except
        projenv = env
    click.echo("\n%s\n" % dump_json_to_unicode(
        projenv.DumpIDEData(env)  # pylint: disable=undefined-variable
Ejemplo n.º 2
0
#
# Target: Build the .hex file
#

if "uploadlazy" in COMMAND_LINE_TARGETS:
    target_firm = join("$BUILD_DIR", "firmware.hex")
else:
    target_firm = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf)

#
# Target: Print binary size
#

target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Upload by default .hex file
#

upload = env.Alias(["upload", "uploadlazy"], target_firm,
                   [BeforeUpload, "$UPLOADHEXCMD"])
AlwaysBuild(upload)

#
# Target: Upload .eep file
#

uploadeep = env.Alias("uploadeep", target_eep, [BeforeUpload, "$UPLOADEEPCMD"])
AlwaysBuild(uploadeep)
Ejemplo n.º 3
0
        if "nrfutil" == upload_protocol:
            target_firm = env.PackageDfu(
                join("$BUILD_DIR", "${PROGNAME}"),
                env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf))
        elif "nrfjprog" == upload_protocol:
            target_firm = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"),
                                       target_elf)
        else:
            target_firm = env.SignBin(
                join("$BUILD_DIR", "${PROGNAME}"),
                env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf))
    else:
        target_firm = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"),
                                   target_elf)

AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)

if "DFUBOOTHEX" in env:
    env.Append(
        # Check the linker script for the correct location
        BOOT_SETTING_ADDR=board.get("build.bootloader.settings_addr",
                                    "0x7F000"))

    AlwaysBuild(
        env.Alias(
            "dfu",
            env.PackageDfu(
                join("$BUILD_DIR", "${PROGNAME}"),
                env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf))))
Ejemplo n.º 4
0
        __tmp_hook_before_pio_3_2()
        fetch_spiffs_size(env)
        target_firm = join("$BUILD_DIR", "spiffs.bin")
    elif env.subst("$PIOFRAMEWORK") in ("intorobot"):
        target_firm = join("$BUILD_DIR", "firmware.bin")
    else:
        target_firm = [
            join("$BUILD_DIR", "eagle.flash.bin"),
            join("$BUILD_DIR", "eagle.irom0text.bin")
        ]
else:
    if set(["buildfs", "uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
        __tmp_hook_before_pio_3_2()
        target_firm = env.DataToBin(join("$BUILD_DIR", "spiffs"),
                                    "$PROJECTDATA_DIR")
        AlwaysBuild(target_firm)
        AlwaysBuild(env.Alias("buildfs", target_firm))
    else:
        target_elf = env.BuildProgram()
        if env.subst("$PIOFRAMEWORK") in ("intorobot"):
            target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"),
                                       target_elf)
        else:
            target_firm = env.ElfToBin([
                join("$BUILD_DIR", "eagle.flash.bin"),
                join("$BUILD_DIR", "eagle.irom0text.bin")
            ], target_elf)

AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
Ejemplo n.º 5
0
        ]
    )

#
# 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}.hex")
else:
    target_elf = env.BuildProgram()
    target_firm = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), 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)

#
# Target: Upload firmware
#
debug_tools = env.BoardConfig().get("debug.tools", {})
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
Ejemplo n.º 6
0
def BuildProgram(env):

    def _append_pio_macros():
        env.AppendUnique(CPPDEFINES=[(
            "PLATFORMIO",
            int("{0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())))])

    _append_pio_macros()

    env.PrintConfiguration()

    # fix ASM handling under non case-sensitive OS
    if not Util.case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    if "__debug" in COMMAND_LINE_TARGETS:
        env.ProcessDebug()

    # process extra flags from board
    if "BOARD" in env and "build.extra_flags" in env.BoardConfig():
        env.ProcessFlags(env.BoardConfig().get("build.extra_flags"))

    # apply user flags
    env.ProcessFlags(env.get("BUILD_FLAGS"))

    # process framework scripts
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))

    # restore PIO macros if it was deleted by framework
    _append_pio_macros()

    # remove specified flags
    env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))

    if "__test" in COMMAND_LINE_TARGETS:
        env.ProcessTest()

    # build project with dependencies
    _build_project_deps(env)

    # append into the beginning a main LD script
    if (env.get("LDSCRIPT_PATH")
            and not any("-Wl,-T" in f for f in env['LINKFLAGS'])):
        env.Prepend(LINKFLAGS=["-T", "$LDSCRIPT_PATH"])

    # enable "cyclic reference" for linker
    if env.get("LIBS") and env.GetCompilerType() == "gcc":
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    program = env.Program(
        join("$BUILD_DIR", env.subst("$PROGNAME")), env['PIOBUILDFILES'])
    env.Replace(PIOMAINPROG=program)

    AlwaysBuild(
        env.Alias(
            "checkprogsize", program,
            env.VerboseAction(env.CheckUploadSize,
                              "Checking size $PIOMAINPROG")))

    return program
Ejemplo n.º 7
0
#
# Target: Build executable and linkable firmware or SPIFFS image
#

target_elf = env.BuildProgram()
if "nobuild" in COMMAND_LINE_TARGETS:
    if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
        fetch_spiffs_size(env)
        target_firm = join("$BUILD_DIR", "spiffs.bin")
    else:
        target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
else:
    if set(["buildfs", "uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
        target_firm = env.DataToBin(join("$BUILD_DIR", "spiffs"),
                                    "$PROJECTDATA_DIR")
        AlwaysBuild(target_firm)
        AlwaysBuild(env.Alias("buildfs", target_firm))
    else:
        target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"),
                                   target_elf)

AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)

# update max upload size based on CSV file
if env.get("PIOMAINPROG"):
    env.AddPreAction(
        "checkprogsize",
        env.VerboseAction(
            lambda source, target, env: _update_max_upload_size(env),
            "Retrieving maximum program size $SOURCES"))
Ejemplo n.º 8
0
    )

#
# Target: Build executable and linkable firmware
#

target_elf = env.BuildProgram()

#
# Target: Build the .hex or SPIFFS image
#

if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
    target_firm = env.DataToBin(
        join("$BUILD_DIR", "spiffs"), "$PROJECTDATA_DIR")
    AlwaysBuild(target_firm)

elif "uploadlazy" in COMMAND_LINE_TARGETS:
    if "FRAMEWORK" not in env:
        target_firm = [
            join("$BUILD_DIR", "firmware_00000.bin"),
            join("$BUILD_DIR", "firmware_40000.bin")
        ]
    else:
        target_firm = join("$BUILD_DIR", "firmware.bin")
else:
    if "FRAMEWORK" not in env:
        target_firm = env.ElfToBin(
            [join("$BUILD_DIR", "firmware_00000"),
             join("$BUILD_DIR", "firmware_40000")], target_elf)
    else:
Ejemplo n.º 9
0
            "_INIT_DECLARATION_REQUIRED"
        ],
        LINKFLAGS=["-mcpu=%s" % env.BoardConfig().get("build.cpu")])

#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()

#
# Target: Print binary size
#
target_size = env.Alias(
    "size", target_elf,
    env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"))
AlwaysBuild(target_size)

#
# Target: Build the .hex file
#
target_hex = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf)

#
# Target: Upload firmware
#
debug_tools = env.BoardConfig().get("debug.tools", {})
upload_protocol = env.subst("$UPLOAD_PROTOCOL")


def _jlink_cmd_script(env, source):
    build_dir = env.subst("$BUILD_DIR")
Ejemplo n.º 10
0
# Restore C/C++ build flags as they were overridden by env.Tool
env.Append(CFLAGS=backup_cflags, CXXFLAGS=backup_cxxflags)

#
# Target: Build executable program
#

target_bin = env.BuildProgram()

#
# Target: Execute binary
#

exec_action = env.VerboseAction("$SOURCE $PROGRAM_ARGS", "Executing $SOURCE")

AlwaysBuild(env.Alias("exec", target_bin, exec_action))
AlwaysBuild(env.Alias("upload", target_bin, exec_action))

#
# Target: Print binary size
#

target_size = env.Alias(
    "size", target_bin,
    env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"))
AlwaysBuild(target_size)

#
# Default targets
#
Ejemplo n.º 11
0
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##########################################################################
# Autor: WizIO 2018 Georgi Angelov
#   http://www.wizio.eu/
#   https://github.com/Wiz-IO/platform-azure
# 
# Support: Comet Electronics 
#   https://www.comet.bg/?cid=92
##########################################################################

from os.path import join
from SCons.Script import (AlwaysBuild, Default, DefaultEnvironment)
from colorama import Fore

env = DefaultEnvironment()
print( Fore.GREEN + '<<<<<<<<<<<< ' + env.BoardConfig().get("name").upper() + " 2019 Georgi Angelov >>>>>>>>>>>>" + Fore.BLACK )
elf = env.BuildProgram()
src = env.PackImage( join("$BUILD_DIR", "${PROGNAME}"), elf ) 
AlwaysBuild( src )
upload = env.Alias("upload", src, [ env.VerboseAction("$UPLOADCMD", "\n"), env.VerboseAction("", "\n") ] )
AlwaysBuild( upload )    
Default( src )
Ejemplo n.º 12
0
Archivo: main.py Proyecto: OS-Q/P68
#
# 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}.bin")
    target_firm_fota = join("$BUILD_DIR", "fota_${PROGNAME}.bin")
else:
    target_elf = env.BuildProgram()
    target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf)
    target_firm_fota = env.BinToFOTA(
        join("$BUILD_DIR", "fota_${PROGNAME}"), target_firm)

AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)

#
# Target: Build FOTA Binary
#

target_buildota = env.Alias("buildfota", target_firm_fota, target_firm_fota)
AlwaysBuild(target_buildota)

#
# Target: Print binary size
#

target_size = env.Alias("size", target_elf, env.VerboseAction(
    "$SIZEPRINTCMD", "Calculating size $SOURCE"))
Ejemplo n.º 13
0
app_includes = get_app_includes(elf_config)
project_lib_includes = get_project_lib_includes(env)

#
# Compile bootloader
#

env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", build_bootloader())

#
# Target: ESP-IDF menuconfig
#

AlwaysBuild(
    env.Alias(
        "menuconfig", None, [env.VerboseAction(RunMenuconfig, "Running menuconfig...")]
    )
)

#
# Process main parts of the framework
#

libs = find_lib_deps(
    framework_components_map, elf_config, link_args, [project_target_name]
)

# Extra flags which need to be explicitly specified in LINKFLAGS section because SCons
# cannot merge them correctly
extra_flags = filter_args(link_args["LINKFLAGS"], ["-T", "-u"])
link_args["LINKFLAGS"] = sorted(list(set(link_args["LINKFLAGS"]) - set(extra_flags)))
Ejemplo n.º 14
0
    env.Replace(
        __jlink_cmd_script=_jlink_cmd_script,
        UPLOADER="JLink.exe" if system() == "Windows" else "JLinkExe",
        UPLOADERFLAGS=[
            "-device",
            env.BoardConfig().get("debug", {}).get("jlink_device"), "-speed",
            "4000", "-if",
            ("jtag" if upload_protocol == "jlink-jtag" else "swd"),
            "-autoconnect", "1"
        ],
        UPLOADCMD=
        '$UPLOADER $UPLOADERFLAGS -CommanderScript "${__jlink_cmd_script(__env__, SOURCE)}"'
    )

    AlwaysBuild(
        env.Alias("upload", upload_source,
                  [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]))
#elif upload_protocol in debug_tools:
#    env.Replace(
#        UPLOADER="openocd",
#        UPLOADERFLAGS=["-s", platform.get_package_dir("tool-openocd") or ""] +
#        debug_tools.get(upload_protocol).get("server").get("arguments", []) + [
#            "-c",
#            "program {$SOURCE} verify reset %s; shutdown;" %
#            env.BoardConfig().get("upload.offset_address", "")
#        ],
#        UPLOADCMD="$UPLOADER $UPLOADERFLAGS")
#
#    if not env.BoardConfig().get("upload").get("offset_address"):
#        upload_source = target_firm_elf
#
Ejemplo n.º 15
0
#

if "zephyr" in env.get("PIOFRAMEWORK", []):
    env.SConscript(join(platform.get_package_dir("framework-zephyr"),
                        "scripts", "platformio", "platformio-build-pre.py"),
                   exports={"env": env})

target_elf = None
if "nobuild" in COMMAND_LINE_TARGETS:
    target_elf = join("$BUILD_DIR", "${PROGNAME}.elf")
    target_hex = join("$BUILD_DIR", "${PROGNAME}.hex")
else:
    target_elf = env.BuildProgram()
    target_hex = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf)

AlwaysBuild(env.Alias("nobuild", target_elf))
target_buildprog = env.Alias("buildprog", target_elf, target_elf)

#
# Target: Print binary size
#

target_size = env.Alias(
    "size", target_elf,
    env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"))
AlwaysBuild(target_size)

#
# Target: Upload by default .bin file
#
Ejemplo n.º 16
0
    DATABASE_PATH, '--idcode ' + env.BoardConfig().get('build.idcode', '')
    if env.BoardConfig().get('build.idcode', '') else ''),
                    suffix='.bit',
                    src_suffix='.config')

env.Append(BUILDERS={'Synth': synth, 'PnR': pnr, 'Bin': bitstream})

blif = env.Synth(TARGET, [src_synth])
config = env.PnR(TARGET, [blif, LPF])
bit = env.Bin(TARGET, config)

#
# Target: Upload bitstream
#
target_upload = env.Alias('upload', bit, '$UPLOADBINCMD')
AlwaysBuild(target_upload)

#
# Builders: Icarus Verilog
#
iverilog = Builder(
    action='iverilog {0} -o $TARGET -D VCD_OUTPUT={1} {2} $SOURCES'.format(
        IVER_PATH, TARGET_SIM + '.vcd' if TARGET_SIM else '', VLIB_FILES),
    suffix='.out',
    src_suffix='.v')
vcd = Builder(action='vvp {0} $SOURCE'.format(VVP_PATH),
              suffix='.vcd',
              src_suffix='.out')
# NOTE: output file name is defined in the
#       iverilog call using VCD_OUTPUT macro
Ejemplo n.º 17
0
# Checking program size
if env.get("SIZETOOL") and "nobuild" not in COMMAND_LINE_TARGETS:
    env.Depends(["upload", "program"], "checkprogsize")
    # Replace platform's "size" target with our
    _new_targets = [t for t in DEFAULT_TARGETS if str(t) != "size"]
    Default(None)
    Default(_new_targets)
    Default("checkprogsize")

# Print configured protocols
env.AddPreAction(
    ["upload", "program"],
    env.VerboseAction(lambda source, target, env: env.PrintUploadInfo(),
                      "Configuring upload protocol..."))

AlwaysBuild(env.Alias("debug", DEFAULT_TARGETS))
AlwaysBuild(env.Alias("__test", DEFAULT_TARGETS))

##############################################################################

if "envdump" in COMMAND_LINE_TARGETS:
    print(env.Dump())
    env.Exit(0)

if "idedata" in COMMAND_LINE_TARGETS:
    Import("projenv")
    print("\n%s\n" % dump_json_to_unicode(
        env.DumpIDEData(projenv)  # pylint: disable=undefined-variable
    ))
    env.Exit(0)
Ejemplo n.º 18
0
#
# Target: Build the .bin file
#

if "uploadlazy" in COMMAND_LINE_TARGETS:
    target_firm = join("$BUILD_DIR", "firmware.bin")
else:
    target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf)

#
# Target: Print binary size
#

target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Upload by default .bin file
#

upload = env.Alias(["upload", "uploadlazy"], target_firm,
                   [BeforeUpload, "$UPLOADCMD"])

AlwaysBuild(upload)

#
# Target: Unit Testing
#

AlwaysBuild(env.Alias("test", [target_firm, target_size]))
Ejemplo n.º 19
0
]

uploading = [
    env.VerboseAction(
        BTAsize_create,
        "Generating " + join(env.subst("$BUILD_DIR"), "BTAsize.gdb")),
    env.VerboseAction(
        fwsize_create,
        "Generating " + join(env.subst("$BUILD_DIR"), "fwsize.gdb")),
    env.VerboseAction(
        replace_rtl, "Generating " +
        join(env.subst("$BUILD_DIR"), "rtl_gdb_flash_write.txt")),
    env.VerboseAction(
        "$CP $BOOTALL_BIN " + join(env.subst("$BUILD_DIR"), "boot_all.bin"),
        '.'),
    env.VerboseAction(
        env.subst("$UPLOADCMD").replace("\\", "\\\\") + env["OPENOCD_KILL"],
        "Uploading binary to flash"),
]

env.Append(BUILDERS=dict(Manipulate=Builder(
    action=env.VerboseAction(manipulating, "Manipulating images")), ))

program_b = env.BuildProgram()
manipulate_images_b = env.Manipulate("$BUILD_DIR/image2_all_ota1.bin",
                                     [program_b])
upload = env.Alias("upload", manipulate_images_b, uploading)
AlwaysBuild(upload)

Default([manipulate_images_b])
Ejemplo n.º 20
0
Import("env", "projenv")

# Override unused "upload" to execute compiled binary
from SCons.Script import AlwaysBuild
AlwaysBuild(
    env.Alias("build", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}"))

# Add custom target to explorer
env.AddTarget(
    name="execute",
    dependencies="$BUILD_DIR/${PROGNAME}",
    actions="$BUILD_DIR/${PROGNAME}",
    #    actions = 'cmd.exe /C "start cmd.exe /C $BUILD_DIR\${PROGNAME}.exe"',
    title="Execute",
    description="Build and execute",
    group="General")

#print('=====================================')
#print(env.Dump())
Ejemplo n.º 21
0
def BuildProgram(env):
    def _append_pio_macros():
        env.AppendUnique(CPPDEFINES=[("PLATFORMIO",
                                      int("{0:02d}{1:02d}{2:02d}".format(
                                          *pioversion_to_intstr())))])

    _append_pio_macros()

    env.PrintConfiguration()

    # fix ASM handling under non case-sensitive OS
    if not Util.case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    if "__debug" in COMMAND_LINE_TARGETS:
        env.ProcessDebug()

    # process extra flags from board
    if "BOARD" in env and "build.extra_flags" in env.BoardConfig():
        env.ProcessFlags(env.BoardConfig().get("build.extra_flags"))
    # apply user flags
    env.ProcessFlags(env.get("BUILD_FLAGS"))

    # process framework scripts
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))

    # restore PIO macros if it was deleted by framework
    _append_pio_macros()

    # remove specified flags
    env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))

    # build dependent libs; place them before built-in libs
    env.Prepend(LIBS=env.BuildProjectLibraries())

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env
            and not any("-Wl,-T" in f for f in env['LINKFLAGS'])):
        env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"'])

    # enable "cyclic reference" for linker
    if env.get("LIBS") and env.GetCompilerType() == "gcc":
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))

    if "__test" in COMMAND_LINE_TARGETS:
        env.Append(PIOBUILDFILES=env.ProcessTest())
    else:
        env.Append(PIOBUILDFILES=env.CollectBuildFiles("$BUILDSRC_DIR",
                                                       "$PROJECTSRC_DIR",
                                                       src_filter=env.get(
                                                           "SRC_FILTER")))

    if not env['PIOBUILDFILES'] and not COMMAND_LINE_TARGETS:
        sys.stderr.write(
            "Error: Nothing to build. Please put your source code files "
            "to '%s' folder\n" % env.subst("$PROJECTSRC_DIR"))
        env.Exit(1)

    program = env.Program(join("$BUILD_DIR", env.subst("$PROGNAME")),
                          env['PIOBUILDFILES'])

    checksize_action = env.VerboseAction(env.CheckUploadSize,
                                         "Checking program size")
    AlwaysBuild(env.Alias("checkprogsize", program, checksize_action))
    if set(["upload", "program"]) & set(COMMAND_LINE_TARGETS):
        env.AddPostAction(program, checksize_action)

    return program
Ejemplo n.º 22
0
        "-U%s:w:%s:m" % (k, v)
        for k, v in env.BoardConfig().get("fuses", {}).items()
    ]))

#
# Target: Build executable and linkable firmware
#

target_elf = None
if "nobuild" in COMMAND_LINE_TARGETS:
    target_firm = join("$BUILD_DIR", "firmware.hex")
else:
    target_elf = env.BuildProgram()
    target_firm = env.ElfToHex(join("$BUILD_DIR", "firmware"), 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)

#
# Target: Upload by default .hex file
#
Ejemplo n.º 23
0
Archivo: main.py Proyecto: OS-Q/P426
                             ]), "Building $TARGET"),
                                          suffix=".hex")))

#
# 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}.bin")
else:
    target_elf = env.BuildProgram()
    target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf)

AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)

target_size = env.Alias(
    "size", target_elf,
    env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"))
AlwaysBuild(target_size)

#
# Target: Upload firmware
#

upload_source = target_firm
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
upload_actions = []
Ejemplo n.º 24
0
# Configure extra library source directories for LDF
if util.get_project_optional_dir("lib_extra_dirs"):
    env.Prepend(LIBSOURCE_DIRS=[
        l.strip()
        for l in util.get_project_optional_dir("lib_extra_dirs").split(", ")
        if l.strip()
    ])
env.Prepend(LIBSOURCE_DIRS=env.get("LIB_EXTRA_DIRS", []))

env.LoadPioPlatform(commonvars)

env.SConscriptChdir(0)
env.SConsignFile(join("$PROJECTPIOENVS_DIR", ".sconsign.dblite"))
env.SConscript("$BUILD_SCRIPT")

AlwaysBuild(env.Alias("__test", DEFAULT_TARGETS + ["size"]))

if "UPLOAD_FLAGS" in env:
    env.Append(UPLOADERFLAGS=["$UPLOAD_FLAGS"])

if env.get("EXTRA_SCRIPT"):
    env.SConscript(env.get("EXTRA_SCRIPT"), exports="env")

if "envdump" in COMMAND_LINE_TARGETS:
    print env.Dump()
    env.Exit(0)

if "idedata" in COMMAND_LINE_TARGETS:
    print "\n%s\n" % json.dumps(env.DumpIDEData())
    env.Exit(0)
Ejemplo n.º 25
0
        target_firm = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"),
                                   target_elf)
    elif "sam-ba" == upload_protocol:
        target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"),
                                   target_elf)
    else:
        if "DFUBOOTHEX" in env:
            target_firm = env.SignBin(
                join("$BUILD_DIR", "${PROGNAME}"),
                env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf))
        else:
            target_firm = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"),
                                       target_elf)
        env.Depends(target_firm, "checkprogsize")

AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)

if "DFUBOOTHEX" in env:
    env.Append(
        # Check the linker script for the correct location
        BOOT_SETTING_ADDR=board.get("build.bootloader.settings_addr",
                                    "0x7F000"))

    env.AddPlatformTarget(
        "dfu",
        env.PackageDfu(
            join("$BUILD_DIR", "${PROGNAME}"),
            env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf),
        ),
        target_firm,
Ejemplo n.º 26
0
    env.SConscript("frameworks/_bare.py", exports="env")

#
# Target: Build executable and linkable firmware
#

target_elf = None
if "nobuild" in COMMAND_LINE_TARGETS:
    target_elf = os.path.join("$BUILD_DIR", "${PROGNAME}.elf")
    target_bin = os.path.join("$BUILD_DIR", "${PROGNAME}.bin")
else:
    target_elf = env.BuildProgram()
    target_bin = env.ElfToBin(os.path.join("$BUILD_DIR", "${PROGNAME}"),
                              target_elf)

AlwaysBuild(env.Alias("nobuild", target_bin))
target_buildprog = env.Alias("buildprog", target_bin, target_bin)

env.AddPostAction(
    target_elf,
    env.VerboseAction(generate_disassembly, "Generating disassembly"))

#
# Target: Print binary size
#

target_size = env.AddPlatformTarget(
    "size",
    target_elf,
    env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"),
    "Program Size",
Ejemplo n.º 27
0
    PROGSUFFIX=".exe"
)

if get_systype() == "darwin_x86_64":
    env.Replace(
        _BINPREFIX="i586-mingw32-"
    )
elif get_systype() in ("linux_x86_64", "linux_i686"):
    env.Replace(
        _BINPREFIX="i686-w64-mingw32-"
    )

#
# Target: Build executable program
#

target_bin = env.BuildProgram()

#
# Target: Print binary size
#

target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Define targets
#

Default([target_bin])
Ejemplo n.º 28
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##########################################################################
# Autor: WizIO 2018 Georgi Angelov
#   http://www.wizio.eu/
#   https://github.com/Wiz-IO
#
##########################################################################
from os.path import join
from SCons.Script import (AlwaysBuild, Builder, COMMAND_LINE_TARGETS, Default,
                          DefaultEnvironment)
from colorama import Fore
env = DefaultEnvironment()
print(Fore.GREEN + '<<<<<<<<<<<< ' + env.BoardConfig().get("name").upper() +
      " 2019 Georgi Angelov >>>>>>>>>>>>")
#print( env.Dump )
####################################################
# Build executable and linkable program
####################################################
elf = env.BuildProgram()
AlwaysBuild(elf)
upload = env.Alias("upload", elf, [
    env.VerboseAction("$UPLOADCMD", '\033[93m' + "Runing $PROGNAME"),
])
AlwaysBuild(upload)
Default(elf)
Ejemplo n.º 29
0
def show_progress(env):
    import sys
    from SCons.Script import Progress, Command, AlwaysBuild

    screen = sys.stdout
    # Progress reporting is not available in non-TTY environments since it
    # messes with the output (for example, when writing to a file)
    show_progress = env["progress"] and sys.stdout.isatty()
    node_count = 0
    node_count_max = 0
    node_count_interval = 1
    node_count_fname = str(env.Dir("#")) + "/.scons_node_count"

    import time, math

    class cache_progress:
        # The default is 1 GB cache and 12 hours half life
        def __init__(self, path=None, limit=1073741824, half_life=43200):
            self.path = path
            self.limit = limit
            self.exponent_scale = math.log(2) / half_life
            if env["verbose"] and path != None:
                screen.write("Current cache limit is {} (used: {})\n".format(
                    self.convert_size(limit),
                    self.convert_size(self.get_size(path))))
            self.delete(self.file_list())

        def __call__(self, node, *args, **kw):
            nonlocal node_count, node_count_max, node_count_interval, node_count_fname, show_progress
            if show_progress:
                # Print the progress percentage
                node_count += node_count_interval
                if node_count_max > 0 and node_count <= node_count_max:
                    screen.write("\r[%3d%%] " %
                                 (node_count * 100 / node_count_max))
                    screen.flush()
                elif node_count_max > 0 and node_count > node_count_max:
                    screen.write("\r[100%] ")
                    screen.flush()
                else:
                    screen.write("\r[Initial build] ")
                    screen.flush()

        def delete(self, files):
            if len(files) == 0:
                return
            if env["verbose"]:
                # Utter something
                screen.write(
                    "\rPurging %d %s from cache...\n" %
                    (len(files), len(files) > 1 and "files" or "file"))
            [os.remove(f) for f in files]

        def file_list(self):
            if self.path is None:
                # Nothing to do
                return []
            # Gather a list of (filename, (size, atime)) within the
            # cache directory
            file_stat = [(x, os.stat(x)[6:8])
                         for x in glob.glob(os.path.join(self.path, "*", "*"))]
            if file_stat == []:
                # Nothing to do
                return []
            # Weight the cache files by size (assumed to be roughly
            # proportional to the recompilation time) times an exponential
            # decay since the ctime, and return a list with the entries
            # (filename, size, weight).
            current_time = time.time()
            file_stat = [(x[0], x[1][0], (current_time - x[1][1]))
                         for x in file_stat]
            # Sort by the most recently accessed files (most sensible to keep) first
            file_stat.sort(key=lambda x: x[2])
            # Search for the first entry where the storage limit is
            # reached
            sum, mark = 0, None
            for i, x in enumerate(file_stat):
                sum += x[1]
                if sum > self.limit:
                    mark = i
                    break
            if mark is None:
                return []
            else:
                return [x[0] for x in file_stat[mark:]]

        def convert_size(self, size_bytes):
            if size_bytes == 0:
                return "0 bytes"
            size_name = ("bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB",
                         "YB")
            i = int(math.floor(math.log(size_bytes, 1024)))
            p = math.pow(1024, i)
            s = round(size_bytes / p, 2)
            return "%s %s" % (int(s) if i == 0 else s, size_name[i])

        def get_size(self, start_path="."):
            total_size = 0
            for dirpath, dirnames, filenames in os.walk(start_path):
                for f in filenames:
                    fp = os.path.join(dirpath, f)
                    total_size += os.path.getsize(fp)
            return total_size

    def progress_finish(target, source, env):
        nonlocal node_count, progressor
        with open(node_count_fname, "w") as f:
            f.write("%d\n" % node_count)
        progressor.delete(progressor.file_list())

    try:
        with open(node_count_fname) as f:
            node_count_max = int(f.readline())
    except:
        pass

    cache_directory = os.environ.get("SCONS_CACHE")
    # Simple cache pruning, attached to SCons' progress callback. Trim the
    # cache directory to a size not larger than cache_limit.
    cache_limit = float(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024
    progressor = cache_progress(cache_directory, cache_limit)
    Progress(progressor, interval=node_count_interval)

    progress_finish_command = Command("progress_finish", [], progress_finish)
    AlwaysBuild(progress_finish_command)
Ejemplo n.º 30
0
    src_suffix='.asc')

env.Append(BUILDERS={
    'Synth': synth, 'PnR': pnr, 'Bin': bitstream, 'Time': time_rpt})

blif = env.Synth(TARGET, [src_synth])
asc = env.PnR(TARGET, [blif, PCF])
binf = env.Bin(TARGET, asc)

#
# Target: Time analysis (.rpt)
#
rpt = env.Time(asc)

target_time = env.Alias('time', rpt)
AlwaysBuild(target_time)

#
# Target: Upload bitstream
#
target_upload = env.Alias('upload', binf, '$UPLOADBINCMD')
AlwaysBuild(target_upload)

#
# Builders: Icarus Verilog
#
iverilog = Builder(
    action='iverilog {0} -o $TARGET -D VCD_OUTPUT={1} {2} $SOURCES'.format(
        IVER_PATH, TARGET_SIM, VLIB_FILES),
    suffix='.out',
    src_suffix='.v')