Skip to content

Commit 4e875f1

Browse files
committed
programmer/tinyprog: Use the same function to parse meta json content
Use the same _parse_json function to handle parsing of json content stored in flash. This allows for the _resolve_pointers function to read out json data in the same way as the _read_metadata function, such that 0x00 and 0xff bytes are ignored. This allows for the bootmeta to reference a section of flash instead of the exact content length.
1 parent 858d1a9 commit 4e875f1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

programmer/tinyprog/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __init__(self, prog):
158158

159159
def _parse_json(self, data):
160160
try:
161-
return json.loads(bytes(data).decode("utf-8"))
161+
return json.loads(bytes(data).replace(b"\x00", b"").replace(b"\xff", b"").decode("utf-8"))
162162
except BaseException:
163163
return None
164164

@@ -176,7 +176,7 @@ def _resolve_pointers(self, meta):
176176
if m:
177177
data = self.prog.read(
178178
int(m.group("addr"), 16), int(m.group("len")))
179-
return json.loads(bytes(data).decode("utf-8"))
179+
return self._parse_json(data)
180180
else:
181181
return meta
182182

@@ -187,14 +187,12 @@ def _read_metadata(self):
187187
meta_roots = (
188188
[
189189
self._parse_json(
190-
self.prog.read_security_register_page(p).replace(
191-
b"\x00", b"").replace(b"\xff", b""))
190+
self.prog.read_security_register_page(p))
192191
for p in [1, 2, 3]
193192
] + [
194193
self._parse_json(
195194
self.prog.read(
196-
int(math.pow(2, p) - (4 * 1024)), (4 * 1024)).replace(
197-
b"\x00", b"").replace(b"\xff", b""))
195+
int(math.pow(2, p) - (4 * 1024)), (4 * 1024)))
198196
for p in [17, 18, 19, 20, 21, 22, 23, 24]
199197
])
200198
meta_roots = [root for root in meta_roots if root is not None]

0 commit comments

Comments
 (0)