mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
add a utility to generate the csr image for writing into FLASH
This commit is contained in:
parent
c0f11d4808
commit
9be9d80c17
1 changed files with 36 additions and 0 deletions
36
csr2bin.py
Executable file
36
csr2bin.py
Executable file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description="Convert csr.csv to binary image file")
|
||||||
|
parser.add_argument(
|
||||||
|
"-i", "--input-file", required=True, help="file containing CSV input", type=str
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-o", "--output-file", required=True, help="destination file for binary data", type=str
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
pad_to = 0x7FC0
|
||||||
|
with open(args.input_file, "rb") as ifile:
|
||||||
|
with open(args.output_file, "wb") as ofile:
|
||||||
|
data = ifile.read() # read in the whole block of CSV data
|
||||||
|
|
||||||
|
odata = bytearray()
|
||||||
|
odata += len(data).to_bytes(4, 'little')
|
||||||
|
odata += data
|
||||||
|
padding = bytes([0xff]) * (pad_to - len(data) - 4)
|
||||||
|
odata += padding
|
||||||
|
|
||||||
|
hasher = hashlib.sha512()
|
||||||
|
hasher.update(odata)
|
||||||
|
digest = hasher.digest()
|
||||||
|
odata += digest
|
||||||
|
|
||||||
|
ofile.write(odata)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue