diff options
author | Rafal Jaworowski <raj@semihalf.com> | 2008-01-09 19:39:36 +0100 |
---|---|---|
committer | Rafal Jaworowski <raj@semihalf.com> | 2008-01-09 19:39:36 +0100 |
commit | 500856eb1707ed17d9204baa61dd59948d3b2899 (patch) | |
tree | e29338498cbf1b92ad496271e65934b890115545 /api_examples | |
parent | 26a41790f8eba19ad450e18ae91351daf485b3e2 (diff) | |
download | u-boot-imx-500856eb1707ed17d9204baa61dd59948d3b2899.zip u-boot-imx-500856eb1707ed17d9204baa61dd59948d3b2899.tar.gz u-boot-imx-500856eb1707ed17d9204baa61dd59948d3b2899.tar.bz2 |
API for external applications.
This is an API for external (standalone) applications running on top of
U-Boot, and is meant to be more extensible and robust than the existing
jumptable mechanism. It is similar to UNIX syscall approach. See api/README
for more details.
Included is the demo application using this new framework (api_examples).
Please note this is still an experimental feature, and is turned off by
default.
Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Diffstat (limited to 'api_examples')
-rw-r--r-- | api_examples/Makefile | 103 | ||||
-rw-r--r-- | api_examples/crt0.S | 50 | ||||
-rw-r--r-- | api_examples/demo.c | 258 | ||||
-rw-r--r-- | api_examples/glue.c | 405 | ||||
-rw-r--r-- | api_examples/glue.h | 76 | ||||
-rw-r--r-- | api_examples/libgenwrap.c | 90 |
6 files changed, 982 insertions, 0 deletions
diff --git a/api_examples/Makefile b/api_examples/Makefile new file mode 100644 index 0000000..5812bcd --- /dev/null +++ b/api_examples/Makefile @@ -0,0 +1,103 @@ +# +# (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 = 0xc100000 +#endif + +include $(TOPDIR)/config.mk + +ELF += demo +BIN += demo.bin + +#CFLAGS += -v + +COBJS := $(ELF:=.o) +SOBJS := crt0.o +ifeq ($(ARCH),ppc) +SOBJS += ppcstring.o +endif + +LIB = $(obj)libglue.a +LIBCOBJS= glue.o crc32.o ctype.o string.o vsprintf.o libgenwrap.o + +LIBOBJS = $(addprefix $(obj),$(SOBJS) $(LIBCOBJS)) + +SRCS := $(COBJS:.o=.c) $(LIBCOBJS:.o=.c) $(SOBJS:.o=.S) +OBJS := $(addprefix $(obj),$(COBJS)) +ELF := $(addprefix $(obj),$(ELF)) +BIN := $(addprefix $(obj),$(BIN)) + +gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`) + +CPPFLAGS += -I.. + +all: $(obj).depend $(OBJS) $(LIB) $(BIN) $(ELF) + +######################################################################### +$(LIB): $(obj).depend $(LIBOBJS) + $(AR) $(ARFLAGS) $@ $(LIBOBJS) + +$(ELF): +$(obj)%: $(obj)%.o $(LIB) + $(LD) $(obj)crt0.o -Ttext $(LOAD_ADDR) \ + -o $@ $< $(LIB) \ + -L$(gcclibdir) -lgcc + +$(BIN): +$(obj)%.bin: $(obj)% + $(OBJCOPY) -O binary $< $@ 2>/dev/null + +$(obj)crc32.c: + @rm -f $(obj)crc32.c + ln -s $(src)../lib_generic/crc32.c $(obj)crc32.c + +$(obj)ctype.c: + @rm -f $(obj)ctype.c + ln -s $(src)../lib_generic/ctype.c $(obj)ctype.c + +$(obj)string.c: + @rm -f $(obj)string.c + ln -s $(src)../lib_generic/string.c $(obj)string.c + +$(obj)vsprintf.c: + @rm -f $(obj)vsprintf.c + ln -s $(src)../lib_generic/vsprintf.c $(obj)vsprintf.c + +ifeq ($(ARCH),ppc) +$(obj)ppcstring.S: + @rm -f $(obj)ppcstring.S + ln -s $(src)../lib_ppc/ppcstring.S $(obj)ppcstring.S +endif + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/api_examples/crt0.S b/api_examples/crt0.S new file mode 100644 index 0000000..8d4f706 --- /dev/null +++ b/api_examples/crt0.S @@ -0,0 +1,50 @@ +/* + * (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: + b main + + + .globl syscall +syscall: + lis %r11, syscall_ptr@ha + addi %r11, %r11, syscall_ptr@l + lwz %r11, 0(%r11) + mtctr %r11 + bctr + + + .globl syscall_ptr +syscall_ptr: + .align 4 + .long 0 +#else +#error No support for this arch! +#endif diff --git a/api_examples/demo.c b/api_examples/demo.c new file mode 100644 index 0000000..a4aeef1 --- /dev/null +++ b/api_examples/demo.c @@ -0,0 +1,258 @@ +/* + * (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 + * + */ + +#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) + +void test_dump_si(struct sys_info *); +void test_dump_di(int); +void test_dump_sig(struct api_signature *); + +char buf[2048]; + +#define WAIT_SECS 5 + +int main(int argc, char *argv[]) +{ + int rv = 0; + int h, i, j; + int devs_no; + struct api_signature *sig = NULL; + ulong start, now; + struct device_info *di; + + 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", sig); + test_dump_sig(sig); + + printf("\n*** Consumer API test ***\n"); + printf("syscall ptr 0x%08x@%08x\n", syscall_ptr, &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 { + if ((rv = ub_dev_open(i)) != 0) + errf("open device %d error %d\n", i, rv); + else if ((rv = ub_dev_read(i, &buf, 200, 20)) != 0) + errf("could not read from device %d, error %d\n", i, rv); + + 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 */ + 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", sig->syscall); +} + +void test_dump_si(struct sys_info *si) +{ + int i; + + printf("sys info:\n"); + printf(" clkbus\t= 0x%08x\n", si->clk_bus); + printf(" clkcpu\t= 0x%08x\n", si->clk_cpu); + printf(" bar\t\t= 0x%08x\n", 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_SCSI) + return "SCSI"; + + if (type & DT_STOR_USB) + return "USB"; + + if (type & DT_STOR_MMC); + return "MMC"; + + return "Unknown"; +} + +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", di->di_stor.block_size); + printf(" blk count\t\t= %d\n", di->di_stor.block_count); + } +} diff --git a/api_examples/glue.c b/api_examples/glue.c new file mode 100644 index 0000000..7598369 --- /dev/null +++ b/api_examples/glue.c @@ -0,0 +1,405 @@ +/* + * (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 + * + */ + +#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; + + if (sig == NULL) + return 0; + + sp = (unsigned char *)API_SEARCH_START; + + while ((sp + (int)API_SIG_MAGLEN) < (unsigned char *)API_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); +} + +#define MR_MAX 5 +static struct mem_region mr[MR_MAX]; +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 = MR_MAX; + 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, ..., MAX_DEVS-1 + * + ***************************************************************************/ + +#define MAX_DEVS 6 + +static struct device_info devices[MAX_DEVS]; + +struct device_info * ub_dev_get(int i) +{ + return ((i < 0 || i >= MAX_DEVS) ? 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) * MAX_DEVS); + di = &devices[0]; + + if (!syscall(API_DEV_ENUM, NULL, di)) + return 0; + + while (di->cookie != NULL) { + + if (++n >= MAX_DEVS) + 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 >= MAX_DEVS) + 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 >= MAX_DEVS) + 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 >= MAX_DEVS) + 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) +{ + 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 -1; + + if (err) + return err; + + if (act_len != len) + return API_EIO; + + return 0; +} + +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) +{ + 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 -1; + + if (err) + return -1; + + return act_len; +} + +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 -1; + + 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/api_examples/glue.h b/api_examples/glue.h new file mode 100644 index 0000000..a82f783 --- /dev/null +++ b/api_examples/glue.h @@ -0,0 +1,76 @@ +/* + * (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_START (255 * 1024 * 1024) /* start at 1MB below top RAM */ +#define API_SEARCH_END (256 * 1024 * 1024 - 1) /* ...and search to the end */ + +int syscall(int, int *, ...); +void * syscall_ptr; + +int api_search_sig(struct api_signature **sig); + +/* + * 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); +int ub_dev_send(int handle, void *buf, int len); +int ub_dev_recv(int handle, void *buf, int len); +struct device_info * ub_dev_get(int); + +#endif /* _API_GLUE_H_ */ diff --git a/api_examples/libgenwrap.c b/api_examples/libgenwrap.c new file mode 100644 index 0000000..df62633 --- /dev/null +++ b/api_examples/libgenwrap.c @@ -0,0 +1,90 @@ +/* + * (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; +} |