From 2269f47eb485cdcc8cbc697957b34e3991894ff6 Mon Sep 17 00:00:00 2001 From: Fabio Utzig Date: Thu, 17 Oct 2019 11:14:33 -0300 Subject: [PATCH] imgtool: Add complete trailer to HEX images When generating HEX output, instead of just adding the `magic`, also add the whole trailer (with erased value). This allows for HEX writing tools to erase the trailer region, avoiding possible issues when garbage exists there. Signed-off-by: Fabio Utzig --- scripts/imgtool/image.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/imgtool/image.py b/scripts/imgtool/image.py index e6ae581a..8eec4ced 100644 --- a/scripts/imgtool/image.py +++ b/scripts/imgtool/image.py @@ -179,9 +179,13 @@ class Image(): self.base_addr = hex_addr h.frombytes(bytes=self.payload, offset=self.base_addr) if self.pad: - magic_addr = (self.base_addr + self.slot_size) - \ - len(boot_magic) - h.puts(magic_addr, boot_magic) + trailer_size = self._trailer_size(self.align, self.max_sectors, + self.overwrite_only, + self.enckey) + trailer_addr = (self.base_addr + self.slot_size) - trailer_size + padding = bytes([self.erased_val] * + (trailer_size - len(boot_magic))) + boot_magic + h.puts(trailer_addr, padding) h.tofile(path, 'hex') else: if self.pad: