diff options
author | Peter Tyser <ptyser@xes-inc.com> | 2009-07-20 19:02:21 -0500 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2009-07-21 09:23:36 +0200 |
commit | d4abc757c26c531293f5bbc4262ade44a317eec9 (patch) | |
tree | 125ef9d60654aafbf8c413cb8379957e14917196 /examples | |
parent | af1d7d984a23a0faa1f436ebfeb55c876b1a99e1 (diff) |
Move api_examples to examples/api
Also add a rule to remove demo.bin which was previously leftover
after a "make clean"
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/api/.gitignore | 2 | ||||
-rw-r--r-- | examples/api/Makefile | 90 | ||||
-rw-r--r-- | examples/api/crt0.S | 71 | ||||
-rw-r--r-- | examples/api/demo.c | 300 | ||||
-rw-r--r-- | examples/api/glue.c | 404 | ||||
-rw-r--r-- | examples/api/glue.h | 80 | ||||
-rw-r--r-- | examples/api/libgenwrap.c | 95 |
7 files changed, 1042 insertions, 0 deletions
diff --git a/examples/api/.gitignore b/examples/api/.gitignore new file mode 100644 index 00000000000..d7b18dcef5f --- /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 00000000000..2d05a0121e7 --- /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 00000000000..6daf127893f --- /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 00000000000..df9c4bd8bc8 --- /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 00000000000..eff6a7e62f5 --- /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 00000000000..6bf47d07c8f --- /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 00000000000..2b62badfb88 --- /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) ; +} |