aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Bießmann2013-02-06 22:58:19 -0600
committerTom Rini2013-03-11 16:00:28 -0500
commitefd7c11404e59874d4da86d04cab4acacf77d793 (patch)
treed62969bc304fa19f68d77371c56b878584b2413b /lib
parenta2681707b2478abef34b8c403e7ab52daae9c331 (diff)
downloadu-boot-efd7c11404e59874d4da86d04cab4acacf77d793.tar.gz
u-boot-efd7c11404e59874d4da86d04cab4acacf77d793.tar.xz
u-boot-efd7c11404e59874d4da86d04cab4acacf77d793.zip
display_options:print_buffer: align ASCII print
This patch adds whitespace to the printed hex numbers to have an aligned ASCII printout at the end of the line. This changes for example the md output from: ---8<--- OMAP3 Tricorder # md.l $loadaddr 5 82000000: 30200109 20a4028c 90010000 08a00000 .. 0... ........ 82000010: 01010000 .... --->8--- to ---8<--- OMAP3 Tricorder # md.l $loadaddr 5 82000000: 30200109 20a4028c 90010000 08a00000 .. 0... ........ 82000010: 01010000 .... --->8--- The cost of this is about 72 byte .text increase (tested with at91 build). Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/display_options.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/display_options.c b/lib/display_options.c
index 0339970e7d..e6d684bd60 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -115,14 +115,15 @@ int print_buffer(ulong addr, const void *data, uint width, uint count,
115 linelen = DEFAULT_LINE_LENGTH_BYTES / width; 115 linelen = DEFAULT_LINE_LENGTH_BYTES / width;
116 116
117 while (count) { 117 while (count) {
118 uint thislinelen = linelen;
118 printf("%08lx:", addr); 119 printf("%08lx:", addr);
119 120
120 /* check for overflow condition */ 121 /* check for overflow condition */
121 if (count < linelen) 122 if (count < thislinelen)
122 linelen = count; 123 thislinelen = count;
123 124
124 /* Copy from memory into linebuf and print hex values */ 125 /* Copy from memory into linebuf and print hex values */
125 for (i = 0; i < linelen; i++) { 126 for (i = 0; i < thislinelen; i++) {
126 uint32_t x; 127 uint32_t x;
127 if (width == 4) 128 if (width == 4)
128 x = lb.ui[i] = *(volatile uint32_t *)data; 129 x = lb.ui[i] = *(volatile uint32_t *)data;
@@ -134,8 +135,15 @@ int print_buffer(ulong addr, const void *data, uint width, uint count,
134 data += width; 135 data += width;
135 } 136 }
136 137
138 while (thislinelen < linelen) {
139 /* fill line with whitespace for nice ASCII print */
140 for (i=0; i<width*2+1; i++)
141 puts(" ");
142 linelen--;
143 }
144
137 /* Print data in ASCII characters */ 145 /* Print data in ASCII characters */
138 for (i = 0; i < linelen * width; i++) { 146 for (i = 0; i < thislinelen * width; i++) {
139 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80) 147 if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
140 lb.uc[i] = '.'; 148 lb.uc[i] = '.';
141 } 149 }
@@ -143,8 +151,8 @@ int print_buffer(ulong addr, const void *data, uint width, uint count,
143 printf(" %s\n", lb.uc); 151 printf(" %s\n", lb.uc);
144 152
145 /* update references */ 153 /* update references */
146 addr += linelen * width; 154 addr += thislinelen * width;
147 count -= linelen; 155 count -= thislinelen;
148 156
149 if (ctrlc()) 157 if (ctrlc())
150 return -1; 158 return -1;