introduce common bootstrap code
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
345dd51467
commit
df132b9d78
|
@ -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, char *fstype);
|
||||||
|
#else
|
||||||
|
static inline void* bootstrap_read_disk(char *devname, char *fstype)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __BOOSTRAP_H__ */
|
|
@ -52,4 +52,6 @@ config LIBMTD
|
||||||
|
|
||||||
source lib/gui/Kconfig
|
source lib/gui/Kconfig
|
||||||
|
|
||||||
|
source lib/bootstrap/Kconfig
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
obj-$(CONFIG_BOOTSTRAP) += bootstrap/
|
||||||
obj-y += ctype.o
|
obj-y += ctype.o
|
||||||
obj-y += rbtree.o
|
obj-y += rbtree.o
|
||||||
obj-y += display_options.o
|
obj-y += display_options.o
|
||||||
|
|
|
@ -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
|
|
@ -0,0 +1,3 @@
|
||||||
|
obj-y += common.o
|
||||||
|
obj-$(CONFIG_BOOTSTRAP_DEVFS) += devfs.o
|
||||||
|
obj-$(CONFIG_BOOTSTRAP_DISK) += disk.o
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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 (!func)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (barebox && !is_barebox_head((void*)func))
|
||||||
|
return;
|
||||||
|
|
||||||
|
shutdown_barebox();
|
||||||
|
func();
|
||||||
|
|
||||||
|
while (1);
|
||||||
|
}
|
|
@ -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 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);
|
||||||
|
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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -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, char *fstype)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
void *buf;
|
||||||
|
int len;
|
||||||
|
char *path = "/";
|
||||||
|
|
||||||
|
ret = mount(dev, fstype, path);
|
||||||
|
if (ret) {
|
||||||
|
bootstrap_err("mounting %s failed with %d\n", dev, ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = read_file("/barebox.bin", &len);
|
||||||
|
if (!buf) {
|
||||||
|
bootstrap_err("could not read barebox.bin from %s\n", dev);
|
||||||
|
umount(path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
Loading…
Reference in New Issue