2011-03-18 20:46:25 +01:00
|
|
|
/****************************************************************************
|
2021-06-10 17:10:34 +02:00
|
|
|
* apps/nshlib/nsh_dbgcmds.c
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2019-02-11 20:10:10 +01:00
|
|
|
#include <fcntl.h>
|
2012-11-09 15:54:29 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
#include "nsh.h"
|
2012-02-02 17:04:09 +01:00
|
|
|
#include "nsh_console.h"
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-02 22:06:11 +02:00
|
|
|
* Pre-processor Definitions
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-27 14:29:46 +01:00
|
|
|
#undef NSH_HAVE_MEMCMDS
|
|
|
|
#if !defined(CONFIG_NSH_DISABLE_MB) || !defined(CONFIG_NSH_DISABLE_MH) || \
|
|
|
|
!defined(CONFIG_NSH_DISABLE_MW)
|
|
|
|
# define NSH_HAVE_MEMCMDS 1
|
2017-02-27 14:49:49 +01:00
|
|
|
#endif
|
2017-02-27 14:29:46 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-27 14:29:46 +01:00
|
|
|
#ifdef NSH_HAVE_MEMCMDS
|
2011-03-18 20:46:25 +01:00
|
|
|
struct dbgmem_s
|
|
|
|
{
|
2020-02-23 05:51:44 +01:00
|
|
|
bool dm_write; /* true: perform write operation */
|
2017-02-27 14:54:21 +01:00
|
|
|
FAR void *dm_addr; /* Address to access */
|
2011-03-18 20:46:25 +01:00
|
|
|
uint32_t dm_value; /* Value to write */
|
|
|
|
unsigned int dm_count; /* The number of bytes to access */
|
|
|
|
};
|
2017-02-27 14:29:46 +01:00
|
|
|
#endif
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mem_parse
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-27 14:29:46 +01:00
|
|
|
#ifdef NSH_HAVE_MEMCMDS
|
2017-02-27 14:54:21 +01:00
|
|
|
static int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv,
|
|
|
|
FAR struct dbgmem_s *mem)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(vtbl);
|
|
|
|
|
2017-02-27 14:54:21 +01:00
|
|
|
FAR char *pcvalue = strchr(argv[1], '=');
|
2011-03-18 20:46:25 +01:00
|
|
|
unsigned long lvalue = 0;
|
|
|
|
|
|
|
|
/* Check if we are writing a value */
|
|
|
|
|
|
|
|
if (pcvalue)
|
|
|
|
{
|
|
|
|
*pcvalue = '\0';
|
|
|
|
pcvalue++;
|
|
|
|
|
2017-04-27 01:54:56 +02:00
|
|
|
lvalue = strtoul(pcvalue, NULL, 16);
|
2020-03-17 06:18:11 +01:00
|
|
|
if (lvalue > 0xffffffffl)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mem->dm_write = true;
|
|
|
|
mem->dm_value = (uint32_t)lvalue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mem->dm_write = false;
|
|
|
|
mem->dm_value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the address to be accessed */
|
|
|
|
|
2017-04-27 01:54:56 +02:00
|
|
|
mem->dm_addr = (FAR void *)((uintptr_t)strtoul(argv[1], NULL, 16));
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
/* Get the number of bytes to access */
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
{
|
2017-04-27 01:54:56 +02:00
|
|
|
mem->dm_count = (unsigned int)strtoul(argv[2], NULL, 16);
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mem->dm_count = 1;
|
|
|
|
}
|
2012-12-09 18:34:53 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
return OK;
|
|
|
|
}
|
2017-02-27 14:29:46 +01:00
|
|
|
#endif
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mb
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-18 21:35:31 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_MB
|
2017-02-27 14:54:21 +01:00
|
|
|
int cmd_mb(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
struct dbgmem_s mem;
|
2017-02-27 14:54:21 +01:00
|
|
|
FAR volatile uint8_t *ptr;
|
2014-01-14 20:30:22 +01:00
|
|
|
unsigned int i;
|
2011-03-18 20:46:25 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mem_parse(vtbl, argc, argv, &mem);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Loop for the number of requested bytes */
|
|
|
|
|
2020-03-17 06:18:11 +01:00
|
|
|
for (i = 0, ptr = (volatile uint8_t *)mem.dm_addr; i < mem.dm_count;
|
|
|
|
i++, ptr++)
|
2012-02-02 17:04:09 +01:00
|
|
|
{
|
|
|
|
/* Print the value at the address */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
nsh_output(vtbl, " %p = 0x%02x", ptr, *ptr);
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Are we supposed to write a value to this address? */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
if (mem.dm_write)
|
|
|
|
{
|
|
|
|
/* Yes, was the supplied value within range? */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
if (mem.dm_value > 0x000000ff)
|
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtargrange, argv[0]);
|
2012-02-02 17:04:09 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Write the value and re-read the address so that we print its
|
|
|
|
* current value (if the address is a process address, then the
|
|
|
|
* value read might not necessarily be the value written).
|
|
|
|
*/
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
*ptr = (uint8_t)mem.dm_value;
|
|
|
|
nsh_output(vtbl, " -> 0x%02x", *ptr);
|
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Make sure we end it with a newline */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-07-17 08:05:23 +02:00
|
|
|
nsh_output(vtbl, "\n");
|
2012-02-02 17:04:09 +01:00
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
2014-01-13 15:21:18 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mh
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-18 21:35:31 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_MH
|
2017-02-27 14:54:21 +01:00
|
|
|
int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
struct dbgmem_s mem;
|
2017-02-27 14:54:21 +01:00
|
|
|
FAR volatile uint16_t *ptr;
|
2014-01-14 20:30:22 +01:00
|
|
|
unsigned int i;
|
2011-03-18 20:46:25 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mem_parse(vtbl, argc, argv, &mem);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Loop for the number of requested bytes */
|
|
|
|
|
2020-03-17 06:18:11 +01:00
|
|
|
for (i = 0, ptr = (volatile uint16_t *)mem.dm_addr;
|
2014-01-14 20:30:22 +01:00
|
|
|
i < mem.dm_count;
|
|
|
|
i += 2, ptr++)
|
2012-02-02 17:04:09 +01:00
|
|
|
{
|
|
|
|
/* Print the value at the address */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
nsh_output(vtbl, " %p = 0x%04x", ptr, *ptr);
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Are we supposed to write a value to this address? */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
if (mem.dm_write)
|
|
|
|
{
|
|
|
|
/* Yes, was the supplied value within range? */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
if (mem.dm_value > 0x0000ffff)
|
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtargrange, argv[0]);
|
2012-02-02 17:04:09 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Write the value and re-read the address so that we print its
|
|
|
|
* current value (if the address is a process address, then the
|
|
|
|
* value read might not necessarily be the value written).
|
|
|
|
*/
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
*ptr = (uint16_t)mem.dm_value;
|
|
|
|
nsh_output(vtbl, " -> 0x%04x", *ptr);
|
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Make sure we end it with a newline */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-07-17 08:05:23 +02:00
|
|
|
nsh_output(vtbl, "\n");
|
2012-02-02 17:04:09 +01:00
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
2014-01-13 15:21:18 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mw
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-18 21:35:31 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_MW
|
2017-02-27 14:54:21 +01:00
|
|
|
int cmd_mw(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
struct dbgmem_s mem;
|
2017-02-27 14:54:21 +01:00
|
|
|
FAR volatile uint32_t *ptr;
|
2014-01-14 20:30:22 +01:00
|
|
|
unsigned int i;
|
2011-03-18 20:46:25 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mem_parse(vtbl, argc, argv, &mem);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Loop for the number of requested bytes */
|
|
|
|
|
2020-03-17 06:18:11 +01:00
|
|
|
for (i = 0, ptr = (volatile uint32_t *)mem.dm_addr; i < mem.dm_count;
|
|
|
|
i += 4, ptr++)
|
2012-02-02 17:04:09 +01:00
|
|
|
{
|
|
|
|
/* Print the value at the address */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-07-17 08:05:23 +02:00
|
|
|
nsh_output(vtbl, " %p = 0x%08" PRIx32, ptr, *ptr);
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Are we supposed to write a value to this address? */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
if (mem.dm_write)
|
|
|
|
{
|
|
|
|
/* Write the value and re-read the address so that we print its
|
|
|
|
* current value (if the address is a process address, then the
|
|
|
|
* value read might not necessarily be the value written).
|
|
|
|
*/
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
*ptr = mem.dm_value;
|
2022-07-17 08:05:23 +02:00
|
|
|
nsh_output(vtbl, " -> 0x%08" PRIx32, *ptr);
|
2012-02-02 17:04:09 +01:00
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2012-02-02 17:04:09 +01:00
|
|
|
/* Make sure we end it with a newline */
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2022-07-17 08:05:23 +02:00
|
|
|
nsh_output(vtbl, "\n");
|
2012-02-02 17:04:09 +01:00
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
2014-01-13 15:21:18 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_dumpbuffer
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-27 14:54:21 +01:00
|
|
|
void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, FAR const char *msg,
|
|
|
|
FAR const uint8_t *buffer, ssize_t nbytes)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
char line[128];
|
|
|
|
int ch;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
nsh_output(vtbl, "%s:\n", msg);
|
|
|
|
for (i = 0; i < nbytes; i += 16)
|
|
|
|
{
|
|
|
|
sprintf(line, "%04x: ", i);
|
|
|
|
|
2020-03-17 06:18:11 +01:00
|
|
|
for (j = 0; j < 16; j++)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
if (i + j < nbytes)
|
|
|
|
{
|
2020-03-17 06:18:11 +01:00
|
|
|
sprintf(&line[strlen(line)], "%02x ", buffer[i + j]);
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(&line[strlen(line)], " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 06:18:11 +01:00
|
|
|
for (j = 0; j < 16; j++)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
if (i + j < nbytes)
|
|
|
|
{
|
2020-03-17 06:18:11 +01:00
|
|
|
ch = buffer[i + j];
|
|
|
|
sprintf(&line[strlen(line)], "%c",
|
|
|
|
ch >= 0x20 && ch <= 0x7e ? ch : '.');
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-13 15:21:18 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
nsh_output(vtbl, "%s\n", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-11-09 15:54:29 +01:00
|
|
|
* Name: cmd_xd, hex dump of memory
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-18 21:35:31 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_XD
|
2017-02-27 14:54:21 +01:00
|
|
|
int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(argc);
|
|
|
|
|
2011-06-17 20:20:14 +02:00
|
|
|
FAR char *addr;
|
|
|
|
FAR char *endptr;
|
|
|
|
int nbytes;
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2020-03-17 06:18:11 +01:00
|
|
|
addr = (FAR char *)((uintptr_t)strtoul(argv[1], &endptr, 16));
|
2011-03-18 20:46:25 +01:00
|
|
|
if (argv[0][0] == '\0' || *endptr != '\0')
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbytes = (int)strtol(argv[2], &endptr, 0);
|
|
|
|
if (argv[0][0] == '\0' || *endptr != '\0' || nbytes < 0)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2020-03-17 06:18:11 +01:00
|
|
|
nsh_dumpbuffer(vtbl, "Hex dump", (uint8_t *)addr, nbytes);
|
2011-03-18 20:46:25 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-09 15:54:29 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_hexdump, hex dump of files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HEXDUMP
|
2017-02-27 14:54:21 +01:00
|
|
|
int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2012-11-09 15:54:29 +01:00
|
|
|
{
|
2014-04-22 02:12:59 +02:00
|
|
|
FAR uint8_t *buffer;
|
2012-11-12 16:22:27 +01:00
|
|
|
char msg[32];
|
2013-11-01 14:15:14 +01:00
|
|
|
off_t position;
|
2012-11-09 15:54:29 +01:00
|
|
|
int fd;
|
|
|
|
int ret = OK;
|
2013-11-01 14:15:14 +01:00
|
|
|
#ifdef CONFIG_NSH_CMDOPT_HEXDUMP
|
|
|
|
off_t skip = 0;
|
|
|
|
off_t count = 0xfffffff;
|
|
|
|
off_t dumpbytes;
|
|
|
|
int x;
|
|
|
|
#endif
|
|
|
|
|
2012-11-09 15:54:29 +01:00
|
|
|
/* Open the file for reading */
|
|
|
|
|
|
|
|
fd = open(argv[1], O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO);
|
2012-11-09 15:54:29 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
2013-11-01 14:15:14 +01:00
|
|
|
|
2014-04-22 02:12:59 +02:00
|
|
|
buffer = (FAR uint8_t *)malloc(IOBUFFERSIZE);
|
2020-03-17 06:18:11 +01:00
|
|
|
if (buffer == NULL)
|
2014-04-22 02:12:59 +02:00
|
|
|
{
|
2020-01-02 13:09:50 +01:00
|
|
|
close(fd);
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "malloc", NSH_ERRNO);
|
2014-04-22 02:12:59 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2013-11-01 14:15:14 +01:00
|
|
|
#ifdef CONFIG_NSH_CMDOPT_HEXDUMP
|
|
|
|
for (x = 2; x < argc; x++)
|
|
|
|
{
|
|
|
|
if (strncmp(argv[x], "skip=", 5) == 0)
|
|
|
|
{
|
|
|
|
skip = atoi(&argv[x][5]);
|
|
|
|
}
|
|
|
|
else if (strncmp(argv[x], "count=", 6) == 0)
|
|
|
|
{
|
|
|
|
count = atoi(&argv[x][6]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-12 16:22:27 +01:00
|
|
|
position = 0;
|
2020-03-17 06:18:11 +01:00
|
|
|
for (; ; )
|
2013-11-01 14:15:14 +01:00
|
|
|
{
|
|
|
|
int nbytesread = read(fd, buffer, IOBUFFERSIZE);
|
|
|
|
|
|
|
|
/* Check for read errors */
|
|
|
|
|
|
|
|
if (nbytesread < 0)
|
|
|
|
{
|
|
|
|
int errval = errno;
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, "hexdump", "read",
|
2013-11-01 14:15:14 +01:00
|
|
|
NSH_ERRNO_OF(errval));
|
|
|
|
ret = ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (nbytesread > 0)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_NSH_CMDOPT_HEXDUMP
|
|
|
|
if (position < skip)
|
|
|
|
{
|
|
|
|
/* Skip bytes until we reach the skip point */
|
|
|
|
|
|
|
|
position += nbytesread;
|
|
|
|
if (position > skip)
|
|
|
|
{
|
|
|
|
dumpbytes = position - skip;
|
|
|
|
if (dumpbytes > count)
|
|
|
|
{
|
|
|
|
dumpbytes = count;
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:09:11 +01:00
|
|
|
snprintf(msg, sizeof(msg), "%s at %08jx", argv[1],
|
|
|
|
(uintmax_t)skip);
|
2013-11-01 14:15:14 +01:00
|
|
|
nsh_dumpbuffer(vtbl, msg,
|
2020-03-17 06:18:11 +01:00
|
|
|
&buffer[nbytesread - (position - skip)],
|
2013-11-01 14:15:14 +01:00
|
|
|
dumpbytes);
|
|
|
|
|
|
|
|
if (count > dumpbytes)
|
|
|
|
{
|
|
|
|
count -= dumpbytes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't print if we are in skip mode */
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Limit dumpbuffer to count if less than a full buffer needed */
|
|
|
|
|
|
|
|
if (nbytesread > count)
|
|
|
|
{
|
|
|
|
nbytesread = count;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-11-05 13:09:11 +01:00
|
|
|
snprintf(msg, sizeof(msg), "%s at %08jx", argv[1],
|
|
|
|
(uintmax_t)position);
|
2013-11-01 14:15:14 +01:00
|
|
|
nsh_dumpbuffer(vtbl, msg, buffer, nbytesread);
|
|
|
|
position += nbytesread;
|
|
|
|
|
|
|
|
#ifdef CONFIG_NSH_CMDOPT_HEXDUMP
|
|
|
|
if (count > nbytesread)
|
|
|
|
{
|
|
|
|
count -= nbytesread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-27 15:02:43 +01:00
|
|
|
break; /* EOF */
|
2013-11-01 14:15:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
close(fd);
|
2014-04-22 02:12:59 +02:00
|
|
|
free(buffer);
|
2012-11-09 15:54:29 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-13 00:58:44 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_irqinfo
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_IRQINFO
|
|
|
|
int cmd_irqinfo(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(argc);
|
|
|
|
|
2018-01-13 00:58:44 +01:00
|
|
|
return nsh_catfile(vtbl, argv[0], CONFIG_NSH_PROC_MOUNTPOINT "/irqs");
|
|
|
|
}
|
|
|
|
#endif
|