Improve checking for the program size before uploading // Issue #689

This commit is contained in:
Ivan Kravets
2016-06-11 15:39:06 +03:00
parent a4345cedc5
commit 5398dbef95
12 changed files with 36 additions and 61 deletions

View File

@ -10,8 +10,8 @@ PlatformIO 2.0
* Added support for `emonPi <https://github.com/openenergymonitor/emonpi>`__,
the OpenEnergyMonitor system
(`issue #687 <https://github.com/platformio/platformio/issues/687>`_)
* Added support for STM32F0 boards for `SPL <http://platformio.org/frameworks/spl>`__
framework
* Added support for `SPL <http://platformio.org/frameworks/spl>`__
framework for STM32F0 boards
(`issue #683 <https://github.com/platformio/platformio/issues/683>`_)
* Added support for `Arduboy DevKit <https://www.arduboy.com>`__, the game system
the size of a credit card

View File

@ -14,7 +14,7 @@
import sys
VERSION = (2, 9, "5.dev2")
VERSION = (2, 9, "5.dev3")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -142,25 +142,23 @@ AlwaysBuild(target_size)
#
upload = env.Alias(["upload", "uploadlazy"], target_firm,
[env.CheckUploadSize, BeforeUpload, "$UPLOADHEXCMD"])
[BeforeUpload, "$UPLOADHEXCMD"])
AlwaysBuild(upload)
#
# Target: Upload EEPROM data (from EEMEM directive)
#
uploadeep = env.Alias(
"uploadeep",
env.ElfToEep(join("$BUILD_DIR", "firmware"), target_elf),
[BeforeUpload, "$UPLOADEEPCMD"])
uploadeep = env.Alias("uploadeep",
env.ElfToEep(join("$BUILD_DIR", "firmware"), target_elf),
[BeforeUpload, "$UPLOADEEPCMD"])
AlwaysBuild(uploadeep)
#
# Target: Upload firmware using external programmer
#
program = env.Alias("program", target_firm,
[env.CheckUploadSize, BeforeUpload, "$PROGRAMHEXCMD"])
program = env.Alias("program", target_firm, [BeforeUpload, "$PROGRAMHEXCMD"])
AlwaysBuild(program)
#

View File

@ -25,8 +25,6 @@ from platformio.util import get_serialports
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
env.AutodetectUploadPort()
board_type = env.subst("$BOARD")
if "zero" not in board_type:
env.Append(
@ -177,8 +175,9 @@ if env.subst("$BOARD") == "zero":
upload = env.Alias(["upload", "uploadlazy"], target_firm,
[env.CheckUploadSize, "$UPLOADCMD"])
else:
upload = env.Alias(["upload", "uploadlazy"], target_firm,
[env.CheckUploadSize, BeforeUpload, "$UPLOADCMD"])
upload = env.Alias(
["upload", "uploadlazy"], target_firm,
[env.AutodetectUploadPort, BeforeUpload, "$UPLOADCMD"])
AlwaysBuild(upload)

View File

@ -346,7 +346,7 @@ AlwaysBuild(target_size)
target_upload = env.Alias(
["upload", "uploadlazy", "uploadfs"], target_firm,
[lambda target, source, env: env.AutodetectUploadPort(), "$UPLOADCMD"])
[env.AutodetectUploadPort, "$UPLOADCMD"])
env.AlwaysBuild(target_upload)

View File

