diff options
author | Yang Zhang <yang.z.zhang@intel.com> | 2015-08-28 09:58:54 +0800 |
---|---|---|
committer | Yang Zhang <yang.z.zhang@intel.com> | 2015-09-01 12:44:00 +0800 |
commit | e44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch) | |
tree | 66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/u-boot/examples/api | |
parent | 9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff) |
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/u-boot/examples/api')
-rw-r--r-- | qemu/roms/u-boot/examples/api/.gitignore | 2 | ||||
-rw-r--r-- | qemu/roms/u-boot/examples/api/Makefile | 57 | ||||
-rw-r--r-- | qemu/roms/u-boot/examples/api/crt0.S | 54 | ||||
-rw-r--r-- | qemu/roms/u-boot/examples/api/demo.c | 314 | ||||
-rw-r--r-- | qemu/roms/u-boot/examples/api/glue.c | 418 | ||||
-rw-r--r-- | qemu/roms/u-boot/examples/api/glue.h | 68 | ||||
-rw-r--r-- | qemu/roms/u-boot/examples/api/libgenwrap.c | 80 |
7 files changed, 993 insertions, 0 deletions
diff --git a/qemu/roms/u-boot/examples/api/.gitignore b/qemu/roms/u-boot/examples/api/.gitignore new file mode 100644 index 000000000..d7b18dcef --- /dev/null +++ b/qemu/roms/u-boot/examples/api/.gitignore @@ -0,0 +1,2 @@ +demo +demo.bin diff --git a/qemu/roms/u-boot/examples/api/Makefile b/qemu/roms/u-boot/examples/api/Makefile new file mode 100644 index 000000000..6cf23d10a --- /dev/null +++ b/qemu/roms/u-boot/examples/api/Makefile @@ -0,0 +1,57 @@ +# +# (C) Copyright 2007 Semihalf +# +# SPDX-License-Identifier: GPL-2.0+ +# + +ifeq ($(ARCH),powerpc) +LOAD_ADDR = 0x40000 +endif +ifeq ($(ARCH),arm) +LOAD_ADDR = 0x1000000 +endif + +# Resulting ELF and binary exectuables will be named demo and demo.bin +extra-y = demo + +# Source files located in the examples/api directory +OBJ-y += crt0.o +OBJ-y += demo.o +OBJ-y += glue.o +OBJ-y += libgenwrap.o + +# Source files which exist outside the examples/api directory +EXT_COBJ-y += lib/crc32.o +EXT_COBJ-y += lib/ctype.o +EXT_COBJ-y += lib/div64.o +EXT_COBJ-y += lib/string.o +EXT_COBJ-y += lib/time.o +EXT_COBJ-y += lib/vsprintf.o +EXT_SOBJ-$(CONFIG_PPC) += arch/powerpc/lib/ppcstring.o + +# Create a list of object files to be compiled +OBJS := $(OBJ-y) $(notdir $(EXT_COBJ-y) $(EXT_SOBJ-y)) +targets += $(OBJS) +OBJS := $(addprefix $(obj)/,$(OBJS)) + +######################################################################### + +quiet_cmd_link_demo = LD $@ +cmd_link_demo = $(LD) --gc-sections -Ttext $(LOAD_ADDR) -o $@ $(filter-out $(PHONY), $^) $(PLATFORM_LIBS) + +$(obj)/demo: $(OBJS) FORCE + $(call if_changed,link_demo) + +# demo.bin is never genrated. Is this necessary? +OBJCOPYFLAGS_demo.bin := -O binary +$(obj)/demo.bin: $(obj)/demo FORCE + $(call if_changed,objcopy) + +# Rule to build generic library C files +$(addprefix $(obj)/,$(notdir $(EXT_COBJ-y))): $(obj)/%.o: lib/%.c FORCE + $(call cmd,force_checksrc) + $(call if_changed_rule,cc_o_c) + +# Rule to build architecture-specific library assembly files +$(addprefix $(obj)/,$(notdir $(EXT_SOBJ-y))): $(obj)/%.o: arch/powerpc/lib/%.S FORCE + $(call if_changed_dep,as_o_S) diff --git a/qemu/roms/u-boot/examples/api/crt0.S b/qemu/roms/u-boot/examples/api/crt0.S new file mode 100644 index 000000000..78d35a289 --- /dev/null +++ b/qemu/roms/u-boot/examples/api/crt0.S @@ -0,0 +1,54 @@ +/* + * (C) Copyright 2007 Semihalf + * + * Written by: Rafal Jaworowski <raj@semihalf.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#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/qemu/roms/u-boot/examples/api/demo.c b/qemu/roms/u-boot/examples/api/demo.c new file mode 100644 index 000000000..8c30457ce --- /dev/null +++ b/qemu/roms/u-boot/examples/api/demo.c @@ -0,0 +1,314 @@ +/* + * (C) Copyright 2007-2008 Semihalf + * + * Written by: Rafal Jaworowski <raj@semihalf.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#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 * const argv[]) +{ + int rv = 0, h, i, j, devs_no; + struct api_signature *sig = NULL; + ulong start, now; + struct device_info *di; + lbasize_t rlen; + struct display_info disinfo; + + 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)); + + printf("\n*** Display ***\n"); + + if (ub_display_get_info(DISPLAY_TYPE_LCD, &disinfo)) { + printf("LCD info: failed\n"); + } else { + printf("LCD info:\n"); + printf(" pixel width: %d\n", disinfo.pixel_width); + printf(" pixel height: %d\n", disinfo.pixel_height); + printf(" screen rows: %d\n", disinfo.screen_rows); + printf(" screen cols: %d\n", disinfo.screen_cols); + } + if (ub_display_get_info(DISPLAY_TYPE_VIDEO, &disinfo)) { + printf("video info: failed\n"); + } else { + printf("video info:\n"); + printf(" pixel width: %d\n", disinfo.pixel_width); + printf(" pixel height: %d\n", disinfo.pixel_height); + printf(" screen rows: %d\n", disinfo.screen_rows); + printf(" screen cols: %d\n", disinfo.screen_cols); + } + + printf("*** Press any key to continue ***\n"); + printf("got char 0x%x\n", ub_getc()); + + /* + * This only clears messages on screen, not on serial port. It is + * equivalent to a no-op if no display is available. + */ + ub_display_clear(); + + /* 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/qemu/roms/u-boot/examples/api/glue.c b/qemu/roms/u-boot/examples/api/glue.c new file mode 100644 index 000000000..d619518d4 --- /dev/null +++ b/qemu/roms/u-boot/examples/api/glue.c @@ -0,0 +1,418 @@ +/* + * (C) Copyright 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#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; +} + +/**************************************** + * + * display + * + ****************************************/ + +int ub_display_get_info(int type, struct display_info *di) +{ + int err = 0; + + if (!syscall(API_DISPLAY_GET_INFO, &err, (uint32_t)type, (uint32_t)di)) + return API_ESYSC; + + return err; +} + +int ub_display_draw_bitmap(ulong bitmap, int x, int y) +{ + int err = 0; + + if (!syscall(API_DISPLAY_DRAW_BITMAP, &err, bitmap, x, y)) + return API_ESYSC; + + return err; +} + +void ub_display_clear(void) +{ + syscall(API_DISPLAY_CLEAR, NULL); +} diff --git a/qemu/roms/u-boot/examples/api/glue.h b/qemu/roms/u-boot/examples/api/glue.h new file mode 100644 index 000000000..91c8c1ca6 --- /dev/null +++ b/qemu/roms/u-boot/examples/api/glue.h @@ -0,0 +1,68 @@ +/* + * (C) Copyright 2007 Semihalf + * + * Written by: Rafal Jaworowski <raj@semihalf.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * 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); + +/* display */ +int ub_display_get_info(int type, struct display_info *di); +int ub_display_draw_bitmap(ulong bitmap, int x, int y); +void ub_display_clear(void); + +#endif /* _API_GLUE_H_ */ diff --git a/qemu/roms/u-boot/examples/api/libgenwrap.c b/qemu/roms/u-boot/examples/api/libgenwrap.c new file mode 100644 index 000000000..c1afa5bc0 --- /dev/null +++ b/qemu/roms/u-boot/examples/api/libgenwrap.c @@ -0,0 +1,80 @@ +/* + * (C) Copyright 2007 Semihalf + * + * Written by: Rafal Jaworowski <raj@semihalf.com> + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This is is a set of wrappers/stubs that allow to use certain routines from + * U-Boot's lib 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 + */ +int 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); + return i; +} + +int 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); + return i; +} + +void putc (const char c) +{ + ub_putc(c); +} + +void __udelay(unsigned long usec) +{ + ub_udelay(usec); +} + +int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + ub_reset(); + return 0; +} + +void *malloc (size_t len) +{ + return NULL; +} + +void hang (void) +{ + while (1) ; +} |