Skip to contentSkip to conversation

introduce binfmt support

PATCH In review Jean-Christophe PLAGNIOL-VILLARD 2 participants 7 messages Apr 18, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover introduce binfmt support

Hi,i

the following patch series

Introduce binfmt support

This will allow to execute any file and detect it's type to handle it. This will allow to use shell for bootp bootfile or dfu.

v2:

fix simple conole support
rebase against next

The following changes since commit a2d2e8868fe3c963ebac634b695ae18bb4b411ca:

config: switch machine to hostname (2012-04-18 12:03:58 +0200)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git binfmt

for you to fetch changes up to 2b26b148f4c8633a19bca0cbb96d4393ece8f54e:

defaultenv: add binfmt support (2012-04-18 20:19:20 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (5):
filetype: add Bourne Shell support
Introduce binfmt support
bootm: add uimage binfmt support
arm: bootm: add barebox, zImage and aImage binfmt support
defaultenv: add binfmt support

 arch/arm/lib/bootm.c |   22 +++++++++++-
 commands/bootm.c     |   12 ++++++
 common/Kconfig       |    5 +++
 common/Makefile      |    1 +
 common/binfmt.c      |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++
 common/filetype.c    |    3 ++
 common/hush.c        |   31 ++++++++++------
 defaultenv/bin/boot  |    4 ++
 include/binfmt.h     |   39 ++++++++++++++++++++
 include/filetype.h   |    1 +
 10 files changed, 200 insertions(+), 13 deletions(-)
 create mode 100644 common/binfmt.c
 create mode 100644 include/binfmt.h

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH v2 1/5 filetype: add Bourne Shell support

Put it at first as it's the most likely to detect

---
 common/filetype.c  |    3 +++
 include/filetype.h |    1 +
 2 files changed, 4 insertions(+), 0 deletions(-)
common/filetype.c +3 -0
index 0120913..15a3732 100644
@@ -38,6 +38,7 @@ static const char *filetype_str[] = {
 	[filetype_bzip2] = "bzip2 compressed",
 	[filetype_oftree] = "open firmware flat device tree",
 	[filetype_aimage] = "Android boot image",
+	[filetype_sh] = "Bourne Shell",
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -53,6 +54,8 @@ enum filetype file_detect_type(void *_buf)
 	u32 *buf = _buf;
 	u8 *buf8 = _buf;
 
+	if (strncmp(buf8, "#!/bin/sh", 9) == 0)
+		return filetype_sh;
 	if (buf[8] == 0x65726162 && buf[9] == 0x00786f62)
 		return filetype_arm_barebox;
 	if (buf[9] == 0x016f2818 || buf[9] == 0x18286f01)
include/filetype.h +1 -0
index d0b6226..9338793 100644
@@ -16,6 +16,7 @@ enum filetype {
 	filetype_bzip2,
 	filetype_oftree,
 	filetype_aimage,
+	filetype_sh,
 };
 
 const char *file_type_to_string(enum filetype f);
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 2/5 Introduce binfmt support

In reply to Jean-Christophe PLAGNIOL-VILLARD

This will allow to execute any file and detect it's type to handle it. This will allow to use shell for bootp bootfile or dfu.

You can register multiple hook for the same filetype. They will be execute in the invert order of register. If a hook does not handle the file you just return -ERESTARTNOHAND;

This is only available with hush parser.

---
fix simple paser support

 common/Kconfig   |    5 +++
 common/Makefile  |    1 +
 common/binfmt.c  |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/hush.c    |   31 +++++++++++-------
 include/binfmt.h |   39 ++++++++++++++++++++++
 5 files changed, 159 insertions(+), 12 deletions(-)
 create mode 100644 common/binfmt.c
 create mode 100644 include/binfmt.h
common/Kconfig +5 -0
index a997f3d..73d620a 100644
@@ -43,6 +43,10 @@ config HAVE_NOSHELL
 config FILETYPE
 	bool
 
+config BINFMT
+	bool
+	select FILETYPE
+
 menu "General Settings              "
 
 config LOCALVERSION
@@ -275,6 +279,7 @@ choice
 		select ENVIRONMENT_VARIABLES
 		select COMMAND_SUPPORT
 		select PARAMETER
+		select BINFMT
 		help
 		  Enable hush support. This is the most advanced shell available
 		  for barebox.
common/Makefile +1 -0
index bfde73c..a58aef9 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_BINFMT)		+= binfmt.o
 obj-$(CONFIG_SHELL_HUSH)	+= hush.o
 obj-$(CONFIG_SHELL_SIMPLE)	+= parser.o
 obj-$(CONFIG_GREGORIAN_CALENDER) += date.o
common/binfmt.c new file +95 -0

95 lines not on this page · raw message

common/hush.c +19 -12
index 053d9a5..2d89f2b 100644
@@ -124,6 +124,8 @@
 #include <libbb.h>
 #include <magicvar.h>
 #include <linux/list.h>
+#include <binfmt.h>
+#include <init.h>
 
 /*cmd_boot.c*/
 extern int do_bootd(int flag, int argc, char *argv[]);      /* do_bootd */
@@ -572,8 +574,6 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi)
 	int nextin;
 	struct child_prog *child;
 	char *p;
