summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWolfgang Denk <wd@pollux.denx.de>2006-11-27 16:13:00 +0100
committerWolfgang Denk <wd@denx.de>2006-11-27 16:13:00 +0100
commitd3c5e8b2f5945d93de8f23b053e9dcd033983245 (patch)
tree72c292c41bc0dfadd6f634fe03e697d8a4473487 /common
parent98280e3d431db77d92219438b8840853bd7cb412 (diff)
parenta9398e018593782c5fa7d0741955fc1256b34c1e (diff)
downloadu-boot-imx-d3c5e8b2f5945d93de8f23b053e9dcd033983245.zip
u-boot-imx-d3c5e8b2f5945d93de8f23b053e9dcd033983245.tar.gz
u-boot-imx-d3c5e8b2f5945d93de8f23b053e9dcd033983245.tar.bz2
Merge with /home/wd/git/u-boot/master
Diffstat (limited to 'common')
-rw-r--r--common/Makefile27
-rw-r--r--common/cmd_bdinfo.c6
-rw-r--r--common/cmd_boot.c2
-rw-r--r--common/cmd_bootm.c171
-rw-r--r--common/cmd_dcr.c131
-rw-r--r--common/cmd_jffs2.c16
-rw-r--r--common/cmd_mac.c66
-rw-r--r--common/cmd_mii.c4
-rw-r--r--common/cmd_nand.c465
-rw-r--r--common/cmd_nvedit.c5
-rw-r--r--common/cmd_scsi.c7
-rw-r--r--common/env_nand.c50
-rw-r--r--common/environment.c3
-rw-r--r--common/exports.c7
-rw-r--r--common/ft_build.c349
-rw-r--r--common/lcd.c31
-rw-r--r--common/main.c179
-rw-r--r--common/memsize.c17
-rw-r--r--common/miiphybb.c6
-rw-r--r--common/serial.c28
-rw-r--r--common/usb_storage.c25
-rw-r--r--common/xyzModem.c993
22 files changed, 1630 insertions, 958 deletions
diff --git a/common/Makefile b/common/Makefile
index eb0b5da..07ddc95 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -1,5 +1,5 @@
#
-# (C) Copyright 2004
+# (C) Copyright 2004-2006
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
# See file CREDITS for list of people who contributed to this
@@ -23,7 +23,7 @@
include $(TOPDIR)/config.mk
-LIB = libcommon.a
+LIB = $(obj)libcommon.a
AOBJS =
@@ -51,30 +51,31 @@ COBJS = main.o ACEX1K.o altera.o bedbug.o circbuf.o \
memsize.o miiphybb.o miiphyutil.o \
s_record.o serial.o soft_i2c.o soft_spi.o spartan2.o spartan3.o \
usb.o usb_kbd.o usb_storage.o \
- virtex2.o xilinx.o crc16.o xyzModem.o
+ virtex2.o xilinx.o crc16.o xyzModem.o cmd_mac.o
-OBJS = $(AOBJS) $(COBJS)
+SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
+OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
CPPFLAGS += -I..
all: $(LIB) $(AOBJS)
-$(LIB): .depend $(OBJS)
- $(AR) crv $@ $(OBJS)
+$(LIB): $(obj).depend $(OBJS)
+ $(AR) $(ARFLAGS) $@ $(OBJS)
-environment.o: environment.c ../tools/envcrc
+$(obj)environment.o: $(src)environment.c $(obj)../tools/envcrc
$(CC) $(AFLAGS) -Wa,--no-warn \
- -DENV_CRC=$(shell ../tools/envcrc) \
- -c -o $@ environment.c
+ -DENV_CRC=$(shell $(obj)../tools/envcrc) \
+ -c -o $@ $(src)environment.c
-../tools/envcrc:
+$(obj)../tools/envcrc:
$(MAKE) -C ../tools
#########################################################################
-.depend: Makefile $(AOBJS:.o=.S) $(COBJS:.o=.c)
- $(CC) -M $(CFLAGS) $(AOBJS:.o=.S) $(COBJS:.o=.c) > $@
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
-sinclude .depend
+sinclude $(obj).depend
#########################################################################
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c
index 256e4bc..70de795 100644
--- a/common/cmd_bdinfo.c
+++ b/common/cmd_bdinfo.c
@@ -62,11 +62,13 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
defined(CONFIG_405EP) || defined(CONFIG_XILINX_ML300) || \
defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
- defined(CONFIG_440SP)
+ defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
+ defined(CONFIG_440SP) || defined(CONFIG_440SPE)
print_str ("procfreq", strmhz(buf, bd->bi_procfreq));
print_str ("plb_busfreq", strmhz(buf, bd->bi_plb_busfreq));
#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || defined(CONFIG_XILINX_ML300) || \
- defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SPE)
+ defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SPE) || \
+ defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
print_str ("pci_busfreq", strmhz(buf, bd->bi_pci_busfreq));
#endif
#else /* ! CONFIG_405GP, CONFIG_405CR, CONFIG_405EP, CONFIG_XILINX_ML300, CONFIG_440EP CONFIG_440GR */
diff --git a/common/cmd_boot.c b/common/cmd_boot.c
index e68f16f..182e2ab 100644
--- a/common/cmd_boot.c
+++ b/common/cmd_boot.c
@@ -83,7 +83,7 @@ U_BOOT_CMD(
extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
U_BOOT_CMD(
- reset, 1, 0, do_reset,
+ reset, CFG_MAXARGS, 1, do_reset,
"reset - Perform RESET of the CPU\n",
NULL
);
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index fdf7180..3091a58 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -260,6 +260,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
if (hdr->ih_arch != IH_CPU_NIOS2)
#elif defined(__blackfin__)
if (hdr->ih_arch != IH_CPU_BLACKFIN)
+#elif defined(__avr32__)
+ if (hdr->ih_arch != IH_CPU_AVR32)
#else
# error Unknown CPU type
#endif
@@ -465,6 +467,13 @@ U_BOOT_CMD(
"[addr [arg ...]]\n - boot application image stored in memory\n"
"\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
"\t'arg' can be the address of an initrd image\n"
+#ifdef CONFIG_OF_FLAT_TREE
+ "\tWhen booting a Linux kernel which requires a flat device-tree\n"
+ "\ta third argument is required which is the address of the of the\n"
+ "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
+ "\tuse a '-' for the second argument. If you do not pass a third\n"
+ "\ta bd_info struct will be passed instead\n"
+#endif
);
#ifdef CONFIG_SILENT_CONSOLE
@@ -500,13 +509,8 @@ fixup_silent_linux ()
}
#endif /* CONFIG_SILENT_CONSOLE */
-#ifdef CONFIG_OF_FLAT_TREE
-extern const unsigned char oftree_dtb[];
-extern const unsigned int oftree_dtb_len;
-#endif
-
#ifdef CONFIG_PPC
-static void
+static void __attribute__((noinline))
do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
int argc, char *argv[],
ulong addr,
@@ -526,7 +530,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
image_header_t *hdr = &header;
#ifdef CONFIG_OF_FLAT_TREE
- char *of_flat_tree;
+ char *of_flat_tree = NULL;
+ ulong of_data = 0;
#endif
if ((s = getenv ("initrd_high")) != NULL) {
@@ -616,7 +621,17 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
/*
* Check if there is an initrd image
*/
+
+#ifdef CONFIG_OF_FLAT_TREE
+ /* Look for a '-' which indicates to ignore the ramdisk argument */
+ if (argc >= 3 && strcmp(argv[2], "-") == 0) {
+ debug ("Skipping initrd\n");
+ len = data = 0;
+ }
+ else
+#endif
if (argc >= 3) {
+ debug ("Not skipping initrd\n");
SHOW_BOOT_PROGRESS (9);
addr = simple_strtoul(argv[2], NULL, 16);
@@ -724,6 +739,106 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
len = data = 0;
}
+#ifdef CONFIG_OF_FLAT_TREE
+ if(argc > 3) {
+ of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16);
+ hdr = (image_header_t *)of_flat_tree;
+
+ if (*(ulong *)of_flat_tree == OF_DT_HEADER) {
+#ifndef CFG_NO_FLASH
+ if (addr2info((ulong)of_flat_tree) != NULL)
+ of_data = (ulong)of_flat_tree;
+#endif
+ } else if (ntohl(hdr->ih_magic) == IH_MAGIC) {
+ printf("## Flat Device Tree Image at %08lX\n", hdr);
+ print_image_hdr(hdr);
+
+ if ((ntohl(hdr->ih_load) < ((unsigned long)hdr + ntohl(hdr->ih_size) + sizeof(hdr))) &&
+ ((ntohl(hdr->ih_load) + ntohl(hdr->ih_size)) > (unsigned long)hdr)) {
+ printf ("ERROR: Load address overwrites Flat Device Tree uImage\n");
+ return;
+ }
+
+ printf(" Verifying Checksum ... ");
+ memmove (&header, (char *)hdr, sizeof(image_header_t));
+ checksum = ntohl(header.ih_hcrc);
+ header.ih_hcrc = 0;
+
+ if(checksum != crc32(0, (uchar *)&header, sizeof(image_header_t))) {
+ printf("ERROR: Flat Device Tree header checksum is invalid\n");
+ return;
+ }
+
+ checksum = ntohl(hdr->ih_dcrc);
+ addr = (ulong)((uchar *)(hdr) + sizeof(image_header_t));
+ len = ntohl(hdr->ih_size);
+
+ if(checksum != crc32(0, (uchar *)addr, len)) {
+ printf("ERROR: Flat Device Tree checksum is invalid\n");
+ return;
+ }
+ printf("OK\n");
+
+ if (ntohl(hdr->ih_type) != IH_TYPE_FLATDT) {
+ printf ("ERROR: uImage not Flat Device Tree type\n");
+ return;
+ }
+ if (ntohl(hdr->ih_comp) != IH_COMP_NONE) {
+ printf("ERROR: uImage is not uncompressed\n");
+ return;
+ }
+ if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) {
+ printf ("ERROR: uImage data is not a flat device tree\n");
+ return;
+ }
+
+ memmove((void *)ntohl(hdr->ih_load),
+ (void *)(of_flat_tree + sizeof(image_header_t)),
+ ntohl(hdr->ih_size));
+ of_flat_tree = (char *)ntohl(hdr->ih_load);
+ } else {
+ printf ("Did not find a flat flat device tree at address %08lX\n", of_flat_tree);
+ return;
+ }
+ printf (" Booting using flat device tree at 0x%x\n",
+ of_flat_tree);
+ } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]) && (len_ptr[2])) {
+ u_long tail = ntohl(len_ptr[0]) % 4;
+ int i;
+
+ /* skip kernel length, initrd length, and terminator */
+ of_data = (ulong)(&len_ptr[3]);
+ /* skip any additional image length fields */
+ for (i=2; len_ptr[i]; ++i)
+ of_data += 4;
+ /* add kernel length, and align */
+ of_data += ntohl(len_ptr[0]);
+ if (tail) {
+ of_data += 4 - tail;
+ }
+
+ /* add initrd length, and align */
+ tail = ntohl(len_ptr[1]) % 4;
+ of_data += ntohl(len_ptr[1]);
+ if (tail) {
+ of_data += 4 - tail;
+ }
+
+ if (((struct boot_param_header *)of_data)->magic != OF_DT_HEADER) {
+ printf ("ERROR: image is not a flat device tree\n");
+ return;
+ }
+
+ if (((struct boot_param_header *)of_data)->totalsize != ntohl(len_ptr[2])) {
+ printf ("ERROR: flat device tree size does not agree with image\n");
+ return;
+ }
+
+ } else if (getenv("disable_of") == NULL) {
+ printf ("ERROR: bootm needs flat device tree as third argument\n");
+ return;
+ }
+#endif
if (!data) {
debug ("No initrd\n");
}
@@ -793,15 +908,6 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
initrd_end = 0;
}
-#ifdef CONFIG_OF_FLAT_TREE
- if (initrd_start == 0)
- of_flat_tree = (char *)(((ulong)kbd - OF_FLAT_TREE_MAX_SIZE -
- sizeof(bd_t)) & ~0xF);
- else
- of_flat_tree = (char *)((initrd_start - OF_FLAT_TREE_MAX_SIZE -
- sizeof(bd_t)) & ~0xF);
-#endif
-
debug ("## Transferring control to Linux (at address %08lx) ...\n",
(ulong)kernel);
@@ -823,8 +929,27 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
*/
(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
-#else
- ft_setup(of_flat_tree, OF_FLAT_TREE_MAX_SIZE, kbd, initrd_start, initrd_end);
+#else /* CONFIG_OF_FLAT_TREE */
+ /* move of_flat_tree if needed */
+ if (of_data) {
+ ulong of_start, of_len;
+ of_len = ((struct boot_param_header *)of_data)->totalsize;
+ /* provide extra 8k pad */
+ if (initrd_start)
+ of_start = initrd_start - of_len - 8192;
+ else
+ of_start = (ulong)kbd - of_len - 8192;
+ of_start &= ~(4096 - 1); /* align on page */
+ debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
+ of_data, of_data + of_len - 1, of_len, of_len);
+
+ of_flat_tree = (char *)of_start;
+ printf (" Loading Device Tree to %08lx, end %08lx ... ",
+ of_start, of_start + of_len - 1);
+ memmove ((void *)of_start, (void *)of_data, of_len);
+ }
+
+ ft_setup(of_flat_tree, kbd, initrd_start, initrd_end);
/* ft_dump_blob(of_flat_tree); */
#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
@@ -841,10 +966,12 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
if (getenv("disable_of") != NULL)
(*kernel) ((bd_t *)of_flat_tree, initrd_start, initrd_end,
cmd_start, cmd_end);
- else
+ else {
+ ft_setup(of_flat_tree, kbd, initrd_start, initrd_end);
+ /* ft_dump_blob(of_flat_tree); */
(*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
-
-#endif
+ }
+#endif /* CONFIG_OF_FLAT_TREE */
}
#endif /* CONFIG_PPC */
@@ -1236,6 +1363,7 @@ print_type (image_header_t *hdr)
case IH_CPU_INVALID: arch = "Invalid CPU"; break;
case IH_CPU_ALPHA: arch = "Alpha"; break;
case IH_CPU_ARM: arch = "ARM"; break;
+ case IH_CPU_AVR32: arch = "AVR32"; break;
case IH_CPU_I386: arch = "Intel x86"; break;
case IH_CPU_IA64: arch = "IA64"; break;
case IH_CPU_MIPS: arch = "MIPS"; break;
@@ -1260,6 +1388,7 @@ print_type (image_header_t *hdr)
case IH_TYPE_MULTI: type = "Multi-File Image"; break;
case IH_TYPE_FIRMWARE: type = "Firmware"; break;
case IH_TYPE_SCRIPT: type = "Script"; break;
+ case IH_TYPE_FLATDT: type = "Flat Device Tree"; break;
default: type = "Unknown Image"; break;
}
diff --git a/common/cmd_dcr.c b/common/cmd_dcr.c
index 5842471..7221a86 100644
--- a/common/cmd_dcr.c
+++ b/common/cmd_dcr.c
@@ -31,6 +31,9 @@
#if defined(CONFIG_4xx) && (CONFIG_COMMANDS & CFG_CMD_SETGETDCR)
+unsigned long get_dcr (unsigned short);
+unsigned long set_dcr (unsigned short, unsigned long);
+
/* =======================================================================
* Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
* =======================================================================
@@ -64,8 +67,6 @@ int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
*/
int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
- unsigned long get_dcr (unsigned short);
- unsigned long set_dcr (unsigned short, unsigned long);
unsigned short dcrn; /* Device Control Register Num */
unsigned long value;
@@ -106,6 +107,120 @@ int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
return 0;
}
+/* =======================================================================
+ * Interpreter command to retrieve an register value through AMCC PPC 4xx
+ * Device Control Register inderect addressing.
+ * =======================================================================
+ */
+int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ unsigned short adr_dcrn; /* Device Control Register Num for Address */
+ unsigned short dat_dcrn; /* Device Control Register Num for Data */
+ unsigned short offset; /* Register's offset */
+ unsigned long value; /* Register's value */
+ char *ptr = NULL;
+ char buf[80];
+
+ /* Validate arguments */
+ if (argc < 3) {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ /* Find out whether ther is '.' (dot) symbol in the first parameter. */
+ strncpy (buf, argv[1], sizeof(buf)-1);
+ buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
+ ptr = strchr (buf, '.');
+
+ if (ptr != NULL) {
+ /* First parameter has format adr_dcrn.dat_dcrn */
+ *ptr++ = 0; /* erase '.', create zero-end string */
+ adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+ dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
+ } else {
+ /*
+ * First parameter has format adr_dcrn; dat_dcrn will be
+ * calculated as adr_dcrn+1.
+ */
+ adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+ dat_dcrn = adr_dcrn+1;
+ }
+
+ /* Register's offset */
+ offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
+
+ /* Disable interrupts */
+ disable_interrupts ();
+ /* Set offset */
+ set_dcr (adr_dcrn, offset);
+ /* get data */
+ value = get_dcr (dat_dcrn);
+ /* Enable interrupts */
+ enable_interrupts ();
+
+ printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
+
+ return 0;
+}
+
+/* =======================================================================
+ * Interpreter command to update an register value through AMCC PPC 4xx
+ * Device Control Register inderect addressing.
+ * =======================================================================
+ */
+int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+{
+ unsigned short adr_dcrn; /* Device Control Register Num for Address */
+ unsigned short dat_dcrn; /* Device Control Register Num for Data */
+ unsigned short offset; /* Register's offset */
+ unsigned long value; /* Register's value */
+ char *ptr = NULL;
+ char buf[80];
+
+ /* Validate arguments */
+ if (argc < 4) {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ /* Find out whether ther is '.' (dot) symbol in the first parameter. */
+ strncpy (buf, argv[1], sizeof(buf)-1);
+ buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
+ ptr = strchr (buf, '.');
+
+ if (ptr != NULL) {
+ /* First parameter has format adr_dcrn.dat_dcrn */
+ *ptr++ = 0; /* erase '.', create zero-end string */
+ adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+ dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
+ } else {
+ /*
+ * First parameter has format adr_dcrn; dat_dcrn will be
+ * calculated as adr_dcrn+1.
+ */
+ adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
+ dat_dcrn = adr_dcrn+1;
+ }
+
+ /* Register's offset */
+ offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
+ /* New value */
+ value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
+
+ /* Disable interrupts */
+ disable_interrupts ();
+ /* Set offset */
+ set_dcr (adr_dcrn, offset);
+ /* set data */
+ set_dcr (dat_dcrn, value);
+ /* Enable interrupts */
+ enable_interrupts ();
+
+ printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
+
+ return 0;
+}
+
/***************************************************/
U_BOOT_CMD(
@@ -119,4 +234,16 @@ U_BOOT_CMD(
"dcrn - set a DCR's value.\n"
);
+U_BOOT_CMD(
+ getidcr, 3, 1, do_getidcr,
+ "getidcr - Get a register value via indirect DCR addressing\n",
+ "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn.\n"
+);
+
+U_BOOT_CMD(
+ setidcr, 4, 1, do_setidcr,
+ "setidcr - Set a register value via indirect DCR addressing\n",
+ "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn.\n"
+);
+
#endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */
diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c
index 201c3c1..7fd1fa3 100644
--- a/common/cmd_jffs2.c
+++ b/common/cmd_jffs2.c
@@ -1268,7 +1268,7 @@ static void list_partitions(void)
part_num = 0;
list_for_each(pentry, &dev->parts) {
part = list_entry(pentry, struct part_info, link);
- printf(" %d: %-22s\t0x%08x\t0x%08x\t%d\n",
+ printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
part_num, part->name, part->size,
part->offset, part->mask_flags);
@@ -1300,7 +1300,7 @@ static void list_partitions(void)
* Given partition identifier in form of <dev_type><dev_num>,<part_num> find
* corresponding device and verify partition number.
*
- * @param id string describing device and partition
+ * @param id string describing device and partition or partition name
* @param dev pointer to the requested device (output)
* @param part_num verified partition number (output)
* @param part pointer to requested partition (output)
@@ -1309,11 +1309,23 @@ static void list_partitions(void)
int find_dev_and_part(const char *id, struct mtd_device **dev,
u8 *part_num, struct part_info **part)
{
+ struct list_head *dentry, *pentry;
u8 type, dnum, pnum;
const char *p;
DEBUGF("--- find_dev_and_part ---\nid = %s\n", id);
+ list_for_each(dentry, &devices) {
+ *part_num = 0;
+ *dev = list_entry(dentry, struct mtd_device, link);
+ list_for_each(pentry, &(*dev)->parts) {
+ *part = list_entry(pentry, struct part_info, link);
+ if (strcmp((*part)->name, id) == 0)
+ return 0;
+ (*part_num)++;
+ }
+ }
+
p = id;
*dev = NULL;
*part = NULL;
diff --git a/common/cmd_mac.c b/common/cmd_mac.c
new file mode 100644
index 0000000..0add432
--- /dev/null
+++ b/common/cmd_mac.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 Freescale Semiconductor
+ * York Sun (yorksun@freescale.com)
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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
+ */
+
+#include <common.h>
+#include <command.h>
+
+#ifdef CFG_ID_EEPROM
+
+extern int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+
+U_BOOT_CMD(
+ mac, 3, 1, do_mac,
+ "mac - display and program the system ID and MAC addresses in EEPROM\n",
+ "[read|save|id|num|errata|date|ports|0|1|2|3|4|5|6|7]\n"
+ "read\n"
+ " - show content of mac\n"
+ "mac save\n"
+ " - save to the EEPROM\n"
+ "mac id\n"
+ " - program system id\n"
+ "mac num\n"
+ " - program system serial number\n"
+ "mac errata\n"
+ " - program errata data\n"
+ "mac date\n"
+ " - program data date\n"
+ "mac ports\n"
+ " - program the number of ports\n"
+ "mac 0\n"
+ " - program the MAC address for port 0\n"
+ "mac 1\n"
+ " - program the MAC address for port 1\n"
+ "mac 2\n"
+ " - program the MAC address for port 2\n"
+ "mac 3\n"
+ " - program the MAC address for port 3\n"
+ "mac 4\n"
+ " - program the MAC address for port 4\n"
+ "mac 5\n"
+ " - program the MAC address for port 5\n"
+ "mac 6\n"
+ " - program the MAC address for port 6\n"
+ "mac 7\n"
+ " - program the MAC address for port 7\n"
+);
+#endif /* CFG_ID_EEPROM */
diff --git a/common/cmd_mii.c b/common/cmd_mii.c
index ee5e43e..e659536 100644
--- a/common/cmd_mii.c
+++ b/common/cmd_mii.c
@@ -117,8 +117,6 @@ int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
miiphy_speed (devname, j),
(miiphy_duplex (devname, j) == FULL)
? "FDX" : "HDX");
- } else {
- puts ("Error reading info from the PHY\n");
}
}
} else if (op == 'r') {
@@ -503,8 +501,6 @@ int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
miiphy_speed (devname, j),
(miiphy_duplex (devname, j) == FULL)
? "FDX" : "HDX");
- } else {
- puts ("Error reading info from the PHY\n");
}
}
} else if (op[0] == 'r') {
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 21adb1b..7286726 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -36,6 +36,15 @@
#include <jffs2/jffs2.h>
#include <nand.h>
+#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+
+/* parition handling routines */
+int mtdparts_init(void);
+int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num);
+int find_dev_and_part(const char *id, struct mtd_device **dev,
+ u8 *part_num, struct part_info **part);
+#endif
+
extern nand_info_t nand_info[]; /* info for NAND chips */
static int nand_dump_oob(nand_info_t *nand, ulong off)
@@ -83,50 +92,75 @@ static int nand_dump(nand_info_t *nand, ulong off)
/* ------------------------------------------------------------------------- */
-static void
-arg_off_size(int argc, char *argv[], ulong *off, ulong *size, ulong totsize)
+static inline int str2long(char *p, ulong *num)
{
- *off = 0;
- *size = 0;
-
-#if defined(CONFIG_JFFS2_NAND) && defined(CFG_JFFS_CUSTOM_PART)
- if (argc >= 1 && strcmp(argv[0], "partition") == 0) {
- int part_num;
- struct part_info *part;
- const char *partstr;
-
- if (argc >= 2)
- partstr = argv[1];
- else
- partstr = getenv("partition");
+ char *endptr;
- if (partstr)
- part_num = (int)simple_strtoul(partstr, NULL, 10);
- else
- part_num = 0;
+ *num = simple_strtoul(p, &endptr, 16);
+ return (*p != '\0' && *endptr == '\0') ? 1 : 0;
+}
- part = jffs2_part_info(part_num);
- if (part == NULL) {
- printf("\nInvalid partition %d\n", part_num);
- return;
+static int
+arg_off_size(int argc, char *argv[], nand_info_t *nand, ulong *off, ulong *size)
+{
+ int idx = nand_curr_device;
+#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+ struct mtd_device *dev;
+ struct part_info *part;
+ u8 pnum;
+
+ if (argc >= 1 && !(str2long(argv[0], off))) {
+ if ((mtdparts_init() == 0) &&
+ (find_dev_and_part(argv[0], &dev, &pnum, &part) == 0)) {
+ if (dev->id->type != MTD_DEV_TYPE_NAND) {
+ puts("not a NAND device\n");
+ return -1;
+ }
+ *off = part->offset;
+ if (argc >= 2) {
+ if (!(str2long(argv[1], size))) {
+ printf("'%s' is not a number\n", argv[1]);
+ return -1;
+ }
+ if (*size > part->size)
+ *size = part->size;
+ } else {
+ *size = part->size;
+ }
+ idx = dev->id->num;
+ *nand = nand_info[idx];
+ goto out;
}
- *size = part->size;
- *off = (ulong)part->offset;
- } else
+ }
#endif
- {
- if (argc >= 1)
- *off = (ulong)simple_strtoul(argv[0], NULL, 16);
- else
- *off = 0;
- if (argc >= 2)
- *size = (ulong)simple_strtoul(argv[1], NULL, 16);
- else
- *size = totsize - *off;
+ if (argc >= 1) {
+ if (!(str2long(argv[0], off))) {
+ printf("'%s' is not a number\n", argv[0]);
+ return -1;
+ }
+ } else {
+ *off = 0;
+ }
+ if (argc >= 2) {
+ if (!(str2long(argv[1], size))) {
+ printf("'%s' is not a number\n", argv[1]);
+ return -1;
+ }
+ } else {
+ *size = nand->size - *off;
}
+#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+out:
+#endif
+ printf("device %d ", idx);
+ if (*size == nand->size)
+ puts("whole chip\n");
+ else
+ printf("offset 0x%x, size 0x%x\n", *off, *size);
+ return 0;
}
int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
@@ -135,11 +169,16 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
ulong addr, off, size;
char *cmd, *s;
nand_info_t *nand;
+ int quiet = 0;
+ const char *quiet_str = getenv("quiet");
/* at least two arguments please */
if (argc < 2)
goto usage;
+ if (quiet_str)
+ quiet = simple_strtoul(quiet_str, NULL, 0) != 0;
+
cmd = argv[1];
if (strcmp(cmd, "info") == 0) {
@@ -173,12 +212,23 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
printf("Device %d: %s", dev, nand_info[dev].name);
puts("... is now current device\n");
nand_curr_device = dev;
+
+#ifdef CFG_NAND_SELECT_DEVICE
+ /*
+ * Select the chip in the board/cpu specific driver
+ */
+ board_nand_select_device(nand_info[dev].priv, dev);
+#endif
+
return 0;
}
if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 &&
strncmp(cmd, "dump", 4) != 0 &&
- strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0)
+ strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 &&
+ strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 &&
+ strcmp(cmd, "biterr") != 0 &&
+ strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0 )
goto usage;
/* the following commands operate on the current device */
@@ -197,14 +247,50 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
return 0;
}
- if (strcmp(cmd, "erase") == 0) {
- arg_off_size(argc - 2, argv + 2, &off, &size, nand->size);
- if (off == 0 && size == 0)
+ /*
+ * Syntax is:
+ * 0 1 2 3 4
+ * nand erase [clean] [off size]
+ */
+ if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) {
+ nand_erase_options_t opts;
+ /* "clean" at index 2 means request to write cleanmarker */
+ int clean = argc > 2 && !strcmp("clean", argv[2]);
+ int o = clean ? 3 : 2;
+ int scrub = !strcmp(cmd, "scrub");
+
+ printf("\nNAND %s: ", scrub ? "scrub" : "erase");
+ /* skip first two or three arguments, look for offset and size */
+ if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0)
return 1;
- printf("\nNAND erase: device %d offset 0x%x, size 0x%x ",
- nand_curr_device, off, size);
- ret = nand_erase(nand, off, size);
+ memset(&opts, 0, sizeof(opts));
+ opts.offset = off;
+ opts.length = size;
+ opts.jffs2 = clean;
+ opts.quiet = quiet;
+
+ if (scrub) {
+ puts("Warning: "
+ "scrub option will erase all factory set "
+ "bad blocks!\n"
+ " "
+ "There is no reliable way to recover them.\n"
+ " "
+ "Use this command only for testing purposes "
+ "if you\n"
+ " "
+ "are sure of what you are doing!\n"
+ "\nReally scrub this NAND flash? <y/N>\n");
+
+ if (getc() == 'y' && getc() == '\r') {
+ opts.scrub = 1;
+ } else {
+ puts("scrub aborted\n");
+ return -1;
+ }
+ }
+ ret = nand_erase_opts(nand, &opts);
printf("%s\n", ret ? "ERROR" : "OK");
return ret == 0 ? 0 : 1;
@@ -228,37 +314,142 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
/* read write */
if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) {
+ int read;
+
if (argc < 4)
goto usage;
-/*
- s = strchr(cmd, '.');
- clean = CLEAN_NONE;
- if (s != NULL) {
- if (strcmp(s, ".jffs2") == 0 || strcmp(s, ".e") == 0
- || strcmp(s, ".i"))
- clean = CLEAN_JFFS2;
- }
-*/
+
addr = (ulong)simple_strtoul(argv[2], NULL, 16);
- arg_off_size(argc - 3, argv + 3, &off, &size, nand->size);
- if (off == 0 && size == 0)
+ read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
+ printf("\nNAND %s: ", read ? "read" : "write");
+ if (arg_off_size(argc - 3, argv + 3, nand, &off, &size) != 0)
return 1;
- i = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */
- printf("\nNAND %s: device %d offset %u, size %u ... ",
- i ? "read" : "write", nand_curr_device, off, size);
-
- if (i)
- ret = nand_read(nand, off, &size, (u_char *)addr);
- else
- ret = nand_write(nand, off, &size, (u_char *)addr);
+ s = strchr(cmd, '.');
+ if (s != NULL &&
+ (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i"))) {
+ if (read) {
+ /* read */
+ nand_read_options_t opts;
+ memset(&opts, 0, sizeof(opts));
+ opts.buffer = (u_char*) addr;
+ opts.length = size;
+ opts.offset = off;
+ opts.quiet = quiet;
+ ret = nand_read_opts(nand, &opts);
+ } else {
+ /* write */
+ nand_write_options_t opts;
+ memset(&opts, 0, sizeof(opts));
+ opts.buffer = (u_char*) addr;
+ opts.length = size;
+ opts.offset = off;
+ /* opts.forcejffs2 = 1; */
+ opts.pad = 1;
+ opts.blockalign = 1;
+ opts.quiet = quiet;
+ ret = nand_write_opts(nand, &opts);
+ }
+ } else {
+ if (read)
+ ret = nand_read(nand, off, &size, (u_char *)addr);
+ else
+ ret = nand_write(nand, off, &size, (u_char *)addr);
+ }
printf(" %d bytes %s: %s\n", size,
- i ? "read" : "written", ret ? "ERROR" : "OK");
+ read ? "read" : "written", ret ? "ERROR" : "OK");
return ret == 0 ? 0 : 1;
}
+
+ if (strcmp(cmd, "markbad") == 0) {
+ addr = (ulong)simple_strtoul(argv[2], NULL, 16);
+
+ int ret = nand->block_markbad(nand, addr);
+ if (ret == 0) {
+ printf("block 0x%08lx successfully marked as bad\n",
+ (ulong) addr);
+ return 0;
+ } else {
+ printf("block 0x%08lx NOT marked as bad! ERROR %d\n",
+ (ulong) addr, ret);
+ }
+ return 1;
+ }
+ if (strcmp(cmd, "biterr") == 0) {
+ /* todo */
+ return 1;
+ }
+
+ if (strcmp(cmd, "lock") == 0) {
+ int tight = 0;
+ int status = 0;
+ if (argc == 3) {
+ if (!strcmp("tight", argv[2]))
+ tight = 1;
+ if (!strcmp("status", argv[2]))
+ status = 1;
+ }
+
+ if (status) {
+ ulong block_start = 0;
+ ulong off;
+ int last_status = -1;
+
+ struct nand_chip *nand_chip = nand->priv;
+ /* check the WP bit */
+ nand_chip->cmdfunc (nand, NAND_CMD_STATUS, -1, -1);
+ printf("device is %swrite protected\n",
+ (nand_chip->read_byte(nand) & 0x80 ?
+ "NOT " : "" ) );
+
+ for (off = 0; off < nand->size; off += nand->oobblock) {
+ int s = nand_get_lock_status(nand, off);
+
+ /* print message only if status has changed
+ * or at end of chip
+ */
+ if (off == nand->size - nand->oobblock
+ || (s != last_status && off != 0)) {
+
+ printf("%08x - %08x: %8d pages %s%s%s\n",
+ block_start,
+ off-1,
+ (off-block_start)/nand->oobblock,
+ ((last_status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""),
+ ((last_status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""),
+ ((last_status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : ""));
+ }
+
+ last_status = s;
+ }
+ } else {
+ if (!nand_lock(nand, tight)) {
+ puts("NAND flash successfully locked\n");
+ } else {
+ puts("Error locking NAND flash\n");
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ if (strcmp(cmd, "unlock") == 0) {
+ if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0)
+ return 1;
+
+ if (!nand_unlock(nand, off, size)) {
+ puts("NAND flash successfully unlocked\n");
+ } else {
+ puts("Error unlocking NAND flash, "
+ "write and erase will probably fail\n");
+ return 1;
+ }
+ return 0;
+ }
+
usage:
printf("Usage:\n%s\n", cmdtp->usage);
return 1;
@@ -268,8 +459,8 @@ U_BOOT_CMD(nand, 5, 1, do_nand,
"nand - NAND sub-system\n",
"info - show available NAND devices\n"
"nand device [dev] - show or set current device\n"
- "nand read[.jffs2] - addr off size\n"
- "nand write[.jffs2] - addr off size - read/write `size' bytes starting\n"
+ "nand read[.jffs2] - addr off|partition size\n"
+ "nand write[.jffs2] - addr off|partiton size - read/write `size' bytes starting\n"
" at offset `off' to/from memory address `addr'\n"
"nand erase [clean] [off size] - erase `size' bytes from\n"
" offset `off' (entire device if not specified)\n"
@@ -277,64 +468,24 @@ U_BOOT_CMD(nand, 5, 1, do_nand,
"nand dump[.oob] off - dump page\n"
"nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n"
"nand markbad off - mark bad block at offset (UNSAFE)\n"
- "nand biterr off - make a bit error at offset (UNSAFE)\n");
+ "nand biterr off - make a bit error at offset (UNSAFE)\n"
+ "nand lock [tight] [status] - bring nand to lock state or display locked pages\n"
+ "nand unlock [offset] [size] - unlock section\n");
-int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
+ ulong offset, ulong addr, char *cmd)
{
- char *boot_device = NULL;
- char *ep;
- int dev;
int r;
- ulong addr, cnt, offset = 0;
+ char *ep;
+ ulong cnt;
image_header_t *hdr;
- nand_info_t *nand;
-
- switch (argc) {
- case 1:
- addr = CFG_LOAD_ADDR;
- boot_device = getenv("bootdevice");
- break;
- case 2:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = getenv("bootdevice");
- break;
- case 3:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = argv[2];
- break;
- case 4:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = argv[2];
- offset = simple_strtoul(argv[3], NULL, 16);
- break;
- default:
- printf("Usage:\n%s\n", cmdtp->usage);
- SHOW_BOOT_PROGRESS(-1);
- return 1;
- }
-
- if (!boot_device) {
- puts("\n** No boot device **\n");
- SHOW_BOOT_PROGRESS(-1);
- return 1;
- }
- dev = simple_strtoul(boot_device, &ep, 16);
-
- if (dev < 0 || dev >= CFG_MAX_NAND_DEVICE || !nand_info[dev].name) {
- printf("\n** Device %d not available\n", dev);
- SHOW_BOOT_PROGRESS(-1);
- return 1;
- }
-
- nand = &nand_info[dev];
- printf("\nLoading from device %d: %s (offset 0x%lx)\n",
- dev, nand->name, offset);
+ printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset);
cnt = nand->oobblock;
r = nand_read(nand, offset, &cnt, (u_char *) addr);
if (r) {
- printf("** Read error on %d\n", dev);
+ puts("** Read error\n");
SHOW_BOOT_PROGRESS(-1);
return 1;
}
@@ -353,7 +504,7 @@ int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
r = nand_read(nand, offset, &cnt, (u_char *) addr);
if (r) {
- printf("** Read error on %d\n", dev);
+ puts("** Read error\n");
SHOW_BOOT_PROGRESS(-1);
return 1;
}
@@ -367,7 +518,7 @@ int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
char *local_args[2];
extern int do_bootm(cmd_tbl_t *, int, int, char *[]);
- local_args[0] = argv[0];
+ local_args[0] = cmd;
local_args[1] = NULL;
printf("Automatic boot of image at addr 0x%08lx ...\n", addr);
@@ -378,9 +529,83 @@ int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
return 0;
}
-U_BOOT_CMD(nboot, 4, 1, do_nandboot,
- "nboot - boot from NAND device\n", "loadAddr dev\n");
+int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+{
+ char *boot_device = NULL;
+ int idx;
+ ulong addr, offset = 0;
+#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+ struct mtd_device *dev;
+ struct part_info *part;
+ u8 pnum;
+
+ if (argc >= 2) {
+ char *p = (argc == 2) ? argv[1] : argv[2];
+ if (!(str2long(p, &addr)) && (mtdparts_init() == 0) &&
+ (find_dev_and_part(p, &dev, &pnum, &part) == 0)) {
+ if (dev->id->type != MTD_DEV_TYPE_NAND) {
+ puts("Not a NAND device\n");
+ return 1;
+ }
+ if (argc > 3)
+ goto usage;
+ if (argc == 3)
+ addr = simple_strtoul(argv[2], NULL, 16);
+ else
+ addr = CFG_LOAD_ADDR;
+ return nand_load_image(cmdtp, &nand_info[dev->id->num],
+ part->offset, addr, argv[0]);
+ }
+ }
+#endif
+ switch (argc) {
+ case 1:
+ addr = CFG_LOAD_ADDR;
+ boot_device = getenv("bootdevice");
+ break;
+ case 2:
+ addr = simple_strtoul(argv[1], NULL, 16);
+ boot_device = getenv("bootdevice");
+ break;
+ case 3:
+ addr = simple_strtoul(argv[1], NULL, 16);
+ boot_device = argv[2];
+ break;
+ case 4:
+ addr = simple_strtoul(argv[1], NULL, 16);
+ boot_device = argv[2];
+ offset = simple_strtoul(argv[3], NULL, 16);
+ break;
+ default:
+#if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
+usage:
+#endif
+ printf("Usage:\n%s\n", cmdtp->usage);
+ SHOW_BOOT_PROGRESS(-1);
+ return 1;
+ }
+
+ if (!boot_device) {
+ puts("\n** No boot device **\n");
+ SHOW_BOOT_PROGRESS(-1);
+ return 1;
+ }
+
+ idx = simple_strtoul(boot_device, NULL, 16);
+
+ if (idx < 0 || idx >= CFG_MAX_NAND_DEVICE || !nand_info[idx].name) {
+ printf("\n** Device %d not available\n", idx);
+ SHOW_BOOT_PROGRESS(-1);
+ return 1;
+ }
+
+ return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]);
+}
+
+U_BOOT_CMD(nboot, 4, 1, do_nandboot,
+ "nboot - boot from NAND device\n",
+ "[partition] | [[[loadAddr] dev] offset]\n");
#endif /* (CONFIG_COMMANDS & CFG_CMD_NAND) */
@@ -596,7 +821,7 @@ int do_nand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1;
}
- printf ("\nNAND %s: device %d offset %ld, size %ld ... ",
+ printf ("\nNAND %s: device %d offset %ld, size %ld ...\n",
(cmd & NANDRW_READ) ? "read" : "write",
curr_device, off, size);
@@ -615,7 +840,7 @@ int do_nand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
ulong size = simple_strtoul(argv[3 + clean], NULL, 16);
int ret;
- printf ("\nNAND erase: device %d offset %ld, size %ld ... ",
+ printf ("\nNAND erase: device %d offset %ld, size %ld ...\n",
curr_device, off, size);
ret = nand_legacy_erase (nand_dev_desc + curr_device,
@@ -635,7 +860,7 @@ int do_nand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
U_BOOT_CMD(
nand, 5, 1, do_nand,
- "nand - NAND sub-system\n",
+ "nand - legacy NAND sub-system\n",
"info - show available NAND devices\n"
"nand device [dev] - show or set current device\n"
"nand read[.jffs2[s]] addr off size\n"
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 6257fbd..d3f50f8 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -167,6 +167,11 @@ int _do_setenv (int flag, int argc, char *argv[])
name = argv[1];
+ if (strchr(name, '=')) {
+ printf ("## Error: illegal character '=' in variable name \"%s\"\n", name);
+ return 1;
+ }
+
/*
* search if variable with this name already exists
*/
diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c
index e804861..cc08743 100644
--- a/common/cmd_scsi.c
+++ b/common/cmd_scsi.c
@@ -43,8 +43,13 @@
#else
#define SCSI_DEV_ID CONFIG_SCSI_DEV_ID
#endif
+#elif defined CONFIG_SATA_ULI5288
+
+#define SCSI_VEND_ID 0x10b9
+#define SCSI_DEV_ID 0x5288
+
#else
-#error CONFIG_SCSI_SYM53C8XX must be defined
+#error no scsi device defined
#endif
diff --git a/common/env_nand.c b/common/env_nand.c
index 0a05b09..67c4a4e 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -2,7 +2,7 @@
* (C) Copyright 2004
* Jian Zhang, Texas Instruments, jzhang@ti.com.
- * (C) Copyright 2000-2004
+ * (C) Copyright 2000-2006
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
@@ -76,7 +76,9 @@ env_t *env_ptr = 0;
/* local functions */
+#if !defined(ENV_IS_EMBEDDED)
static void use_default(void);
+#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -91,11 +93,55 @@ uchar env_get_char_spec (int index)
* Mark it OK for now. env_relocate() in env_common.c
* will call our relocate function which will does
* the real validation.
+ *
+ * When using a NAND boot image (like sequoia_nand), the environment
+ * can be embedded or attached to the U-Boot image in NAND flash. This way
+ * the SPL loads not only the U-Boot image from NAND but also the
+ * environment.
*/
int env_init(void)
{
+#if defined(ENV_IS_EMBEDDED)
+ ulong total;
+ int crc1_ok = 0, crc2_ok = 0;
+ env_t *tmp_env1, *tmp_env2;
+
+ total = CFG_ENV_SIZE;
+
+ tmp_env1 = env_ptr;
+ tmp_env2 = (env_t *)((ulong)env_ptr + CFG_ENV_SIZE);
+
+ crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
+ crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
+
+ if (!crc1_ok && !crc2_ok)
+ gd->env_valid = 0;
+ else if(crc1_ok && !crc2_ok)
+ gd->env_valid = 1;
+ else if(!crc1_ok && crc2_ok)
+ gd->env_valid = 2;
+ else {
+ /* both ok - check serial */
+ if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
+ gd->env_valid = 2;
+ else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
+ gd->env_valid = 1;
+ else if(tmp_env1->flags > tmp_env2->flags)
+ gd->env_valid = 1;
+ else if(tmp_env2->flags > tmp_env1->flags)
+ gd->env_valid = 2;
+ else /* flags are equal - almost impossible */
+ gd->env_valid = 1;
+ }
+
+ if (gd->env_valid == 1)
+ env_ptr = tmp_env1;
+ else if (gd->env_valid == 2)
+ env_ptr = tmp_env2;
+#else /* ENV_IS_EMBEDDED */
gd->env_addr = (ulong)&default_environment[0];
gd->env_valid = 1;
+#endif /* ENV_IS_EMBEDDED */
return (0);
}
@@ -236,6 +282,7 @@ void env_relocate_spec (void)
}
#endif /* CFG_ENV_OFFSET_REDUND */
+#if !defined(ENV_IS_EMBEDDED)
static void use_default()
{
puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
@@ -253,5 +300,6 @@ static void use_default()
gd->env_valid = 1;
}
+#endif
#endif /* CFG_ENV_IS_IN_NAND */
diff --git a/common/environment.c b/common/environment.c
index 81471ce..19bdeb0 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -60,7 +60,8 @@
defined(CONFIG_RRVISION) || \
defined(CONFIG_TRAB) || \
defined(CONFIG_PPCHAMELEONEVB) || \
- defined(CONFIG_M5271EVB)) && \
+ defined(CONFIG_M5271EVB) || \
+ defined(CONFIG_NAND_U_BOOT)) && \
defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */
/* XXX - This only works with GNU C */
# define __PPCENV__ __attribute__ ((section(".ppcenv")))
diff --git a/common/exports.c b/common/exports.c
index ef25338..0cb4396 100644
--- a/common/exports.c
+++ b/common/exports.c
@@ -23,8 +23,11 @@ void jumptable_init (void)
gd->jt[XF_get_version] = (void *) get_version;
gd->jt[XF_malloc] = (void *) malloc;
gd->jt[XF_free] = (void *) free;
- gd->jt[XF_get_timer] = (void *)get_timer;
- gd->jt[XF_udelay] = (void *)udelay;
+ gd->jt[XF_getenv] = (void *) getenv;
+ gd->jt[XF_setenv] = (void *) setenv;
+ gd->jt[XF_get_timer] = (void *) get_timer;
+ gd->jt[XF_simple_strtoul] = (void *) simple_strtoul;
+ gd->jt[XF_udelay] = (void *) udelay;
#if defined(CONFIG_I386) || defined(CONFIG_PPC)
gd->jt[XF_install_hdlr] = (void *) irq_install_handler;
gd->jt[XF_free_hdlr] = (void *) irq_free_handler;
diff --git a/common/ft_build.c b/common/ft_build.c
index 9e9c906..980e40f 100644
--- a/common/ft_build.c
+++ b/common/ft_build.c
@@ -1,5 +1,22 @@
/*
* OF flat tree builder
+ * Written by: Pantelis Antoniou <pantelis.antoniou@gmail.com>
+ * Updated by: Matthew McClintock <msm@freescale.com>
+ *
+ * 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
*/
#include <common.h>
@@ -13,44 +30,39 @@
#include <ft_build.h>
+#undef DEBUG
+
/* align addr on a size boundary - adjust address up if needed -- Cort */
#define _ALIGN(addr,size) (((addr)+(size)-1)&(~((size)-1)))
+#ifndef CONFIG_OF_BOOT_CPU
+#define CONFIG_OF_BOOT_CPU 0
+#endif
+#define SIZE_OF_RSVMAP_ENTRY (2*sizeof(u64))
static void ft_put_word(struct ft_cxt *cxt, u32 v)
{
- if (cxt->overflow) /* do nothing */
- return;
-
- /* check for overflow */
- if (cxt->p + 4 > cxt->pstr) {
- cxt->overflow = 1;
- return;
- }
+ memmove(cxt->p + sizeof(u32), cxt->p, cxt->p_end - cxt->p);
*(u32 *) cxt->p = cpu_to_be32(v);
- cxt->p += 4;
+ cxt->p += sizeof(u32);
+ cxt->p_end += sizeof(u32);
}
static inline void ft_put_bin(struct ft_cxt *cxt, const void *data, int sz)
{
- u8 *p;
+ int aligned_size = ((u8 *)_ALIGN((unsigned long)cxt->p + sz,
+ sizeof(u32))) - cxt->p;
- if (cxt->overflow) /* do nothing */
- return;
-
- /* next pointer pos */
- p = (u8 *) _ALIGN((unsigned long)cxt->p + sz, 4);
+ memmove(cxt->p + aligned_size, cxt->p, cxt->p_end - cxt->p);
- /* check for overflow */
- if (p > cxt->pstr) {
- cxt->overflow = 1;
- return;
- }
+ /* make sure the last bytes are zeroed */
+ memset(cxt->p + aligned_size - (aligned_size % sizeof(u32)), 0,
+ (aligned_size % sizeof(u32)));
memcpy(cxt->p, data, sz);
- if ((sz & 3) != 0)
- memset(cxt->p + sz, 0, 4 - (sz & 3));
- cxt->p = p;
+
+ cxt->p += aligned_size;
+ cxt->p_end += aligned_size;
}
void ft_begin_node(struct ft_cxt *cxt, const char *name)
@@ -73,11 +85,11 @@ static int lookup_string(struct ft_cxt *cxt, const char *name)
{
u8 *p;
- p = cxt->pstr;
- while (p < cxt->pstr_begin) {
- if (strcmp(p, name) == 0)
- return p - cxt->p_begin;
- p += strlen(p) + 1;
+ p = cxt->p;
+ while (p < cxt->p_end) {
+ if (strcmp((char *)p, name) == 0)
+ return p - cxt->p;
+ p += strlen((char *)p) + 1;
}
return -1;
@@ -85,24 +97,13 @@ static int lookup_string(struct ft_cxt *cxt, const char *name)
void ft_prop(struct ft_cxt *cxt, const char *name, const void *data, int sz)
{
- int len, off;
-
- if (cxt->overflow)
- return;
-
- len = strlen(name) + 1;
+ int off = 0;
off = lookup_string(cxt, name);
if (off == -1) {
- /* check if we have space */
- if (cxt->p + 12 + sz + len > cxt->pstr) {
- cxt->overflow = 1;
- return;
- }
-
- cxt->pstr -= len;
- memcpy(cxt->pstr, name, len);
- off = cxt->pstr - cxt->p_begin;
+ memcpy(cxt->p_end, name, strlen(name) + 1);
+ off = cxt->p_end - cxt->p;
+ cxt->p_end += strlen(name) + 1;
}
/* now put offset from beginning of *STRUCTURE* */
@@ -122,138 +123,63 @@ void ft_prop_int(struct ft_cxt *cxt, const char *name, int val)
{
u32 v = cpu_to_be32((u32) val);
- ft_prop(cxt, name, &v, 4);
+ ft_prop(cxt, name, &v, sizeof(u32));
}
-/* start construction of the flat OF tree */
-void ft_begin(struct ft_cxt *cxt, void *blob, int max_size)
+/* pick up and start working on a tree in place */
+void ft_init_cxt(struct ft_cxt *cxt, void *blob)
{
struct boot_param_header *bph = blob;
- u32 off;
- /* clear the cxt */
memset(cxt, 0, sizeof(*cxt));
cxt->bph = bph;
- cxt->max_size = max_size;
-
- /* zero everything in the header area */
- memset(bph, 0, sizeof(*bph));
-
- bph->magic = cpu_to_be32(OF_DT_HEADER);
- bph->version = cpu_to_be32(0x10);
- bph->last_comp_version = cpu_to_be32(0x10);
+ bph->boot_cpuid_phys = CONFIG_OF_BOOT_CPU;
- /* start pointers */
- cxt->pres_begin = (u8 *) _ALIGN((unsigned long)(bph + 1), 8);
- cxt->pres = cxt->pres_begin;
-
- off = (unsigned long)cxt->pres_begin - (unsigned long)bph;
- bph->off_mem_rsvmap = cpu_to_be32(off);
-
- ((u64 *) cxt->pres)[0] = 0; /* phys = 0, size = 0, terminate */
- ((u64 *) cxt->pres)[1] = 0;
+ /* find beginning and end of reserve map table (zeros in last entry) */
+ cxt->p_rsvmap = (u8 *)bph + bph->off_mem_rsvmap;
+ while ( ((uint64_t *)cxt->p_rsvmap)[0] != 0 &&
+ ((uint64_t *)cxt->p_rsvmap)[1] != 0 ) {
+ cxt->p_rsvmap += SIZE_OF_RSVMAP_ENTRY;
+ }
- cxt->p_anchor = cxt->pres + 16; /* over the terminator */
+ cxt->p_start = (u8 *)bph + bph->off_dt_struct;
+ cxt->p_end = (u8 *)bph + bph->totalsize;
+ cxt->p = (u8 *)bph + bph->off_dt_strings;
}
/* add a reserver physical area to the rsvmap */
-void ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size)
+void ft_add_rsvmap(struct ft_cxt *cxt, u64 physstart, u64 physend)
{
- ((u64 *) cxt->pres)[0] = cpu_to_be64(physaddr); /* phys = 0, size = 0, terminate */
- ((u64 *) cxt->pres)[1] = cpu_to_be64(size);
-
- cxt->pres += 16; /* advance */
-
- ((u64 *) cxt->pres)[0] = 0; /* phys = 0, size = 0, terminate */
- ((u64 *) cxt->pres)[1] = 0;
-
- /* keep track of size */
- cxt->res_size = cxt->pres + 16 - cxt->pres_begin;
-
- cxt->p_anchor = cxt->pres + 16; /* over the terminator */
+ memmove(cxt->p_rsvmap + SIZE_OF_RSVMAP_ENTRY, cxt->p_rsvmap,
+ cxt->p_end - cxt->p_rsvmap);
+
+ ((u64 *)cxt->p_rsvmap)[0] = cpu_to_be64(physstart);
+ ((u64 *)cxt->p_rsvmap)[1] = cpu_to_be64(physend);
+ ((u64 *)cxt->p_rsvmap)[2] = 0;
+ ((u64 *)cxt->p_rsvmap)[3] = 0;
+
+ cxt->p_rsvmap += SIZE_OF_RSVMAP_ENTRY;
+ cxt->p_start += SIZE_OF_RSVMAP_ENTRY;
+ cxt->p += SIZE_OF_RSVMAP_ENTRY;
+ cxt->p_end += SIZE_OF_RSVMAP_ENTRY;
}
-void ft_begin_tree(struct ft_cxt *cxt)
+void ft_end_tree(struct ft_cxt *cxt)
{
- cxt->p_begin = cxt->p_anchor;
- cxt->pstr_begin = (char *)cxt->bph + cxt->max_size; /* point at the end */
-
- cxt->p = cxt->p_begin;
- cxt->pstr = cxt->pstr_begin;
+ ft_put_word(cxt, OF_DT_END);
}
-int ft_end_tree(struct ft_cxt *cxt)
-{
+/* update the boot param header with correct values */
+void ft_finalize_tree(struct ft_cxt *cxt) {
struct boot_param_header *bph = cxt->bph;
- int off, sz, sz1;
- u32 tag, v;
- u8 *p;
-
- ft_put_word(cxt, OF_DT_END);
-
- if (cxt->overflow)
- return -ENOMEM;
-
- /* size of the areas */
- cxt->struct_size = cxt->p - cxt->p_begin;
- cxt->strings_size = cxt->pstr_begin - cxt->pstr;
-
- /* the offset we must move */
- off = (cxt->pstr_begin - cxt->p_begin) - cxt->strings_size;
-
- /* the new strings start */
- cxt->pstr_begin = cxt->p_begin + cxt->struct_size;
-
- /* move the whole string area */
- memmove(cxt->pstr_begin, cxt->pstr, cxt->strings_size);
- /* now perform the fixup of the strings */
- p = cxt->p_begin;
- while ((tag = be32_to_cpu(*(u32 *) p)) != OF_DT_END) {
- p += 4;
-
- if (tag == OF_DT_BEGIN_NODE) {
- p = (u8 *) _ALIGN((unsigned long)p + strlen(p) + 1, 4);
- continue;
- }
-
- if (tag == OF_DT_END_NODE || tag == OF_DT_NOP)
- continue;
-
- if (tag != OF_DT_PROP)
- return -EINVAL;
-
- sz = be32_to_cpu(*(u32 *) p);
- p += 4;
-
- v = be32_to_cpu(*(u32 *) p);
- v -= off;
- *(u32 *) p = cpu_to_be32(v); /* move down */
- p += 4;
-
- p = (u8 *) _ALIGN((unsigned long)p + sz, 4);
- }
-
- /* fix sizes */
- p = (char *)cxt->bph;
- sz = (cxt->pstr_begin + cxt->strings_size) - p;
- sz1 = _ALIGN(sz, 16); /* align at 16 bytes */
- if (sz != sz1)
- memset(p + sz, 0, sz1 - sz);
- bph->totalsize = cpu_to_be32(sz1);
- bph->off_dt_struct = cpu_to_be32(cxt->p_begin - p);
- bph->off_dt_strings = cpu_to_be32(cxt->pstr_begin - p);
-
- /* the new strings start */
- cxt->pstr_begin = cxt->p_begin + cxt->struct_size;
- cxt->pstr = cxt->pstr_begin + cxt->strings_size;
-
- return 0;
+ bph->totalsize = cxt->p_end - (u8 *)bph;
+ bph->off_dt_struct = cxt->p_start - (u8 *)bph;
+ bph->off_dt_strings = cxt->p - (u8 *)bph;
+ bph->dt_strings_size = cxt->p_end - cxt->p;
}
-/**********************************************************************/
-
static inline int isprint(int c)
{
return c >= 0x20 && c <= 0x7e;
@@ -293,22 +219,24 @@ static void print_data(const void *data, int len)
return;
if (is_printable_string(data, len)) {
- printf(" = \"%s\"", (char *)data);
+ puts(" = \"");
+ puts(data);
+ puts("\"");
return;
}
switch (len) {
case 1: /* byte */
- printf(" = <0x%02x>", (*(u8 *) data) & 0xff);
+ printf(" = <%02x>", (*(u8 *) data) & 0xff);
break;
case 2: /* half-word */
- printf(" = <0x%04x>", be16_to_cpu(*(u16 *) data) & 0xffff);
+ printf(" = <%04x>", be16_to_cpu(*(u16 *) data) & 0xffff);
break;
case 4: /* word */
- printf(" = <0x%08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
+ printf(" = <%x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
break;
case 8: /* double-word */
- printf(" = <0x%16llx>", be64_to_cpu(*(uint64_t *) data));
+ printf(" = <%qx>", be64_to_cpu(*(uint64_t *) data));
break;
default: /* anything else... hexdump */
printf(" = [");
@@ -350,7 +278,7 @@ void ft_dump_blob(const void *bphp)
if (addr == 0 && size == 0)
break;
- printf("/memreserve/ 0x%llx 0x%llx;\n", addr, size);
+ printf("/memreserve/ %qx %qx;\n", addr, size);
}
p = p_struct;
@@ -381,8 +309,8 @@ void ft_dump_blob(const void *bphp)
}
if (tag != OF_DT_PROP) {
- fprintf(stderr, "%*s ** Unknown tag 0x%08x\n",
- depth * shift, "", tag);
+ fprintf(stderr, "%*s ** Unknown tag 0x%08x at 0x%x\n",
+ depth * shift, "", tag, --p);
break;
}
sz = be32_to_cpu(*p++);
@@ -397,64 +325,15 @@ void ft_dump_blob(const void *bphp)
void ft_backtrack_node(struct ft_cxt *cxt)
{
- if (be32_to_cpu(*(u32 *) (cxt->p - 4)) != OF_DT_END_NODE)
- return; /* XXX only for node */
-
- cxt->p -= 4;
-}
-
-/* note that the root node of the blob is "peeled" off */
-void ft_merge_blob(struct ft_cxt *cxt, void *blob)
-{
- struct boot_param_header *bph = (struct boot_param_header *)blob;
- u32 *p_struct = (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_struct));
- u32 *p_strings =
- (u32 *) ((char *)bph + be32_to_cpu(bph->off_dt_strings));
- u32 tag, *p;
- char *s, *t;
- int depth, sz;
-
- if (be32_to_cpu(*(u32 *) (cxt->p - 4)) != OF_DT_END_NODE)
- return; /* XXX only for node */
-
- cxt->p -= 4;
-
- depth = 0;
- p = p_struct;
- while ((tag = be32_to_cpu(*p++)) != OF_DT_END) {
-
- /* printf("tag: 0x%08x (%d) - %d\n", tag, p - p_struct, depth); */
-
- if (tag == OF_DT_BEGIN_NODE) {
- s = (char *)p;
- p = (u32 *) _ALIGN((unsigned long)p + strlen(s) + 1, 4);
-
- if (depth++ > 0)
- ft_begin_node(cxt, s);
-
- continue;
- }
-
- if (tag == OF_DT_END_NODE) {
- ft_end_node(cxt);
- if (--depth == 0)
- break;
- continue;
- }
-
- if (tag == OF_DT_NOP)
- continue;
+ int i = 4;
- if (tag != OF_DT_PROP)
- break;
+ while (be32_to_cpu(*(u32 *) (cxt->p - i)) != OF_DT_END_NODE)
+ i += 4;
- sz = be32_to_cpu(*p++);
- s = (char *)p_strings + be32_to_cpu(*p++);
- t = (char *)p;
- p = (u32 *) _ALIGN((unsigned long)p + sz, 4);
+ memmove (cxt->p - i, cxt->p, cxt->p_end - cxt->p);
- ft_prop(cxt, s, t, sz);
- }
+ cxt->p_end -= i;
+ cxt->p -= i;
}
void *ft_get_prop(void *bphp, const char *propname, int *szp)
@@ -521,9 +400,6 @@ void *ft_get_prop(void *bphp, const char *propname, int *szp)
/********************************************************************/
-extern unsigned char oftree_dtb[];
-extern unsigned int oftree_dtb_len;
-
/* Function that returns a character from the environment */
extern uchar(*env_get_char) (int);
@@ -577,7 +453,7 @@ static const struct {
};
#endif
-void ft_setup(void *blob, int size, bd_t * bd, ulong initrd_start, ulong initrd_end)
+void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end)
{
u32 *p;
int len;
@@ -600,20 +476,16 @@ void ft_setup(void *blob, int size, bd_t * bd, ulong initrd_start, ulong initrd_
return;
}
- ft_begin(&cxt, blob, size);
+#ifdef DEBUG
+ printf ("recieved oftree\n");
+ ft_dump_blob(blob);
+#endif
+
+ ft_init_cxt(&cxt, blob);
if (initrd_start && initrd_end)
ft_add_rsvmap(&cxt, initrd_start, initrd_end - initrd_start + 1);
- ft_begin_tree(&cxt);
-
- ft_begin_node(&cxt, "");
-
- ft_end_node(&cxt);
-
- /* copy RO tree */
- ft_merge_blob(&cxt, oftree_dtb);
-
/* back into root */
ft_backtrack_node(&cxt);
@@ -642,8 +514,8 @@ void ft_setup(void *blob, int size, bd_t * bd, ulong initrd_start, ulong initrd_
#endif
ft_begin_node(&cxt, "chosen");
-
ft_prop_str(&cxt, "name", "chosen");
+
ft_prop_str(&cxt, "bootargs", getenv("bootargs"));
ft_prop_int(&cxt, "linux,platform", 0x600); /* what is this? */
if (initrd_start && initrd_end) {
@@ -659,11 +531,7 @@ void ft_setup(void *blob, int size, bd_t * bd, ulong initrd_start, ulong initrd_
ft_end_node(&cxt); /* end root */
ft_end_tree(&cxt);
-
- /*
- printf("merged OF-tree\n");
- ft_dump_blob(blob);
- */
+ ft_finalize_tree(&cxt);
#ifdef CONFIG_OF_HAS_BD_T
/* paste the bd_t at the end of the flat tree */
@@ -712,11 +580,12 @@ void ft_setup(void *blob, int size, bd_t * bd, ulong initrd_start, ulong initrd_
ft_board_setup(blob, bd);
#endif
- /*
- printf("final OF-tree\n");
- ft_dump_blob(blob);
- */
+ /* in case the size changed in the platform code */
+ ft_finalize_tree(&cxt);
+#ifdef DEBUG
+ printf("final OF-tree\n");
+ ft_dump_blob(blob);
+#endif
}
-
#endif
diff --git a/common/lcd.c b/common/lcd.c
index 0be1912..eaed2ab 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -578,13 +578,16 @@ void bitmap_plot (int x, int y)
*/
int lcd_display_bitmap(ulong bmp_image, int x, int y)
{
+#if !defined(CONFIG_MCC200)
ushort *cmap;
+#endif
ushort i, j;
uchar *fb;
bmp_image_t *bmp=(bmp_image_t *)bmp_image;
uchar *bmap;
ushort padded_line;
unsigned long width, height;
+ unsigned long pwidth = panel_info.vl_col;
unsigned colors,bpix;
unsigned long compression;
#if defined(CONFIG_PXA250)
@@ -623,6 +626,8 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
debug ("Display-bmp: %d x %d with %d colors\n",
(int)width, (int)height, (int)colors);
+#if !defined(CONFIG_MCC200)
+ /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
if (bpix==8) {
#if defined(CONFIG_PXA250)
cmap = (ushort *)fbi->palette;
@@ -651,10 +656,30 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
#endif
}
}
+#endif
+
+ /*
+ * BMP format for Monochrome assumes that the state of a
+ * pixel is described on a per Bit basis, not per Byte.
+ * So, in case of Monochrome BMP we should align widths
+ * on a byte boundary and convert them from Bit to Byte
+ * units.
+ * Probably, PXA250 and MPC823 process 1bpp BMP images in
+ * their own ways, so make the converting to be MCC200
+ * specific.
+ */
+#if defined(CONFIG_MCC200)
+ if (bpix==1)
+ {
+ width = ((width + 7) & ~7) >> 3;
+ x = ((x + 7) & ~7) >> 3;
+ pwidth= ((pwidth + 7) & ~7) >> 3;
+ }
+#endif
padded_line = (width&0x3) ? ((width&~0x3)+4) : (width);
- if ((x + width)>panel_info.vl_col)
- width = panel_info.vl_col - x;
+ if ((x + width)>pwidth)
+ width = pwidth - x;
if ((y + height)>panel_info.vl_row)
height = panel_info.vl_row - y;
@@ -666,7 +691,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
for (j = 0; j < width ; j++)
#if defined(CONFIG_PXA250)
*(fb++)=*(bmap++);
-#elif defined(CONFIG_MPC823)
+#elif defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
*(fb++)=255-*(bmap++);
#endif
bmap += (width - padded_line);
diff --git a/common/main.c b/common/main.c
index 3788bd5..cc4b50f 100644
--- a/common/main.c
+++ b/common/main.c
@@ -95,14 +95,12 @@ static __inline__ int abortboot(int bootdelay)
{
int abort = 0;
uint64_t etime = endtick(bootdelay);
- struct
- {
+ struct {
char* str;
u_int len;
int retry;
}
- delaykey [] =
- {
+ delaykey [] = {
{ str: getenv ("bootdelaykey"), retry: 1 },
{ str: getenv ("bootdelaykey2"), retry: 1 },
{ str: getenv ("bootstopkey"), retry: 0 },
@@ -498,7 +496,7 @@ void main_loop (void)
#ifdef CONFIG_BOOT_RETRY_TIME
/***************************************************************************
- * initialise command line timeout
+ * initialize command line timeout
*/
void init_cmd_timeout(void)
{
@@ -529,23 +527,9 @@ void reset_cmd_timeout(void)
* Author: Janghoon Lyu <nandy@mizi.com>
*/
-#if 1 /* avoid redundand code -- wd */
#define putnstr(str,n) do { \
printf ("%.*s", n, str); \
} while (0)
-#else
-void putnstr(const char *str, size_t n)
-{
- if (str == NULL)
- return;
-
- while (n && *str != '\0') {
- putc(*str);
- str++;
- n--;
- }
-}
-#endif
#define CTL_CH(c) ((c) - 'a' + 1)
@@ -937,6 +921,7 @@ int readline (const char *const prompt)
#ifdef CONFIG_CMDLINE_EDITING
char *p = console_buffer;
unsigned int len=MAX_CMDBUF_SIZE;
+ int rc;
static int initted = 0;
if (!initted) {
@@ -946,8 +931,8 @@ int readline (const char *const prompt)
puts (prompt);
- cread_line(p, &len);
- return len;
+ rc = cread_line(p, &len);
+ return rc < 0 ? rc : len;
#else
char *p = console_buffer;
int n = 0; /* buffer index */
@@ -1137,97 +1122,99 @@ static void process_macros (const char *input, char *output)
{
char c, prev;
const char *varname_start = NULL;
- int inputcnt = strlen (input);
+ int inputcnt = strlen (input);
int outputcnt = CFG_CBSIZE;
- int state = 0; /* 0 = waiting for '$' */
- /* 1 = waiting for '(' or '{' */
- /* 2 = waiting for ')' or '}' */
- /* 3 = waiting for ''' */
+ int state = 0; /* 0 = waiting for '$' */
+
+ /* 1 = waiting for '(' or '{' */
+ /* 2 = waiting for ')' or '}' */
+ /* 3 = waiting for ''' */
#ifdef DEBUG_PARSER
char *output_start = output;
- printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen(input), input);
+ printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen (input),
+ input);
#endif
- prev = '\0'; /* previous character */
+ prev = '\0'; /* previous character */
while (inputcnt && outputcnt) {
- c = *input++;
- inputcnt--;
-
- if (state!=3) {
- /* remove one level of escape characters */
- if ((c == '\\') && (prev != '\\')) {
- if (inputcnt-- == 0)
- break;
- prev = c;
c = *input++;
- }
- }
-
- switch (state) {
- case 0: /* Waiting for (unescaped) $ */
- if ((c == '\'') && (prev != '\\')) {
- state = 3;
- break;
- }
- if ((c == '$') && (prev != '\\')) {
- state++;
- } else {
- *(output++) = c;
- outputcnt--;
+ inputcnt--;
+
+ if (state != 3) {
+ /* remove one level of escape characters */
+ if ((c == '\\') && (prev != '\\')) {
+ if (inputcnt-- == 0)
+ break;
+ prev = c;
+ c = *input++;
+ }
}
- break;
- case 1: /* Waiting for ( */
- if (c == '(' || c == '{') {
- state++;
- varname_start = input;
- } else {
- state = 0;
- *(output++) = '$';
- outputcnt--;
-
- if (outputcnt) {
+
+ switch (state) {
+ case 0: /* Waiting for (unescaped) $ */
+ if ((c == '\'') && (prev != '\\')) {
+ state = 3;
+ break;
+ }
+ if ((c == '$') && (prev != '\\')) {
+ state++;
+ } else {
*(output++) = c;
outputcnt--;
}
- }
- break;
- case 2: /* Waiting for ) */
- if (c == ')' || c == '}') {
- int i;
- char envname[CFG_CBSIZE], *envval;
- int envcnt = input-varname_start-1; /* Varname # of chars */
-
- /* Get the varname */
- for (i = 0; i < envcnt; i++) {
- envname[i] = varname_start[i];
- }
- envname[i] = 0;
-
- /* Get its value */
- envval = getenv (envname);
+ break;
+ case 1: /* Waiting for ( */
+ if (c == '(' || c == '{') {
+ state++;
+ varname_start = input;
+ } else {
+ state = 0;
+ *(output++) = '$';
+ outputcnt--;
- /* Copy into the line if it exists */
- if (envval != NULL)
- while ((*envval) && outputcnt) {
- *(output++) = *(envval++);
+ if (outputcnt) {
+ *(output++) = c;
outputcnt--;
}
- /* Look for another '$' */
- state = 0;
- }
- break;
- case 3: /* Waiting for ' */
- if ((c == '\'') && (prev != '\\')) {
- state = 0;
- } else {
- *(output++) = c;
- outputcnt--;
+ }
+ break;
+ case 2: /* Waiting for ) */
+ if (c == ')' || c == '}') {
+ int i;
+ char envname[CFG_CBSIZE], *envval;
+ int envcnt = input - varname_start - 1; /* Varname # of chars */
+
+ /* Get the varname */
+ for (i = 0; i < envcnt; i++) {
+ envname[i] = varname_start[i];
+ }
+ envname[i] = 0;
+
+ /* Get its value */
+ envval = getenv (envname);
+
+ /* Copy into the line if it exists */
+ if (envval != NULL)
+ while ((*envval) && outputcnt) {
+ *(output++) = *(envval++);
+ outputcnt--;
+ }
+ /* Look for another '$' */
+ state = 0;
+ }
+ break;
+ case 3: /* Waiting for ' */
+ if ((c == '\'') && (prev != '\\')) {
+ state = 0;
+ } else {
+ *(output++) = c;
+ outputcnt--;
+ }
+ break;
}
- break;
- }
- prev = c;
+ prev = c;
}
if (outputcnt)
@@ -1235,7 +1222,7 @@ static void process_macros (const char *input, char *output)
#ifdef DEBUG_PARSER
printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n",
- strlen(output_start), output_start);
+ strlen (output_start), output_start);
#endif
}
diff --git a/common/memsize.c b/common/memsize.c
index dbc812d..6c275c9 100644
--- a/common/memsize.c
+++ b/common/memsize.c
@@ -21,6 +21,16 @@
* MA 02111-1307 USA
*/
+#include <config.h>
+#ifdef __PPC__
+/*
+ * At least on G2 PowerPC cores, sequential accesses to non-existent
+ * memory must be synchronized.
+ */
+# include <asm/io.h> /* for sync() */
+#else
+# define sync() /* nothing */
+#endif
/*
* Check memory range for valid RAM. A simple memory test determines
@@ -38,20 +48,27 @@ long get_ram_size(volatile long *base, long maxsize)
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
addr = base + cnt; /* pointer arith! */
+ sync ();
save[i++] = *addr;
+ sync ();
*addr = ~cnt;
}
addr = base;
+ sync ();
save[i] = *addr;
+ sync ();
*addr = 0;
+ sync ();
if ((val = *addr) != 0) {
/* Restore the original data before leaving the function.
*/
+ sync ();
*addr = save[i];
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
addr = base + cnt;
+ sync ();
*addr = save[--i];
}
return (0);
diff --git a/common/miiphybb.c b/common/miiphybb.c
index adb697c..537c15d 100644
--- a/common/miiphybb.c
+++ b/common/miiphybb.c
@@ -41,7 +41,7 @@
static void miiphy_pre (char read, unsigned char addr, unsigned char reg)
{
int j; /* counter */
-#ifndef CONFIG_EP8248
+#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
#endif
@@ -126,7 +126,7 @@ int bb_miiphy_read (char *devname, unsigned char addr,
{
short rdreg; /* register working value */
int j; /* counter */
-#ifndef CONFIG_EP8248
+#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
#endif
@@ -193,7 +193,7 @@ int bb_miiphy_write (char *devname, unsigned char addr,
unsigned char reg, unsigned short value)
{
int j; /* counter */
-#ifndef CONFIG_EP8248
+#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
#endif
diff --git a/common/serial.c b/common/serial.c
index 38057d2..605d4e3 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -42,7 +42,19 @@ struct serial_device *default_serial_console (void)
return &serial_scc_device;
#elif defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_440) \
|| defined(CONFIG_405EP) || defined(CONFIG_MPC5xxx)
-#if defined(CONFIG_UART1_CONSOLE)
+#if defined(CONFIG_CONS_INDEX) && defined(CFG_NS16550_SERIAL)
+#if (CONFIG_CONS_INDEX==1)
+ return &eserial1_device;
+#elif (CONFIG_CONS_INDEX==2)
+ return &eserial2_device;
+#elif (CONFIG_CONS_INDEX==3)
+ return &eserial3_device;
+#elif (CONFIG_CONS_INDEX==4)
+ return &eserial4_device;
+#else
+#error "Bad CONFIG_CONS_INDEX."
+#endif
+#elif defined(CONFIG_UART1_CONSOLE)
return &serial1_device;
#else
return &serial0_device;
@@ -84,6 +96,20 @@ void serial_initialize (void)
serial_register(&serial1_device);
#endif
+#if defined(CFG_NS16550_SERIAL)
+#if defined(CFG_NS16550_COM1)
+ serial_register(&eserial1_device);
+#endif
+#if defined(CFG_NS16550_COM2)
+ serial_register(&eserial2_device);
+#endif
+#if defined(CFG_NS16550_COM3)
+ serial_register(&eserial3_device);
+#endif
+#if defined(CFG_NS16550_COM4)
+ serial_register(&eserial4_device);
+#endif
+#endif /* CFG_NS16550_SERIAL */
serial_assign (default_serial_console ()->name);
}
diff --git a/common/usb_storage.c b/common/usb_storage.c
index e64470c..06ea99b 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -916,6 +916,28 @@ static int usb_read_10(ccb *srb,struct us_data *ss, unsigned long start, unsigne
}
+#ifdef CONFIG_USB_BIN_FIXUP
+/*
+ * Some USB storage devices queried for SCSI identification data respond with
+ * binary strings, which if output to the console freeze the terminal. The
+ * workaround is to modify the vendor and product strings read from such
+ * device with proper values (as reported by 'usb info').
+ *
+ * Vendor and product length limits are taken from the definition of
+ * block_dev_desc_t in include/part.h.
+ */
+static void usb_bin_fixup(struct usb_device_descriptor descriptor,
+ unsigned char vendor[],
+ unsigned char product[]) {
+ const unsigned char max_vendor_len = 40;
+ const unsigned char max_product_len = 20;
+ if (descriptor.idVendor == 0x0424 && descriptor.idProduct == 0x223a) {
+ strncpy ((char *)vendor, "SMSC", max_vendor_len);
+ strncpy ((char *)product, "Flash Media Cntrller", max_product_len);
+ }
+}
+#endif /* CONFIG_USB_BIN_FIXUP */
+
#define USB_MAX_READ_BLK 20
unsigned long usb_stor_read(int device, unsigned long blknr, unsigned long blkcnt, unsigned long *buffer)
@@ -1171,6 +1193,9 @@ int usb_stor_get_info(struct usb_device *dev,struct us_data *ss,block_dev_desc_t
dev_desc->vendor[8] = 0;
dev_desc->product[16] = 0;
dev_desc->revision[4] = 0;
+#ifdef CONFIG_USB_BIN_FIXUP
+ usb_bin_fixup(dev->descriptor, dev_desc->vendor, dev_desc->product);
+#endif /* CONFIG_USB_BIN_FIXUP */
USB_STOR_PRINTF("ISO Vers %X, Response Data %X\n",usb_stor_buf[2],usb_stor_buf[3]);
if(usb_test_unit_ready(pccb,ss)) {
printf("Device NOT ready\n Request Sense returned %02X %02X %02X\n",pccb->sense_buf[2],pccb->sense_buf[12],pccb->sense_buf[13]);
diff --git a/common/xyzModem.c b/common/xyzModem.c
index d1d66e8..a209dfa 100644
--- a/common/xyzModem.c
+++ b/common/xyzModem.c
@@ -69,135 +69,157 @@
#define BSP 0x08
#define NAK 0x15
#define CAN 0x18
-#define EOF 0x1A /* ^Z for DOS officionados */
+#define EOF 0x1A /* ^Z for DOS officionados */
#define USE_YMODEM_LENGTH
/* Data & state local to the protocol */
-static struct {
+static struct
+{
#ifdef REDBOOT
- hal_virtual_comm_table_t* __chan;
+ hal_virtual_comm_table_t *__chan;
#else
- int *__chan;
+ int *__chan;
#endif
- unsigned char pkt[1024], *bufp;
- unsigned char blk,cblk,crc1,crc2;
- unsigned char next_blk; /* Expected block */
- int len, mode, total_retries;
- int total_SOH, total_STX, total_CAN;
- bool crc_mode, at_eof, tx_ack;
+ unsigned char pkt[1024], *bufp;
+ unsigned char blk, cblk, crc1, crc2;
+ unsigned char next_blk; /* Expected block */
+ int len, mode, total_retries;
+ int total_SOH, total_STX, total_CAN;
+ bool crc_mode, at_eof, tx_ack;
#ifdef USE_YMODEM_LENGTH
- unsigned long file_length, read_length;
+ unsigned long file_length, read_length;
#endif
} xyz;
-#define xyzModem_CHAR_TIMEOUT 2000 /* 2 seconds */
+#define xyzModem_CHAR_TIMEOUT 2000 /* 2 seconds */
#define xyzModem_MAX_RETRIES 20
#define xyzModem_MAX_RETRIES_WITH_CRC 10
-#define xyzModem_CAN_COUNT 3 /* Wait for 3 CAN before quitting */
+#define xyzModem_CAN_COUNT 3 /* Wait for 3 CAN before quitting */
-#ifndef REDBOOT /*SB */
+#ifndef REDBOOT /*SB */
typedef int cyg_int32;
-int CYGACC_COMM_IF_GETC_TIMEOUT (char chan,char *c) {
+int
+CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c)
+{
#define DELAY 20
- unsigned long counter=0;
- while (!tstc() && (counter < xyzModem_CHAR_TIMEOUT*1000/DELAY)) {
- udelay(DELAY);
- counter++;
- }
- if (tstc()) {
- *c=getc();
- return 1;
- }
- return 0;
+ unsigned long counter = 0;
+ while (!tstc () && (counter < xyzModem_CHAR_TIMEOUT * 1000 / DELAY))
+ {
+ udelay (DELAY);
+ counter++;
+ }
+ if (tstc ())
+ {
+ *c = getc ();
+ return 1;
+ }
+ return 0;
}
-void CYGACC_COMM_IF_PUTC(char x,char y) {
- putc(y);
+void
+CYGACC_COMM_IF_PUTC (char x, char y)
+{
+ putc (y);
}
/* Validate a hex character */
__inline__ static bool
-_is_hex(char c)
+_is_hex (char c)
{
- return (((c >= '0') && (c <= '9')) ||
- ((c >= 'A') && (c <= 'F')) ||
- ((c >= 'a') && (c <= 'f')));
+ return (((c >= '0') && (c <= '9')) ||
+ ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f')));
}
/* Convert a single hex nibble */
__inline__ static int
-_from_hex(char c)
+_from_hex (char c)
{
- int ret = 0;
-
- if ((c >= '0') && (c <= '9')) {
- ret = (c - '0');
- } else if ((c >= 'a') && (c <= 'f')) {
- ret = (c - 'a' + 0x0a);
- } else if ((c >= 'A') && (c <= 'F')) {
- ret = (c - 'A' + 0x0A);
+ int ret = 0;
+
+ if ((c >= '0') && (c <= '9'))
+ {
+ ret = (c - '0');
+ }
+ else if ((c >= 'a') && (c <= 'f'))
+ {
+ ret = (c - 'a' + 0x0a);
}
- return ret;
+ else if ((c >= 'A') && (c <= 'F'))
+ {
+ ret = (c - 'A' + 0x0A);
+ }
+ return ret;
}
/* Convert a character to lower case */
__inline__ static char
-_tolower(char c)
+_tolower (char c)
{
- if ((c >= 'A') && (c <= 'Z')) {
- c = (c - 'A') + 'a';
+ if ((c >= 'A') && (c <= 'Z'))
+ {
+ c = (c - 'A') + 'a';
}
- return c;
+ return c;
}
/* Parse (scan) a number */
bool
-parse_num(char *s, unsigned long *val, char **es, char *delim)
+parse_num (char *s, unsigned long *val, char **es, char *delim)
{
- bool first = true;
- int radix = 10;
- char c;
- unsigned long result = 0;
- int digit;
-
- while (*s == ' ') s++;
- while (*s) {
- if (first && (s[0] == '0') && (_tolower(s[1]) == 'x')) {
- radix = 16;
- s += 2;
- }
- first = false;
- c = *s++;
- if (_is_hex(c) && ((digit = _from_hex(c)) < radix)) {
- /* Valid digit */
+ bool first = true;
+ int radix = 10;
+ char c;
+ unsigned long result = 0;
+ int digit;
+
+ while (*s == ' ')
+ s++;
+ while (*s)
+ {
+ if (first && (s[0] == '0') && (_tolower (s[1]) == 'x'))
+ {
+ radix = 16;
+ s += 2;
+ }
+ first = false;
+ c = *s++;
+ if (_is_hex (c) && ((digit = _from_hex (c)) < radix))
+ {
+ /* Valid digit */
#ifdef CYGPKG_HAL_MIPS
- /* FIXME: tx49 compiler generates 0x2539018 for MUL which */
- /* isn't any good. */
- if (16 == radix)
- result = result << 4;
- else
- result = 10 * result;
- result += digit;
+ /* FIXME: tx49 compiler generates 0x2539018 for MUL which */
+ /* isn't any good. */
+ if (16 == radix)
+ result = result << 4;
+ else
+ result = 10 * result;
+ result += digit;
#else
- result = (result * radix) + digit;
+ result = (result * radix) + digit;
#endif
- } else {
- if (delim != (char *)0) {
- /* See if this character is one of the delimiters */
- char *dp = delim;
- while (*dp && (c != *dp)) dp++;
- if (*dp) break; /* Found a good delimiter */
- }
- return false; /* Malformatted number */
- }
+ }
+ else
+ {
+ if (delim != (char *) 0)
+ {
+ /* See if this character is one of the delimiters */
+ char *dp = delim;
+ while (*dp && (c != *dp))
+ dp++;
+ if (*dp)
+ break; /* Found a good delimiter */
+ }
+ return false; /* Malformatted number */
+ }
}
- *val = result;
- if (es != (char **)0) {
- *es = s;
+ *val = result;
+ if (es != (char **) 0)
+ {
+ *es = s;
}
- return true;
+ return true;
}
#endif
@@ -211,24 +233,26 @@ parse_num(char *s, unsigned long *val, char **es, char *delim)
* messages.
*/
static int
-zm_dprintf(char *fmt, ...)
+zm_dprintf (char *fmt, ...)
{
- int cur_console;
- va_list args;
+ int cur_console;
+ va_list args;
- va_start(args, fmt);
+ va_start (args, fmt);
#ifdef REDBOOT
- cur_console = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
- CYGACC_CALL_IF_SET_CONSOLE_COMM(1);
+ cur_console =
+ CYGACC_CALL_IF_SET_CONSOLE_COMM
+ (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+ CYGACC_CALL_IF_SET_CONSOLE_COMM (1);
#endif
- diag_vprintf(fmt, args);
+ diag_vprintf (fmt, args);
#ifdef REDBOOT
- CYGACC_CALL_IF_SET_CONSOLE_COMM(cur_console);
+ CYGACC_CALL_IF_SET_CONSOLE_COMM (cur_console);
#endif
}
static void
-zm_flush(void)
+zm_flush (void)
{
}
@@ -238,42 +262,43 @@ zm_flush(void)
*/
#define FINAL
#ifdef FINAL
-static char *zm_out = (char *)0x00380000;
-static char *zm_out_start = (char *)0x00380000;
+static char *zm_out = (char *) 0x00380000;
+static char *zm_out_start = (char *) 0x00380000;
#else
static char zm_buf[8192];
-static char *zm_out=zm_buf;
+static char *zm_out = zm_buf;
static char *zm_out_start = zm_buf;
#endif
static int
-zm_dprintf(char *fmt, ...)
+zm_dprintf (char *fmt, ...)
{
- int len;
- va_list args;
+ int len;
+ va_list args;
- va_start(args, fmt);
- len = diag_vsprintf(zm_out, fmt, args);
- zm_out += len;
- return len;
+ va_start (args, fmt);
+ len = diag_vsprintf (zm_out, fmt, args);
+ zm_out += len;
+ return len;
}
static void
-zm_flush(void)
+zm_flush (void)
{
#ifdef REDBOOT
- char *p = zm_out_start;
- while (*p) mon_write_char(*p++);
+ char *p = zm_out_start;
+ while (*p)
+ mon_write_char (*p++);
#endif
- zm_out = zm_out_start;
+ zm_out = zm_out_start;
}
#endif
static void
-zm_dump_buf(void *buf, int len)
+zm_dump_buf (void *buf, int len)
{
#ifdef REDBOOT
- diag_vdump_buf_with_offset(zm_dprintf, buf, len, 0);
+ diag_vdump_buf_with_offset (zm_dprintf, buf, len, 0);
#else
#endif
@@ -283,22 +308,22 @@ static unsigned char zm_buf[2048];
static unsigned char *zm_bp;
static void
-zm_new(void)
+zm_new (void)
{
- zm_bp = zm_buf;
+ zm_bp = zm_buf;
}
static void
-zm_save(unsigned char c)
+zm_save (unsigned char c)
{
- *zm_bp++ = c;
+ *zm_bp++ = c;
}
static void
-zm_dump(int line)
+zm_dump (int line)
{
- zm_dprintf("Packet at line: %d\n", line);
- zm_dump_buf(zm_buf, zm_bp-zm_buf);
+ zm_dprintf ("Packet at line: %d\n", line);
+ zm_dump_buf (zm_buf, zm_bp - zm_buf);
}
#define ZM_DEBUG(x) x
@@ -308,439 +333,517 @@ zm_dump(int line)
/* Wait for the line to go idle */
static void
-xyzModem_flush(void)
+xyzModem_flush (void)
{
- int res;
- char c;
- while (true) {
- res = CYGACC_COMM_IF_GETC_TIMEOUT(*xyz.__chan, &c);
- if (!res) return;
+ int res;
+ char c;
+ while (true)
+ {
+ res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c);
+ if (!res)
+ return;
}
}
static int
-xyzModem_get_hdr(void)
+xyzModem_get_hdr (void)
{
- char c;
- int res;
- bool hdr_found = false;
- int i, can_total, hdr_chars;
- unsigned short cksum;
-
- ZM_DEBUG(zm_new());
- /* Find the start of a header */
- can_total = 0;
- hdr_chars = 0;
-
- if (xyz.tx_ack) {
- CYGACC_COMM_IF_PUTC(*xyz.__chan, ACK);
- xyz.tx_ack = false;
+ char c;
+ int res;
+ bool hdr_found = false;
+ int i, can_total, hdr_chars;
+ unsigned short cksum;
+
+ ZM_DEBUG (zm_new ());
+ /* Find the start of a header */
+ can_total = 0;
+ hdr_chars = 0;
+
+ if (xyz.tx_ack)
+ {
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
+ xyz.tx_ack = false;
}
- while (!hdr_found) {
- res = CYGACC_COMM_IF_GETC_TIMEOUT(*xyz.__chan, &c);
- ZM_DEBUG(zm_save(c));
- if (res) {
- hdr_chars++;
- switch (c) {
- case SOH:
- xyz.total_SOH++;
- case STX:
- if (c == STX) xyz.total_STX++;
- hdr_found = true;
- break;
- case CAN:
- xyz.total_CAN++;
- ZM_DEBUG(zm_dump(__LINE__));
- if (++can_total == xyzModem_CAN_COUNT) {
- return xyzModem_cancel;
- } else {
- /* Wait for multiple CAN to avoid early quits */
- break;
- }
- case EOT:
- /* EOT only supported if no noise */
- if (hdr_chars == 1) {
- CYGACC_COMM_IF_PUTC(*xyz.__chan, ACK);
- ZM_DEBUG(zm_dprintf("ACK on EOT #%d\n", __LINE__));
- ZM_DEBUG(zm_dump(__LINE__));
- return xyzModem_eof;
- }
- default:
- /* Ignore, waiting for start of header */
- ;
- }
- } else {
- /* Data stream timed out */
- xyzModem_flush(); /* Toss any current input */
- ZM_DEBUG(zm_dump(__LINE__));
- CYGACC_CALL_IF_DELAY_US((cyg_int32)250000);
- return xyzModem_timeout;
- }
+ while (!hdr_found)
+ {
+ res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c);
+ ZM_DEBUG (zm_save (c));
+ if (res)
+ {
+ hdr_chars++;
+ switch (c)
+ {
+ case SOH:
+ xyz.total_SOH++;
+ case STX:
+ if (c == STX)
+ xyz.total_STX++;
+ hdr_found = true;
+ break;
+ case CAN:
+ xyz.total_CAN++;
+ ZM_DEBUG (zm_dump (__LINE__));
+ if (++can_total == xyzModem_CAN_COUNT)
+ {
+ return xyzModem_cancel;
+ }
+ else
+ {
+ /* Wait for multiple CAN to avoid early quits */
+ break;
+ }
+ case EOT:
+ /* EOT only supported if no noise */
+ if (hdr_chars == 1)
+ {
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
+ ZM_DEBUG (zm_dprintf ("ACK on EOT #%d\n", __LINE__));
+ ZM_DEBUG (zm_dump (__LINE__));
+ return xyzModem_eof;
+ }
+ default:
+ /* Ignore, waiting for start of header */
+ ;
+ }
+ }
+ else
+ {
+ /* Data stream timed out */
+ xyzModem_flush (); /* Toss any current input */
+ ZM_DEBUG (zm_dump (__LINE__));
+ CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000);
+ return xyzModem_timeout;
+ }
}
- /* Header found, now read the data */
- res = CYGACC_COMM_IF_GETC_TIMEOUT(*xyz.__chan, (char *)&xyz.blk);
- ZM_DEBUG(zm_save(xyz.blk));
- if (!res) {
- ZM_DEBUG(zm_dump(__LINE__));
- return xyzModem_timeout;
+ /* Header found, now read the data */
+ res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.blk);
+ ZM_DEBUG (zm_save (xyz.blk));
+ if (!res)
+ {
+ ZM_DEBUG (zm_dump (__LINE__));
+ return xyzModem_timeout;
}
- res = CYGACC_COMM_IF_GETC_TIMEOUT(*xyz.__chan, (char *)&xyz.cblk);
- ZM_DEBUG(zm_save(xyz.cblk));
- if (!res) {
- ZM_DEBUG(zm_dump(__LINE__));
- return xyzModem_timeout;
+ res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.cblk);
+ ZM_DEBUG (zm_save (xyz.cblk));
+ if (!res)
+ {
+ ZM_DEBUG (zm_dump (__LINE__));
+ return xyzModem_timeout;
}
- xyz.len = (c == SOH) ? 128 : 1024;
- xyz.bufp = xyz.pkt;
- for (i = 0; i < xyz.len; i++) {
- res = CYGACC_COMM_IF_GETC_TIMEOUT(*xyz.__chan, &c);
- ZM_DEBUG(zm_save(c));
- if (res) {
- xyz.pkt[i] = c;
- } else {
- ZM_DEBUG(zm_dump(__LINE__));
- return xyzModem_timeout;
- }
+ xyz.len = (c == SOH) ? 128 : 1024;
+ xyz.bufp = xyz.pkt;
+ for (i = 0; i < xyz.len; i++)
+ {
+ res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c);
+ ZM_DEBUG (zm_save (c));
+ if (res)
+ {
+ xyz.pkt[i] = c;
+ }
+ else
+ {
+ ZM_DEBUG (zm_dump (__LINE__));
+ return xyzModem_timeout;
+ }
}
- res = CYGACC_COMM_IF_GETC_TIMEOUT(*xyz.__chan, (char *)&xyz.crc1);
- ZM_DEBUG(zm_save(xyz.crc1));
- if (!res) {
- ZM_DEBUG(zm_dump(__LINE__));
- return xyzModem_timeout;
+ res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc1);
+ ZM_DEBUG (zm_save (xyz.crc1));
+ if (!res)
+ {
+ ZM_DEBUG (zm_dump (__LINE__));
+ return xyzModem_timeout;
}
- if (xyz.crc_mode) {
- res = CYGACC_COMM_IF_GETC_TIMEOUT(*xyz.__chan, (char *)&xyz.crc2);
- ZM_DEBUG(zm_save(xyz.crc2));
- if (!res) {
- ZM_DEBUG(zm_dump(__LINE__));
- return xyzModem_timeout;
- }
+ if (xyz.crc_mode)
+ {
+ res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc2);
+ ZM_DEBUG (zm_save (xyz.crc2));
+ if (!res)
+ {
+ ZM_DEBUG (zm_dump (__LINE__));
+ return xyzModem_timeout;
+ }
}
- ZM_DEBUG(zm_dump(__LINE__));
- /* Validate the message */
- if ((xyz.blk ^ xyz.cblk) != (unsigned char)0xFF) {
- ZM_DEBUG(zm_dprintf("Framing error - blk: %x/%x/%x\n", xyz.blk, xyz.cblk, (xyz.blk ^ xyz.cblk)));
- ZM_DEBUG(zm_dump_buf(xyz.pkt, xyz.len));
- xyzModem_flush();
- return xyzModem_frame;
+ ZM_DEBUG (zm_dump (__LINE__));
+ /* Validate the message */
+ if ((xyz.blk ^ xyz.cblk) != (unsigned char) 0xFF)
+ {
+ ZM_DEBUG (zm_dprintf
+ ("Framing error - blk: %x/%x/%x\n", xyz.blk, xyz.cblk,
+ (xyz.blk ^ xyz.cblk)));
+ ZM_DEBUG (zm_dump_buf (xyz.pkt, xyz.len));
+ xyzModem_flush ();
+ return xyzModem_frame;
}
- /* Verify checksum/CRC */
- if (xyz.crc_mode) {
- cksum = cyg_crc16(xyz.pkt, xyz.len);
- if (cksum != ((xyz.crc1 << 8) | xyz.crc2)) {
- ZM_DEBUG(zm_dprintf("CRC error - recvd: %02x%02x, computed: %x\n",
- xyz.crc1, xyz.crc2, cksum & 0xFFFF));
- return xyzModem_cksum;
- }
- } else {
- cksum = 0;
- for (i = 0; i < xyz.len; i++) {
- cksum += xyz.pkt[i];
- }
- if (xyz.crc1 != (cksum & 0xFF)) {
- ZM_DEBUG(zm_dprintf("Checksum error - recvd: %x, computed: %x\n", xyz.crc1, cksum & 0xFF));
- return xyzModem_cksum;
- }
+ /* Verify checksum/CRC */
+ if (xyz.crc_mode)
+ {
+ cksum = cyg_crc16 (xyz.pkt, xyz.len);
+ if (cksum != ((xyz.crc1 << 8) | xyz.crc2))
+ {
+ ZM_DEBUG (zm_dprintf ("CRC error - recvd: %02x%02x, computed: %x\n",
+ xyz.crc1, xyz.crc2, cksum & 0xFFFF));
+ return xyzModem_cksum;
+ }
}
- /* If we get here, the message passes [structural] muster */
- return 0;
+ else
+ {
+ cksum = 0;
+ for (i = 0; i < xyz.len; i++)
+ {
+ cksum += xyz.pkt[i];
+ }
+ if (xyz.crc1 != (cksum & 0xFF))
+ {
+ ZM_DEBUG (zm_dprintf
+ ("Checksum error - recvd: %x, computed: %x\n", xyz.crc1,
+ cksum & 0xFF));
+ return xyzModem_cksum;
+ }
+ }
+ /* If we get here, the message passes [structural] muster */
+ return 0;
}
int
-xyzModem_stream_open(connection_info_t *info, int *err)
+xyzModem_stream_open (connection_info_t * info, int *err)
{
#ifdef REDBOOT
- int console_chan;
+ int console_chan;
#endif
- int stat = 0;
- int retries = xyzModem_MAX_RETRIES;
- int crc_retries = xyzModem_MAX_RETRIES_WITH_CRC;
+ int stat = 0;
+ int retries = xyzModem_MAX_RETRIES;
+ int crc_retries = xyzModem_MAX_RETRIES_WITH_CRC;
/* ZM_DEBUG(zm_out = zm_out_start); */
#ifdef xyzModem_zmodem
- if (info->mode == xyzModem_zmodem) {
- *err = xyzModem_noZmodem;
- return -1;
+ if (info->mode == xyzModem_zmodem)
+ {
+ *err = xyzModem_noZmodem;
+ return -1;
}
#endif
#ifdef REDBOOT
- /* Set up the I/O channel. Note: this allows for using a different port in the future */
- console_chan = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
- if (info->chan >= 0) {
- CYGACC_CALL_IF_SET_CONSOLE_COMM(info->chan);
- } else {
- CYGACC_CALL_IF_SET_CONSOLE_COMM(console_chan);
+ /* Set up the I/O channel. Note: this allows for using a different port in the future */
+ console_chan =
+ CYGACC_CALL_IF_SET_CONSOLE_COMM
+ (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+ if (info->chan >= 0)
+ {
+ CYGACC_CALL_IF_SET_CONSOLE_COMM (info->chan);
}
- xyz.__chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+ else
+ {
+ CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan);
+ }
+ xyz.__chan = CYGACC_CALL_IF_CONSOLE_PROCS ();
- CYGACC_CALL_IF_SET_CONSOLE_COMM(console_chan);
- CYGACC_COMM_IF_CONTROL(*xyz.__chan, __COMMCTL_SET_TIMEOUT, xyzModem_CHAR_TIMEOUT);
+ CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan);
+ CYGACC_COMM_IF_CONTROL (*xyz.__chan, __COMMCTL_SET_TIMEOUT,
+ xyzModem_CHAR_TIMEOUT);
#else
/* TODO: CHECK ! */
- int dummy;
- xyz.__chan=&dummy;
+ int dummy;
+ xyz.__chan = &dummy;
#endif
- xyz.len = 0;
- xyz.crc_mode = true;
- xyz.at_eof = false;
- xyz.tx_ack = false;
- xyz.mode = info->mode;
- xyz.total_retries = 0;
- xyz.total_SOH = 0;
- xyz.total_STX = 0;
- xyz.total_CAN = 0;
+ xyz.len = 0;
+ xyz.crc_mode = true;
+ xyz.at_eof = false;
+ xyz.tx_ack = false;
+ xyz.mode = info->mode;
+ xyz.total_retries = 0;
+ xyz.total_SOH = 0;
+ xyz.total_STX = 0;
+ xyz.total_CAN = 0;
#ifdef USE_YMODEM_LENGTH
- xyz.read_length = 0;
- xyz.file_length = 0;
+ xyz.read_length = 0;
+ xyz.file_length = 0;
#endif
- CYGACC_COMM_IF_PUTC(*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
- if (xyz.mode == xyzModem_xmodem) {
- /* X-modem doesn't have an information header - exit here */
- xyz.next_blk = 1;
- return 0;
+ if (xyz.mode == xyzModem_xmodem)
+ {
+ /* X-modem doesn't have an information header - exit here */
+ xyz.next_blk = 1;
+ return 0;
}
- while (retries-- > 0) {
- stat = xyzModem_get_hdr();
- if (stat == 0) {
- /* Y-modem file information header */
- if (xyz.blk == 0) {
+ while (retries-- > 0)
+ {
+ stat = xyzModem_get_hdr ();
+ if (stat == 0)
+ {
+ /* Y-modem file information header */
+ if (xyz.blk == 0)
+ {
#ifdef USE_YMODEM_LENGTH
- /* skip filename */
- while (*xyz.bufp++);
- /* get the length */
- parse_num((char *)xyz.bufp, &xyz.file_length, NULL, " ");
+ /* skip filename */
+ while (*xyz.bufp++);
+ /* get the length */
+ parse_num ((char *) xyz.bufp, &xyz.file_length, NULL, " ");
#endif
- /* The rest of the file name data block quietly discarded */
- xyz.tx_ack = true;
- }
- xyz.next_blk = 1;
- xyz.len = 0;
- return 0;
- } else
- if (stat == xyzModem_timeout) {
- if (--crc_retries <= 0) xyz.crc_mode = false;
- CYGACC_CALL_IF_DELAY_US(5*100000); /* Extra delay for startup */
- CYGACC_COMM_IF_PUTC(*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
- xyz.total_retries++;
- ZM_DEBUG(zm_dprintf("NAK (%d)\n", __LINE__));
- }
- if (stat == xyzModem_cancel) {
- break;
- }
+ /* The rest of the file name data block quietly discarded */
+ xyz.tx_ack = true;
+ }
+ xyz.next_blk = 1;
+ xyz.len = 0;
+ return 0;
+ }
+ else if (stat == xyzModem_timeout)
+ {
+ if (--crc_retries <= 0)
+ xyz.crc_mode = false;
+ CYGACC_CALL_IF_DELAY_US (5 * 100000); /* Extra delay for startup */
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
+ xyz.total_retries++;
+ ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__));
+ }
+ if (stat == xyzModem_cancel)
+ {
+ break;
+ }
}
- *err = stat;
- ZM_DEBUG(zm_flush());
- return -1;
+ *err = stat;
+ ZM_DEBUG (zm_flush ());
+ return -1;
}
int
-xyzModem_stream_read(char *buf, int size, int *err)
+xyzModem_stream_read (char *buf, int size, int *err)
{
- int stat, total, len;
- int retries;
-
- total = 0;
- stat = xyzModem_cancel;
- /* Try and get 'size' bytes into the buffer */
- while (!xyz.at_eof && (size > 0)) {
- if (xyz.len == 0) {
- retries = xyzModem_MAX_RETRIES;
- while (retries-- > 0) {
- stat = xyzModem_get_hdr();
- if (stat == 0) {
- if (xyz.blk == xyz.next_blk) {
- xyz.tx_ack = true;
- ZM_DEBUG(zm_dprintf("ACK block %d (%d)\n", xyz.blk, __LINE__));
- xyz.next_blk = (xyz.next_blk + 1) & 0xFF;
+ int stat, total, len;
+ int retries;
+
+ total = 0;
+ stat = xyzModem_cancel;
+ /* Try and get 'size' bytes into the buffer */
+ while (!xyz.at_eof && (size > 0))
+ {
+ if (xyz.len == 0)
+ {
+ retries = xyzModem_MAX_RETRIES;
+ while (retries-- > 0)
+ {
+ stat = xyzModem_get_hdr ();
+ if (stat == 0)
+ {
+ if (xyz.blk == xyz.next_blk)
+ {
+ xyz.tx_ack = true;
+ ZM_DEBUG (zm_dprintf
+ ("ACK block %d (%d)\n", xyz.blk, __LINE__));
+ xyz.next_blk = (xyz.next_blk + 1) & 0xFF;
#if defined(xyzModem_zmodem) || defined(USE_YMODEM_LENGTH)
- if (xyz.mode == xyzModem_xmodem || xyz.file_length == 0) {
+ if (xyz.mode == xyzModem_xmodem || xyz.file_length == 0)
+ {
#else
- if (1) {
+ if (1)
+ {
#endif
- /* Data blocks can be padded with ^Z (EOF) characters */
- /* This code tries to detect and remove them */
- if ((xyz.bufp[xyz.len-1] == EOF) &&
- (xyz.bufp[xyz.len-2] == EOF) &&
- (xyz.bufp[xyz.len-3] == EOF)) {
- while (xyz.len && (xyz.bufp[xyz.len-1] == EOF)) {
- xyz.len--;
- }
- }
- }
+ /* Data blocks can be padded with ^Z (EOF) characters */
+ /* This code tries to detect and remove them */
+ if ((xyz.bufp[xyz.len - 1] == EOF) &&
+ (xyz.bufp[xyz.len - 2] == EOF) &&
+ (xyz.bufp[xyz.len - 3] == EOF))
+ {
+ while (xyz.len
+ && (xyz.bufp[xyz.len - 1] == EOF))
+ {
+ xyz.len--;
+ }
+ }
+ }
#ifdef USE_YMODEM_LENGTH
- /*
- * See if accumulated length exceeds that of the file.
- * If so, reduce size (i.e., cut out pad bytes)
- * Only do this for Y-modem (and Z-modem should it ever
- * be supported since it can fall back to Y-modem mode).
- */
- if (xyz.mode != xyzModem_xmodem && 0 != xyz.file_length) {
- xyz.read_length += xyz.len;
- if (xyz.read_length > xyz.file_length) {
- xyz.len -= (xyz.read_length - xyz.file_length);
- }
- }
+ /*
+ * See if accumulated length exceeds that of the file.
+ * If so, reduce size (i.e., cut out pad bytes)
+ * Only do this for Y-modem (and Z-modem should it ever
+ * be supported since it can fall back to Y-modem mode).
+ */
+ if (xyz.mode != xyzModem_xmodem && 0 != xyz.file_length)
+ {
+ xyz.read_length += xyz.len;
+ if (xyz.read_length > xyz.file_length)
+ {
+ xyz.len -= (xyz.read_length - xyz.file_length);
+ }
+ }
#endif
- break;
- } else if (xyz.blk == ((xyz.next_blk - 1) & 0xFF)) {
- /* Just re-ACK this so sender will get on with it */
- CYGACC_COMM_IF_PUTC(*xyz.__chan, ACK);
- continue; /* Need new header */
- } else {
- stat = xyzModem_sequence;
- }
- }
- if (stat == xyzModem_cancel) {
- break;
- }
- if (stat == xyzModem_eof) {
- CYGACC_COMM_IF_PUTC(*xyz.__chan, ACK);
- ZM_DEBUG(zm_dprintf("ACK (%d)\n", __LINE__));
- if (xyz.mode == xyzModem_ymodem) {
- CYGACC_COMM_IF_PUTC(*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
- xyz.total_retries++;
- ZM_DEBUG(zm_dprintf("Reading Final Header\n"));
- stat = xyzModem_get_hdr();
- CYGACC_COMM_IF_PUTC(*xyz.__chan, ACK);
- ZM_DEBUG(zm_dprintf("FINAL ACK (%d)\n", __LINE__));
- }
- xyz.at_eof = true;
- break;
- }
- CYGACC_COMM_IF_PUTC(*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
- xyz.total_retries++;
- ZM_DEBUG(zm_dprintf("NAK (%d)\n", __LINE__));
- }
- if (stat < 0) {
- *err = stat;
- xyz.len = -1;
- return total;
- }
- }
- /* Don't "read" data from the EOF protocol package */
- if (!xyz.at_eof) {
- len = xyz.len;
- if (size < len) len = size;
- memcpy(buf, xyz.bufp, len);
- size -= len;
- buf += len;
- total += len;
- xyz.len -= len;
- xyz.bufp += len;
- }
+ break;
+ }
+ else if (xyz.blk == ((xyz.next_blk - 1) & 0xFF))
+ {
+ /* Just re-ACK this so sender will get on with it */
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
+ continue; /* Need new header */
+ }
+ else
+ {
+ stat = xyzModem_sequence;
+ }
+ }
+ if (stat == xyzModem_cancel)
+ {
+ break;
+ }
+ if (stat == xyzModem_eof)
+ {
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
+ ZM_DEBUG (zm_dprintf ("ACK (%d)\n", __LINE__));
+ if (xyz.mode == xyzModem_ymodem)
+ {
+ CYGACC_COMM_IF_PUTC (*xyz.__chan,
+ (xyz.crc_mode ? 'C' : NAK));
+ xyz.total_retries++;
+ ZM_DEBUG (zm_dprintf ("Reading Final Header\n"));
+ stat = xyzModem_get_hdr ();
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
+ ZM_DEBUG (zm_dprintf ("FINAL ACK (%d)\n", __LINE__));
+ }
+ xyz.at_eof = true;
+ break;
+ }
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
+ xyz.total_retries++;
+ ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__));
+ }
+ if (stat < 0)
+ {
+ *err = stat;
+ xyz.len = -1;
+ return total;
+ }
+ }
+ /* Don't "read" data from the EOF protocol package */
+ if (!xyz.at_eof)
+ {
+ len = xyz.len;
+ if (size < len)
+ len = size;
+ memcpy (buf, xyz.bufp, len);
+ size -= len;
+ buf += len;
+ total += len;
+ xyz.len -= len;
+ xyz.bufp += len;
+ }
}
- return total;
+ return total;
}
void
-xyzModem_stream_close(int *err)
+xyzModem_stream_close (int *err)
{
- diag_printf("xyzModem - %s mode, %d(SOH)/%d(STX)/%d(CAN) packets, %d retries\n",
- xyz.crc_mode ? "CRC" : "Cksum",
- xyz.total_SOH, xyz.total_STX, xyz.total_CAN,
- xyz.total_retries);
- ZM_DEBUG(zm_flush());
+ diag_printf
+ ("xyzModem - %s mode, %d(SOH)/%d(STX)/%d(CAN) packets, %d retries\n",
+ xyz.crc_mode ? "CRC" : "Cksum", xyz.total_SOH, xyz.total_STX,
+ xyz.total_CAN, xyz.total_retries);
+ ZM_DEBUG (zm_flush ());
}
/* Need to be able to clean out the input buffer, so have to take the */
/* getc */
-void xyzModem_stream_terminate(bool abort, int (*getc)(void))
+void
+xyzModem_stream_terminate (bool abort, int (*getc) (void))
{
int c;
- if (abort) {
- ZM_DEBUG(zm_dprintf("!!!! TRANSFER ABORT !!!!\n"));
- switch (xyz.mode) {
+ if (abort)
+ {
+ ZM_DEBUG (zm_dprintf ("!!!! TRANSFER ABORT !!!!\n"));
+ switch (xyz.mode)
+ {
case xyzModem_xmodem:
case xyzModem_ymodem:
/* The X/YMODEM Spec seems to suggest that multiple CAN followed by an equal */
/* number of Backspaces is a friendly way to get the other end to abort. */
- CYGACC_COMM_IF_PUTC(*xyz.__chan,CAN);
- CYGACC_COMM_IF_PUTC(*xyz.__chan,CAN);
- CYGACC_COMM_IF_PUTC(*xyz.__chan,CAN);
- CYGACC_COMM_IF_PUTC(*xyz.__chan,CAN);
- CYGACC_COMM_IF_PUTC(*xyz.__chan,BSP);
- CYGACC_COMM_IF_PUTC(*xyz.__chan,BSP);
- CYGACC_COMM_IF_PUTC(*xyz.__chan,BSP);
- CYGACC_COMM_IF_PUTC(*xyz.__chan,BSP);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
+ CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
/* Now consume the rest of what's waiting on the line. */
- ZM_DEBUG(zm_dprintf("Flushing serial line.\n"));
- xyzModem_flush();
- xyz.at_eof = true;
- break;
+ ZM_DEBUG (zm_dprintf ("Flushing serial line.\n"));
+ xyzModem_flush ();
+ xyz.at_eof = true;
+ break;
#ifdef xyzModem_zmodem
case xyzModem_zmodem:
/* Might support it some day I suppose. */
#endif
- break;
- }
- } else {
- ZM_DEBUG(zm_dprintf("Engaging cleanup mode...\n"));
+ break;
+ }
+ }
+ else
+ {
+ ZM_DEBUG (zm_dprintf ("Engaging cleanup mode...\n"));
/*
* Consume any trailing crap left in the inbuffer from
* previous recieved blocks. Since very few files are an exact multiple
* of the transfer block size, there will almost always be some gunk here.
* If we don't eat it now, RedBoot will think the user typed it.
*/
- ZM_DEBUG(zm_dprintf("Trailing gunk:\n"));
- while ((c = (*getc)()) > -1) ;
- ZM_DEBUG(zm_dprintf("\n"));
+ ZM_DEBUG (zm_dprintf ("Trailing gunk:\n"));
+ while ((c = (*getc) ()) > -1);
+ ZM_DEBUG (zm_dprintf ("\n"));
/*
* Make a small delay to give terminal programs like minicom
* time to get control again after their file transfer program
* exits.
*/
- CYGACC_CALL_IF_DELAY_US((cyg_int32)250000);
- }
+ CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000);
+ }
}
char *
-xyzModem_error(int err)
+xyzModem_error (int err)
{
- switch (err) {
+ switch (err)
+ {
case xyzModem_access:
- return "Can't access file";
- break;
+ return "Can't access file";
+ break;
case xyzModem_noZmodem:
- return "Sorry, zModem not available yet";
- break;
+ return "Sorry, zModem not available yet";
+ break;
case xyzModem_timeout:
- return "Timed out";
- break;
+ return "Timed out";
+ break;
case xyzModem_eof:
- return "End of file";
- break;
+ return "End of file";
+ break;
case xyzModem_cancel:
- return "Cancelled";
- break;
+ return "Cancelled";
+ break;
case xyzModem_frame:
- return "Invalid framing";
- break;
+ return "Invalid framing";
+ break;
case xyzModem_cksum:
- return "CRC/checksum error";
- break;
+ return "CRC/checksum error";
+ break;
case xyzModem_sequence:
- return "Block sequence error";
- break;
+ return "Block sequence error";
+ break;
default:
- return "Unknown error";
- break;
+ return "Unknown error";
+ break;
}
}
/*
* RedBoot interface
*/
-#if 0 /* SB */
-GETC_IO_FUNCS(xyzModem_io, xyzModem_stream_open, xyzModem_stream_close,
- xyzModem_stream_terminate, xyzModem_stream_read, xyzModem_error);
-RedBoot_load(xmodem, xyzModem_io, false, false, xyzModem_xmodem);
-RedBoot_load(ymodem, xyzModem_io, false, false, xyzModem_ymodem);
+#if 0 /* SB */
+GETC_IO_FUNCS (xyzModem_io, xyzModem_stream_open, xyzModem_stream_close,
+ xyzModem_stream_terminate, xyzModem_stream_read,
+ xyzModem_error);
+RedBoot_load (xmodem, xyzModem_io, false, false, xyzModem_xmodem);
+RedBoot_load (ymodem, xyzModem_io, false, false, xyzModem_ymodem);
#endif