Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed header structure and added script
Signed-off-by: Yonatan Schachter <yonatan.schachter@gmail.com>
- Loading branch information
Showing
5 changed files
with
156 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import argparse | ||
import struct | ||
|
||
BIN_DESCRIPTOR_MAGIC = 0x2c31b9b9 | ||
BIN_DESCRIPTOR_ALIGNMENT = 4 | ||
|
||
TYPE_STR = 0 | ||
TYPE_UINT = 1 | ||
|
||
BIN_DESCRIPTOR_IDS = { | ||
0x1000: ("APP_VERSION_STRING", TYPE_STR), | ||
0x1001: ("APP_VERSION_MAJOR", TYPE_UINT), | ||
0x1002: ("APP_VERSION_MINOR", TYPE_UINT), | ||
0x1003: ("APP_VERSION_REVISION", TYPE_UINT), | ||
0x1004: ("KERNEL_VERSION_STRING", TYPE_STR), | ||
0x1005: ("KERNEL_VERSION_MAJOR", TYPE_UINT), | ||
0x1006: ("KERNEL_VERSION_MINOR", TYPE_UINT), | ||
0x1007: ("KERNEL_VERSION_PATCHLEVEL", TYPE_UINT), | ||
0x1008: ("KERNEL_VERSION_NUMBER", TYPE_UINT), | ||
0x1009: ("BUILD_DATE_TIME_STRING", TYPE_STR), | ||
0x100a: ("BUILD_DATE_STRING", TYPE_STR), | ||
0x100b: ("BUILD_TIME_STRING", TYPE_STR), | ||
} | ||
|
||
BIN_DESC_TYPE_DESCRIPTORS_END = 0xffffffff | ||
|
||
def bytes_to_uint(b): | ||
return struct.unpack("I", b)[0] | ||
|
||
def align(x, alignment): | ||
return (x + alignment - 1) & (~(alignment - 1)) | ||
|
||
def read_descriptors(filename): | ||
with open(filename, "rb") as f: | ||
binary_data = f.read() | ||
|
||
index = binary_data.find(struct.pack("I", BIN_DESCRIPTOR_MAGIC)) | ||
if index == -1: | ||
print("Could not find binary descriptor magic") | ||
|
||
descriptors = [] | ||
|
||
index += 4 # index points to first descriptor | ||
current_id = bytes_to_uint(binary_data[index:index+4]) | ||
while current_id != BIN_DESC_TYPE_DESCRIPTORS_END: | ||
index += 4 # index points to length | ||
length = bytes_to_uint(binary_data[index:index+4]) | ||
index += 4 # index points to data | ||
data = binary_data[index:index+length] | ||
|
||
if BIN_DESCRIPTOR_IDS[current_id][1] == TYPE_STR: | ||
parsed_data = data[:-1].decode("ascii") | ||
else: | ||
parsed_data = bytes_to_uint(data) | ||
descriptors.append((BIN_DESCRIPTOR_IDS[current_id][0], parsed_data)) | ||
index += length | ||
index = align(index, 4) | ||
current_id = bytes_to_uint(binary_data[index:index+4]) | ||
|
||
return descriptors | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('filename', | ||
help='Binary image' | ||
) | ||
args = parser.parse_args() | ||
descriptors = read_descriptors(args.filename) | ||
print(descriptors) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#include <zephyr/bin_descriptors.h> | ||
|
||
LONG(BIN_DESCRIPTOR_MAGIC); | ||
LONG((_bin_desc_end - _bin_desc_start) / 8); | ||
_bin_desc_start = .; | ||
Z_LINK_ITERABLE(bin_descriptor_entry); | ||
_bin_desc_end = .; | ||
Z_LINK_ITERABLE(bin_descriptor); | ||
. = ALIGN(BIN_DESCRIPTOR_ALIGNMENT); | ||
LONG(BIN_DESC_TYPE_DESCRIPTORS_END) |