summaryrefslogtreecommitdiffstats
path: root/arch/sandbox
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-09-12 07:53:27 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-09-12 07:53:27 +0200
commitc4f5b9e72b190e294c9fb6654294cbea8556f633 (patch)
treed61329a62876d1c1cb9099f81bf0beab5a713efa /arch/sandbox
parente5fc57847e7a68ad4a662e9799afb103211e4073 (diff)
parent9feb86e11d491981c0848a8923d0407d2f9abf0d (diff)
downloadbarebox-c4f5b9e72b190e294c9fb6654294cbea8556f633.tar.gz
barebox-c4f5b9e72b190e294c9fb6654294cbea8556f633.tar.xz
Merge branch 'for-next/sandbox'
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/Kconfig3
-rw-r--r--arch/sandbox/Makefile6
-rw-r--r--arch/sandbox/board/Makefile1
-rw-r--r--arch/sandbox/board/board.c7
-rw-r--r--arch/sandbox/board/dev-random.c24
-rw-r--r--arch/sandbox/board/devices.c1
-rw-r--r--arch/sandbox/board/hostfile.c16
-rw-r--r--arch/sandbox/dts/sandbox-state-example.dtsi50
-rw-r--r--arch/sandbox/mach-sandbox/include/mach/linux.h8
-rw-r--r--arch/sandbox/os/common.c5
10 files changed, 112 insertions, 9 deletions
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index c20a9171a7..6ec71a99e5 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -15,9 +15,6 @@ config LINUX
default y
select GENERIC_FIND_NEXT_BIT
-config ARCH_LINUX
- bool
-
config SANDBOX_UNWIND
bool
default y
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index 52ad4850cb..b127560a2b 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -1,6 +1,7 @@
KBUILD_DEFCONFIG := sandbox_defconfig
-CPPFLAGS += -D__SANDBOX__ -fno-strict-aliasing
+CPPFLAGS += -D__SANDBOX__ -fno-strict-aliasing -fvisibility=hidden
+
machine-y := sandbox
@@ -23,7 +24,8 @@ CFLAGS += -Dmalloc=barebox_malloc -Dcalloc=barebox_calloc \
-Dglob=barebox_glob -Dglobfree=barebox_globfree \
-Dioctl=barebox_ioctl -Dfstat=barebox_fstat \
-Dopendir=barebox_opendir -Dreaddir=barebox_readdir \
- -Dclosedir=barebox_closedir
+ -Dclosedir=barebox_closedir \
+ -Doptarg=barebox_optarg -Doptind=barebox_optind
machdirs := $(patsubst %,arch/sandbox/mach-%/,$(machine-y))
diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index b6c271c858..26f6cb1922 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -5,5 +5,6 @@ obj-y += console.o
obj-y += devices.o
obj-y += dtb.o
obj-y += poweroff.o
+obj-y += dev-random.o
extra-y += barebox.lds
diff --git a/arch/sandbox/board/board.c b/arch/sandbox/board/board.c
index 1f6392d15e..ad2bc910c3 100644
--- a/arch/sandbox/board/board.c
+++ b/arch/sandbox/board/board.c
@@ -42,6 +42,11 @@ static struct device_d sdl_device = {
.platform_data = &mode,
};
+static struct device_d devrandom_device = {
+ .id = DEVICE_ID_DYNAMIC,
+ .name = "devrandom",
+};
+
static int devices_init(void)
{
platform_device_register(&tap_device);
@@ -54,6 +59,8 @@ static int devices_init(void)
platform_device_register(&sdl_device);
+ platform_device_register(&devrandom_device);
+
return 0;
}
diff --git a/arch/sandbox/board/dev-random.c b/arch/sandbox/board/dev-random.c
new file mode 100644
index 0000000000..f65e5ef6e5
--- /dev/null
+++ b/arch/sandbox/board/dev-random.c
@@ -0,0 +1,24 @@
+#include <common.h>
+#include <mach/linux.h>
+
+devrandom_t *devrandom_init(void) {
+ devrandom_t *fds = xzalloc(sizeof(*fds));
+
+ fds->randomfd = linux_open("/dev/random", false);
+ if (fds->randomfd < 0)
+ return ERR_PTR(-EPERM);
+
+ fds->urandomfd = linux_open("/dev/urandom", false);
+ if (fds->urandomfd < 0)
+ return ERR_PTR(-EPERM);
+
+ return fds;
+}
+
+int devrandom_read(devrandom_t *devrandom, void *buf, size_t len, int wait)
+{
+ if (wait)
+ return linux_read(devrandom->randomfd, buf, len);
+
+ return linux_read(devrandom->urandomfd, buf, len);
+}
diff --git a/arch/sandbox/board/devices.c b/arch/sandbox/board/devices.c
index 242a0d718e..72e62552a3 100644
--- a/arch/sandbox/board/devices.c
+++ b/arch/sandbox/board/devices.c
@@ -8,6 +8,7 @@
#include <driver.h>
#include <mach/linux.h>
#include <init.h>
+#include <mach/linux.h>
static LIST_HEAD(sandbox_device_list);
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 745f078d1a..e5a7580d07 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -84,15 +84,16 @@ static int hf_probe(struct device_d *dev)
if (!dev->device_node)
return -ENODEV;
- err = of_property_read_u32(dev->device_node, "barebox,fd", &priv->fd);
- if (err)
- return err;
+ of_property_read_u32(dev->device_node, "barebox,fd", &priv->fd);
err = of_property_read_string(dev->device_node, "barebox,filename",
&priv->filename);
if (err)
return err;
+ if (!priv->fd)
+ priv->fd = linux_open(priv->filename, true);
+
priv->cdev.name = dev->device_node->name;
priv->cdev.dev = dev;
priv->cdev.ops = &hf_fops;
@@ -101,7 +102,14 @@ static int hf_probe(struct device_d *dev)
dev->info = hf_info;
dev->priv = priv;
- return devfs_create(&priv->cdev);
+ err = devfs_create(&priv->cdev);
+ if (err)
+ return err;
+
+ of_parse_partitions(&priv->cdev, dev->device_node);
+ of_partitions_register_fixup(&priv->cdev);
+
+ return 0;
}
static __maybe_unused struct of_device_id hostfile_dt_ids[] = {
diff --git a/arch/sandbox/dts/sandbox-state-example.dtsi b/arch/sandbox/dts/sandbox-state-example.dtsi
new file mode 100644
index 0000000000..fc17bd0788
--- /dev/null
+++ b/arch/sandbox/dts/sandbox-state-example.dtsi
@@ -0,0 +1,50 @@
+/ {
+ aliases {
+ state = &state;
+ };
+
+ disk {
+ compatible = "barebox,hostfile";
+ barebox,filename = "disk";
+ reg = <0x0 0x0 0x100000>;
+
+ partitions {
+ compatible = "fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ hostfile_state: state@0 {
+ reg = <0x0 0x1000>;
+ label = "state";
+ };
+ };
+ };
+
+ state: state {
+ magic = <0xaa3b86a6>;
+ compatible = "barebox,state";
+ backend-type = "raw";
+ backend = <&hostfile_state>;
+ backend-storage-type = "direct";
+ backend-stridesize = <64>;
+
+ #address-cells = <1>;
+ #size-cells = <1>;
+ vars {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ x {
+ reg = <0x0 0x4>;
+ type = "uint32";
+ default = <1>;
+ };
+
+ y {
+ reg = <0x4 0x4>;
+ type = "uint32";
+ default = <3>;
+ };
+ };
+ };
+};
diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h b/arch/sandbox/mach-sandbox/include/mach/linux.h
index 7d0ed55735..1e64d41c6a 100644
--- a/arch/sandbox/mach-sandbox/include/mach/linux.h
+++ b/arch/sandbox/mach-sandbox/include/mach/linux.h
@@ -10,6 +10,7 @@ struct fb_bitfield;
int linux_register_device(const char *name, void *start, void *end);
int tap_alloc(const char *dev);
uint64_t linux_get_time(void);
+int linux_open(const char *filename, int readwrite);
int linux_read(int fd, void *buf, size_t count);
int linux_read_nonblock(int fd, void *buf, size_t count);
ssize_t linux_write(int fd, const void *buf, size_t count);
@@ -50,4 +51,11 @@ void barebox_libftdi1_gpio_set_value(struct ft2232_bitbang *ftbb,
int barebox_libftdi1_update(struct ft2232_bitbang *ftbb);
void barebox_libftdi1_close(void);
+typedef struct {
+ int randomfd;
+ int urandomfd;
+} devrandom_t;
+devrandom_t *devrandom_init(void);
+int devrandom_read(devrandom_t *devrandom, void *buf, size_t len, int wait);
+
#endif /* __ASM_ARCH_LINUX_H */
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index a7ea8f2d3b..86118822a1 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -121,6 +121,11 @@ void __attribute__((noreturn)) linux_exit(void)
exit(0);
}
+int linux_open(const char *filename, int readwrite)
+{
+ return open(filename, readwrite ? O_RDWR : O_RDONLY);
+}
+
int linux_read(int fd, void *buf, size_t count)
{
ssize_t ret;