You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/09/29 01:34:38 UTC
[31/49] incubator-mynewt-core git commit: directory re-org
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/mynewt.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/mynewt.c b/libs/baselibc/src/mynewt.c
deleted file mode 100644
index e35b39e..0000000
--- a/libs/baselibc/src/mynewt.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <stdio.h>
-#include <console/console.h>
-
-static size_t
-stdin_read(FILE *fp, char *bp, size_t n)
-{
- return 0;
-}
-
-static size_t
-stdout_write(FILE *fp, const char *bp, size_t n)
-{
- console_write(bp, n);
- return n;
-}
-
-static struct File_methods _stdin_methods = {
- .write = stdout_write,
- .read = stdin_read
-};
-
-static struct File _stdin = {
- .vmt = &_stdin_methods
-};
-
-struct File *const stdin = &_stdin;
-struct File *const stdout = &_stdin;
-struct File *const stderr = &_stdin;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/nrand48.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/nrand48.c b/libs/baselibc/src/nrand48.c
deleted file mode 100644
index cb3532b..0000000
--- a/libs/baselibc/src/nrand48.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * nrand48.c
- */
-
-#include <stdlib.h>
-#include <stdint.h>
-
-long nrand48(unsigned short xsubi[3])
-{
- return (long)((uint32_t) jrand48(xsubi) >> 1);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/qsort.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/qsort.c b/libs/baselibc/src/qsort.c
deleted file mode 100644
index 4c189fc..0000000
--- a/libs/baselibc/src/qsort.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * qsort.c
- *
- * This is actually combsort. It's an O(n log n) algorithm with
- * simplicity/small code size being its main virtue.
- */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-static inline size_t newgap(size_t gap)
-{
- gap = (gap * 10) / 13;
- if (gap == 9 || gap == 10)
- gap = 11;
-
- if (gap < 1)
- gap = 1;
- return gap;
-}
-
-void qsort(void *base, size_t nmemb, size_t size,
- int (*compar) (const void *, const void *))
-{
- size_t gap = nmemb;
- size_t i, j;
- char *p1, *p2;
- int swapped;
-
- if (!nmemb)
- return;
-
- do {
- gap = newgap(gap);
- swapped = 0;
-
- for (i = 0, p1 = base; i < nmemb - gap; i++, p1 += size) {
- j = i + gap;
- if (compar(p1, p2 = (char *)base + j * size) > 0) {
- memswap(p1, p2, size);
- swapped = 1;
- }
- }
- } while (gap > 1 || swapped);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/realloc.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/realloc.c b/libs/baselibc/src/realloc.c
deleted file mode 100644
index 77e8acb..0000000
--- a/libs/baselibc/src/realloc.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * realloc.c
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "malloc.h"
-
-/* FIXME: This is cheesy, it should be fixed later */
-
-void *realloc(void *ptr, size_t size)
-{
- struct free_arena_header *ah;
- void *newptr;
- size_t oldsize;
-
- if (!ptr)
- return malloc(size);
-
- if (size == 0) {
- free(ptr);
- return NULL;
- }
-
- /* Add the obligatory arena header, and round up */
- size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
-
- ah = (struct free_arena_header *)
- ((struct arena_header *)ptr - 1);
-
- if (ah->a.size >= size && size >= (ah->a.size >> 2)) {
- /* This field is a good size already. */
- return ptr;
- } else {
- /* Make me a new block. This is kind of bogus; we should
- be checking the following block to see if we can do an
- in-place adjustment... fix that later. */
-
- oldsize = ah->a.size - sizeof(struct arena_header);
-
- newptr = malloc(size);
- if(newptr) {
- memcpy(newptr, ptr, (size < oldsize) ? size : oldsize);
- }
- free(ptr);
-
- return newptr;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/sprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/sprintf.c b/libs/baselibc/src/sprintf.c
deleted file mode 100644
index c6d8758..0000000
--- a/libs/baselibc/src/sprintf.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * sprintf.c
- */
-
-#include <stdio.h>
-#include <unistd.h>
-
-int sprintf(char *buffer, const char *format, ...)
-{
- va_list ap;
- int rv;
-
- va_start(ap, format);
- rv = vsnprintf(buffer, ~(size_t) 0, format, ap);
- va_end(ap);
-
- return rv;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/srand48.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/srand48.c b/libs/baselibc/src/srand48.c
deleted file mode 100644
index e1c9567..0000000
--- a/libs/baselibc/src/srand48.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * srand48.c
- */
-
-#include <stdlib.h>
-#include <stdint.h>
-
-unsigned short __rand48_seed[3]; /* Common with mrand48.c, lrand48.c */
-
-void srand48(long seedval)
-{
- __rand48_seed[0] = 0x330e;
- __rand48_seed[1] = (unsigned short)seedval;
- __rand48_seed[2] = (unsigned short)((uint32_t) seedval >> 16);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/sscanf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/sscanf.c b/libs/baselibc/src/sscanf.c
deleted file mode 100644
index f53b276..0000000
--- a/libs/baselibc/src/sscanf.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * sscanf()
- */
-
-#include <stdio.h>
-
-int sscanf(const char *str, const char *format, ...)
-{
- va_list ap;
- int rv;
-
- va_start(ap, format);
- rv = vsscanf(str, format, ap);
- va_end(ap);
-
- return rv;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strcasecmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcasecmp.c b/libs/baselibc/src/strcasecmp.c
deleted file mode 100644
index ee1f28b..0000000
--- a/libs/baselibc/src/strcasecmp.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * strcasecmp.c
- */
-
-#include <string.h>
-#include <ctype.h>
-
-int strcasecmp(const char *s1, const char *s2)
-{
- const unsigned char *c1 = (const unsigned char *)s1;
- const unsigned char *c2 = (const unsigned char *)s2;
- unsigned char ch;
- int d = 0;
-
- while (1) {
- /* toupper() expects an unsigned char (implicitly cast to int)
- as input, and returns an int, which is exactly what we want. */
- d = toupper(ch = *c1++) - toupper(*c2++);
- if (d || !ch)
- break;
- }
-
- return d;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strcat.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcat.c b/libs/baselibc/src/strcat.c
deleted file mode 100644
index 6c5b673..0000000
--- a/libs/baselibc/src/strcat.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * strcat.c
- */
-
-#include <string.h>
-
-char *strcat(char *dst, const char *src)
-{
- strcpy(strchr(dst, '\0'), src);
- return dst;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strchr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strchr.c b/libs/baselibc/src/strchr.c
deleted file mode 100644
index 6a57313..0000000
--- a/libs/baselibc/src/strchr.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * strchr.c
- */
-
-#include <string.h>
-
-char *strchr(const char *s, int c)
-{
- while (*s != (char)c) {
- if (!*s)
- return NULL;
- s++;
- }
-
- return (char *)s;
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strcmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcmp.c b/libs/baselibc/src/strcmp.c
deleted file mode 100644
index 3ab9f5a..0000000
--- a/libs/baselibc/src/strcmp.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * strcmp.c
- */
-
-#include <string.h>
-
-int strcmp(const char *s1, const char *s2)
-{
- const unsigned char *c1 = (const unsigned char *)s1;
- const unsigned char *c2 = (const unsigned char *)s2;
- unsigned char ch;
- int d = 0;
-
- while (1) {
- d = (int)(ch = *c1++) - (int)*c2++;
- if (d || !ch)
- break;
- }
-
- return d;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strcpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcpy.c b/libs/baselibc/src/strcpy.c
deleted file mode 100644
index aa656cf..0000000
--- a/libs/baselibc/src/strcpy.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * strcpy.c
- *
- * strcpy()
- */
-
-#include <string.h>
-
-char *strcpy(char *dst, const char *src)
-{
- char *q = dst;
- const char *p = src;
- char ch;
-
- do {
- *q++ = ch = *p++;
- } while (ch);
-
- return dst;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strcspn.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcspn.c b/libs/baselibc/src/strcspn.c
deleted file mode 100644
index ba9e3be..0000000
--- a/libs/baselibc/src/strcspn.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-FUNCTION
- <<strcspn>>---count characters not in string
-
-INDEX
- strcspn
-
-ANSI_SYNOPSIS
- size_t strcspn(const char *<[s1]>, const char *<[s2]>);
-
-TRAD_SYNOPSIS
- size_t strcspn(<[s1]>, <[s2]>)
- char *<[s1]>;
- char *<[s2]>;
-
-DESCRIPTION
- This function computes the length of the initial part of
- the string pointed to by <[s1]> which consists entirely of
- characters <[NOT]> from the string pointed to by <[s2]>
- (excluding the terminating null character).
-
-RETURNS
- <<strcspn>> returns the length of the substring found.
-
-PORTABILITY
-<<strcspn>> is ANSI C.
-
-<<strcspn>> requires no supporting OS subroutines.
- */
-
-#include <string.h>
-
-size_t strcspn(const char *s1, const char *s2)
-{
- const char *s = s1;
- const char *c;
-
- while (*s1)
- {
- for (c = s2; *c; c++)
- {
- if (*s1 == *c)
- break;
- }
- if (*c)
- break;
- s1++;
- }
-
- return s1 - s;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strdup.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strdup.c b/libs/baselibc/src/strdup.c
deleted file mode 100644
index 905b51d..0000000
--- a/libs/baselibc/src/strdup.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * strdup.c
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-char *strdup(const char *s)
-{
- int l = strlen(s) + 1;
- char *d = malloc(l);
-
- if (d)
- memcpy(d, s, l);
-
- return d;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strlcat.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strlcat.c b/libs/baselibc/src/strlcat.c
deleted file mode 100644
index 6d95087..0000000
--- a/libs/baselibc/src/strlcat.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * strlcat.c
- */
-
-#include <string.h>
-
-size_t strlcat(char *dst, const char *src, size_t size)
-{
- size_t bytes = 0;
- char *q = dst;
- const char *p = src;
- char ch;
-
- while (bytes < size && *q) {
- q++;
- bytes++;
- }
- if (bytes == size)
- return (bytes + strlen(src));
-
- while ((ch = *p++)) {
- if (bytes + 1 < size)
- *q++ = ch;
-
- bytes++;
- }
-
- *q = '\0';
- return bytes;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strlcpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strlcpy.c b/libs/baselibc/src/strlcpy.c
deleted file mode 100644
index 3ec8fd2..0000000
--- a/libs/baselibc/src/strlcpy.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * strlcpy.c
- */
-
-#include <string.h>
-
-size_t strlcpy(char *dst, const char *src, size_t size)
-{
- size_t bytes = 0;
- char *q = dst;
- const char *p = src;
- char ch;
-
- while ((ch = *p++)) {
- if (bytes + 1 < size)
- *q++ = ch;
-
- bytes++;
- }
-
- /* If size == 0 there is no space for a final null... */
- if (size)
- *q = '\0';
-
- return bytes;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strlen.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strlen.c b/libs/baselibc/src/strlen.c
deleted file mode 100644
index 86526a5..0000000
--- a/libs/baselibc/src/strlen.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * strlen()
- */
-
-#include <string.h>
-
-size_t strlen(const char *s)
-{
- const char *ss = s;
- while (*ss)
- ss++;
- return ss - s;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strncasecmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncasecmp.c b/libs/baselibc/src/strncasecmp.c
deleted file mode 100644
index 0551935..0000000
--- a/libs/baselibc/src/strncasecmp.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * strncasecmp.c
- */
-
-#include <string.h>
-#include <ctype.h>
-
-int strncasecmp(const char *s1, const char *s2, size_t n)
-{
- const unsigned char *c1 = (const unsigned char *)s1;
- const unsigned char *c2 = (const unsigned char *)s2;
- unsigned char ch;
- int d = 0;
-
- while (n--) {
- /* toupper() expects an unsigned char (implicitly cast to int)
- as input, and returns an int, which is exactly what we want. */
- d = toupper(ch = *c1++) - toupper(*c2++);
- if (d || !ch)
- break;
- }
-
- return d;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strncat.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncat.c b/libs/baselibc/src/strncat.c
deleted file mode 100644
index 5b86216..0000000
--- a/libs/baselibc/src/strncat.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * strncat.c
- */
-
-#include <string.h>
-
-char *strncat(char *dst, const char *src, size_t n)
-{
- char *q = strchr(dst, '\0');
- const char *p = src;
- char ch;
-
- while (n--) {
- *q++ = ch = *p++;
- if (!ch)
- return dst;
- }
- *q = '\0';
-
- return dst;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strncmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncmp.c b/libs/baselibc/src/strncmp.c
deleted file mode 100644
index 5235545..0000000
--- a/libs/baselibc/src/strncmp.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * strncmp.c
- */
-
-#include <string.h>
-
-int strncmp(const char *s1, const char *s2, size_t n)
-{
- const unsigned char *c1 = (const unsigned char *)s1;
- const unsigned char *c2 = (const unsigned char *)s2;
- unsigned char ch;
- int d = 0;
-
- while (n--) {
- d = (int)(ch = *c1++) - (int)*c2++;
- if (d || !ch)
- break;
- }
-
- return d;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strncpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncpy.c b/libs/baselibc/src/strncpy.c
deleted file mode 100644
index fffc118..0000000
--- a/libs/baselibc/src/strncpy.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * strncpy.c
- */
-
-#include <string.h>
-
-char *strncpy(char *dst, const char *src, size_t n)
-{
- char *q = dst;
- const char *p = src;
- char ch;
-
- while (n) {
- n--;
- *q++ = ch = *p++;
- if (!ch)
- break;
- }
-
- /* The specs say strncpy() fills the entire buffer with NUL. Sigh. */
- memset(q, 0, n);
-
- return dst;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strndup.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strndup.c b/libs/baselibc/src/strndup.c
deleted file mode 100644
index 427162f..0000000
--- a/libs/baselibc/src/strndup.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * strndup.c
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-char *strndup(const char *s, size_t n)
-{
- int l = n > strlen(s) ? strlen(s) + 1 : n + 1;
- char *d = malloc(l);
-
- if (!d)
- return NULL;
-
- memcpy(d, s, l);
- d[n] = '\0';
- return d;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strnlen.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strnlen.c b/libs/baselibc/src/strnlen.c
deleted file mode 100644
index 1678f4b..0000000
--- a/libs/baselibc/src/strnlen.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * strnlen()
- */
-
-#include <string.h>
-
-size_t strnlen(const char *s, size_t maxlen)
-{
- const char *ss = s;
-
- /* Important: the maxlen test must precede the reference through ss;
- since the byte beyond the maximum may segfault */
- while ((maxlen > 0) && *ss) {
- ss++;
- maxlen--;
- }
- return ss - s;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strntoimax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strntoimax.c b/libs/baselibc/src/strntoimax.c
deleted file mode 100644
index 179d9e5..0000000
--- a/libs/baselibc/src/strntoimax.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * strntoimax.c
- *
- * strntoimax()
- */
-
-#include <stddef.h>
-#include <inttypes.h>
-
-intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
-{
- return (intmax_t) strntoumax(nptr, endptr, base, n);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strntoumax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strntoumax.c b/libs/baselibc/src/strntoumax.c
deleted file mode 100644
index 56dddad..0000000
--- a/libs/baselibc/src/strntoumax.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * strntoumax.c
- *
- * The strntoumax() function and associated
- */
-
-#include <stddef.h>
-#include <stdint.h>
-#include <ctype.h>
-#include <inttypes.h>
-
-static inline int digitval(int ch)
-{
- if (ch >= '0' && ch <= '9') {
- return ch - '0';
- } else if (ch >= 'A' && ch <= 'Z') {
- return ch - 'A' + 10;
- } else if (ch >= 'a' && ch <= 'z') {
- return ch - 'a' + 10;
- } else {
- return -1;
- }
-}
-
-uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
-{
- int minus = 0;
- uintmax_t v = 0;
- int d;
-
- while (n && isspace((unsigned char)*nptr)) {
- nptr++;
- n--;
- }
-
- /* Single optional + or - */
- if (n) {
- char c = *nptr;
- if (c == '-' || c == '+') {
- minus = (c == '-');
- nptr++;
- n--;
- }
- }
-
- if (base == 0) {
- if (n >= 2 && nptr[0] == '0' &&
- (nptr[1] == 'x' || nptr[1] == 'X')) {
- n -= 2;
- nptr += 2;
- base = 16;
- } else if (n >= 1 && nptr[0] == '0') {
- n--;
- nptr++;
- base = 8;
- } else {
- base = 10;
- }
- } else if (base == 16) {
- if (n >= 2 && nptr[0] == '0' &&
- (nptr[1] == 'x' || nptr[1] == 'X')) {
- n -= 2;
- nptr += 2;
- }
- }
-
- while (n && (d = digitval(*nptr)) >= 0 && d < base) {
- v = v * base + d;
- n--;
- nptr++;
- }
-
- if (endptr)
- *endptr = (char *)nptr;
-
- return minus ? -v : v;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strpbrk.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strpbrk.c b/libs/baselibc/src/strpbrk.c
deleted file mode 100644
index 1873971..0000000
--- a/libs/baselibc/src/strpbrk.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-FUNCTION
- <<strpbrk>>---find characters in string
-
-INDEX
- strpbrk
-
-ANSI_SYNOPSIS
- #include <string.h>
- char *strpbrk(const char *<[s1]>, const char *<[s2]>);
-
-TRAD_SYNOPSIS
- #include <string.h>
- char *strpbrk(<[s1]>, <[s2]>)
- char *<[s1]>;
- char *<[s2]>;
-
-DESCRIPTION
- This function locates the first occurence in the string
- pointed to by <[s1]> of any character in string pointed to by
- <[s2]> (excluding the terminating null character).
-
-RETURNS
- <<strpbrk>> returns a pointer to the character found in <[s1]>, or a
- null pointer if no character from <[s2]> occurs in <[s1]>.
-
-PORTABILITY
-<<strpbrk>> requires no supporting OS subroutines.
-*/
-
-#include <string.h>
-
-char *strpbrk(const char *s1, const char *s2)
-{
- const char *c = s2;
- if (!*s1)
- return (char *) NULL;
-
- while (*s1)
- {
- for (c = s2; *c; c++)
- {
- if (*s1 == *c)
- break;
- }
- if (*c)
- break;
- s1++;
- }
-
- if (*c == '\0')
- s1 = NULL;
-
- return (char *) s1;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strrchr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strrchr.c b/libs/baselibc/src/strrchr.c
deleted file mode 100644
index 69b238f..0000000
--- a/libs/baselibc/src/strrchr.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * strrchr.c
- */
-
-#include <string.h>
-
-char *strrchr(const char *s, int c)
-{
- const char *found = NULL;
-
- while (*s) {
- if (*s == (char)c)
- found = s;
- s++;
- }
-
- return (char *)found;
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strsep.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strsep.c b/libs/baselibc/src/strsep.c
deleted file mode 100644
index 44e76bd..0000000
--- a/libs/baselibc/src/strsep.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * strsep.c
- */
-
-#include <string.h>
-
-char *strsep(char **stringp, const char *delim)
-{
- char *s = *stringp;
- char *e;
-
- if (!s)
- return NULL;
-
- e = strpbrk(s, delim);
- if (e)
- *e++ = '\0';
-
- *stringp = e;
- return s;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strspn.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strspn.c b/libs/baselibc/src/strspn.c
deleted file mode 100644
index e8b213c..0000000
--- a/libs/baselibc/src/strspn.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-FUNCTION
- <<strspn>>---find initial match
-
-INDEX
- strspn
-
-ANSI_SYNOPSIS
- #include <string.h>
- size_t strspn(const char *<[s1]>, const char *<[s2]>);
-
-TRAD_SYNOPSIS
- #include <string.h>
- size_t strspn(<[s1]>, <[s2]>)
- char *<[s1]>;
- char *<[s2]>;
-
-DESCRIPTION
- This function computes the length of the initial segment of
- the string pointed to by <[s1]> which consists entirely of
- characters from the string pointed to by <[s2]> (excluding the
- terminating null character).
-
-RETURNS
- <<strspn>> returns the length of the segment found.
-
-PORTABILITY
-<<strspn>> is ANSI C.
-
-<<strspn>> requires no supporting OS subroutines.
-
-QUICKREF
- strspn ansi pure
-*/
-
-#include <string.h>
-
-size_t strspn(const char *s1, const char *s2)
-{
- const char *s = s1;
- const char *c;
-
- while (*s1)
- {
- for (c = s2; *c; c++)
- {
- if (*s1 == *c)
- break;
- }
- if (*c == '\0')
- break;
- s1++;
- }
-
- return s1 - s;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strstr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strstr.c b/libs/baselibc/src/strstr.c
deleted file mode 100644
index 8850858..0000000
--- a/libs/baselibc/src/strstr.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * strstr.c
- */
-
-#include <string.h>
-
-char *strstr(const char *haystack, const char *needle)
-{
- return (char *)memmem(haystack, strlen(haystack), needle,
- strlen(needle));
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtoimax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoimax.c b/libs/baselibc/src/strtoimax.c
deleted file mode 100644
index cd4fdca..0000000
--- a/libs/baselibc/src/strtoimax.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#define TYPE intmax_t
-#define NAME strtoimax
-#include "templates/strtox.c.template"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtok.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtok.c b/libs/baselibc/src/strtok.c
deleted file mode 100644
index 6b169a1..0000000
--- a/libs/baselibc/src/strtok.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * strtok.c
- */
-
-#include <string.h>
-
-char *strtok(char *s, const char *delim)
-{
- static char *holder;
-
- return strtok_r(s, delim, &holder);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtok_r.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtok_r.c b/libs/baselibc/src/strtok_r.c
deleted file mode 100644
index 695d516..0000000
--- a/libs/baselibc/src/strtok_r.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <string.h>
-
-char *strtok_r(char *s, const char *delim, char **holder)
-{
- if (s)
- *holder = s;
-
- do {
- s = strsep(holder, delim);
- } while (s && !*s);
-
- return s;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtol.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtol.c b/libs/baselibc/src/strtol.c
deleted file mode 100644
index ab318cd..0000000
--- a/libs/baselibc/src/strtol.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#define TYPE signed long
-#define NAME strtol
-#include "templates/strtox.c.template"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtoll.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoll.c b/libs/baselibc/src/strtoll.c
deleted file mode 100644
index ceb924d..0000000
--- a/libs/baselibc/src/strtoll.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#define TYPE signed long long
-#define NAME strtoll
-#include "templates/strtox.c.template"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtoul.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoul.c b/libs/baselibc/src/strtoul.c
deleted file mode 100644
index d0201e1..0000000
--- a/libs/baselibc/src/strtoul.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#define TYPE unsigned long
-#define NAME strtoul
-#include "templates/strtox.c.template"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtoull.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoull.c b/libs/baselibc/src/strtoull.c
deleted file mode 100644
index 2da622a..0000000
--- a/libs/baselibc/src/strtoull.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#define TYPE unsigned long long
-#define NAME strtoull
-#include "templates/strtox.c.template"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/strtoumax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoumax.c b/libs/baselibc/src/strtoumax.c
deleted file mode 100644
index c49d125..0000000
--- a/libs/baselibc/src/strtoumax.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#define TYPE uintmax_t
-#define NAME strtoumax
-#include "templates/strtox.c.template"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/templates/atox.c.template
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/templates/atox.c.template b/libs/baselibc/src/templates/atox.c.template
deleted file mode 100644
index c013bb4..0000000
--- a/libs/baselibc/src/templates/atox.c.template
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * atox.c
- *
- * atoi(), atol(), atoll()
- */
-
-#include <inttypes.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-TYPE NAME(const char *nptr)
-{
- return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/templates/strtox.c.template
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/templates/strtox.c.template b/libs/baselibc/src/templates/strtox.c.template
deleted file mode 100644
index c22e7c7..0000000
--- a/libs/baselibc/src/templates/strtox.c.template
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * strtox.c
- *
- * strto...() functions, by macro definition
- */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-TYPE NAME(const char *nptr, char **endptr, int base)
-{
- return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/tinyprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/tinyprintf.c b/libs/baselibc/src/tinyprintf.c
deleted file mode 100644
index e48be4a..0000000
--- a/libs/baselibc/src/tinyprintf.c
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
-File: tinyprintf.c
-
-Copyright (C) 2004 Kustaa Nyholm
-Copyright (C) 2010 CJlano
-Copyright (C) 2011 Petteri Aimonen
-
-This file is dual-licensed. You can use either of these licenses:
-
-1) GNU LGPL
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-2) BSD
-Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of Kustaa Nyholm or SpareTimeLabs nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*/
-
-/* This is a smaller implementation of printf-family of functions,
- * based on tinyprintf code by Kustaa Nyholm.
- * The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
- * Zero padding and field width are also supported.
- * If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
- * long specifier is also supported.
- * Otherwise it is ignored, so on 32 bit platforms there is no point to use
- * PRINTF_SUPPORT_LONG because int == long.
- */
-
-#include <stdio.h>
-
-struct param {
- unsigned char width; /**< field width */
- char lz; /**< Leading zeros */
- char sign:1; /**< The sign to display (if any) */
- char alt:1; /**< alternate form */
- char uc:1; /**< Upper case (for base16 only) */
- char base; /**< number base (e.g.: 8, 10, 16) */
- char *bf; /**< Buffer to output */
-};
-
-static void ui2a(unsigned long long int num, struct param *p)
-{
- int n = 0;
- unsigned long long int d = 1;
- char *bf = p->bf;
- while (num / d >= p->base)
- d *= p->base;
- while (d != 0) {
- unsigned long long dgt = num / d;
- num %= d;
- d /= p->base;
- if (n || dgt > 0 || d == 0) {
- *bf++ = dgt + (dgt < 10 ? '0' : (p->uc ? 'A' : 'a') - 10);
- ++n;
- }
- }
- *bf = 0;
-}
-
-static void i2a(long long int num, struct param *p)
-{
- if (num < 0) {
- num = -num;
- p->sign = 1;
- }
- ui2a(num, p);
-}
-
-static int a2d(char ch)
-{
- if (ch >= '0' && ch <= '9')
- return ch - '0';
- else if (ch >= 'a' && ch <= 'f')
- return ch - 'a' + 10;
- else if (ch >= 'A' && ch <= 'F')
- return ch - 'A' + 10;
- else
- return -1;
-}
-
-static char a2i(char ch, const char **src, int base, unsigned char *nump)
-{
- const char *p = *src;
- int num = 0;
- int digit;
- while ((digit = a2d(ch)) >= 0) {
- if (digit > base)
- break;
- num = num * base + digit;
- ch = *p++;
- }
- *src = p;
- *nump = num;
- return ch;
-}
-
-static int putf(FILE *putp, char c)
-{
- if (fputc(c, putp) == EOF)
- return 0;
- else
- return 1;
-}
-
-static unsigned putchw(FILE *putp, struct param *p)
-{
- unsigned written = 0;
- char ch;
- int n = p->width;
- char *bf = p->bf;
-
- /* Number of filling characters */
- while (*bf++ && n > 0)
- n--;
- if (p->sign)
- n--;
- if (p->alt && p->base == 16)
- n -= 2;
- else if (p->alt && p->base == 8)
- n--;
-
- /* Fill with space, before alternate or sign */
- if (!p->lz) {
- while (n-- > 0)
- written += putf(putp, ' ');
- }
-
- /* print sign */
- if (p->sign)
- written += putf(putp, '-');
-
- /* Alternate */
- if (p->alt && p->base == 16) {
- written += putf(putp, '0');
- written += putf(putp, (p->uc ? 'X' : 'x'));
- } else if (p->alt && p->base == 8) {
- written += putf(putp, '0');
- }
-
- /* Fill with zeros, after alternate or sign */
- if (p->lz) {
- while (n-- > 0)
- written += putf(putp, '0');
- }
-
- /* Put actual buffer */
- bf = p->bf;
- while ((ch = *bf++))
- written += putf(putp, ch);
-
- return written;
-}
-
-static unsigned long long
-intarg(int lng, int sign, va_list *va)
-{
- unsigned long long val;
-
- switch (lng) {
- case 0:
- if (sign) {
- val = va_arg(*va, int);
- } else {
- val = va_arg(*va, unsigned int);
- }
- break;
-
- case 1:
- if (sign) {
- val = va_arg(*va, long);
- } else {
- val = va_arg(*va, unsigned long);
- }
- break;
-
- case 2:
- default:
- /* Pull the 64-bit number off the stack as a pair of 32-bit integers.
- * The va_arg macro was reading from the wrong location when a 64-bit
- * type was specified.
- */
- /* XXX: Look into this; may just be an incorrect setting when the
- * compiler / newlib was built.
- */
- val = va_arg(*va, unsigned long);
- val |= (unsigned long long)(va_arg(*va, unsigned long)) << 32;
- break;
- }
-
- return val;
-}
-
-size_t tfp_format(FILE *putp, const char *fmt, va_list va)
-{
- size_t written = 0;
- struct param p;
- char bf[23];
- char ch;
- char lng;
-
- p.bf = bf;
-
- while ((ch = *(fmt++))) {
- if (ch != '%') {
- written += putf(putp, ch);
- } else {
- /* Init parameter struct */
- p.lz = 0;
- p.alt = 0;
- p.width = 0;
- p.sign = 0;
- lng = 0;
-
- /* Flags */
- while ((ch = *(fmt++))) {
- switch (ch) {
- case '0':
- p.lz = 1;
- continue;
- case '#':
- p.alt = 1;
- continue;
- default:
- break;
- }
- break;
- }
-
- /* Width */
- if (ch >= '0' && ch <= '9') {
- ch = a2i(ch, &fmt, 10, &(p.width));
- }
- if (ch == 'l') {
- ch = *(fmt++);
- lng = 1;
-
- if (ch == 'l') {
- ch = *(fmt++);
- lng = 2;
- }
- }
-
- switch (ch) {
- case 0:
- goto abort;
- case 'u':
- p.base = 10;
- ui2a(intarg(lng, 0, &va), &p);
- written += putchw(putp, &p);
- break;
- case 'd':
- case 'i':
- p.base = 10;
- i2a(intarg(lng, 1, &va), &p);
- written += putchw(putp, &p);
- break;
- case 'x':
- case 'X':
- p.base = 16;
- p.uc = (ch == 'X');
- ui2a(intarg(lng, 0, &va), &p);
- written += putchw(putp, &p);
- break;
- case 'o':
- p.base = 8;
- ui2a(intarg(lng, 0, &va), &p);
- written += putchw(putp, &p);
- break;
- case 'c':
- written += putf(putp, (char)(va_arg(va, int)));
- break;
- case 's':
- p.bf = va_arg(va, char *);
- written += putchw(putp, &p);
- p.bf = bf;
- break;
- case '%':
- written += putf(putp, ch);
- default:
- break;
- }
- }
- }
- abort:;
-
- return written;
-}
-
-int vfprintf(FILE *f, const char *fmt, va_list va)
-{
- return tfp_format(f, fmt, va);
-}
-
-int fprintf(FILE *f, const char *fmt, ...)
-{
- va_list va;
- va_start(va, fmt);
- int rv = vfprintf(f, fmt, va);
- va_end(va);
- return rv;
-}
-
-int printf(const char *fmt, ...)
-{
- va_list va;
- va_start(va, fmt);
- int rv = vfprintf(stdout, fmt, va);
- va_end(va);
- return rv;
-}
-
-int vsnprintf(char *str, size_t size, const char *fmt, va_list va)
-{
- struct MemFile state;
- FILE *f = fmemopen_w(&state, str, size - 1);
- tfp_format(f, fmt, va);
- *(state.buffer) = '\0';
- return state.bytes_written;
-}
-
-int snprintf(char *str, size_t size, const char *fmt, ...)
-{
- va_list va;
- va_start(va, fmt);
- int rv = vsnprintf(str, size, fmt, va);
- va_end(va);
- return rv;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/vasprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/vasprintf.c b/libs/baselibc/src/vasprintf.c
deleted file mode 100644
index cdc302f..0000000
--- a/libs/baselibc/src/vasprintf.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * vasprintf.c
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-int vasprintf(char **bufp, const char *format, va_list ap)
-{
- va_list ap1;
- int bytes;
- char *p;
-
- va_copy(ap1, ap);
-
- bytes = vsnprintf(NULL, 0, format, ap1) + 1;
- va_end(ap1);
-
- *bufp = p = malloc(bytes);
- if (!p)
- return -1;
-
- return vsnprintf(p, bytes, format, ap);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/vprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/vprintf.c b/libs/baselibc/src/vprintf.c
deleted file mode 100644
index d6bfeaf..0000000
--- a/libs/baselibc/src/vprintf.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * vprintf.c
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-int vprintf(const char *format, va_list ap)
-{
- return vfprintf(stdout, format, ap);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/vsprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/vsprintf.c b/libs/baselibc/src/vsprintf.c
deleted file mode 100644
index 51f5d87..0000000
--- a/libs/baselibc/src/vsprintf.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * vsprintf.c
- */
-
-#include <stdio.h>
-#include <unistd.h>
-
-int vsprintf(char *buffer, const char *format, va_list ap)
-{
- return vsnprintf(buffer, ~(size_t) 0, format, ap);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/baselibc/src/vsscanf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/vsscanf.c b/libs/baselibc/src/vsscanf.c
deleted file mode 100644
index 60eaca6..0000000
--- a/libs/baselibc/src/vsscanf.c
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * vsscanf.c
- *
- * vsscanf(), from which the rest of the scanf()
- * family is built
- */
-
-#include <ctype.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <inttypes.h>
-#include <string.h>
-#include <limits.h>
-#include <stdio.h>
-
-#ifndef LONG_BIT
-#define LONG_BIT (CHAR_BIT*sizeof(long))
-#endif
-
-enum flags {
- FL_SPLAT = 0x01, /* Drop the value, do not assign */
- FL_INV = 0x02, /* Character-set with inverse */
- FL_WIDTH = 0x04, /* Field width specified */
- FL_MINUS = 0x08, /* Negative number */
-};
-
-enum ranks {
- rank_char = -2,
- rank_short = -1,
- rank_int = 0,
- rank_long = 1,
- rank_longlong = 2,
- rank_ptr = INT_MAX /* Special value used for pointers */
-};
-
-#define MIN_RANK rank_char
-#define MAX_RANK rank_longlong
-
-#define INTMAX_RANK rank_longlong
-#define SIZE_T_RANK rank_long
-#define PTRDIFF_T_RANK rank_long
-
-enum bail {
- bail_none = 0, /* No error condition */
- bail_eof, /* Hit EOF */
- bail_err /* Conversion mismatch */
-};
-
-static inline const char *skipspace(const char *p)
-{
- while (isspace((unsigned char)*p))
- p++;
- return p;
-}
-
-#undef set_bit
-static inline void set_bit(unsigned long *bitmap, unsigned int bit)
-{
- bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
-}
-
-#undef test_bit
-static inline int test_bit(unsigned long *bitmap, unsigned int bit)
-{
- return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
-}
-
-int vsscanf(const char *buffer, const char *format, va_list ap)
-{
- const char *p = format;
- char ch;
- unsigned char uc;
- const char *q = buffer;
- const char *qq;
- uintmax_t val = 0;
- int rank = rank_int; /* Default rank */
- unsigned int width = UINT_MAX;
- int base;
- enum flags flags = 0;
- enum {
- st_normal, /* Ground state */
- st_flags, /* Special flags */
- st_width, /* Field width */
- st_modifiers, /* Length or conversion modifiers */
- st_match_init, /* Initial state of %[ sequence */
- st_match, /* Main state of %[ sequence */
- st_match_range, /* After - in a %[ sequence */
- } state = st_normal;
- char *sarg = NULL; /* %s %c or %[ string argument */
- enum bail bail = bail_none;
- int sign;
- int converted = 0; /* Successful conversions */
- unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT];
- int matchinv = 0; /* Is match map inverted? */
- unsigned char range_start = 0;
- (void)sign;
-
- while ((ch = *p++) && !bail) {
- switch (state) {
- case st_normal:
- if (ch == '%') {
- state = st_flags;
- flags = 0;
- rank = rank_int;
- width = UINT_MAX;
- } else if (isspace((unsigned char)ch)) {
- q = skipspace(q);
- } else {
- if (*q == ch)
- q++;
- else
- bail = bail_err; /* Match failure */
- }
- break;
-
- case st_flags:
- switch (ch) {
- case '*':
- flags |= FL_SPLAT;
- break;
- case '0'...'9':
- width = (ch - '0');
- state = st_width;
- flags |= FL_WIDTH;
- break;
- default:
- state = st_modifiers;
- p--; /* Process this character again */
- break;
- }
- break;
-
- case st_width:
- if (ch >= '0' && ch <= '9') {
- width = width * 10 + (ch - '0');
- } else {
- state = st_modifiers;
- p--; /* Process this character again */
- }
- break;
-
- case st_modifiers:
- switch (ch) {
- /* Length modifiers - nonterminal sequences */
- case 'h':
- rank--; /* Shorter rank */
- break;
- case 'l':
- rank++; /* Longer rank */
- break;
- case 'j':
- rank = INTMAX_RANK;
- break;
- case 'z':
- rank = SIZE_T_RANK;
- break;
- case 't':
- rank = PTRDIFF_T_RANK;
- break;
- case 'L':
- case 'q':
- rank = rank_longlong; /* long double/long long */
- break;
-
- default:
- /* Output modifiers - terminal sequences */
- /* Next state will be normal */
- state = st_normal;
-
- /* Canonicalize rank */
- if (rank < MIN_RANK)
- rank = MIN_RANK;
- else if (rank > MAX_RANK)
- rank = MAX_RANK;
-
- switch (ch) {
- case 'P': /* Upper case pointer */
- case 'p': /* Pointer */
- rank = rank_ptr;
- base = 0;
- sign = 0;
- goto scan_int;
-
- case 'i': /* Base-independent integer */
- base = 0;
- sign = 1;
- goto scan_int;
-
- case 'd': /* Decimal integer */
- base = 10;
- sign = 1;
- goto scan_int;
-
- case 'o': /* Octal integer */
- base = 8;
- sign = 0;
- goto scan_int;
-
- case 'u': /* Unsigned decimal integer */
- base = 10;
- sign = 0;
- goto scan_int;
-
- case 'x': /* Hexadecimal integer */
- case 'X':
- base = 16;
- sign = 0;
- goto scan_int;
-
- case 'n': /* # of characters consumed */
- val = (q - buffer);
- goto set_integer;
-
- scan_int:
- q = skipspace(q);
- if (!*q) {
- bail = bail_eof;
- break;
- }
- val =
- strntoumax(q, (char **)&qq, base,
- width);
- if (qq == q) {
- bail = bail_err;
- break;
- }
- q = qq;
- if (!(flags & FL_SPLAT))
- converted++;
- /* fall through */
-
- set_integer:
- if (!(flags & FL_SPLAT)) {
- switch (rank) {
- case rank_char:
- *va_arg(ap,
- unsigned char *)
- = val;
- break;
- case rank_short:
- *va_arg(ap,
- unsigned short
- *) = val;
- break;
- case rank_int:
- *va_arg(ap,
- unsigned int *)
- = val;
- break;
- case rank_long:
- *va_arg(ap,
- unsigned long *)
- = val;
- break;
- case rank_longlong:
- *va_arg(ap,
- unsigned long
- long *) = val;
- break;
- case rank_ptr:
- *va_arg(ap, void **) =
- (void *)
- (uintptr_t)val;
- break;
- }
- }
- break;
-
- case 'c': /* Character */
- /* Default width == 1 */
- width = (flags & FL_WIDTH) ? width : 1;
- if (flags & FL_SPLAT) {
- while (width--) {
- if (!*q) {
- bail = bail_eof;
- break;
- }
- }
- } else {
- sarg = va_arg(ap, char *);
- while (width--) {
- if (!*q) {
- bail = bail_eof;
- break;
- }
- *sarg++ = *q++;
- }
- if (!bail)
- converted++;
- }
- break;
-
- case 's': /* String */
- uc = 1; /* Anything nonzero */
- if (flags & FL_SPLAT) {
- while (width-- && (uc = *q) &&
- !isspace(uc)) {
- q++;
- }
- } else {
- char *sp;
- sp = sarg = va_arg(ap, char *);
- while (width-- && (uc = *q) &&
- !isspace(uc)) {
- *sp++ = uc;
- q++;
- }
- if (sarg != sp) {
- /* Terminate output */
- *sp = '\0';
- converted++;
- }
- }
- if (!uc)
- bail = bail_eof;
- break;
-
- case '[': /* Character range */
- sarg = (flags & FL_SPLAT) ? NULL
- : va_arg(ap, char *);
- state = st_match_init;
- matchinv = 0;
- memset(matchmap, 0, sizeof matchmap);
- break;
-
- case '%': /* %% sequence */
- if (*q == '%')
- q++;
- else
- bail = bail_err;
- break;
-
- default: /* Anything else */
- /* Unknown sequence */
- bail = bail_err;
- break;
- }
- }
- break;
-
- case st_match_init: /* Initial state for %[ match */
- if (ch == '^' && !(flags & FL_INV)) {
- matchinv = 1;
- } else {
- set_bit(matchmap, (unsigned char)ch);
- state = st_match;
- }
- break;
-
- case st_match: /* Main state for %[ match */
- if (ch == ']') {
- goto match_run;
- } else if (ch == '-') {
- range_start = (unsigned char)ch;
- state = st_match_range;
- } else {
- set_bit(matchmap, (unsigned char)ch);
- }
- break;
-
- case st_match_range: /* %[ match after - */
- if (ch == ']') {
- /* - was last character */
- set_bit(matchmap, (unsigned char)'-');
- goto match_run;
- } else {
- int i;
- for (i = range_start; i < (unsigned char)ch;
- i++)
- set_bit(matchmap, i);
- state = st_match;
- }
- break;
-
- match_run: /* Match expression finished */
- qq = q;
- uc = 1; /* Anything nonzero */
- while (width && (uc = *q)
- && test_bit(matchmap, uc)^matchinv) {
- if (sarg)
- *sarg++ = uc;
- q++;
- }
- if (q != qq && sarg) {
- *sarg = '\0';
- converted++;
- } else {
- bail = bail_err;
- }
- if (!uc)
- bail = bail_eof;
- break;
- }
- }
-
- if (bail == bail_eof && !converted)
- converted = -1; /* Return EOF (-1) */
-
- return converted;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/bleuart/include/bleuart/bleuart.h
----------------------------------------------------------------------
diff --git a/libs/bleuart/include/bleuart/bleuart.h b/libs/bleuart/include/bleuart/bleuart.h
deleted file mode 100644
index 6639747..0000000
--- a/libs/bleuart/include/bleuart/bleuart.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef _BLEUART_H_
-#define _BLEUART_H_
-
-void
-bleuart_init(void);
-int
-bleuart_svc_register(void);
-int
-bleuart_gatt_svr_init(void);
-void
-bleuart_set_conn_handle(uint16_t conn_handle);
-
-extern const uint8_t gatt_svr_svc_uart[16];
-
-#endif /* _BLEUART_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/bleuart/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/bleuart/pkg.yml b/libs/bleuart/pkg.yml
deleted file mode 100644
index 272f53d..0000000
--- a/libs/bleuart/pkg.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-pkg.name: libs/bleuart
-pkg.description: BLE uart service.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
- - ble
- - bluetooth
- - uart
-
-pkg.deps:
- - libs/os
- - net/nimble/host
-
-pkg.req_apis:
- - console
-
-pkg.init_function: bleuart_init
-pkg.init_stage: 5
-
-pkg.syscfg_defs:
- BLEUART_MAX_INPUT:
- description: 'TBD'
- value: 120
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/bleuart/src/bleuart.c
----------------------------------------------------------------------
diff --git a/libs/bleuart/src/bleuart.c b/libs/bleuart/src/bleuart.c
deleted file mode 100644
index b7b2591..0000000
--- a/libs/bleuart/src/bleuart.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "sysinit/sysinit.h"
-#include "host/ble_hs.h"
-#include "bleuart/bleuart.h"
-#include "os/endian.h"
-#include "console/console.h"
-
-/* ble uart attr read handle */
-uint16_t g_bleuart_attr_read_handle;
-
-/* ble uart attr write handle */
-uint16_t g_bleuart_attr_write_handle;
-
-/* Pointer to a console buffer */
-char *console_buf;
-
-uint16_t g_console_conn_handle;
-/**
- * The vendor specific "bleuart" service consists of one write no-rsp characteristic
- * and one notification only read charateristic
- * o "write no-rsp": a single-byte characteristic that can be written only
- * over a non-encrypted connection
- * o "read": a single-byte characteristic that can always be read only via
- * notifications
- */
-
-/* {6E400001-B5A3-F393-E0A9-E50E24DCCA9E} */
-const uint8_t gatt_svr_svc_uart[16] = {
- 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
- 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e
-};
-
-/* {6E400002-B5A3-F393-E0A9-E50E24DCCA9E} */
-const uint8_t gatt_svr_chr_uart_write[16] = {
- 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
- 0x93, 0xf3, 0xa3, 0xb5, 0x02, 0x00, 0x40, 0x6e
-};
-
-
-/* {6E400003-B5A3-F393-E0A9-E50E24DCCA9E} */
-const uint8_t gatt_svr_chr_uart_read[16] = {
- 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
- 0x93, 0xf3, 0xa3, 0xb5, 0x03, 0x00, 0x40, 0x6e
-};
-
-static int
-gatt_svr_chr_access_uart_write(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg);
-
-static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
- {
- /* Service: uart */
- .type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = (void *)gatt_svr_svc_uart,
- .characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid128 = gatt_svr_chr_uart_read,
- .val_handle = &g_bleuart_attr_read_handle,
- .access_cb = gatt_svr_chr_access_uart_write,
- .flags = BLE_GATT_CHR_F_NOTIFY,
- }, {
- /* Characteristic: Write */
- .uuid128 = (void *)gatt_svr_chr_uart_write,
- .access_cb = gatt_svr_chr_access_uart_write,
- .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_NO_RSP,
- .val_handle = &g_bleuart_attr_write_handle,
- }, {
- 0, /* No more characteristics in this service */
- } },
- },
-
- {
- 0, /* No more services */
- },
-};
-
-static int
-gatt_svr_chr_access_uart_write(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
- struct os_mbuf *om = ctxt->om;
- switch (ctxt->op) {
- case BLE_GATT_ACCESS_OP_WRITE_CHR:
- while(om) {
- console_write((char *)om->om_data, om->om_len);
- om = SLIST_NEXT(om, om_next);
- }
- console_write("\n", 1);
- return 0;
- default:
- assert(0);
- return BLE_ATT_ERR_UNLIKELY;
- }
-}
-
-/**
- * bleuart GATT server initialization
- *
- * @param eventq
- * @return 0 on success; non-zero on failure
- */
-int
-bleuart_gatt_svr_init(void)
-{
- int rc;
-
- rc = ble_gatts_count_cfg(gatt_svr_svcs);
- if (rc != 0) {
- goto err;
- }
-
- rc = ble_gatts_add_svcs(gatt_svr_svcs);
- if (rc != 0) {
- return rc;
- }
-
-err:
- return rc;
-}
-
-/**
- * Reads console and sends data over BLE
- */
-static void
-bleuart_uart_read(void)
-{
- int rc;
- int off;
- int full_line;
- struct os_mbuf *om;
-
- off = 0;
- while (1) {
- rc = console_read(console_buf + off,
- MYNEWT_VAL(BLEUART_MAX_INPUT) - off, &full_line);
- if (rc <= 0 && !full_line) {
- continue;
- }
- off += rc;
- if (!full_line) {
- continue;
- }
-
- om = ble_hs_mbuf_from_flat(console_buf, off);
- if (!om) {
- return;
- }
- ble_gattc_notify_custom(g_console_conn_handle,
- g_bleuart_attr_read_handle, om);
- off = 0;
- break;
- }
-}
-
-/**
- * Sets the global connection handle
- *
- * @param connection handle
- */
-void
-bleuart_set_conn_handle(uint16_t conn_handle) {
- g_console_conn_handle = conn_handle;
-}
-
-/**
- * BLEuart console initialization
- *
- * @param Maximum input
- */
-void
-bleuart_init(void)
-{
- int rc;
-
- rc = console_init(bleuart_uart_read);
- SYSINIT_PANIC_ASSERT(rc == 0);
-
- console_buf = malloc(MYNEWT_VAL(BLEUART_MAX_INPUT));
- SYSINIT_PANIC_ASSERT(console_buf != NULL);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/boot_serial/include/boot_serial/boot_serial.h
----------------------------------------------------------------------
diff --git a/libs/boot_serial/include/boot_serial/boot_serial.h b/libs/boot_serial/include/boot_serial/boot_serial.h
deleted file mode 100644
index 67fa415..0000000
--- a/libs/boot_serial/include/boot_serial/boot_serial.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef __BOOT_SERIAL_H__
-#define __BOOT_SERIAL_H__
-
-/*
- * Create a task for uploading image0 over serial.
- *
- * Task opens console serial port and waits for download command.
- * Return code 0 means new image was uploaded, non-zero means that
- * there was an error.
- */
-int boot_serial_task_init(struct os_task *task, uint8_t prio,
- os_stack_t *stack, uint16_t stack_size, int max_input);
-
-#endif /* __BOOT_SERIAL_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/boot_serial/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/boot_serial/pkg.yml b/libs/boot_serial/pkg.yml
deleted file mode 100644
index b556e13..0000000
--- a/libs/boot_serial/pkg.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-pkg.name: libs/boot_serial
-pkg.description: The boot_serial library is used when downloading image over serial port.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
- - boot
- - bootloader
-
-pkg.deps:
- - hw/hal
- - libs/os
- - libs/bootutil
- - libs/util
-
-pkg.req_apis:
- - console
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/boot_serial/src/boot_serial.c
----------------------------------------------------------------------
diff --git a/libs/boot_serial/src/boot_serial.c b/libs/boot_serial/src/boot_serial.c
deleted file mode 100644
index c8dfaf4..0000000
--- a/libs/boot_serial/src/boot_serial.c
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#include <assert.h>
-#include <stddef.h>
-#include <inttypes.h>
-#include <ctype.h>
-#include <stdio.h>
-
-#include <bsp/bsp.h>
-
-#include <hal/flash_map.h>
-#include <hal/hal_flash.h>
-#include <hal/hal_system.h>
-
-#include <os/endian.h>
-#include <os/os.h>
-#include <os/os_malloc.h>
-
-#include <console/console.h>
-
-#include <util/base64.h>
-#include <util/crc16.h>
-
-#include <bootutil/image.h>
-
-#include "boot_serial/boot_serial.h"
-#include "boot_serial_priv.h"
-
-#define BOOT_SERIAL_OUT_MAX 48
-
-static uint32_t curr_off;
-static uint32_t img_size;
-static struct nmgr_hdr *bs_hdr;
-
-static void boot_serial_output(char *data, int len);
-
-/*
- * Looks for 'name' from NULL-terminated json data in buf.
- * Returns pointer to first character of value for that name.
- * Returns NULL if 'name' is not found.
- */
-char *
-bs_find_val(char *buf, char *name)
-{
- char *ptr;
-
- ptr = strstr(buf, name);
- if (!ptr) {
- return NULL;
- }
- ptr += strlen(name);
-
- while (*ptr != '\0') {
- if (*ptr != ':' && !isspace(*ptr)) {
- break;
- }
- ++ptr;
- }
- if (*ptr == '\0') {
- ptr = NULL;
- }
- return ptr;
-}
-
-/*
- * List images.
- */
-static void
-bs_list(char *buf, int len)
-{
- char *ptr;
- struct image_header hdr;
- uint8_t tmpbuf[64];
- const struct flash_area *fap = NULL;
- int good_img, need_comma = 0;
- int rc;
- int i;
-
- ptr = os_malloc(BOOT_SERIAL_OUT_MAX);
- if (!ptr) {
- return;
- }
- len = snprintf(ptr, BOOT_SERIAL_OUT_MAX, "{\"images\":[");
- for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
- rc = flash_area_open(i, &fap);
- if (rc) {
- continue;
- }
-
- flash_area_read(fap, 0, &hdr, sizeof(hdr));
-
- if (hdr.ih_magic == IMAGE_MAGIC &&
- bootutil_img_validate(&hdr, fap->fa_flash_id, fap->fa_off,
- tmpbuf, sizeof(tmpbuf), NULL, 0, NULL) == 0) {
- good_img = 1;
- } else {
- good_img = 0;
- }
- if (good_img) {
- len += snprintf(ptr + len, BOOT_SERIAL_OUT_MAX - len,
- "%c\"%u.%u.%u.%u\"", need_comma ? ',' : ' ',
- hdr.ih_ver.iv_major, hdr.ih_ver.iv_minor, hdr.ih_ver.iv_revision,
- (unsigned int)hdr.ih_ver.iv_build_num);
- }
- flash_area_close(fap);
- }
- len += snprintf(ptr + len, BOOT_SERIAL_OUT_MAX - len, "]}");
- boot_serial_output(ptr, len);
- os_free(ptr);
-}
-
-/*
- * Image upload request.
- */
-static void
-bs_upload(char *buf, int len)
-{
- char *ptr;
- char *data_ptr;
- uint32_t off, data_len = 0;
- const struct flash_area *fap = NULL;
- int rc;
-
- /*
- * should be json inside
- */
- ptr = bs_find_val(buf, "\"off\"");
- if (!ptr) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
- off = strtoul(ptr, NULL, 10);
-
- if (off == 0) {
- ptr = bs_find_val(buf, "\"len\"");
- if (!ptr) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
- data_len = strtoul(ptr, NULL, 10);
-
- }
- data_ptr = bs_find_val(buf, "\"data\"");
- if (!data_ptr) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
- if (*data_ptr != '"') {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
- ++data_ptr;
- data_ptr = strsep(&data_ptr, "\"");
- if (!data_ptr) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
-
- len = base64_decode(data_ptr, data_ptr);
- if (len <= 0) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
-
- rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
- if (rc) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
-
- if (off == 0) {
- curr_off = 0;
- if (data_len > fap->fa_size) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
- rc = flash_area_erase(fap, 0, fap->fa_size);
- if (rc) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
- img_size = data_len;
- }
- if (off != curr_off) {
- rc = 0;
- goto out;
- }
- rc = flash_area_write(fap, curr_off, data_ptr, len);
- if (rc) {
- rc = NMGR_ERR_EINVAL;
- goto out;
- }
- curr_off += len;
-
-out:
- ptr = os_malloc(BOOT_SERIAL_OUT_MAX);
- if (!ptr) {
- return;
- }
- if (rc == 0) {
- len = snprintf(ptr, BOOT_SERIAL_OUT_MAX, "{\"rc\":%d,\"off\":%u}",
- rc, (int)curr_off);
- } else {
- len = snprintf(ptr, BOOT_SERIAL_OUT_MAX, "{\"rc\":%d}", rc);
- }
- boot_serial_output(ptr, len);
- os_free(ptr);
- flash_area_close(fap);
-}
-
-/*
- * Console echo control. Send empty response, don't do anything.
- */
-static void
-bs_echo_ctl(char *buf, int len)
-{
- boot_serial_output(NULL, 0);
-}
-
-/*
- * Reset, and (presumably) boot to newly uploaded image. Flush console
- * before restarting.
- */
-static void
-bs_reset(char *buf, int len)
-{
- char msg[] = "{\"rc\":0}";
-
- boot_serial_output(msg, strlen(msg));
- os_time_delay(250);
- system_reset();
-}
-
-/*
- * Parse incoming line of input from console.
- * Expect newtmgr protocol with serial transport.
- */
-void
-boot_serial_input(char *buf, int len)
-{
- int rc;
- uint16_t crc;
- uint16_t expected_len;
- struct nmgr_hdr *hdr;
-
- if (len < BASE64_ENCODE_SIZE(sizeof(uint16_t) * 2)) {
- return;
- }
- rc = base64_decode(buf, buf);
- if (rc < 0) {
- return;
- }
- len = rc;
-
- expected_len = ntohs(*(uint16_t *)buf);
- buf += sizeof(uint16_t);
- len -= sizeof(uint16_t);
-
- len = min(len, expected_len);
-
- crc = crc16_ccitt(CRC16_INITIAL_CRC, buf, len);
- if (crc || len <= sizeof(crc)) {
- return;
- }
- len -= sizeof(crc);
- buf[len] = '\0';
-
- hdr = (struct nmgr_hdr *)buf;
- if (len < sizeof(*hdr) ||
- (hdr->nh_op != NMGR_OP_READ && hdr->nh_op != NMGR_OP_WRITE) ||
- (ntohs(hdr->nh_len) < len - sizeof(*hdr))) {
- return;
- }
- bs_hdr = hdr;
- hdr->nh_group = ntohs(hdr->nh_group);
-
- buf += sizeof(*hdr);
- len -= sizeof(*hdr);
-
- /*
- * Limited support for commands.
- */
- if (hdr->nh_group == NMGR_GROUP_ID_IMAGE) {
- switch (hdr->nh_id) {
- case IMGMGR_NMGR_OP_LIST:
- bs_list(buf, len);
- break;
- case IMGMGR_NMGR_OP_UPLOAD:
- bs_upload(buf, len);
- break;
- default:
- break;
- }
- } else if (hdr->nh_group == NMGR_GROUP_ID_DEFAULT) {
- switch (hdr->nh_id) {
- case NMGR_ID_CONS_ECHO_CTRL:
- bs_echo_ctl(buf, len);
- break;
- case NMGR_ID_RESET:
- bs_reset(buf, len);
- break;
- default:
- break;
- }
- }
-}
-
-static void
-boot_serial_output(char *data, int len)
-{
- uint16_t crc;
- uint16_t totlen;
- char pkt_start[2] = { SHELL_NLIP_PKT_START1, SHELL_NLIP_PKT_START2 };
- char buf[BOOT_SERIAL_OUT_MAX];
- char encoded_buf[BASE64_ENCODE_SIZE(BOOT_SERIAL_OUT_MAX)];
-
- bs_hdr->nh_op++;
- bs_hdr->nh_len = htons(len);
- bs_hdr->nh_group = htons(bs_hdr->nh_group);
-
- crc = crc16_ccitt(CRC16_INITIAL_CRC, bs_hdr, sizeof(*bs_hdr));
- crc = crc16_ccitt(crc, data, len);
- crc = htons(crc);
-
- console_write(pkt_start, sizeof(pkt_start));
-
- totlen = len + sizeof(*bs_hdr) + sizeof(crc);
- totlen = htons(totlen);
-
- memcpy(buf, &totlen, sizeof(totlen));
- totlen = sizeof(totlen);
- memcpy(&buf[totlen], bs_hdr, sizeof(*bs_hdr));
- totlen += sizeof(*bs_hdr);
- memcpy(&buf[totlen], data, len);
- totlen += len;
- memcpy(&buf[totlen], &crc, sizeof(crc));
- totlen += sizeof(crc);
- totlen = base64_encode(buf, totlen, encoded_buf, 1);
- console_write(encoded_buf, totlen);
- console_write("\n", 1);
-}
-
-/*
- * Task which waits reading console, expecting to get image over
- * serial port.
- */
-static void
-boot_serial(void *arg)
-{
- int rc;
- int off;
- char *buf;
- int full_line;
- int max_input = (int)arg;
-
- rc = console_init(NULL);
- assert(rc == 0);
- console_echo(0);
-
- buf = os_malloc(max_input);
- assert(buf);
-
- off = 0;
- while (1) {
- rc = console_read(buf + off, max_input - off, &full_line);
- if (rc <= 0 && !full_line) {
- continue;
- }
- off += rc;
- if (!full_line) {
- continue;
- }
- if (buf[0] == SHELL_NLIP_PKT_START1 &&
- buf[1] == SHELL_NLIP_PKT_START2) {
- boot_serial_input(&buf[2], off - 2);
- }
- off = 0;
- }
-}
-
-int
-boot_serial_task_init(struct os_task *task, uint8_t prio, os_stack_t *stack,
- uint16_t stack_size, int max_input)
-{
- return os_task_init(task, "boot", boot_serial, (void *)max_input,
- prio, OS_WAIT_FOREVER, stack, stack_size);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/boot_serial/src/boot_serial_priv.h
----------------------------------------------------------------------
diff --git a/libs/boot_serial/src/boot_serial_priv.h b/libs/boot_serial/src/boot_serial_priv.h
deleted file mode 100644
index 86ba6c6..0000000
--- a/libs/boot_serial/src/boot_serial_priv.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef __BOOTUTIL_SERIAL_PRIV_H__
-#define __BOOTUTIL_SERIAL_PRIV_H__
-
-/*
- * From shell.h
- */
-#define SHELL_NLIP_PKT_START1 6
-#define SHELL_NLIP_PKT_START2 9
-
-/*
- * From newtmgr.h
- */
-#define NMGR_ERR_EINVAL 3
-
-#define NMGR_OP_READ 0
-#define NMGR_OP_WRITE 2
-
-#define NMGR_GROUP_ID_DEFAULT 0
-#define NMGR_GROUP_ID_IMAGE 1
-
-#define NMGR_ID_CONS_ECHO_CTRL 1
-#define NMGR_ID_RESET 5
-
-struct nmgr_hdr {
- uint8_t nh_op; /* NMGR_OP_XXX */
- uint8_t nh_flags;
- uint16_t nh_len; /* length of the payload */
- uint16_t nh_group; /* NMGR_GROUP_XXX */
- uint8_t nh_seq; /* sequence number */
- uint8_t nh_id; /* message ID within group */
-};
-
-/*
- * From imgmgr.h
- */
-#define IMGMGR_NMGR_OP_LIST 0
-#define IMGMGR_NMGR_OP_UPLOAD 1
-
-
-void boot_serial_input(char *buf, int len);
-
-#endif /* __BOOTUTIL_SERIAL_PRIV_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/boot_serial/test/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/boot_serial/test/pkg.yml b/libs/boot_serial/test/pkg.yml
deleted file mode 100644
index 561c94b..0000000
--- a/libs/boot_serial/test/pkg.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-pkg.name: libs/boot_serial/test
-pkg.type: unittest
-pkg.description: "Boot serial unit tests."
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-
-pkg.deps:
- - libs/boot_serial
- - libs/testutil
-
-pkg.deps.SELFTEST:
- - libs/console/stub
-
-pkg.syscfg_vals.SELFTEST:
- CONFIG_FCB: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/libs/boot_serial/test/src/boot_test.c
----------------------------------------------------------------------
diff --git a/libs/boot_serial/test/src/boot_test.c b/libs/boot_serial/test/src/boot_test.c
deleted file mode 100644
index 853a391..0000000
--- a/libs/boot_serial/test/src/boot_test.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include "syscfg/syscfg.h"
-#include "util/base64.h"
-#include "util/crc16.h"
-#include "testutil/testutil.h"
-#include "hal/hal_flash.h"
-#include "hal/flash_map.h"
-
-#include "boot_serial_priv.h"
-
-void
-tx_msg(void *src, int len)
-{
- char *msg;
- char *enc;
- int off;
- uint16_t crc;
-
- crc = htons(crc16_ccitt(CRC16_INITIAL_CRC, src, len));
-
- /*
- * Lazy, malloc a buffer, fill it and send it.
- */
- msg = malloc(len + 2 * sizeof(uint16_t));
- assert(msg);
-
- *(uint16_t *)msg = ntohs(len + sizeof(uint16_t));
- off = sizeof(uint16_t);
- memcpy(&msg[off], src, len);
- off += len;
- memcpy(&msg[off], &crc, sizeof(crc));
- off += sizeof(uint16_t);
-
- enc = malloc(BASE64_ENCODE_SIZE(off) + 1);
- assert(enc);
-
- off = base64_encode(msg, off, enc, 1);
- assert(off > 0);
-
- boot_serial_input(enc, off + 1);
-
- free(enc);
- free(msg);
-}
-
-TEST_CASE(boot_serial_setup)
-{
-
-}
-
-TEST_CASE(boot_serial_empty_msg)
-{
- char buf[4];
- struct nmgr_hdr hdr;
-
- boot_serial_input(buf, 0);
-
- tx_msg(buf, 0);
-
- strcpy(buf, "--");
- tx_msg(buf, 2);
-
- memset(&hdr, 0, sizeof(hdr));
- tx_msg(&hdr, sizeof(hdr));
-
- hdr.nh_op = NMGR_OP_WRITE;
-
- tx_msg(&hdr, sizeof(hdr));
-}
-
-TEST_CASE(boot_serial_empty_img_msg)
-{
- char buf[sizeof(struct nmgr_hdr) + 32];
- struct nmgr_hdr *hdr;
-
- hdr = (struct nmgr_hdr *)buf;
- memset(hdr, 0, sizeof(*hdr));
- hdr->nh_op = NMGR_OP_WRITE;
- hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
- hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
- hdr->nh_len = htons(2);
- strcpy((char *)(hdr + 1), "{}");
-
- tx_msg(buf, sizeof(*hdr) + 2);
-}
-
-TEST_CASE(boot_serial_img_msg)
-{
- char img[16];
- char enc_img[BASE64_ENCODE_SIZE(sizeof(img))];
- char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
- int len;
- int rc;
- struct nmgr_hdr *hdr;
- const struct flash_area *fap;
-
- memset(img, 0xa5, sizeof(img));
- len = base64_encode(img, sizeof(img), enc_img, 1);
- assert(len > 0);
-
- hdr = (struct nmgr_hdr *)buf;
- memset(hdr, 0, sizeof(*hdr));
- hdr->nh_op = NMGR_OP_WRITE;
- hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
- hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
- len = sprintf((char *)(hdr + 1), "{\"off\":0,\"len\":16,\"data\":\"%s\"}",
- enc_img);
- hdr->nh_len = htons(len);
-
- len = sizeof(*hdr) + len;
-
- tx_msg(buf, len);
-
- /*
- * Validate contents inside image 0 slot
- */
- rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
- assert(rc == 0);
-
- rc = flash_area_read(fap, 0, enc_img, sizeof(img));
- assert(rc == 0);
- assert(!memcmp(enc_img, img, sizeof(img)));
-}
-
-TEST_CASE(boot_serial_upload_bigger_image)
-{
- char img[256];
- char enc_img[64];
- char buf[sizeof(struct nmgr_hdr) + 128];
- int len;
- int off;
- int rc;
- struct nmgr_hdr *hdr;
- const struct flash_area *fap;
- int i;
-
- for (i = 0; i < sizeof(img); i++) {
- img[i] = i;
- }
-
- for (off = 0; off < sizeof(img); off += 32) {
- len = base64_encode(&img[off], 32, enc_img, 1);
- assert(len > 0);
-
- hdr = (struct nmgr_hdr *)buf;
- memset(hdr, 0, sizeof(*hdr));
- hdr->nh_op = NMGR_OP_WRITE;
- hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
- hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
- if (off) {
- len = sprintf((char *)(hdr + 1), "{\"off\":%d,\"data\":\"%s\"}",
- off, enc_img);
- } else {
- len = sprintf((char *)(hdr + 1), "{\"off\": 0 ,\"len\":%ld, "
- "\"data\":\"%s\"}", (long)sizeof(img), enc_img);
- }
- hdr->nh_len = htons(len);
-
- len = sizeof(*hdr) + len;
-
- tx_msg(buf, len);
- }
-
- /*
- * Validate contents inside image 0 slot
- */
- rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
- assert(rc == 0);
-
- for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
- rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
- assert(rc == 0);
- assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
- }
-}
-
-TEST_SUITE(boot_serial_suite)
-{
- boot_serial_setup();
- boot_serial_empty_msg();
- boot_serial_empty_img_msg();
- boot_serial_img_msg();
- boot_serial_upload_bigger_image();
-}
-
-int
-boot_serial_test(void)
-{
- boot_serial_suite();
- return tu_any_failed;
-}
-
-#if MYNEWT_VAL(SELFTEST)
-int
-main(void)
-{
- tu_config.tc_print_results = 1;
- tu_init();
-
- boot_serial_test();
-
- return tu_any_failed;
-}
-
-#endif