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

Subversion Repositories qaz_libs

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /qaz_libs/trunk/cli
    from Rev 18 to Rev 22
    Reverse comparison

Rev 18 → Rev 22

/sys_error.h File deleted
/sys_cmd.c File deleted
/memtest.c File deleted
/sys_cli.c File deleted
/sys_cmd.h File deleted
/memtest.h File deleted
/sys_error.c File deleted
/cli/memtest.c
0,0 → 1,222
/**********************************************************************
*
* Filename: memtest.c
*
* Description: General-purpose memory testing functions.
*
* Notes: This software can be easily ported to systems with
* different data bus widths by redefining 'datum'.
*
*
* Copyright (c) 1998 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/
 
 
#include "memtest.h"
 
 
/**********************************************************************
*
* Function: memTestDataBus()
*
* Description: Test the data bus wiring in a memory region by
* performing a walking 1's test at a fixed address
* within that region. The address (and hence the
* memory region) is selected by the caller.
*
* Notes:
*
* Returns: 0 if the test succeeds.
* A non-zero result is the first pattern that failed.
*
**********************************************************************/
datum
memTestDataBus(volatile datum * address)
{
datum pattern;
 
 
/*
* Perform a walking 1's test at the given address.
*/
for (pattern = 1; pattern != 0; pattern <<= 1)
{
/*
* Write the test pattern.
*/
*address = pattern;
 
/*
* Read it back (immediately is okay for this test).
*/
if (*address != pattern)
{
return (pattern);
}
}
 
return (0);
 
} /* memTestDataBus() */
 
 
/**********************************************************************
*
* Function: memTestAddressBus()
*
* Description: Test the address bus wiring in a memory region by
* performing a walking 1's test on the relevant bits
* of the address and checking for aliasing. This test
* will find single-bit address failures such as stuck
* -high, stuck-low, and shorted pins. The base address
* and size of the region are selected by the caller.
*
* Notes: For best results, the selected base address should
* have enough LSB 0's to guarantee single address bit
* changes. For example, to test a 64-Kbyte region,
* select a base address on a 64-Kbyte boundary. Also,
* select the region size as a power-of-two--if at all
* possible.
*
* Returns: NULL if the test succeeds.
* A non-zero result is the first address at which an
* aliasing problem was uncovered. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum *
memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long addressMask = (nBytes/sizeof(datum) - 1);
unsigned long offset;
unsigned long testOffset;
 
datum pattern = (datum) 0xAAAAAAAA;
datum antipattern = (datum) 0x55555555;
 
 
/*
* Write the default pattern at each of the power-of-two offsets.
*/
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
baseAddress[offset] = pattern;
}
 
/*
* Check for address bits stuck high.
*/
testOffset = 0;
baseAddress[testOffset] = antipattern;
 
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
}
 
baseAddress[testOffset] = pattern;
 
/*
* Check for address bits stuck low or shorted.
*/
for (testOffset = 1; (testOffset & addressMask) != 0; testOffset <<= 1)
{
baseAddress[testOffset] = antipattern;
 
if (baseAddress[0] != pattern)
{
return ((datum *) &baseAddress[testOffset]);
}
 
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
if ((baseAddress[offset] != pattern) && (offset != testOffset))
{
return ((datum *) &baseAddress[testOffset]);
}
}
 
baseAddress[testOffset] = pattern;
}
 
return (NULL);
 
} /* memTestAddressBus() */
 
 
/**********************************************************************
*
* Function: memTestDevice()
*
* Description: Test the integrity of a physical memory device by
* performing an increment/decrement test over the
* entire region. In the process every storage bit
* in the device is tested as a zero and a one. The
* base address and the size of the region are
* selected by the caller.
*
* Notes:
*
* Returns: NULL if the test succeeds.
*
* A non-zero result is the first address at which an
* incorrect value was read back. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum *
memTestDevice(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long offset;
unsigned long nWords = nBytes / sizeof(datum);
 
datum pattern;
datum antipattern;
 
 
/*
* Fill memory with a known pattern.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
baseAddress[offset] = pattern;
}
 
/*
* Check each location and invert it for the second pass.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
 
antipattern = ~pattern;
baseAddress[offset] = antipattern;
}
 
/*
* Check each location for the inverted pattern and zero it.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
antipattern = ~pattern;
if (baseAddress[offset] != antipattern)
{
return ((datum *) &baseAddress[offset]);
}
}
 
return (NULL);
 
} /* memTestDevice() */
 
