Debian Codegraph @

util/mediatek/check-pi-img.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 #
3 # SPDX-License-Identifier: GPL-2.0-only
4
5 import argparse
6
7
8 HEADER_OFFSET = 0x200
9 COOKIE = 0x17C3A6B4
10
11
12 def check_pi_img(pi_img):
13 cookie_count = 0
14 with open(pi_img, "rb") as f:
15 f.seek(HEADER_OFFSET)
16 while True:
17 data = f.read(4)
18 if not data:
19 break
20 value = int.from_bytes(data, byteorder="little", signed=False)
21 if value == COOKIE:
22 cookie_count += 1
23 if cookie_count != 2:
24 raise ValueError("Invalid PI_IMG {} (expected 2 cookies; found {})"
25 .format(pi_img, cookie_count))
26
27
28 def main():
29 parser = argparse.ArgumentParser()
30 parser.add_argument("pi_img")
31 args = parser.parse_args()
32 check_pi_img(args.pi_img)
33
34 if __name__ == '__main__':
35 main()