-	char *path;
-	int ret;
 # if __GNUC__
 	/* Avoid longjmp clobbering */
 	(void) &i;
@@ -642,16 +642,7 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi)
 		if (!strcmp(child->argv[i], "getopt"))
 			return builtin_getopt(ctx, child);
 #endif
-		if (strchr(child->argv[i], '/')) {
-			return execute_script(child->argv[i], child->argc-i, &child->argv[i]);
-		}
-		if ((path = find_execable(child->argv[i]))) {
-			ret = execute_script(path, child->argc-i, &child->argv[i]);
-			free(path);
-			return ret;
-		}
-
-		return execute_command(child->argc - i, &child->argv[i]);
+		return execute_binfmt(child->argc - i, &child->argv[i]);
 	}
 	return -1;
 }
@@ -1749,6 +1740,22 @@ BAREBOX_MAGICVAR(PATH, "colon seperated list of pathes to search for executables
 BAREBOX_MAGICVAR(PS1, "hush prompt");
 #endif
 
+static int binfmt_sh_excute(struct binfmt_hook *b, char *file, int argc, char **argv)
+{
+	return execute_script(file, argc, argv);
+}
+
+static struct binfmt_hook binfmt_sh_hook = {
+	.type = filetype_sh,
+	.hook = binfmt_sh_excute,
+};
+
+static int binfmt_sh_init(void)
+{
+	return binfmt_register(&binfmt_sh_hook);
+}
+fs_initcall(binfmt_sh_init);
+
 /**
  * @file
  * @brief A prototype Bourne shell grammar parser
include/binfmt.h new file +39 -0
new file mode 100644
index 0000000..46b627e
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * GPL v2
+ */
+
+#ifndef __BFMT_H__
+#define __BFMT_H__
+
+#include <filetype.h>
+#include <linux/list.h>
+
+struct binfmt_hook {
+	enum filetype type;
+	int (*hook)(struct binfmt_hook *b, char *file, int argc, char **argv);
+	char *exec;
+
+	struct list_head list;
+};
+
+#ifdef CONFIG_BINFMT
+int binfmt_register(struct binfmt_hook *b);
+void binfmt_unregister(struct binfmt_hook *b);
+
+int execute_binfmt(int argc, char **argv);
+#else
+static inline int binfmt_register(struct binfmt_hook *b)
+{
+	return -EINVAL;
+}
+static inline void binfmt_unregister(struct binfmt_hook *b) {}
+
+static inline int execute_binfmt(int argc, char **argv)
+{
+	return 1;
+}
+#endif
+
+#endif /* __BFMT_H__ */
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v2 3/5 bootm: add uimage binfmt support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 commands/bootm.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
commands/bootm.c +12 -0
index 1e1dc52..9e9abe4 100644
@@ -46,6 +46,7 @@
 #include <uncompress.h>
 #include <memory.h>
 #include <filetype.h>
+#include <binfmt.h>
 #include <asm-generic/memory_layout.h>
 
 static LIST_HEAD(handler_list);
@@ -454,6 +455,17 @@ BAREBOX_CMD_END
 
 BAREBOX_MAGICVAR(bootargs, "Linux Kernel parameters");
 
+static struct binfmt_hook binfmt_uimage_hook = {
+	.type = filetype_uimage,
+	.exec = "bootm",
+};
+
+static int binfmt_uimage_init(void)
+{
+	return binfmt_register(&binfmt_uimage_hook);
+}
+fs_initcall(binfmt_uimage_init);
+
 /**
  * @file
  * @brief Boot support for Linux
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v2 4/5 arm: bootm: add barebox, zImage and aImage binfmt support

In reply to Jean-Christophe PLAGNIOL-VILLARD

---
rebase against current next
add aimage support

 arch/arm/lib/bootm.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
arch/arm/lib/bootm.c +21 -1
index 26053dc..c4bd156 100644
@@ -15,6 +15,7 @@
 #include <libbb.h>
 #include <magicvar.h>
 #include <libfdt.h>
+#include <binfmt.h>
 
 #include <asm/byteorder.h>
 #include <asm/setup.h>
@@ -445,14 +446,33 @@ BAREBOX_MAGICVAR(aimage_noverwrite_bootargs, "Disable overwrite of the bootargs
 BAREBOX_MAGICVAR(aimage_noverwrite_tags, "Disable overwrite of the tags addr with the one present in aimage");
 #endif
 
+static struct binfmt_hook binfmt_aimage_hook = {
+	.type = filetype_aimage,
+	.exec = "bootm",
+};
+
+static struct binfmt_hook binfmt_arm_zimage_hook = {
+	.type = filetype_arm_zimage,
+	.exec = "bootm",
+};
+
+static struct binfmt_hook binfmt_barebox_hook = {
+	.type = filetype_arm_barebox,
+	.exec = "bootm",
+};
+
 static int armlinux_register_image_handler(void)
 {
 	register_image_handler(&barebox_handler);
 	register_image_handler(&uimage_handler);
 	register_image_handler(&rawimage_handler);
 	register_image_handler(&zimage_handler);
-	if (IS_BUILTIN(CONFIG_CMD_BOOTM_AIMAGE))
+	if (IS_BUILTIN(CONFIG_CMD_BOOTM_AIMAGE)) {
 		register_image_handler(&aimage_handler);
+		binfmt_register(&binfmt_aimage_hook);
+	}
+	binfmt_register(&binfmt_arm_zimage_hook);
+	binfmt_register(&binfmt_barebox_hook);
 
 	return 0;
 }
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v2 5/5 defaultenv: add binfmt support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 defaultenv/bin/boot |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
defaultenv/bin/boot +4 -0
index b54ea6b..61b893a 100644
@@ -134,4 +134,8 @@ fi
 
 echo "booting kernel from $kdev"
 
+#try to execute the file
+# it does not work as example for /dev as the file is not executable
+$kdev $bootm_opt
+# fall back on bootm
 bootm $bootm_opt $kdev
Signature · 7 lines
1.7.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 14 lines · Jean-Christophe PLAGNIOL-VILLARD

Hi,i

the following patch series

Introduce binfmt support

This will allow to execute any file and detect it's type to handle it. This will allow to use shell for bootp bootfile or dfu.

v2:

fix simple conole support
rebase against next

Quoted 7 lines

The following changes since commit a2d2e8868fe3c963ebac634b695ae18bb4b411ca:

config: switch machine to hostname (2012-04-18 12:03:58 +0200)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git binfmt

Pulled, thanks.

Sascha

Quoted 35 lines

for you to fetch changes up to 2b26b148f4c8633a19bca0cbb96d4393ece8f54e:

defaultenv: add binfmt support (2012-04-18 20:19:20 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (5):
filetype: add Bourne Shell support
Introduce binfmt support
bootm: add uimage binfmt support
arm: bootm: add barebox, zImage and aImage binfmt support
defaultenv: add binfmt support

 arch/arm/lib/bootm.c |   22 +++++++++++-
 commands/bootm.c     |   12 ++++++
 common/Kconfig       |    5 +++
 common/Makefile      |    1 +
 common/binfmt.c      |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++
 common/filetype.c    |    3 ++
 common/hush.c        |   31 ++++++++++------
 defaultenv/bin/boot  |    4 ++
 include/binfmt.h     |   39 ++++++++++++++++++++
 include/filetype.h   |    1 +
 10 files changed, 200 insertions(+), 13 deletions(-)
 create mode 100644 common/binfmt.c
 create mode 100644 include/binfmt.h

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox