summaryrefslogtreecommitdiff
path: root/arch/sandbox
diff options
context:
space:
mode:
authorAlbert ARIBAUD <albert.u.boot@aribaud.net>2014-03-25 10:25:14 +0100
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>2014-03-25 10:53:15 +0100
commitab6423cae0323e8db2c8fdd0a99138d93fde2137 (patch)
treea97493753a119e577161a4fb0b40b8edfc3923bb /arch/sandbox
parent63f347ec4ca94e3b57c6c719e4acaec81b61dc7a (diff)
parent2c072c958bb544c72f0e848375803dbd6971f022 (diff)
downloadu-boot-imx-ab6423cae0323e8db2c8fdd0a99138d93fde2137.zip
u-boot-imx-ab6423cae0323e8db2c8fdd0a99138d93fde2137.tar.gz
u-boot-imx-ab6423cae0323e8db2c8fdd0a99138d93fde2137.tar.bz2
Merge branch 'u-boot/master' into 'u-boot-arm/master'
Trivial merge conflict, needed to manually remove local_info as per commit 41364f0f. Conflicts: board/samsung/common/board.c
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/config.mk5
-rw-r--r--arch/sandbox/cpu/Makefile3
-rw-r--r--arch/sandbox/cpu/cpu.c2
-rw-r--r--arch/sandbox/cpu/os.c103
-rw-r--r--arch/sandbox/cpu/sdl.c341
-rw-r--r--arch/sandbox/cpu/start.c60
-rw-r--r--arch/sandbox/cpu/state.c6
-rw-r--r--arch/sandbox/dts/sandbox.dts96
-rw-r--r--arch/sandbox/include/asm/arch-sandbox/sound.h14
-rw-r--r--arch/sandbox/include/asm/sdl.h118
-rw-r--r--arch/sandbox/include/asm/state.h29
-rw-r--r--arch/sandbox/include/asm/u-boot-sandbox.h3
12 files changed, 771 insertions, 9 deletions
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 668aa71..e094ae2 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -5,6 +5,11 @@ PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ -U_FORTIFY_SOURCE
PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM -DCONFIG_SYS_GENERIC_BOARD
PLATFORM_LIBS += -lrt
+ifdef CONFIG_SANDBOX_SDL
+PLATFORM_LIBS += $(shell sdl-config --libs)
+PLATFORM_CPPFLAGS += $(shell sdl-config --cflags)
+endif
+
# Support generic board on sandbox
__HAVE_ARCH_GENERIC_BOARD := y
diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile
index 63deded..7d4410c 100644
--- a/arch/sandbox/cpu/Makefile
+++ b/arch/sandbox/cpu/Makefile
@@ -8,6 +8,7 @@
#
obj-y := cpu.o os.o start.o state.o
+obj-$(CONFIG_SANDBOX_SDL) += sdl.o
# os.c is build in the system environment, so needs standard includes
# CFLAGS_REMOVE_os.o cannot be used to drop header include path
@@ -17,3 +18,5 @@ cmd_cc_os.o = $(CC) $(filter-out -nostdinc, \
$(obj)/os.o: $(src)/os.c FORCE
$(call if_changed_dep,cc_os.o)
+$(obj)/sdl.o: $(src)/sdl.c FORCE
+ $(call if_changed_dep,cc_os.o)
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index 38019e0..3f4005b 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -58,7 +58,7 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
return (void *)(gd->arch.ram_buf + paddr);
}
-phys_addr_t map_to_sysmem(void *ptr)
+phys_addr_t map_to_sysmem(const void *ptr)
{
return (u8 *)ptr - gd->arch.ram_buf;
}
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 98f565e..57d04a4 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -104,21 +104,22 @@ void os_exit(int exit_code)
/* Restore tty state when we exit */
static struct termios orig_term;
+static bool term_setup;
static void os_fd_restore(void)
{
- tcsetattr(0, TCSANOW, &orig_term);
+ if (term_setup)
+ tcsetattr(0, TCSANOW, &orig_term);
}
/* Put tty into raw mode so <tab> and <ctrl+c> work */
-void os_tty_raw(int fd)
+void os_tty_raw(int fd, bool allow_sigs)
{
- static int setup = 0;
struct termios term;
- if (setup)
+ if (term_setup)
return;
- setup = 1;
+ term_setup = true;
/* If not a tty, don't complain */
if (tcgetattr(fd, &orig_term))
@@ -128,7 +129,7 @@ void os_tty_raw(int fd)
term.c_iflag = IGNBRK | IGNPAR;
term.c_oflag = OPOST | ONLCR;
term.c_cflag = CS8 | CREAD | CLOCAL;
- term.c_lflag = 0;
+ term.c_lflag = allow_sigs ? ISIG : 0;
if (tcsetattr(fd, TCSANOW, &term))
return;
@@ -443,3 +444,93 @@ int os_read_ram_buf(const char *fname)
return 0;
}
+
+static int make_exec(char *fname, const void *data, int size)
+{
+ int fd;
+
+ strcpy(fname, "/tmp/u-boot.jump.XXXXXX");
+ fd = mkstemp(fname);
+ if (fd < 0)
+ return -ENOENT;
+ if (write(fd, data, size) < 0)
+ return -EIO;
+ close(fd);
+ if (chmod(fname, 0777))
+ return -ENOEXEC;
+
+ return 0;
+}
+
+static int add_args(char ***argvp, const char *add_args[], int count)
+{
+ char **argv;
+ int argc;
+
+ for (argv = *argvp, argc = 0; (*argvp)[argc]; argc++)
+ ;
+
+ argv = malloc((argc + count + 1) * sizeof(char *));
+ if (!argv) {
+ printf("Out of memory for %d argv\n", count);
+ return -ENOMEM;
+ }
+ memcpy(argv, *argvp, argc * sizeof(char *));
+ memcpy(argv + argc, add_args, count * sizeof(char *));
+ argv[argc + count] = NULL;
+
+ *argvp = argv;
+ return 0;
+}
+
+int os_jump_to_image(const void *dest, int size)
+{
+ struct sandbox_state *state = state_get_current();
+ char fname[30], mem_fname[30];
+ int fd, err;
+ const char *extra_args[5];
+ char **argv = state->argv;
+#ifdef DEBUG
+ int argc, i;
+#endif
+
+ err = make_exec(fname, dest, size);
+ if (err)
+ return err;
+
+ strcpy(mem_fname, "/tmp/u-boot.mem.XXXXXX");
+ fd = mkstemp(mem_fname);
+ if (fd < 0)
+ return -ENOENT;
+ close(fd);
+ err = os_write_ram_buf(mem_fname);
+ if (err)
+ return err;
+
+ os_fd_restore();
+
+ extra_args[0] = "-j";
+ extra_args[1] = fname;
+ extra_args[2] = "-m";
+ extra_args[3] = mem_fname;
+ extra_args[4] = "--rm_memory";
+ err = add_args(&argv, extra_args,
+ sizeof(extra_args) / sizeof(extra_args[0]));
+ if (err)
+ return err;
+
+#ifdef DEBUG
+ for (i = 0; argv[i]; i++)
+ printf("%d %s\n", i, argv[i]);
+#endif
+
+ if (state_uninit())
+ os_exit(2);
+
+ err = execv(fname, argv);
+ free(argv);
+ if (err)
+ return err;
+
+ return unlink(fname);
+}
diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
new file mode 100644
index 0000000..18dc7ed
--- /dev/null
+++ b/arch/sandbox/cpu/sdl.c
@@ -0,0 +1,341 @@
+/*
+ * Copyright (c) 2013 Google, Inc
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <errno.h>
+#include <linux/input.h>
+#include <SDL/SDL.h>
+#include <sound.h>
+#include <asm/state.h>
+
+static struct sdl_info {
+ SDL_Surface *screen;
+ int width;
+ int height;
+ int depth;
+ int pitch;
+ uint frequency;
+ uint audio_pos;
+ uint audio_size;
+ uint8_t *audio_data;
+ bool audio_active;
+ bool inited;
+} sdl;
+
+static void sandbox_sdl_poll_events(void)
+{
+ /*
+ * We don't want to include common.h in this file since it uses
+ * system headers. So add a declation here.
+ */
+ extern void reset_cpu(unsigned long addr);
+ SDL_Event event;
+
+ while (SDL_PollEvent(&event)) {
+ switch (event.type) {
+ case SDL_QUIT:
+ puts("LCD window closed - quitting\n");
+ reset_cpu(1);
+ break;
+ }
+ }
+}
+
+static int sandbox_sdl_ensure_init(void)
+{
+ if (!sdl.inited) {
+ if (SDL_Init(0) < 0) {
+ printf("Unable to initialize SDL: %s\n",
+ SDL_GetError());
+ return -EIO;
+ }
+
+ atexit(SDL_Quit);
+
+ sdl.inited = true;
+ }
+ return 0;
+}
+
+int sandbox_sdl_init_display(int width, int height, int log2_bpp)
+{
+ struct sandbox_state *state = state_get_current();
+ int err;
+
+ if (!width || !state->show_lcd)
+ return 0;
+ err = sandbox_sdl_ensure_init();
+ if (err)
+ return err;
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
+ printf("Unable to initialize SDL LCD: %s\n", SDL_GetError());
+ return -EPERM;
+ }
+ SDL_WM_SetCaption("U-Boot", "U-Boot");
+
+ sdl.width = width;
+ sdl.height = height;
+ sdl.depth = 1 << log2_bpp;
+ sdl.pitch = sdl.width * sdl.depth / 8;
+ sdl.screen = SDL_SetVideoMode(width, height, 0, 0);
+ sandbox_sdl_poll_events();
+
+ return 0;
+}
+
+int sandbox_sdl_sync(void *lcd_base)
+{
+ SDL_Surface *frame;
+
+ frame = SDL_CreateRGBSurfaceFrom(lcd_base, sdl.width, sdl.height,
+ sdl.depth, sdl.pitch,
+ 0x1f << 11, 0x3f << 5, 0x1f << 0, 0);
+ SDL_BlitSurface(frame, NULL, sdl.screen, NULL);
+ SDL_FreeSurface(frame);
+ SDL_UpdateRect(sdl.screen, 0, 0, 0, 0);
+ sandbox_sdl_poll_events();
+
+ return 0;
+}
+
+#define NONE (-1)
+#define NUM_SDL_CODES (SDLK_UNDO + 1)
+
+static int16_t sdl_to_keycode[NUM_SDL_CODES] = {
+ /* 0 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, KEY_BACKSPACE, KEY_TAB,
+ NONE, NONE, NONE, KEY_ENTER, NONE,
+ NONE, NONE, NONE, NONE, KEY_POWER, /* use PAUSE as POWER */
+
+ /* 20 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, KEY_ESC, NONE, NONE,
+ NONE, NONE, KEY_SPACE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 40 */
+ NONE, NONE, NONE, NONE, KEY_COMMA,
+ KEY_MINUS, KEY_DOT, KEY_SLASH, KEY_0, KEY_1,
+ KEY_2, KEY_3, KEY_4, KEY_5, KEY_6,
+ KEY_7, KEY_8, KEY_9, NONE, KEY_SEMICOLON,
+
+ /* 60 */
+ NONE, KEY_EQUAL, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 80 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, KEY_BACKSLASH, NONE, NONE,
+ NONE, KEY_GRAVE, KEY_A, KEY_B, KEY_C,
+
+ /* 100 */
+ KEY_D, KEY_E, KEY_F, KEY_G, KEY_H,
+ KEY_I, KEY_J, KEY_K, KEY_L, KEY_M,
+ KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R,
+ KEY_S, KEY_T, KEY_U, KEY_V, KEY_W,
+
+ /* 120 */
+ KEY_X, KEY_Y, KEY_Z, NONE, NONE,
+ NONE, NONE, KEY_DELETE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 140 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 160 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 180 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 200 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 220 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 240 */
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+ NONE, KEY_KP0, KEY_KP1, KEY_KP2, KEY_KP3,
+
+ /* 260 */
+ KEY_KP4, KEY_KP5, KEY_KP6, KEY_KP7, KEY_KP8,
+ KEY_KP9, KEY_KPDOT, KEY_KPSLASH, KEY_KPASTERISK, KEY_KPMINUS,
+ KEY_KPPLUS, KEY_KPENTER, KEY_KPEQUAL, KEY_UP, KEY_DOWN,
+ KEY_RIGHT, KEY_LEFT, KEY_INSERT, KEY_HOME, KEY_END,
+
+ /* 280 */
+ KEY_PAGEUP, KEY_PAGEDOWN, KEY_F1, KEY_F2, KEY_F3,
+ KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8,
+ KEY_F9, KEY_F10, KEY_F11, KEY_F12, NONE,
+ NONE, NONE, NONE, NONE, NONE,
+
+ /* 300 */
+ KEY_NUMLOCK, KEY_CAPSLOCK, KEY_SCROLLLOCK, KEY_RIGHTSHIFT,
+ KEY_LEFTSHIFT,
+ KEY_RIGHTCTRL, KEY_LEFTCTRL, KEY_RIGHTALT, KEY_LEFTALT, KEY_RIGHTMETA,
+ KEY_LEFTMETA, NONE, KEY_FN, NONE, KEY_COMPOSE,
+ NONE, KEY_PRINT, KEY_SYSRQ, KEY_PAUSE, NONE,
+
+ /* 320 */
+ NONE, NONE, NONE,
+};
+
+int sandbox_sdl_scan_keys(int key[], int max_keys)
+{
+ Uint8 *keystate;
+ int i, count;
+
+ sandbox_sdl_poll_events();
+ keystate = SDL_GetKeyState(NULL);
+ for (i = count = 0; i < NUM_SDL_CODES; i++) {
+ if (count >= max_keys)
+ break;
+ else if (keystate[i])
+ key[count++] = sdl_to_keycode[i];
+ }
+
+ return count;
+}
+
+int sandbox_sdl_key_pressed(int keycode)
+{
+ int key[8]; /* allow up to 8 keys to be pressed at once */
+ int count;
+ int i;
+
+ count = sandbox_sdl_scan_keys(key, sizeof(key) / sizeof(key[0]));
+ for (i = 0; i < count; i++) {
+ if (key[i] == keycode)
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
+void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
+{
+ int avail;
+
+ avail = sdl.audio_size - sdl.audio_pos;
+ if (avail < len)
+ len = avail;
+
+ SDL_MixAudio(stream, sdl.audio_data + sdl.audio_pos, len,
+ SDL_MIX_MAXVOLUME);
+ sdl.audio_pos += len;
+
+ /* Loop if we are at the end */
+ if (sdl.audio_pos == sdl.audio_size)
+ sdl.audio_pos = 0;
+}
+
+int sandbox_sdl_sound_init(void)
+{
+ SDL_AudioSpec wanted;
+
+ if (sandbox_sdl_ensure_init())
+ return -1;
+
+ if (sdl.audio_active)
+ return 0;
+
+ /*
+ * At present all sandbox sounds crash. This is probably due to
+ * symbol name conflicts with U-Boot. We can remove the malloc()
+ * probles with:
+ *
+ * #define USE_DL_PREFIX
+ *
+ * and get this:
+ *
+ * Assertion 'e->pollfd->fd == e->fd' failed at pulse/mainloop.c:676,
+ * function dispatch_pollfds(). Aborting.
+ *
+ * The right solution is probably to make U-Boot's names private or
+ * link os.c and sdl.c against their libraries before liking with
+ * U-Boot. TBD. For now sound is disabled.
+ */
+ printf("(Warning: sandbox sound disabled)\n");
+ return 0;
+
+ /* Set the audio format */
+ wanted.freq = 22050;
+ wanted.format = AUDIO_S16;
+ wanted.channels = 1; /* 1 = mono, 2 = stereo */
+ wanted.samples = 1024; /* Good low-latency value for callback */
+ wanted.callback = sandbox_sdl_fill_audio;
+ wanted.userdata = NULL;
+
+ sdl.audio_size = sizeof(uint16_t) * wanted.freq;
+ sdl.audio_data = malloc(sdl.audio_size);
+ if (!sdl.audio_data) {
+ printf("%s: Out of memory\n", __func__);
+ return -1;
+ }
+ sdl.audio_pos = 0;
+
+ if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
+ printf("Unable to initialize SDL audio: %s\n", SDL_GetError());
+ goto err;
+ }
+
+ /* Open the audio device, forcing the desired format */
+ if (SDL_OpenAudio(&wanted, NULL) < 0) {
+ printf("Couldn't open audio: %s\n", SDL_GetError());
+ goto err;
+ }
+ sdl.audio_active = true;
+
+ return 0;
+
+err:
+ free(sdl.audio_data);
+ return -1;
+}
+
+int sandbox_sdl_sound_start(uint frequency)
+{
+ if (!sdl.audio_active)
+ return -1;
+ sdl.frequency = frequency;
+ sound_create_square_wave((unsigned short *)sdl.audio_data,
+ sdl.audio_size, frequency);
+ sdl.audio_pos = 0;
+ SDL_PauseAudio(0);
+
+ return 0;
+}
+
+int sandbox_sdl_sound_stop(void)
+{
+ if (!sdl.audio_active)
+ return -1;
+ SDL_PauseAudio(1);
+
+ return 0;
+}
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 1df21d4..aad3b8b 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -107,6 +107,16 @@ static int sandbox_cmdline_cb_interactive(struct sandbox_state *state,
SANDBOX_CMDLINE_OPT_SHORT(interactive, 'i', 0, "Enter interactive mode");
+static int sandbox_cmdline_cb_jump(struct sandbox_state *state,
+ const char *arg)
+{
+ /* Remember to delete this U-Boot image later */
+ state->jumped_fname = arg;
+
+ return 0;
+}
+SANDBOX_CMDLINE_OPT_SHORT(jump, 'j', 1, "Jumped from previous U-Boot");
+
static int sandbox_cmdline_cb_memory(struct sandbox_state *state,
const char *arg)
{
@@ -126,6 +136,15 @@ static int sandbox_cmdline_cb_memory(struct sandbox_state *state,
SANDBOX_CMDLINE_OPT_SHORT(memory, 'm', 1,
"Read/write ram_buf memory contents from file");
+static int sandbox_cmdline_cb_rm_memory(struct sandbox_state *state,
+ const char *arg)
+{
+ state->ram_buf_rm = true;
+
+ return 0;
+}
+SANDBOX_CMDLINE_OPT(rm_memory, 0, "Remove memory file after reading");
+
static int sandbox_cmdline_cb_state(struct sandbox_state *state,
const char *arg)
{
@@ -159,6 +178,43 @@ static int sandbox_cmdline_cb_ignore_missing(struct sandbox_state *state,
SANDBOX_CMDLINE_OPT_SHORT(ignore_missing, 'n', 0,
"Ignore missing state on read");
+static int sandbox_cmdline_cb_show_lcd(struct sandbox_state *state,
+ const char *arg)
+{
+ state->show_lcd = true;
+ return 0;
+}
+SANDBOX_CMDLINE_OPT_SHORT(show_lcd, 'l', 0,
+ "Show the sandbox LCD display");
+
+static const char *term_args[STATE_TERM_COUNT] = {
+ "raw-with-sigs",
+ "raw",
+ "cooked",
+};
+
+static int sandbox_cmdline_cb_terminal(struct sandbox_state *state,
+ const char *arg)
+{
+ int i;
+
+ for (i = 0; i < STATE_TERM_COUNT; i++) {
+ if (!strcmp(arg, term_args[i])) {
+ state->term_raw = i;
+ return 0;
+ }
+ }
+
+ printf("Unknown terminal setting '%s' (", arg);
+ for (i = 0; i < STATE_TERM_COUNT; i++)
+ printf("%s%s", i ? ", " : "", term_args[i]);
+ puts(")\n");
+
+ return 1;
+}
+SANDBOX_CMDLINE_OPT_SHORT(terminal, 't', 1,
+ "Set terminal to raw/cooked mode");
+
int main(int argc, char *argv[])
{
struct sandbox_state *state;
@@ -176,6 +232,10 @@ int main(int argc, char *argv[])
if (ret)
goto err;
+ /* Remove old memory file if required */
+ if (state->ram_buf_rm && state->ram_buf_fname)
+ os_unlink(state->ram_buf_fname);
+
/* Do pre- and post-relocation init */
board_init_f(0);
diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index a145808..59adad6 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -365,7 +365,7 @@ int state_uninit(void)
state = &main_state;
- if (state->write_ram_buf) {
+ if (state->write_ram_buf && !state->ram_buf_rm) {
err = os_write_ram_buf(state->ram_buf_fname);
if (err) {
printf("Failed to write RAM buffer\n");
@@ -380,6 +380,10 @@ int state_uninit(void)
}
}
+ /* Delete this at the last moment so as not to upset gdb too much */
+ if (state->jumped_fname)
+ os_unlink(state->jumped_fname);
+
if (state->state_fdt)
os_free(state->state_fdt);
memset(state, '\0', sizeof(*state));
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 96a4438..62d8037 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -17,4 +17,100 @@
colour = "white";
sides = <6>;
};
+
+ host@0 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ compatible = "sandbox,host-emulation";
+ cros-ec@0 {
+ reg = <0>;
+ compatible = "google,cros-ec";
+
+ /*
+ * This describes the flash memory within the EC. Note
+ * that the STM32L flash erases to 0, not 0xff.
+ */
+ #address-cells = <1>;
+ #size-cells = <1>;
+ flash@8000000 {
+ reg = <0x08000000 0x20000>;
+ erase-value = <0>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ /* Information for sandbox */
+ ro {
+ reg = <0 0xf000>;
+ };
+ wp-ro {
+ reg = <0xf000 0x1000>;
+ };
+ rw {
+ reg = <0x10000 0x10000>;
+ };
+ };
+ };
+ };
+
+ lcd {
+ compatible = "sandbox,lcd-sdl";
+ xres = <800>;
+ yres = <600>;
+ };
+
+ cros-ec-keyb {
+ compatible = "google,cros-ec-keyb";
+ google,key-rows = <8>;
+ google,key-columns = <13>;
+ google,repeat-delay-ms = <240>;
+ google,repeat-rate-ms = <30>;
+ google,ghost-filter;
+ /*
+ * Keymap entries take the form of 0xRRCCKKKK where
+ * RR=Row CC=Column KKKK=Key Code
+ * The values below are for a US keyboard layout and
+ * are taken from the Linux driver. Note that the
+ * 102ND key is not used for US keyboards.
+ */
+ linux,keymap = <
+ /* CAPSLCK F1 B F10 */
+ 0x0001003a 0x0002003b 0x00030030 0x00040044
+ /* N = R_ALT ESC */
+ 0x00060031 0x0008000d 0x000a0064 0x01010001
+ /* F4 G F7 H */
+ 0x0102003e 0x01030022 0x01040041 0x01060023
+ /* ' F9 BKSPACE L_CTRL */
+ 0x01080028 0x01090043 0x010b000e 0x0200001d
+ /* TAB F3 T F6 */
+ 0x0201000f 0x0202003d 0x02030014 0x02040040
+ /* ] Y 102ND [ */
+ 0x0205001b 0x02060015 0x02070056 0x0208001a
+ /* F8 GRAVE F2 5 */
+ 0x02090042 0x03010029 0x0302003c 0x03030006
+ /* F5 6 - \ */
+ 0x0304003f 0x03060007 0x0308000c 0x030b002b
+ /* R_CTRL A D F */
+ 0x04000061 0x0401001e 0x04020020 0x04030021
+ /* S K J ; */
+ 0x0404001f 0x04050025 0x04060024 0x04080027
+ /* L ENTER Z C */
+ 0x04090026 0x040b001c 0x0501002c 0x0502002e
+ /* V X , M */
+ 0x0503002f 0x0504002d 0x05050033 0x05060032
+ /* L_SHIFT / . SPACE */
+ 0x0507002a 0x05080035 0x05090034 0x050B0039
+ /* 1 3 4 2 */
+ 0x06010002 0x06020004 0x06030005 0x06040003
+ /* 8 7 0 9 */
+ 0x06050009 0x06060008 0x0608000b 0x0609000a
+ /* L_ALT DOWN RIGHT Q */
+ 0x060a0038 0x060b006c 0x060c006a 0x07010010
+ /* E R W I */
+ 0x07020012 0x07030013 0x07040011 0x07050017
+ /* U R_SHIFT P O */
+ 0x07060016 0x07070036 0x07080019 0x07090018
+ /* UP LEFT */
+ 0x070b0067 0x070c0069>;
+ };
+
};
diff --git a/arch/sandbox/include/asm/arch-sandbox/sound.h b/arch/sandbox/include/asm/arch-sandbox/sound.h
new file mode 100644
index 0000000..a32e8c8
--- /dev/null
+++ b/arch/sandbox/include/asm/arch-sandbox/sound.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2013 Google, Inc
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef __SANDBOX_SOUND_H
+#define __SANDBOX_SOUND_H
+
+int sound_play(unsigned int msec, unsigned int frequency);
+
+int sound_init(const void *blob);
+
+#endif
diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h
new file mode 100644
index 0000000..6edec1a
--- /dev/null
+++ b/arch/sandbox/include/asm/sdl.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2013 Google, Inc
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef __SANDBOX_SDL_H
+#define __SANDBOX_SDL_H
+
+#include <errno.h>
+
+#ifdef CONFIG_SANDBOX_SDL
+
+/**
+ * sandbox_sdl_init_display() - Set up SDL video ready for use
+ *
+ * @width: Window width in pixels
+ * @height Window height in pixels
+ * @log2_bpp: Log to base 2 of the number of bits per pixel. So a 32bpp
+ * display will pass 5, since 2*5 = 32
+ * @return 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize
+ * and -EPERM if the video failed to come up.
+ */
+int sandbox_sdl_init_display(int width, int height, int log2_bpp);
+
+/**
+ * sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL
+ *
+ * This must be called periodically to update the screen for SDL so that the
+ * user can see it.
+ *
+ * @lcd_base: Base of frame buffer
+ * @return 0 if screen was updated, -ENODEV is there is no screen.
+ */
+int sandbox_sdl_sync(void *lcd_base);
+
+/**
+ * sandbox_sdl_scan_keys() - scan for pressed keys
+ *
+ * Works out which keys are pressed and returns a list
+ *
+ * @key: Array to receive keycodes
+ * @max_keys: Size of array
+ * @return number of keycodes found, 0 if none, -ENODEV if no keyboard
+ */
+int sandbox_sdl_scan_keys(int key[], int max_keys);
+
+/**
+ * sandbox_sdl_key_pressed() - check if a particular key is pressed
+ *
+ * @keycode: Keycode to check (KEY_... - see include/linux/input.h
+ * @return 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not
+ * available,
+ */
+int sandbox_sdl_key_pressed(int keycode);
+
+/**
+ * sandbox_sdl_sound_start() - start playing a sound
+ *
+ * @frequency: Frequency of sounds in Hertz
+ * @return 0 if OK, -ENODEV if no sound is available
+ */
+int sandbox_sdl_sound_start(uint frequency);
+
+/**
+ * sandbox_sdl_sound_stop() - stop playing a sound
+ *
+ * @return 0 if OK, -ENODEV if no sound is available
+ */
+int sandbox_sdl_sound_stop(void);
+
+/**
+ * sandbox_sdl_sound_init() - set up the sound system
+ *
+ * @return 0 if OK, -ENODEV if no sound is available
+ */
+int sandbox_sdl_sound_init(void);
+
+#else
+static inline int sandbox_sdl_init_display(int width, int height,
+ int log2_bpp)
+{
+ return -ENODEV;
+}
+
+static inline int sandbox_sdl_sync(void *lcd_base)
+{
+ return -ENODEV;
+}
+
+static inline int sandbox_sdl_scan_keys(int key[], int max_keys)
+{
+ return -ENODEV;
+}
+
+static inline int sandbox_sdl_key_pressed(int keycode)
+{
+ return -ENODEV;
+}
+
+static inline int sandbox_sdl_sound_start(uint frequency)
+{
+ return -ENODEV;
+}
+
+static inline int sandbox_sdl_sound_stop(void)
+{
+ return -ENODEV;
+}
+
+static inline int sandbox_sdl_sound_init(void)
+{
+ return -ENODEV;
+}
+
+#endif
+
+#endif
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index e8e4fea..d17a82e 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -17,6 +17,29 @@ enum exit_type_id {
STATE_EXIT_POWER_OFF,
};
+/**
+ * Selects the behavior of the serial terminal.
+ *
+ * If Ctrl-C is processed by U-Boot, then the only way to quit sandbox is with
+ * the 'reset' command, or equivalent.
+ *
+ * If the terminal is cooked, then Ctrl-C will terminate U-Boot, and the
+ * command line will not be quite such a faithful emulation.
+ *
+ * Options are:
+ *
+ * raw-with-sigs - Raw, but allow signals (Ctrl-C will quit)
+ * raw - Terminal is always raw
+ * cooked - Terminal is always cooked
+ */
+enum state_terminal_raw {
+ STATE_TERM_RAW_WITH_SIGS, /* Default */
+ STATE_TERM_RAW,
+ STATE_TERM_COOKED,
+
+ STATE_TERM_COUNT,
+};
+
struct sandbox_spi_info {
const char *spec;
const struct sandbox_spi_emu_ops *ops;
@@ -30,16 +53,20 @@ struct sandbox_state {
enum exit_type_id exit_type; /* How we exited U-Boot */
const char *parse_err; /* Error to report from parsing */
int argc; /* Program arguments */
- char **argv;
+ char **argv; /* Command line arguments */
+ const char *jumped_fname; /* Jumped from previous U_Boot */
uint8_t *ram_buf; /* Emulated RAM buffer */
unsigned int ram_size; /* Size of RAM buffer */
const char *ram_buf_fname; /* Filename to use for RAM buffer */
+ bool ram_buf_rm; /* Remove RAM buffer file after read */
bool write_ram_buf; /* Write RAM buffer on exit */
const char *state_fname; /* File containing sandbox state */
void *state_fdt; /* Holds saved state for sandbox */
bool read_state; /* Read sandbox state on startup */
bool write_state; /* Write sandbox state on exit */
bool ignore_missing_state_on_read; /* No error if state missing */
+ bool show_lcd; /* Show LCD on start-up */
+ enum state_terminal_raw term_raw; /* Terminal raw/cooked */
/* Pointer to information for each SPI bus/cs */
struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]
diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h
index 5707c27..d2f1b65 100644
--- a/arch/sandbox/include/asm/u-boot-sandbox.h
+++ b/arch/sandbox/include/asm/u-boot-sandbox.h
@@ -25,4 +25,7 @@ int sandbox_main_loop_init(void);
int cleanup_before_linux(void);
+/* drivers/video/sandbox_sdl.c */
+int sandbox_lcd_sdl_early_init(void);
+
#endif /* _U_BOOT_SANDBOX_H_ */