1502494cba
BUG=chromium:1023662 TEST=1. Create a tiny file `in.txt` as input 2. Run `fixed_cksum.py in.txt out.txt 20` with py2 and py3 version, the output is the same 3. Run `variable_cksum.py in.txt out.txt` with py2 and py3 version, the output is the same Signed-off-by: Yilin Yang <kerker@google.com> Change-Id: I9428269dfb826a3a95fffef9ea3f7c1a7107ef84 Reviewed-on: https://review.coreboot.org/c/coreboot/+/45460 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
36 lines
829 B
Python
Executable file
36 lines
829 B
Python
Executable file
#!/usr/bin/env python3
|
|
#
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
"""
|
|
This utility computes and fills Exynos ROM checksum (for BL1 or BL2).
|
|
(Algorithm from U-Boot: tools/mkexynosspl.c)
|
|
|
|
Input: IN OUT
|
|
|
|
Output:
|
|
|
|
Checksum header added to IN and written to OUT.
|
|
Header: uint32_t size, checksum, reserved[2].
|
|
"""
|
|
|
|
import struct
|
|
import sys
|
|
|
|
def main(argv):
|
|
if len(argv) != 3:
|
|
exit('usage: %s IN OUT' % argv[0])
|
|
|
|
in_name, out_name = argv[1:3]
|
|
header_format = "<IIII"
|
|
with open(in_name, "rb") as in_file, open(out_name, "wb") as out_file:
|
|
data = in_file.read()
|
|
header = struct.pack(header_format,
|
|
struct.calcsize(header_format) + len(data),
|
|
sum(data),
|
|
0, 0)
|
|
out_file.write(header + data)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv)
|