OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [cli/] [util/] [uboot_lib.c] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 qaztronic
/*-----------------------------------------------------------*/
2
 
3
#include "uboot_lib.h"
4
 
5
 
6
/*-----------------------------------------------------------*/
7
int cmd_get_data_size(const char * arg, int default_size)
8
{
9
        /* Check for a size specification .b, .w or .l.
10
         */
11
        int len = strlen(arg);
12
        if (len > 2 && arg[len-2] == '.') {
13
                switch (arg[len-1]) {
14
                case 'b':
15
                        return 1;
16
                case 'w':
17
                        return 2;
18
                case 'l':
19
                        return 4;
20
                case 's':
21
                        return -2;
22
                default:
23
                        return -1;
24
                }
25
        }
26
        return default_size;
27
}
28
 
29
 
30
/*-----------------------------------------------------------*/
31
unsigned long simple_strtoul(const char *cp, char **endp,
32
                                unsigned int base)
33
{
34
        unsigned long result = 0;
35
 
36
  result  = strtoul( cp, endp, base );
37
 
38
        return result;
39
}
40
 
41
 
42
/*-----------------------------------------------------------*/
43
#define MAX_LINE_LENGTH_BYTES (64)
44
#define DEFAULT_LINE_LENGTH_BYTES (16)
45
int print_buffer(ulong addr, const void *data, uint width, uint count,
46
                 uint linelen)
47
{
48
        /* linebuf as a union causes proper alignment */
49
        union linebuf {
50
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
51
                uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
52
#endif
53
                uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
54
                uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
55
                uint8_t  uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
56
        } lb;
57
        int i;
58
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
59
        uint64_t __maybe_unused x;
60
#else
61
        uint32_t __maybe_unused x;
62
#endif
63
 
64
        if (linelen*width > MAX_LINE_LENGTH_BYTES)
65
                linelen = MAX_LINE_LENGTH_BYTES / width;
66
        if (linelen < 1)
67
                linelen = DEFAULT_LINE_LENGTH_BYTES / width;
68
 
69
        while (count) {
70
                uint thislinelen = linelen;
71
                PRINTF_MACRO("%08lx:", addr);
72
 
73
                /* check for overflow condition */
74
                if (count < thislinelen)
75
                        thislinelen = count;
76
 
77
                /* Copy from memory into linebuf and print hex values */
78
                for (i = 0; i < thislinelen; i++) {
79
                        if (width == 4)
80
      {
81
                                x = lb.ui[i] = *(volatile uint32_t *)data;
82
        PRINTF_MACRO(" %08x", x);
83
      }
84
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
85
                        else if (width == 8)
86
      {
87
                                x = lb.uq[i] = *(volatile uint64_t *)data;
88
        PRINTF_MACRO(" %016llx", (long long)x);
89
      }
90
#endif
91
                        else if (width == 2)
92
      {
93
                                x = lb.us[i] = *(volatile uint16_t *)data;
94
        PRINTF_MACRO(" %04x", x);
95
      }
96
                        else
97
      {
98
                                x = lb.uc[i] = *(volatile uint8_t *)data;
99
        PRINTF_MACRO(" %02x", x);
100
      }
101
// #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
102
                        // PRINTF_MACRO(" %0*llx", width * 2, (long long)x);
103
// #else
104
                        // PRINTF_MACRO(" %0*x", width * 2, x);
105
// #endif
106
                        data += width;
107
                }
108
 
109
                while (thislinelen < linelen) {
110
                        /* fill line with whitespace for nice ASCII print */
111
                        for (i=0; i<width*2+1; i++)
112
                                puts(" ");
113
                        linelen--;
114
                }
115
 
116
                /* Print data in ASCII characters */
117
                for (i = 0; i < thislinelen * width; i++) {
118
                        if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
119
                                lb.uc[i] = '.';
120
                }
121
                lb.uc[i] = '\0';
122
                PRINTF_MACRO("    %s\r\n", lb.uc);
123
 
124
                /* update references */
125
                addr += thislinelen * width;
126
                count -= thislinelen;
127
 
128
                // if (ctrlc())
129
                        // return -1;
130
        }
131
 
132
        return 0;
133
}
134
 
135
 
136
 
137
 
138
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.