<div dir="ltr">hi,<br><div class="gmail_extra"><br>found a little 'things'. Maybe it's matter.<br><br><div class="gmail_quote">2013/1/21 Jean-Christophe PLAGNIOL-VILLARD <span dir="ltr"><<a href="mailto:plagnioj@jcrosoft.com" target="_blank">plagnioj@jcrosoft.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This will allow to have a generic code to create different bootstrap<br>
<br>
As example<br>
Barebox as TI Xloader<br>
Barebox as AT91 Bootstrap<br>
<br>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnioj@jcrosoft.com">plagnioj@jcrosoft.com</a>><br>
---<br>
include/bootstrap.h | 34 ++++++++++++++<br>
lib/Kconfig | 2 +<br>
lib/Makefile | 1 +<br>
lib/bootstrap/Kconfig | 13 ++++++<br>
lib/bootstrap/Makefile | 3 ++<br>
lib/bootstrap/common.c | 21 +++++++++<br>
lib/bootstrap/devfs.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++<br>
lib/bootstrap/disk.c | 37 +++++++++++++++<br>
8 files changed, 229 insertions(+)<br>
create mode 100644 include/bootstrap.h<br>
create mode 100644 lib/bootstrap/Kconfig<br>
create mode 100644 lib/bootstrap/Makefile<br>
create mode 100644 lib/bootstrap/common.c<br>
create mode 100644 lib/bootstrap/devfs.c<br>
create mode 100644 lib/bootstrap/disk.c<br>
<br>
diff --git a/include/bootstrap.h b/include/bootstrap.h<br>
new file mode 100644<br>
index 0000000..26e9dbc<br>
--- /dev/null<br>
+++ b/include/bootstrap.h<br>
@@ -0,0 +1,34 @@<br>
+/*<br>
+ * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnio@jcrosoft.com">plagnio@jcrosoft.com</a>><br>
+ *<br>
+ * Under GPLv2<br>
+ */<br>
+<br>
+#ifndef __BOOSTRAP_H__<br>
+#define __BOOSTRAP_H__<br>
+<br>
+#define bootstrap_err(fmt, arg...) printf(fmt, ##arg)<br>
+<br>
+void bootstrap_boot(int (*func)(void), bool barebox);<br>
+<br>
+#ifdef CONFIG_BOOTSTRAP_DEVFS<br>
+void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,<br>
+ int default_size, int max_size);<br>
+#else<br>
+static inline void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,<br>
+ int default_size, int max_size)<br>
+{<br>
+ return NULL;<br>
+}<br>
+#endif<br>
+<br>
+#ifdef CONFIG_BOOTSTRAP_DISK<br>
+void* bootstrap_read_disk(char *devname);<br>
+#else<br>
+static inline void* bootstrap_read_disk(char *devname)<br>
+{<br>
+ return NULL;<br>
+}<br>
+#endif<br>
+<br>
+#endif /* __BOOSTRAP_H__ */<br>
diff --git a/lib/Kconfig b/lib/Kconfig<br>
index db8a6ad..4578353 100644<br>
--- a/lib/Kconfig<br>
+++ b/lib/Kconfig<br>
@@ -52,4 +52,6 @@ config LIBMTD<br>
<br>
source lib/gui/Kconfig<br>
<br>
+source lib/bootstrap/Kconfig<br>
+<br>
endmenu<br>
diff --git a/lib/Makefile b/lib/Makefile<br>
index 85f4ec9..43f6ea3 100644<br>
--- a/lib/Makefile<br>
+++ b/lib/Makefile<br>
@@ -1,3 +1,4 @@<br>
+obj-$(CONFIG_BOOTSTRAP) += bootstrap/<br>
obj-y += ctype.o<br>
obj-y += rbtree.o<br>
obj-y += display_options.o<br>
diff --git a/lib/bootstrap/Kconfig b/lib/bootstrap/Kconfig<br>
new file mode 100644<br>
index 0000000..558da00<br>
--- /dev/null<br>
+++ b/lib/bootstrap/Kconfig<br>
@@ -0,0 +1,13 @@<br>
+menuconfig BOOTSTRAP<br>
+ bool "Library bootstrap routines "<br>
+ depends on SHELL_NONE<br>
+<br>
+if BOOTSTRAP<br>
+<br>
+config BOOTSTRAP_DEVFS<br>
+ bool "devfs support"<br>
+<br>
+config BOOTSTRAP_DISK<br>
+ bool "disk support"<br>
+<br>
+endif<br>
diff --git a/lib/bootstrap/Makefile b/lib/bootstrap/Makefile<br>
new file mode 100644<br>
index 0000000..cbaa49f<br>
--- /dev/null<br>
+++ b/lib/bootstrap/Makefile<br>
@@ -0,0 +1,3 @@<br>
+obj-y += common.o<br>
+obj-$(CONFIG_BOOTSTRAP_DEVFS) += devfs.o<br>
+obj-$(CONFIG_BOOTSTRAP_DISK) += disk.o<br>
diff --git a/lib/bootstrap/common.c b/lib/bootstrap/common.c<br>
new file mode 100644<br>
index 0000000..3652698<br>
--- /dev/null<br>
+++ b/lib/bootstrap/common.c<br>
@@ -0,0 +1,21 @@<br>
+/*<br>
+ * Copyright (C) 2011 Sascha Hauer, Pengutronix<br>
+ * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnio@jcrosoft.com">plagnio@jcrosoft.com</a>><br>
+ *<br>
+ * Under GPLv2<br>
+ */<br>
+<br>
+#include <common.h><br>
+#include <bootstrap.h><br>
+#include <filetype.h><br>
+<br>
+void bootstrap_boot(int (*func)(void), bool barebox)<br>
+{<br>
+ if (barebox && !is_barebox_head((void*)func))<br>
+ return;<br>
+<br>
+ shutdown_barebox();<br>
+ func();<br>
+<br>
+ while (1);<br>
+}<br>
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c<br>
new file mode 100644<br>
index 0000000..25d07c7<br>
--- /dev/null<br>
+++ b/lib/bootstrap/devfs.c<br>
@@ -0,0 +1,118 @@<br>
+/*<br>
+ * Copyright (C) 2011 Sascha Hauer, Pengutronix<br>
+ * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnio@jcrosoft.com">plagnio@jcrosoft.com</a>><br>
+ *<br>
+ * Under GPLv2<br>
+ */<br>
+<br>
+#include <common.h><br>
+#include <partition.h><br>
+#include <nand.h><br>
+#include <driver.h><br>
+#include <linux/mtd/mtd.h><br>
+#include <fcntl.h><br>
+#include <filetype.h><br>
+#include <sizes.h><br>
+#include <errno.h><br>
+#include <malloc.h><br>
+#include <bootstrap.h><br>
+<br>
+#if defined(CONFIG_ARM) || defined(CONFIG_MIPS)<br>
+#if defined(CONFIG_ARM)<br>
+#define BAREBOX_HEAD_SIZE ARM_HEAD_SIZE<br>
+#define BAREBOX_HEAD_SIZE_OFFSET ARM_HEAD_SIZE_OFFSET<br>
+#elif defined(CONFIG_MIPS)<br>
+#define BAREBOX_HEAD_SIZE MIPS_HEAD_SIZE<br>
+#define BAREBOX_HEAD_SIZE_OFFSET MIPS_HEAD_SIZE_OFFSET<br>
+#endif<br>
+<br>
+static void *read_image_head(const char *name)<br>
+{<br>
+ void *header = xmalloc(BAREBOX_HEAD_SIZE);<br>
+ struct cdev *cdev;<br>
+ int ret;<br>
+<br>
+ cdev = cdev_open(name, O_RDONLY);<br>
+ if (!cdev) {<br>
+ bootstrap_err("failed to open partition\n");<br>
+ return NULL;<br>
+ }<br>
+<br>
+ ret = cdev_read(cdev, header, BAREBOX_HEAD_SIZE, 0, 0);<br></blockquote><div>check on error here?<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ cdev_close(cdev);<br>
+<br>
+ if (ret != BAREBOX_HEAD_SIZE) {<br>
+ bootstrap_err("failed to read from partition\n");<br>
+ return NULL;<br>
+ }<br>
+<br>
+ return header;<br>
+}<br>
+<br>
+static unsigned int get_image_size(void *head)<br>
+{<br>
+ unsigned int ret = 0;<br>
+ unsigned int *psize = head + BAREBOX_HEAD_SIZE_OFFSET;<br>
+<br>
+ if (is_barebox_head(head))<br>
+ ret = *psize;<br>
+ debug("Detected barebox image size %u\n", ret);<br>
+<br>
+ return ret;<br>
+}<br>
+#else<br>
+static void *read_image_head(const char *name)<br>
+{<br>
+ return NULL;<br>
+}<br>
+<br>
+static unsigned int get_image_size(void *head)<br>
+{<br>
+ return 0;<br>
+}<br>
+#endif<br>
+<br>
+void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,<br>
+ int default_size, int max_size)<br>
+{<br>
+ int ret;<br>
+ int size = 0;<br>
+ void *to, *header;<br>
+ struct cdev *cdev;<br>
+ char *partname = "x";<br>
+<br>
+ devfs_add_partition(devname, offset, max_size, DEVFS_PARTITION_FIXED, partname);<br>
+ if (use_bb) {<br>
+ dev_add_bb_dev(partname, "bbx");<br>
+ partname = "bbx";<br>
+ }<br>
+<br>
+ header = read_image_head(partname);<br>
+ if (header) {<br>
+ size = get_image_size(header);<br>
+ if (!size)<br>
+ bootstrap_err("%s: failed to get image size\n", devname);<br>
+ }<br>
+<br>
+ if (!size) {<br>
+ size = default_size;<br>
+ bootstrap_err("%s: failed to detect barebox and it's image size so use %d\n",<br>
+ devname, size);<br>
+ }<br>
+<br>
+ to = xmalloc(size);<br></blockquote><div>check on null here?<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+ cdev = cdev_open(partname, O_RDONLY);<br>
+ if (!cdev) {<br>
+ bootstrap_err("%s: failed to open %s\n", devname, partname);<br>
+ return NULL;<br>
+ }<br>
+<br>
+ ret = cdev_read(cdev, to, size, 0, 0);<br>
+ if (ret != size) {<br>
+ bootstrap_err("%s: failed to read from %s\n", devname, partname);<br>
+ return NULL;<br>
+ }<br>
+<br>
+ return to;<br>
+}<br>
diff --git a/lib/bootstrap/disk.c b/lib/bootstrap/disk.c<br>
new file mode 100644<br>
index 0000000..fad8990<br>
--- /dev/null<br>
+++ b/lib/bootstrap/disk.c<br>
@@ -0,0 +1,37 @@<br>
+/*<br>
+ * Copyright (C) 2011 Sascha Hauer, Pengutronix<br>
+ * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnio@jcrosoft.com">plagnio@jcrosoft.com</a>><br>
+ *<br>
+ * Under GPLv2<br>
+ */<br>
+<br>
+#include <common.h><br>
+#include <fs.h><br>
+#include <fcntl.h><br>
+#include <sizes.h><br>
+#include <errno.h><br>
+#include <malloc.h><br>
+#include <bootstrap.h><br>
+<br>
+void* bootstrap_read_disk(char *dev)<br>
+{<br>
+ int ret;<br>
+ void *buf;<br>
+ int len;<br>
+ char *path = "/";<br>
+<br>
+ ret = mount(dev, "fat", path);<br>
+ if (ret) {<br>
+ bootstrap_err("mounting %s failed with %d\n", dev, ret);<br>
+ return NULL;<br>
+ }<br>
+<br>
+ buf = read_file("/barebox.bin", &len);<br></blockquote><div>Can be set to read_file("/barebox.bin", null);<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ if (!buf) {<br>
+ bootstrap_err("could not read barebox.bin from %s\n", dev);<br>
+ umount(path);<br>
+ return NULL;<br>
+ }<br>
+<br>
+ return buf;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.10.4<br>
<br>
<br>
_______________________________________________<br>
barebox mailing list<br>
<a href="mailto:barebox@lists.infradead.org">barebox@lists.infradead.org</a><br>
<a href="http://lists.infradead.org/mailman/listinfo/barebox" target="_blank">http://lists.infradead.org/mailman/listinfo/barebox</a><br>
</font></span></blockquote></div><br></div></div>