mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC, PATCH] barebox-update command support
@ 2012-09-14  7:45 Sascha Hauer
  2012-09-14  7:45 ` [PATCH 1/3] Add barebox update infrastructure Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Sascha Hauer @ 2012-09-14  7:45 UTC (permalink / raw)
  To: barebox

Hi All,

The following adds barebox-update command support. This command is
supposed to provide a dedicated command for updating barebox.

The rationale behind this is:

- We can add additional generic, SoC specific, board specific sanity
  checks (Is this really a barebox image? Does the image fit into the
  device?)
- Sometimes SoC or board specific fixups are necessary. For example,
  with Omap Nand boot we have to switch the Nand driver into a different
  ECC mode before flashing barebox. With i.MX MMC card boot we want
  to preserve the partition table. On i.MX28 Nand boot we have to create
  a Boot Control Block. The list does not end here...

The current idea is:

A board can register one or multiple update handlers. The update handlers
themselves are registered by a board because only the board knows where
it actually can boot from. Nevertheless there might be generic handlers
available, the most simple one being: Check image header, check size, write
to device.

This is in an early state, right now there are only dummy handlers, hence the
RFC state.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      Add barebox update infrastructure
      ARM: Add dummy update handler
      ARM pcm038: register nor update handler

 arch/arm/boards/pcm038/pcm038.c |    7 +++
 arch/arm/lib/Makefile           |    1 +
 arch/arm/lib/bbu.c              |   56 ++++++++++++++++++++
 commands/Kconfig                |    5 ++
 commands/Makefile               |    1 +
 commands/barebox-update.c       |   80 ++++++++++++++++++++++++++++
 common/Kconfig                  |    3 ++
 common/Makefile                 |    1 +
 common/bbu.c                    |  110 +++++++++++++++++++++++++++++++++++++++
 include/bbu.h                   |   40 ++++++++++++++
 10 files changed, 304 insertions(+)
 create mode 100644 arch/arm/lib/bbu.c
 create mode 100644 commands/barebox-update.c
 create mode 100644 common/bbu.c
 create mode 100644 include/bbu.h

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

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

* [PATCH 1/3] Add barebox update infrastructure
  2012-09-14  7:45 [RFC, PATCH] barebox-update command support Sascha Hauer
@ 2012-09-14  7:45 ` Sascha Hauer
  2012-09-14 12:15   ` Jan Weitzel
  2012-09-14  7:45 ` [PATCH 2/3] ARM: Add dummy update handler Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2012-09-14  7:45 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/Kconfig          |    5 +++
 commands/Makefile         |    1 +
 commands/barebox-update.c |   80 +++++++++++++++++++++++++++++++++
 common/Kconfig            |    3 ++
 common/Makefile           |    1 +
 common/bbu.c              |  110 +++++++++++++++++++++++++++++++++++++++++++++
 include/bbu.h             |   37 +++++++++++++++
 7 files changed, 237 insertions(+)
 create mode 100644 commands/barebox-update.c
 create mode 100644 common/bbu.c
 create mode 100644 include/bbu.h

diff --git a/commands/Kconfig b/commands/Kconfig
index f2756cc..0ed0d69 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -470,6 +470,11 @@ config CMD_OFTREE
 	prompt "oftree"
 	select FDT
 
+config CMD_BAREBOX_UPDATE
+	tristate
+	select BAREBOX_UPDATE
+	prompt "barebox-update"
+
 endmenu
 
 config CMD_TIMEOUT
diff --git a/commands/Makefile b/commands/Makefile
index ccebd7f..62762de 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -74,3 +74,4 @@ obj-$(CONFIG_CMD_BASENAME)	+= basename.o
 obj-$(CONFIG_CMD_DIRNAME)	+= dirname.o
 obj-$(CONFIG_CMD_READLINK)	+= readlink.o
 obj-$(CONFIG_CMD_LN)		+= ln.o
