mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/1] arm: add Android boot image support
@ 2012-04-11  5:42 Jean-Christophe PLAGNIOL-VILLARD
  2012-04-11  6:13 ` Baruch Siach
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-11  5:42 UTC (permalink / raw)
  To: barebox; +Cc: Magnus Damm

The Android Image contains 3 components and params

 - kernel
 - initrd
 - second stage (optional)

 - tags addr
 - bootargs

In fast boot the initrd is mandatory, in barebox we are less restrictive
use the initrd only if present

add to env params:
image_noverwrite_bootargs
	Disable overwrite of the bootargs with the one present in aimage

aimage_noverwrite_tags
	Disable overwrite of the tags addr with the one present in aimage

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: Magnus Damm <magnus.damm@gmail.com>
---
 arch/arm/lib/bootm.c |  147 ++++++++++++++++++++++++++++++++++++++++++++++++++
 commands/Kconfig     |    7 +++
 include/aimage.h     |   74 +++++++++++++++++++++++++
 3 files changed, 228 insertions(+), 0 deletions(-)
 create mode 100644 include/aimage.h

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 26833bd..305a4c6 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <sizes.h>
 #include <libbb.h>
+#include <magicvar.h>
 
 #include <asm/byteorder.h>
 #include <asm/setup.h>
@@ -238,12 +239,158 @@ static struct image_handler barebox_handler = {
 	.filetype = filetype_arm_barebox,
 };
 
+#include <aimage.h>
+
+static int aimage_load_resource(int fd, struct resource *r, void* buf, int ps)
+{
+	int ret;
+	void *image = (void *)r->start;
+	unsigned to_read = ps - r->size % ps;
+
+	ret = read_full(fd, image, r->size);
+	if (ret < 0)
+		return ret;
+
+	ret = read_full(fd, buf, to_read);
+	if (ret < 0)
+		printf("could not read dummy %d\n", to_read);
+
+	return ret;
+}
+
+static int do_bootm_aimage(struct image_data *data)
+{
+	struct resource *snd_stage_res;
+	int fd, ret;
+	struct android_header __header, *header;
+	void *buf;
+	int to_read;
+	struct android_header_comp *cmp;
+
+	fd = open(data->os_file, O_RDONLY);
+	if (fd < 0) {
+		perror("open");
+		return 1;
+	}
+
+	header = &__header;
+	ret = read(fd, header, sizeof(*header));
+	if (ret < sizeof(*header)) {
+		printf("could not read %s\n", data->os_file);
+		goto err_out;
+	}
+
+	printf("Android Image for '%s'\n", header->name);
+
+	/*
+	 * As on tftp we do not support lseek and we will just have to seek
+	 * for the size of a page - 1 max just buffer instead to read to dummy
+	 * data
+	 */
+	buf = xmalloc(header->page_size);
+
+	to_read = header->page_size - sizeof(*header);
+	ret = read_full(fd, buf, to_read);
+	if (ret < 0) {
+		printf("could not read dummy %d from %s\n", to_read, data->os_file);
+		goto err_out;
+	}
+
+	cmp = &header->kernel;
+	data->os_res = request_sdram_region("akernel", cmp->load_addr, cmp->size);
+	if (!data->os_res) {
+		ret = -ENOMEM;
+		goto err_out;
+	}
+
+	ret = aimage_load_resource(fd, data->os_res, buf, header->page_size);
+	if (ret < 0) {
+		perror("could not read kernel");
+		goto err_out;
+	}
+
+	/*
+	 * fastboot always expect a ramdisk
+	 * in barebox we can be less restrictive
+	 */
+	cmp = &header->ramdisk;
+	if (cmp->size) {
+		data->initrd_res = request_sdram_region("ainitrd", cmp->load_addr, cmp->size);
+		if (!data->initrd_res) {
+			ret = -ENOMEM;
+			goto err_out;
+		}
+
+		ret = aimage_load_resource(fd, data->initrd_res, buf, header->page_size);
+		if (ret < 0) {
+			perror("could not read initrd");
+			goto err_out;
+		}
+	}
+
+	if (!getenv("aimage_noverwrite_bootargs"))
+		setenv("bootargs", header->cmdline);
+
+	if (!getenv("aimage_noverwrite_tags"))
+		armlinux_set_bootparams((void*)header->tags_addr);
+
+	if (data->oftree) {
+		ret = of_fix_tree(data->oftree);
+		if (ret)
+			goto err_out;
+	}
+
+	cmp = &header->second_stage;
+	if (cmp->size) {
+		void (*second)(void);
+
+		snd_stage_res = request_sdram_region("asecond", cmp->load_addr, cmp->size);
+		if (!snd_stage_res) {
+			ret = -ENOMEM;
+			goto err_out;
+		}
+
+		ret = aimage_load_resource(fd, snd_stage_res, buf, header->page_size);
+		if (ret < 0) {
+			perror("could not read initrd");
+			goto err_out;
+		}
+
+		second = (void*)snd_stage_res->start;
+		shutdown_barebox();
+
+		second();
+
+		reset_cpu(0);
+	}
+
+	return __do_bootm_linux(data, 0);
+
+err_out:
+	close(fd);
+
+	return ret;
+}
+
+static struct image_handler aimage_handler = {
+	.name = "ARM Android Image",
+	.bootm = do_bootm_aimage,
+	.filetype = filetype_aimage,
+};
+
+#ifdef CONFIG_CMD_BOOTM_AIMAGE
+BAREBOX_MAGICVAR(aimage_noverwrite_bootargs, "Disable overwrite of the bootargs with the one present in aimage");
+BAREBOX_MAGICVAR(aimage_noverwrite_tags, "Disable overwrite of the tags addr with the one present in aimage");
+#endif
+
 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))
+		register_image_handler(&aimage_handler);
 
 	return 0;
 }
diff --git a/commands/Kconfig b/commands/Kconfig
index 2409178..e0c2f09 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -364,6 +364,13 @@ config CMD_BOOTM_OFTREE_UIMAGE
 	  Support using oftree uImages. Without this only raw oftree
 	  blobs can be used.
 
+config CMD_BOOTM_AIMAGE
+	bool
+	prompt "bootm Android image support"
+	depends on CMD_BOOTM && ARM
+	help
+	  Support using Android Images.
+
 config CMD_UIMAGE
 	tristate
 	prompt "uimage"
diff --git a/include/aimage.h b/include/aimage.h
new file mode 100644
index 0000000..9702b7d
--- /dev/null
+++ b/include/aimage.h
@@ -0,0 +1,74 @@
+/*
+ * (C) Copyright 2011 Jean-Christhophe PLAGNIOL-VILLARD <plagniol@jcrosoft.com>
+ *
+ * Android boot image
+ *
+ * Under GPLv2 only
+ */
+
+#ifndef __AIMAGE_H__
+#define __AIMAGE_H__
+
+#define BOOT_MAGIC	"ANDROID!"
+#define BOOT_MAGIC_SIZE	8
+#define BOOT_NAME_SIZE	16
+#define BOOT_ARGS_SIZE	512
+
+struct android_header_comp
+{
+	unsigned size;
+	unsigned load_addr;
+};
+
+struct android_header
+{
+	u8 magic[BOOT_MAGIC_SIZE];
+
+	struct android_header_comp kernel;
+
+	struct android_header_comp ramdisk;
+
+	struct android_header_comp second_stage;
+
+	/* physical addr for kernel tags */
+	unsigned tags_addr;
+	/* flash page size we assume */
+	unsigned page_size;
+	/* future expansion: should be 0 */
+	unsigned unused[2];
+
+	unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
+
+	unsigned char cmdline[BOOT_ARGS_SIZE];
+
+	unsigned id[8]; /* timestamp / checksum / sha1 / etc */
+};
+
+/*
+ * +-----------------+
+ * | boot header     | 1 page
+ * +-----------------+
+ * | kernel          | n pages
+ * +-----------------+
+ * | ramdisk         | m pages
+ * +-----------------+
+ * | second stage    | o pages
+ * +-----------------+
+ *
+ * n = (kernel_size + page_size - 1) / page_size
+ * m = (ramdisk_size + page_size - 1) / page_size
+ * o = (second_size + page_size - 1) / page_size
+ *
+ * 0. all entities are page_size aligned in flash
+ * 1. kernel and ramdisk are required (size != 0)
+ * 2. second is optional (second_size == 0 -> no second)
+ * 3. load each element (kernel, ramdisk, second) at
+ *    the specified physical address (kernel_addr, etc)
+ * 4. prepare tags at tag_addr.  kernel_args[] is
+ *    appended to the kernel commandline in the tags.
+ * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
+ * 6. if second_size != 0: jump to second_addr
+ *    else: jump to kernel_addr
+ */
+
+#endif /* __AIMAGE_H__ */
-- 
1.7.9.1


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

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

* Re: [PATCH 1/1] arm: add Android boot image support
  2012-04-11  5:42 [PATCH 1/1] arm: add Android boot image support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-11  6:13 ` Baruch Siach
  2012-04-11  7:25 ` [PATCH 1/1] filetype: " Jean-Christophe PLAGNIOL-VILLARD
  2012-04-12 10:01 ` [PATCH 1/1] arm: " Sascha Hauer
  2 siblings, 0 replies; 6+ messages in thread
From: Baruch Siach @ 2012-04-11  6:13 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox, Magnus Damm

Hi Jean-Christophe,

On Wed, Apr 11, 2012 at 07:42:34AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> The Android Image contains 3 components and params
> 
>  - kernel
>  - initrd
>  - second stage (optional)
> 
>  - tags addr
>  - bootargs
> 
> In fast boot the initrd is mandatory, in barebox we are less restrictive
> use the initrd only if present
> 
> add to env params:
> image_noverwrite_bootargs

s/image/aimage/

> 	Disable overwrite of the bootargs with the one present in aimage
> 
> aimage_noverwrite_tags
> 	Disable overwrite of the tags addr with the one present in aimage
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Magnus Damm <magnus.damm@gmail.com>

baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

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

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

* [PATCH 1/1] filetype: add Android boot image support
  2012-04-11  5:42 [PATCH 1/1] arm: add Android boot image support Jean-Christophe PLAGNIOL-VILLARD
  2012-04-11  6:13 ` Baruch Siach
@ 2012-04-11  7:25 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-12 10:01   ` Sascha Hauer
  2012-04-12 10:01 ` [PATCH 1/1] arm: " Sascha Hauer
  2 siblings, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-11  7:25 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/filetype.c  |    3 +++
 include/filetype.h |    1 +
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 40faff3..b784bff 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -37,6 +37,7 @@ static const char *filetype_str[] = {
 	[filetype_gzip] = "gzip compressed",
 	[filetype_bzip2] = "bzip2 compressed",
 	[filetype_oftree] = "open firmware flat device tree",
+	[filetype_aimage] = "Android boot image",
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -72,6 +73,8 @@ enum filetype file_detect_type(void *_buf)
                 return filetype_bzip2;
 	if (buf[0] == be32_to_cpu(0xd00dfeed))
 		return filetype_oftree;
+	if (strncmp(buf8, "ANDROID!", 8) == 0)
+		return filetype_aimage;
 
 	return filetype_unknown;
 }
diff --git a/include/filetype.h b/include/filetype.h
index 88f31df..d0b6226 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -15,6 +15,7 @@ enum filetype {
 	filetype_gzip,
 	filetype_bzip2,
 	filetype_oftree,
+	filetype_aimage,
 };
 
 const char *file_type_to_string(enum filetype f);
-- 
1.7.9.1


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

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

* Re: [PATCH 1/1] arm: add Android boot image support
  2012-04-11  5:42 [PATCH 1/1] arm: add Android boot image support Jean-Christophe PLAGNIOL-VILLARD
  2012-04-11  6:13 ` Baruch Siach
  2012-04-11  7:25 ` [PATCH 1/1] filetype: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-12 10:01 ` Sascha Hauer
  2012-04-12 11:29   ` Jean-Christophe PLAGNIOL-VILLARD
  2 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2012-04-12 10:01 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox, Magnus Damm

On Wed, Apr 11, 2012 at 07:42:34AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> The Android Image contains 3 components and params
> 
>  - kernel
>  - initrd
>  - second stage (optional)
> 
>  - tags addr
>  - bootargs
> 
> In fast boot the initrd is mandatory, in barebox we are less restrictive
> use the initrd only if present
> 
> add to env params:
> image_noverwrite_bootargs
> 	Disable overwrite of the bootargs with the one present in aimage
> 
> aimage_noverwrite_tags
> 	Disable overwrite of the tags addr with the one present in aimage
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: Magnus Damm <magnus.damm@gmail.com>
> ---
>  arch/arm/lib/bootm.c |  147 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  commands/Kconfig     |    7 +++
>  include/aimage.h     |   74 +++++++++++++++++++++++++
>  3 files changed, 228 insertions(+), 0 deletions(-)
>  create mode 100644 include/aimage.h
> 
> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c

Can we have this in a seperate file? You made Android support optional
already and support is only registered when the option is enabled, but
the code is compiled even without the option.

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

* Re: [PATCH 1/1] filetype: add Android boot image support
  2012-04-11  7:25 ` [PATCH 1/1] filetype: " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-12 10:01   ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-04-12 10:01 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Apr 11, 2012 at 09:25:24AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Applied this one, thanks

Sascha

> ---
>  common/filetype.c  |    3 +++
>  include/filetype.h |    1 +
>  2 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/common/filetype.c b/common/filetype.c
> index 40faff3..b784bff 100644
> --- a/common/filetype.c
> +++ b/common/filetype.c
> @@ -37,6 +37,7 @@ static const char *filetype_str[] = {
>  	[filetype_gzip] = "gzip compressed",
>  	[filetype_bzip2] = "bzip2 compressed",
>  	[filetype_oftree] = "open firmware flat device tree",
> +	[filetype_aimage] = "Android boot image",
>  };
>  
>  const char *file_type_to_string(enum filetype f)
> @@ -72,6 +73,8 @@ enum filetype file_detect_type(void *_buf)
>                  return filetype_bzip2;
>  	if (buf[0] == be32_to_cpu(0xd00dfeed))
>  		return filetype_oftree;
> +	if (strncmp(buf8, "ANDROID!", 8) == 0)
> +		return filetype_aimage;
>  
>  	return filetype_unknown;
>  }
> diff --git a/include/filetype.h b/include/filetype.h
> index 88f31df..d0b6226 100644
> --- a/include/filetype.h
> +++ b/include/filetype.h
> @@ -15,6 +15,7 @@ enum filetype {
>  	filetype_gzip,
>  	filetype_bzip2,
>  	filetype_oftree,
> +	filetype_aimage,
>  };
>  
>  const char *file_type_to_string(enum filetype f);
> -- 
> 1.7.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

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

