mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] startup: allow ctrl+c abort during boot sequence
@ 2019-08-22  6:54 Ahmad Fatoum
  2019-08-22  6:54 ` [PATCH 2/4] libfile: have write_full return a descriptive error code Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2019-08-22  6:54 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

At the moment e.g. a wait for an ARP response during net boot can only
aborted if the auto boot countdown was aborted. Otherwise ctrl+c is
without effect. For better user experience allow code querying for ctrl+c
to see it even if barebox had not dropped into a shell.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/startup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index 92bf94f849f1..d2f1b4846752 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -310,11 +310,11 @@ static int run_init(void)
 
 	autoboot = do_autoboot_countdown();
 
+	console_ctrlc_allow();
+
 	if (autoboot == AUTOBOOT_BOOT)
 		run_command("boot");
 
-	console_ctrlc_allow();
-
 	if (autoboot == AUTOBOOT_MENU)
 		run_command(MENUFILE);
 
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] libfile: have write_full return a descriptive error code
  2019-08-22  6:54 [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Ahmad Fatoum
@ 2019-08-22  6:54 ` Ahmad Fatoum
  2019-08-22  6:54 ` [PATCH 3/4] ARM: i.MX: bbu: early exit when partition too small Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2019-08-22  6:54 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

So far (p|)write_full has been returning -1 on error.
Some callers of write_full like imx_bbu_write_device print out the
function's return value on error, effectively rendering every printed
error message to be due to EPERM.

On the other hand, some callers like do_memcpy, use it correctly and
use errno. Sidestep the issue by having the function return -errno on
errors as well.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/libfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index b42753c2b5ea..f6c588d7373f 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -38,7 +38,7 @@ int pwrite_full(int fd, const void *buf, size_t size, loff_t offset)
 		now = pwrite(fd, buf, size, offset);
 		if (now == 0) {
 			errno = ENOSPC;
-			return -1;
+			return -errno;
 		}
 		if (now < 0)
 			return now;
@@ -66,7 +66,7 @@ int write_full(int fd, const void *buf, size_t size)
 		now = write(fd, buf, size);
 		if (now == 0) {
 			errno = ENOSPC;
-			return -1;
+			return -errno;
 		}
 		if (now < 0)
 			return now;
@@ -194,6 +194,7 @@ again:
 	buf = calloc(read_size + 1, 1);
 	if (!buf) {
 		ret = -ENOMEM;
+		errno = ENOMEM;
 		goto err_out;
 	}
 
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] ARM: i.MX: bbu: early exit when partition too small
  2019-08-22  6:54 [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Ahmad Fatoum
  2019-08-22  6:54 ` [PATCH 2/4] libfile: have write_full return a descriptive error code Ahmad Fatoum