+obj-$(CONFIG_CMD_BAREBOX_UPDATE)+= barebox-update.o
diff --git a/commands/barebox-update.c b/commands/barebox-update.c
new file mode 100644
index 0000000..db8ae7d
--- /dev/null
+++ b/commands/barebox-update.c
@@ -0,0 +1,80 @@
+/*
+ * barebox-update.c - update barebox
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <malloc.h>
+#include <errno.h>
+#include <bbu.h>
+#include <fs.h>
+
+static int do_barebox_update(int argc, char *argv[])
+{
+	int opt, ret;
+	struct bbu_data data = {};
+
+	while ((opt = getopt(argc, argv, "t:yf:l")) > 0) {
+		switch (opt) {
+		case 'f':
+			data.force = simple_strtoul(optarg, NULL, 0);
+			data.flags |= BBU_FLAG_FORCE;
+			break;
+		case 't':
+			data.handler_name = optarg;
+			break;
+		case 'y':
+			data.flags |= BBU_FLAG_YES;
+			break;
+		case 'l':
+			printf("registered handlers:\n");
+			bbu_handlers_list();
+			return 0;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (!(argc - optind))
+		return COMMAND_ERROR_USAGE;
+
+	data.imagefile = argv[optind];
+
+	data.image = read_file(data.imagefile, &data.len);
+	if (!data.image)
+		return -errno;
+
+	ret = barebox_update(&data);
+
+	free(data.image);
+
+	return ret;
+}
+
+BAREBOX_CMD_HELP_START(barebox_update)
+BAREBOX_CMD_HELP_USAGE("barebox_update [OPTIONS <image>]\n")
+BAREBOX_CMD_HELP_OPT("-t <target>", "\n")
+BAREBOX_CMD_HELP_OPT("-y\t", "yes. Do not ask for confirmation\n")
+BAREBOX_CMD_HELP_OPT("-f <level>", "Set force level\n")
+BAREBOX_CMD_HELP_OPT("-l\t", "list registered targets\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(barebox_update)
+	.cmd		= do_barebox_update,
+	.usage		= "update barebox",
+	BAREBOX_CMD_HELP(cmd_barebox_update_help)
+BAREBOX_CMD_END
diff --git a/common/Kconfig b/common/Kconfig
index b97392c..a6f6c0f 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -58,6 +58,9 @@ config GLOBALVAR
 config STDDEV
 	bool
 
+config BAREBOX_UPDATE
+	bool
+
 menu "General Settings              "
 
 config LOCALVERSION
diff --git a/common/Makefile b/common/Makefile
index df9f301..07c422a 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_MENU) += menu.o
 obj-$(CONFIG_PASSWORD) += password.o
 obj-$(CONFIG_MODULES) += module.o
 obj-$(CONFIG_FLEXIBLE_BOOTARGS) += bootargs.o
+obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
 extra-$(CONFIG_MODULES) += module.lds
 
 ifdef CONFIG_DEFAULT_ENVIRONMENT
diff --git a/common/bbu.c b/common/bbu.c
new file mode 100644
index 0000000..928c34b
--- /dev/null
+++ b/common/bbu.c
@@ -0,0 +1,110 @@
+/*
+ * bbu.c - barebox update functions
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <common.h>
+#include <bbu.h>
+#include <linux/list.h>
+#include <errno.h>
+#include <readkey.h>
+
+static LIST_HEAD(bbu_image_handlers);
+
+int bbu_force(struct bbu_data *data, const char *fmt, ...)
+{
+	va_list args;
+
+	printf("UPDATE: ");
+
+	va_start(args, fmt);
+
+	vprintf(fmt, args);
+
+	va_end(args);
+
+	if (!(data->flags & BBU_FLAG_FORCE))
+		goto out;
+
+	if (!data->force)
+		goto out;
+
+	data->force--;
+
+	printf(" (forced)\n");
+
+	return 1;
+out:
+	printf("\n");
+
+	return 0;
+}
+
+int bbu_confirm(struct bbu_data *data)
+{
+	int key;
+
+	if (data->flags & BBU_FLAG_YES)
+		return 1;
+
+	printf("update barebox from %s to %s (y/n)?\n",
+			data->imagefile, data->handler_name);
+
+	key = read_key();
+	if (key == 'y')
+		return 1;
+	return 0;
+}
+
+int barebox_update(struct bbu_data *data)
+{
+	struct bbu_handler *handler;
+	int ret;
+
+	list_for_each_entry(handler, &bbu_image_handlers, list) {
+		if (!data->handler_name) {
+			if (handler->flags & BBU_HANDLER_FLAG_DEFAULT) {
+				data->handler_name = handler->name;
+				goto found;
+			}
+			continue;
+		}
+		if (!strcmp(handler->name, data->handler_name))
+			goto found;
+	}
+
+	return -ENODEV;
+
+found:
+
+	ret = handler->handler(handler, data);
+	return ret;
+}
+
+void bbu_handlers_list(void)
+{
+	struct bbu_handler *handler;
+
+	list_for_each_entry(handler, &bbu_image_handlers, list)
+		printf("%s%s\n", handler->name,
+				handler->flags & BBU_HANDLER_FLAG_DEFAULT ?
+				" (default)" : "");
+}
+
+int bbu_register_handler(struct bbu_handler *handler)
+{
+	list_add_tail(&handler->list, &bbu_image_handlers);
+	return 0;
+}
diff --git a/include/bbu.h b/include/bbu.h
new file mode 100644
index 0000000..ce1a608
--- /dev/null
+++ b/include/bbu.h
@@ -0,0 +1,37 @@
+#ifndef __INCLUDE_BBU_H
+#define __INCLUDE_BBU_H
+
+struct bbu_data {
+#define BBU_FLAG_FORCE	(1 << 0)
+#define BBU_FLAG_YES	(1 << 1)
+	unsigned long flags;
+	int force;
+	void *image;
+	const char *imagefile;
+	size_t len;
+	const char *handler_name;
+};
+
+struct bbu_handler {
+	int (*handler)(struct bbu_handler *, struct bbu_data *);
+	void *handler_data;
+	const char *name;
+	struct list_head list;
+#define BBU_HANDLER_FLAG_DEFAULT	(1 << 0)
+	unsigned long flags;
+};
+
+int bbu_force(struct bbu_data *, const char *fmt, ...)
+	__attribute__ ((format(__printf__, 2, 3)));
+
+int bbu_confirm(struct bbu_data *);
+
+int bbu_register_handler(struct bbu_handler *);
+
+int barebox_update(struct bbu_data *);
+
+int barebox_arm_update(struct bbu_handler *, struct bbu_data *data);
+
+void bbu_handlers_list(void);
+
+#endif /* __INCLUDE_BBU_H */
-- 
1.7.10.4


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

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

