11 char part_version[21];
24 PART_VERSION_SIZE
= 21
31 def str_to_bytes_pad(string
, size
):
32 str_bytes
= string
.encode()
33 num_bytes
= len(str_bytes
)
35 str_bytes
= str_bytes
[: size
- 1] + "\0".encode()
37 str_bytes
+= "\0".encode() * (size
- num_bytes
)
41 def create_tag(args
, in_bytes
, size
):
42 # JAM CRC32 is bitwise not and unsigned
43 crc
= ~binascii
.crc32(in_bytes
) & 0xFFFFFFFF
46 tag
+= struct
.pack(">I", args
.part_id
)
47 tag
+= struct
.pack(">I", size
)
48 tag
+= struct
.pack(">H", args
.part_flags
)
49 tag
+= str_to_bytes_pad(args
.part_name
, PART_NAME_SIZE
)
50 tag
+= str_to_bytes_pad(args
.part_version
, PART_VERSION_SIZE
)
51 tag
+= struct
.pack(">I", crc
)
56 def create_output(args
):
57 in_st
= os
.stat(args
.input_file
)
58 in_size
= in_st
.st_size
60 in_f
= open(args
.input_file
, "r+b")
61 in_bytes
= in_f
.read(in_size
)
64 tag
= create_tag(args
, in_bytes
, in_size
)
66 out_f
= open(args
.output_file
, "w+b")
74 parser
= argparse
.ArgumentParser(description
="")
81 help="Partition Flags",
113 help="Partition Name",
121 help="Partition Version",
124 args
= parser
.parse_args()
127 (not args
.part_flags
)
128 or (not args
.part_id
)
129 or (not args
.input_file
)
130 or (not args
.output_file
)
131 or (not args
.part_name
)
132 or (not args
.part_version
)