diff options
Diffstat (limited to 'arch/sandbox')
46 files changed, 330 insertions, 146 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 ed01cb9c3e..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 @@ -11,9 +13,4 @@ obj-$(CONFIG_LED) += led.o extra-y += barebox.lds -extra-y += stickypage.bin - -OBJCOPYFLAGS_stickypage.bin = -O binary - -%.bin: %.o - $(call if_changed,objcopy) +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 43e355afe8..c8d1c99897 100644 --- a/arch/sandbox/board/board.c +++ b/arch/sandbox/board/board.c @@ -29,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(struct device_d *dev) +static int devices_init(struct device *dev) { platform_device_register(&tap_device); @@ -68,7 +68,7 @@ static struct of_device_id sandbox_dt_ids[] = { }; BAREBOX_DEEP_PROBE_ENABLE(sandbox_dt_ids); -static struct driver_d sandbox_board_drv = { +static struct driver sandbox_board_drv = { .name = "sandbox-board", .of_compatible = sandbox_dt_ids, .probe = devices_init, 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/hostfile.c b/arch/sandbox/board/hostfile.c index 7df69f8cfc..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 device_node *np = dev->device_node; + 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->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,7 +249,20 @@ 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] = {}; @@ -241,13 +274,6 @@ static int of_hostfile_map_fixup(struct device_node *root, void *ctx) continue; } - if (memcmp(hf.filename, "$build/", 7) == 0) { - char *fullpath = xasprintf("%s/%s", linux_get_builddir(), - hf.filename + sizeof "$build/" - 1); - - hf.filename = fullpath; - } - hf.is_blockdev = of_property_read_bool(node, "barebox,blockdev"); hf.is_cdev = of_property_read_bool(node, "barebox,cdev"); hf.is_readonly = of_property_read_bool(node, "barebox,read-only"); @@ -259,23 +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; - - 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 aa778792c1..8300c589c7 100644 --- a/arch/sandbox/board/power.c +++ b/arch/sandbox/board/power.c @@ -1,9 +1,11 @@ +// 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 <asm/reset_source.h> #include <linux/nvmem-consumer.h> struct sandbox_power { @@ -16,7 +18,8 @@ static void sandbox_poweroff(struct poweroff_handler *poweroff) { struct sandbox_power *power = container_of(poweroff, struct sandbox_power, poweroff); - nvmem_cell_write(power->reset_source_cell, &(u8) { RESET_POR }, 1); + sandbox_save_reset_source(power->reset_source_cell, RESET_POR); + linux_exit(); } @@ -27,16 +30,14 @@ static void sandbox_rst_hang(struct restart_handler *rst) static void sandbox_rst_reexec(struct restart_handler *rst) { - u8 reason = RESET_RST; struct sandbox_power *power = container_of(rst, struct sandbox_power, rst_reexec); - if (!IS_ERR(power->reset_source_cell)) - WARN_ON(nvmem_cell_write(power->reset_source_cell, &reason, 1) <= 0); + 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)); size_t len; @@ -64,9 +65,13 @@ static int sandbox_power_probe(struct device_d *dev) if (IS_ENABLED(CONFIG_SANDBOX_REEXEC)) restart_handler_register(&power->rst_reexec); - power->reset_source_cell = of_nvmem_cell_get(dev->device_node, "reset-source"); + power->reset_source_cell = of_nvmem_cell_get(dev->of_node, + "reset-source"); if (IS_ERR(power->reset_source_cell)) { - dev_warn(dev, "No reset source info available: %pe\n", 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; } @@ -84,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 index f1915ab986..1d3861c373 100644 --- a/arch/sandbox/board/stickypage.S +++ b/arch/sandbox/board/stickypage.S @@ -1,5 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ +.section .note.GNU-stack,"",%progbits +.section .rodata.stickypage,"a" + .globl stickypage; stickypage: diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c index daaf549642..074c96a8a9 100644 --- a/arch/sandbox/board/watchdog.c +++ b/arch/sandbox/board/watchdog.c @@ -7,7 +7,7 @@ #include <of.h> #include <watchdog.h> #include <linux/nvmem-consumer.h> -#include <reset_source.h> +#include <asm/reset_source.h> struct sandbox_watchdog { struct watchdog wdd; @@ -30,18 +30,17 @@ static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeo if (timeout > wdd->timeout_max) return -EINVAL; - nvmem_cell_write(wd->reset_source_cell, &(u8) { RESET_WDG }, 1); + 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; - int ret; wd = xzalloc(sizeof(*wd)); @@ -50,23 +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(dev->device_node, "reset-source"); + wd->reset_source_cell = of_nvmem_cell_get(np, "reset-source"); if (IS_ERR(wd->reset_source_cell)) { - dev_warn(dev, "No reset source info available: %pe\n", wd->reset_source_cell); - goto out; + 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; } -out: - dev_info(dev, "probed\n"); - return 0; + wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable"); + + return watchdog_register(wdd); } @@ -74,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 881762444b..1bb98c550c 100644 --- a/arch/sandbox/configs/sandbox_defconfig +++ b/arch/sandbox/configs/sandbox_defconfig @@ -86,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 @@ -95,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 @@ -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 index d06074790c..22845def61 100644 --- a/arch/sandbox/configs/targettools_defconfig +++ b/arch/sandbox/configs/targettools_defconfig @@ -7,3 +7,4 @@ 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 5b2cab219e..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,10 +56,11 @@ }; stickypage: stickypage { - compatible = "barebox,hostfile", "syscon", "simple-mfd"; - barebox,filename = "$build/stickypage.bin"; + compatible = "barebox,stickypage", "syscon"; reg = <0 0 0 4096>; barebox,cdev; /* no caching allowed */ + barebox,feature-controller; + #feature-cells = <0>; bmode: reboot-mode { compatible = "nvmem-reboot-mode"; 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 3e5c0580bc..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 @@ -9,14 +11,4 @@ extern unsigned char __pci_iobase[IO_SPACE_LIMIT]; #include <asm-generic/io.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 453813952e..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,7 +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); -const char *linux_get_builddir(void); +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 e36e3972bc..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,7 +131,7 @@ uint64_t linux_get_time(void) void __attribute__((noreturn)) linux_exit(void) { - cookmode(); + prepare_exit(); exit(0); } @@ -168,7 +176,7 @@ void linux_reexec(void) void linux_hang(void) { - cookmode(); + prepare_exit(); /* falls through to generic hang() */ } @@ -330,19 +338,60 @@ static int add_image(const char *_str, char *devname_template, int *devname_numb return ret; } -const char *linux_get_builddir(void) +extern uint8_t stickypage[4096]; + +char *linux_get_stickypage_path(void) { - static char path[4097]; - int ret; + size_t nwritten; + ssize_t ret; + int fd; + + ret = asprintf(&stickypage_path, "%s/barebox/stickypage.%lu", + getenv("XDG_RUNTIME_DIR") ?: "/run", (long)getpid()); + if (ret < 0) + goto err_asprintf; - if (!path[0]) { - ret = selfpath(path, sizeof(path)); - if (ret < 0) - return NULL; - dirname(path); + ret = mkdir(dirname(stickypage_path), 0755); + if (ret < 0 && errno != EEXIST) { + perror("mkdir"); + goto err_creat; } - return path; + 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; + } + + for (nwritten = 0; nwritten < sizeof(stickypage); ) { + ret = write(fd, &stickypage[nwritten], sizeof(stickypage) - nwritten); + if (ret < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + perror("write"); + goto err_write; + } + + nwritten += ret; + } + + close(fd); + + return stickypage_path; + +err_write: + close(fd); +err_creat: + free(stickypage_path); +err_asprintf: + stickypage_path = NULL; + + return NULL; } int linux_open_hostfile(struct hf_info *hf) @@ -470,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) { 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; } |