Skip to content

Commit b59ef96

Browse files
committed
bricks/ev3/make_bootable_image: fail on u-boot.bin too big
Do not truncate u-boot.bin to 256KiB. This could cause crashes or other undefined behavior. Instead, just fail with an error message.
1 parent b81978a commit b59ef96

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

bricks/ev3/make_bootable_image.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
import argparse
5+
import sys
56

67
# Expected layout of the firmware image:
78
#
@@ -21,14 +22,18 @@
2122
FIRMWARE_ROUND_SIZE = 256 * 1024
2223

2324

24-
def make_firmware(uboot_blob, uimage_blob):
25+
def make_firmware(uboot_blob: bytes, uimage_blob: bytes) -> bytes:
2526

2627
if len(uboot_blob) > UBOOT_MAX_SIZE:
27-
print("u-boot file is bigger than expected. Using only the first 256KiB.")
28-
uboot_blob = uboot_blob[:UBOOT_MAX_SIZE]
28+
print(
29+
f"u-boot file is bigger than 256KiB ({len(uboot_blob)} bytes), it is not safe to use.",
30+
file=sys.stderr,
31+
)
32+
exit(1)
2933

3034
if len(uimage_blob) > UIMAGE_MAX_SIZE:
31-
raise ValueError("uImage file is too big.")
35+
print(f"uImage file is too big ({len(uimage_blob)} > {UIMAGE_MAX_SIZE}).", file=sys.stderr)
36+
exit(1)
3237

3338
# Gets combined size, rounded to nearest expected size.
3439
combined_size = UIMAGE_OFFSET + len(uimage_blob)

0 commit comments

Comments
 (0)