summaryrefslogtreecommitdiffstats
path: root/arch/sandbox
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/Kconfig23
-rw-r--r--arch/sandbox/Makefile12
-rw-r--r--arch/sandbox/board/.gitignore2
-rw-r--r--arch/sandbox/board/Makefile4
-rw-r--r--arch/sandbox/board/barebox.lds.S4
-rw-r--r--arch/sandbox/board/board.c22
-rw-r--r--arch/sandbox/board/clock.c1
-rw-r--r--arch/sandbox/board/console.c4
-rw-r--r--arch/sandbox/board/dev-random.c2
-rw-r--r--arch/sandbox/board/devices.c5
-rw-r--r--arch/sandbox/board/dtb.c4
-rw-r--r--arch/sandbox/board/env/init/state13
-rw-r--r--arch/sandbox/board/hostfile.c94
-rw-r--r--arch/sandbox/board/led.c9
-rw-r--r--arch/sandbox/board/power.c57
-rw-r--r--arch/sandbox/board/stickypage.S29
-rw-r--r--arch/sandbox/board/watchdog.c42
-rw-r--r--arch/sandbox/configs/hosttools_defconfig1
-rw-r--r--arch/sandbox/configs/sandbox_defconfig6
-rw-r--r--arch/sandbox/configs/targettools_defconfig10
-rw-r--r--arch/sandbox/dts/.gitignore1
-rw-r--r--arch/sandbox/dts/Makefile4
-rw-r--r--arch/sandbox/dts/sandbox.dts41
-rw-r--r--arch/sandbox/include/asm/barebox.lds.h3
-rw-r--r--arch/sandbox/include/asm/bitsperlong.h2
-rw-r--r--arch/sandbox/include/asm/byteorder.h2
-rw-r--r--arch/sandbox/include/asm/common.h4
-rw-r--r--arch/sandbox/include/asm/debug_ll.h16
-rw-r--r--arch/sandbox/include/asm/dma.h23
-rw-r--r--arch/sandbox/include/asm/elf.h2
-rw-r--r--arch/sandbox/include/asm/io.h13
-rw-r--r--arch/sandbox/include/asm/linkage.h8
-rw-r--r--arch/sandbox/include/asm/mmu.h2
-rw-r--r--arch/sandbox/include/asm/posix_types.h2
-rw-r--r--arch/sandbox/include/asm/reset_source.h16
-rw-r--r--arch/sandbox/include/asm/sections.h2
-rw-r--r--arch/sandbox/include/asm/string.h2
-rw-r--r--arch/sandbox/include/asm/swab.h2
-rw-r--r--arch/sandbox/include/asm/types.h2
-rw-r--r--arch/sandbox/include/asm/unaligned.h2
-rw-r--r--arch/sandbox/include/asm/word-at-a-time.h2
-rw-r--r--arch/sandbox/lib/Makefile2
-rw-r--r--arch/sandbox/lib/asm-offsets.c2
-rw-r--r--arch/sandbox/mach-sandbox/include/mach/hostfile.h2
-rw-r--r--arch/sandbox/mach-sandbox/include/mach/linux.h7
-rw-r--r--arch/sandbox/os/Makefile6
-rw-r--r--arch/sandbox/os/common.c138
-rw-r--r--arch/sandbox/os/libc_malloc.c28
48 files changed, 461 insertions, 219 deletions
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index 01078bca97..3419b6e4f6 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
source "scripts/Kconfig.include"
config SANDBOX
@@ -13,19 +15,17 @@ config SANDBOX
select PARTITION_DISK
select ARCH_HAS_STACK_DUMP if ASAN
select GENERIC_FIND_NEXT_BIT
- select HAS_ARCH_SJLJ
+ select ARCH_HAS_SJLJ
+ select ARCH_HAS_CTRLC
+ select HAS_DEBUG_LL
+ select ARCH_DMA_DEFAULT_COHERENT
default y
config ARCH_TEXT_BASE
hex
default 0x00000000
-config SANDBOX_REEXEC
- prompt "exec(2) reset handler"
- def_bool y
- help
- The normal reset handler hangs barebox. On Linux, barebox
- instead can exec itself to simulate a reset.
+menu "Sandbox specific settings"
config PHYS_ADDR_T_64BIT
bool
@@ -49,5 +49,14 @@ config 32BIT
config SANDBOX_LINUX_I386
bool "32-bit x86 barebox" if CC_HAS_LINUX_I386_SUPPORT
+config SANDBOX_REEXEC
+ prompt "exec(2) reset handler"
+ def_bool y
+ help
+ The normal reset handler hangs barebox. On Linux, barebox
+ instead can exec itself to simulate a reset.
+
config SDL
bool
+
+endmenu
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index 5fc7e227be..c2906c0b1c 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
KBUILD_DEFCONFIG := sandbox_defconfig
KBUILD_CPPFLAGS += -D__SANDBOX__ -fno-strict-aliasing -fvisibility=hidden
@@ -28,7 +30,9 @@ KBUILD_CFLAGS += -Dmalloc=barebox_malloc -Dcalloc=barebox_calloc \
-Dopendir=barebox_opendir -Dreaddir=barebox_readdir \
-Dclosedir=barebox_closedir -Dreadlink=barebox_readlink \
-Doptarg=barebox_optarg -Doptind=barebox_optind \
- -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+ -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp \
+ -Dmkdir=barebox_mkdir -Ddirname=barebox_dirname \
+ -Dremove=barebox_remove -Dputchar=barebox_putchar
machdirs := $(patsubst %,arch/sandbox/mach-%/,$(machine-y))
@@ -39,11 +43,11 @@ archprepare: maketools
PHONY += maketools
ifeq ($(CONFIG_SDL),y)
-SDL_LIBS := $(shell pkg-config sdl2 --libs)
+SDL_LIBS := $(shell $(PKG_CONFIG) sdl2 --libs)
endif
ifeq ($(CONFIG_GPIO_LIBFTDI1),y)
-FTDI1_LIBS := $(shell pkg-config libftdi1 --libs)
+FTDI1_LIBS := $(shell $(PKG_CONFIG) libftdi1 --libs)
endif
ifeq ($(CONFIG_ASAN),y)
@@ -72,6 +76,8 @@ cmd_barebox__ = $(CC) -o $@ $(BAREBOX_LDFLAGS)
common-y += $(BOARD) arch/sandbox/os/ arch/sandbox/lib/
+KBUILD_IMAGE := barebox
+
common-$(CONFIG_OFTREE) += arch/sandbox/dts/
CLEAN_FILES += $(BOARD)/barebox.lds
diff --git a/arch/sandbox/board/.gitignore b/arch/sandbox/board/.gitignore
index d1165788c9..03987a7009 100644
--- a/arch/sandbox/board/.gitignore
+++ b/arch/sandbox/board/.gitignore
@@ -1 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
barebox.lds
diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index ffb1dbc21e..b4bab02163 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
obj-y += board.o
obj-y += clock.o
obj-y += hostfile.o
@@ -10,3 +12,5 @@ obj-y += watchdog.o
obj-$(CONFIG_LED) += led.o
extra-y += barebox.lds
+
+obj-y += stickypage.o
diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index 7a5a8eb1e7..ab2801f3d2 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -1,4 +1,6 @@
-#include <asm-generic/barebox.lds.h>
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm/barebox.lds.h>
SECTIONS
{
diff --git a/arch/sandbox/board/board.c b/arch/sandbox/board/board.c
index 45b7c7deff..c8d1c99897 100644
--- a/arch/sandbox/board/board.c
+++ b/arch/sandbox/board/board.c
@@ -20,6 +20,7 @@
#include <mach/linux.h>
#include <init.h>
#include <errno.h>
+#include <deep-probe.h>
#include <fb.h>
struct fb_videomode mode = {
@@ -28,23 +29,23 @@ struct fb_videomode mode = {
.yres = 480,
};
-static struct device_d tap_device = {
+static struct device tap_device = {
.id = DEVICE_ID_DYNAMIC,
.name = "tap",
};
-static struct device_d sdl_device = {
+static struct device sdl_device = {
.id = DEVICE_ID_DYNAMIC,
.name = "sdlfb",
.platform_data = &mode,
};
-static struct device_d devrandom_device = {
+static struct device devrandom_device = {
.id = DEVICE_ID_DYNAMIC,
.name = "devrandom",
};
-static int devices_init(void)
+static int devices_init(struct device *dev)
{
platform_device_register(&tap_device);
@@ -61,4 +62,15 @@ static int devices_init(void)
return 0;
}
-device_initcall(devices_init);
+static struct of_device_id sandbox_dt_ids[] = {
+ { .compatible = "barebox,sandbox" },
+ { /* sentinel */ }
+};
+BAREBOX_DEEP_PROBE_ENABLE(sandbox_dt_ids);
+
+static struct driver sandbox_board_drv = {
+ .name = "sandbox-board",
+ .of_compatible = sandbox_dt_ids,
+ .probe = devices_init,
+};
+device_platform_driver(sandbox_board_drv);
diff --git a/arch/sandbox/board/clock.c b/arch/sandbox/board/clock.c
index b005e71633..1787fb5786 100644
--- a/arch/sandbox/board/clock.c
+++ b/arch/sandbox/board/clock.c
@@ -28,6 +28,7 @@ static struct clocksource cs = {
.read = linux_clocksource_read,
.mask = CLOCKSOURCE_MASK(32),
.shift = 10,
+ .priority = 80,
};
static int clocksource_init (void)
diff --git a/arch/sandbox/board/console.c b/arch/sandbox/board/console.c
index cea62d57b1..274ef67aef 100644
--- a/arch/sandbox/board/console.c
+++ b/arch/sandbox/board/console.c
@@ -21,10 +21,10 @@
int barebox_register_console(int stdinfd, int stdoutfd)
{
- struct device_d *dev;
+ struct device *dev;
struct linux_console_data *data;
- dev = xzalloc(sizeof(struct device_d) + sizeof(struct linux_console_data));
+ dev = xzalloc(sizeof(struct device) + sizeof(struct linux_console_data));
data = (struct linux_console_data *)(dev + 1);
diff --git a/arch/sandbox/board/dev-random.c b/arch/sandbox/board/dev-random.c
index 60295e9fce..b62e8cc0d7 100644
--- a/arch/sandbox/board/dev-random.c
+++ b/arch/sandbox/board/dev-random.c
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
#include <common.h>
#include <mach/linux.h>
diff --git a/arch/sandbox/board/devices.c b/arch/sandbox/board/devices.c
index 26152a8b90..ecd24e9207 100644
--- a/arch/sandbox/board/devices.c
+++ b/arch/sandbox/board/devices.c
@@ -6,7 +6,6 @@
#include <common.h>
#include <driver.h>
-#include <mach/linux.h>
#include <init.h>
#include <mach/linux.h>
#include <asm/io.h>
@@ -15,7 +14,7 @@ unsigned char __pci_iobase[IO_SPACE_LIMIT];
static LIST_HEAD(sandbox_device_list);
-int sandbox_add_device(struct device_d *dev)
+int sandbox_add_device(struct device *dev)
{
list_add(&dev->list, &sandbox_device_list);
@@ -24,7 +23,7 @@ int sandbox_add_device(struct device_d *dev)
static int sandbox_device_init(void)
{
- struct device_d *dev, *tmp;
+ struct device *dev, *tmp;
list_for_each_entry_safe(dev, tmp, &sandbox_device_list, list) {
/* reset the list_head before registering for real */
diff --git a/arch/sandbox/board/dtb.c b/arch/sandbox/board/dtb.c
index 4a8cbfb26f..98d2e774b8 100644
--- a/arch/sandbox/board/dtb.c
+++ b/arch/sandbox/board/dtb.c
@@ -39,8 +39,6 @@ static int of_sandbox_init(void)
if (!dtb)
dtb = __dtb_sandbox_start;
- barebox_register_fdt(dtb);
-
- return 0;
+ return barebox_register_fdt(dtb);
}
core_initcall(of_sandbox_init);
diff --git a/arch/sandbox/board/env/init/state b/arch/sandbox/board/env/init/state
deleted file mode 100644
index b8a2b42a53..0000000000
--- a/arch/sandbox/board/env/init/state
+++ /dev/null
@@ -1,13 +0,0 @@
-if [ "x$state.dirty" != "x1" -o $global.system.reset != "POR" ]; then
- exit
-fi
-
-source /env/data/ansi-colors
-
-echo -e $CYAN
-echo "*******************************************************"
-echo "*** Inconsistent barebox state buckets detected ***"
-echo "*** This is normal for a first boot ***"
-echo "*** barebox will repair them on next poweroff/reset ***"
-echo "*******************************************************"
-echo -e -n $NC
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 4fdf2b317d..7afad95b6d 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -24,10 +24,9 @@
#include <errno.h>
#include <linux/err.h>
#include <mach/hostfile.h>
+#include <featctrl.h>
#include <xfuncs.h>
-#include <linux/err.h>
-
struct hf_priv {
union {
struct block_device blk;
@@ -35,6 +34,7 @@ struct hf_priv {
};
const char *filename;
int fd;
+ struct feature_controller feat;
};
static ssize_t hf_read(struct hf_priv *priv, void *buf, size_t count, loff_t offset, ulong flags)
@@ -91,25 +91,48 @@ static struct block_device_ops hf_blk_ops = {
.write = hf_blk_write,
};
-static void hf_info(struct device_d *dev)
+static void hf_info(struct device *dev)
{
struct hf_priv *priv = dev->priv;
printf("file: %s\n", priv->filename);
}
-static int hf_probe(struct device_d *dev)
+static int hostfile_feat_check(struct feature_controller *feat, int idx)
+{
+ struct hf_priv *priv = container_of(feat, struct hf_priv, feat);
+
+ return priv->fd >= 0 ? FEATCTRL_OKAY : FEATCTRL_GATED;
+}
+
+static int hf_probe(struct device *dev)
{
- struct device_node *np = dev->device_node;
+ struct device_node *np = dev->of_node;
struct hf_priv *priv = xzalloc(sizeof(*priv));
struct cdev *cdev;
- bool is_blockdev;
+ bool is_featctrl = false, is_blockdev;
u64 reg[2];
int err;
if (!np)
return -ENODEV;
+ dev->priv = priv;
+ priv->fd = -1;
+
+ if (IS_ENABLED(CONFIG_FEATURE_CONTROLLER) &&
+ of_property_read_bool(np, "barebox,feature-controller")) {
+ priv->feat.dev = dev;
+ priv->feat.check = hostfile_feat_check;
+
+ err = feature_controller_register(&priv->feat);
+ if (err)
+ return err;
+
+ is_featctrl = true;
+ }
+
+
err = of_property_read_u64_array(np, "reg", reg, ARRAY_SIZE(reg));
if (err)
return err;
@@ -122,16 +145,15 @@ static int hf_probe(struct device_d *dev)
return err;
if (priv->fd < 0)
- return priv->fd;
+ return is_featctrl ? 0 : priv->fd;
dev->info = hf_info;
- dev->priv = priv;
is_blockdev = of_property_read_bool(np, "barebox,blockdev");
cdev = is_blockdev ? &priv->blk.cdev : &priv->cdev;
- cdev->device_node = np;
+ cdev_set_of_node(cdev, np);
if (is_blockdev) {
cdev->name = np->name;
@@ -139,15 +161,12 @@ static int hf_probe(struct device_d *dev)
priv->blk.ops = &hf_blk_ops;
priv->blk.blockbits = SECTOR_SHIFT;
priv->blk.num_blocks = reg[1] / SECTOR_SIZE;
+ priv->blk.type = BLK_TYPE_VIRTUAL;
err = blockdevice_register(&priv->blk);
if (err)
return err;
- err = parse_partition_table(&priv->blk);
- if (err)
- dev_warn(dev, "No partition table found\n");
-
dev_info(dev, "registered as block device\n");
} else {
cdev->name = np->name;
@@ -166,7 +185,7 @@ static int hf_probe(struct device_d *dev)
of_parse_partitions(cdev, np);
of_partitions_register_fixup(cdev);
- return 0;
+ return of_platform_populate(np, NULL, dev);
}
static __maybe_unused struct of_device_id hostfile_dt_ids[] = {
@@ -176,8 +195,9 @@ static __maybe_unused struct of_device_id hostfile_dt_ids[] = {
/* sentinel */
}
};
+MODULE_DEVICE_TABLE(of, hostfile_dt_ids);
-static struct driver_d hf_drv = {
+static struct driver hf_drv = {
.name = "hostfile",
.of_compatible = DRV_OF_COMPAT(hostfile_dt_ids),
.probe = hf_probe,
@@ -229,15 +249,30 @@ static int of_hostfile_map_fixup(struct device_node *root, void *ctx)
struct device_node *node;
int ret;
- for_each_compatible_node_from(node, root, NULL, hostfile_dt_ids->compatible) {
+ for_each_compatible_node_from(node, root, NULL, "barebox,stickypage") {
+ char *filename;
+
+ filename = linux_get_stickypage_path();
+ if (!filename) {
+ pr_err("error allocating stickypage\n");
+ continue;
+ }
+
+ of_property_write_string(node, "barebox,filename", filename);
+ of_property_write_string(node, "compatible", "barebox,hostfile");
+ }
+
+ for_each_compatible_node_from(node, root, NULL, "barebox,hostfile") {
struct hf_info hf = {};
uint64_t reg[2] = {};
- bool no_filename;
hf.devname = node->name;
ret = of_property_read_string(node, "barebox,filename", &hf.filename);
- no_filename = ret;
+ if (ret) {
+ pr_err("skipping nameless hostfile %s\n", hf.devname);
+ continue;
+ }
hf.is_blockdev = of_property_read_bool(node, "barebox,blockdev");
hf.is_cdev = of_property_read_bool(node, "barebox,cdev");
@@ -250,29 +285,14 @@ static int of_hostfile_map_fixup(struct device_node *root, void *ctx)
ret = linux_open_hostfile(&hf);
if (ret)
- goto out;
+ continue;
reg[0] = hf.base;
reg[1] = hf.size;
- ret = of_property_write_u64_array(node, "reg", reg, ARRAY_SIZE(reg));
- if (ret)
- goto out;
-
- ret = of_property_write_bool(node, "barebox,blockdev", hf.is_blockdev);
- if (ret)
- goto out;
-
- if (no_filename) {
- ret = of_property_write_string(node, "barebox,filename", hf.filename);
- if (ret)
- goto out;
- }
-
- ret = of_property_write_u32(node, "barebox,fd", hf.fd);
-out:
- if (ret)
- pr_err("error fixing up %s: %pe\n", hf.devname, ERR_PTR(ret));
+ of_property_write_u64_array(node, "reg", reg, ARRAY_SIZE(reg));
+ of_property_write_bool(node, "barebox,blockdev", hf.is_blockdev);
+ of_property_write_u32(node, "barebox,fd", hf.fd);
}
return 0;
diff --git a/arch/sandbox/board/led.c b/arch/sandbox/board/led.c
index b7ab81112b..ced7e82f99 100644
--- a/arch/sandbox/board/led.c
+++ b/arch/sandbox/board/led.c
@@ -26,9 +26,9 @@ static void sandbox_led_set(struct led *led, unsigned int brightness)
sandbox_led.active = true;
}
-static int sandbox_led_of_probe(struct device_d *dev)
+static int sandbox_led_of_probe(struct device *dev)
{
- struct device_node *np = dev->device_node;
+ struct device_node *np = dev->of_node;
int ret;
if (sandbox_led.led.set)
@@ -47,7 +47,7 @@ static int sandbox_led_of_probe(struct device_d *dev)
return 0;
}
-static void sandbox_led_of_remove(struct device_d *dev)
+static void sandbox_led_of_remove(struct device *dev)
{
if (sandbox_led.active)
sandbox_led_set(NULL, 0);
@@ -57,8 +57,9 @@ static struct of_device_id sandbox_led_of_ids[] = {
{ .compatible = "barebox,sandbox-led", },
{ }
};
+MODULE_DEVICE_TABLE(of, sandbox_led_of_ids);
-static struct driver_d sandbox_led_of_driver = {
+static struct driver sandbox_led_of_driver = {
.name = "sandbox-led",
.probe = sandbox_led_of_probe,
.remove = sandbox_led_of_remove,
diff --git a/arch/sandbox/board/power.c b/arch/sandbox/board/power.c
index 3cc9447958..8300c589c7 100644
--- a/arch/sandbox/board/power.c
+++ b/arch/sandbox/board/power.c
@@ -1,19 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
#include <common.h>
#include <driver.h>
#include <poweroff.h>
#include <restart.h>
#include <mach/linux.h>
-#include <reset_source.h>
-#include <mfd/syscon.h>
+#include <asm/reset_source.h>
+#include <linux/nvmem-consumer.h>
struct sandbox_power {
struct restart_handler rst_hang, rst_reexec;
- struct regmap *src;
- u32 src_offset;
+ struct poweroff_handler poweroff;
+ struct nvmem_cell *reset_source_cell;
};
static void sandbox_poweroff(struct poweroff_handler *poweroff)
{
+ struct sandbox_power *power = container_of(poweroff, struct sandbox_power, poweroff);
+
+ sandbox_save_reset_source(power->reset_source_cell, RESET_POR);
+
linux_exit();
}
@@ -25,17 +31,24 @@ static void sandbox_rst_hang(struct restart_handler *rst)
static void sandbox_rst_reexec(struct restart_handler *rst)
{
struct sandbox_power *power = container_of(rst, struct sandbox_power, rst_reexec);
- regmap_update_bits(power->src, power->src_offset, 0xff, RESET_RST);
+
+ sandbox_save_reset_source(power->reset_source_cell, RESET_RST);
+
linux_reexec();
}
-static int sandbox_power_probe(struct device_d *dev)
+static int sandbox_power_probe(struct device *dev)
{
struct sandbox_power *power = xzalloc(sizeof(*power));
- unsigned int rst;
- int ret;
+ size_t len;
+ u8 *rst;
+
+ power->poweroff = (struct poweroff_handler) {
+ .name = "exit",
+ .poweroff = sandbox_poweroff
+ };
- poweroff_handler_register_fn(sandbox_poweroff);
+ poweroff_handler_register(&power->poweroff);
power->rst_hang = (struct restart_handler) {
.name = "hang",
@@ -52,20 +65,23 @@ static int sandbox_power_probe(struct device_d *dev)
if (IS_ENABLED(CONFIG_SANDBOX_REEXEC))
restart_handler_register(&power->rst_reexec);
- power->src = syscon_regmap_lookup_by_phandle(dev->device_node, "barebox,reset-source");
- if (IS_ERR(power->src))
+ power->reset_source_cell = of_nvmem_cell_get(dev->of_node,
+ "reset-source");
+ if (IS_ERR(power->reset_source_cell)) {
+ if (PTR_ERR(power->reset_source_cell) != -EPROBE_DEFER)
+ dev_warn(dev, "No reset source info available: %pe\n",
+ power->reset_source_cell);
+ power->reset_source_cell = NULL;
return 0;
+ }
- ret = of_property_read_u32_index(dev->device_node, "barebox,reset-source", 1,
- &power->src_offset);
- if (ret)
- return 0;
+ rst = nvmem_cell_read(power->reset_source_cell, &len);
+ if (!IS_ERR(rst)) {
+ reset_source_set_prinst(*rst, RESET_SOURCE_DEFAULT_PRIORITY, 0);
- ret = regmap_read(power->src, power->src_offset, &rst);
- if (ret == 0 && rst == 0)
- rst = RESET_POR;
+ free(rst);
+ }
- reset_source_set_prinst(rst, RESET_SOURCE_DEFAULT_PRIORITY, 0);
return 0;
}
@@ -73,8 +89,9 @@ static __maybe_unused struct of_device_id sandbox_power_dt_ids[] = {
{ .compatible = "barebox,sandbox-power" },
{ /* sentinel */ }
};
+MODULE_DEVICE_TABLE(of, sandbox_power_dt_ids);
-static struct driver_d sandbox_power_drv = {
+static struct driver sandbox_power_drv = {
.name = "sandbox-power",
.of_compatible = sandbox_power_dt_ids,
.probe = sandbox_power_probe,
diff --git a/arch/sandbox/board/stickypage.S b/arch/sandbox/board/stickypage.S
new file mode 100644
index 0000000000..1d3861c373
--- /dev/null
+++ b/arch/sandbox/board/stickypage.S
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+.section .note.GNU-stack,"",%progbits
+.section .rodata.stickypage,"a"
+
+.globl stickypage;
+stickypage:
+
+/* nvmem */ .org 0x300
+.byte 0x01
+
+/* env */ .org 0x400
+.byte 0x79, 0xba, 0x8f, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+.byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x69, 0x9c, 0x7f, 0x00, 0x00, 0x00, 0x00
+
+/* state */ .org 0xC00
+.byte 0xf3, 0xfd, 0x54, 0x23, 0x18, 0x00, 0x00, 0x00, 0xa6, 0x86, 0x3b, 0xaa, 0x00, 0x00, 0x08, 0x00
+.byte 0x19, 0x70, 0x3d, 0xbb, 0x64, 0x89, 0x3b, 0x31, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00
+.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+.byte 0xf3, 0xfd, 0x54, 0x23, 0x18, 0x00, 0x00, 0x00, 0xa6, 0x86, 0x3b, 0xaa, 0x00, 0x00, 0x08, 0x00
+.byte 0x19, 0x70, 0x3d, 0xbb, 0x64, 0x89, 0x3b, 0x31, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00
+.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+.byte 0xf3, 0xfd, 0x54, 0x23, 0x18, 0x00, 0x00, 0x00, 0xa6, 0x86, 0x3b, 0xaa, 0x00, 0x00, 0x08, 0x00
+.byte 0x19, 0x70, 0x3d, 0xbb, 0x64, 0x89, 0x3b, 0x31, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00
+
+.fill 4096-(.-stickypage), 1, 0
+.size stickypage, 4096
diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c
index e1cff7a0bf..074c96a8a9 100644
--- a/arch/sandbox/board/watchdog.c
+++ b/arch/sandbox/board/watchdog.c
@@ -6,12 +6,13 @@
#include <mach/linux.h>
#include <of.h>
#include <watchdog.h>
-#include <mfd/syscon.h>
-#include <reset_source.h>
+#include <linux/nvmem-consumer.h>
+#include <asm/reset_source.h>
struct sandbox_watchdog {
struct watchdog wdd;
bool cant_disable :1;
+ struct nvmem_cell *reset_source_cell;
};
static inline struct sandbox_watchdog *to_sandbox_watchdog(struct watchdog *wdd)
@@ -29,18 +30,17 @@ static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeo
if (timeout > wdd->timeout_max)
return -EINVAL;
+ sandbox_save_reset_source(wd->reset_source_cell, RESET_WDG);
+
linux_watchdog_set_timeout(timeout);
return 0;
}
-static int sandbox_watchdog_probe(struct device_d *dev)
+static int sandbox_watchdog_probe(struct device *dev)
{
- struct device_node *np = dev->device_node;
+ struct device_node *np = dev->of_node;
struct sandbox_watchdog *wd;
struct watchdog *wdd;
- struct regmap *src;
- u32 src_offset;
- int ret;
wd = xzalloc(sizeof(*wd));
@@ -49,26 +49,17 @@ static int sandbox_watchdog_probe(struct device_d *dev)
wdd->set_timeout = sandbox_watchdog_set_timeout;
wdd->timeout_max = 1000;
- wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable");
-
- ret = watchdog_register(wdd);
- if (ret) {
- dev_err(dev, "Failed to register watchdog device\n");
- return ret;
+ wd->reset_source_cell = of_nvmem_cell_get(np, "reset-source");
+ if (IS_ERR(wd->reset_source_cell)) {
+ if (PTR_ERR(wd->reset_source_cell) != -EPROBE_DEFER)
+ dev_warn(dev, "No reset source info available: %pe\n",
+ wd->reset_source_cell);
+ wd->reset_source_cell = NULL;
}
- src = syscon_regmap_lookup_by_phandle(np, "barebox,reset-source");
- if (IS_ERR(src))
- return 0;
-
- ret = of_property_read_u32_index(np, "barebox,reset-source", 1, &src_offset);
- if (ret)
- return 0;
-
- regmap_update_bits(src, src_offset, 0xff, RESET_WDG);
+ wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable");
- dev_info(dev, "probed\n");
- return 0;
+ return watchdog_register(wdd);
}
@@ -76,8 +67,9 @@ static __maybe_unused struct of_device_id sandbox_watchdog_dt_ids[] = {
{ .compatible = "barebox,sandbox-watchdog" },
{ /* sentinel */ }
};
+MODULE_DEVICE_TABLE(of, sandbox_watchdog_dt_ids);
-static struct driver_d sandbox_watchdog_drv = {
+static struct driver sandbox_watchdog_drv = {
.name = "sandbox-watchdog",
.of_compatible = sandbox_watchdog_dt_ids,
.probe = sandbox_watchdog_probe,
diff --git a/arch/sandbox/configs/hosttools_defconfig b/arch/sandbox/configs/hosttools_defconfig
index 7d33853124..0b62b648c7 100644
--- a/arch/sandbox/configs/hosttools_defconfig
+++ b/arch/sandbox/configs/hosttools_defconfig
@@ -4,3 +4,4 @@ CONFIG_ARCH_IMX_USBLOADER=y
CONFIG_MVEBU_HOSTTOOLS=y
CONFIG_OMAP3_USB_LOADER=y
CONFIG_OMAP4_HOSTTOOL_USBBOOT=y
+CONFIG_RK_USB_LOADER=y
diff --git a/arch/sandbox/configs/sandbox_defconfig b/arch/sandbox/configs/sandbox_defconfig
index d9d96d9481..1bb98c550c 100644
--- a/arch/sandbox/configs/sandbox_defconfig
+++ b/arch/sandbox/configs/sandbox_defconfig
@@ -4,7 +4,6 @@ CONFIG_CMDLINE_EDITING=y
CONFIG_AUTO_COMPLETE=y
CONFIG_MENU=y
CONFIG_CONSOLE_ALLOW_COLOR=y
-CONFIG_PARTITION=y
CONFIG_PARTITION_DISK_EFI=y
CONFIG_DEFAULT_COMPRESSION_GZIP=y
CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
@@ -87,6 +86,7 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
CONFIG_CMD_OF_OVERLAY=y
CONFIG_CMD_OFTREE=y
CONFIG_CMD_TIME=y
+CONFIG_CMD_UPTIME=y
CONFIG_CMD_STATE=y
CONFIG_CMD_DHRYSTONE=y
CONFIG_CMD_SPD_DECODE=y
@@ -96,7 +96,9 @@ CONFIG_NET_NFS=y
CONFIG_NET_NETCONSOLE=y
CONFIG_NET_SNTP=y
CONFIG_NET_FASTBOOT=y
+CONFIG_FEATURE_CONTROLLER=y
CONFIG_OFDEVICE=y
+# CONFIG_FEATURE_CONTROLLER_FIXUP is not set
CONFIG_OF_BAREBOX_DRIVERS=y
CONFIG_OF_BAREBOX_ENV_IN_FS=y
CONFIG_OF_OVERLAY_LIVE=y
@@ -126,6 +128,7 @@ CONFIG_WATCHDOG_POLLER=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_DS1307=y
CONFIG_SYSCON_REBOOT_MODE=y
+CONFIG_NVMEM_REBOOT_MODE=y
CONFIG_FS_CRAMFS=y
CONFIG_FS_EXT4=y
CONFIG_FS_TFTP=y
@@ -146,7 +149,6 @@ CONFIG_XZ_DECOMPRESS=y
CONFIG_BASE64=y
CONFIG_LZO_DECOMPRESS=y
CONFIG_BMP=y
-CONFIG_PNG=y
CONFIG_FONT_8x16=y
CONFIG_FONT_7x14=y
CONFIG_FONT_MINI_4x6=y
diff --git a/arch/sandbox/configs/targettools_defconfig b/arch/sandbox/configs/targettools_defconfig
new file mode 100644
index 0000000000..22845def61
--- /dev/null
+++ b/arch/sandbox/configs/targettools_defconfig
@@ -0,0 +1,10 @@
+CONFIG_IMD=y
+CONFIG_IMD_TARGET=y
+CONFIG_KERNEL_INSTALL_TARGET=y
+CONFIG_BAREBOXENV_TARGET=y
+CONFIG_BAREBOXCRC32_TARGET=y
+CONFIG_MVEBU_KWBOOT_TARGET=y
+CONFIG_ARCH_IMX_USBLOADER_TARGET=y
+CONFIG_OMAP3_USB_LOADER_TARGET=y
+CONFIG_OMAP4_USBBOOT_TARGET=y
+CONFIG_RK_USB_LOADER_TARGET=y
diff --git a/arch/sandbox/dts/.gitignore b/arch/sandbox/dts/.gitignore
deleted file mode 100644
index 077903c50a..0000000000
--- a/arch/sandbox/dts/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-*dtb*
diff --git a/arch/sandbox/dts/Makefile b/arch/sandbox/dts/Makefile
index c8d83141ce..79625b103e 100644
--- a/arch/sandbox/dts/Makefile
+++ b/arch/sandbox/dts/Makefile
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
obj-$(CONFIG_OFTREE) += \
sandbox.dtb.o
@@ -5,4 +7,4 @@ obj-$(CONFIG_OFTREE) += \
# created.
obj- += dummy.o
-clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts
+clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index e99986bb90..f3fe6ce65c 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -31,6 +31,8 @@
backend = <&part_state>;
backend-storage-type = "direct";
backend-stridesize = <64>;
+ /* suppres sandbox warnings when stickypage is missing */
+ barebox,feature-gates = <&stickypage>;
#address-cells = <1>;
#size-cells = <1>;
@@ -54,16 +56,19 @@
};
stickypage: stickypage {
- compatible = "barebox,hostfile", "syscon", "simple-mfd";
+ compatible = "barebox,stickypage", "syscon";
reg = <0 0 0 4096>;
barebox,cdev; /* no caching allowed */
+ barebox,feature-controller;
+ #feature-cells = <0>;
bmode: reboot-mode {
- compatible = "syscon-reboot-mode";
- offset = <0>;
- mask = <0xffffff00>;
- mode-normal = <0x00000000>;
- mode-loader = <0xbbbbbb00>;
+ compatible = "nvmem-reboot-mode";
+ nvmem-cells = <&reboot_mode>;
+ nvmem-cell-names = "reboot-mode";
+
+ mode-normal = <0x000000>;
+ mode-loader = <0xbbbbbb>;
};
partitions {
@@ -71,14 +76,28 @@
#address-cells = <1>;
#size-cells = <1>;
- /* 0x00+4 reserved for syscon use */
+ part_nvmem: nvmem@300 {
+ compatible = "nvmem-cells";
+ reg = <0x300 0x100>;
+ label = "nvmem";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ reset_source: reset-source@0 {
+ reg = <0x0 0x1>;
+ };
+
+ reboot_mode: reboot-mode@1 {
+ reg = <0x1 0x4>;
+ };
+ };
part_env: env@400 {
reg = <0x400 0x800>;
label = "env";
};
- part_state: state@800 {
+ part_state: state@c00 {
reg = <0xC00 0x400>;
label = "state";
};
@@ -87,12 +106,14 @@
power {
compatible = "barebox,sandbox-power";
- barebox,reset-source = <&stickypage 0>;
+ nvmem-cell-names = "reset-source";
+ nvmem-cells = <&reset_source>;
};
watchdog {
compatible = "barebox,sandbox-watchdog";
- barebox,reset-source = <&stickypage 0>;
+ nvmem-cell-names = "reset-source";
+ nvmem-cells = <&reset_source>;
};
sound {
diff --git a/arch/sandbox/include/asm/barebox.lds.h b/arch/sandbox/include/asm/barebox.lds.h
new file mode 100644
index 0000000000..540d740959
--- /dev/null
+++ b/arch/sandbox/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/sandbox/include/asm/bitsperlong.h b/arch/sandbox/include/asm/bitsperlong.h
index 6dc0bb0c13..bf000a04cc 100644
--- a/arch/sandbox/include/asm/bitsperlong.h
+++ b/arch/sandbox/include/asm/bitsperlong.h
@@ -1 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#include <asm-generic/bitsperlong.h>
diff --git a/arch/sandbox/include/asm/byteorder.h b/arch/sandbox/include/asm/byteorder.h
index 3d82bcba6e..fdb421c7a5 100644
--- a/arch/sandbox/include/asm/byteorder.h
+++ b/arch/sandbox/include/asm/byteorder.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef _SANDBOX_BYTEORDER_H
#define _SANDBOX_BYTEORDER_H
diff --git a/arch/sandbox/include/asm/common.h b/arch/sandbox/include/asm/common.h
index 9b8bd2d94c..002dfb52b5 100644
--- a/arch/sandbox/include/asm/common.h
+++ b/arch/sandbox/include/asm/common.h
@@ -1,6 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef ASM_COMMON_H
#define ASM_COMMON_H
-#define ARCH_HAS_CTRLC
-
#endif /* ASM_COMMON_H */
diff --git a/arch/sandbox/include/asm/debug_ll.h b/arch/sandbox/include/asm/debug_ll.h
new file mode 100644
index 0000000000..7bef871058
--- /dev/null
+++ b/arch/sandbox/include/asm/debug_ll.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ASM_DEBUG_LL__
+#define __ASM_DEBUG_LL__
+
+#undef putchar
+
+static inline void PUTC_LL(char ch)
+{
+ int putchar(int c);
+ putchar(ch);
+}
+
+#define putchar barebox_putchar
+
+#endif /* __ASM_DEBUG_LL__ */
diff --git a/arch/sandbox/include/asm/dma.h b/arch/sandbox/include/asm/dma.h
index 34c0fc5190..2dbce1ad6c 100644
--- a/arch/sandbox/include/asm/dma.h
+++ b/arch/sandbox/include/asm/dma.h
@@ -8,16 +8,13 @@
#ifndef __ASM_DMA_H
#define __ASM_DMA_H
-#include <linux/kernel.h>
+#include <xfuncs.h>
+#include <linux/types.h>
#include <linux/string.h>
-#include <driver.h>
-#define dma_alloc dma_alloc
-static inline void *dma_alloc(size_t size)
-{
- return xmemalign(64, ALIGN(size, 64));
-}
+#define DMA_ALIGNMENT 64
+#define dma_alloc_coherent dma_alloc_coherent
static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
{
void *ret = xmemalign(4096, size);
@@ -29,24 +26,28 @@ static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
return ret;
}
+#define dma_alloc_writecombine dma_alloc_writecombine
static inline void *dma_alloc_writecombine(size_t size, dma_addr_t *dma_handle)
{
return dma_alloc_coherent(size, dma_handle);
}
+#define dma_free_coherent dma_free_coherent
static inline void dma_free_coherent(void *mem, dma_addr_t dma_handle,
size_t size)
{
free(mem);
}
-static inline void dma_sync_single_for_cpu(dma_addr_t address, size_t size,
- enum dma_data_direction dir)
+#define arch_sync_dma_for_cpu arch_sync_dma_for_cpu
+static inline void arch_sync_dma_for_cpu(void *vaddr, size_t size,
+ enum dma_data_direction dir)
{
}
-static inline void dma_sync_single_for_device(dma_addr_t address, size_t size,
- enum dma_data_direction dir)
+#define arch_sync_dma_for_device arch_sync_dma_for_device
+static inline void arch_sync_dma_for_device(void *vaddr, size_t size,
+ enum dma_data_direction dir)
{
}
diff --git a/arch/sandbox/include/asm/elf.h b/arch/sandbox/include/asm/elf.h
index e71a60aeb9..f08d5930c6 100644
--- a/arch/sandbox/include/asm/elf.h
+++ b/arch/sandbox/include/asm/elf.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef __ASM_SANDBOX_ELF_H__
#define __ASM_SANDBOX_ELF_H__
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index 9f9cd3a42a..eec279b888 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef __ASM_SANDBOX_IO_H
#define __ASM_SANDBOX_IO_H
@@ -8,16 +10,5 @@
extern unsigned char __pci_iobase[IO_SPACE_LIMIT];
#include <asm-generic/io.h>
-#include <asm-generic/bitio.h>
-
-static inline void *phys_to_virt(unsigned long phys)
-{
- return (void *)phys;
-}
-
-static inline unsigned long virt_to_phys(volatile void *mem)
-{
- return (unsigned long)mem;
-}
#endif /* __ASM_SANDBOX_IO_H */
diff --git a/arch/sandbox/include/asm/linkage.h b/arch/sandbox/include/asm/linkage.h
new file mode 100644
index 0000000000..1d78d9169b
--- /dev/null
+++ b/arch/sandbox/include/asm/linkage.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ASM_LINKAGE_H
+#define __ASM_LINKAGE_H
+
+/* referenced by <linux/linkage.h> */
+
+#endif
diff --git a/arch/sandbox/include/asm/mmu.h b/arch/sandbox/include/asm/mmu.h
index 95af871420..1c2646ebb3 100644
--- a/arch/sandbox/include/asm/mmu.h
+++ b/arch/sandbox/include/asm/mmu.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef __ASM_MMU_H
#define __ASM_MMU_H
diff --git a/arch/sandbox/include/asm/posix_types.h b/arch/sandbox/include/asm/posix_types.h
index 22cae6230c..feaed42471 100644
--- a/arch/sandbox/include/asm/posix_types.h
+++ b/arch/sandbox/include/asm/posix_types.h
@@ -1 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#include <asm-generic/posix_types.h>
diff --git a/arch/sandbox/include/asm/reset_source.h b/arch/sandbox/include/asm/reset_source.h
new file mode 100644
index 0000000000..1690299c47
--- /dev/null
+++ b/arch/sandbox/include/asm/reset_source.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __SANDBOX_RESET_SOURCE_H
+#define __SANDBOX_RESET_SOURCE_H
+
+#include <reset_source.h>
+#include <linux/nvmem-consumer.h>
+
+static inline void sandbox_save_reset_source(struct nvmem_cell *reset_source_cell,
+ enum reset_src_type src)
+{
+ if (reset_source_cell)
+ WARN_ON(nvmem_cell_write(reset_source_cell, &(u8) { src }, 1) <= 0);
+}
+
+#endif
diff --git a/arch/sandbox/include/asm/sections.h b/arch/sandbox/include/asm/sections.h
index 2b8c516038..c6dd0eead2 100644
--- a/arch/sandbox/include/asm/sections.h
+++ b/arch/sandbox/include/asm/sections.h
@@ -1 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#include <asm-generic/sections.h>
diff --git a/arch/sandbox/include/asm/string.h b/arch/sandbox/include/asm/string.h
index 2997587d82..b3c27a412d 100644
--- a/arch/sandbox/include/asm/string.h
+++ b/arch/sandbox/include/asm/string.h
@@ -1 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
/* dummy */
diff --git a/arch/sandbox/include/asm/swab.h b/arch/sandbox/include/asm/swab.h
index 60a90120b6..0ca746f0f1 100644
--- a/arch/sandbox/include/asm/swab.h
+++ b/arch/sandbox/include/asm/swab.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef _ASM_SWAB_H
#define _ASM_SWAB_H
diff --git a/arch/sandbox/include/asm/types.h b/arch/sandbox/include/asm/types.h
index 7b356a99eb..e29dde377c 100644
--- a/arch/sandbox/include/asm/types.h
+++ b/arch/sandbox/include/asm/types.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef __ASM_SANDBOX_TYPES_H
#define __ASM_SANDBOX_TYPES_H
diff --git a/arch/sandbox/include/asm/unaligned.h b/arch/sandbox/include/asm/unaligned.h
index d02da6e60d..7bca3ff8a4 100644
--- a/arch/sandbox/include/asm/unaligned.h
+++ b/arch/sandbox/include/asm/unaligned.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef _ASM_SANDBOX_UNALIGNED_H
#define _ASM_SANDBOX_UNALIGNED_H
diff --git a/arch/sandbox/include/asm/word-at-a-time.h b/arch/sandbox/include/asm/word-at-a-time.h
new file mode 100644
index 0000000000..f6306fb896
--- /dev/null
+++ b/arch/sandbox/include/asm/word-at-a-time.h
@@ -0,0 +1,2 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <asm-generic/word-at-a-time.h>
diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile
index b32ca6aaf8..9535305d5b 100644
--- a/arch/sandbox/lib/Makefile
+++ b/arch/sandbox/lib/Makefile
@@ -1 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
obj-$(CONFIG_ARCH_HAS_STACK_DUMP) += unwind.o
diff --git a/arch/sandbox/lib/asm-offsets.c b/arch/sandbox/lib/asm-offsets.c
index 22f382b71e..21aab692d0 100644
--- a/arch/sandbox/lib/asm-offsets.c
+++ b/arch/sandbox/lib/asm-offsets.c
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
/*
* Generate definitions needed by assembly language modules.
* This code generates raw asm output which is post-processed to extract
diff --git a/arch/sandbox/mach-sandbox/include/mach/hostfile.h b/arch/sandbox/mach-sandbox/include/mach/hostfile.h
index 3ef34bcc1c..b461d5ebc3 100644
--- a/arch/sandbox/mach-sandbox/include/mach/hostfile.h
+++ b/arch/sandbox/mach-sandbox/include/mach/hostfile.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef __ASM_ARCH_HOSTFILE_H
#define __ASM_ARCH_HOSTFILE_H
diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h b/arch/sandbox/mach-sandbox/include/mach/linux.h
index 831e170d90..f4d91f08de 100644
--- a/arch/sandbox/mach-sandbox/include/mach/linux.h
+++ b/arch/sandbox/mach-sandbox/include/mach/linux.h
@@ -1,11 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
#ifndef __ASM_ARCH_LINUX_H
#define __ASM_ARCH_LINUX_H
struct hf_info;
-struct device_d;
+struct device;
-int sandbox_add_device(struct device_d *dev);
+int sandbox_add_device(struct device *dev);
struct fb_bitfield;
@@ -13,6 +15,7 @@ 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);
+char *linux_get_stickypage_path(void);
int linux_open_hostfile(struct hf_info *hf);
int linux_read(int fd, void *buf, size_t count);
int linux_read_nonblock(int fd, void *buf, size_t count);
diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile
index 5d0c938ce6..055ce1a316 100644
--- a/arch/sandbox/os/Makefile
+++ b/arch/sandbox/os/Makefile
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
machine-y := sandbox
machdirs := $(patsubst %,arch/sandbox/mach-%/,$(machine-y))
@@ -18,8 +20,8 @@ endif
obj-y = common.o tap.o setjmp.o
obj-$(CONFIG_MALLOC_LIBC) += libc_malloc.o
-CFLAGS_sdl.o = $(shell pkg-config sdl2 --cflags)
+CFLAGS_sdl.o = $(shell $(PKG_CONFIG) sdl2 --cflags)
obj-$(CONFIG_SDL) += sdl.o
-CFLAGS_ftdi.o = $(shell pkg-config libftdi1 --cflags)
+CFLAGS_ftdi.o = $(shell $(PKG_CONFIG) libftdi1 --cflags)
obj-$(CONFIG_GPIO_LIBFTDI1) += ftdi.o
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 4eb6d37fff..3446074f99 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -40,7 +40,6 @@
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <sys/time.h>
-#include <signal.h>
/*
* ...except the ones needed to connect with barebox
*/
@@ -76,6 +75,15 @@ static void cookmode(void)
tcsetattr(0, TCSANOW, &term_orig);
}
+static char *stickypage_path;
+
+static void prepare_exit(void)
+{
+ cookmode();
+ if (stickypage_path)
+ remove(stickypage_path);
+}
+
int linux_tstc(int fd)
{
struct timeval tv = {
@@ -123,13 +131,27 @@ uint64_t linux_get_time(void)
void __attribute__((noreturn)) linux_exit(void)
{
- cookmode();
+ prepare_exit();
exit(0);
}
-static size_t saved_argv_len;
static char **saved_argv;
+static int selfpath(char *buf, size_t len)
+{
+ int ret;
+
+ /* we must follow the symlink, so we can exec an updated executable */
+ ret = readlink("/proc/self/exe", buf, len - 1);
+ if (ret < 0)
+ return ret;
+
+ if (0 < ret && ret < len - 1)
+ buf[ret] = '\0';
+
+ return ret;
+}
+
void linux_reexec(void)
{
char buf[4097];
@@ -138,9 +160,8 @@ void linux_reexec(void)
cookmode();
/* we must follow the symlink, so we can exec an updated executable */
- ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
- if (0 < ret && ret < sizeof(buf) - 1) {
- buf[ret] = '\0';
+ ret = selfpath(buf, sizeof(buf));
+ if (ret > 0) {
execv(buf, saved_argv);
if (!strcmp(&buf[ret - DELETED_OFFSET], " (deleted)")) {
printf("barebox image on disk changed. Loading new.\n");
@@ -155,7 +176,7 @@ void linux_reexec(void)
void linux_hang(void)
{
- cookmode();
+ prepare_exit();
/* falls through to generic hang() */
}
@@ -317,55 +338,76 @@ static int add_image(const char *_str, char *devname_template, int *devname_numb
return ret;
}
-int linux_open_hostfile(struct hf_info *hf)
+extern uint8_t stickypage[4096];
+
+char *linux_get_stickypage_path(void)
{
- char *buf = NULL;
- struct stat s;
- int fd = -1;
+ size_t nwritten;
+ ssize_t ret;
+ int fd;
- printf("add %s %sbacked by file %s%s\n", hf->devname,
- hf->filename ? "" : "initially un", hf->filename ?: "",
- hf->is_readonly ? "(ro)" : "");
+ ret = asprintf(&stickypage_path, "%s/barebox/stickypage.%lu",
+ getenv("XDG_RUNTIME_DIR") ?: "/run", (long)getpid());
+ if (ret < 0)
+ goto err_asprintf;
- if (hf->filename) {
- fd = hf->fd = open(hf->filename, (hf->is_readonly ? O_RDONLY : O_RDWR) | O_CLOEXEC);
- } else {
- char *filename;
- int ret;
+ ret = mkdir(dirname(stickypage_path), 0755);
+ if (ret < 0 && errno != EEXIST) {
+ perror("mkdir");
+ goto err_creat;
+ }
+
+ stickypage_path[strlen(stickypage_path)] = '/';
+
+ fd = open(stickypage_path, O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644);
+ if (fd < 0) {
+ if (errno == EEXIST)
+ return stickypage_path;
+
+ perror("open");
+ goto err_creat;
+ }
- ret = asprintf(&buf, "--image=%s=/tmp/barebox-hostfileXXXXXX", hf->devname);
+ for (nwritten = 0; nwritten < sizeof(stickypage); ) {
+ ret = write(fd, &stickypage[nwritten], sizeof(stickypage) - nwritten);
if (ret < 0) {
- perror("asprintf");
- goto err_out;
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ perror("write");
+ goto err_write;
}
- filename = buf + strlen("--image==") + strlen(hf->devname);
+ nwritten += ret;
+ }
- fd = hf->fd = mkstemp(filename);
- if (fd >= 0) {
- ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
- perror("fcntl");
- goto err_out;
- }
+ close(fd);
- ret = ftruncate(fd, hf->size);
- if (ret < 0) {
- perror("ftruncate");
- goto err_out;
- }
+ return stickypage_path;
- hf->filename = filename;
+err_write:
+ close(fd);
+err_creat:
+ free(stickypage_path);
+err_asprintf:
+ stickypage_path = NULL;
- saved_argv = realloc(saved_argv,
- ++saved_argv_len * sizeof(*saved_argv));
- if (!saved_argv)
- exit(1);
- saved_argv[saved_argv_len - 2] = buf;
- saved_argv[saved_argv_len - 1] = NULL;
- }
- }
+ return NULL;
+}
+
+int linux_open_hostfile(struct hf_info *hf)
+{
+ char *buf = NULL;
+ struct stat s;
+ int fd = -1;
+ printf("add %s %sbacked by file %s%s\n", hf->devname,
+ hf->filename ? "" : "initially un", hf->filename ?: "",
+ hf->is_readonly ? "(ro)" : "");
+
+ if (!hf->filename)
+ return -ENOENT;
+
+ fd = hf->fd = open(hf->filename, (hf->is_readonly ? O_RDONLY : O_RDWR) | O_CLOEXEC);
if (fd < 0) {
perror("open");
goto err_out;
@@ -477,7 +519,7 @@ int main(int argc, char *argv[])
char *aux;
#ifdef CONFIG_ASAN
- __sanitizer_set_death_callback(cookmode);
+ __sanitizer_set_death_callback(prepare_exit);
#endif
while (1) {
@@ -517,11 +559,7 @@ int main(int argc, char *argv[])
}
}
- saved_argv_len = argc + 1;
- saved_argv = calloc(saved_argv_len, sizeof(*saved_argv));
- if (!saved_argv)
- exit(1);
- memcpy(saved_argv, argv, saved_argv_len * sizeof(*saved_argv));
+ saved_argv = argv;
ram = malloc(malloc_size);
if (!ram) {
diff --git a/arch/sandbox/os/libc_malloc.c b/arch/sandbox/os/libc_malloc.c
index 74e3e26805..975c41b0ec 100644
--- a/arch/sandbox/os/libc_malloc.c
+++ b/arch/sandbox/os/libc_malloc.c
@@ -6,18 +6,30 @@
#include <stdlib.h>
#include <malloc.h>
+#define BAREBOX_ENOMEM 12
+extern int barebox_errno;
+
void barebox_malloc_stats(void)
{
}
void *barebox_memalign(size_t alignment, size_t bytes)
{
- return memalign(alignment, bytes);
+ void *mem = memalign(alignment, bytes);
+ if (!mem)
+ barebox_errno = BAREBOX_ENOMEM;
+
+ return mem;
}
void *barebox_malloc(size_t size)
{
- return malloc(size);
+
+ void *mem = malloc(size);
+ if (!mem)
+ barebox_errno = BAREBOX_ENOMEM;
+
+ return mem;
}
void barebox_free(void *ptr)
@@ -27,10 +39,18 @@ void barebox_free(void *ptr)
void *barebox_realloc(void *ptr, size_t size)
{
- return realloc(ptr, size);
+ void *mem = realloc(ptr, size);
+ if (!mem)
+ barebox_errno = BAREBOX_ENOMEM;
+
+ return mem;
}
void *barebox_calloc(size_t n, size_t elem_size)
{
- return calloc(n, elem_size);
+ void *mem = calloc(n, elem_size);
+ if (!mem)
+ barebox_errno = BAREBOX_ENOMEM;
+
+ return mem;
}