mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] bareboximd: make the '-c' option work again
Date: Thu, 28 Oct 2021 04:28:16 +0300	[thread overview]
Message-ID: <20211028012816.929611-5-antonynpavlov@gmail.com> (raw)
In-Reply-To: <20211028012816.929611-1-antonynpavlov@gmail.com>

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/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.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 scripts/bareboximd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
index c3dcb4dcf0..fe0d274380 100644
--- a/scripts/bareboximd.c
+++ b/scripts/bareboximd.c
@@ -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) {
-- 
2.33.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-10-28  1:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28  1:28 [PATCH 0/4] imd fixes Antony Pavlov
2021-10-28  1:28 ` [PATCH 1/4] imd: fix imd_is_crc32() Antony Pavlov
2021-10-28  1:28 ` [PATCH 2/4] imd: reuse imd_is_crc32() Antony Pavlov
2021-10-28  1:28 ` [PATCH 3/4] include/image-metadata.h: fix whitespaces in the BAREBOX_IMD_CRC macro Antony Pavlov
2021-10-28  1:28 ` Antony Pavlov [this message]
2021-10-28  6:45   ` [PATCH 4/4] bareboximd: make the '-c' option work again Ahmad Fatoum
2021-10-28  7:00     ` Antony Pavlov
2021-11-01  9:05 ` [PATCH 0/4] imd fixes Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211028012816.929611-5-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox