blob: c9c9a992d72aafe9e328957e205ad0b125ee8e3c [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#!/usr/bin/env python
2
3import sys
4import os
5
6
7if len(sys.argv) != 2:
8 print('Usage : align_4kb [file_name]')
9 sys.exit()
10
11if not os.path.isfile(sys.argv[1]):
12 print(sys.argv[1] + ' not exist')
13 sys.exit()
14
15if os.path.getsize(sys.argv[1]) % 4096 == 0:
16 print('file size is 4KB alignment')
17 sys.exit()
18
19file_src = sys.argv[1]
20file_dst = os.path.splitext(
21 file_src)[0] + "_original" + os.path.splitext(file_src)[1]
22
23if os.path.exists(file_dst):
24 os.remove(file_dst)
25
26os.rename(file_src, file_dst)
27
28file_src = file_dst
29file_dst = sys.argv[1]
30
31with open(file_dst, 'ab') as fdst:
32 with open(file_src, 'rb') as fsrc:
33 data = fsrc.read()
34 len_diff = 4096 - len(data) % 4096
35 fdst.write(data)
36 if len_diff:
37 fdst.write(b'\xff' * len_diff)