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 33

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

Line No. Rev Author Line
1 24 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27 22 qaztronic
 
28
#include "uboot_lib.h"
29
 
30
 
31
/*-----------------------------------------------------------*/
32
int cmd_get_data_size(const char * arg, int default_size)
33
{
34
        /* Check for a size specification .b, .w or .l.
35
         */
36
        int len = strlen(arg);
37
        if (len > 2 && arg[len-2] == '.') {
38
                switch (arg[len-1]) {
39
                case 'b':
40
                        return 1;
41
                case 'w':
42
                        return 2;
43
                case 'l':
44
                        return 4;
45
                case 's':
46
                        return -2;
47
                default:
48
                        return -1;
49
                }
50
        }
51
        return default_size;
52
}
53
 
54
 
55
/*-----------------------------------------------------------*/
56
unsigned long simple_strtoul(const char *cp, char **endp,
57
                                unsigned int base)
58
{
59
        unsigned long result = 0;
60
 
61
  result  = strtoul( cp, endp, base );
62
 
63
        return result;
64
}
65
 
66
 
67
/*-----------------------------------------------------------*/
68
#define MAX_LINE_LENGTH_BYTES (64)
69
#define DEFAULT_LINE_LENGTH_BYTES (16)
70
int print_buffer(ulong addr, const void *data, uint width, uint count,
71
                 uint linelen)
72
{
73
        /* linebuf as a union causes proper alignment */
74
        union linebuf {
75
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
76
                uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
77
#endif
78
                uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
79
                uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
80
                uint8_t  uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
81
        } lb;
82
        int i;
83
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
84
        uint64_t __maybe_unused x;
85
#else
86
        uint32_t __maybe_unused x;
87
#endif
88
 
89
        if (linelen*width > MAX_LINE_LENGTH_BYTES)
90
                linelen = MAX_LINE_LENGTH_BYTES / width;
91
        if (linelen < 1)
92
                linelen = DEFAULT_LINE_LENGTH_BYTES / width;
93
 
94
        while (count) {
95
                uint thislinelen = linelen;
96
                PRINTF_MACRO("%08lx:", addr);
97
 
98
                /* check for overflow condition */
99
                if (count < thislinelen)
100
                        thislinelen = count;
101
 
102
                /* Copy from memory into linebuf and print hex values */
103
                for (i = 0; i < thislinelen; i++) {
104
                        if (width == 4)
105
      {
106
                                x = lb.ui[i] = *(volatile uint32_t *)data;
107
        PRINTF_MACRO(" %08x", x);
108
      }
109
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
110
                        else if (width == 8)
111
      {
112
                                x = lb.uq[i] = *(volatile uint64_t *)data;
113
        PRINTF_MACRO(" %016llx", (long long)x);
114
      }
115
#endif
116
                        else if (width == 2)
117
      {
118
                                x = lb.us[i] = *(volatile uint16_t *)data;
119
        PRINTF_MACRO(" %04x", x);
120
      }
121
                        else
122
      {
123
                                x = lb.uc[i] = *(volatile uint8_t *)data;
124
        PRINTF_MACRO(" %02x", x);
125
      }
126
// #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
127
                        // PRINTF_MACRO(" %0*llx", width * 2, (long long)x);
128
// #else
129
                        // PRINTF_MACRO(" %0*x", width * 2, x);
130
// #endif
131
                        data += width;
132
                }
133
 
134
                while (thislinelen < linelen) {
135
                        /* fill line with whitespace for nice ASCII print */
136
                        for (i=0; i<width*2+1; i++)
137
                                puts(" ");
138
                        linelen--;
139
                }
140
 
141
                /* Print data in ASCII characters */
142
                for (i = 0; i < thislinelen * width; i++) {
143
                        if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
144
                                lb.uc[i] = '.';
145
                }
146
                lb.uc[i] = '\0';
147
                PRINTF_MACRO("    %s\r\n", lb.uc);
148
 
149
                /* update references */
150
                addr += thislinelen * width;
151
                count -= thislinelen;
152
 
153
                // if (ctrlc())
154
                        // return -1;
155
        }
156
 
157
        return 0;
158
}
159
 
160
 
161
 
162
 
163
 

powered by: WebSVN 2.1.0

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