diff options
author | raj <raj@FreeBSD.org> | 2008-10-04 13:10:38 +0000 |
---|---|---|
committer | raj <raj@FreeBSD.org> | 2008-10-04 13:10:38 +0000 |
commit | 2a77c29adae965cd014d2d82376d68280e2846a4 (patch) | |
tree | b761593699187a27c02dd46c0d6e88ccedafd035 /sys/boot | |
parent | aa0d5826064a4ef4cf0e7827a6b587eebc679f74 (diff) | |
download | FreeBSD-src-2a77c29adae965cd014d2d82376d68280e2846a4.zip FreeBSD-src-2a77c29adae965cd014d2d82376d68280e2846a4.tar.gz |
U-Boot API glue improvements:
- extend ub_dev_read() and ub_dev_recv() so that the actual len and
all error codes can be passed and processed properly; unify behaviour of
these routines
- introduce syscall general error code (API_ESYSC)
Diffstat (limited to 'sys/boot')
-rw-r--r-- | sys/boot/uboot/lib/api_public.h | 1 | ||||
-rw-r--r-- | sys/boot/uboot/lib/glue.c | 50 | ||||
-rw-r--r-- | sys/boot/uboot/lib/glue.h | 9 | ||||
-rw-r--r-- | sys/boot/uboot/lib/net.c | 27 |
4 files changed, 45 insertions, 42 deletions
diff --git a/sys/boot/uboot/lib/api_public.h b/sys/boot/uboot/lib/api_public.h index 0ec6129..9edf3af 100644 --- a/sys/boot/uboot/lib/api_public.h +++ b/sys/boot/uboot/lib/api_public.h @@ -62,6 +62,7 @@ #define API_ENOMEM 3 /* no memory */ #define API_EBUSY 4 /* busy, occupied etc. */ #define API_EIO 5 /* I/O error */ +#define API_ESYSC 6 /* syscall error */ typedef int (*scp_t)(int, int *, ...); diff --git a/sys/boot/uboot/lib/glue.c b/sys/boot/uboot/lib/glue.c index 0aca89c..ae5d1c0 100644 --- a/sys/boot/uboot/lib/glue.c +++ b/sys/boot/uboot/lib/glue.c @@ -216,9 +216,7 @@ ub_reset(void) syscall(API_RESET, NULL); } - -#define MR_MAX 5 -static struct mem_region mr[MR_MAX]; +static struct mem_region mr[UB_MAX_MR]; static struct sys_info si; struct sys_info * @@ -228,7 +226,7 @@ ub_get_sys_info(void) memset(&si, 0, sizeof(struct sys_info)); si.mr = mr; - si.mr_no = MR_MAX; + si.mr_no = UB_MAX_MR; memset(&mr, 0, sizeof(mr)); if (!syscall(API_GET_SYS_INFO, &err, (u_int32_t)&si)) @@ -267,19 +265,17 @@ ub_get_timer(unsigned long base) * * devices * - * Devices are identified by handles: numbers 0, 1, 2, ..., MAX_DEVS-1 + * Devices are identified by handles: numbers 0, 1, 2, ..., UB_MAX_DEV-1 * ***************************************************************************/ -#define MAX_DEVS 6 - -static struct device_info devices[MAX_DEVS]; +static struct device_info devices[UB_MAX_DEV]; struct device_info * ub_dev_get(int i) { - return ((i < 0 || i >= MAX_DEVS) ? NULL : &devices[i]); + return ((i < 0 || i >= UB_MAX_DEV) ? NULL : &devices[i]); } /* @@ -294,7 +290,7 @@ ub_dev_enum(void) struct device_info *di; int n = 0; - memset(&devices, 0, sizeof(struct device_info) * MAX_DEVS); + memset(&devices, 0, sizeof(struct device_info) * UB_MAX_DEV); di = &devices[0]; if (!syscall(API_DEV_ENUM, NULL, di)) @@ -302,7 +298,7 @@ ub_dev_enum(void) while (di->cookie != NULL) { - if (++n >= MAX_DEVS) + if (++n >= UB_MAX_DEV) break; /* take another device_info */ @@ -330,7 +326,7 @@ ub_dev_open(int handle) struct device_info *di; int err = 0; - if (handle < 0 || handle >= MAX_DEVS) + if (handle < 0 || handle >= UB_MAX_DEV) return (API_EINVAL); di = &devices[handle]; @@ -345,7 +341,7 @@ ub_dev_close(int handle) { struct device_info *di; - if (handle < 0 || handle >= MAX_DEVS) + if (handle < 0 || handle >= UB_MAX_DEV) return (API_EINVAL); di = &devices[handle]; @@ -367,7 +363,7 @@ static int dev_valid(int handle) { - if (handle < 0 || handle >= MAX_DEVS) + if (handle < 0 || handle >= UB_MAX_DEV) return (0); if (devices[handle].state != DEV_STA_OPEN) @@ -390,7 +386,8 @@ dev_stor_valid(int handle) } int -ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start) +ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start, + lbasize_t *rlen) { struct device_info *di; lbasize_t act_len; @@ -401,15 +398,12 @@ ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start) di = &devices[handle]; if (!syscall(API_DEV_READ, &err, di, buf, &len, &start, &act_len)) - return (-1); + return (API_ESYSC); - if (err) - return (err); + if (!err && rlen) + *rlen = act_len; - if (act_len != len) - return (API_EIO); - - return (0); + return (err); } static int @@ -426,7 +420,7 @@ dev_net_valid(int handle) } int -ub_dev_recv(int handle, void *buf, int len) +ub_dev_recv(int handle, void *buf, int len, int *rlen) { struct device_info *di; int err = 0, act_len; @@ -436,12 +430,12 @@ ub_dev_recv(int handle, void *buf, int len) di = &devices[handle]; if (!syscall(API_DEV_READ, &err, di, buf, &len, &act_len)) - return (-1); + return (API_ESYSC); - if (err) - return (-1); + if (!err) + *rlen = act_len; - return (act_len); + return (err); } int @@ -455,7 +449,7 @@ ub_dev_send(int handle, void *buf, int len) di = &devices[handle]; if (!syscall(API_DEV_WRITE, &err, di, buf, &len)) - return (-1); + return (API_ESYSC); return (err); } diff --git a/sys/boot/uboot/lib/glue.h b/sys/boot/uboot/lib/glue.h index 06944b2..674c960 100644 --- a/sys/boot/uboot/lib/glue.h +++ b/sys/boot/uboot/lib/glue.h @@ -40,6 +40,9 @@ void *syscall_ptr; int api_search_sig(struct api_signature **sig); +#define UB_MAX_MR 5 /* max mem regions number */ +#define UB_MAX_DEV 6 /* max devices number */ + /* * 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 @@ -70,10 +73,10 @@ const char *ub_env_enum(const char *last); 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_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 ub_dev_recv(int handle, void *buf, int len, int *rlen); struct device_info * ub_dev_get(int); void ub_dump_di(int); diff --git a/sys/boot/uboot/lib/net.c b/sys/boot/uboot/lib/net.c index 5902a1b..bef6898 100644 --- a/sys/boot/uboot/lib/net.c +++ b/sys/boot/uboot/lib/net.c @@ -173,35 +173,40 @@ net_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout) struct netif *nif = desc->io_netif; struct uboot_softc *sc = nif->nif_devdata; time_t t; - int length; + int err, rlen; #if defined(NETIF_DEBUG) printf("net_get: pkt %x, len %d, timeout %d\n", pkt, len, timeout); #endif t = getsecs(); do { - length = ub_dev_recv(sc->sc_handle, sc->sc_rxbuf, len); - } while ((length == -1 || length == 0) && - (getsecs() - t < timeout)); + err = ub_dev_recv(sc->sc_handle, sc->sc_rxbuf, len, &rlen); + + if (err != 0) { + printf("net_get: ub_dev_recv() failed, error=%d\n", + err); + rlen = 0; + break; + } + } while ((rlen == -1 || rlen == 0) && (getsecs() - t < timeout)); #if defined(NETIF_DEBUG) - printf("net_get: received len %d (%x)\n", length, length); + printf("net_get: received len %d (%x)\n", rlen, rlen); #endif - if (length > 0) { - memcpy(pkt, sc->sc_rxbuf, MIN(len, length)); - if (length != len) { + if (rlen > 0) { + memcpy(pkt, sc->sc_rxbuf, MIN(len, rlen)); + if (rlen != len) { #if defined(NETIF_DEBUG) - printf("net_get: len %x, length %x\n", len, length); + printf("net_get: len %x, rlen %x\n", len, rlen); #endif } - return (length); + return (rlen); } return (-1); } - static void net_init(struct iodesc *desc, void *machdep_hint) { |