From 6c2e86d876c9d23006b28c869387f660cefdfc83 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 3 Nov 2022 21:03:40 +0800 Subject: [PATCH] add support for small-sized PDDB images plus some debugging info --- tools/cycle.ps1 | 31 +++++++++++++++++++++++++++++++ tools/pddbcommon.py | 4 ++-- tools/pddbdbg.py | 13 +++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tools/cycle.ps1 diff --git a/tools/cycle.ps1 b/tools/cycle.ps1 new file mode 100644 index 000000000..1798528f1 --- /dev/null +++ b/tools/cycle.ps1 @@ -0,0 +1,31 @@ +target\debug\create-image.exe ` + target\riscv32imac-unknown-xous-elf\release\xous_presign.img ` + --kernel target/riscv32imac-unknown-xous-elf/release/xous-kernel ` + --init target/riscv32imac-unknown-xous-elf/release/xous-ticktimer ` + --init target/riscv32imac-unknown-xous-elf/release/xous-log ` + --init fake-root-keys\target\riscv32imac-unknown-xous-elf\debug\fake-root-keys ` + --init pddb-raw\target\riscv32imac-unknown-xous-elf\debug\pddb-raw ` + --init target/riscv32imac-unknown-xous-elf/release/xous-names ` + --init target/riscv32imac-unknown-xous-elf/release/xous-susres ` + --init target\riscv32imac-unknown-xous-elf\release\pddb ` + --init target\riscv32imac-unknown-xous-elf\release\trng ` + --init target\riscv32imac-unknown-xous-elf\release\llio ` + --init target\riscv32imac-unknown-xous-elf\release\spinor ` + --svd utralib/renode/renode.svd + +target\debug\copy-object.exe ` + target/riscv32imac-unknown-xous-elf/release/loader ` + target/riscv32imac-unknown-xous-elf/release\loader_presign.bin + +target\debug\sign-image.exe ` + --loader-image target/riscv32imac-unknown-xous-elf/release\loader_presign.bin ` + --loader-key devkey/dev.key ` + --loader-output target/riscv32imac-unknown-xous-elf/release\loader.bin ` + --min-xous-ver v0.9.8-791 + +target\debug\sign-image.exe ` + --kernel-image target/riscv32imac-unknown-xous-elf/release\xous_presign.img ` + --kernel-key devkey/dev.key ` + --kernel-output target/riscv32imac-unknown-xous-elf/release\xous.img ` + --min-xous-ver v0.9.8-791 + \ No newline at end of file diff --git a/tools/pddbcommon.py b/tools/pddbcommon.py index 502b35c46..d28fe519e 100644 --- a/tools/pddbcommon.py +++ b/tools/pddbcommon.py @@ -305,8 +305,8 @@ def __init__(self, index, v2p, disk, key, name, dna=DNA): except ValueError: logging.error("\n") # make some whitespace so this stands out in the logs logging.error("**** basisdicts: encountered an invalid dict root record. Data loss may have occurred!") - logging.error("**** couldn't decrypt vpage @ {:x} ppage @ {:x} in basis {}, dna {}".format(dict_header_vaddr, v2p[dict_header_vaddr], name, dna)) - logging.error("****** partial dump: {}\n".format(disk[pp:pp + 64].hex())) + logging.error("**** couldn't decrypt vpage @ {:x} ppage @ {:x} in basis {}, aad {}".format(dict_header_vaddr, v2p[dict_header_vaddr], name, basis_aad(name, dna=dna).hex())) + logging.error("****** partial dump: {}...{} len {}\n".format(disk[pp:pp + 48].hex(), disk[pp + 4048:pp + 4096].hex(), len(disk[pp:pp + 4096]))) self.valid = False if self.num_keys > 0: diff --git a/tools/pddbdbg.py b/tools/pddbdbg.py index 70314c516..4daebe20a 100755 --- a/tools/pddbdbg.py +++ b/tools/pddbdbg.py @@ -19,6 +19,9 @@ def main(): parser.add_argument( "--renode", required=False, help="Override flex-size settings and read a Renode bin file", action="store_true" ) + parser.add_argument( + "--smalldb", required=False, help="Override default size of PDDB and set it to 4MiB (for images built to that size only)", action="store_true" + ) parser.add_argument( "--basis", type=str, help="Extra Bases to unlock, as `name:pass`. Each additional basis requires another --basis separator. Note that : is not legal to use in a Basis name.", action="append", nargs="+" ) @@ -57,7 +60,10 @@ def main(): keyrom = key_f.read() with open(imagefile, 'rb') as img_f: raw_img = img_f.read() - raw_img = raw_img[0x01D80000:0x07F80000] + if args.smalldb: + raw_img = raw_img[0x01D80000:0x1D8_0000 + 1024 * 1024 * 4] + else: + raw_img = raw_img[0x01D80000:0x07F80000] keys = extract_keys(keyrom, raw_img, args.pin, basis_credentials) else: if args.name == None: @@ -102,7 +108,10 @@ def main(): with open(imagefile, 'rb') as img_f: raw_img = img_f.read() if args.renode: - raw_img = raw_img[0x01D80000:0x07F80000] + if args.smalldb: + raw_img = raw_img[0x01D80000:0x1D8_0000 + 1024 * 1024 * 4] + else: + raw_img = raw_img[0x01D80000:0x07F80000] pddb_len = len(raw_img) pddb_size_pages = pddb_len // PAGE_SIZE logging.info("Disk size: 0x{:x}".format(pddb_len))