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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [cli/] [util/] [uboot_lib.c] - Diff between revs 22 and 24

Only display areas with differences | Details | Blame | View Log

Rev 22 Rev 24
/*-----------------------------------------------------------*/
//////////////////////////////////////////////////////////////////////
 
////                                                              ////
 
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
 
////                                                              ////
 
//// This source file may be used and distributed without         ////
 
//// restriction provided that this copyright statement is not    ////
 
//// removed from the file and that any derivative work contains  ////
 
//// the original copyright notice and the associated disclaimer. ////
 
////                                                              ////
 
//// This source file is free software; you can redistribute it   ////
 
//// and/or modify it under the terms of the GNU Lesser General   ////
 
//// Public License as published by the Free Software Foundation; ////
 
//// either version 2.1 of the License, or (at your option) any   ////
 
//// later version.                                               ////
 
////                                                              ////
 
//// This source 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 Lesser General Public License for more ////
 
//// details.                                                     ////
 
////                                                              ////
 
//// You should have received a copy of the GNU Lesser General    ////
 
//// Public License along with this source; if not, download it   ////
 
//// from http://www.opencores.org/lgpl.shtml                     ////
 
////                                                              ////
 
//////////////////////////////////////////////////////////////////////
 
 
#include "uboot_lib.h"
#include "uboot_lib.h"
 
 
 
 
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
int cmd_get_data_size(const char * arg, int default_size)
int cmd_get_data_size(const char * arg, int default_size)
{
{
        /* Check for a size specification .b, .w or .l.
        /* Check for a size specification .b, .w or .l.
         */
         */
        int len = strlen(arg);
        int len = strlen(arg);
        if (len > 2 && arg[len-2] == '.') {
        if (len > 2 && arg[len-2] == '.') {
                switch (arg[len-1]) {
                switch (arg[len-1]) {
                case 'b':
                case 'b':
                        return 1;
                        return 1;
                case 'w':
                case 'w':
                        return 2;
                        return 2;
                case 'l':
                case 'l':
                        return 4;
                        return 4;
                case 's':
                case 's':
                        return -2;
                        return -2;
                default:
                default:
                        return -1;
                        return -1;
                }
                }
        }
        }
        return default_size;
        return default_size;
}
}
 
 
 
 
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
unsigned long simple_strtoul(const char *cp, char **endp,
unsigned long simple_strtoul(const char *cp, char **endp,
                                unsigned int base)
                                unsigned int base)
{
{
        unsigned long result = 0;
        unsigned long result = 0;
 
 
  result  = strtoul( cp, endp, base );
  result  = strtoul( cp, endp, base );
 
 
        return result;
        return result;
}
}
 
 
 
 
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
#define MAX_LINE_LENGTH_BYTES (64)
#define MAX_LINE_LENGTH_BYTES (64)
#define DEFAULT_LINE_LENGTH_BYTES (16)
#define DEFAULT_LINE_LENGTH_BYTES (16)
int print_buffer(ulong addr, const void *data, uint width, uint count,
int print_buffer(ulong addr, const void *data, uint width, uint count,
                 uint linelen)
                 uint linelen)
{
{
        /* linebuf as a union causes proper alignment */
        /* linebuf as a union causes proper alignment */
        union linebuf {
        union linebuf {
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
                uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
                uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
#endif
#endif
                uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
                uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
                uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
                uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
                uint8_t  uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
                uint8_t  uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
        } lb;
        } lb;
        int i;
        int i;
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
        uint64_t __maybe_unused x;
        uint64_t __maybe_unused x;
#else
#else
        uint32_t __maybe_unused x;
        uint32_t __maybe_unused x;
#endif
#endif
 
 
        if (linelen*width > MAX_LINE_LENGTH_BYTES)
        if (linelen*width > MAX_LINE_LENGTH_BYTES)
                linelen = MAX_LINE_LENGTH_BYTES / width;
                linelen = MAX_LINE_LENGTH_BYTES / width;
        if (linelen < 1)
        if (linelen < 1)
                linelen = DEFAULT_LINE_LENGTH_BYTES / width;
                linelen = DEFAULT_LINE_LENGTH_BYTES / width;
 
 
        while (count) {
        while (count) {
                uint thislinelen = linelen;
                uint thislinelen = linelen;
                PRINTF_MACRO("%08lx:", addr);
                PRINTF_MACRO("%08lx:", addr);
 
 
                /* check for overflow condition */
                /* check for overflow condition */
                if (count < thislinelen)
                if (count < thislinelen)
                        thislinelen = count;
                        thislinelen = count;
 
 
                /* Copy from memory into linebuf and print hex values */
                /* Copy from memory into linebuf and print hex values */
                for (i = 0; i < thislinelen; i++) {
                for (i = 0; i < thislinelen; i++) {
                        if (width == 4)
                        if (width == 4)
      {
      {
                                x = lb.ui[i] = *(volatile uint32_t *)data;
                                x = lb.ui[i] = *(volatile uint32_t *)data;
        PRINTF_MACRO(" %08x", x);
        PRINTF_MACRO(" %08x", x);
      }
      }
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
                        else if (width == 8)
                        else if (width == 8)
      {
      {
                                x = lb.uq[i] = *(volatile uint64_t *)data;
                                x = lb.uq[i] = *(volatile uint64_t *)data;
        PRINTF_MACRO(" %016llx", (long long)x);
        PRINTF_MACRO(" %016llx", (long long)x);
      }
      }
#endif
#endif
                        else if (width == 2)
                        else if (width == 2)
      {
      {
                                x = lb.us[i] = *(volatile uint16_t *)data;
                                x = lb.us[i] = *(volatile uint16_t *)data;
        PRINTF_MACRO(" %04x", x);
        PRINTF_MACRO(" %04x", x);
      }
      }
                        else
                        else
      {
      {
                                x = lb.uc[i] = *(volatile uint8_t *)data;
                                x = lb.uc[i] = *(volatile uint8_t *)data;
        PRINTF_MACRO(" %02x", x);
        PRINTF_MACRO(" %02x", x);
      }
      }
// #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
// #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
                        // PRINTF_MACRO(" %0*llx", width * 2, (long long)x);
                        // PRINTF_MACRO(" %0*llx", width * 2, (long long)x);
// #else
// #else
                        // PRINTF_MACRO(" %0*x", width * 2, x);
                        // PRINTF_MACRO(" %0*x", width * 2, x);
// #endif
// #endif
                        data += width;
                        data += width;
                }
                }
 
 
                while (thislinelen < linelen) {
                while (thislinelen < linelen) {
                        /* fill line with whitespace for nice ASCII print */
                        /* fill line with whitespace for nice ASCII print */
                        for (i=0; i<width*2+1; i++)
                        for (i=0; i<width*2+1; i++)
                                puts(" ");
                                puts(" ");
                        linelen--;
                        linelen--;
                }
                }
 
 
                /* Print data in ASCII characters */
                /* Print data in ASCII characters */
                for (i = 0; i < thislinelen * width; i++) {
                for (i = 0; i < thislinelen * width; i++) {
                        if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
                        if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
                                lb.uc[i] = '.';
                                lb.uc[i] = '.';
                }
                }
                lb.uc[i] = '\0';
                lb.uc[i] = '\0';
                PRINTF_MACRO("    %s\r\n", lb.uc);
                PRINTF_MACRO("    %s\r\n", lb.uc);
 
 
                /* update references */
                /* update references */
                addr += thislinelen * width;
                addr += thislinelen * width;
                count -= thislinelen;
                count -= thislinelen;
 
 
                // if (ctrlc())
                // if (ctrlc())
                        // return -1;
                        // return -1;
        }
        }
 
 
        return 0;
        return 0;
}
}
 
 
 
 
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

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