@ 2019-08-22  6:54 ` Ahmad Fatoum
  2019-08-22  6:54 ` [PATCH 4/4] fs: omap4_usbbootfs: remove commented out code Ahmad Fatoum
  2019-08-23  7:55 ` [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2019-08-22  6:54 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

So far, writing a barebox image exceeding the partition size aborts with
EPERM as truncate isn't implemented:

  ERROR: writing to /dev/flash-boot.barebox failed with Operation
  not permitted
  update failed
  ERROR: fastboot: update barebox: Operation not permitted

This is unfortunate because by the time the truncation fails, erasing
the partition had already occurred. Avoid this by checking prior to the
pwrite_all whether the file to be written is big enough. This is valid
here because barebox update wouldn't be called on a regular file.

While at it, present callers with a more helpful ENOSPC error.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-internal.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index a563b3bc2906..946a3e9a779b 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -87,6 +87,7 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 		const void *buf, int image_len)
 {
 	int fd, ret, offset = 0;
+	struct stat st;
 
 	fd = open(devicefile, O_RDWR | O_CREAT);
 	if (fd < 0)
@@ -101,6 +102,15 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler,
 	if (imx_handler->handler.flags & IMX_BBU_FLAG_KEEP_HEAD)
 		offset += imx_handler->flash_header_offset;
 
+	ret = fstat(fd, &st);
+	if (ret)
+		goto err_close;
+
+	if (image_len > st.st_size) {
+		ret = -ENOSPC;
+		goto err_close;
+	}
+
 	ret = imx_bbu_protect(fd, imx_handler, devicefile, offset,
 			      image_len, 0);
 	if (ret)
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] fs: omap4_usbbootfs: remove commented out code
  2019-08-22  6:54 [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Ahmad Fatoum
  2019-08-22  6:54 ` [PATCH 2/4] libfile: have write_full return a descriptive error code Ahmad Fatoum
  2019-08-22  6:54 ` [PATCH 3/4] ARM: i.MX: bbu: early exit when partition too small Ahmad Fatoum
@ 2019-08-22  6:54 ` Ahmad Fatoum
  2019-08-23  7:55 ` [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2019-08-22  6:54 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The code has been sitting commented out in version control for close
to 7 years now, drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/omap4_usbbootfs.c | 41 -----------------------------------------
 1 file changed, 41 deletions(-)

diff --git a/fs/omap4_usbbootfs.c b/fs/omap4_usbbootfs.c
index 169cde7ddb0f..4f159210d1e5 100644
--- a/fs/omap4_usbbootfs.c
+++ b/fs/omap4_usbbootfs.c
@@ -29,39 +29,6 @@ struct file_priv {
 	s32 id;
 	u32 size;
 };
-/*
-static int omap4_usbbootfs_create(
-	struct device_d *dev, const char *pathname, mode_t mode)
-{
-	return -ENOSYS;
-}
-
-static int omap4_usbbootfs_unlink(struct device_d *dev, const char *pathname)
-{
-	return -ENOSYS;
-}
-
-static int omap4_usbbootfs_mkdir(struct device_d *dev, const char *pathname)
-{
-	return -ENOSYS;
-}
-
-static int omap4_usbbootfs_rmdir(struct device_d *dev, const char *pathname)
-{
-	return -ENOSYS;
-}
-
-static int omap4_usbbootfs_write(
-	struct device_d *_dev, FILE *f, const void *inbuf, size_t size)
-{
-	return -ENOSYS;
-}
-
-static int omap4_usbbootfs_truncate(struct device_d *dev, FILE *f, loff_t size)
-{
-	return -ENOSYS;
-}
-*/
 
 static struct file_priv *omap4_usbbootfs_do_open(
 	struct device_d *dev, int accmode, const char *filename)
@@ -187,14 +154,6 @@ static struct fs_driver_d omap4_usbbootfs_driver = {
 	.read    = omap4_usbbootfs_read,
 	.opendir = omap4_usbbootfs_opendir,
 	.stat    = omap4_usbbootfs_stat,
-/*
-	.create	= omap4_usbbootfs_create,
-	.unlink	= omap4_usbbootfs_unlink,
-	.mkdir	= omap4_usbbootfs_mkdir,
-	.rmdir	= omap4_usbbootfs_rmdir,
-	.write	= omap4_usbbootfs_write,
-	.truncate= omap4_usbbootfs_truncate,
-*/
 	.flags	 = 0,
 	.drv = {
 		.probe	= omap4_usbbootfs_probe,
-- 
2.20.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] startup: allow ctrl+c abort during boot sequence
  2019-08-22  6:54 [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2019-08-22  6:54 ` [PATCH 4/4] fs: omap4_usbbootfs: remove commented out code Ahmad Fatoum
@ 2019-08-23  7:55 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2019-08-23  7:55 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Aug 22, 2019 at 08:54:05AM +0200, Ahmad Fatoum wrote:
> At the moment e.g. a wait for an ARP response during net boot can only
> aborted if the auto boot countdown was aborted. Otherwise ctrl+c is
> without effect. For better user experience allow code querying for ctrl+c
> to see it even if barebox had not dropped into a shell.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  common/startup.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-23  7:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22  6:54 [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Ahmad Fatoum
2019-08-22  6:54 ` [PATCH 2/4] libfile: have write_full return a descriptive error code Ahmad Fatoum
2019-08-22  6:54 ` [PATCH 3/4] ARM: i.MX: bbu: early exit when partition too small Ahmad Fatoum
2019-08-22  6:54 ` [PATCH 4/4] fs: omap4_usbbootfs: remove commented out code Ahmad Fatoum
2019-08-23  7:55 ` [PATCH 1/4] startup: allow ctrl+c abort during boot sequence Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox