From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-wi0-f175.google.com ([209.85.212.175]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TxFBx-00013B-Hc for barebox@lists.infradead.org; Mon, 21 Jan 2013 11:05:33 +0000 Received: by mail-wi0-f175.google.com with SMTP id hm11so7018479wib.2 for ; Mon, 21 Jan 2013 03:04:16 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1358764040-10690-8-git-send-email-plagnioj@jcrosoft.com> References: <20130121102319.GE26329@game.jcrosoft.org> <1358764040-10690-1-git-send-email-plagnioj@jcrosoft.com> <1358764040-10690-8-git-send-email-plagnioj@jcrosoft.com> Date: Mon, 21 Jan 2013 12:04:16 +0100 Message-ID: From: Alexander Aring List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============0688326851371528376==" Sender: barebox-bounces@lists.infradead.org Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: Re: [PATCH 08/10] introduce common bootstrap code To: Jean-Christophe PLAGNIOL-VILLARD Cc: barebox --===============0688326851371528376== Content-Type: multipart/alternative; boundary=089e0122896c071ca104d3ca6c60 --089e0122896c071ca104d3ca6c60 Content-Type: text/plain; charset=UTF-8 hi, found a little 'things'. Maybe it's matter. 2013/1/21 Jean-Christophe PLAGNIOL-VILLARD > 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 > --- > 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 | 118 > ++++++++++++++++++++++++++++++++++++++++++++++++ > lib/bootstrap/disk.c | 37 +++++++++++++++ > 8 files changed, 229 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..3652698 > --- /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 > +#include > +#include > + > +void bootstrap_boot(int (*func)(void), bool barebox) > +{ > + if (barebox && !is_barebox_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..25d07c7 > --- /dev/null > +++ b/lib/bootstrap/devfs.c > @@ -0,0 +1,118 @@ > +/* > + * Copyright (C) 2011 Sascha Hauer, Pengutronix > + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD < > plagnio@jcrosoft.com> > + * > + * Under GPLv2 > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) > +#if defined(CONFIG_ARM) > +#define BAREBOX_HEAD_SIZE ARM_HEAD_SIZE > +#define BAREBOX_HEAD_SIZE_OFFSET ARM_HEAD_SIZE_OFFSET > +#elif defined(CONFIG_MIPS) > +#define BAREBOX_HEAD_SIZE MIPS_HEAD_SIZE > +#define BAREBOX_HEAD_SIZE_OFFSET MIPS_HEAD_SIZE_OFFSET > +#endif > + > +static void *read_image_head(const char *name) > +{ > + void *header = xmalloc(BAREBOX_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, BAREBOX_HEAD_SIZE, 0, 0); > check on error here? > + cdev_close(cdev); > + > + if (ret != BAREBOX_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 + BAREBOX_HEAD_SIZE_OFFSET; > + > + if (is_barebox_head(head)) > + ret = *psize; > + debug("Detected barebox image size %u\n", ret); > + > + return ret; > +} > +#else > +static void *read_image_head(const char *name) > +{ > + return NULL; > +} > + > +static unsigned int get_image_size(void *head) > +{ > + return 0; > +} > +#endif > + > +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); > check on null here? > + > + 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..fad8990 > --- /dev/null > +++ b/lib/bootstrap/disk.c > @@ -0,0 +1,37 @@ > +/* > + * Copyright (C) 2011 Sascha Hauer, Pengutronix > + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD < > plagnio@jcrosoft.com> > + * > + * Under GPLv2 > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +void* bootstrap_read_disk(char *dev) > +{ > + int ret; > + void *buf; > + int len; > + char *path = "/"; > + > + ret = mount(dev, "fat", path); > + if (ret) { > + bootstrap_err("mounting %s failed with %d\n", dev, ret); > + return NULL; > + } > + > + buf = read_file("/barebox.bin", &len); > Can be set to read_file("/barebox.bin", null); > + if (!buf) { > + bootstrap_err("could not read barebox.bin from %s\n", dev); > + umount(path); > + return NULL; > + } > + > + return buf; > +} > -- > 1.7.10.4 > > > _______________________________________________ > barebox mailing list > barebox@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/barebox > --089e0122896c071ca104d3ca6c60 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
hi,

found a little '= things'. Maybe it's matter.

2013/= 1/21 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
This will allow to have a generic code to cr= eate different bootstrap

As example
Barebox as TI Xloader
Barebox as AT91 Bootstrap

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
=C2=A0include/bootstrap.h =C2=A0 =C2=A0| =C2=A0 34 ++++++++++++++
=C2=A0lib/Kconfig =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A02= +
=C2=A0lib/Makefile =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A01 + =C2=A0lib/bootstrap/Kconfig =C2=A0| =C2=A0 13 ++++++
=C2=A0lib/bootstrap/Makefile | =C2=A0 =C2=A03 ++
=C2=A0lib/bootstrap/common.c | =C2=A0 21 +++++++++
=C2=A0lib/bootstrap/devfs.c =C2=A0| =C2=A0118 +++++++++++++++++++++++++++++= +++++++++++++++++++
=C2=A0lib/bootstrap/disk.c =C2=A0 | =C2=A0 37 +++++++++++++++
=C2=A08 files changed, 229 insertions(+)
=C2=A0create mode 100644 include/bootstrap.h
=C2=A0create mode 100644 lib/bootstrap/Kconfig
=C2=A0create mode 100644 lib/bootstrap/Makefile
=C2=A0create mode 100644 lib/bootstrap/common.c
=C2=A0create mode 100644 lib/bootstrap/devfs.c
=C2=A0create 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,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0int default_size, int max_size);
+#else
+static inline void* bootstrap_read_devfs(char *devname, bool use_bb, int o= ffset,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0int default_size, int max_size)
+{
+ =C2=A0 =C2=A0 =C2=A0 return NULL;
+}
+#endif
+
+#ifdef CONFIG_BOOTSTRAP_DISK
+void* bootstrap_read_disk(char *devname);
+#else
+static inline void* bootstrap_read_disk(char *devname)
+{
+ =C2=A0 =C2=A0 =C2=A0 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

=C2=A0source lib/gui/Kconfig

+source lib/bootstrap/Kconfig
+
=C2=A0endmenu
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) =C2=A0 =C2=A0 =C2=A0 =C2=A0+=3D bootstrap/
=C2=A0obj-y =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+= =3D ctype.o
=C2=A0obj-y =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+= =3D rbtree.o
=C2=A0obj-y =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+= =3D 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
+ =C2=A0 =C2=A0 =C2=A0 bool "Library bootstrap routines =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 "
+ =C2=A0 =C2=A0 =C2=A0 depends on SHELL_NONE
+
+if BOOTSTRAP
+
+config BOOTSTRAP_DEVFS
+ =C2=A0 =C2=A0 =C2=A0 bool "devfs support"
+
+config BOOTSTRAP_DISK
+ =C2=A0 =C2=A0 =C2=A0 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 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0+=3D common.o
+obj-$(CONFIG_BOOTSTRAP_DEVFS) =C2=A0+=3D devfs.o
+obj-$(CONFIG_BOOTSTRAP_DISK) =C2=A0 +=3D disk.o
diff --git a/lib/bootstrap/common.c b/lib/bootstrap/common.c
new file mode 100644
index 0000000..3652698
--- /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)
+{
+ =C2=A0 =C2=A0 =C2=A0 if (barebox && !is_barebox_head((void*)func)= )
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
+
+ =C2=A0 =C2=A0 =C2=A0 shutdown_barebox();
+ =C2=A0 =C2=A0 =C2=A0 func();
+
+ =C2=A0 =C2=A0 =C2=A0 while (1);
+}
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
new file mode 100644
index 0000000..25d07c7
--- /dev/null
+++ b/lib/bootstrap/devfs.c
@@ -0,0 +1,118 @@
+/*
+ * 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>
+
+#if defined(CONFIG_ARM) || defined(CONFIG_MIPS)
+#if defined(CONFIG_ARM)
+#define BAREBOX_HEAD_SIZE =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= ARM_HEAD_SIZE
+#define BAREBOX_HEAD_SIZE_OFFSET =C2=A0 =C2=A0 =C2=A0 ARM_HEAD_SIZE_OFFSET=
+#elif defined(CONFIG_MIPS)
+#define BAREBOX_HEAD_SIZE =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= MIPS_HEAD_SIZE
+#define BAREBOX_HEAD_SIZE_OFFSET =C2=A0 =C2=A0 =C2=A0 MIPS_HEAD_SIZE_OFFSE= T
+#endif
+
+static void *read_image_head(const char *name)
+{
+ =C2=A0 =C2=A0 =C2=A0 void *header =3D xmalloc(BAREBOX_HEAD_SIZE);
+ =C2=A0 =C2=A0 =C2=A0 struct cdev *cdev;
+ =C2=A0 =C2=A0 =C2=A0 int ret;
+
+ =C2=A0 =C2=A0 =C2=A0 cdev =3D cdev_open(name, O_RDONLY);
+ =C2=A0 =C2=A0 =C2=A0 if (!cdev) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bootstrap_err("fail= ed to open partition\n");
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 ret =3D cdev_read(cdev, header, BAREBOX_HEAD_SIZE, 0= , 0);
check on error here?
=C2=A0
+ =C2=A0 =C2=A0 =C2=A0 cdev_close(cdev);
+
+ =C2=A0 =C2=A0 =C2=A0 if (ret !=3D BAREBOX_HEAD_SIZE) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bootstrap_err("fail= ed to read from partition\n");
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 return header;
+}
+
+static unsigned int get_image_size(void *head)
+{
+ =C2=A0 =C2=A0 =C2=A0 unsigned int ret =3D 0;
+ =C2=A0 =C2=A0 =C2=A0 unsigned int *psize =3D head + BAREBOX_HEAD_SIZE_OFF= SET;
+
+ =C2=A0 =C2=A0 =C2=A0 if (is_barebox_head(head))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D *psize;
+ =C2=A0 =C2=A0 =C2=A0 debug("Detected barebox image size %u\n", = ret);
+
+ =C2=A0 =C2=A0 =C2=A0 return ret;
+}
+#else
+static void *read_image_head(const char *name)
+{
+ =C2=A0 =C2=A0 =C2=A0 return NULL;
+}
+
+static unsigned int get_image_size(void *head)
+{
+ =C2=A0 =C2=A0 =C2=A0 return 0;
+}
+#endif
+
+void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0int default_size, int max_size)
+{
+ =C2=A0 =C2=A0 =C2=A0 int ret;
+ =C2=A0 =C2=A0 =C2=A0 int size =3D 0;
+ =C2=A0 =C2=A0 =C2=A0 void *to, *header;
+ =C2=A0 =C2=A0 =C2=A0 struct cdev *cdev;
+ =C2=A0 =C2=A0 =C2=A0 char *partname =3D "x";
+
+ =C2=A0 =C2=A0 =C2=A0 devfs_add_partition(devname, offset, max_size, DEVFS= _PARTITION_FIXED, partname);
+ =C2=A0 =C2=A0 =C2=A0 if (use_bb) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_add_bb_dev(partname,= "bbx");
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 partname =3D "bbx&q= uot;;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 header =3D read_image_head(partname);
+ =C2=A0 =C2=A0 =C2=A0 if (header) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D get_image_size(= header);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!size)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 bootstrap_err("%s: failed to get image size\n", devname);
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 if (!size) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D default_size; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bootstrap_err("%s: = failed to detect barebox and it's image size so use %d\n",
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0devname, size);
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 to =3D xmalloc(size);
check on = null here?
=C2=A0
+
+ =C2=A0 =C2=A0 =C2=A0 cdev =3D cdev_open(partname, O_RDONLY);
+ =C2=A0 =C2=A0 =C2=A0 if (!cdev) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bootstrap_err("%s: = failed to open %s\n", devname, partname);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 ret =3D cdev_read(cdev, to, size, 0, 0);
+ =C2=A0 =C2=A0 =C2=A0 if (ret !=3D size) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bootstrap_err("%s: = failed to read from %s\n", devname, partname);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 return to;
+}
diff --git a/lib/bootstrap/disk.c b/lib/bootstrap/disk.c
new file mode 100644
index 0000000..fad8990
--- /dev/null
+++ b/lib/bootstrap/disk.c
@@ -0,0 +1,37 @@
+/*
+ * 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>
+#include <bootstrap.h>
+
+void* bootstrap_read_disk(char *dev)
+{
+ =C2=A0 =C2=A0 =C2=A0 int ret;
+ =C2=A0 =C2=A0 =C2=A0 void *buf;
+ =C2=A0 =C2=A0 =C2=A0 int len;
+ =C2=A0 =C2=A0 =C2=A0 char *path =3D "/";
+
+ =C2=A0 =C2=A0 =C2=A0 ret =3D mount(dev, "fat", path);
+ =C2=A0 =C2=A0 =C2=A0 if (ret) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bootstrap_err("moun= ting %s failed with %d\n", dev, ret);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 buf =3D read_file("/barebox.bin", &len= );
Can be set to read_file("/barebox.bin", n= ull);
=C2=A0
+ =C2=A0 =C2=A0 =C2=A0 if (!buf) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bootstrap_err("coul= d not read barebox.bin from %s\n", dev);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 umount(path);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+ =C2=A0 =C2=A0 =C2=A0 }
+
+ =C2=A0 =C2=A0 =C2=A0 return buf;
+}
--
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org<= /a>
http://lists.infradead.org/mailman/listinfo/barebox

--089e0122896c071ca104d3ca6c60-- --===============0688326851371528376== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox --===============0688326851371528376==--