summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Bech <joakim.bech@linaro.org>2016-09-06 23:04:55 +0200
committerJoakim Bech <joakim.bech@linaro.org>2016-09-06 23:04:55 +0200
commit2a37def821f6ec08a9f856a20c2cfc8b65a3ccc0 (patch)
treedba798ef670afecf6b72611d956acd6a38e9f09b
parenteab19a88a78c0d52e336cb4ce275448d7606234c (diff)
Ability to pad images til a certain sizestm
In some cases it's convenient to pad the image, to avoid extra steps to be able to write to flash. For example. The default settings on STM Nucleo F401RE doesn't allow to write a part of a sector, which is something we would like to do when adding the boot image trailer at the correct location. The --pad parameter will add pad your image til the size (N) you give as parameter. Currently it also always add the boot image trailer if you use this command. So you will end up with this: 0 N-8 N | data | pad | boot_image_trailer | Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
-rw-r--r--newtimg.py1
-rwxr-xr-xzep2newt.py30
2 files changed, 31 insertions, 0 deletions
diff --git a/newtimg.py b/newtimg.py
index 1c5c7a9..4f87e4d 100644
--- a/newtimg.py
+++ b/newtimg.py
@@ -1,3 +1,4 @@
+BOOT_IMG_MAGIC = 0x12344321
IMAGE_MAGIC = 0x96f3b83c
IMAGE_MAGIC_NONE = 0xffffffff
diff --git a/zep2newt.py b/zep2newt.py
index 3ae3601..772a0c2 100755
--- a/zep2newt.py
+++ b/zep2newt.py
@@ -40,6 +40,9 @@ def get_args():
default=str(hex(OFFSET_VECTOR_TABLE)), \
help='Offset to vector table in HEX')
+ parser.add_argument('--pad', required=False, \
+ help='Pad file with 0xff up to this size (in hex)')
+
parser.add_argument('--bit', required=False, \
help='Flash boot image trailer magic')
@@ -288,6 +291,28 @@ def create_jlink_clear_bit_script(bit_file, bitoffset="0x7bff8"):
except IOError:
print("[ERROR]: Cannot create to %s" % (jlink_file))
sys.exit(1)
+################################################################################
+def pad_binary(binary_file, pad_size, boot_magic=False):
+ try:
+ # Get the correct size for the image
+ size = pad_size - os.path.getsize(binary_file)
+ if boot_magic:
+ size -= 8
+
+ if size <= 0:
+ print("Nothing to pad\n")
+ return
+
+ with open(binary_file, "ab") as f:
+ f.write(('\xff') * size)
+ if boot_magic:
+ f.write(struct.pack('I', BOOT_IMG_MAGIC) )
+ f.write(('\xff') * 4)
+ f.close()
+
+ except (OSError, IOError):
+ print("[ERROR]: Cannot open/append to %s" % (binary_file))
+ sys.exit(1)
################################################################################
def main(argv):
@@ -300,6 +325,11 @@ def main(argv):
global DEBUG
DEBUG = True
+ if (args.pad):
+ pad_size = int(args.pad, 16)
+ pad_binary(args.binary_file, pad_size, True)
+ sys.exit(1)
+
# Since it's a hex string, let's convert to an integer instead
vtable_offs = int(args.vtable_offs, 16)