* [PATCH 2/3] ARM: Add dummy update handler
  2012-09-14  7:45 [RFC, PATCH] barebox-update command support Sascha Hauer
  2012-09-14  7:45 ` [PATCH 1/3] Add barebox update infrastructure Sascha Hauer
@ 2012-09-14  7:45 ` Sascha Hauer
  2012-09-14 12:17   ` Jan Weitzel
  2012-09-14  7:45 ` [PATCH 3/3] ARM pcm038: register nor " Sascha Hauer
  2012-09-14 12:36 ` [RFC, PATCH] barebox-update command support Jan Weitzel
  3 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2012-09-14  7:45 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/Makefile |    1 +
 arch/arm/lib/bbu.c    |   56 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/bbu.h         |    3 +++
 3 files changed, 60 insertions(+)
 create mode 100644 arch/arm/lib/bbu.c

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 9d0ff7a..c5d6a06 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -16,6 +16,7 @@ obj-y	+= lib1funcs.o
 obj-y	+= ashrdi3.o
 obj-y	+= ashldi3.o
 obj-y	+= lshrdi3.o
+obj-y	+= bbu.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memcpy.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memset.o
 obj-$(CONFIG_ARM_UNWIND) += unwind.o
diff --git a/arch/arm/lib/bbu.c b/arch/arm/lib/bbu.c
new file mode 100644
index 0000000..71a0d85
--- /dev/null
+++ b/arch/arm/lib/bbu.c
@@ -0,0 +1,56 @@
+/*
+ * bbu.c - ARM specific barebox update functions
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <common.h>
+#include <malloc.h>
+#include <bbu.h>
+#include <filetype.h>
+#include <errno.h>
+
+int barebox_arm_update(struct bbu_handler *handler, struct bbu_data *data)
+{
+	if (file_detect_type(data->image) != filetype_arm_barebox) {
+		if (!bbu_force(data, "Not an ARM barebox image"))
+			return -EINVAL;
+	}
+
+	if (!bbu_confirm(data))
+		return -EINVAL;
+
+	printf("updating to %s\n", (char *)handler->handler_data);
+
+	return 0;
+}
+
+int bbu_register_arm_handler(const char *name, char *devicefile,
+		unsigned long flags)
+{
+	struct bbu_handler *handler;
+	int ret;
+
+	handler = xzalloc(sizeof(*handler));
+	handler->name = name;
+	handler->handler_data = devicefile;
+	handler->flags = flags;
+	handler->handler = barebox_arm_update;
+
+	ret = bbu_register_handler(handler);
+	if (ret)
+		free(handler);
+
+	return ret;
+}
diff --git a/include/bbu.h b/include/bbu.h
index ce1a608..a71c25b 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -30,6 +30,9 @@ int bbu_register_handler(struct bbu_handler *);
 
 int barebox_update(struct bbu_data *);
 
+int bbu_register_arm_handler(const char *name, char *devicefile,
+		unsigned long flags);
+
 int barebox_arm_update(struct bbu_handler *, struct bbu_data *data);
 
 void bbu_handlers_list(void);
-- 
1.7.10.4


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

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

* [PATCH 3/3] ARM pcm038: register nor update handler
  2012-09-14  7:45 [RFC, PATCH] barebox-update command support Sascha Hauer
  2012-09-14  7:45 ` [PATCH 1/3] Add barebox update infrastructure Sascha Hauer
  2012-09-14  7:45 ` [PATCH 2/3] ARM: Add dummy update handler Sascha Hauer
@ 2012-09-14  7:45 ` Sascha Hauer
  2012-09-14 12:36 ` [RFC, PATCH] barebox-update command support Jan Weitzel
  3 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2012-09-14  7:45 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/pcm038/pcm038.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 912d6ea..2f4d71d 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -30,6 +30,7 @@
 #include <generated/mach-types.h>
 #include <partition.h>
 #include <fs.h>
+#include <bbu.h>
 #include <nand.h>
 #include <spi/spi.h>
 #include <io.h>
@@ -196,6 +197,7 @@ static int pcm038_devices_init(void)
 	int i;
 	u64 uid = 0;
 	char *envdev;
+	unsigned long bbu_flags_nor = 0, bbu_flags_nand = 0;
 
 	unsigned int mode[] = {
 		PD0_AIN_FEC_TXD0,
@@ -318,6 +320,7 @@ static int pcm038_devices_init(void)
 					DEVFS_PARTITION_FIXED, "env_raw");
 		dev_add_bb_dev("env_raw", "env0");
 		envdev = "NAND";
+		bbu_flags_nand = BBU_HANDLER_FLAG_DEFAULT;
 		break;
 	default:
 		devfs_add_partition("nor0", 0x00000, 0x80000,
@@ -327,6 +330,7 @@ static int pcm038_devices_init(void)
 		protect_file("/dev/env0", 1);
 
 		envdev = "NOR";
+		bbu_flags_nor = BBU_HANDLER_FLAG_DEFAULT;
 	}
 
 	printf("Using environment in %s Flash\n", envdev);
@@ -336,6 +340,9 @@ static int pcm038_devices_init(void)
 	armlinux_set_bootparams((void *)0xa0000100);
 	armlinux_set_architecture(MACH_TYPE_PCM038);
 
+	bbu_register_arm_handler("nor", "/dev/nor0", bbu_flags_nor);
+	bbu_register_arm_handler("nand", "/dev/nand0", bbu_flags_nand);
+
 	return 0;
 }
 
-- 
1.7.10.4


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

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

* Re: [PATCH 1/3] Add barebox update infrastructure
  2012-09-14  7:45 ` [PATCH 1/3] Add barebox update infrastructure Sascha Hauer
