imd fixes
cover imd fixes
Antony Pavlov (4):
imd: fix imd_is_crc32()
imd: reuse imd_is_crc32()
include/image-metadata.h: fix whitespaces in the BAREBOX_IMD_CRC macro
bareboximd: make the '-c' option work again
common/imd.c | 2 +- include/image-metadata.h | 8 ++++---- scripts/bareboximd.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 7 lines
2.33.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/4 imd: fix imd_is_crc32()
--- include/image-metadata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/image-metadata.h +1 -1
@@ -67,7 +67,7 @@ struct imd_entry_crc32 {static inline int imd_is_crc32 (uint32_t type) { -return (type &IMD_TYPE_CRC32 ) ?1 :0 ; +return type ==IMD_TYPE_CRC32 ; }static inline int imd_crc32_is_valid (uint32_t flags)
Signature · 7 lines
2.33.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/4 imd: reuse imd_is_crc32()
In reply to Antony Pavlov--- common/imd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/imd.c +1 -1
@@ -317,7 +317,7 @@ static int imd_calculate_crc32(void *input, const struct imd_header *imd_start, length =ALIGN (length,4 ); length +=sizeof (struct imd_header ); -if (imd_read_type (imd) ==IMD_TYPE_CRC32 ) { +if (imd_is_crc32 (imd_read_type (imd))) { *imd_crc = (struct imd_header *)imd;debug ("Found crc token at %d\n" , end_ofs);break ;
Signature · 7 lines
2.33.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/4 include/image-metadata.h: fix whitespaces in the BAREBOX_IMD_CRC macro
In reply to Antony Pavlov--- include/image-metadata.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/image-metadata.h +3 -3
@@ -139,12 +139,12 @@ int imd_verify_crc32(void *buf, size_t size); }#define BAREBOX_IMD_CRC (_name, _crc, _keep_if_unused) \ - const struct imd_entry_crc32 __barebox_imd_##__name \ - __BAREBOX_IMD_SECTION(.barebox_imd_ ## _keep_if_unused ## _ ## _name) = { \ + const struct imd_entry_crc32 __barebox_imd_##__name \ + __BAREBOX_IMD_SECTION(.barebox_imd_ ## _keep_if_unused ## _ ## _name) = { \ .header.type = cpu_to_le32(IMD_TYPE_CRC32), \ .header.datalength = cpu_to_le32(sizeof(uint32_t) * 2), \ .data = _crc, \ - } + }#ifdef CONFIG_IMD void imd_used (const void *);
Signature · 7 lines
2.33.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/4 bareboximd: make the '-c' option work again
In reply to Antony Pavlovbareboximd with the '-c' option craches while
trying to alter an image file, e.g.:
barebox$ git describe
v2021.10.0-125-gd136ec5ac6
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- imx_v8_defconfig
...
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
...
images built:
barebox-nxp-imx8mm-evk.img
barebox-prt-prt8mm.img
barebox-nxp-imx8mn-evk.img
barebox-nxp-imx8mp-evk.img
barebox-nxp-imx8mq-evk.img
barebox-zii-imx8mq-dev.img
barebox-phytec-phycore-imx8mq.img
barebox$ ./scripts/bareboximd images/barebox-phytec-phycore-imx8mq.img
build: #1 Thu Oct 28 01:11:07 UTC 2021
buildsystem version:
crc32: 0x00000000
release: 2021.10.0-00125-gd136ec5ac6
barebox$ ./scripts/bareboximd -c images/barebox-phytec-phycore-imx8mq.img Segmentation fault (core dumped)
The problem is that the bareboximd uses mmap() on an image file in read-only mode.
--- scripts/bareboximd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/bareboximd.c +1 -1
@@ -97,7 +97,7 @@ static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t goto close; } - buf =mmap (NULL , max_size,PROT_READ ,MAP_SHARED , fd,0 ); + buf =mmap (NULL , max_size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );if (buf ==MAP_FAILED ) { buf =malloc (max_size);if (!buf) {
Signature · 7 lines
2.33.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/4] bareboximd: make the '-c' option work again
Hello Antony,
Quoted 38 lines · Antony Pavlov
bareboximd with the '-c' option craches while
trying to alter an image file, e.g.:barebox$ git describe
v2021.10.0-125-gd136ec5ac6
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-imx_v8_defconfig
...
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
...
images built:
barebox-nxp-imx8mm-evk.img
barebox-prt-prt8mm.img
barebox-nxp-imx8mn-evk.img
barebox-nxp-imx8mp-evk.img
barebox-nxp-imx8mq-evk.img
barebox-zii-imx8mq-dev.img
barebox-phytec-phycore-imx8mq.img
barebox$./scripts/bareboximdimages/barebox-phytec-phycore-imx8mq.img
build: #1 Thu Oct 28 01:11:07 UTC 2021
buildsystem version:
crc32:0x00000000
release: 2021.10.0-00125-gd136ec5ac6
barebox$./scripts/bareboximd-c images/barebox-phytec-phycore-imx8mq.img Segmentation fault (core dumped)The problem is that the bareboximd uses
mmap()on an image file in read-only mode.Signed-off-by Antony Pavlov <[email protected]>--- scripts/bareboximd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/bareboximd.c +0
-0
scripts/bareboximd.c static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t · line 100
Quoted 5 lines
scripts/bareboximd.c +1
-1@@ -97,7 +97,7 @@ static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t goto close; } - buf =mmap (NULL , max_size,PROT_READ ,MAP_SHARED , fd,0 ); + buf =mmap (NULL , max_size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );
I think this here only works incidentally, by failing and then doing a malloc. See mmap(2):
Errors: EACCES MAP_SHARED was requested and PROT_WRITE is set, but fd is not open
in read/write (O_RDWR) mode.
Correct would be MAP_PRIVATE. I sent a patch to that effect yesterday:
https://lore.barebox.org/barebox/[email protected]/T/#u
Quoted 4 lines
scripts/bareboximd.c +0
-0if (buf ==MAP_FAILED ) { buf =malloc (max_size);if (!buf) {
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/4] bareboximd: make the '-c' option work again
On Thu, 28 Oct 2021 08:45:19 +0200
Ahmad Fatoum <[email protected]> wrote:
Hi Ahmad!
Quoted 47 lines · Antony Pavlov
Quoted 38 lines
bareboximd with the '-c' option craches while
trying to alter an image file, e.g.:barebox$ git describe
v2021.10.0-125-gd136ec5ac6
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-imx_v8_defconfig
...
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
...
images built:
barebox-nxp-imx8mm-evk.img
barebox-prt-prt8mm.img
barebox-nxp-imx8mn-evk.img
barebox-nxp-imx8mp-evk.img
barebox-nxp-imx8mq-evk.img
barebox-zii-imx8mq-dev.img
barebox-phytec-phycore-imx8mq.img
barebox$./scripts/bareboximdimages/barebox-phytec-phycore-imx8mq.img
build: #1 Thu Oct 28 01:11:07 UTC 2021
buildsystem version:
crc32:0x00000000
release: 2021.10.0-00125-gd136ec5ac6
barebox$./scripts/bareboximd-c images/barebox-phytec-phycore-imx8mq.img Segmentation fault (core dumped)The problem is that the bareboximd uses
mmap()on an image file in read-only mode.Signed-off-by Antony Pavlov <[email protected]>--- scripts/bareboximd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/bareboximd.c +0
-0scripts/bareboximd.c static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t · line 100
Quoted 5 lines
scripts/bareboximd.c +1
-1@@ -97,7 +97,7 @@ static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t goto close; } - buf =mmap (NULL , max_size,PROT_READ ,MAP_SHARED , fd,0 ); + buf =mmap (NULL , max_size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );I think this here only works incidentally, by failing and then doing a malloc. See mmap(2):
Quoted 5 lines
Errors: EACCES
MAP_SHAREDwas requested andPROT_WRITEis set, but fd is not open
in read/write (O_RDWR) mode.Correct would be
MAP_PRIVATE. I sent a patch to that effect yesterday:
https://lore.barebox.org/barebox/[email protected]/T/#u
Aghh! I have not seen your patch :(
Quoted 12 lines
Quoted 5 lines
scripts/bareboximd.c +0
-0if (buf ==MAP_FAILED ) { buf =malloc (max_size);if (!buf) {Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Signature · 7 lines
Best regards, Antony Pavlov _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 5 lines · Antony Pavlov
Antony Pavlov (4):
imd: fiximd_is_crc32()
imd: reuseimd_is_crc32()
include/image-metadata.h: fix whitespaces in theBAREBOX_IMD_CRCmacro
bareboximd: make the '-c' option work again
Applied 1-3, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox