From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 5/7] introduce common bootstrap code
Date: Sat, 19 Jan 2013 12:26:31 +0100 [thread overview]
Message-ID: <20130119112631.GJ22953@game.jcrosoft.org> (raw)
In-Reply-To: <20130119112432.GG1906@pengutronix.de>
On 12:24 Sat 19 Jan , Sascha Hauer wrote:
> On Sat, Jan 19, 2013 at 08:35:12AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > This will allow to have a generic code to create different bootstrap
> >
> > As example
> > Barebox as TI Xloader
> > Barebox as AT91 Bootstrap
> >
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> > include/bootstrap.h | 34 +++++++++++++++++
> > lib/Kconfig | 2 +
> > lib/Makefile | 1 +
> > lib/bootstrap/Kconfig | 13 +++++++
> > lib/bootstrap/Makefile | 3 ++
> > lib/bootstrap/common.c | 21 +++++++++++
> > lib/bootstrap/devfs.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
> > lib/bootstrap/disk.c | 36 ++++++++++++++++++
> > 8 files changed, 208 insertions(+)
> > create mode 100644 include/bootstrap.h
> > create mode 100644 lib/bootstrap/Kconfig
> > create mode 100644 lib/bootstrap/Makefile
> > create mode 100644 lib/bootstrap/common.c
> > create mode 100644 lib/bootstrap/devfs.c
> > create mode 100644 lib/bootstrap/disk.c
> >
> > diff --git a/include/bootstrap.h b/include/bootstrap.h
> > new file mode 100644
> > index 0000000..26e9dbc
> > --- /dev/null
> > +++ b/include/bootstrap.h
> > @@ -0,0 +1,34 @@
> > +/*
> > + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
> > + *
> > + * Under GPLv2
> > + */
> > +
> > +#ifndef __BOOSTRAP_H__
> > +#define __BOOSTRAP_H__
> > +
> > +#define bootstrap_err(fmt, arg...) printf(fmt, ##arg)
> > +
> > +void bootstrap_boot(int (*func)(void), bool barebox);
> > +
> > +#ifdef CONFIG_BOOTSTRAP_DEVFS
> > +void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
> > + int default_size, int max_size);
> > +#else
> > +static inline void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
> > + int default_size, int max_size)
> > +{
> > + return NULL;
> > +}
> > +#endif
> > +
> > +#ifdef CONFIG_BOOTSTRAP_DISK
> > +void* bootstrap_read_disk(char *devname);
> > +#else
> > +static inline void* bootstrap_read_disk(char *devname)
> > +{
> > + return NULL;
> > +}
> > +#endif
> > +
> > +#endif /* __BOOSTRAP_H__ */
> > diff --git a/lib/Kconfig b/lib/Kconfig
> > index db8a6ad..4578353 100644
> > --- a/lib/Kconfig
> > +++ b/lib/Kconfig
> > @@ -52,4 +52,6 @@ config LIBMTD
> >
> > source lib/gui/Kconfig
> >
> > +source lib/bootstrap/Kconfig
> > +
> > endmenu
> > diff --git a/lib/Makefile b/lib/Makefile
> > index 85f4ec9..43f6ea3 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -1,3 +1,4 @@
> > +obj-$(CONFIG_BOOTSTRAP) += bootstrap/
> > obj-y += ctype.o
> > obj-y += rbtree.o
> > obj-y += display_options.o
> > diff --git a/lib/bootstrap/Kconfig b/lib/bootstrap/Kconfig
> > new file mode 100644
> > index 0000000..558da00
> > --- /dev/null
> > +++ b/lib/bootstrap/Kconfig
> > @@ -0,0 +1,13 @@
> > +menuconfig BOOTSTRAP
> > + bool "Library bootstrap routines "
> > + depends on SHELL_NONE
> > +
> > +if BOOTSTRAP
> > +
> > +config BOOTSTRAP_DEVFS
> > + bool "devfs support"
> > +
> > +config BOOTSTRAP_DISK
> > + bool "disk support"
> > +
> > +endif
> > diff --git a/lib/bootstrap/Makefile b/lib/bootstrap/Makefile
> > new file mode 100644
> > index 0000000..cbaa49f
> > --- /dev/null
> > +++ b/lib/bootstrap/Makefile
> > @@ -0,0 +1,3 @@
> > +obj-y += common.o
> > +obj-$(CONFIG_BOOTSTRAP_DEVFS) += devfs.o
> > +obj-$(CONFIG_BOOTSTRAP_DISK) += disk.o
> > diff --git a/lib/bootstrap/common.c b/lib/bootstrap/common.c
> > new file mode 100644
> > index 0000000..bca3eb7
> > --- /dev/null
> > +++ b/lib/bootstrap/common.c
> > @@ -0,0 +1,21 @@
> > +/*
> > + * Copyright (C) 2011 Sascha Hauer, Pengutronix
> > + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
> > + *
> > + * Under GPLv2
> > + */
> > +
> > +#include <common.h>
> > +#include <bootstrap.h>
> > +#include <filetype.h>
> > +
> > +void bootstrap_boot(int (*func)(void), bool barebox)
> > +{
> > + if (barebox && !is_barebox_arm_head((void*)func))
> > + return;
> > +
> > + shutdown_barebox();
> > + func();
> > +
> > + while (1);
> > +}
> > diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
> > new file mode 100644
> > index 0000000..1da9920
> > --- /dev/null
> > +++ b/lib/bootstrap/devfs.c
> > @@ -0,0 +1,98 @@
> > +/*
> > + * Copyright (C) 2011 Sascha Hauer, Pengutronix
> > + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
> > + *
> > + * Under GPLv2
> > + */
> > +
> > +#include <common.h>
> > +#include <partition.h>
> > +#include <nand.h>
> > +#include <driver.h>
> > +#include <linux/mtd/mtd.h>
> > +#include <fcntl.h>
> > +#include <filetype.h>
> > +#include <sizes.h>
> > +#include <errno.h>
> > +#include <malloc.h>
> > +#include <bootstrap.h>
> > +
> > +static void *read_image_head(const char *name)
> > +{
> > + void *header = xmalloc(ARM_HEAD_SIZE);
> > + struct cdev *cdev;
> > + int ret;
> > +
> > + cdev = cdev_open(name, O_RDONLY);
> > + if (!cdev) {
> > + bootstrap_err("failed to open partition\n");
> > + return NULL;
> > + }
> > +
> > + ret = cdev_read(cdev, header, ARM_HEAD_SIZE, 0, 0);
> > + cdev_close(cdev);
> > +
> > + if (ret != ARM_HEAD_SIZE) {
> > + bootstrap_err("failed to read from partition\n");
> > + return NULL;
> > + }
> > +
> > + return header;
> > +}
> > +
> > +static unsigned int get_image_size(void *head)
> > +{
> > + unsigned int ret = 0;
> > + unsigned int *psize = head + ARM_HEAD_SIZE_OFFSET;
> > +
> > + if (is_barebox_arm_head(head))
> > + ret = *psize;
> > + debug("Detected barebox image size %u\n", ret);
> > +
> > + return ret;
> > +}
> > +
> > +void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
> > + int default_size, int max_size)
> > +{
> > + int ret;
> > + int size = 0;
> > + void *to, *header;
> > + struct cdev *cdev;
> > + char *partname = "x";
> > +
> > + devfs_add_partition(devname, offset, max_size, DEVFS_PARTITION_FIXED, partname);
> > + if (use_bb) {
> > + dev_add_bb_dev(partname, "bbx");
> > + partname = "bbx";
> > + }
> > +
> > + header = read_image_head(partname);
> > + if (header) {
> > + size = get_image_size(header);
> > + if (!size)
> > + bootstrap_err("%s: failed to get image size\n", devname);
> > + }
> > +
> > + if (!size) {
> > + size = default_size;
> > + bootstrap_err("%s: failed to detect barebox and it's image size so use %d\n",
> > + devname, size);
> > + }
> > +
> > + to = xmalloc(size);
> > +
> > + cdev = cdev_open(partname, O_RDONLY);
> > + if (!cdev) {
> > + bootstrap_err("%s: failed to open %s\n", devname, partname);
> > + return NULL;
> > + }
> > +
> > + ret = cdev_read(cdev, to, size, 0, 0);
> > + if (ret != size) {
> > + bootstrap_err("%s: failed to read from %s\n", devname, partname);
> > + return NULL;
> > + }
> > +
> > + return to;
> > +}
> > diff --git a/lib/bootstrap/disk.c b/lib/bootstrap/disk.c
> > new file mode 100644
> > index 0000000..647f608
> > --- /dev/null
> > +++ b/lib/bootstrap/disk.c
> > @@ -0,0 +1,36 @@
> > +/*
> > + * Copyright (C) 2011 Sascha Hauer, Pengutronix
> > + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com>
> > + *
> > + * Under GPLv2
> > + */
> > +
> > +#include <common.h>
> > +#include <fs.h>
> > +#include <fcntl.h>
> > +#include <sizes.h>
> > +#include <errno.h>
> > +#include <malloc.h>
> > +
> > +void* bootstrap_read_disk(char *devname)
> > +{
> > + int ret;
> > + void *buf;
> > + int len;
> > + char *path = "/";
> > +
> > + ret = mount(dev, "fat", path);
>
> lib/bootstrap/disk.c: In function 'bootstrap_read_disk':
> lib/bootstrap/disk.c:22:14: error: 'dev' undeclared (first use in this function)
> lib/bootstrap/disk.c:22:14: note: each undeclared identifier is reported only once for each function it appears in
>
> > + if (ret) {
> > + boot_err("mounting %s failed with %d\n", dev, ret);
>
> lib/bootstrap/disk.c:24:3: warning: implicit declaration of function 'boot_err' [-Wimplicit-function-declaration]
I see too I send the old patch seres
Best Regards,
J.
>
> 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
next prev parent reply other threads:[~2013-01-19 11:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-19 7:33 [PATCH 0/7 v2] at91: add bootstrap support Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 7:35 ` [PATCH 1/7] at91: add test commamd to emulate bootrom boot Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 7:35 ` [PATCH 2/7] at91sam926x: lowlevel add external boot support Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 7:35 ` [PATCH 3/7] at91: sam926x: switch lowlevel param to c code Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 7:35 ` [PATCH 4/7] at91: usb-a9263 add lowlevel init Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 7:35 ` [PATCH 5/7] introduce common bootstrap code Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 11:24 ` Sascha Hauer
2013-01-19 11:26 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-01-19 11:29 ` Sascha Hauer
2013-01-19 13:36 ` Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 7:35 ` [PATCH 6/7] at91: add bootstrap version Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 7:35 ` [PATCH 7/7] at91: usb_a9263: " Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 11:22 ` Sascha Hauer
2013-01-19 11:24 ` Jean-Christophe PLAGNIOL-VILLARD
-- strict thread matches above, loose matches on Subject: below --
2013-01-19 11:21 [PATCH 0/7 v3] at91: add bootstrap support Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 11:26 ` [PATCH 1/7] at91: add test commamd to emulate bootrom boot Jean-Christophe PLAGNIOL-VILLARD
2013-01-19 11:26 ` [PATCH 5/7] introduce common bootstrap code Jean-Christophe PLAGNIOL-VILLARD
2012-12-29 10:04 [PATCH 0/7] at91: add bootstrap support Jean-Christophe PLAGNIOL-VILLARD
2012-12-29 10:08 ` [PATCH 1/7] at91: add test commamd to emulate bootrom boot Jean-Christophe PLAGNIOL-VILLARD
2012-12-29 10:08 ` [PATCH 5/7] introduce common bootstrap code Jean-Christophe PLAGNIOL-VILLARD
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=20130119112631.GJ22953@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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