Nico Huber | ca41a6a | 2016-01-23 21:29:47 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Gabe Black | b6b1077 | 2013-12-08 12:48:45 -0800 | [diff] [blame] | 2 | # |
Patrick Georgi | 7051707 | 2020-05-10 18:47:05 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: BSD-3-Clause |
Gabe Black | b6b1077 | 2013-12-08 12:48:45 -0800 | [diff] [blame] | 4 | |
| 5 | """ |
| 6 | This utility computes and fills Exynos ROM checksum (for BL1 or BL2). |
| 7 | (Algorithm from U-Boot: tools/mkexynosspl.c) |
| 8 | |
| 9 | Input: IN OUT |
| 10 | |
| 11 | Output: |
| 12 | |
| 13 | Checksum header added to IN and written to OUT. |
| 14 | Header: uint32_t size, checksum, reserved[2]. |
| 15 | """ |
| 16 | |
| 17 | import struct |
| 18 | import sys |
| 19 | |
| 20 | def main(argv): |
| 21 | if len(argv) != 3: |
| 22 | exit('usage: %s IN OUT' % argv[0]) |
| 23 | |
| 24 | in_name, out_name = argv[1:3] |
| 25 | header_format = "<IIII" |
| 26 | with open(in_name, "rb") as in_file, open(out_name, "wb") as out_file: |
| 27 | data = in_file.read() |
| 28 | header = struct.pack(header_format, |
| 29 | struct.calcsize(header_format) + len(data), |
| 30 | sum(map(ord, data)), |
| 31 | 0, 0) |
| 32 | out_file.write(header + data) |
| 33 | |
| 34 | |
| 35 | if __name__ == '__main__': |
| 36 | main(sys.argv) |