util/mediatek: Add check-pi-img.py
According to MediaTek's proprietary PI_IMG parser, two cookies (one header and one footer) are expected. Therefore, add a script to perform validity check of the PI_IMG firmware, so that format errors could be caught in build time. Change-Id: I27011492c7fab747aa3ee12d514d20a6a52d0a4d Signed-off-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/87226 Reviewed-by: Yidi Lin <yidilin@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
402419c3b3
commit
f762708822
4 changed files with 38 additions and 0 deletions
|
|
@ -88,6 +88,7 @@ image for testing purposes and for working on firmware. `Bash`
|
|||
* __[me_cleaner](https://github.com/corna/me_cleaner)__ - Tool for
|
||||
partial deblobbing of Intel ME/TXE firmware images `Python`
|
||||
* __mediatek__
|
||||
* check-pi-img.py - Check `PI_IMG` firmware. `Python3`
|
||||
* gen-bl-img.py - Generate MediaTek bootloader header.
|
||||
`Python3`
|
||||
* __mma__ - Memory Margin Analysis automation tests `Bash`
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ image for testing purposes and for working on firmware. `Bash`
|
|||
* __[me_cleaner](https://github.com/corna/me_cleaner)__ - Tool for
|
||||
partial deblobbing of Intel ME/TXE firmware images `Python`
|
||||
* __mediatek__
|
||||
* check-pi-img.py - Check `PI_IMG` firmware. `Python3`
|
||||
* gen-bl-img.py - Generate MediaTek bootloader header.
|
||||
`Python3`
|
||||
* __mma__ - Memory Margin Analysis automation tests `Bash`
|
||||
|
|
|
|||
35
util/mediatek/check-pi-img.py
Executable file
35
util/mediatek/check-pi-img.py
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
import argparse
|
||||
|
||||
|
||||
HEADER_OFFSET = 0x200
|
||||
COOKIE = 0x17C3A6B4
|
||||
|
||||
|
||||
def check_pi_img(pi_img):
|
||||
cookie_count = 0
|
||||
with open(pi_img, "rb") as f:
|
||||
f.seek(HEADER_OFFSET)
|
||||
while True:
|
||||
data = f.read(4)
|
||||
if not data:
|
||||
break
|
||||
value = int.from_bytes(data, byteorder="little", signed=False)
|
||||
if value == COOKIE:
|
||||
cookie_count += 1
|
||||
if cookie_count != 2:
|
||||
raise ValueError("Invalid PI_IMG {} (expected 2 cookies; found {})"
|
||||
.format(pi_img, cookie_count))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("pi_img")
|
||||
args = parser.parse_args()
|
||||
check_pi_img(args.pi_img)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
__mediatek__
|
||||
* check-pi-img.py - Check `PI_IMG` firmware. `Python3`
|
||||
* gen-bl-img.py - Generate MediaTek bootloader header. `Python3`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue