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)
This commit is contained in:
Rafal Jaworowski 2008-10-04 13:10:38 +00:00
parent 243e1539f3
commit 4c0a9db94a
4 changed files with 45 additions and 42 deletions

View File

@ -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 *, ...);

View File

@ -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);
}

View File

@ -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);

View File

@ -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)
{