9
0
Fork 0

sandbox: do not register device before barebox is started

This will crash when use registered bus with device registered to it.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2012-09-20 07:36:42 +02:00 committed by Sascha Hauer
parent 48842b9b25
commit fc5caa43a8
5 changed files with 55 additions and 3 deletions

View File

@ -2,5 +2,6 @@ obj-y += board.o
obj-y += clock.o
obj-y += hostfile.o
obj-y += console.o
obj-y += devices.o
extra-y += barebox.lds

View File

@ -47,6 +47,6 @@ int barebox_register_console(char *name, int stdinfd, int stdoutfd)
data->stdoutfd = stdoutfd;
data->stdinfd = stdinfd;
return register_device(dev);
return sandbox_add_device(dev);
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
*
* Under GPLv2 only
*/
#include <common.h>
#include <driver.h>
#include <init.h>
static LIST_HEAD(sandbox_device_list);
int sandbox_add_device(struct device_d *dev)
{
list_add(&dev->list, &sandbox_device_list);
return 0;
}
static int sandbox_device_init(void)
{
struct device_d *dev, *tmp;
list_for_each_entry_safe(dev, tmp, &sandbox_device_list, list) {
/* reset the list_head before registering for real */
dev->list.prev = NULL;
dev->list.next = NULL;
register_device(dev);
}
return 0;
}
postcore_initcall(sandbox_device_init);

View File

@ -102,7 +102,22 @@ device_initcall(hf_init);
int barebox_register_filedev(struct hf_platform_data *hf)
{
return !add_generic_device("hostfile", DEVICE_ID_DYNAMIC, NULL, hf->base, hf->size,
IORESOURCE_MEM, hf);
struct device_d *dev;
struct resource *res;
dev = xzalloc(sizeof(*dev));
strcpy(dev->name, "hostfile");
dev->id = DEVICE_ID_DYNAMIC;
dev->platform_data = hf;
res = xzalloc(sizeof(struct resource));
res[0].start = hf->base;
res[0].end = hf->base + hf->size - 1;
res[0].flags = IORESOURCE_MEM;
dev->resource = res;
dev->num_resources = 1;
return sandbox_add_device(dev);
}

View File

@ -1,6 +1,9 @@
#ifndef __ASM_ARCH_LINUX_H
#define __ASM_ARCH_LINUX_H
struct device_d;
int sandbox_add_device(struct device_d *dev);
int linux_register_device(const char *name, void *start, void *end);
int tap_alloc(char *dev);
uint64_t linux_get_time(void);