summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/api/.gitignore2
-rw-r--r--examples/api/Makefile90
-rw-r--r--examples/api/crt0.S71
-rw-r--r--examples/api/demo.c300
-rw-r--r--examples/api/glue.c404
-rw-r--r--examples/api/glue.h80
-rw-r--r--examples/api/libgenwrap.c95
-rw-r--r--examples/standalone/.gitignore (renamed from examples/.gitignore)0
-rw-r--r--examples/standalone/82559_eeprom.c (renamed from examples/82559_eeprom.c)0
-rw-r--r--examples/standalone/Makefile (renamed from examples/Makefile)0
-rw-r--r--examples/standalone/README.smc91111_eeprom (renamed from examples/README.smc91111_eeprom)0
-rw-r--r--examples/standalone/eepro100_eeprom.c (renamed from examples/eepro100_eeprom.c)0
-rw-r--r--examples/standalone/hello_world.c (renamed from examples/hello_world.c)0
-rw-r--r--examples/standalone/interrupt.c (renamed from examples/interrupt.c)0
-rw-r--r--examples/standalone/mem_to_mem_idma2intr.c (renamed from examples/mem_to_mem_idma2intr.c)0
-rw-r--r--examples/standalone/mips.lds (renamed from examples/mips.lds)0
-rw-r--r--examples/standalone/nios.lds (renamed from examples/nios.lds)0
-rw-r--r--examples/standalone/nios2.lds (renamed from examples/nios2.lds)0
-rw-r--r--examples/standalone/ppc_longjmp.S (renamed from examples/ppc_longjmp.S)0
-rw-r--r--examples/standalone/ppc_setjmp.S (renamed from examples/ppc_setjmp.S)0
-rw-r--r--examples/standalone/sched.c (renamed from examples/sched.c)0
-rw-r--r--examples/standalone/smc91111_eeprom.c (renamed from examples/smc91111_eeprom.c)0
-rw-r--r--examples/standalone/smc911x_eeprom.c (renamed from examples/smc911x_eeprom.c)0
-rw-r--r--examples/standalone/sparc.lds (renamed from examples/sparc.lds)0
-rw-r--r--examples/standalone/stubs.c (renamed from examples/stubs.c)0
-rw-r--r--examples/standalone/test_burst.c (renamed from examples/test_burst.c)0
-rw-r--r--examples/standalone/test_burst.h (renamed from examples/test_burst.h)0
-rw-r--r--examples/standalone/test_burst_lib.S (renamed from examples/test_burst_lib.S)0
-rw-r--r--examples/standalone/timer.c (renamed from examples/timer.c)0
-rw-r--r--examples/standalone/x86-testapp.c (renamed from examples/x86-testapp.c)0
30 files changed, 1042 insertions, 0 deletions
diff --git a/examples/api/.gitignore b/examples/api/.gitignore
new file mode 100644
index 0000000..d7b18dc
--- /dev/null
+++ b/examples/api/.gitignore
@@ -0,0 +1,2 @@
+demo
+demo.bin
diff --git a/examples/api/Makefile b/examples/api/Makefile
new file mode 100644
index 0000000..2d05a01
--- /dev/null
+++ b/examples/api/Makefile
@@ -0,0 +1,90 @@
+#
+# (C) Copyright 2007 Semihalf
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundatio; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+ifeq ($(ARCH),ppc)
+LOAD_ADDR = 0x40000
+endif
+ifeq ($(ARCH),arm)
+LOAD_ADDR = 0x1000000
+endif
+
+include $(TOPDIR)/config.mk
+
+# Resulting ELF and binary exectuables will be named demo and demo.bin
+OUTPUT-$(CONFIG_API) = $(obj)demo
+OUTPUT = $(OUTPUT-y)
+
+# Source files located in the examples/api directory
+SOBJ_FILES-$(CONFIG_API) += crt0.o
+COBJ_FILES-$(CONFIG_API) += demo.o
+COBJ_FILES-$(CONFIG_API) += glue.o
+COBJ_FILES-$(CONFIG_API) += libgenwrap.o
+
+# Source files which exist outside the examples/api directory
+EXT_COBJ_FILES-$(CONFIG_API) += lib_generic/crc32.o
+EXT_COBJ_FILES-$(CONFIG_API) += lib_generic/ctype.o
+EXT_COBJ_FILES-$(CONFIG_API) += lib_generic/string.o
+EXT_COBJ_FILES-$(CONFIG_API) += lib_generic/vsprintf.o
+ifeq ($(ARCH),ppc)
+EXT_SOBJ_FILES-$(CONFIG_API) += lib_ppc/ppcstring.o
+endif
+
+# Create a list of source files so their dependencies can be auto-generated
+SRCS += $(addprefix $(SRCTREE)/,$(EXT_COBJ_FILES-y:.o=.c))
+SRCS += $(addprefix $(SRCTREE)/,$(EXT_SOBJ_FILES-y:.o=.S))
+SRCS += $(addprefix $(SRCTREE)/examples/api/,$(COBJ_FILES-y:.o=.c))
+SRCS += $(addprefix $(SRCTREE)/examples/api/,$(SOBJ_FILES-y:.o=.S))
+
+# Create a list of object files to be compiled
+OBJS += $(addprefix $(obj),$(SOBJ_FILES-y))
+OBJS += $(addprefix $(obj),$(COBJ_FILES-y))
+OBJS += $(addprefix $(obj),$(notdir $(EXT_COBJ_FILES-y)))
+OBJS += $(addprefix $(obj),$(notdir $(EXT_SOBJ_FILES-y)))
+
+gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`)
+
+CPPFLAGS += -I..
+
+all: $(obj).depend $(OUTPUT)
+
+#########################################################################
+
+$(OUTPUT): $(OBJS)
+ $(LD) -Ttext $(LOAD_ADDR) -o $@ $^ -L$(gcclibdir) -lgcc
+ $(OBJCOPY) -O binary $@ $(OUTPUT).bin 2>/dev/null
+
+# Rule to build generic library C files
+$(obj)%.o: $(SRCTREE)/lib_generic/%.c
+ $(CC) -g $(CFLAGS) -c -o $@ $<
+
+# Rule to build architecture-specific library assembly files
+$(obj)%.o: $(SRCTREE)/lib_$(ARCH)/%.S
+ $(CC) -g $(CFLAGS) -c -o $@ $<
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
diff --git a/examples/api/crt0.S b/examples/api/crt0.S
new file mode 100644
index 0000000..6daf127
--- /dev/null
+++ b/examples/api/crt0.S
@@ -0,0 +1,71 @@
+/*
+ * (C) Copyright 2007 Semihalf
+ *
+ * Written by: Rafal Jaworowski <raj@semihalf.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#if defined(CONFIG_PPC)
+
+ .text
+ .globl _start
+_start:
+ lis %r11, search_hint@ha
+ addi %r11, %r11, search_hint@l
+ stw %r1, 0(%r11)
+ b main
+
+
+ .globl syscall
+syscall:
+ lis %r11, syscall_ptr@ha
+ addi %r11, %r11, syscall_ptr@l
+ lwz %r11, 0(%r11)
+ mtctr %r11
+ bctr
+
+#elif defined(CONFIG_ARM)
+
+ .text
+ .globl _start
+_start:
+ ldr ip, =search_hint
+ str sp, [ip]
+ b main
+
+
+ .globl syscall
+syscall:
+ ldr ip, =syscall_ptr
+ ldr pc, [ip]
+
+#else
+#error No support for this arch!
+#endif
+
+ .globl syscall_ptr
+syscall_ptr:
+ .align 4
+ .long 0
+
+ .globl search_hint
+search_hint:
+ .long 0
diff --git a/examples/api/demo.c b/examples/api/demo.c
new file mode 100644
index 0000000..df9c4bd
--- /dev/null
+++ b/examples/api/demo.c
@@ -0,0 +1,300 @@
+/*
+ * (C) Copyright 2007-2008 Semihalf
+ *
+ * Written by: Rafal Jaworowski <raj@semihalf.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <api_public.h>
+
+#include "glue.h"
+
+#define errf(fmt, args...) do { printf("ERROR @ %s(): ", __func__); printf(fmt, ##args); } while (0)
+
+#define BUF_SZ 2048
+#define WAIT_SECS 5
+
+void test_dump_buf(void *, int);
+void test_dump_di(int);
+void test_dump_si(struct sys_info *);
+void test_dump_sig(struct api_signature *);
+
+static char buf[BUF_SZ];
+
+int main(int argc, char *argv[])
+{
+ int rv = 0, h, i, j, devs_no;
+ struct api_signature *sig = NULL;
+ ulong start, now;
+ struct device_info *di;
+ lbasize_t rlen;
+
+ if (!api_search_sig(&sig))
+ return -1;
+
+ syscall_ptr = sig->syscall;
+ if (syscall_ptr == NULL)
+ return -2;
+
+ if (sig->version > API_SIG_VERSION)
+ return -3;
+
+ printf("API signature found @%x\n", (unsigned int)sig);
+ test_dump_sig(sig);
+
+ printf("\n*** Consumer API test ***\n");
+ printf("syscall ptr 0x%08x@%08x\n", (unsigned int)syscall_ptr,
+ (unsigned int)&syscall_ptr);
+
+ /* console activities */
+ ub_putc('B');
+
+ printf("*** Press any key to continue ***\n");
+ printf("got char 0x%x\n", ub_getc());
+
+ /* system info */
+ test_dump_si(ub_get_sys_info());
+
+ /* timing */
+ printf("\n*** Timing - wait a couple of secs ***\n");
+ start = ub_get_timer(0);
+ printf("\ntime: start %lu\n\n", start);
+ for (i = 0; i < WAIT_SECS; i++)
+ for (j = 0; j < 1000; j++)
+ ub_udelay(1000); /* wait 1 ms */
+
+ /* this is the number of milliseconds that passed from ub_get_timer(0) */
+ now = ub_get_timer(start);
+ printf("\ntime: now %lu\n\n", now);
+
+ /* enumerate devices */
+ printf("\n*** Enumerate devices ***\n");
+ devs_no = ub_dev_enum();
+
+ printf("Number of devices found: %d\n", devs_no);
+ if (devs_no == 0)
+ return -1;
+
+ printf("\n*** Show devices ***\n");
+ for (i = 0; i < devs_no; i++) {
+ test_dump_di(i);
+ printf("\n");
+ }
+
+ printf("\n*** Operations on devices ***\n");
+
+ /* test opening a device already opened */
+ h = 0;
+ if ((rv = ub_dev_open(h)) != 0) {
+ errf("open device %d error %d\n", h, rv);
+ return -1;
+ }
+ if ((rv = ub_dev_open(h)) != 0)
+ errf("open device %d error %d\n", h, rv);
+
+ ub_dev_close(h);
+
+ /* test storage */
+ printf("Trying storage devices...\n");
+ for (i = 0; i < devs_no; i++) {
+ di = ub_dev_get(i);
+
+ if (di->type & DEV_TYP_STOR)
+ break;
+
+ }
+ if (i == devs_no)
+ printf("No storage devices available\n");
+ else {
+ memset(buf, 0, BUF_SZ);
+
+ if ((rv = ub_dev_open(i)) != 0)
+ errf("open device %d error %d\n", i, rv);
+
+ else if ((rv = ub_dev_read(i, buf, 1, 0, &rlen)) != 0)
+ errf("could not read from device %d, error %d\n", i, rv);
+ else {
+ printf("Sector 0 dump (512B):\n");
+ test_dump_buf(buf, 512);
+ }
+
+ ub_dev_close(i);
+ }
+
+ /* test networking */
+ printf("Trying network devices...\n");
+ for (i = 0; i < devs_no; i++) {
+ di = ub_dev_get(i);
+
+ if (di->type == DEV_TYP_NET)
+ break;
+
+ }
+ if (i == devs_no)
+ printf("No network devices available\n");
+ else {
+ if ((rv = ub_dev_open(i)) != 0)
+ errf("open device %d error %d\n", i, rv);
+ else if ((rv = ub_dev_send(i, &buf, 2048)) != 0)
+ errf("could not send to device %d, error %d\n", i, rv);
+
+ ub_dev_close(i);
+ }
+
+ if (ub_dev_close(h) != 0)
+ errf("could not close device %d\n", h);
+
+ printf("\n*** Env vars ***\n");
+
+ printf("ethact = %s\n", ub_env_get("ethact"));
+ printf("old fileaddr = %s\n", ub_env_get("fileaddr"));
+ ub_env_set("fileaddr", "deadbeef");
+ printf("new fileaddr = %s\n", ub_env_get("fileaddr"));
+
+ const char *env = NULL;
+
+ while ((env = ub_env_enum(env)) != NULL)
+ printf("%s = %s\n", env, ub_env_get(env));
+
+ /* reset */
+ printf("\n*** Resetting board ***\n");
+ ub_reset();
+ printf("\nHmm, reset returned...?!\n");
+
+ return rv;
+}
+
+void test_dump_sig(struct api_signature *sig)
+{
+ printf("signature:\n");
+ printf(" version\t= %d\n", sig->version);
+ printf(" checksum\t= 0x%08x\n", sig->checksum);
+ printf(" sc entry\t= 0x%08x\n", (unsigned int)sig->syscall);
+}
+
+void test_dump_si(struct sys_info *si)
+{
+ int i;
+
+ printf("sys info:\n");
+ printf(" clkbus\t= 0x%08x\n", (unsigned int)si->clk_bus);
+ printf(" clkcpu\t= 0x%08x\n", (unsigned int)si->clk_cpu);
+ printf(" bar\t\t= 0x%08x\n", (unsigned int)si->bar);
+
+ printf("---\n");
+ for (i = 0; i < si->mr_no; i++) {
+ if (si->mr[i].flags == 0)
+ break;
+
+ printf(" start\t= 0x%08lx\n", si->mr[i].start);
+ printf(" size\t= 0x%08lx\n", si->mr[i].size);
+
+ switch(si->mr[i].flags & 0x000F) {
+ case MR_ATTR_FLASH:
+ printf(" type FLASH\n");
+ break;
+ case MR_ATTR_DRAM:
+ printf(" type DRAM\n");
+ break;
+ case MR_ATTR_SRAM:
+ printf(" type SRAM\n");
+ break;
+ default:
+ printf(" type UNKNOWN\n");
+ }
+ printf("---\n");
+ }
+}
+
+static char *test_stor_typ(int type)
+{
+ if (type & DT_STOR_IDE)
+ return "IDE";
+
+ if (type & DT_STOR_MMC)
+ return "MMC";
+
+ if (type & DT_STOR_SATA)
+ return "SATA";
+
+ if (type & DT_STOR_SCSI)
+ return "SCSI";
+
+ if (type & DT_STOR_USB)
+ return "USB";
+
+ return "Unknown";
+}
+
+void test_dump_buf(void *buf, int len)
+{
+ int i;
+ int line_counter = 0;
+ int sep_flag = 0;
+ int addr = 0;
+
+ printf("%07x:\t", addr);
+
+ for (i = 0; i < len; i++) {
+ if (line_counter++ > 15) {
+ line_counter = 0;
+ sep_flag = 0;
+ addr += 16;
+ i--;
+ printf("\n%07x:\t", addr);
+ continue;
+ }
+
+ if (sep_flag++ > 1) {
+ sep_flag = 1;
+ printf(" ");
+ }
+
+ printf("%02x", *((char *)buf++));
+ }
+
+ printf("\n");
+}
+
+void test_dump_di(int handle)
+{
+ int i;
+ struct device_info *di = ub_dev_get(handle);
+
+ printf("device info (%d):\n", handle);
+ printf(" cookie\t= 0x%08x\n", (uint32_t)di->cookie);
+ printf(" type\t\t= 0x%08x\n", di->type);
+
+ if (di->type == DEV_TYP_NET) {
+ printf(" hwaddr\t= ");
+ for (i = 0; i < 6; i++)
+ printf("%02x ", di->di_net.hwaddr[i]);
+
+ printf("\n");
+
+ } else if (di->type & DEV_TYP_STOR) {
+ printf(" type\t\t= %s\n", test_stor_typ(di->type));
+ printf(" blk size\t\t= %d\n", (unsigned int)di->di_stor.block_size);
+ printf(" blk count\t\t= %d\n", (unsigned int)di->di_stor.block_count);
+ }
+}
diff --git a/examples/api/glue.c b/examples/api/glue.c
new file mode 100644
index 0000000..eff6a7e
--- /dev/null
+++ b/examples/api/glue.c
@@ -0,0 +1,404 @@
+/*
+ * (C) Copyright 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <api_public.h>
+
+#include "glue.h"
+
+static int valid_sig(struct api_signature *sig)
+{
+ uint32_t checksum;
+ struct api_signature s;
+
+ if (sig == NULL)
+ return 0;
+ /*
+ * Clear the checksum field (in the local copy) so as to calculate the
+ * CRC with the same initial contents as at the time when the sig was
+ * produced
+ */
+ s = *sig;
+ s.checksum = 0;
+
+ checksum = crc32(0, (unsigned char *)&s, sizeof(struct api_signature));
+
+ if (checksum != sig->checksum)
+ return 0;
+
+ return 1;
+}
+
+/*
+ * Searches for the U-Boot API signature
+ *
+ * returns 1/0 depending on found/not found result
+ */
+int api_search_sig(struct api_signature **sig)
+{
+ unsigned char *sp;
+ uint32_t search_start = 0;
+ uint32_t search_end = 0;
+
+ if (sig == NULL)
+ return 0;
+
+ if (search_hint == 0)
+ search_hint = 255 * 1024 * 1024;
+
+ search_start = search_hint & ~0x000fffff;
+ search_end = search_start + API_SEARCH_LEN - API_SIG_MAGLEN;
+
+ sp = (unsigned char *)search_start;
+ while ((sp + API_SIG_MAGLEN) < (unsigned char *)search_end) {
+ if (!memcmp(sp, API_SIG_MAGIC, API_SIG_MAGLEN)) {
+ *sig = (struct api_signature *)sp;
+ if (valid_sig(*sig))
+ return 1;
+ }
+ sp += API_SIG_MAGLEN;
+ }
+
+ *sig = NULL;
+ return 0;
+}
+
+/****************************************
+ *
+ * console
+ *
+ ****************************************/
+
+int ub_getc(void)
+{
+ int c;
+
+ if (!syscall(API_GETC, NULL, (uint32_t)&c))
+ return -1;
+
+ return c;
+}
+
+int ub_tstc(void)
+{
+ int t;
+
+ if (!syscall(API_TSTC, NULL, (uint32_t)&t))
+ return -1;
+
+ return t;
+}
+
+void ub_putc(char c)
+{
+ syscall(API_PUTC, NULL, (uint32_t)&c);
+}
+
+void ub_puts(const char *s)
+{
+ syscall(API_PUTS, NULL, (uint32_t)s);
+}
+
+/****************************************
+ *
+ * system
+ *
+ ****************************************/
+
+void ub_reset(void)
+{
+ syscall(API_RESET, NULL);
+}
+
+static struct mem_region mr[UB_MAX_MR];
+static struct sys_info si;
+
+struct sys_info * ub_get_sys_info(void)
+{
+ int err = 0;
+
+ memset(&si, 0, sizeof(struct sys_info));
+ si.mr = mr;
+ si.mr_no = UB_MAX_MR;
+ memset(&mr, 0, sizeof(mr));
+
+ if (!syscall(API_GET_SYS_INFO, &err, (u_int32_t)&si))
+ return NULL;
+
+ return ((err) ? NULL : &si);
+}
+
+/****************************************
+ *
+ * timing
+ *
+ ****************************************/
+
+void ub_udelay(unsigned long usec)
+{
+ syscall(API_UDELAY, NULL, &usec);
+}
+
+unsigned long ub_get_timer(unsigned long base)
+{
+ unsigned long cur;
+
+ if (!syscall(API_GET_TIMER, NULL, &cur, &base))
+ return 0;
+
+ return cur;
+}
+
+
+/****************************************************************************
+ *
+ * devices
+ *
+ * Devices are identified by handles: numbers 0, 1, 2, ..., UB_MAX_DEV-1
+ *
+ ***************************************************************************/
+
+static struct device_info devices[UB_MAX_DEV];
+
+struct device_info * ub_dev_get(int i)
+{
+ return ((i < 0 || i >= UB_MAX_DEV) ? NULL : &devices[i]);
+}
+
+/*
+ * Enumerates the devices: fills out device_info elements in the devices[]
+ * array.
+ *
+ * returns: number of devices found
+ */
+int ub_dev_enum(void)
+{
+ struct device_info *di;
+ int n = 0;
+
+ memset(&devices, 0, sizeof(struct device_info) * UB_MAX_DEV);
+ di = &devices[0];
+
+ if (!syscall(API_DEV_ENUM, NULL, di))
+ return 0;
+
+ while (di->cookie != NULL) {
+
+ if (++n >= UB_MAX_DEV)
+ break;
+
+ /* take another device_info */
+ di++;
+
+ /* pass on the previous cookie */
+ di->cookie = devices[n - 1].cookie;
+
+ if (!syscall(API_DEV_ENUM, NULL, di))
+ return 0;
+ }
+
+ return n;
+}
+
+/*
+ * handle: 0-based id of the device
+ *
+ * returns: 0 when OK, err otherwise
+ */
+int ub_dev_open(int handle)
+{
+ struct device_info *di;
+ int err = 0;
+
+ if (handle < 0 || handle >= UB_MAX_DEV)
+ return API_EINVAL;
+
+ di = &devices[handle];
+
+ if (!syscall(API_DEV_OPEN, &err, di))
+ return -1;
+
+ return err;
+}
+
+int ub_dev_close(int handle)
+{
+ struct device_info *di;
+
+ if (handle < 0 || handle >= UB_MAX_DEV)
+ return API_EINVAL;
+
+ di = &devices[handle];
+ if (!syscall(API_DEV_CLOSE, NULL, di))
+ return -1;
+
+ return 0;
+}
+
+/*
+ *
+ * Validates device for read/write, it has to:
+ *
+ * - have sane handle
+ * - be opened
+ *
+ * returns: 0/1 accordingly
+ */
+static int dev_valid(int handle)
+{
+ if (handle < 0 || handle >= UB_MAX_DEV)
+ return 0;
+
+ if (devices[handle].state != DEV_STA_OPEN)
+ return 0;
+
+ return 1;
+}
+
+static int dev_stor_valid(int handle)
+{
+ if (!dev_valid(handle))
+ return 0;
+
+ if (!(devices[handle].type & DEV_TYP_STOR))
+ return 0;
+
+ return 1;
+}
+
+int ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start,
+ lbasize_t *rlen)
+{
+ struct device_info *di;
+ lbasize_t act_len;
+ int err = 0;
+
+ if (!dev_stor_valid(handle))
+ return API_ENODEV;
+
+ di = &devices[handle];
+ if (!syscall(API_DEV_READ, &err, di, buf, &len, &start, &act_len))
+ return API_ESYSC;
+
+ if (!err && rlen)
+ *rlen = act_len;
+
+ return err;
+}
+
+static int dev_net_valid(int handle)
+{
+ if (!dev_valid(handle))
+ return 0;
+
+ if (devices[handle].type != DEV_TYP_NET)
+ return 0;
+
+ return 1;
+}
+
+int ub_dev_recv(int handle, void *buf, int len, int *rlen)
+{
+ struct device_info *di;
+ int err = 0, act_len;
+
+ if (!dev_net_valid(handle))
+ return API_ENODEV;
+
+ di = &devices[handle];
+ if (!syscall(API_DEV_READ, &err, di, buf, &len, &act_len))
+ return API_ESYSC;
+
+ if (!err && rlen)
+ *rlen = act_len;
+
+ return (err);
+}
+
+int ub_dev_send(int handle, void *buf, int len)
+{
+ struct device_info *di;
+ int err = 0;
+
+ if (!dev_net_valid(handle))
+ return API_ENODEV;
+
+ di = &devices[handle];
+ if (!syscall(API_DEV_WRITE, &err, di, buf, &len))
+ return API_ESYSC;
+
+ return err;
+}
+
+/****************************************
+ *
+ * env vars
+ *
+ ****************************************/
+
+char * ub_env_get(const char *name)
+{
+ char *value;
+
+ if (!syscall(API_ENV_GET, NULL, (uint32_t)name, (uint32_t)&value))
+ return NULL;
+
+ return value;
+}
+
+void ub_env_set(const char *name, char *value)
+{
+ syscall(API_ENV_SET, NULL, (uint32_t)name, (uint32_t)value);
+}
+
+static char env_name[256];
+
+const char * ub_env_enum(const char *last)
+{
+ const char *env, *str;
+ int i;
+
+ env = NULL;
+
+ /*
+ * It's OK to pass only the name piece as last (and not the whole
+ * 'name=val' string), since the API_ENUM_ENV call uses envmatch()
+ * internally, which handles such case
+ */
+ if (!syscall(API_ENV_ENUM, NULL, (uint32_t)last, (uint32_t)&env))
+ return NULL;
+
+ if (!env)
+ /* no more env. variables to enumerate */
+ return NULL;
+
+ /* next enumerated env var */
+ memset(env_name, 0, 256);
+ for (i = 0, str = env; *str != '=' && *str != '\0';)
+ env_name[i++] = *str++;
+
+ env_name[i] = '\0';
+
+ return env_name;
+}
diff --git a/examples/api/glue.h b/examples/api/glue.h
new file mode 100644
index 0000000..6bf47d0
--- /dev/null
+++ b/examples/api/glue.h
@@ -0,0 +1,80 @@
+/*
+ * (C) Copyright 2007 Semihalf
+ *
+ * Written by: Rafal Jaworowski <raj@semihalf.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+/*
+ * This is the header file for conveniency wrapper routines (API glue)
+ */
+
+#ifndef _API_GLUE_H_
+#define _API_GLUE_H_
+
+#define API_SEARCH_LEN (3 * 1024 * 1024) /* 3MB search range */
+
+#define UB_MAX_MR 5 /* max mem regions number */
+#define UB_MAX_DEV 6 /* max devices number */
+
+extern void *syscall_ptr;
+extern uint32_t search_hint;
+
+int syscall(int, int *, ...);
+int api_search_sig(struct api_signature **sig);
+
+/*
+ * The ub_ library calls are part of the application, not U-Boot code! They
+ * are front-end wrappers that are used by the consumer application: they
+ * prepare arguments for particular syscall and jump to the low level
+ * syscall()
+ */
+
+/* console */
+int ub_getc(void);
+int ub_tstc(void);
+void ub_putc(char c);
+void ub_puts(const char *s);
+
+/* system */
+void ub_reset(void);
+struct sys_info * ub_get_sys_info(void);
+
+/* time */
+void ub_udelay(unsigned long);
+unsigned long ub_get_timer(unsigned long);
+
+/* env vars */
+char * ub_env_get(const char *name);
+void ub_env_set(const char *name, char *value);
+const char * ub_env_enum(const char *last);
+
+/* devices */
+int ub_dev_enum(void);
+int ub_dev_open(int handle);
+int ub_dev_close(int handle);
+int ub_dev_read(int handle, void *buf, lbasize_t len,
+ lbastart_t start, lbasize_t *rlen);
+int ub_dev_send(int handle, void *buf, int len);
+int ub_dev_recv(int handle, void *buf, int len, int *rlen);
+struct device_info * ub_dev_get(int);
+
+#endif /* _API_GLUE_H_ */
diff --git a/examples/api/libgenwrap.c b/examples/api/libgenwrap.c
new file mode 100644
index 0000000..2b62bad
--- /dev/null
+++ b/examples/api/libgenwrap.c
@@ -0,0 +1,95 @@
+/*
+ * (C) Copyright 2007 Semihalf
+ *
+ * Written by: Rafal Jaworowski <raj@semihalf.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * This is is a set of wrappers/stubs that allow to use certain routines from
+ * U-Boot's lib_generic in the standalone app. This way way we can re-use
+ * existing code e.g. operations on strings and similar.
+ *
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <api_public.h>
+
+#include "glue.h"
+
+/*
+ * printf() and vprintf() are stolen from u-boot/common/console.c
+ */
+void printf (const char *fmt, ...)
+{
+ va_list args;
+ uint i;
+ char printbuffer[256];
+
+ va_start (args, fmt);
+
+ /* For this to work, printbuffer must be larger than
+ * anything we ever want to print.
+ */
+ i = vsprintf (printbuffer, fmt, args);
+ va_end (args);
+
+ /* Print the string */
+ ub_puts (printbuffer);
+}
+
+void vprintf (const char *fmt, va_list args)
+{
+ uint i;
+ char printbuffer[256];
+
+ /* For this to work, printbuffer must be larger than
+ * anything we ever want to print.
+ */
+ i = vsprintf (printbuffer, fmt, args);
+
+ /* Print the string */
+ ub_puts (printbuffer);
+}
+
+void putc (const char c)
+{
+ ub_putc(c);
+}
+
+void udelay(unsigned long usec)
+{
+ ub_udelay(usec);
+}
+
+void do_reset (void)
+{
+ ub_reset();
+}
+
+void *malloc (size_t len)
+{
+ return NULL;
+}
+
+void hang (void)
+{
+ while (1) ;
+}
diff --git a/examples/.gitignore b/examples/standalone/.gitignore
index 0d1864c..0d1864c 100644
--- a/examples/.gitignore
+++ b/examples/standalone/.gitignore
diff --git a/examples/82559_eeprom.c b/examples/standalone/82559_eeprom.c
index 5e2eee9..5e2eee9 100644
--- a/examples/82559_eeprom.c
+++ b/examples/standalone/82559_eeprom.c
diff --git a/examples/Makefile b/examples/standalone/Makefile
index dbcfa92..dbcfa92 100644
--- a/examples/Makefile
+++ b/examples/standalone/Makefile
diff --git a/examples/README.smc91111_eeprom b/examples/standalone/README.smc91111_eeprom
index 28e7e69..28e7e69 100644
--- a/examples/README.smc91111_eeprom
+++ b/examples/standalone/README.smc91111_eeprom
diff --git a/examples/eepro100_eeprom.c b/examples/standalone/eepro100_eeprom.c
index 2b15d05..2b15d05 100644
--- a/examples/eepro100_eeprom.c
+++ b/examples/standalone/eepro100_eeprom.c
diff --git a/examples/hello_world.c b/examples/standalone/hello_world.c
index 9317f6d..9317f6d 100644
--- a/examples/hello_world.c
+++ b/examples/standalone/hello_world.c
diff --git a/examples/interrupt.c b/examples/standalone/interrupt.c
index f3061d1..f3061d1 100644
--- a/examples/interrupt.c
+++ b/examples/standalone/interrupt.c
diff --git a/examples/mem_to_mem_idma2intr.c b/examples/standalone/mem_to_mem_idma2intr.c
index 15779d0..15779d0 100644
--- a/examples/mem_to_mem_idma2intr.c
+++ b/examples/standalone/mem_to_mem_idma2intr.c
diff --git a/examples/mips.lds b/examples/standalone/mips.lds
index 717b201..717b201 100644
--- a/examples/mips.lds
+++ b/examples/standalone/mips.lds
diff --git a/examples/nios.lds b/examples/standalone/nios.lds
index 4c1080b..4c1080b 100644
--- a/examples/nios.lds
+++ b/examples/standalone/nios.lds
diff --git a/examples/nios2.lds b/examples/standalone/nios2.lds
index a3e5ea8..a3e5ea8 100644
--- a/examples/nios2.lds
+++ b/examples/standalone/nios2.lds
diff --git a/examples/ppc_longjmp.S b/examples/standalone/ppc_longjmp.S
index 5ca6f6f..5ca6f6f 100644
--- a/examples/ppc_longjmp.S
+++ b/examples/standalone/ppc_longjmp.S
diff --git a/examples/ppc_setjmp.S b/examples/standalone/ppc_setjmp.S
index 421abfd..421abfd 100644
--- a/examples/ppc_setjmp.S
+++ b/examples/standalone/ppc_setjmp.S
diff --git a/examples/sched.c b/examples/standalone/sched.c
index b32766f..b32766f 100644
--- a/examples/sched.c
+++ b/examples/standalone/sched.c
diff --git a/examples/smc91111_eeprom.c b/examples/standalone/smc91111_eeprom.c
index 39e5306..39e5306 100644
--- a/examples/smc91111_eeprom.c
+++ b/examples/standalone/smc91111_eeprom.c
diff --git a/examples/smc911x_eeprom.c b/examples/standalone/smc911x_eeprom.c
index bf22f0a..bf22f0a 100644
--- a/examples/smc911x_eeprom.c
+++ b/examples/standalone/smc911x_eeprom.c
diff --git a/examples/sparc.lds b/examples/standalone/sparc.lds
index 9733daa..9733daa 100644
--- a/examples/sparc.lds
+++ b/examples/standalone/sparc.lds
diff --git a/examples/stubs.c b/examples/standalone/stubs.c
index a8cb954..a8cb954 100644
--- a/examples/stubs.c
+++ b/examples/standalone/stubs.c
diff --git a/examples/test_burst.c b/examples/standalone/test_burst.c
index 7109c09..7109c09 100644
--- a/examples/test_burst.c
+++ b/examples/standalone/test_burst.c
diff --git a/examples/test_burst.h b/examples/standalone/test_burst.h
index f85928c..f85928c 100644
--- a/examples/test_burst.h
+++ b/examples/standalone/test_burst.h
diff --git a/examples/test_burst_lib.S b/examples/standalone/test_burst_lib.S
index aef4e32..aef4e32 100644
--- a/examples/test_burst_lib.S
+++ b/examples/standalone/test_burst_lib.S
diff --git a/examples/timer.c b/examples/standalone/timer.c
index 6628b21..6628b21 100644
--- a/examples/timer.c
+++ b/examples/standalone/timer.c
diff --git a/examples/x86-testapp.c b/examples/standalone/x86-testapp.c
index e8603d9..e8603d9 100644
--- a/examples/x86-testapp.c
+++ b/examples/standalone/x86-testapp.c