#1063097 /usr/bin/mkimage: opens image and device trees (-d, -b) O_RDONLY, then O_RDWR, and fails if they're read-only (it doesn't write to them) #1063097
- Package:
- u-boot-tools
- Source:
- u-boot-tools
- Description:
- companion tools for Das U-Boot bootloader
- Submitter:
- наб
- Date:
- 2024-03-20 13:15:02 UTC
- Severity:
- normal
- Tags:
Dear Maintainer,
From a strace:
1390 openat(AT_FDCWD, "/tmp/tmp.j2DX6x1MgV/Image-6.6.11.lz4", O_RDONLY) = 3
1390 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=12611929, ...}, AT_EMPTY_PATH) = 0
1390 close(3) = 0
1390 openat(AT_FDCWD, "mt8173-elm-hana-6.6.11.dtb", O_RDONLY) = 3
1390 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=43853, ...}, AT_EMPTY_PATH) = 0
1390 close(3) = 0
1390 mmap(NULL, 12660736, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xffffafecd000
1390 openat(AT_FDCWD, "/tmp/tmp.j2DX6x1MgV/Image-6.6.11.lz4", O_RDWR) = 3
1390 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=12611929, ...}, AT_EMPTY_PATH) = 0
1390 read(3, "\4\"M\30dp\271\361K!\0\225\37 \3\325'\360X\24\0\1\0 \243\1\6\0/\n\0\1"..., 12611929) = 12611929
1390 close(3) = 0
1390 openat(AT_FDCWD, "mt8173-elm-hana-6.6.11.dtb", O_RDWR) = -1 EACCES (Permission denied)
1390 write(2, "mkimage: Can't open mt8173-elm-h"..., 66) = 66
1390 write(2, "mkimage: Failed to build FIT ima"..., 35) = 35
1390 munmap(0xffffafecd000, 12660736) = 0
here, the dtb is unwritable.
An analogous error happens if the Image is unwritable,
but as we can see here, it doesn't write to it anyway.
(Nor should it, given this is an input file.)
Please turn this into an O_RDONLY.
Best,
наб
It would be helpful to list the exact command you are running, although best to take this upstream. live well, vagrant
Control: tags -1 + upstream
whoops!
mkimage -f auto -A arm64 \
-T kernel -C lz4 -d Image-6.6.15.lz4 \
-b mt8173-elm-hana-6.6.15.dtb outf
Yeah, can repro on mkimage from upstream checkout:
$ strace -oss tools/mkimage -f auto -A arm64 -T kernel -C lz4 -d Image-6.6.15.lz4 -b mt8173-elm-hana-6.6.15.dtb /dev/null
tools/mkimage: Can't open Image-6.6.15.lz4: Permission denied
tools/mkimage: Failed to build FIT image
tools/mkimage: failed to build FIT
Error: Bad parameters for FIT image type
$ grep Image ss
execve("tools/mkimage", ["tools/mkimage", "-f", "auto", "-A", "arm64", "-T", "kernel", "-C", "lz4", "-d", "Image-6.6.15.lz4", "-b", "mt8173-elm-hana-6.6.15.dtb", "/dev/null"], 0x7ffdbed66100 /* 30 vars */) = 0
openat(AT_FDCWD, "Image-6.6.15.lz4", O_RDONLY) = 3
openat(AT_FDCWD, "Image-6.6.15.lz4", O_RDWR) = -1 EACCES (Permission denied)
write(2, "tools/mkimage: Can't open Image-"..., 62) = 62
$ gdb --args tools/mkimage -f auto -A arm64 -T kernel -C lz4 -d Image-6.6.15.lz4 -b mt8173-elm-hana-6.6.15.dtb /dev/null
#0 __libc_open64 (file=0x7fffffffe587 "Image-6.6.15.lz4", oflag=2) at ../sysdeps/unix/sysv/linux/open64.c:30
#1 0x000055555555f0f7 in fdt_property_file ()
#2 0x000055555555def9 in fit_handle_file ()
#3 0x000055555557d1da in main ()
so I'll post a patch there probably.
Best,