summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/asm-offsets.c3
-rw-r--r--lib/div64.c1
-rw-r--r--lib/fdtdec.c61
-rw-r--r--lib/hashtable.c17
-rw-r--r--lib/lmb.c6
-rw-r--r--lib/sha1.c2
-rw-r--r--lib/time.c18
-rw-r--r--lib/vsprintf.c22
8 files changed, 104 insertions, 26 deletions
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
index 6ea7b03..129bc3e 100644
--- a/lib/asm-offsets.c
+++ b/lib/asm-offsets.c
@@ -28,6 +28,9 @@ int main(void)
DEFINE(GD_SIZE, sizeof(struct global_data));
DEFINE(GD_BD, offsetof(struct global_data, bd));
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+ DEFINE(GD_MALLOC_BASE, offsetof(struct global_data, malloc_base));
+#endif
#if defined(CONFIG_ARM)
diff --git a/lib/div64.c b/lib/div64.c
index e688a91..795ef0e 100644
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -16,6 +16,7 @@
* assembly versions such as arch/powerpc/lib/div64.S and arch/sh/lib/div64.S.
*/
+#include <div64.h>
#include <linux/types.h>
uint32_t __div64_32(uint64_t *n, uint32_t base)
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index aaa6620..eb5aa20 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -5,9 +5,11 @@
#ifndef USE_HOSTCC
#include <common.h>
+#include <errno.h>
#include <serial.h>
#include <libfdt.h>
#include <fdtdec.h>
+#include <linux/ctype.h>
#include <asm/gpio.h>
@@ -319,6 +321,65 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
return num_found;
}
+int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
+ int *seqp)
+{
+ int base_len = strlen(base);
+ const char *find_name;
+ int find_namelen;
+ int prop_offset;
+ int aliases;
+
+ find_name = fdt_get_name(blob, offset, &find_namelen);
+ debug("Looking for '%s' at %d, name %s\n", base, offset, find_name);
+
+ aliases = fdt_path_offset(blob, "/aliases");
+ for (prop_offset = fdt_first_property_offset(blob, aliases);
+ prop_offset > 0;
+ prop_offset = fdt_next_property_offset(blob, prop_offset)) {
+ const char *prop;
+ const char *name;
+ const char *slash;
+ const char *p;
+ int len;
+
+ prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
+ debug(" - %s, %s\n", name, prop);
+ if (len < find_namelen || *prop != '/' || prop[len - 1] ||
+ strncmp(name, base, base_len))
+ continue;
+
+ slash = strrchr(prop, '/');
+ if (strcmp(slash + 1, find_name))
+ continue;
+ for (p = name; *p; p++) {
+ if (isdigit(*p)) {
+ *seqp = simple_strtoul(p, NULL, 10);
+ debug("Found seq %d\n", *seqp);
+ return 0;
+ }
+ }
+ }
+
+ debug("Not found\n");
+ return -ENOENT;
+}
+
+int fdtdec_get_alias_node(const void *blob, const char *name)
+{
+ const char *prop;
+ int alias_node;
+ int len;
+
+ if (!blob)
+ return -FDT_ERR_NOTFOUND;
+ alias_node = fdt_path_offset(blob, "/aliases");
+ prop = fdt_getprop(blob, alias_node, name, &len);
+ if (!prop)
+ return -FDT_ERR_NOTFOUND;
+ return fdt_path_offset(blob, prop);
+}
+
int fdtdec_check_fdt(void)
{
/*
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 4356b23..18ed590 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -776,7 +776,7 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[])
int himport_r(struct hsearch_data *htab,
const char *env, size_t size, const char sep, int flag,
- int nvars, char * const vars[])
+ int crlf_is_lf, int nvars, char * const vars[])
{
char *data, *sp, *dp, *name, *value;
char *localvars[nvars];
@@ -841,6 +841,21 @@ int himport_r(struct hsearch_data *htab,
}
}
+ if(!size)
+ return 1; /* everything OK */
+ if(crlf_is_lf) {
+ /* Remove Carriage Returns in front of Line Feeds */
+ unsigned ignored_crs = 0;
+ for(;dp < data + size && *dp; ++dp) {
+ if(*dp == '\r' &&
+ dp < data + size - 1 && *(dp+1) == '\n')
+ ++ignored_crs;
+ else
+ *(dp-ignored_crs) = *dp;
+ }
+ size -= ignored_crs;
+ dp = data;
+ }
/* Parse environment; allow for '\0' and 'sep' as separators */
do {
ENTRY e, *rv;
diff --git a/lib/lmb.c b/lib/lmb.c
index 081e418..49a3c9e 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -332,14 +332,12 @@ int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr)
return 0;
}
-void __board_lmb_reserve(struct lmb *lmb)
+__weak void board_lmb_reserve(struct lmb *lmb)
{
/* please define platform specific board_lmb_reserve() */
}
-void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
-void __arch_lmb_reserve(struct lmb *lmb)
+__weak void arch_lmb_reserve(struct lmb *lmb)
{
/* please define platform specific arch_lmb_reserve() */
}
-void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
diff --git a/lib/sha1.c b/lib/sha1.c
index 0a5f688..05b17a2 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -389,8 +389,6 @@ void sha1_hmac(const unsigned char *key, int keylen,
memset (&ctx, 0, sizeof (sha1_context));
}
-static const char _sha1_src[] = "_sha1_src";
-
#ifdef SELF_TEST
/*
* FIPS-180-1 test vectors
diff --git a/lib/time.c b/lib/time.c
index 73c3b6a..c7b0264 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -15,12 +15,13 @@
#endif
#ifndef CONFIG_WD_PERIOD
-# define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default*/
+# define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default */
#endif
DECLARE_GLOBAL_DATA_PTR;
#ifdef CONFIG_SYS_TIMER_RATE
+/* Returns tick rate in ticks per second */
ulong notrace get_tbclk(void)
{
return CONFIG_SYS_TIMER_RATE;
@@ -51,9 +52,10 @@ unsigned long long __weak notrace get_ticks(void)
return ((unsigned long long)gd->timebase_h << 32) | gd->timebase_l;
}
-static unsigned long long notrace tick_to_time(uint64_t tick)
+/* Returns time in milliseconds */
+static unsigned long long notrace tick_to_time(unsigned long long tick)
{
- unsigned int div = get_tbclk();
+ ulong div = get_tbclk();
tick *= CONFIG_SYS_HZ;
do_div(tick, div);
@@ -65,6 +67,7 @@ int __weak timer_init(void)
return 0;
}
+/* Returns time in milliseconds */
ulong __weak get_timer(ulong base)
{
return tick_to_time(get_ticks()) - base;
@@ -74,9 +77,10 @@ unsigned long __weak notrace timer_get_us(void)
{
return tick_to_time(get_ticks() * 1000);
}
+
static unsigned long long usec_to_tick(unsigned long usec)
{
- uint64_t tick = usec;
+ unsigned long long tick = usec;
tick *= get_tbclk();
do_div(tick, 1000000);
return tick;
@@ -85,12 +89,10 @@ static unsigned long long usec_to_tick(unsigned long usec)
void __weak __udelay(unsigned long usec)
{
unsigned long long tmp;
- ulong tmo;
- tmo = usec_to_tick(usec);
- tmp = get_ticks() + tmo; /* get current timestamp */
+ tmp = get_ticks() + usec_to_tick(usec); /* get current timestamp */
- while (get_ticks() < tmp) /* loop till event */
+ while (get_ticks() < tmp+1) /* loop till event */
/*NOP*/;
}
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 60874da..7ec758e 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -28,17 +28,6 @@
/* some reluctance to put this into a new limits.h, so it is here */
#define INT_MAX ((int)(~0U>>1))
-static const char hex_asc[] = "0123456789abcdef";
-#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
-#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
-
-static inline char *pack_hex_byte(char *buf, u8 byte)
-{
- *buf++ = hex_asc_hi(byte);
- *buf++ = hex_asc_lo(byte);
- return buf;
-}
-
unsigned long simple_strtoul(const char *cp, char **endp,
unsigned int base)
{
@@ -434,6 +423,17 @@ static char *string(char *buf, char *end, char *s, int field_width,
}
#ifdef CONFIG_CMD_NET
+static const char hex_asc[] = "0123456789abcdef";
+#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
+#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
+
+static inline char *pack_hex_byte(char *buf, u8 byte)
+{
+ *buf++ = hex_asc_hi(byte);
+ *buf++ = hex_asc_lo(byte);
+ return buf;
+}
+
static char *mac_address_string(char *buf, char *end, u8 *addr, int field_width,
int precision, int flags)
{