@ 2012-09-14 12:15   ` Jan Weitzel
  2012-09-15 12:28     ` Sascha Hauer
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Weitzel @ 2012-09-14 12:15 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Am Freitag, den 14.09.2012, 09:45 +0200 schrieb Sascha Hauer:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  commands/Kconfig          |    5 +++
>  commands/Makefile         |    1 +
>  commands/barebox-update.c |   80 +++++++++++++++++++++++++++++++++
>  common/Kconfig            |    3 ++
>  common/Makefile           |    1 +
>  common/bbu.c              |  110 +++++++++++++++++++++++++++++++++++++++++++++
>  include/bbu.h             |   37 +++++++++++++++
>  7 files changed, 237 insertions(+)
>  create mode 100644 commands/barebox-update.c
>  create mode 100644 common/bbu.c
>  create mode 100644 include/bbu.h
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index f2756cc..0ed0d69 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -470,6 +470,11 @@ config CMD_OFTREE
>  	prompt "oftree"
>  	select FDT
>  
> +config CMD_BAREBOX_UPDATE
> +	tristate
> +	select BAREBOX_UPDATE
> +	prompt "barebox-update"
> +
>  endmenu
>  
>  config CMD_TIMEOUT
> diff --git a/commands/Makefile b/commands/Makefile
> index ccebd7f..62762de 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -74,3 +74,4 @@ obj-$(CONFIG_CMD_BASENAME)	+= basename.o
>  obj-$(CONFIG_CMD_DIRNAME)	+= dirname.o
>  obj-$(CONFIG_CMD_READLINK)	+= readlink.o
>  obj-$(CONFIG_CMD_LN)		+= ln.o
> +obj-$(CONFIG_CMD_BAREBOX_UPDATE)+= barebox-update.o
> diff --git a/commands/barebox-update.c b/commands/barebox-update.c
> new file mode 100644
> index 0000000..db8ae7d
> --- /dev/null
> +++ b/commands/barebox-update.c
> @@ -0,0 +1,80 @@
> +/*
> + * barebox-update.c - update barebox
> + *
> + * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include <common.h>
> +#include <command.h>
> +#include <getopt.h>
> +#include <malloc.h>
> +#include <errno.h>
> +#include <bbu.h>
> +#include <fs.h>
> +
> +static int do_barebox_update(int argc, char *argv[])
> +{
> +	int opt, ret;
> +	struct bbu_data data = {};
> +
> +	while ((opt = getopt(argc, argv, "t:yf:l")) > 0) {
> +		switch (opt) {
> +		case 'f':
> +			data.force = simple_strtoul(optarg, NULL, 0);
> +			data.flags |= BBU_FLAG_FORCE;
> +			break;
> +		case 't':
> +			data.handler_name = optarg;
> +			break;
> +		case 'y':
> +			data.flags |= BBU_FLAG_YES;
> +			break;
> +		case 'l':
> +			printf("registered handlers:\n");
> +			bbu_handlers_list();
> +			return 0;
> +		default:
> +			return COMMAND_ERROR_USAGE;
> +		}
> +	}
> +
> +	if (!(argc - optind))
> +		return COMMAND_ERROR_USAGE;
> +
> +	data.imagefile = argv[optind];
> +
> +	data.image = read_file(data.imagefile, &data.len);
> +	if (!data.image)
> +		return -errno;
> +
> +	ret = barebox_update(&data);
> +
> +	free(data.image);
> +
> +	return ret;
> +}
> +
> +BAREBOX_CMD_HELP_START(barebox_update)
> +BAREBOX_CMD_HELP_USAGE("barebox_update [OPTIONS <image>]\n")
image is mandatory
> +BAREBOX_CMD_HELP_OPT("-t <target>", "\n")
> +BAREBOX_CMD_HELP_OPT("-y\t", "yes. Do not ask for confirmation\n")
> +BAREBOX_CMD_HELP_OPT("-f <level>", "Set force level\n")
> +BAREBOX_CMD_HELP_OPT("-l\t", "list registered targets\n")
> +BAREBOX_CMD_HELP_END
> +
> +BAREBOX_CMD_START(barebox_update)
> +	.cmd		= do_barebox_update,
> +	.usage		= "update barebox",
> +	BAREBOX_CMD_HELP(cmd_barebox_update_help)
> +BAREBOX_CMD_END
> diff --git a/common/Kconfig b/common/Kconfig
> index b97392c..a6f6c0f 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -58,6 +58,9 @@ config GLOBALVAR
>  config STDDEV
>  	bool
>  
> +config BAREBOX_UPDATE
> +	bool
> +
>  menu "General Settings              "
>  
>  config LOCALVERSION
> diff --git a/common/Makefile b/common/Makefile
> index df9f301..07c422a 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -37,6 +37,7 @@ obj-$(CONFIG_MENU) += menu.o
>  obj-$(CONFIG_PASSWORD) += password.o
>  obj-$(CONFIG_MODULES) += module.o
>  obj-$(CONFIG_FLEXIBLE_BOOTARGS) += bootargs.o
> +obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
>  extra-$(CONFIG_MODULES) += module.lds
>  
>  ifdef CONFIG_DEFAULT_ENVIRONMENT
> diff --git a/common/bbu.c b/common/bbu.c
> new file mode 100644
> index 0000000..928c34b
> --- /dev/null
> +++ b/common/bbu.c
> @@ -0,0 +1,110 @@
> +/*
> + * bbu.c - barebox update functions
> + *
> + * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include <common.h>
> +#include <bbu.h>
> +#include <linux/list.h>
> +#include <errno.h>
> +#include <readkey.h>
> +
> +static LIST_HEAD(bbu_image_handlers);
> +
> +int bbu_force(struct bbu_data *data, const char *fmt, ...)
> +{
> +	va_list args;
> +
> +	printf("UPDATE: ");
> +
> +	va_start(args, fmt);
> +
> +	vprintf(fmt, args);
> +
> +	va_end(args);
> +
> +	if (!(data->flags & BBU_FLAG_FORCE))
> +		goto out;
> +
> +	if (!data->force)
> +		goto out;
> +
> +	data->force--;
> +
> +	printf(" (forced)\n");
> +
> +	return 1;
> +out:
> +	printf("\n");
> +
> +	return 0;
> +}
> +
> +int bbu_confirm(struct bbu_data *data)
> +{
> +	int key;
> +
> +	if (data->flags & BBU_FLAG_YES)
> +		return 1;
> +
> +	printf("update barebox from %s to %s (y/n)?\n",
> +			data->imagefile, data->handler_name);
> +
> +	key = read_key();
> +	if (key == 'y')
> +		return 1;
> +	return 0;
> +}
> +
> +int barebox_update(struct bbu_data *data)
> +{
> +	struct bbu_handler *handler;
> +	int ret;
> +
> +	list_for_each_entry(handler, &bbu_image_handlers, list) {
> +		if (!data->handler_name) {
> +			if (handler->flags & BBU_HANDLER_FLAG_DEFAULT) {
> +				data->handler_name = handler->name;
> +				goto found;
> +			}
> +			continue;
> +		}
> +		if (!strcmp(handler->name, data->handler_name))
> +			goto found;
> +	}
> +
> +	return -ENODEV;
> +
> +found:
> +
> +	ret = handler->handler(handler, data);
> +	return ret;
> +}
> +
> +void bbu_handlers_list(void)
> +{
> +	struct bbu_handler *handler;
> +
> +	list_for_each_entry(handler, &bbu_image_handlers, list)
> +		printf("%s%s\n", handler->name,
> +				handler->flags & BBU_HANDLER_FLAG_DEFAULT ?
> +				" (default)" : "");
> +}
> +
> +int bbu_register_handler(struct bbu_handler *handler)
> +{
> +	list_add_tail(&handler->list, &bbu_image_handlers);
> +	return 0;
> +}
> diff --git a/include/bbu.h b/include/bbu.h
> new file mode 100644
> index 0000000..ce1a608
> --- /dev/null
> +++ b/include/bbu.h
> @@ -0,0 +1,37 @@
> +#ifndef __INCLUDE_BBU_H
> +#define __INCLUDE_BBU_H
> +
> +struct bbu_data {
> +#define BBU_FLAG_FORCE	(1 << 0)
> +#define BBU_FLAG_YES	(1 << 1)
> +	unsigned long flags;
> +	int force;
> +	void *image;
> +	const char *imagefile;
> +	size_t len;
> +	const char *handler_name;
> +};
> +
> +struct bbu_handler {
> +	int (*handler)(struct bbu_handler *, struct bbu_data *);
> +	void *handler_data;
> +	const char *name;
> +	struct list_head list;
> +#define BBU_HANDLER_FLAG_DEFAULT	(1 << 0)
> +	unsigned long flags;
> +};
> +
> +int bbu_force(struct bbu_data *, const char *fmt, ...)
> +	__attribute__ ((format(__printf__, 2, 3)));
> +
> +int bbu_confirm(struct bbu_data *);
> +
> +int bbu_register_handler(struct bbu_handler *);
> +
> +int barebox_update(struct bbu_data *);
> +
> +int barebox_arm_update(struct bbu_handler *, struct bbu_data *data);
> +
> +void bbu_handlers_list(void);
> +
> +#endif /* __INCLUDE_BBU_H */



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

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

