]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_itest.c
armv8/fsl_lsch3: Change arch to fsl-layerscape
[u-boot] / common / cmd_itest.c
index 29f8076f825568833cdc4324b9aaf778e67f4180..596341c9635ac6c1777c171fbda01186e23e02a3 100644 (file)
@@ -15,6 +15,9 @@
 #include <common.h>
 #include <config.h>
 #include <command.h>
+#include <mapmem.h>
+
+#include <asm/io.h>
 
 #define EQ     0
 #define NE     1
@@ -49,21 +52,29 @@ static const op_tbl_t op_table [] = {
 static long evalexp(char *s, int w)
 {
        long l = 0;
-       long *p;
+       unsigned long addr;
+       void *buf;
 
        /* if the parameter starts with a * then assume is a pointer to the value we want */
        if (s[0] == '*') {
-               p = (long *)simple_strtoul(&s[1], NULL, 16);
+               addr = simple_strtoul(&s[1], NULL, 16);
+               buf = map_physmem(addr, w, MAP_WRBACK);
+               if (!buf) {
+                       puts("Failed to map physical memory\n");
+                       return 0;
+               }
                switch (w) {
-               case 1: return((long)(*(unsigned char *)p));
-               case 2: return((long)(*(unsigned short *)p));
-               case 4: return(*p);
+               case 1: l = (long)(*(unsigned char *)buf);
+               case 2: l = (long)(*(unsigned short *)buf);
+               case 4: l = (long)(*(unsigned long *)buf);
                }
+               unmap_physmem(buf, w);
+               return l;
        } else {
                l = simple_strtoul(s, NULL, 16);
        }
 
-       return (l & ((1 << (w * 8)) - 1));
+       return l & ((1UL << (w * 8)) - 1);
 }
 
 static char * evalstr(char *s)
@@ -71,6 +82,19 @@ static char * evalstr(char *s)
        /* if the parameter starts with a * then assume a string pointer else its a literal */
        if (s[0] == '*') {
                return (char *)simple_strtoul(&s[1], NULL, 16);
+       } else if (s[0] == '$') {
+               int i = 2;
+
+               if (s[1] != '{')
+                       return NULL;
+
+               while (s[i] != '}') {
+                       if (s[i] == 0)
+                               return NULL;
+                       i++;
+               }
+               s[i] = 0;
+               return  getenv((const char *)&s[2]);
        } else {
                return s;
        }