diff options
author | Anup Patel <anup.patel@wdc.com> | 2019-01-18 10:28:58 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2019-01-18 10:47:30 +0530 |
commit | ebfe23125666a11fd3dc14b85f5ca58b7f40276b (patch) | |
tree | eacf671042d394bcb6e615cc9c7278c1349153b3 | |
parent | e0686ca844f6c7372edd353cffe08ddee5dcf5c9 (diff) |
platform: Fix compile error caused by standard includes
Avoid using standard includes namely stdint.h, string.h, stdlib.h, etc.
All standard include except stddef.h give compilation error due
to differences in RISC-V toolchain configuration. Typically, the
compilation error is related to "gnu-stubs-lp64.h".
This patch fixes compile error caused by standard includes by
providing substitutes of definetions provided by standard includes
wherever required.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
-rw-r--r-- | platform/common/include/plat/string.h | 39 | ||||
-rw-r--r-- | platform/common/irqchip/plic.c | 2 | ||||
-rw-r--r-- | platform/common/libc/string.c | 22 | ||||
-rw-r--r-- | platform/common/libfdt/libfdt_env.h | 10 | ||||
-rw-r--r-- | platform/common/tinyfdt.c | 2 |
5 files changed, 60 insertions, 15 deletions
diff --git a/platform/common/include/plat/string.h b/platform/common/include/plat/string.h new file mode 100644 index 0000000..ab09f4e --- /dev/null +++ b/platform/common/include/plat/string.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra <atish.patra@wdc.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifndef __STRING_H__ +#define __STRING_H__ + +#include <sbi/sbi_types.h> + +int strcmp(const char *a, const char *b); + +size_t strlen(const char *str); + +size_t strnlen(const char *str, size_t count); + +char *strcpy(char *dest,const char *src); + +char *strncpy(char *dest, const char *src, size_t count); + +char *strchr(const char *s, int c); + +char *strrchr(const char *s, int c); + +void *memset(void *s,int c,size_t count); + +void *memcpy(void *dest, const void *src, size_t count); + +void *memmove(void *dest,const void *src, size_t count); + +int memcmp(const void *s1,const void *s2, size_t count); + +void *memchr(const void *s, int c, size_t count); + +#endif diff --git a/platform/common/irqchip/plic.c b/platform/common/irqchip/plic.c index 59265cf..ce2aafc 100644 --- a/platform/common/irqchip/plic.c +++ b/platform/common/irqchip/plic.c @@ -10,9 +10,9 @@ #include <sbi/riscv_io.h> #include <sbi/riscv_encoding.h> #include <sbi/sbi_console.h> +#include <plat/string.h> #include <plat/tinyfdt.h> #include <plat/irqchip/plic.h> -#include <string.h> #define PLIC_PRIORITY_BASE 0x0 #define PLIC_PENDING_BASE 0x1000 diff --git a/platform/common/libc/string.c b/platform/common/libc/string.c index cb467a6..9c09445 100644 --- a/platform/common/libc/string.c +++ b/platform/common/libc/string.c @@ -12,12 +12,13 @@ * bugs as well. Use any optimized routines from newlib or glibc if required. */ -#include <string.h> +#include <plat/string.h> int strcmp(const char *a, const char *b) { /* search first diff or end of string */ for (; *a == *b && *a != '\0'; a++, b++); + return *a - *b; } @@ -46,7 +47,7 @@ size_t strnlen(const char *str, size_t count) return ret; } -char * strcpy(char * dest,const char *src) +char *strcpy(char *dest, const char *src) { char *ret = dest; @@ -57,7 +58,7 @@ char * strcpy(char * dest,const char *src) return ret; } -char * strncpy(char * dest,const char *src,size_t count) +char *strncpy(char *dest, const char *src, size_t count) { char *ret = dest; @@ -68,7 +69,7 @@ char * strncpy(char * dest,const char *src,size_t count) return ret; } -char * strchr(const char * s, int c) +char *strchr(const char *s, int c) { while(*s != '\0' && *s != (char)c) s++; @@ -79,7 +80,7 @@ char * strchr(const char * s, int c) return (char *)s; } -char * strrchr(const char * s, int c) +char *strrchr(const char *s, int c) { const char *last = s + strlen(s); @@ -91,7 +92,7 @@ char * strrchr(const char * s, int c) else return (char *)last; } -void * memset(void * s,int c,size_t count) +void *memset(void *s, int c, size_t count) { char *temp = s; @@ -103,7 +104,7 @@ void * memset(void * s,int c,size_t count) return s; } -void * memcpy(void *dest, const void *src, size_t count) +void *memcpy(void *dest, const void *src, size_t count) { char *temp1 = dest; const char *temp2 = src; @@ -116,7 +117,7 @@ void * memcpy(void *dest, const void *src, size_t count) return dest; } -void * memmove(void * dest,const void *src,size_t count) +void *memmove(void *dest, const void *src, size_t count) { char *temp1 = (char *)dest; const char *temp2 = (char *)src; @@ -138,13 +139,15 @@ void * memmove(void * dest,const void *src,size_t count) count--; } } + return dest; } -int memcmp(const void * s1,const void * s2,size_t count) +int memcmp(const void *s1, const void *s2, size_t count) { const char *temp1 = s1; const char *temp2 = s2; + for (; count > 0 && (*temp1 == *temp2); count--) { temp1++; temp2++; @@ -166,5 +169,6 @@ void *memchr(const void *s, int c, size_t count) } count--; } + return NULL; } diff --git a/platform/common/libfdt/libfdt_env.h b/platform/common/libfdt/libfdt_env.h index eb20538..235a1fc 100644 --- a/platform/common/libfdt/libfdt_env.h +++ b/platform/common/libfdt/libfdt_env.h @@ -52,11 +52,13 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <sbi/sbi_types.h> +#include <plat/string.h> + +#define INT_MAX ((int)(~0U >> 1)) +#define UINT_MAX ((unsigned int)~0U) + #include <stddef.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <limits.h> #ifdef __CHECKER__ #define FDT_FORCE __attribute__((force)) diff --git a/platform/common/tinyfdt.c b/platform/common/tinyfdt.c index a3c1fcf..c3bf210 100644 --- a/platform/common/tinyfdt.c +++ b/platform/common/tinyfdt.c @@ -7,8 +7,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <plat/string.h> #include <plat/tinyfdt.h> -#include <string.h> #define FDT_MAGIC 0xd00dfeed #define FDT_VERSION 17 |