X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=api%2Fapi.c;h=c7f5db776af9d9e80fe1ac7fcb6718627d48589f;hb=c05ed00afb95fa5237f16962fccf5810437317bf;hp=4fae95d2801db2d1d7e304559630500949d405db;hpb=5cc9e6b7fa4fac8dc7b709af3bd6f259171ff0bb;p=oweals%2Fu-boot.git diff --git a/api/api.c b/api/api.c index 4fae95d280..c7f5db776a 100644 --- a/api/api.c +++ b/api/api.c @@ -1,18 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2007 Semihalf * * Written by: Rafal Jaworowski - * - * SPDX-License-Identifier: GPL-2.0+ */ #include #include #include +#include #include -#include +#include +#include #include #include +#include #include "api_private.h" @@ -295,27 +297,31 @@ static int API_dev_close(va_list ap) /* - * Notice: this is for sending network packets only, as U-Boot does not - * support writing to storage at the moment (12.2007) - * * pseudo signature: * * int API_dev_write( * struct device_info *di, * void *buf, - * int *len + * int *len, + * unsigned long *start * ) * * buf: ptr to buffer from where to get the data to send * - * len: length of packet to be sent (in bytes) + * len: ptr to length to be read + * - network: len of packet to be sent (in bytes) + * - storage: # of blocks to write (can vary in size depending on define) * + * start: ptr to start block (only used for storage devices, ignored for + * network) */ static int API_dev_write(va_list ap) { struct device_info *di; void *buf; - int *len; + lbasize_t *len_stor, act_len_stor; + lbastart_t *start; + int *len_net; int err = 0; /* 1. arg is ptr to the device_info struct */ @@ -333,23 +339,36 @@ static int API_dev_write(va_list ap) if (buf == NULL) return API_EINVAL; - /* 3. arg is length of buffer */ - len = (int *)va_arg(ap, uintptr_t); - if (len == NULL) - return API_EINVAL; - if (*len <= 0) - return API_EINVAL; + if (di->type & DEV_TYP_STOR) { + /* 3. arg - ptr to var with # of blocks to write */ + len_stor = (lbasize_t *)va_arg(ap, uintptr_t); + if (!len_stor) + return API_EINVAL; + if (*len_stor <= 0) + return API_EINVAL; - if (di->type & DEV_TYP_STOR) - /* - * write to storage is currently not supported by U-Boot: - * no storage device implements block_write() method - */ - return API_ENODEV; + /* 4. arg - ptr to var with start block */ + start = (lbastart_t *)va_arg(ap, uintptr_t); - else if (di->type & DEV_TYP_NET) - err = dev_write_net(di->cookie, buf, *len); - else + act_len_stor = dev_write_stor(di->cookie, buf, *len_stor, *start); + if (act_len_stor != *len_stor) { + debugf("write @ %llu: done %llu out of %llu blocks", + (uint64_t)blk, (uint64_t)act_len_stor, + (uint64_t)len_stor); + return API_EIO; + } + + } else if (di->type & DEV_TYP_NET) { + /* 3. arg points to the var with length of packet to write */ + len_net = (int *)va_arg(ap, uintptr_t); + if (!len_net) + return API_EINVAL; + if (*len_net <= 0) + return API_EINVAL; + + err = dev_write_net(di->cookie, buf, *len_net); + + } else err = API_ENODEV; return err; @@ -458,7 +477,7 @@ static int API_env_get(va_list ap) if ((value = (char **)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - *value = getenv(name); + *value = env_get(name); return 0; } @@ -481,7 +500,7 @@ static int API_env_set(va_list ap) if ((value = (char *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - setenv(name, value); + env_set(name, value); return 0; } @@ -497,7 +516,7 @@ static int API_env_enum(va_list ap) { int i, buflen; char *last, **next, *s; - ENTRY *match, search; + struct env_entry *match, search; static char *var; last = (char *)va_arg(ap, unsigned long); @@ -514,7 +533,7 @@ static int API_env_enum(va_list ap) if (s != NULL) *s = 0; search.key = var; - i = hsearch_r(search, FIND, &match, &env_htab, 0); + i = hsearch_r(search, ENV_FIND, &match, &env_htab, 0); if (i == 0) { i = API_EINVAL; goto done; @@ -663,7 +682,7 @@ void api_init(void) return; } - setenv_hex("api_address", (unsigned long)sig); + env_set_hex("api_address", (unsigned long)sig); debugf("API sig @ 0x%lX\n", (unsigned long)sig); memcpy(sig->magic, API_SIG_MAGIC, 8); sig->version = API_SIG_VERSION;