Skip to content

Commit

Permalink
tools/partition_table: change hacky script default
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Silva <[email protected]>
  • Loading branch information
perigoso committed Jun 9, 2022
1 parent 175a4f7 commit a872328
Showing 1 changed file with 54 additions and 52 deletions.
106 changes: 54 additions & 52 deletions tools/partition_table.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env python3

import argparse
import os
# import argparse
import struct
import sys


BIN = 'partition_table.bin'
# /* version */
PARTITION_TABLE_VERSION = 0x00

# /* magic words */
PARTITION_TABLE_MW = 0x07AB1E00
PARTITION_TABLE_MW = 0x07AB1E00
PARTITION_TABLE_ENTRY_MW = 0x55

# /* partition location */
Expand All @@ -19,67 +18,70 @@

# /* partition type */
# /* partition type: 0 = firmware, 1 = binary blob, 2 = nvs */
PARTITION_TYPE_FW = 0
PARTITION_TYPE_FW = 0
PARTITION_TYPE_BLOB = 1
PARTITION_TYPE_NVS = 2
PARTITION_TYPE_NVS = 2


def table_header(numEntries: int = 1) -> bytes:
# struct partition_table_t {
# u32 magic_word;
# u8 reserved0;
# u8 reserved1;
# u8 reserved2;
# u8 num_entries;
# struct partition_table_entry_t *entries;
# } __attribute__((__packed__));

data = struct.pack('<I', PARTITION_TABLE_MW + PARTITION_TABLE_VERSION)
data += struct.pack('<B', 0x55)
data += struct.pack('<B', 0xAA)
data += struct.pack('<B', 0x55)
data += struct.pack('<B', numEntries)

return data
# struct partition_table_t {
# u32 magic_word;
# u8 reserved0;
# u8 reserved1;
# u8 reserved2;
# u8 num_entries;
# struct partition_table_entry_t *entries;
# } __attribute__((__packed__));

data = struct.pack('<I', PARTITION_TABLE_MW + PARTITION_TABLE_VERSION)
data += struct.pack('<B', 0x55)
data += struct.pack('<B', 0xAA)
data += struct.pack('<B', 0x55)
data += struct.pack('<B', numEntries)

return data


def add_entry(
location: int = PARTITION_LOC_INTERNAL,
ptype: int = PARTITION_TYPE_BLOB,
id: int = 0,
start_addr: int = 0,
end_addr: int = 0,
name: str = '') -> bytes:
location: int = PARTITION_LOC_INTERNAL,
ptype: int = PARTITION_TYPE_BLOB,
id: int = 0,
start_addr: int = 0,
end_addr: int = 0,
name: str = '') -> bytes:

# struct partition_table_entry_t {
# u8 magic_word;
# u8 location;
# u8 type;
# u8 id;
# u32 start_addr;
# u32 end_addr;
# u8 name[16];
# } __attribute__((__packed__));
# struct partition_table_entry_t {
# u8 magic_word;
# u8 location;
# u8 type;
# u8 id;
# u32 start_addr;
# u32 end_addr;
# u8 name[16];
# } __attribute__((__packed__));

data = struct.pack('<B', PARTITION_TABLE_ENTRY_MW)
data += struct.pack('<B', location)
data += struct.pack('<B', ptype)
data += struct.pack('<B', id)
data += struct.pack('<I', start_addr)
data += struct.pack('<I', end_addr)
data = struct.pack('<B', PARTITION_TABLE_ENTRY_MW)
data += struct.pack('<B', location)
data += struct.pack('<B', ptype)
data += struct.pack('<B', id)
data += struct.pack('<I', start_addr)
data += struct.pack('<I', end_addr)

if(len(name) > 16):
exit(1)
if(len(name) > 16):
exit(1)

for b in bytes(name, 'utf-8'):
data += struct.pack('<B', b)
for b in bytes(name, 'utf-8'):
data += struct.pack('<B', b)

data += bytes(16 - (len(name) % 16))
data += bytes(16 - (len(name) % 16))

return data
return data


if __name__ == '__main__':

bin = open(BIN, 'wb')
bin = open(BIN, 'wb')

bin.write(table_header())
bin.write(add_entry(name='blob', start_addr=0x0047EF00, end_addr=0x0047FF00))
bin.write(table_header(numEntries=2)) # @ 0x0047FE00
bin.write(add_entry(name='nv_data', ptype=PARTITION_TYPE_NVS, start_addr=0x00460000, end_addr=0x0047C000))
bin.write(add_entry(name='sensor_blob', ptype=PARTITION_TYPE_BLOB, start_addr=0x0047C000, end_addr=0x47E000))

0 comments on commit a872328

Please sign in to comment.