* Re: [PATCH 2/3] ARM: Add dummy update handler
  2012-09-14  7:45 ` [PATCH 2/3] ARM: Add dummy update handler Sascha Hauer
@ 2012-09-14 12:17   ` Jan Weitzel
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Weitzel @ 2012-09-14 12:17 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Am Freitag, den 14.09.2012, 09:45 +0200 schrieb Sascha Hauer:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/lib/Makefile |    1 +
>  arch/arm/lib/bbu.c    |   56 +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/bbu.h         |    3 +++
>  3 files changed, 60 insertions(+)
>  create mode 100644 arch/arm/lib/bbu.c
> 
> diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
> index 9d0ff7a..c5d6a06 100644
> --- a/arch/arm/lib/Makefile
> +++ b/arch/arm/lib/Makefile
> @@ -16,6 +16,7 @@ obj-y	+= lib1funcs.o
>  obj-y	+= ashrdi3.o
>  obj-y	+= ashldi3.o
>  obj-y	+= lshrdi3.o
> +obj-y	+= bbu.o
>  obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memcpy.o
>  obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memset.o
>  obj-$(CONFIG_ARM_UNWIND) += unwind.o
> diff --git a/arch/arm/lib/bbu.c b/arch/arm/lib/bbu.c
> new file mode 100644
> index 0000000..71a0d85
> --- /dev/null
> +++ b/arch/arm/lib/bbu.c
> @@ -0,0 +1,56 @@
> +/*
> + * bbu.c - ARM specific barebox update functions
> + *
> + * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include <common.h>
> +#include <malloc.h>
> +#include <bbu.h>
> +#include <filetype.h>
> +#include <errno.h>
> +
> +int barebox_arm_update(struct bbu_handler *handler, struct bbu_data *data)
> +{
> +	if (file_detect_type(data->image) != filetype_arm_barebox) {
is_barebox_arm_head(data->image) ?
> +		if (!bbu_force(data, "Not an ARM barebox image"))
> +			return -EINVAL;
> +	}
> +
> +	if (!bbu_confirm(data))
> +		return -EINVAL;
> +
> +	printf("updating to %s\n", (char *)handler->handler_data);
> +
> +	return 0;
> +}
> +
> +int bbu_register_arm_handler(const char *name, char *devicefile,
> +		unsigned long flags)
> +{
> +	struct bbu_handler *handler;
> +	int ret;
> +
> +	handler = xzalloc(sizeof(*handler));
> +	handler->name = name;
> +	handler->handler_data = devicefile;
> +	handler->flags = flags;
> +	handler->handler = barebox_arm_update;
> +
> +	ret = bbu_register_handler(handler);
> +	if (ret)
> +		free(handler);
> +
> +	return ret;
> +}
> diff --git a/include/bbu.h b/include/bbu.h
> index ce1a608..a71c25b 100644
> --- a/include/bbu.h
> +++ b/include/bbu.h
> @@ -30,6 +30,9 @@ int bbu_register_handler(struct bbu_handler *);
>  
>  int barebox_update(struct bbu_data *);
>  
> +int bbu_register_arm_handler(const char *name, char *devicefile,
> +		unsigned long flags);
> +
>  int barebox_arm_update(struct bbu_handler *, struct bbu_data *data);
>  
>  void bbu_handlers_list(void);



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

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

* Re: [RFC, PATCH] barebox-update command support
  2012-09-14  7:45 [RFC, PATCH] barebox-update command support Sascha Hauer
                   ` (2 preceding siblings ...)
  2012-09-14  7:45 ` [PATCH 3/3] ARM pcm038: register nor " Sascha Hauer
@ 2012-09-14 12:36 ` Jan Weitzel
  2012-09-15 12:33   ` Sascha Hauer
  3 siblings, 1 reply; 9+ messages in thread
From: Jan Weitzel @ 2012-09-14 12:36 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Am Freitag, den 14.09.2012, 09:45 +0200 schrieb Sascha Hauer:
> Hi All,
> 
> The following adds barebox-update command support. This command is
> supposed to provide a dedicated command for updating barebox.
On OMAP we have MLO and barebox. Should we use the command only for MLO?
The barebox didn't need special handling. Whats about kernel image and
rootfs? 
Jan 

> The rationale behind this is:
> 
> - We can add additional generic, SoC specific, board specific sanity
>   checks (Is this really a barebox image? Does the image fit into the
>   device?)
> - Sometimes SoC or board specific fixups are necessary. For example,
>   with Omap Nand boot we have to switch the Nand driver into a different
>   ECC mode before flashing barebox. With i.MX MMC card boot we want
>   to preserve the partition table. On i.MX28 Nand boot we have to create
>   a Boot Control Block. The list does not end here...
> 
> The current idea is:
> 
> A board can register one or multiple update handlers. The update handlers
> themselves are registered by a board because only the board knows where
> it actually can boot from. Nevertheless there might be generic handlers
> available, the most simple one being: Check image header, check size, write
> to device.
> 
> This is in an early state, right now there are only dummy handlers, hence the
> RFC state.
> 
> Sascha
> 
> ----------------------------------------------------------------
> Sascha Hauer (3):
>       Add barebox update infrastructure
>       ARM: Add dummy update handler
>       ARM pcm038: register nor update handler
> 
>  arch/arm/boards/pcm038/pcm038.c |    7 +++
>  arch/arm/lib/Makefile           |    1 +
>  arch/arm/lib/bbu.c              |   56 ++++++++++++++++++++
>  commands/Kconfig                |    5 ++
>  commands/Makefile               |    1 +
>  commands/barebox-update.c       |   80 ++++++++++++++++++++++++++++
>  common/Kconfig                  |    3 ++
>  common/Makefile                 |    1 +
>  common/bbu.c                    |  110 +++++++++++++++++++++++++++++++++++++++
>  include/bbu.h                   |   40 ++++++++++++++
>  10 files changed, 304 insertions(+)
>  create mode 100644 arch/arm/lib/bbu.c
>  create mode 100644 commands/barebox-update.c
>  create mode 100644 common/bbu.c
>  create mode 100644 include/bbu.h
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox



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

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

* Re: [PATCH 1/3] Add barebox update infrastructure
  2012-09-14 12:15   ` Jan Weitzel
@ 2012-09-15 12:28     ` Sascha Hauer
  0 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2012-09-15 12:28 UTC (permalink / raw)
  To: Jan Weitzel; +Cc: barebox

On Fri, Sep 14, 2012 at 02:15:46PM +0200, Jan Weitzel wrote:
> > +
> > +BAREBOX_CMD_HELP_START(barebox_update)
> > +BAREBOX_CMD_HELP_USAGE("barebox_update [OPTIONS <image>]\n")
> image is mandatory

Ok, fixed. 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] 9+ messages in thread

* Re: [RFC, PATCH] barebox-update command support
  2012-09-14 12:36 ` [RFC, PATCH] barebox-update command support Jan Weitzel
@ 2012-09-15 12:33   ` Sascha Hauer
  0 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2012-09-15 12:33 UTC (permalink / raw)
  To: Jan Weitzel; +Cc: barebox

On Fri, Sep 14, 2012 at 02:36:20PM +0200, Jan Weitzel wrote:
> Am Freitag, den 14.09.2012, 09:45 +0200 schrieb Sascha Hauer:
> > Hi All,
> > 
> > The following adds barebox-update command support. This command is
> > supposed to provide a dedicated command for updating barebox.
> On OMAP we have MLO and barebox. Should we use the command only for MLO?
> The barebox didn't need special handling. Whats about kernel image and
> rootfs?

For Omap I am not sure. Making it bootable indeed requires two images,
so of these should be handled here. I don't know though how this could
be handled in a generic command.

Kernel and rootfs is another story, this shouldn't be handled here.
This command is thought to be for the potentially dangerous barebox
update where you only have a single try. Also, flashing kernel or rootfs
is not really SoC or board specific.

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] 9+ messages in thread

end of thread, other threads:[~2012-09-15 12:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-14  7:45 [RFC, PATCH] barebox-update command support Sascha Hauer
2012-09-14  7:45 ` [PATCH 1/3] Add barebox update infrastructure Sascha Hauer
2012-09-14 12:15   ` Jan Weitzel
2012-09-15 12:28     ` Sascha Hauer
2012-09-14  7:45 ` [PATCH 2/3] ARM: Add dummy update handler Sascha Hauer
2012-09-14 12:17   ` Jan Weitzel
2012-09-14  7:45 ` [PATCH 3/3] ARM pcm038: register nor " Sascha Hauer
2012-09-14 12:36 ` [RFC, PATCH] barebox-update command support Jan Weitzel
2012-09-15 12:33   ` Sascha Hauer

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