/cli/sys_cmd.c
0,0 → 1,129
/*-----------------------------------------------------------*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sys_cmd.h"
 
 
/*-----------------------------------------------------------*/
static unsigned int cli_no_of_commands;
 
void cli_init( void )
{
int i;
for(i = 0; cli_commands[i].func != NULL; i++);
cli_no_of_commands = i;
}
 
 
/*-----------------------------------------------------------*/
static int cmd_cmp( const void *e1, const void *e2 )
{
struct cli_cmd_tab_t *p_cmd_1 = (struct cli_cmd_tab_t *)e1;
struct cli_cmd_tab_t *p_cmd_2 = (struct cli_cmd_tab_t *)e2;
 
return strncmp( p_cmd_1->cmd, p_cmd_2->cmd, MAX_CMD_LENGTH );
}
 
 
/*-----------------------------------------------------------*/
cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check )
{
struct cli_cmd_tab_t *cli_cmd;
cli_cmd = (struct cli_cmd_tab_t *) bsearch( cmd_to_check, cli_commands, cli_no_of_commands, sizeof(struct cli_cmd_tab_t), cmd_cmp );
 
return(cli_cmd);
}
 
 
/*-----------------------------------------------------------*/
static char func_help( const unsigned char argc, const char *argv[] )
{
unsigned int i;
 
PRINTF_MACRO( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" );
PRINTF_MACRO( "\r\n" );
PRINTF_MACRO( "Commands:\r\n" );
 
for( i = 0; i < cli_no_of_commands; i++ )
puts( cli_commands[i].help_string );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
static char func_peek( const unsigned char argc, const char *argv[] )
{
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
 
PRINTF_MACRO( "peek: %s => 0x%08x \r\n", argv[1], *address );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
static char func_poke( const unsigned char argc, const char *argv[] )
{
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
unsigned int value = strtoul( argv[2], (char **)NULL, 16 );
 
*((volatile unsigned int *)address) = value;
 
PRINTF_MACRO( "poke: %s <= %s \r\n", argv[1], argv[2] );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
#include "memtest.h"
 
static char func_memtest( const unsigned char argc, const char *argv[] )
{
datum *address = (datum *)( strtoul( argv[1], (char **)NULL, 16 ) );
unsigned long nBytes = strtoul( argv[2], (char **)NULL, 16 );
 
if( argc != 3 || address == NULL || nBytes == 0 )
{
PRINTF_MACRO( "memtest: bad args \r\n" );
return( EXIT_FAILURE );
}
 
PRINTF_MACRO( "running memTestDataBus() ... " );
 
if( memTestDataBus( address ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
 
PRINTF_MACRO( "running memTestAddressBus() ... " );
 
if( memTestAddressBus( address, nBytes ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
 
PRINTF_MACRO( "running memTestDevice() ... " );
 
if( memTestDevice( address, nBytes ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
// command table
#include "sys_cmd_table.h"
 
 
/cli/memtest.h
0,0 → 1,41
/**********************************************************************
*
* Filename: memtest.h
*
* Description: Memory-testing module API.
*
* Notes: The memory tests can be easily ported to systems with
* different data bus widths by redefining 'datum' type.
*
*
* Copyright (c) 2000 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/
 
#ifndef _memtest_h
#define _memtest_h
 
 
/*
* Define NULL pointer value.
*/
#ifndef NULL
#define NULL (void *) 0
#endif
 
/*
* Set the data bus width.
*/
typedef unsigned long datum;
 
/*
* Function prototypes.
*/
datum memTestDataBus(volatile datum * address);
datum * memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes);
datum * memTestDevice(volatile datum * baseAddress, unsigned long nBytes);
 
 
#endif /* _memtest_h */
/cli/sys_cli.c
0,0 → 1,251
/*-----------------------------------------------------------*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
#include "sys_cmd.h"
#include "sys_error.h"
 
 
 
/*-----------------------------------------------------------*/
#ifdef ANSI_ESCAPE_CODE
#define ASCII_ESC '\x1b'
 
static void send_csi( char c )
{
putchar( ASCII_ESC );
putchar( '[' );
putchar( c );
}
#else
static void send_csi( char c ) {};
#endif
 
 
/*-----------------------------------------------------------*/
static char *cli_edit_buffer( char *in_buffer, char *out_buffer, unsigned int line_length )
{
static char *out_ptr;
static char *begin_ptr;
static char *end_ptr;
 
#ifdef ANSI_ESCAPE_CODE
static char prev_char;
static unsigned int csi;
#endif
 
unsigned int i;
 
if( out_buffer != NULL )
{
out_ptr = out_buffer;
begin_ptr = out_buffer;
end_ptr = out_buffer + INPUT_LINE_LENGTH;
 
#ifdef ANSI_ESCAPE_CODE
prev_char = 0;
csi = 0;
#endif
}
 
for( i = 0 ; i < line_length ; i++ )
{
 
if( out_ptr >= end_ptr )
{
*end_ptr = '\0';
return( NULL );
}
 
if( out_ptr < begin_ptr )
sys_error_fatal( FATAL_ERROR_CLI );
 
switch( in_buffer[i] )
{
case '\0':
return( NULL );
break;
 
case '\n':
*out_ptr = '\0';
return( NULL );
break;
 
case '\r':
*out_ptr = '\0';
return( NULL );
break;
 
case '\b':
if( out_ptr != begin_ptr )
{
send_csi( 'P' );
out_ptr--;
} else
{
putchar( ' ' );
send_csi( '\a' );
}
break;
 
#ifdef ANSI_ESCAPE_CODE
case ASCII_ESC:
break;
 
case '[':
if( prev_char == ASCII_ESC )
{
csi = 1;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'A':
if( csi )
{
send_csi( 'B' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'B':
if( csi == 0 )
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'C':
if( csi )
{
send_csi( 'D' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'D':
if( csi )
{
send_csi( 'C' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
#endif
 
default:
*out_ptr = in_buffer[i];
out_ptr++;
break;
}
 
#ifdef ANSI_ESCAPE_CODE
prev_char = in_buffer[i];
#endif
}
 
return( out_ptr );
}
 
 
/*-----------------------------------------------------------*/
void sys_cli_task( void )
{
char last_return_value = EXIT_SUCCESS;
char in_buffer[INPUT_LINE_LENGTH + 1];
char out_buffer[INPUT_LINE_LENGTH + 1];
char *cli_ptr;
struct cli_cmd_tab_t cmd_to_check = { "", NULL, NULL };
unsigned char cli_argc;
char *cli_argv[MAX_CLI_ARGC];
struct cli_cmd_tab_t *cli_cmd;
unsigned int bytes_read;
 
cli_init();
 
PRINTF_MACRO( "\r\n" );
 
for( ;; )
{
PRINTF_MACRO( "%d > ", last_return_value );
 
cli_argc = 0;
last_return_value = EXIT_SUCCESS;
 
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) );
cli_ptr = cli_edit_buffer( in_buffer, out_buffer, bytes_read );
 
while( cli_ptr != NULL )
{
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) );
cli_ptr = cli_edit_buffer( in_buffer, NULL, bytes_read );
}
 
if( out_buffer[0] == '\0' )
{
PRINTF_MACRO( " NULL String! Command ignored\r\n" );
last_return_value = EXIT_FAILURE;
}
 
while( last_return_value != EXIT_FAILURE )
{
cli_ptr = strtok( out_buffer, " \t" );
 
strncpy( cmd_to_check.cmd, out_buffer, MAX_CMD_LENGTH );
cli_cmd = cli_find_command( &cmd_to_check );
 
if ( cli_cmd == NULL )
{
PRINTF_MACRO( "\r\n Command not found!\r\n" );
last_return_value = EXIT_FAILURE;
break;
}
 
if( cli_ptr == NULL )
{
cli_argv[cli_argc] = out_buffer;
cli_argc++;
} else
{
while( cli_ptr != NULL )
{
cli_argv[cli_argc] = cli_ptr;
cli_argc++;
 
cli_ptr = strtok( NULL, " \t" );
}
}
 
PRINTF_MACRO( "\r\n" );
 
last_return_value = cli_cmd->func( cli_argc, (const char **)cli_argv );
break;
}
 
}
}
 
/cli/sys_cmd.h
0,0 → 1,39
/*-----------------------------------------------------------*/
 
 
#ifndef _SYS_CMD_H_
#define _SYS_CMD_H_
 
#define INPUT_LINE_LENGTH 50
#define MAX_CMD_LENGTH 20
#define MAX_CLI_ARGC 6
 
// #include <xil_printf.h>
 
// #define ANSI_ESCAPE_CODE
 
#define PRINTF_MACRO xil_printf
// #define PRINTF_MACRO iprintf
 
typedef char (*cli_cmd_func)( const unsigned char argc, const char * argv[] );
 
typedef struct cli_cmd_tab_t
{
char cmd[MAX_CMD_LENGTH];
cli_cmd_func func;
const char *help_string;
} cli_cmd_tab_t;
 
extern struct cli_cmd_tab_t cli_commands[];
 
 
/*-----------------------------------------------------------*/
extern void sys_cli_task(void);
extern cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check );
extern void cli_init( void );
 
 
/*-----------------------------------------------------------*/
 
 
#endif // _SYS_CMD_H_
/cli/sys_error.c
0,0 → 1,9
/*-----------------------------------------------------------*/
 
void sys_error_fatal( unsigned int error )
{
// (*( (volatile unsigned int *) (0x8000003c) )) = error; // write to scratch pad reg in FPGA
while(1) {};
}
 
/cli/sys_error.h
0,0 → 1,17
/*-----------------------------------------------------------*/
 
#ifndef _SYS_ERROR_H_
#define _SYS_ERROR_H_
 
typedef enum
{
FATAL_ERROR_CLI = 0,
FATAL_ERROR_FD_SSP0_0,
} sys_error_fatal_type;
 
 
/*-----------------------------------------------------------*/
void sys_error_fatal( unsigned int error );
 
#endif // _SYS_ERROR_H_
 
/cli/sys_cmd_table.h
0,0 → 1,30
/*-----------------------------------------------------------*/
 
#include "sys_cmd.h"
 
extern char func_mw( const unsigned char argc, const char *argv[] );
extern char func_md( const unsigned char argc, const char *argv[] );
 
 
/*-----------------------------------------------------------*/
// command table
 
/*-----------------------------------------------------------*/
/* put in alphabetical order by command name */
struct cli_cmd_tab_t cli_commands[] =
{
{ "help", func_help, " help ~ print help message\r" },
{ "md", func_md, " md [.b, .w, .l] address [# of objects] ~ memory display\r" },
{ "md.b", func_md, " md.w [.b, .w, .l] address [# of objects] ~ memory display\r" },
{ "md.w", func_md, " md.w [.b, .w, .l] address [# of objects] ~ memory display\r" },
{ "memtest", func_memtest, " memtest base_address size\r" },
{ "mw", func_mw, " mw [.b, .w, .l] address value [count] ~ memory write (fill)\r" },
{ "mw.b", func_mw, " mw.w [.b, .w, .l] address value [count] ~ memory write (fill)\r" },
{ "mw.w", func_mw, " mw.w [.b, .w, .l] address value [count] ~ memory write (fill)\r" },
{ "peek", func_peek, " peek address\r" },
{ "poke", func_poke, " poke address value\r" },
{ "~", NULL, NULL }
};
 
 
 
/util/util_bits.c
0,0 → 1,58
/*-----------------------------------------------------------*/
 
#include "util_bits.h"
 
 
/*-----------------------------------------------------------*/
void inline
util_set_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask,
unsigned int data
)
{
volatile unsigned int *word_pointer = (volatile unsigned int *)(address);
unsigned int buffer;
data <<= bit_offset;
data &= bit_mask;
 
buffer = *word_pointer;
buffer &= ~bit_mask;
buffer |= data;
 
*word_pointer = buffer;
}
 
 
/*-----------------------------------------------------------*/
unsigned int inline
util_get_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask
)
{
volatile unsigned int *word_pointer = (volatile unsigned int *)(address);
unsigned int buffer;
 
buffer = *word_pointer;
buffer &= bit_mask;
buffer >>= bit_offset;
return(buffer);
}
 
 
/*-----------------------------------------------------------*/
unsigned char ReverseBits7ops32bit(unsigned char v)
{
return ((v * 0x0802LU & 0x22110LU) |
(v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
}
 
 
 
/util/uboot_lib.c
0,0 → 1,138
/*-----------------------------------------------------------*/
 
#include "uboot_lib.h"
 
 
/*-----------------------------------------------------------*/
int cmd_get_data_size(const char * arg, int default_size)
{
/* Check for a size specification .b, .w or .l.
*/
int len = strlen(arg);
if (len > 2 && arg[len-2] == '.') {
switch (arg[len-1]) {
case 'b':
return 1;
case 'w':
return 2;
case 'l':
return 4;
case 's':
return -2;
default:
return -1;
}
}
return default_size;
}
 
 
/*-----------------------------------------------------------*/
unsigned long simple_strtoul(const char *cp, char **endp,
unsigned int base)
{
unsigned long result = 0;
 
result = strtoul( cp, endp, base );
 
return result;
}
 
 
/*-----------------------------------------------------------*/
#define MAX_LINE_LENGTH_BYTES (64)
#define DEFAULT_LINE_LENGTH_BYTES (16)
int print_buffer(ulong addr, const void *data, uint width, uint count,
uint linelen)
{
/* linebuf as a union causes proper alignment */
union linebuf {
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1];
#endif
uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1];
uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
} lb;
int i;
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
uint64_t __maybe_unused x;
#else
uint32_t __maybe_unused x;
#endif
 
if (linelen*width > MAX_LINE_LENGTH_BYTES)
linelen = MAX_LINE_LENGTH_BYTES / width;
if (linelen < 1)
linelen = DEFAULT_LINE_LENGTH_BYTES / width;
 
while (count) {
uint thislinelen = linelen;
PRINTF_MACRO("%08lx:", addr);
 
/* check for overflow condition */
if (count < thislinelen)
thislinelen = count;
 
/* Copy from memory into linebuf and print hex values */
for (i = 0; i < thislinelen; i++) {
if (width == 4)
{
x = lb.ui[i] = *(volatile uint32_t *)data;
PRINTF_MACRO(" %08x", x);
}
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
else if (width == 8)
{
x = lb.uq[i] = *(volatile uint64_t *)data;
PRINTF_MACRO(" %016llx", (long long)x);
}
#endif
else if (width == 2)
{
x = lb.us[i] = *(volatile uint16_t *)data;
PRINTF_MACRO(" %04x", x);
}
else
{
x = lb.uc[i] = *(volatile uint8_t *)data;
PRINTF_MACRO(" %02x", x);
}
// #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
// PRINTF_MACRO(" %0*llx", width * 2, (long long)x);
// #else
// PRINTF_MACRO(" %0*x", width * 2, x);
// #endif
data += width;
}
 
while (thislinelen < linelen) {
/* fill line with whitespace for nice ASCII print */
for (i=0; i<width*2+1; i++)
puts(" ");
linelen--;
}
 
/* Print data in ASCII characters */
for (i = 0; i < thislinelen * width; i++) {
if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
lb.uc[i] = '.';
}
lb.uc[i] = '\0';
PRINTF_MACRO(" %s\r\n", lb.uc);
 
/* update references */
addr += thislinelen * width;
count -= thislinelen;
 
// if (ctrlc())
// return -1;
}
 
return 0;
}
 
 
 
 
 
/util/util_mem.h
0,0 → 1,24
/*-----------------------------------------------------------*/
 
#ifndef _UTIL_MEM_H_
#define _UTIL_MEM_H_
 
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include "sys_cmd.h"
#include "uboot_lib.h"
 
#undef CONFIG_HAS_DATAFLASH
#undef CONFIG_BLACKFIN
 
/*-----------------------------------------------------------*/
 
 
#endif // _UTIL_MEM_H_
 
 
 
 
/util/mapmem.h
0,0 → 1,32
/*
* Copyright (c) 2015 National Instruments
*
* (C) Copyright 2015
* Joe Hershberger <joe.hershberger@ni.com>
*
* SPDX-License-Identifier: GPL-2.0
*/
 
#ifndef __MAPMEM_H
#define __MAPMEM_H
 
/* Define a null map_sysmem() if the architecture doesn't use it */
# ifdef CONFIG_ARCH_MAP_SYSMEM
#include <asm/io.h>
# else
static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
{
return (void *)(uintptr_t)paddr;
}
 
static inline void unmap_sysmem(const void *vaddr)
{
}
 
static inline phys_addr_t map_to_sysmem(const void *ptr)
{
return (phys_addr_t)(uintptr_t)ptr;
}
# endif
 
#endif /* __MAPMEM_H */
/util/util_bits.h
0,0 → 1,39
/*-----------------------------------------------------------*/
 
#ifndef _UTIL_BITS_H_
#define _UTIL_BITS_H_
 
 
 
/*-----------------------------------------------------------*/
extern void inline
util_set_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask,
unsigned int data
);
 
/*-----------------------------------------------------------*/
extern unsigned int inline
util_get_bits
(
unsigned int address,
unsigned int bit_offset,
unsigned int bit_mask
);
/*-----------------------------------------------------------*/
extern unsigned char ReverseBits7ops32bit(unsigned char v);
 
 
 
 
#endif // _UTIL_BITS_H_
 
 
 
 
/util/uboot_lib.h
0,0 → 1,70
/*-----------------------------------------------------------*/
 
#ifndef _UBOOT_LIB_H_
#define _UBOOT_LIB_H_
 
#include <stdint.h>
#include <inttypes.h>
#include "types.h"
 
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
 
#undef CONFIG_ARCH_MAP_SYSMEM
#include "mapmem.h"
 
#include "sys_cmd.h"
 
 
/*
* Error codes that commands return to cmd_process(). We use the standard 0
* and 1 for success and failure, but add one more case - failure with a
* request to call cmd_usage(). But the cmd_process() function handles
* CMD_RET_USAGE itself and after calling cmd_usage() it will return 1.
* This is just a convenience for commands to avoid them having to call
* cmd_usage() all over the place.
*/
enum command_ret_t {
CMD_RET_SUCCESS, /* 0 = Success */
CMD_RET_FAILURE, /* 1 = Failure */
CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */
};
 
typedef int cmd_tbl_t;
 
/* sysv */
typedef unsigned char unchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
 
 
/*
* Command Flags:
*/
#define CMD_FLAG_REPEAT 0x0001 /* repeat last command */
#define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */
#define CMD_FLAG_ENV 0x0004 /* command is from the environment */
 
 
#define __maybe_unused __attribute__((unused))
 
 
/*-----------------------------------------------------------*/
#undef CONFIG_SYS_SUPPORT_64BIT_DATA
 
 
 
/*-----------------------------------------------------------*/
extern int cmd_get_data_size(const char * arg, int default_size);
extern unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base);
extern int print_buffer(ulong addr, const void *data, uint width, uint count, uint linelen);
 
 
#endif // _UBOOT_LIB_H_
 
 
 
 
/util/types.h
0,0 → 1,55
/*
* Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0+
*/
 
#ifndef __ASM_ARC_TYPES_H
#define __ASM_ARC_TYPES_H
 
// typedef unsigned short umode_t;
 
// /*
// * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
// * header files exported to user space
// */
 
// typedef __signed__ char __s8;
// typedef unsigned char __u8;
 
// typedef __signed__ short __s16;
// typedef unsigned short __u16;
 
// typedef __signed__ int __s32;
// typedef unsigned int __u32;
 
// #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
// typedef __signed__ long long __s64;
// typedef unsigned long long __u64;
// #endif
 
// /*
// * These aren't exported outside the kernel to avoid name space clashes
// */
typedef signed char s8;
typedef unsigned char u8;
 
typedef signed short s16;
typedef unsigned short u16;
 
typedef signed int s32;
typedef unsigned int u32;
 
typedef signed long long s64;
typedef unsigned long long u64;
 
// #define BITS_PER_LONG 32
 
// /* Dma addresses are 32-bits wide. */
 
// typedef u32 dma_addr_t;
 
typedef unsigned long phys_addr_t;
typedef unsigned long phys_size_t;
 
#endif /* __ASM_ARC_TYPES_H */
/util/util_mem.c
0,0 → 1,203
/*-----------------------------------------------------------*/
 
#include "util_mem.h"
 
 
/*-----------------------------------------------------------*/
 
/* Display values from last command.
* Memory modify remembered values are different from display memory.
*/
static ulong dp_last_addr, dp_last_size;
static ulong dp_last_length = 0x40;
// static ulong mm_last_addr, mm_last_size;
 
static ulong base_address = 0;
 
/* Memory Display
*
* Syntax:
* md{.b, .w, .l, .q} {addr} {len}
*/
#define DISP_LINE_LEN 16
static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
{
ulong addr, length;
#if defined(CONFIG_HAS_DATAFLASH)
ulong nbytes, linebytes;
#endif
int size;
int rc = 0;
 
/* We use the last specified parameters, unless new ones are
* entered.
*/
addr = dp_last_addr;
size = dp_last_size;
length = dp_last_length;
 
if (argc < 2)
return CMD_RET_USAGE;
 
if ((flag & CMD_FLAG_REPEAT) == 0) {
/* New command specified. Check for a size specification.
* Defaults to long if no or incorrect specification.
*/
if ((size = cmd_get_data_size(argv[0], 4)) < 0)
return 1;
 
/* Address is specified since argc > 1
*/
addr = simple_strtoul(argv[1], NULL, 16);
addr += base_address;
 
/* If another parameter, it is the length to display.
* Length is the number of objects, not number of bytes.
*/
if (argc > 2)
length = simple_strtoul(argv[2], NULL, 16);
}
 
#if defined(CONFIG_HAS_DATAFLASH)
/* Print the lines.
*
* We buffer all read data, so we can make sure data is read only
* once, and all accesses are with the specified bus width.
*/
nbytes = length * size;
do {
char linebuf[DISP_LINE_LEN];
void* p;
linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
 
rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
 
nbytes -= linebytes;
addr += linebytes;
if (ctrlc()) {
rc = 1;
break;
}
} while (nbytes > 0);
#else
 
# if defined(CONFIG_BLACKFIN)
/* See if we're trying to display L1 inst */
if (addr_bfin_on_chip_mem(addr)) {
char linebuf[DISP_LINE_LEN];
ulong linebytes, nbytes = length * size;
do {
linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
memcpy(linebuf, (void *)addr, linebytes);
print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
 
nbytes -= linebytes;
addr += linebytes;
if (ctrlc()) {
rc = 1;
break;
}
} while (nbytes > 0);
} else
# endif
 
{
ulong bytes = size * length;
const void *buf = map_sysmem(addr, bytes);
 
/* Print the lines. */
print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
addr += bytes;
unmap_sysmem(buf);
}
#endif
 
dp_last_addr = addr;
dp_last_length = length;
dp_last_size = size;
return (rc);
}
 
 
/*-----------------------------------------------------------*/
static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
{
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
u64 writeval;
#else
ulong writeval;
#endif
ulong addr, count;
int size;
void *buf, *start;
ulong bytes;
 
if ((argc < 3) || (argc > 4))
return CMD_RET_USAGE;
 
/* Check for size specification.
*/
if ((size = cmd_get_data_size(argv[0], 4)) < 1)
return 1;
 
/* Address is specified since argc > 1
*/
addr = simple_strtoul(argv[1], NULL, 16);
addr += base_address;
 
/* Get the value to write.
*/
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
writeval = simple_strtoull(argv[2], NULL, 16);
#else
writeval = simple_strtoul(argv[2], NULL, 16);
#endif
 
/* Count ? */
if (argc == 4) {
count = simple_strtoul(argv[3], NULL, 16);
} else {
count = 1;
}
 
bytes = size * count;
start = map_sysmem(addr, bytes);
buf = start;
while (count-- > 0) {
if (size == 4)
*((u32 *)buf) = (u32)writeval;
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
else if (size == 8)
*((u64 *)buf) = (u64)writeval;
#endif
else if (size == 2)
*((u16 *)buf) = (u16)writeval;
else
*((u8 *)buf) = (u8)writeval;
buf += size;
}
unmap_sysmem(start);
return 0;
}
 
 
/*-----------------------------------------------------------*/
char func_mw( const unsigned char argc, const char *argv[] )
{
return do_mem_mw(0, 0, argc, argv);
}
 
 
/*-----------------------------------------------------------*/
char func_md( const unsigned char argc, const char *argv[] )
{
return do_mem_md(0, 0, argc, argv);
}
 
 
 
 
 
 

powered by: WebSVN 2.1.0

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