11 char part_version[21];
24 PART_VERSION_SIZE
= 21
30 def str_to_bytes_pad(string
, size
):
31 str_bytes
= string
.encode()
32 num_bytes
= len(str_bytes
)
33 if (num_bytes
>= size
):
34 str_bytes
= str_bytes
[:size
- 1] + '\0'.encode()
36 str_bytes
+= '\0'.encode() * (size
- num_bytes
)
39 def create_tag(args
, in_bytes
, size
):
40 # JAM CRC32 is bitwise not and unsigned
41 crc
= (~binascii
.crc32(in_bytes
) & 0xFFFFFFFF)
44 tag
+= struct
.pack('>I', args
.part_id
)
45 tag
+= struct
.pack('>I', size
)
46 tag
+= struct
.pack('>H', args
.part_flags
)
47 tag
+= str_to_bytes_pad(args
.part_name
, PART_NAME_SIZE
)
48 tag
+= str_to_bytes_pad(args
.part_version
, PART_VERSION_SIZE
)
49 tag
+= struct
.pack('>I', crc
)
53 def create_output(args
):
54 in_st
= os
.stat(args
.input_file
)
55 in_size
= in_st
.st_size
57 in_f
= open(args
.input_file
, 'r+b')
58 in_bytes
= in_f
.read(in_size
)
61 tag
= create_tag(args
, in_bytes
, in_size
)
63 out_f
= open(args
.output_file
, 'w+b')
70 parser
= argparse
.ArgumentParser(description
='')
72 parser
.add_argument('--flags',
76 help='Partition Flags')
78 parser
.add_argument('--id',
84 parser
.add_argument('--input-file',
90 parser
.add_argument('--output-file',
96 parser
.add_argument('--name',
100 help='Partition Name')
102 parser
.add_argument('--version',
106 help='Partition Version')
108 args
= parser
.parse_args()
110 if ((not args
.part_flags
) or
111 (not args
.part_id
) or
112 (not args
.input_file
) or
113 (not args
.output_file
) or
114 (not args
.part_name
) or
115 (not args
.part_version
)):