* Re: [PATCH 1/1] arm: add Android boot image support
  2012-04-12 10:01 ` [PATCH 1/1] arm: " Sascha Hauer
@ 2012-04-12 11:29   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-12 11:29 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox, Magnus Damm

On 12:01 Thu 12 Apr     , Sascha Hauer wrote:
> On Wed, Apr 11, 2012 at 07:42:34AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > The Android Image contains 3 components and params
> > 
> >  - kernel
> >  - initrd
> >  - second stage (optional)
> > 
> >  - tags addr
> >  - bootargs
> > 
> > In fast boot the initrd is mandatory, in barebox we are less restrictive
> > use the initrd only if present
> > 
> > add to env params:
> > image_noverwrite_bootargs
> > 	Disable overwrite of the bootargs with the one present in aimage
> > 
> > aimage_noverwrite_tags
> > 	Disable overwrite of the tags addr with the one present in aimage
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Cc: Magnus Damm <magnus.damm@gmail.com>
> > ---
> >  arch/arm/lib/bootm.c |  147 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  commands/Kconfig     |    7 +++
> >  include/aimage.h     |   74 +++++++++++++++++++++++++
> >  3 files changed, 228 insertions(+), 0 deletions(-)
> >  create mode 100644 include/aimage.h
> > 
> > diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> 
> Can we have this in a seperate file? You made Android support optional
> already and support is only registered when the option is enabled, but
> the code is compiled even without the option.
IIRC the struct is droped by the garbage collector as it's never used

the idea is to compile it always but drop it is not used

without the option

# ls -al build/tny-a9263/barebox.bin 
-rwxr-xr-x 1 root root 259056 Apr 12 18:29 build/tny-a9263/barebox.bin

with it
# ls -al build/tny-a9263/barebox.bin 
-rwxr-xr-x 1 root root 259960 Apr 12 19:45 build/tny-a9263/barebox.bin

Best Regards,
J.

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

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

end of thread, other threads:[~2012-04-12 11:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-11  5:42 [PATCH 1/1] arm: add Android boot image support Jean-Christophe PLAGNIOL-VILLARD
2012-04-11  6:13 ` Baruch Siach
2012-04-11  7:25 ` [PATCH 1/1] filetype: " Jean-Christophe PLAGNIOL-VILLARD
2012-04-12 10:01   ` Sascha Hauer
2012-04-12 10:01 ` [PATCH 1/1] arm: " Sascha Hauer
2012-04-12 11:29   ` Jean-Christophe PLAGNIOL-VILLARD

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