@ -21,20 +21,6 @@ from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
if "program" in COMMAND_LINE_TARGETS:
return
env.AutodetectUploadPort()
env.Prepend(UPLOADERFLAGS=['"$UPLOAD_PORT"'])
if env.get("BOARD_OPTIONS", {}).get("upload", {}).get(
"use_1200bps_touch", False):
env.TouchSerialPort("$UPLOAD_PORT", 1200)
env = DefaultEnvironment()
env.Replace(
@ -112,6 +98,9 @@ env.Replace(
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES',
UPLOADER=join("$PIOPACKAGES_DIR", "tool-arduino101load", "arduino101load"),
UPLOADERFLAGS=[
'"$UPLOAD_PORT"'
],
DFUUTIL=join("$PIOPACKAGES_DIR", "tool-arduino101load", "dfu-util"),
UPLOADCMD='"$UPLOADER" "$DFUUTIL" $SOURCES $UPLOADERFLAGS verbose',
@ -189,8 +178,8 @@ AlwaysBuild(target_size)
# Target: Upload firmware
#
upload = env.Alias(
["upload", "uploadlazy"], target_firm, [BeforeUpload, "$UPLOADCMD"])
upload = env.Alias(["upload", "uploadlazy"], target_firm,
[env.AutodetectUploadPort, "$UPLOADCMD"])
AlwaysBuild(upload)
#

View File

@ -21,12 +21,6 @@ from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
env.AutodetectUploadPort()
env.Prepend(UPLOADERFLAGS=["-d", '"$UPLOAD_PORT"'])
env = DefaultEnvironment()
env.Replace(
@ -86,7 +80,8 @@ env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "tool-pic32prog", "pic32prog"),
UPLOADERFLAGS=[
"-b", "$UPLOAD_SPEED"
"-b", "$UPLOAD_SPEED",
"-d", '"$UPLOAD_PORT"'
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES',
@ -179,8 +174,8 @@ AlwaysBuild(target_size)
# Target: Upload firmware
#
upload = env.Alias(
["upload", "uploadlazy"], target_firm, [BeforeUpload, "$UPLOADCMD"])
upload = env.Alias(["upload", "uploadlazy"], target_firm,
[env.AutodetectUploadPort, "$UPLOADCMD"])
AlwaysBuild(upload)
#

View File

@ -63,9 +63,8 @@ AlwaysBuild(target_size)
#
if env.subst("$BOARD") == "rfduino":
upload = env.Alias(
["upload", "uploadlazy"], target_firm,
[lambda target, source, env: env.AutodetectUploadPort(), "$UPLOADCMD"])
upload = env.Alias(["upload", "uploadlazy"], target_firm,
[env.AutodetectUploadPort, "$UPLOADCMD"])
else:
upload = env.Alias(["upload", "uploadlazy"], target_firm, env.UploadToDisk)
AlwaysBuild(upload)

View File

@ -17,19 +17,10 @@
"""
from os.path import join
from shutil import copyfile
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
def UploadToDisk(target, source, env): # pylint: disable=W0613,W0621
env.AutodetectUploadPort()
copyfile(join(env.subst("$BUILD_DIR"), "firmware.bin"),
join(env.subst("$UPLOAD_PORT"), "firmware.bin"))
print("Firmware has been successfully uploaded.\n"
"Please restart your board.")
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
@ -60,7 +51,7 @@ AlwaysBuild(target_size)
# Target: Upload by default .bin file
#
upload = env.Alias(["upload", "uploadlazy"], target_firm, UploadToDisk)
upload = env.Alias(["upload", "uploadlazy"], target_firm, env.UploadToDisk)
AlwaysBuild(upload)
#

View File

@ -100,8 +100,7 @@ AlwaysBuild(target_size)
#
if "mbed" in env.subst("$FRAMEWORK") and not env.subst("$UPLOAD_PROTOCOL"):
upload = env.Alias(["upload", "uploadlazy"],
target_firm, env.UploadToDisk)
upload = env.Alias(["upload", "uploadlazy"], target_firm, env.UploadToDisk)
else:
upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD")
AlwaysBuild(upload)

View File

@ -81,7 +81,7 @@ def WaitForNewSerialPort(env, before):
def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
env = args[0]
print("Looking for upload port/disk...")
print "Looking for upload port/disk..."
def _look_for_mbed_disk():
msdlabels = ("mbed", "nucleo", "frdm")
@ -107,7 +107,7 @@ def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
return port
if "UPLOAD_PORT" in env:
print(env.subst("Manually specified: $UPLOAD_PORT"))
print env.subst("Manually specified: $UPLOAD_PORT")
return
if env.subst("$FRAMEWORK") == "mbed":
@ -124,8 +124,7 @@ def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
env.Replace(UPLOAD_PORT=_look_for_serial_port())
if env.subst("$UPLOAD_PORT"):
print(env.subst("Auto-detected: $UPLOAD_PORT"))
print("")
print env.subst("Auto-detected: $UPLOAD_PORT")
else:
env.Exit("Error: Please specify `upload_port` for environment or use "
"global `--upload-port` option.\n"
@ -152,19 +151,20 @@ def CheckUploadSize(_, target, source, env): # pylint: disable=W0613,W0621
if max_size == 0 or "SIZETOOL" not in env:
return
print "Check program size..."
sysenv = environ.copy()
sysenv['PATH'] = str(env['ENV']['PATH'])
cmd = [env.subst("$SIZETOOL"), "-B", str(source[0])]
result = util.exec_command(cmd, env=sysenv)
if result['returncode'] != 0:
return
print result['out'].strip()
line = result['out'].strip().splitlines()[1]
values = [v.strip() for v in line.split("\t")]
used_size = int(values[0]) + int(values[1])
if used_size > max_size:
print result['out']
env.Exit("Error: The program size (%d bytes) is greater "
"than maximum allowed (%s bytes)" % (used_size, max_size))

View File

@ -94,11 +94,16 @@ def BuildProgram(env):
"Error: Nothing to build. Please put your source code files "
"to '%s' folder" % env.subst("$PROJECTSRC_DIR"))
return env.Program(
program = env.Program(
join("$BUILD_DIR", env.subst("$PROGNAME")),
sources
)
if set(["upload", "uploadlazy", "program"]) & set(COMMAND_LINE_TARGETS):
env.AddPostAction(program, env.CheckUploadSize)
return program
def ProcessFlags(env, flags):
for f in flags: