stdio: Correct a build error with driver model
[oweals/u-boot.git] / common / cmd_itest.c
index 2c8e5d05e141ddf936d2b4b6fdf122730ed600dc..91ae5c2704c882be8d4457d67d5f8488b19d2f1c 100644 (file)
@@ -2,23 +2,7 @@
  * (C) Copyright 2003
  * Tait Electronics Limited, Christchurch, New Zealand
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
@@ -31,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
@@ -65,21 +52,35 @@ 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);
+                       break;
+               case 2:
+                       l = (long)(*(unsigned short *)buf);
+                       break;
+               case 4:
+                       l = (long)(*(unsigned long *)buf);
+                       break;
                }
+               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)
@@ -87,6 +88,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;
        }