summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Makefile3
-rw-r--r--common/cmd_bootm.c10
-rw-r--r--common/cmd_cramfs.c216
-rw-r--r--common/cmd_eeprom.c14
-rw-r--r--common/dlmalloc.c6
-rw-r--r--common/env_eeprom.c195
-rw-r--r--common/kgdb.c43
-rw-r--r--common/kgdb_stubs.c64
8 files changed, 517 insertions, 34 deletions
diff --git a/common/Makefile b/common/Makefile
index 7784180..dbf7a05 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -105,6 +105,7 @@ COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o
COBJS-$(CONFIG_CMD_IRQ) += cmd_irq.o
COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o
COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o
+COBJS-$(CONFIG_CMD_CRAMFS) += cmd_cramfs.o
COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o
COBJS-y += cmd_load.o
COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o
@@ -157,7 +158,7 @@ COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
COBJS-$(CONFIG_HWCONFIG) += hwconfig.o
COBJS-$(CONFIG_CONSOLE_MUX) += iomux.o
COBJS-y += flash.o
-COBJS-$(CONFIG_CMD_KGDB) += kgdb.o
+COBJS-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o
COBJS-$(CONFIG_KALLSYMS) += kallsyms.o
COBJS-$(CONFIG_LCD) += lcd.o
COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 94ddac3..05feb39 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -105,10 +105,6 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
typedef int boot_os_fn (int flag, int argc, char *argv[],
bootm_headers_t *images); /* pointers to os/initrd/fdt */
-#define CONFIG_BOOTM_LINUX 1
-#define CONFIG_BOOTM_NETBSD 1
-#define CONFIG_BOOTM_RTEMS 1
-
#ifdef CONFIG_BOOTM_LINUX
extern boot_os_fn do_bootm_linux;
#endif
@@ -297,7 +293,8 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1;
}
- if (images.os.os == IH_OS_LINUX) {
+ if ((images.os.type == IH_TYPE_KERNEL) &&
+ (images.os.os == IH_OS_LINUX)) {
/* find ramdisk */
ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
&images.rd_start, &images.rd_end);
@@ -888,9 +885,6 @@ static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]
image_multi_getimg (hdr, 0, os_data, os_len);
break;
case IH_TYPE_STANDALONE:
- if (argc >2) {
- hdr->ih_load = htonl(simple_strtoul(argv[2], NULL, 16));
- }
*os_data = image_get_data (hdr);
*os_len = image_get_data_size (hdr);
break;
diff --git a/common/cmd_cramfs.c b/common/cmd_cramfs.c
new file mode 100644
index 0000000..55e2d36
--- /dev/null
+++ b/common/cmd_cramfs.c
@@ -0,0 +1,216 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * based on: cmd_jffs2.c
+ *
+ * Add support for a CRAMFS located in RAM
+ */
+
+
+/*
+ * CRAMFS support
+ */
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+#include <jffs2/jffs2.h>
+#include <jffs2/load_kernel.h>
+#include <cramfs/cramfs_fs.h>
+
+/* enable/disable debugging messages */
+#define DEBUG_CRAMFS
+#undef DEBUG_CRAMFS
+
+#ifdef DEBUG_CRAMFS
+# define DEBUGF(fmt, args...) printf(fmt ,##args)
+#else
+# define DEBUGF(fmt, args...)
+#endif
+
+#ifdef CONFIG_CRAMFS_CMDLINE
+flash_info_t flash_info[1];
+
+#ifndef CONFIG_CMD_JFFS2
+#include <linux/stat.h>
+char *mkmodestr(unsigned long mode, char *str)
+{
+ static const char *l = "xwr";
+ int mask = 1, i;
+ char c;
+
+ switch (mode & S_IFMT) {
+ case S_IFDIR: str[0] = 'd'; break;
+ case S_IFBLK: str[0] = 'b'; break;
+ case S_IFCHR: str[0] = 'c'; break;
+ case S_IFIFO: str[0] = 'f'; break;
+ case S_IFLNK: str[0] = 'l'; break;
+ case S_IFSOCK: str[0] = 's'; break;
+ case S_IFREG: str[0] = '-'; break;
+ default: str[0] = '?';
+ }
+
+ for(i = 0; i < 9; i++) {
+ c = l[i%3];
+ str[9-i] = (mode & mask)?c:'-';
+ mask = mask<<1;
+ }
+
+ if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
+ if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
+ if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
+ str[10] = '\0';
+ return str;
+}
+#endif /* CONFIG_CMD_JFFS2 */
+
+extern int cramfs_check (struct part_info *info);
+extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
+extern int cramfs_ls (struct part_info *info, char *filename);
+extern int cramfs_info (struct part_info *info);
+
+/***************************************************/
+/* U-boot commands */
+/***************************************************/
+
+/**
+ * Routine implementing fsload u-boot command. This routine tries to load
+ * a requested file from cramfs filesystem at location 'cramfsaddr'.
+ * cramfsaddr is an evironment variable.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ char *filename;
+ int size;
+ ulong offset = load_addr;
+
+ struct part_info part;
+ struct mtd_device dev;
+ struct mtdids id;
+
+ ulong addr;
+ addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
+
+ /* hack! */
+ /* cramfs_* only supports NOR flash chips */
+ /* fake the device type */
+ id.type = MTD_DEV_TYPE_NOR;
+ id.num = 0;
+ dev.id = &id;
+ part.dev = &dev;
+ /* fake the address offset */
+ part.offset = addr - flash_info[id.num].start[0];
+
+ /* pre-set Boot file name */
+ if ((filename = getenv("bootfile")) == NULL) {
+ filename = "uImage";
+ }
+
+ if (argc == 2) {
+ filename = argv[1];
+ }
+ if (argc == 3) {
+ offset = simple_strtoul(argv[1], NULL, 0);
+ load_addr = offset;
+ filename = argv[2];
+ }
+
+ size = 0;
+ if (cramfs_check(&part))
+ size = cramfs_load ((char *) offset, &part, filename);
+
+ if (size > 0) {
+ char buf[10];
+ printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
+ size, offset);
+ sprintf(buf, "%x", size);
+ setenv("filesize", buf);
+ } else {
+ printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
+ }
+
+ return !(size > 0);
+}
+
+/**
+ * Routine implementing u-boot ls command which lists content of a given
+ * directory at location 'cramfsaddr'.
+ * cramfsaddr is an evironment variable.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ char *filename = "/";
+ int ret;
+ struct part_info part;
+ struct mtd_device dev;
+ struct mtdids id;
+
+ ulong addr;
+ addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
+
+ /* hack! */
+ /* cramfs_* only supports NOR flash chips */
+ /* fake the device type */
+ id.type = MTD_DEV_TYPE_NOR;
+ id.num = 0;
+ dev.id = &id;
+ part.dev = &dev;
+ /* fake the address offset */
+ part.offset = addr - flash_info[id.num].start[0];
+
+ if (argc == 2)
+ filename = argv[1];
+
+ ret = 0;
+ if (cramfs_check(&part))
+ ret = cramfs_ls (&part, filename);
+
+ return ret ? 0 : 1;
+}
+
+/* command line only */
+
+/***************************************************/
+U_BOOT_CMD(
+ cramfsload, 3, 0, do_cramfs_load,
+ "cramfsload\t- load binary file from a filesystem image",
+ "[ off ] [ filename ]\n"
+ " - load binary file from address 'cramfsaddr'\n"
+ " with offset 'off'\n"
+);
+U_BOOT_CMD(
+ cramfsls, 2, 1, do_cramfs_ls,
+ "cramfsls\t- list files in a directory (default /)",
+ "[ directory ]\n"
+ " - list files in a directory.\n"
+);
+
+#endif /* #ifdef CONFIG_CRAMFS_CMDLINE */
+
+/***************************************************/
diff --git a/common/cmd_eeprom.c b/common/cmd_eeprom.c
index 102efaf..519b510 100644
--- a/common/cmd_eeprom.c
+++ b/common/cmd_eeprom.c
@@ -79,7 +79,7 @@ int do_eeprom ( cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
ulong cnt = simple_strtoul (argv[4], NULL, 16);
#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
-# ifndef CONFIG_SPI
+# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
eeprom_init ();
# endif /* !CONFIG_SPI */
@@ -118,7 +118,7 @@ int do_eeprom ( cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
* 0x00000nxx for EEPROM address selectors and page number at n.
*/
-#ifndef CONFIG_SPI
+#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1 || CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2
#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
#endif
@@ -176,7 +176,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
len = maxlen;
#endif
-#ifdef CONFIG_SPI
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
spi_read (addr, alen, buffer, len);
#else
if (i2c_read (addr[0], offset, alen-1, buffer, len) != 0)
@@ -272,7 +272,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
len = maxlen;
#endif
-#ifdef CONFIG_SPI
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
spi_write (addr, alen, buffer, len);
#else
#if defined(CONFIG_SYS_EEPROM_X40430)
@@ -374,7 +374,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
return rcode;
}
-#ifndef CONFIG_SPI
+#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
int
eeprom_probe (unsigned dev_addr, unsigned offset)
{
@@ -403,7 +403,8 @@ eeprom_probe (unsigned dev_addr, unsigned offset)
void eeprom_init (void)
{
-#if defined(CONFIG_SPI)
+
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
spi_init_f ();
#endif
#if defined(CONFIG_HARD_I2C) || \
@@ -411,6 +412,7 @@ void eeprom_init (void)
i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
#endif
}
+
/*-----------------------------------------------------------------------
*/
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 735b344..205fc40 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -2179,6 +2179,12 @@ Void_t* mALLOc(bytes) size_t bytes;
INTERNAL_SIZE_T nb;
+ /* check if mem_malloc_init() was run */
+ if ((mem_malloc_start == 0) && (mem_malloc_end == 0)) {
+ /* not initialized yet */
+ return 0;
+ }
+
if ((long)bytes < 0) return 0;
nb = request2size(bytes); /* padded request size; */
diff --git a/common/env_eeprom.c b/common/env_eeprom.c
index 1578d61..95a7d0d 100644
--- a/common/env_eeprom.c
+++ b/common/env_eeprom.c
@@ -28,19 +28,85 @@
#include <command.h>
#include <environment.h>
#include <linux/stddef.h>
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+#include <i2c.h>
+#endif
+
+#ifdef CONFIG_ENV_OFFSET_REDUND
+#define ACTIVE_FLAG 1
+#define OBSOLETE_FLAG 0
+#endif
DECLARE_GLOBAL_DATA_PTR;
env_t *env_ptr = NULL;
char * env_name_spec = "EEPROM";
+int env_eeprom_bus = -1;
+
+static int eeprom_bus_read (unsigned dev_addr, unsigned offset, uchar *buffer,
+ unsigned cnt)
+{
+ int rcode;
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ int old_bus = i2c_get_bus_num();
+
+ if (gd->flags & GD_FLG_RELOC) {
+ if (env_eeprom_bus == -1) {
+ I2C_MUX_DEVICE *dev = NULL;
+ dev = i2c_mux_ident_muxstring(
+ (uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
+ if (dev != NULL) {
+ env_eeprom_bus = dev->busid;
+ } else
+ printf ("error adding env eeprom bus.\n");
+ }
+ if (old_bus != env_eeprom_bus) {
+ i2c_set_bus_num(env_eeprom_bus);
+ old_bus = env_eeprom_bus;
+ }
+ } else {
+ rcode = i2c_mux_ident_muxstring_f(
+ (uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
+ }
+#endif
+
+ rcode = eeprom_read (dev_addr, offset, buffer, cnt);
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ if (old_bus != env_eeprom_bus)
+ i2c_set_bus_num(old_bus);
+#endif
+ return rcode;
+}
+
+static int eeprom_bus_write (unsigned dev_addr, unsigned offset, uchar *buffer,
+ unsigned cnt)
+{
+ int rcode;
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ int old_bus = i2c_get_bus_num();
+
+ rcode = i2c_mux_ident_muxstring_f((uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
+#endif
+ rcode = eeprom_write (dev_addr, offset, buffer, cnt);
+#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
+ i2c_set_bus_num(old_bus);
+#endif
+ return rcode;
+}
uchar env_get_char_spec (int index)
{
uchar c;
+ unsigned int off;
+ off = CONFIG_ENV_OFFSET;
+#ifdef CONFIG_ENV_OFFSET_REDUND
+ if (gd->env_valid == 2)
+ off = CONFIG_ENV_OFFSET_REDUND;
+#endif
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
- CONFIG_ENV_OFFSET+index+offsetof(env_t,data),
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ off + index + offsetof(env_t,data),
&c, 1);
return (c);
@@ -48,18 +114,52 @@ uchar env_get_char_spec (int index)
void env_relocate_spec (void)
{
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
- CONFIG_ENV_OFFSET,
+ unsigned int off = CONFIG_ENV_OFFSET;
+#ifdef CONFIG_ENV_OFFSET_REDUND
+ if (gd->env_valid == 2)
+ off = CONFIG_ENV_OFFSET_REDUND;
+#endif
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ off,
(uchar*)env_ptr,
CONFIG_ENV_SIZE);
}
int saveenv(void)
{
- return eeprom_write (CONFIG_SYS_DEF_EEPROM_ADDR,
- CONFIG_ENV_OFFSET,
+ int rc;
+ unsigned int off = CONFIG_ENV_OFFSET;
+#ifdef CONFIG_ENV_OFFSET_REDUND
+ unsigned int off_red = CONFIG_ENV_OFFSET_REDUND;
+ char flag_obsolete = OBSOLETE_FLAG;
+ if (gd->env_valid == 1) {
+ off = CONFIG_ENV_OFFSET_REDUND;
+ off_red = CONFIG_ENV_OFFSET;
+ }
+
+ env_ptr->flags = ACTIVE_FLAG;
+#endif
+
+ rc = eeprom_bus_write (CONFIG_SYS_DEF_EEPROM_ADDR,
+ off,
(uchar *)env_ptr,
CONFIG_ENV_SIZE);
+
+#ifdef CONFIG_ENV_OFFSET_REDUND
+ if (rc == 0) {
+ eeprom_bus_write (CONFIG_SYS_DEF_EEPROM_ADDR,
+ off_red + offsetof(env_t,flags),
+ (uchar *)&flag_obsolete,
+ 1);
+ if (gd->env_valid == 1)
+ gd->env_valid = 2;
+ else
+ gd->env_valid = 1;
+
+ }
+#endif
+
+ return rc;
}
/************************************************************************
@@ -68,6 +168,82 @@ int saveenv(void)
* We are still running from ROM, so data use is limited
* Use a (moderately small) buffer on the stack
*/
+
+#ifdef CONFIG_ENV_OFFSET_REDUND
+int env_init(void)
+{
+ ulong len;
+ ulong crc[2], crc_tmp;
+ unsigned int off, off_env[2];
+ uchar buf[64];
+ int crc_ok[2] = {0,0};
+ unsigned char flags[2];
+ int i;
+
+ eeprom_init (); /* prepare for EEPROM read/write */
+
+ off_env[0] = CONFIG_ENV_OFFSET;
+ off_env[1] = CONFIG_ENV_OFFSET_REDUND;
+
+ for (i = 0; i < 2; i++) {
+ /* read CRC */
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ off_env[i] + offsetof(env_t,crc),
+ (uchar *)&crc[i], sizeof(ulong));
+ /* read FLAGS */
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ off_env[i] + offsetof(env_t,flags),
+ (uchar *)&flags[i], sizeof(uchar));
+
+ crc_tmp= 0;
+ len = ENV_SIZE;
+ off = off_env[i] + offsetof(env_t,data);
+ while (len > 0) {
+ int n = (len > sizeof(buf)) ? sizeof(buf) : len;
+
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR, off,
+ buf, n);
+
+ crc_tmp = crc32 (crc_tmp, buf, n);
+ len -= n;
+ off += n;
+ }
+ if (crc_tmp == crc[i])
+ crc_ok[i] = 1;
+ }
+
+ if (!crc_ok[0] && !crc_ok[1]) {
+ gd->env_addr = 0;
+ gd->env_valid = 0;
+
+ return 0;
+ } else if (crc_ok[0] && !crc_ok[1]) {
+ gd->env_valid = 1;
+ }
+ else if (!crc_ok[0] && crc_ok[1]) {
+ gd->env_valid = 2;
+ } else {
+ /* both ok - check serial */
+ if (flags[0] == ACTIVE_FLAG && flags[1] == OBSOLETE_FLAG)
+ gd->env_valid = 1;
+ else if (flags[0] == OBSOLETE_FLAG && flags[1] == ACTIVE_FLAG)
+ gd->env_valid = 2;
+ else if (flags[0] == 0xFF && flags[1] == 0)
+ gd->env_valid = 2;
+ else if(flags[1] == 0xFF && flags[0] == 0)
+ gd->env_valid = 1;
+ else /* flags are equal - almost impossible */
+ gd->env_valid = 1;
+ }
+
+ if (gd->env_valid == 2)
+ gd->env_addr = off_env[1] + offsetof(env_t,data);
+ else if (gd->env_valid == 1)
+ gd->env_addr = off_env[0] + offsetof(env_t,data);
+
+ return (0);
+}
+#else
int env_init(void)
{
ulong crc, len, new;
@@ -77,7 +253,7 @@ int env_init(void)
eeprom_init (); /* prepare for EEPROM read/write */
/* read old CRC */
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
CONFIG_ENV_OFFSET+offsetof(env_t,crc),
(uchar *)&crc, sizeof(ulong));
@@ -87,7 +263,8 @@ int env_init(void)
while (len > 0) {
int n = (len > sizeof(buf)) ? sizeof(buf) : len;
- eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR, CONFIG_ENV_OFFSET+off, buf, n);
+ eeprom_bus_read (CONFIG_SYS_DEF_EEPROM_ADDR,
+ CONFIG_ENV_OFFSET + off, buf, n);
new = crc32 (new, buf, n);
len -= n;
off += n;
@@ -103,3 +280,5 @@ int env_init(void)
return (0);
}
+#endif
+
diff --git a/common/kgdb.c b/common/kgdb.c
index 862f368..0531452 100644
--- a/common/kgdb.c
+++ b/common/kgdb.c
@@ -132,11 +132,20 @@ hex(unsigned char ch)
static unsigned char *
mem2hex(char *mem, char *buf, int count)
{
+ char *tmp;
unsigned char ch;
+ /*
+ * We use the upper half of buf as an intermediate buffer for the
+ * raw memory copy. Hex conversion will work against this one.
+ */
+ tmp = buf + count;
longjmp_on_fault = 1;
+
+ memcpy(tmp, mem, count);
+
while (count-- > 0) {
- ch = *mem++;
+ ch = *tmp++;
*buf++ = hexchars[ch >> 4];
*buf++ = hexchars[ch & 0xf];
}
@@ -151,21 +160,33 @@ mem2hex(char *mem, char *buf, int count)
static char *
hex2mem(char *buf, char *mem, int count)
{
- int i, hexValue;
- unsigned char ch;
- char *mem_start = mem;
+ int hexValue;
+ char *tmp_raw, *tmp_hex;
+
+ /*
+ * We use the upper half of buf as an intermediate buffer for the
+ * raw memory that is converted from hex.
+ */
+ tmp_raw = buf + count * 2;
+ tmp_hex = tmp_raw - 1;
longjmp_on_fault = 1;
- for (i=0; i<count; i++) {
- if ((hexValue = hex(*buf++)) < 0)
+ while (tmp_hex >= buf) {
+ tmp_raw--;
+ hexValue = hex(*tmp_hex--);
+ if (hexValue < 0)
kgdb_error(KGDBERR_NOTHEXDIG);
- ch = hexValue << 4;
- if ((hexValue = hex(*buf++)) < 0)
+ *tmp_raw = hexValue;
+ hexValue = hex(*tmp_hex--);
+ if (hexValue < 0)
kgdb_error(KGDBERR_NOTHEXDIG);
- ch |= hexValue;
- *mem++ = ch;
+ *tmp_raw |= hexValue << 4;
+
}
- kgdb_flush_cache_range((void *)mem_start, (void *)(mem - 1));
+
+ memcpy(mem, tmp_raw, count);
+
+ kgdb_flush_cache_range((void *)mem, (void *)(mem+count));
longjmp_on_fault = 0;
return buf;
diff --git a/common/kgdb_stubs.c b/common/kgdb_stubs.c
new file mode 100644
index 0000000..19b0c18
--- /dev/null
+++ b/common/kgdb_stubs.c
@@ -0,0 +1,64 @@
+/*
+ * U-boot - stub functions for common kgdb code,
+ * can be overridden in board specific files
+ *
+ * Copyright 2009 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <kgdb.h>
+
+int (*debugger_exception_handler)(struct pt_regs *);
+
+__attribute__((weak))
+void kgdb_serial_init(void)
+{
+ puts("[on serial] ");
+}
+
+__attribute__((weak))
+void putDebugChar(int c)
+{
+ serial_putc(c);
+}
+
+__attribute__((weak))
+void putDebugStr(const char *str)
+{
+#ifdef DEBUG
+ serial_puts(str);
+#endif
+}
+
+__attribute__((weak))
+int getDebugChar(void)
+{
+ return serial_getc();
+}
+
+__attribute__((weak))
+void kgdb_interruptible(int yes)
+{
+ return;
+}
+
+__attribute__((weak))
+void kgdb_flush_cache_range(void *from, void *to)
+{
+ flush_cache((unsigned long)from, (unsigned long)(to - from));
+}
+
+__attribute__((weak))
+void kgdb_flush_cache_all(void)
+{
+ if (dcache_status()) {
+ dcache_disable();
+ dcache_enable();
+ }
+ if (icache_status()) {
+ icache_disable();
+ icache_enable();
+ }
+}