From 8bde7f776c77b343aca29b8c7b58464d915ac245 Mon Sep 17 00:00:00 2001 From: wdenk Date: Fri, 27 Jun 2003 21:31:46 +0000 Subject: * Code cleanup: - remove trailing white space, trailing empty lines, C++ comments, etc. - split cmd_boot.c (separate cmd_bdinfo.c and cmd_load.c) * Patches by Kenneth Johansson, 25 Jun 2003: - major rework of command structure (work done mostly by Michal Cendrowski and Joakim Kristiansen) --- common/Makefile | 27 +- common/bedbug.c | 4 +- common/cmd_autoscript.c | 19 +- common/cmd_bdinfo.c | 180 ++++++++ common/cmd_bedbug.c | 65 ++- common/cmd_boot.c | 1114 +---------------------------------------------- common/cmd_bootm.c | 43 +- common/cmd_cache.c | 16 +- common/cmd_console.c | 10 + common/cmd_date.c | 11 + common/cmd_dcr.c | 65 ++- common/cmd_diag.c | 13 +- common/cmd_doc.c | 35 +- common/cmd_dtt.c | 9 +- common/cmd_eeprom.c | 23 + common/cmd_elf.c | 50 ++- common/cmd_fat.c | 1 - common/cmd_fdc.c | 47 +- common/cmd_fdos.c | 96 ++-- common/cmd_flash.c | 40 +- common/cmd_fpga.c | 13 +- common/cmd_i2c.c | 58 ++- common/cmd_ide.c | 26 +- common/cmd_immap.c | 109 ++++- common/cmd_jffs2.c | 49 ++- common/cmd_load.c | 1057 ++++++++++++++++++++++++++++++++++++++++++++ common/cmd_log.c | 11 +- common/cmd_mem.c | 73 +++- common/cmd_mii.c | 12 +- common/cmd_misc.c | 17 + common/cmd_nand.c | 20 +- common/cmd_net.c | 30 +- common/cmd_nvedit.c | 60 ++- common/cmd_pci.c | 144 +++--- common/cmd_pcmcia.c | 27 +- common/cmd_reginfo.c | 13 +- common/cmd_scsi.c | 6 - common/cmd_spi.c | 16 +- common/cmd_usb.c | 36 +- common/cmd_vfd.c | 7 + common/command.c | 330 ++++---------- common/dlmalloc.c | 563 ++++++++++++------------ common/dlmalloc.src | 559 ++++++++++++------------ common/docecc.c | 100 ++--- common/env_common.c | 1 - common/env_eeprom.c | 1 - common/env_flash.c | 29 +- common/env_nvram.c | 1 - common/fpga.c | 4 +- common/hush.c | 66 +-- common/kgdb.c | 14 + common/main.c | 28 +- common/miiphybb.c | 1 - common/soft_i2c.c | 8 +- common/soft_spi.c | 2 - common/spartan2.c | 72 +-- common/usb.c | 1 - common/usb_kbd.c | 6 - common/usb_storage.c | 10 - 59 files changed, 3070 insertions(+), 2378 deletions(-) create mode 100644 common/cmd_bdinfo.c create mode 100644 common/cmd_load.c (limited to 'common') diff --git a/common/Makefile b/common/Makefile index d93dbb3f14..3aa9b65a90 100644 --- a/common/Makefile +++ b/common/Makefile @@ -28,21 +28,24 @@ LIB = libcommon.a AOBJS = COBJS = main.o altera.o bedbug.o \ - cmd_autoscript.o cmd_bedbug.o cmd_bmp.o cmd_boot.o \ - cmd_bootm.o cmd_cache.o cmd_console.o cmd_date.o \ - cmd_dcr.o cmd_diag.o cmd_doc.o cmd_nand.o cmd_dtt.o \ + cmd_autoscript.o \ + cmd_bdinfo.o cmd_bedbug.o cmd_bmp.o cmd_boot.o cmd_bootm.o \ + cmd_cache.o cmd_console.o \ + cmd_date.o cmd_dcr.o cmd_diag.o cmd_doc.o cmd_dtt.o \ cmd_eeprom.o cmd_elf.o \ - cmd_fat.o cmd_fdc.o cmd_fdos.o cmd_flash.o \ - cmd_fpga.o cmd_i2c.o cmd_ide.o cmd_immap.o \ - cmd_jffs2.o cmd_log.o cmd_mem.o cmd_mii.o cmd_misc.o \ - cmd_mmc.o cmd_net.o cmd_nvedit.o env_common.o \ - env_flash.o env_eeprom.o env_nvram.o env_nowhere.o \ + cmd_fat.o cmd_fdc.o cmd_fdos.o cmd_flash.o cmd_fpga.o \ + cmd_i2c.o cmd_ide.o cmd_immap.o cmd_jffs2.o \ + cmd_load.o cmd_log.o \ + cmd_mem.o cmd_mii.o cmd_misc.o cmd_mmc.o \ + cmd_nand.o cmd_net.o cmd_nvedit.o \ cmd_pci.o cmd_pcmcia.o cmd_portio.o \ - cmd_reginfo.o cmd_scsi.o cmd_vfd.o cmd_usb.o \ - command.o console.o devices.o dlmalloc.o \ - docecc.o environment.o flash.o fpga.o \ + cmd_reginfo.o cmd_scsi.o cmd_spi.o cmd_usb.o cmd_vfd.o \ + command.o console.o devices.o dlmalloc.o docecc.o \ + environment.o env_common.o \ + env_flash.o env_eeprom.o env_nvram.o env_nowhere.o \ + flash.o fpga.o \ hush.o kgdb.o lists.o miiphybb.o miiphyutil.o \ - s_record.o soft_i2c.o soft_spi.o cmd_spi.o spartan2.o \ + s_record.o soft_i2c.o soft_spi.o spartan2.o \ usb.o usb_kbd.o usb_storage.o \ virtex2.o xilinx.o diff --git a/common/bedbug.c b/common/bedbug.c index fe54d17f82..6966de7445 100644 --- a/common/bedbug.c +++ b/common/bedbug.c @@ -27,7 +27,7 @@ extern char *symbol_name_from_addr __P ((Elf32_Word, int, int *)); int print_operands __P ((struct ppc_ctx *)); int get_operand_value __P ((struct opcode *, unsigned long, - enum OP_FIELD, unsigned long *)); + enum OP_FIELD, unsigned long *)); struct opcode *find_opcode __P ((unsigned long)); struct opcode *find_opcode_by_name __P ((char *)); char *spr_name __P ((int)); @@ -35,7 +35,7 @@ int spr_value __P ((char *)); char *tbr_name __P ((int)); int tbr_value __P ((char *)); int parse_operand __P ((unsigned long, struct opcode *, - struct operand *, char *, int *)); + struct operand *, char *, int *)); int get_word __P ((char **, char *)); long read_number __P ((char *)); int downstring __P ((char *)); diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index 7e706c93a7..d3d04c3040 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -40,8 +40,6 @@ #include #include #include -#include -#include #if defined(CONFIG_8xx) #include #endif @@ -49,8 +47,9 @@ #include #endif +#define AUTOSCRIPT_MAGIC 0x09011962 #if defined(CONFIG_AUTOSCRIPT) || \ - (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) + (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT ) extern image_header_t header; /* from cmd_bootm.c */ int @@ -118,7 +117,7 @@ autoscript (ulong addr) memmove (cmd, (char *)len_ptr, len); *(cmd + len) = 0; -#ifdef CFG_HUSH_PARSER +#ifdef CFG_HUSH_PARSER /*?? */ rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON); #else { @@ -153,7 +152,7 @@ autoscript (ulong addr) } #endif /* CONFIG_AUTOSCRIPT || CFG_CMD_AUTOSCRIPT */ - +/**************************************************/ #if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) int do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) @@ -171,4 +170,14 @@ do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) rcode = autoscript (addr); return rcode; } + +#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) +cmd_tbl_t U_BOOT_CMD(AUTOSCRIPT) = MK_CMD_ENTRY( + "autoscr", 2, 0, do_autoscript, + "autoscr - run script from memory\n", + "[addr] - run script starting at addr" + " - A valid autoscr header must be present\n" +); #endif /* CFG_CMD_AUTOSCRIPT */ + +#endif /* CONFIG_AUTOSCRIPT || CFG_CMD_AUTOSCRIPT */ diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c new file mode 100644 index 0000000000..3f73cf852e --- /dev/null +++ b/common/cmd_bdinfo.c @@ -0,0 +1,180 @@ +/* + * (C) Copyright 2003 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * 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 + */ + +/* + * Boot support + */ +#include +#include + + +#if (CONFIG_COMMANDS & CFG_CMD_BDI) +static void print_num(const char *, ulong); + +#ifndef CONFIG_ARM /* PowerPC and other */ + +#ifdef CONFIG_PPC +static void print_str(const char *, const char *); + +int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + DECLARE_GLOBAL_DATA_PTR; + + int i; + bd_t *bd = gd->bd; + char buf[32]; + +#ifdef DEBUG + print_num ("bd address", (ulong)bd ); +#endif + print_num ("memstart", bd->bi_memstart ); + print_num ("memsize", bd->bi_memsize ); + print_num ("flashstart", bd->bi_flashstart ); + print_num ("flashsize", bd->bi_flashsize ); + print_num ("flashoffset", bd->bi_flashoffset ); + print_num ("sramstart", bd->bi_sramstart ); + print_num ("sramsize", bd->bi_sramsize ); +#if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260) + print_num ("immr_base", bd->bi_immr_base ); +#endif + print_num ("bootflags", bd->bi_bootflags ); +#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405EP) + 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) + print_str ("pci_busfreq", strmhz(buf, bd->bi_pci_busfreq)); +#endif +#else /* ! CONFIG_405GP, CONFIG_405CR, CONFIG_405EP */ +#if defined(CONFIG_8260) + print_str ("vco", strmhz(buf, bd->bi_vco)); + print_str ("sccfreq", strmhz(buf, bd->bi_sccfreq)); + print_str ("brgfreq", strmhz(buf, bd->bi_brgfreq)); +#endif + print_str ("intfreq", strmhz(buf, bd->bi_intfreq)); +#if defined(CONFIG_8260) + print_str ("cpmfreq", strmhz(buf, bd->bi_cpmfreq)); +#endif + print_str ("busfreq", strmhz(buf, bd->bi_busfreq)); +#endif /* CONFIG_405GP, CONFIG_405CR, CONFIG_405EP */ + printf ("ethaddr ="); + for (i=0; i<6; ++i) { + printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); + } +#ifdef CONFIG_PN62 + printf ("\neth1addr ="); + for (i=0; i<6; ++i) { + printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]); + } +#endif /* CONFIG_PN62 */ +#ifdef CONFIG_HERMES + print_str ("ethspeed", strmhz(buf, bd->bi_ethspeed)); +#endif + printf ("\nIP addr = "); print_IPaddr (bd->bi_ip_addr); + printf ("\nbaudrate = %6ld bps\n", bd->bi_baudrate ); + return 0; +} + +#else /* ! PPC, which leaves MIPS */ + +int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + DECLARE_GLOBAL_DATA_PTR; + + int i; + bd_t *bd = gd->bd; + + print_num ("boot_params", (ulong)bd->bi_boot_params); + print_num ("memstart", (ulong)bd->bi_memstart); + print_num ("memsize", (ulong)bd->bi_memsize); + print_num ("flashstart", (ulong)bd->bi_flashstart); + print_num ("flashsize", (ulong)bd->bi_flashsize); + print_num ("flashoffset", (ulong)bd->bi_flashoffset); + + printf ("ethaddr ="); + for (i=0; i<6; ++i) { + printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); + } + printf ("\nip_addr = "); + print_IPaddr (bd->bi_ip_addr); + printf ("\nbaudrate = %d bps\n", bd->bi_baudrate); + + return 0; +} +#endif /* MIPS */ + +#else /* ARM */ + +int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + DECLARE_GLOBAL_DATA_PTR; + + int i; + bd_t *bd = gd->bd; + + print_num ("arch_number", bd->bi_arch_number); + print_num ("env_t", (ulong)bd->bi_env); + print_num ("boot_params", (ulong)bd->bi_boot_params); + + for (i=0; i start", bd->bi_dram[i].start); + print_num("-> size", bd->bi_dram[i].size); + } + + printf ("ethaddr ="); + for (i=0; i<6; ++i) { + printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); + } + printf ("\n" + "ip_addr = "); + print_IPaddr (bd->bi_ip_addr); + printf ("\n" + "baudrate = %d bps\n", bd->bi_baudrate); + + return 0; +} + +#endif /* CONFIG_ARM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ + +static void print_num(const char *name, ulong value) +{ + printf ("%-12s= 0x%08lX\n", name, value); +} + +#ifdef CONFIG_PPC +static void print_str(const char *name, const char *str) +{ + printf ("%-12s= %6s MHz\n", name, str); +} +#endif /* CONFIG_PPC */ + + +/* -------------------------------------------------------------------- */ + +cmd_tbl_t U_BOOT_CMD(BDINFO) = MK_CMD_ENTRY( + "bdinfo", 1, 1, do_bdinfo, + "bdinfo - print Board Info structure\n", + NULL +); +#endif /* CFG_CMD_BDI */ + diff --git a/common/cmd_bedbug.c b/common/cmd_bedbug.c index f3b5f88dab..6ee01d521a 100644 --- a/common/cmd_bedbug.c +++ b/common/cmd_bedbug.c @@ -6,12 +6,10 @@ #include #include #include - -#include +#include #include #include #include -#include #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG) @@ -110,8 +108,11 @@ int do_bedbug_dis (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) dis_last_len = len; return 0; } /* do_bedbug_dis */ - - +cmd_tbl_t U_BOOT_CMD(DIS) = MK_CMD_ENTRY( + "ds", 3, 1, do_bedbug_dis, + "ds - disassemble memory\n", + "ds
[# instructions]\n" +); /* ====================================================================== * Entry point from the interpreter to the assembler. Assembles @@ -154,7 +155,7 @@ int do_bedbug_asm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) else { printf( "*** Error: %s ***\n", asm_error_str( asm_err )); - rcode = 1; + rcode = 1; } } else @@ -164,8 +165,11 @@ int do_bedbug_asm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } return rcode; } /* do_bedbug_asm */ - - +cmd_tbl_t U_BOOT_CMD(ASM) = MK_CMD_ENTRY( + "as", 2, 0, do_bedbug_asm, + "as - assemble memory\n", + "as
\n" +); /* ====================================================================== * Used to set a break point from the interpreter. Simply calls into the @@ -180,8 +184,14 @@ int do_bedbug_break (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } /* do_bedbug_break */ - - +cmd_tbl_t U_BOOT_CMD(BREAK) = MK_CMD_ENTRY( + "break", 3, 0, do_bedbug_break, + "break - set or clear a breakpoint\n", + " - Set or clear a breakpoint\n" + "break
- Break at an address\n" + "break off - Disable breakpoint.\n" + "break show - List breakpoints.\n" +); /* ====================================================================== * Called from the debug interrupt routine. Simply calls the CPU-specific @@ -278,8 +288,11 @@ int do_bedbug_continue (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) bug_ctx.stopped = 0; return 0; } /* do_bedbug_continue */ - - +cmd_tbl_t U_BOOT_CMD(CONTINUE) = MK_CMD_ENTRY( + "continue", 1, 0, do_bedbug_continue, + "continue- continue from a breakpoint\n", + " - continue from a breakpoint.\n" +); /* ====================================================================== * Interpreter command to continue to the next instruction, stepping into @@ -307,8 +320,11 @@ int do_bedbug_step (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) bug_ctx.stopped = 0; return 0; } /* do_bedbug_step */ - - +cmd_tbl_t U_BOOT_CMD(STEP) = MK_CMD_ENTRY( + "step", 1, 1, do_bedbug_step, + "step - single step execution.\n", + " - single step execution.\n" +); /* ====================================================================== * Interpreter command to continue to the next instruction, stepping over @@ -336,8 +352,11 @@ int do_bedbug_next (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) bug_ctx.stopped = 0; return 0; } /* do_bedbug_next */ - - +cmd_tbl_t U_BOOT_CMD(NEXT) = MK_CMD_ENTRY( + "next", 1, 1, do_bedbug_next, + "next - single step execution, stepping over subroutines.\n", + " - single step execution, stepping over subroutines.\n" +); /* ====================================================================== * Interpreter command to print the current stack. This assumes an EABI @@ -382,8 +401,11 @@ int do_bedbug_stack (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } return 0; } /* do_bedbug_stack */ - - +cmd_tbl_t U_BOOT_CMD(STACK) = MK_CMD_ENTRY( + "where", 1, 1, do_bedbug_stack, + "where - Print the running stack.\n", + " - Print the running stack.\n" +); /* ====================================================================== * Interpreter command to dump the registers. Calls the CPU-specific @@ -402,8 +424,11 @@ int do_bedbug_rdump (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) show_regs( bug_ctx.regs ); return 0; } /* do_bedbug_rdump */ - - +cmd_tbl_t U_BOOT_CMD(RDUMP) = MK_CMD_ENTRY( + "rdump", 1, 1, do_bedbug_rdump, + "rdump - Show registers.\n", + " - Show registers.\n" +); /* ====================================================================== */ #endif /* CFG_CMD_BEDBUG */ diff --git a/common/cmd_boot.c b/common/cmd_boot.c index fef84597dd..a0bc04ba60 100644 --- a/common/cmd_boot.c +++ b/common/cmd_boot.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2000-2002 + * (C) Copyright 2000-2003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this @@ -22,170 +22,16 @@ */ /* - * Boot support + * Misc boot support */ #include #include -#include #include -#include #include #include -#if (CONFIG_COMMANDS & CFG_CMD_LOADS) -static ulong load_serial (ulong offset); -static int read_record (char *buf, ulong len); -# if (CONFIG_COMMANDS & CFG_CMD_SAVES) -static int save_serial (ulong offset, ulong size); -static int write_record (char *buf); -# endif /* CFG_CMD_SAVES */ - -static int do_echo = 1; -#endif /* CFG_CMD_LOADS */ - - -#if (CONFIG_COMMANDS & CFG_CMD_BDI) -static void print_num(const char *, ulong); - -#ifndef CONFIG_ARM /* PowerPC and other */ - -#ifdef CONFIG_PPC -static void print_str(const char *, const char *); - -int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - DECLARE_GLOBAL_DATA_PTR; - - int i; - bd_t *bd = gd->bd; - char buf[32]; - -#ifdef DEBUG - print_num ("bd address", (ulong)bd ); -#endif - print_num ("memstart", bd->bi_memstart ); - print_num ("memsize", bd->bi_memsize ); - print_num ("flashstart", bd->bi_flashstart ); - print_num ("flashsize", bd->bi_flashsize ); - print_num ("flashoffset", bd->bi_flashoffset ); - print_num ("sramstart", bd->bi_sramstart ); - print_num ("sramsize", bd->bi_sramsize ); -#if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260) - print_num ("immr_base", bd->bi_immr_base ); -#endif - print_num ("bootflags", bd->bi_bootflags ); -#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405EP) - 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) - print_str ("pci_busfreq", strmhz(buf, bd->bi_pci_busfreq)); -#endif -#else -#if defined(CONFIG_8260) - print_str ("vco", strmhz(buf, bd->bi_vco)); - print_str ("sccfreq", strmhz(buf, bd->bi_sccfreq)); - print_str ("brgfreq", strmhz(buf, bd->bi_brgfreq)); -#endif - print_str ("intfreq", strmhz(buf, bd->bi_intfreq)); -#if defined(CONFIG_8260) - print_str ("cpmfreq", strmhz(buf, bd->bi_cpmfreq)); -#endif - print_str ("busfreq", strmhz(buf, bd->bi_busfreq)); -#endif /* defined(CONFIG_405GP) || defined(CONFIG_405CR) */ - printf ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } -#ifdef CONFIG_PN62 - printf ("\neth1addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]); - } -#endif /* CONFIG_PN62 */ -#ifdef CONFIG_HERMES - print_str ("ethspeed", strmhz(buf, bd->bi_ethspeed)); -#endif - printf ("\nIP addr = "); print_IPaddr (bd->bi_ip_addr); - printf ("\nbaudrate = %6ld bps\n", bd->bi_baudrate ); - return 0; -} - -#else /* MIPS */ - -int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - DECLARE_GLOBAL_DATA_PTR; - - int i; - bd_t *bd = gd->bd; - - print_num ("boot_params", (ulong)bd->bi_boot_params); - print_num ("memstart", (ulong)bd->bi_memstart); - print_num ("memsize", (ulong)bd->bi_memsize); - print_num ("flashstart", (ulong)bd->bi_flashstart); - print_num ("flashsize", (ulong)bd->bi_flashsize); - print_num ("flashoffset", (ulong)bd->bi_flashoffset); - - printf ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } - printf ("\nip_addr = "); - print_IPaddr (bd->bi_ip_addr); - printf ("\nbaudrate = %d bps\n", bd->bi_baudrate); - - return 0; -} -#endif /* MIPS */ - -#else /* ARM */ - -int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - DECLARE_GLOBAL_DATA_PTR; - - int i; - bd_t *bd = gd->bd; - - print_num ("arch_number", bd->bi_arch_number); - print_num ("env_t", (ulong)bd->bi_env); - print_num ("boot_params", (ulong)bd->bi_boot_params); - - for (i=0; i start", bd->bi_dram[i].start); - print_num("-> size", bd->bi_dram[i].size); - } - - printf ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } - printf ("\n" - "ip_addr = "); - print_IPaddr (bd->bi_ip_addr); - printf ("\n" - "baudrate = %d bps\n", bd->bi_baudrate); - - return 0; -} - -#endif /* CONFIG_ARM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ - -static void print_num(const char *name, ulong value) -{ - printf ("%-12s= 0x%08lX\n", name, value); -} - -#ifdef CONFIG_PPC -static void print_str(const char *name, const char *str) -{ - printf ("%-12s= %6s MHz\n", name, str); -} -#endif /* CONFIG_PPC */ - -#endif /* CFG_CMD_BDI */ +/* -------------------------------------------------------------------- */ int do_go (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { @@ -212,947 +58,19 @@ int do_go (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return rcode; } -#if (CONFIG_COMMANDS & CFG_CMD_LOADS) -int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - ulong offset = 0; - ulong addr; - int i; - char *env_echo; - int rcode = 0; -#ifdef CFG_LOADS_BAUD_CHANGE - DECLARE_GLOBAL_DATA_PTR; - int load_baudrate, current_baudrate; - - load_baudrate = current_baudrate = gd->baudrate; -#endif - - if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) { - do_echo = 1; - } else { - do_echo = 0; - } - -#ifdef CFG_LOADS_BAUD_CHANGE - if (argc >= 2) { - offset = simple_strtoul(argv[1], NULL, 16); - } - if (argc == 3) { - load_baudrate = (int)simple_strtoul(argv[2], NULL, 10); - - /* default to current baudrate */ - if (load_baudrate == 0) - load_baudrate = current_baudrate; - } -#else /* ! CFG_LOADS_BAUD_CHANGE */ - if (argc == 2) { - offset = simple_strtoul(argv[1], NULL, 16); - } -#endif /* CFG_LOADS_BAUD_CHANGE */ - -#ifdef CFG_LOADS_BAUD_CHANGE - if (load_baudrate != current_baudrate) { - printf ("## Switch baudrate to %d bps and press ENTER ...\n", - load_baudrate); - udelay(50000); - gd->baudrate = load_baudrate; - serial_setbrg (); - udelay(50000); - for (;;) { - if (getc() == '\r') - break; - } - } -#endif /* CFG_LOADS_BAUD_CHANGE */ - printf ("## Ready for S-Record download ...\n"); - - addr = load_serial (offset); - - /* - * Gather any trailing characters (for instance, the ^D which - * is sent by 'cu' after sending a file), and give the - * box some time (100 * 1 ms) - */ - for (i=0; i<100; ++i) { - if (serial_tstc()) { - (void) serial_getc(); - } - udelay(1000); - } - - if (addr == ~0) { - printf ("## S-Record download aborted\n"); - rcode = 1; - } else { - printf ("## Start Addr = 0x%08lX\n", addr); - load_addr = addr; - } - -#ifdef CFG_LOADS_BAUD_CHANGE - if (load_baudrate != current_baudrate) { - printf ("## Switch baudrate to %d bps and press ESC ...\n", - current_baudrate); - udelay (50000); - gd->baudrate = current_baudrate; - serial_setbrg (); - udelay (50000); - for (;;) { - if (getc() == 0x1B) /* ESC */ - break; - } - } -#endif - return rcode; -} - -static ulong -load_serial (ulong offset) -{ - char record[SREC_MAXRECLEN + 1]; /* buffer for one S-Record */ - char binbuf[SREC_MAXBINLEN]; /* buffer for binary data */ - int binlen; /* no. of data bytes in S-Rec. */ - int type; /* return code for record type */ - ulong addr; /* load address from S-Record */ - ulong size; /* number of bytes transferred */ - char buf[32]; - ulong store_addr; - ulong start_addr = ~0; - ulong end_addr = 0; - int line_count = 0; - - while (read_record(record, SREC_MAXRECLEN + 1) >= 0) { - type = srec_decode (record, &binlen, &addr, binbuf); - - if (type < 0) { - return (~0); /* Invalid S-Record */ - } - - switch (type) { - case SREC_DATA2: - case SREC_DATA3: - case SREC_DATA4: - store_addr = addr + offset; -#ifndef CFG_NO_FLASH - if (addr2info(store_addr)) { - int rc; - - rc = flash_write((uchar *)binbuf,store_addr,binlen); - if (rc != 0) { - flash_perror (rc); - return (~0); - } - } else -#endif - { - memcpy ((char *)(store_addr), binbuf, binlen); - } - if ((store_addr) < start_addr) - start_addr = store_addr; - if ((store_addr + binlen - 1) > end_addr) - end_addr = store_addr + binlen - 1; - break; - case SREC_END2: - case SREC_END3: - case SREC_END4: - udelay (10000); - size = end_addr - start_addr + 1; - printf ("\n" - "## First Load Addr = 0x%08lX\n" - "## Last Load Addr = 0x%08lX\n" - "## Total Size = 0x%08lX = %ld Bytes\n", - start_addr, end_addr, size, size - ); - flush_cache (addr, size); - sprintf(buf, "%lX", size); - setenv("filesize", buf); - return (addr); - case SREC_START: - break; - default: - break; - } - if (!do_echo) { /* print a '.' every 100 lines */ - if ((++line_count % 100) == 0) - putc ('.'); - } - } - - return (~0); /* Download aborted */ -} - -static int -read_record (char *buf, ulong len) -{ - char *p; - char c; - - --len; /* always leave room for terminating '\0' byte */ - - for (p=buf; p < buf+len; ++p) { - c = serial_getc(); /* read character */ - if (do_echo) - serial_putc (c); /* ... and echo it */ - - switch (c) { - case '\r': - case '\n': - *p = '\0'; - return (p - buf); - case '\0': - case 0x03: /* ^C - Control C */ - return (-1); - default: - *p = c; - } - - /* Check for the console hangup (if any different from serial) */ -#ifdef CONFIG_PPC /* we don't have syscall_tbl anywhere else */ - if (syscall_tbl[SYSCALL_GETC] != serial_getc) { - if (ctrlc()) { - return (-1); - } - } -#endif - } - - /* line too long - truncate */ - *p = '\0'; - return (p - buf); -} - -#if (CONFIG_COMMANDS & CFG_CMD_SAVES) - -int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - ulong offset = 0; - ulong size = 0; -#ifdef CFG_LOADS_BAUD_CHANGE - DECLARE_GLOBAL_DATA_PTR; - int save_baudrate, current_baudrate; - - save_baudrate = current_baudrate = gd->baudrate; -#endif - - if (argc >= 2) { - offset = simple_strtoul(argv[1], NULL, 16); - } -#ifdef CFG_LOADS_BAUD_CHANGE - if (argc >= 3) { - size = simple_strtoul(argv[2], NULL, 16); - } - if (argc == 4) { - save_baudrate = (int)simple_strtoul(argv[3], NULL, 10); - - /* default to current baudrate */ - if (save_baudrate == 0) - save_baudrate = current_baudrate; - } -#else /* ! CFG_LOADS_BAUD_CHANGE */ - if (argc == 3) { - size = simple_strtoul(argv[2], NULL, 16); - } -#endif /* CFG_LOADS_BAUD_CHANGE */ - -#ifdef CFG_LOADS_BAUD_CHANGE - if (save_baudrate != current_baudrate) { - printf ("## Switch baudrate to %d bps and press ENTER ...\n", - save_baudrate); - udelay(50000); - gd->baudrate = save_baudrate; - serial_setbrg (); - udelay(50000); - for (;;) { - if (getc() == '\r') - break; - } - } -#endif /* CFG_LOADS_BAUD_CHANGE */ - printf ("## Ready for S-Record upload, press ENTER to proceed ...\n"); - for (;;) { - if (getc() == '\r') - break; - } - if(save_serial (offset, size)) { - printf ("## S-Record upload aborted\n"); - } else { - printf ("## S-Record upload complete\n"); - } -#ifdef CFG_LOADS_BAUD_CHANGE - if (save_baudrate != current_baudrate) { - printf ("## Switch baudrate to %d bps and press ESC ...\n", - (int)current_baudrate); - udelay (50000); - gd->baudrate = current_baudrate; - serial_setbrg (); - udelay (50000); - for (;;) { - if (getc() == 0x1B) /* ESC */ - break; - } - } -#endif - return 0; -} - -#define SREC3_START "S0030000FC\n" -#define SREC3_FORMAT "S3%02X%08lX%s%02X\n" -#define SREC3_END "S70500000000FA\n" -#define SREC_BYTES_PER_RECORD 16 - -static int save_serial (ulong address, ulong count) -{ - int i, c, reclen, checksum, length; - char *hex = "0123456789ABCDEF"; - char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */ - char data[2*SREC_BYTES_PER_RECORD+1]; /* buffer for hex data */ - - reclen = 0; - checksum = 0; - - if(write_record(SREC3_START)) /* write the header */ - return (-1); - do { - if(count) { /* collect hex data in the buffer */ - c = *(volatile uchar*)(address + reclen); /* get one byte */ - checksum += c; /* accumulate checksum */ - data[2*reclen] = hex[(c>>4)&0x0f]; - data[2*reclen+1] = hex[c & 0x0f]; - data[2*reclen+2] = '\0'; - ++reclen; - --count; - } - if(reclen == SREC_BYTES_PER_RECORD || count == 0) { - /* enough data collected for one record: dump it */ - if(reclen) { /* build & write a data record: */ - /* address + data + checksum */ - length = 4 + reclen + 1; - - /* accumulate length bytes into checksum */ - for(i = 0; i < 2; i++) - checksum += (length >> (8*i)) & 0xff; - - /* accumulate address bytes into checksum: */ - for(i = 0; i < 4; i++) - checksum += (address >> (8*i)) & 0xff; - - /* make proper checksum byte: */ - checksum = ~checksum & 0xff; - - /* output one record: */ - sprintf(record, SREC3_FORMAT, length, address, data, checksum); - if(write_record(record)) - return (-1); - } - address += reclen; /* increment address */ - checksum = 0; - reclen = 0; - } - } - while(count); - if(write_record(SREC3_END)) /* write the final record */ - return (-1); - return(0); -} - -static int -write_record (char *buf) -{ - char c; - - while((c = *buf++)) - serial_putc(c); - - /* Check for the console hangup (if any different from serial) */ - - if (ctrlc()) { - return (-1); - } - return (0); -} -# endif /* CFG_CMD_SAVES */ - -#endif /* CFG_CMD_LOADS */ - - -#if (CONFIG_COMMANDS & CFG_CMD_LOADB) /* loadb command (load binary) included */ - -#define XON_CHAR 17 -#define XOFF_CHAR 19 -#define START_CHAR 0x01 -#define ETX_CHAR 0x03 -#define END_CHAR 0x0D -#define SPACE 0x20 -#define K_ESCAPE 0x23 -#define SEND_TYPE 'S' -#define DATA_TYPE 'D' -#define ACK_TYPE 'Y' -#define NACK_TYPE 'N' -#define BREAK_TYPE 'B' -#define tochar(x) ((char) (((x) + SPACE) & 0xff)) -#define untochar(x) ((int) (((x) - SPACE) & 0xff)) - -extern int os_data_count; -extern int os_data_header[8]; - -static void set_kerm_bin_mode(unsigned long *); -static int k_recv(void); -static ulong load_serial_bin (ulong offset); - - -char his_eol; /* character he needs at end of packet */ -int his_pad_count; /* number of pad chars he needs */ -char his_pad_char; /* pad chars he needs */ -char his_quote; /* quote chars he'll use */ - -int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - DECLARE_GLOBAL_DATA_PTR; - - ulong offset = 0; - ulong addr; - int load_baudrate, current_baudrate; - int rcode = 0; - char *s; - - /* pre-set offset from CFG_LOAD_ADDR */ - offset = CFG_LOAD_ADDR; - - /* pre-set offset from $loadaddr */ - if ((s = getenv("loadaddr")) != NULL) { - offset = simple_strtoul(s, NULL, 16); - } - - load_baudrate = current_baudrate = gd->baudrate; - - if (argc >= 2) { - offset = simple_strtoul(argv[1], NULL, 16); - } - if (argc == 3) { - load_baudrate = (int)simple_strtoul(argv[2], NULL, 10); - - /* default to current baudrate */ - if (load_baudrate == 0) - load_baudrate = current_baudrate; - } - - if (load_baudrate != current_baudrate) { - printf ("## Switch baudrate to %d bps and press ENTER ...\n", - load_baudrate); - udelay(50000); - gd->baudrate = load_baudrate; - serial_setbrg (); - udelay(50000); - for (;;) { - if (getc() == '\r') - break; - } - } - - printf ("## Ready for binary (kermit) download " - "to 0x%08lX at %d bps...\n", - offset, - current_baudrate); - addr = load_serial_bin (offset); - - if (addr == ~0) { - load_addr = 0; - printf ("## Binary (kermit) download aborted\n"); - rcode = 1; - } else { - printf ("## Start Addr = 0x%08lX\n", addr); - load_addr = addr; - } - - if (load_baudrate != current_baudrate) { - printf ("## Switch baudrate to %d bps and press ESC ...\n", - current_baudrate); - udelay (50000); - gd->baudrate = current_baudrate; - serial_setbrg (); - udelay (50000); - for (;;) { - if (getc() == 0x1B) /* ESC */ - break; - } - } - -#ifdef CONFIG_AUTOSCRIPT - if (load_addr) { - char *s; - - if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) { - printf("Running autoscript at addr 0x%08lX ...\n", load_addr); - rcode = autoscript (load_addr); - } - } -#endif - return rcode; -} - - -static ulong load_serial_bin (ulong offset) -{ - int size, i; - char buf[32]; - - set_kerm_bin_mode ((ulong *) offset); - size = k_recv (); - - /* - * Gather any trailing characters (for instance, the ^D which - * is sent by 'cu' after sending a file), and give the - * box some time (100 * 1 ms) - */ - for (i=0; i<100; ++i) { - if (serial_tstc()) { - (void) serial_getc(); - } - udelay(1000); - } - - flush_cache (offset, size); - - printf("## Total Size = 0x%08x = %d Bytes\n", size, size); - sprintf(buf, "%X", size); - setenv("filesize", buf); - - return offset; -} - -void send_pad (void) -{ - int count = his_pad_count; - - while (count-- > 0) - serial_putc (his_pad_char); -} - -/* converts escaped kermit char to binary char */ -char ktrans (char in) -{ - if ((in & 0x60) == 0x40) { - return (char) (in & ~0x40); - } else if ((in & 0x7f) == 0x3f) { - return (char) (in | 0x40); - } else - return in; -} - -int chk1 (char *buffer) -{ - int total = 0; +/* -------------------------------------------------------------------- */ - while (*buffer) { - total += *buffer++; - } - return (int) ((total + ((total >> 6) & 0x03)) & 0x3f); -} +cmd_tbl_t U_BOOT_CMD(GO) = MK_CMD_ENTRY( + "go", CFG_MAXARGS, 1, do_go, + "go - start application at address 'addr'\n", + "addr [arg ...]\n - start application at address 'addr'\n" + " passing 'arg' as arguments\n" +); -void s1_sendpacket (char *packet) -{ - send_pad (); - while (*packet) { - serial_putc (*packet++); - } -} +extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); -static char a_b[24]; -void send_ack (int n) -{ - a_b[0] = START_CHAR; - a_b[1] = tochar (3); - a_b[2] = tochar (n); - a_b[3] = ACK_TYPE; - a_b[4] = '\0'; - a_b[4] = tochar (chk1 (&a_b[1])); - a_b[5] = his_eol; - a_b[6] = '\0'; - s1_sendpacket (a_b); -} - -void send_nack (int n) -{ - a_b[0] = START_CHAR; - a_b[1] = tochar (3); - a_b[2] = tochar (n); - a_b[3] = NACK_TYPE; - a_b[4] = '\0'; - a_b[4] = tochar (chk1 (&a_b[1])); - a_b[5] = his_eol; - a_b[6] = '\0'; - s1_sendpacket (a_b); -} - - - -/* os_data_* takes an OS Open image and puts it into memory, and - puts the boot header in an array named os_data_header - - if image is binary, no header is stored in os_data_header. -*/ -void (*os_data_init) (void); -void (*os_data_char) (char new_char); -static int os_data_state, os_data_state_saved; -int os_data_count; -static int os_data_count_saved; -static char *os_data_addr, *os_data_addr_saved; -static char *bin_start_address; -int os_data_header[8]; -static void bin_data_init (void) -{ - os_data_state = 0; - os_data_count = 0; - os_data_addr = bin_start_address; -} -static void os_data_save (void) -{ - os_data_state_saved = os_data_state; - os_data_count_saved = os_data_count; - os_data_addr_saved = os_data_addr; -} -static void os_data_restore (void) -{ - os_data_state = os_data_state_saved; - os_data_count = os_data_count_saved; - os_data_addr = os_data_addr_saved; -} -static void bin_data_char (char new_char) -{ - switch (os_data_state) { - case 0: /* data */ - *os_data_addr++ = new_char; - --os_data_count; - break; - } -} -static void set_kerm_bin_mode (unsigned long *addr) -{ - bin_start_address = (char *) addr; - os_data_init = bin_data_init; - os_data_char = bin_data_char; -} - - -/* k_data_* simply handles the kermit escape translations */ -static int k_data_escape, k_data_escape_saved; -void k_data_init (void) -{ - k_data_escape = 0; - os_data_init (); -} -void k_data_save (void) -{ - k_data_escape_saved = k_data_escape; - os_data_save (); -} -void k_data_restore (void) -{ - k_data_escape = k_data_escape_saved; - os_data_restore (); -} -void k_data_char (char new_char) -{ - if (k_data_escape) { - /* last char was escape - translate this character */ - os_data_char (ktrans (new_char)); - k_data_escape = 0; - } else { - if (new_char == his_quote) { - /* this char is escape - remember */ - k_data_escape = 1; - } else { - /* otherwise send this char as-is */ - os_data_char (new_char); - } - } -} - -#define SEND_DATA_SIZE 20 -char send_parms[SEND_DATA_SIZE]; -char *send_ptr; - -/* handle_send_packet interprits the protocol info and builds and - sends an appropriate ack for what we can do */ -void handle_send_packet (int n) -{ - int length = 3; - int bytes; - - /* initialize some protocol parameters */ - his_eol = END_CHAR; /* default end of line character */ - his_pad_count = 0; - his_pad_char = '\0'; - his_quote = K_ESCAPE; - - /* ignore last character if it filled the buffer */ - if (send_ptr == &send_parms[SEND_DATA_SIZE - 1]) - --send_ptr; - bytes = send_ptr - send_parms; /* how many bytes we'll process */ - do { - if (bytes-- <= 0) - break; - /* handle MAXL - max length */ - /* ignore what he says - most I'll take (here) is 94 */ - a_b[++length] = tochar (94); - if (bytes-- <= 0) - break; - /* handle TIME - time you should wait for my packets */ - /* ignore what he says - don't wait for my ack longer than 1 second */ - a_b[++length] = tochar (1); - if (bytes-- <= 0) - break; - /* handle NPAD - number of pad chars I need */ - /* remember what he says - I need none */ - his_pad_count = untochar (send_parms[2]); - a_b[++length] = tochar (0); - if (bytes-- <= 0) - break; - /* handle PADC - pad chars I need */ - /* remember what he says - I need none */ - his_pad_char = ktrans (send_parms[3]); - a_b[++length] = 0x40; /* He should ignore this */ - if (bytes-- <= 0) - break; - /* handle EOL - end of line he needs */ - /* remember what he says - I need CR */ - his_eol = untochar (send_parms[4]); - a_b[++length] = tochar (END_CHAR); - if (bytes-- <= 0) - break; - /* handle QCTL - quote control char he'll use */ - /* remember what he says - I'll use '#' */ - his_quote = send_parms[5]; - a_b[++length] = '#'; - if (bytes-- <= 0) - break; - /* handle QBIN - 8-th bit prefixing */ - /* ignore what he says - I refuse */ - a_b[++length] = 'N'; - if (bytes-- <= 0) - break; - /* handle CHKT - the clock check type */ - /* ignore what he says - I do type 1 (for now) */ - a_b[++length] = '1'; - if (bytes-- <= 0) - break; - /* handle REPT - the repeat prefix */ - /* ignore what he says - I refuse (for now) */ - a_b[++length] = 'N'; - if (bytes-- <= 0) - break; - /* handle CAPAS - the capabilities mask */ - /* ignore what he says - I only do long packets - I don't do windows */ - a_b[++length] = tochar (2); /* only long packets */ - a_b[++length] = tochar (0); /* no windows */ - a_b[++length] = tochar (94); /* large packet msb */ - a_b[++length] = tochar (94); /* large packet lsb */ - } while (0); - - a_b[0] = START_CHAR; - a_b[1] = tochar (length); - a_b[2] = tochar (n); - a_b[3] = ACK_TYPE; - a_b[++length] = '\0'; - a_b[length] = tochar (chk1 (&a_b[1])); - a_b[++length] = his_eol; - a_b[++length] = '\0'; - s1_sendpacket (a_b); -} - -/* k_recv receives a OS Open image file over kermit line */ -static int k_recv (void) -{ - char new_char; - char k_state, k_state_saved; - int sum; - int done; - int length; - int n, last_n; - int z = 0; - int len_lo, len_hi; - - /* initialize some protocol parameters */ - his_eol = END_CHAR; /* default end of line character */ - his_pad_count = 0; - his_pad_char = '\0'; - his_quote = K_ESCAPE; - - /* initialize the k_recv and k_data state machine */ - done = 0; - k_state = 0; - k_data_init (); - k_state_saved = k_state; - k_data_save (); - n = 0; /* just to get rid of a warning */ - last_n = -1; - - /* expect this "type" sequence (but don't check): - S: send initiate - F: file header - D: data (multiple) - Z: end of file - B: break transmission - */ - - /* enter main loop */ - while (!done) { - /* set the send packet pointer to begining of send packet parms */ - send_ptr = send_parms; - - /* With each packet, start summing the bytes starting with the length. - Save the current sequence number. - Note the type of the packet. - If a character less than SPACE (0x20) is received - error. - */ - -#if 0 - /* OLD CODE, Prior to checking sequence numbers */ - /* first have all state machines save current states */ - k_state_saved = k_state; - k_data_save (); -#endif - - /* get a packet */ - /* wait for the starting character or ^C */ - for (;;) { - switch (serial_getc ()) { - case START_CHAR: /* start packet */ - goto START; - case ETX_CHAR: /* ^C waiting for packet */ - return (0); - default: - ; - } - } -START: - /* get length of packet */ - sum = 0; - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - sum += new_char & 0xff; - length = untochar (new_char); - /* get sequence number */ - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - sum += new_char & 0xff; - n = untochar (new_char); - --length; - - /* NEW CODE - check sequence numbers for retried packets */ - /* Note - this new code assumes that the sequence number is correctly - * received. Handling an invalid sequence number adds another layer - * of complexity that may not be needed - yet! At this time, I'm hoping - * that I don't need to buffer the incoming data packets and can write - * the data into memory in real time. - */ - if (n == last_n) { - /* same sequence number, restore the previous state */ - k_state = k_state_saved; - k_data_restore (); - } else { - /* new sequence number, checkpoint the download */ - last_n = n; - k_state_saved = k_state; - k_data_save (); - } - /* END NEW CODE */ - - /* get packet type */ - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - sum += new_char & 0xff; - k_state = new_char; - --length; - /* check for extended length */ - if (length == -2) { - /* (length byte was 0, decremented twice) */ - /* get the two length bytes */ - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - sum += new_char & 0xff; - len_hi = untochar (new_char); - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - sum += new_char & 0xff; - len_lo = untochar (new_char); - length = len_hi * 95 + len_lo; - /* check header checksum */ - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f)) - goto packet_error; - sum += new_char & 0xff; -/* --length; */ /* new length includes only data and block check to come */ - } - /* bring in rest of packet */ - while (length > 1) { - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - sum += new_char & 0xff; - --length; - if (k_state == DATA_TYPE) { - /* pass on the data if this is a data packet */ - k_data_char (new_char); - } else if (k_state == SEND_TYPE) { - /* save send pack in buffer as is */ - *send_ptr++ = new_char; - /* if too much data, back off the pointer */ - if (send_ptr >= &send_parms[SEND_DATA_SIZE]) - --send_ptr; - } - } - /* get and validate checksum character */ - new_char = serial_getc (); - if ((new_char & 0xE0) == 0) - goto packet_error; - if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f)) - goto packet_error; - /* get END_CHAR */ - new_char = serial_getc (); - if (new_char != END_CHAR) { - packet_error: - /* restore state machines */ - k_state = k_state_saved; - k_data_restore (); - /* send a negative acknowledge packet in */ - send_nack (n); - } else if (k_state == SEND_TYPE) { - /* crack the protocol parms, build an appropriate ack packet */ - handle_send_packet (n); - } else { - /* send simple acknowledge packet in */ - send_ack (n); - /* quit if end of transmission */ - if (k_state == BREAK_TYPE) - done = 1; - } - ++z; - } - return ((ulong) os_data_addr - (ulong) bin_start_address); -} -#endif /* CFG_CMD_LOADB */ -#if (CONFIG_COMMANDS & CFG_CMD_HWFLOW) -int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - extern int hwflow_onoff(int); - - if (argc == 2) { - if (strcmp(argv[1], "off") == 0) - hwflow_onoff(-1); - else - if (strcmp(argv[1], "on") == 0) - hwflow_onoff(1); - else - printf("Usage: %s\n", cmdtp->usage); - } - printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off"); - return 0; -} -#endif /* CFG_CMD_HWFLOW */ +cmd_tbl_t U_BOOT_CMD(RESET) = MK_CMD_ENTRY( + "reset", 1, 0, do_reset, + "reset - Perform RESET of the CPU\n", + NULL +); diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 8af7c7c9b7..7ade068b56 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -27,12 +27,15 @@ #include #include #include -#include #include #include #include #include #include + + /*cmd_boot.c*/ + extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); + #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP) #include #endif @@ -97,6 +100,10 @@ typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag, ulong *len_ptr, /* multi-file image length table */ int verify); /* getenv("verify")[0] != 'n' */ +#ifdef DEBUG +extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +#endif + #ifdef CONFIG_PPC static boot_os_Fcn do_bootm_linux; #else @@ -192,7 +199,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) read_dataflash(data, len, (char *)CFG_LOAD_ADDR); data = CFG_LOAD_ADDR; } -#endif +#endif if (verify) { printf (" Verifying Checksum ... "); @@ -214,7 +221,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #elif defined(__I386__) if (hdr->ih_arch != IH_CPU_I386) #elif defined(__mips__) - if (hdr->ih_arch != IH_CPU_MIPS) + if (hdr->ih_arch != IH_CPU_MIPS) #else # error Unknown CPU type #endif @@ -253,7 +260,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #ifdef CONFIG_AMIGAONEG3SE /* - * We've possible left the caches enabled during + * We've possible left the caches enabled during * bios emulation, so turn them off again */ icache_disable(); @@ -342,12 +349,12 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) do_bootm_netbsd (cmdtp, flag, argc, argv, addr, len_ptr, verify); break; - + case IH_OS_RTEMS: do_bootm_rtems (cmdtp, flag, argc, argv, addr, len_ptr, verify); break; - + #if (CONFIG_COMMANDS & CFG_CMD_ELF) case IH_OS_VXWORKS: do_bootm_vxworks (cmdtp, flag, argc, argv, @@ -374,6 +381,14 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } +cmd_tbl_t U_BOOT_CMD(BOOTM) = MK_CMD_ENTRY( + "bootm", CFG_MAXARGS, 1, do_bootm, + "bootm - boot application image from memory\n", + "[addr [arg ...]]\n - boot application image stored in memory\n" + " passing arguments 'arg ...'; when booting a Linux kernel,\n" + " 'arg' can be the address of an initrd image\n" +); + #ifdef CONFIG_PPC static void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, @@ -856,6 +871,13 @@ int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #endif return rcode; } + +cmd_tbl_t U_BOOT_CMD(BOOTD) = MK_CMD_ENTRY( + "bootd", 1, 1, do_bootd, + "bootd - boot default, i.e., run 'bootcmd'\n", + NULL +); + #endif #if (CONFIG_COMMANDS & CFG_CMD_IMI) @@ -916,6 +938,15 @@ static int image_info (ulong addr) printf ("OK\n"); return 0; } +cmd_tbl_t U_BOOT_CMD(IMINFO) = MK_CMD_ENTRY( + "iminfo", CFG_MAXARGS, 1, do_iminfo, + "iminfo - print header information for application image\n", + "addr [addr ...]\n" + " - print header information for application image starting at\n" + " address 'addr' in memory; this includes verification of the\n" + " image contents (magic number, header and payload checksums)\n" +); + #endif /* CFG_CMD_IMI */ void diff --git a/common/cmd_cache.c b/common/cmd_cache.c index f2015b3ee5..0016b72891 100644 --- a/common/cmd_cache.c +++ b/common/cmd_cache.c @@ -26,7 +26,6 @@ */ #include #include -#include #if (CONFIG_COMMANDS & CFG_CMD_CACHE) @@ -95,4 +94,19 @@ static int on_off (const char *s) return (-1); } + +cmd_tbl_t U_BOOT_CMD(ICACHE) = MK_CMD_ENTRY( + "icache", 2, 1, do_icache, + "icache - enable or disable instruction cache\n", + "[on, off]\n" + " - enable or disable instruction cache\n" +); + +cmd_tbl_t U_BOOT_CMD(DCACHE) = MK_CMD_ENTRY( + "dcache", 2, 1, do_dcache, + "dcache - enable or disable data cache\n", + "[on, off]\n" + " - enable or disable data (writethrough) cache\n" +); + #endif /* CFG_CMD_CACHE */ diff --git a/common/cmd_console.c b/common/cmd_console.c index a5f792b064..e6b001a15a 100644 --- a/common/cmd_console.c +++ b/common/cmd_console.c @@ -58,4 +58,14 @@ int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char *argv[]) } return 0; } + + +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(CONINFO) = MK_CMD_ENTRY( + "coninfo", 3, 1, do_coninfo, + "coninfo - print console devices and informations\n", + "" +); + #endif /* CFG_CMD_CONSOLE */ diff --git a/common/cmd_date.c b/common/cmd_date.c index 2139cebf83..6b75210862 100644 --- a/common/cmd_date.c +++ b/common/cmd_date.c @@ -189,4 +189,15 @@ int mk_date (char *datestr, struct rtc_time *tmp) return (-1); } +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(DATE) = MK_CMD_ENTRY( + "date", 2, 1, do_date, + "date - get/set/reset date & time\n", + "[MMDDhhmm[[CC]YY][.ss]]\ndate reset\n" + " - without arguments: print date & time\n" + " - with numeric argument: set the system date & time\n" + " - with 'reset' argument: reset the RTC\n" +); + #endif /* CFG_CMD_DATE */ diff --git a/common/cmd_dcr.c b/common/cmd_dcr.c index 072685e4e3..3ec11b0449 100644 --- a/common/cmd_dcr.c +++ b/common/cmd_dcr.c @@ -28,7 +28,6 @@ #include #include #include -#include #if defined(CONFIG_4xx) && defined(CFG_CMD_SETGETDCR) @@ -41,10 +40,12 @@ int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ) unsigned short dcrn; /* Device Control Register Num */ unsigned long value; /* DCR's value */ + unsigned long get_dcr(unsigned short); + /* Validate arguments */ if (argc < 2) { - printf("Usage:\n%s\n", cmdtp->usage); - return 1; + printf("Usage:\n%s\n", cmdtp->usage); + return 1; } /* Get a DCR */ @@ -63,41 +64,57 @@ 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; /* DCR's value */ + unsigned long value; + /* DCR's value */ int nbytes; extern char console_buffer[]; /* Validate arguments */ if (argc < 2) { - printf("Usage:\n%s\n", cmdtp->usage); - return 1; + printf("Usage:\n%s\n", cmdtp->usage); + return 1; } /* Set a DCR */ dcrn = (unsigned short)simple_strtoul(argv[1], NULL, 16); do { - value = get_dcr(dcrn); - printf("%04x: %08lx", dcrn, value); - nbytes = readline(" ? "); - if (nbytes == 0) { - /* - * pressed as only input, don't modify current - * location and exit command. - */ - nbytes = 1; - return 0; - } else { - unsigned long i; - char *endp; - i = simple_strtoul(console_buffer, &endp, 16); - nbytes = endp - console_buffer; - if (nbytes) - set_dcr(dcrn, i); - } + value = get_dcr(dcrn); + printf("%04x: %08lx", dcrn, value); + nbytes = readline(" ? "); + if (nbytes == 0) { + /* + * pressed as only input, don't modify current + * location and exit command. + */ + nbytes = 1; + return 0; + } else { + unsigned long i; + char *endp; + i = simple_strtoul(console_buffer, &endp, 16); + nbytes = endp - console_buffer; + if (nbytes) + set_dcr(dcrn, i); + } } while (nbytes); return 0; } /* do_setdcr */ +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(GETDCR) = MK_CMD_ENTRY( + "getdcr", 2, 1, do_getdcr, + "getdcr - Get an IBM PPC 4xx DCR's value\n", + "dcrn - return a DCR's value.\n" +); +cmd_tbl_t U_BOOT_CMD(SETDCR) = MK_CMD_ENTRY( + "setdcr", 2, 1, do_setdcr, + "setdcr - Set an IBM PPC 4xx DCR's value\n", + "dcrn - set a DCR's value.\n" +); + #endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */ diff --git a/common/cmd_diag.c b/common/cmd_diag.c index 31471ba119..0bb6c7f0e4 100644 --- a/common/cmd_diag.c +++ b/common/cmd_diag.c @@ -26,7 +26,6 @@ */ #include #include -#include #include #if (CONFIG_COMMANDS & CFG_CMD_DIAG) && defined(CONFIG_POST) @@ -65,5 +64,17 @@ int do_diag (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 0; } +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(DIAG) = MK_CMD_ENTRY( + "diag", CFG_MAXARGS, 0, do_diag, + "diag - perform board diagnostics\n", + " - print list of available tests\n" + "diag [test1 [test2]]\n" + " - print information about specified tests\n" + "diag run - run all available tests\n" + "diag run [test1 [test2]]\n" + " - run specified tests\n" +); #endif /* CFG_CMD_DIAG */ diff --git a/common/cmd_doc.c b/common/cmd_doc.c index 612a6d5dc2..17c9d0d5bb 100644 --- a/common/cmd_doc.c +++ b/common/cmd_doc.c @@ -80,7 +80,7 @@ int do_doc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) printf ("Usage:\n%s\n", cmdtp->usage); return 1; case 2: - if (strcmp(argv[1],"info") == 0) { + if (strcmp(argv[1],"info") == 0) { int i; putc ('\n'); @@ -170,6 +170,17 @@ int do_doc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return rcode; } } +cmd_tbl_t U_BOOT_CMD(DOC) = MK_CMD_ENTRY( + "doc", 5, 1, do_doc, + "doc - Disk-On-Chip sub-system\n", + "info - show available DOC devices\n" + "doc device [dev] - show or set current device\n" + "doc read addr off size\n" + "doc write addr off size - read/write `size'" + " bytes starting at offset `off'\n" + " to/from memory address `addr'\n" + "doc erase off size - erase `size' bytes of DOC from offset `off'\n" +); int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { @@ -273,6 +284,12 @@ int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return rcode; } +cmd_tbl_t U_BOOT_CMD(DOCBOOT) = MK_CMD_ENTRY( + "docboot", 4, 1, do_docboot, + "docboot - boot from DOC device\n", + "loadAddr dev\n" +); + int doc_rw (struct DiskOnChip* this, int cmd, loff_t from, size_t len, size_t * retlen, u_char * buf) @@ -385,7 +402,7 @@ static int _DoC_WaitReady(struct DiskOnChip *doc) } #endif udelay(1); - } + } return 0; } @@ -938,7 +955,7 @@ static void DoC2k_init(struct DiskOnChip* this) /* Get physical parameters */ nftl->EraseSize = this->erasesize; - nftl->nb_blocks = this->totlen / this->erasesize; + nftl->nb_blocks = this->totlen / this->erasesize; nftl->mtd = this; if (find_boot_record(nftl) != 0) @@ -1054,18 +1071,18 @@ int doc_read_ecc(struct DiskOnChip* this, loff_t from, size_t len, syndrome[i] = ReadDOC(docptr, ECCSyndrome0 + i); } - nb_errors = doc_decode_ecc(buf, syndrome); + nb_errors = doc_decode_ecc(buf, syndrome); #ifdef ECC_DEBUG printf("Errors corrected: %x\n", nb_errors); #endif - if (nb_errors < 0) { + if (nb_errors < 0) { /* We return error, but have actually done the read. Not that this can be told to user-space, via sys_read(), but at least MTD-aware stuff can know about it by checking *retlen */ printf("ECC Errors at %lx\n", (long)from); ret = DOC_EECC; - } + } } #ifdef PSYCHO_DEBUG @@ -1079,7 +1096,7 @@ int doc_read_ecc(struct DiskOnChip* this, loff_t from, size_t len, } /* according to 11.4.1, we need to wait for the busy line - * drop if we read to the end of the page. */ + * drop if we read to the end of the page. */ if(0 == ((from + *retlen) & 0x1ff)) { DoC_WaitReady(this); @@ -1291,8 +1308,8 @@ int doc_read_oob(struct DiskOnChip* this, loff_t ofs, size_t len, *retlen = len; /* Reading the full OOB data drops us off of the end of the page, - * causing the flash device to go into busy mode, so we need - * to wait until ready 11.4.1 and Toshiba TC58256FT docs */ + * causing the flash device to go into busy mode, so we need + * to wait until ready 11.4.1 and Toshiba TC58256FT docs */ ret = DoC_WaitReady(this); diff --git a/common/cmd_dtt.c b/common/cmd_dtt.c index 943b0c73e2..447076c6f5 100644 --- a/common/cmd_dtt.c +++ b/common/cmd_dtt.c @@ -24,7 +24,6 @@ #include #include #include -#include #if (CONFIG_COMMANDS & CFG_CMD_DTT) @@ -46,4 +45,12 @@ int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 0; } /* do_dtt() */ +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(DTT) = MK_CMD_ENTRY( + "dtt", 1, 1, do_dtt, + "dtt - Digital Thermometer and Themostat\n", + " - Read temperature from digital thermometer and thermostat.\n" +); + #endif /* CONFIG_COMMANDS & CFG_CMD_DTT */ diff --git a/common/cmd_eeprom.c b/common/cmd_eeprom.c index 3db0bca69d..0a7831994d 100644 --- a/common/cmd_eeprom.c +++ b/common/cmd_eeprom.c @@ -371,3 +371,26 @@ void eeprom_init (void) /*----------------------------------------------------------------------- */ #endif /* CFG_CMD_EEPROM */ +/***************************************************/ + +#if (CONFIG_COMMANDS & CFG_CMD_EEPROM) + +#ifdef CFG_I2C_MULTI_EEPROMS +cmd_tbl_t U_BOOT_CMD(EEPROM) = MK_CMD_ENTRY( + "eeprom", 6, 1, do_eeprom, + "eeprom - EEPROM sub-system\n", + "read devaddr addr off cnt\n" + "eeprom write devaddr addr off cnt\n" + " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'\n" +); +#else /* One EEPROM */ +cmd_tbl_t U_BOOT_CMD(EEPROM) = MK_CMD_ENTRY( + "eeprom", 5, 1, do_eeprom, + "eeprom - EEPROM sub-system\n", + "read addr off cnt\n" + "eeprom write addr off cnt\n" + " - read/write `cnt' bytes at EEPROM offset `off'\n" +); +#endif /* CFG_I2C_MULTI_EEPROMS */ + +#endif /* CFG_CMD_EEPROM */ diff --git a/common/cmd_elf.c b/common/cmd_elf.c index 74957622b1..c068c104b1 100644 --- a/common/cmd_elf.c +++ b/common/cmd_elf.c @@ -17,8 +17,6 @@ #include #include #include - -#include #include @@ -28,6 +26,8 @@ #define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif +int valid_elf_image (unsigned long addr); +unsigned long load_elf_image (unsigned long addr); /* ====================================================================== * Interpreter command to boot an arbitrary ELF image from memory. @@ -136,11 +136,11 @@ int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) printf ("## Ethernet MAC address not copied to NV RAM\n"); #endif - /* - * Use bootaddr to find the location in memory that VxWorks - * will look for the bootline string. The default value for - * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which - * defaults to 0x4200 + /* + * Use bootaddr to find the location in memory that VxWorks + * will look for the bootline string. The default value for + * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which + * defaults to 0x4200 */ if ((tmp = getenv ("bootaddr")) == NULL) @@ -148,10 +148,10 @@ int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) else bootaddr = simple_strtoul (tmp, NULL, 16); - /* - * Check to see if the bootline is defined in the 'bootargs' - * parameter. If it is not defined, we may be able to - * construct the info + /* + * Check to see if the bootline is defined in the 'bootargs' + * parameter. If it is not defined, we may be able to + * construct the info */ if ((bootline = getenv ("bootargs")) != NULL) { @@ -194,10 +194,10 @@ int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) flush_cache (bootaddr, MAX(strlen(build_buf), 255)); #else - /* - * I'm not sure what the device should be for other - * PPC flavors, the hostname and ipaddr should be ok - * to just copy + /* + * I'm not sure what the device should be for other + * PPC flavors, the hostname and ipaddr should be ok + * to just copy */ printf ("No bootargs defined\n"); @@ -205,10 +205,10 @@ int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #endif } - /* - * If the data at the load address is an elf image, then - * treat it like an elf image. Otherwise, assume that it is a - * binary image + /* + * If the data at the load address is an elf image, then + * treat it like an elf image. Otherwise, assume that it is a + * binary image */ if (valid_elf_image (addr)) { @@ -321,4 +321,16 @@ unsigned long load_elf_image (unsigned long addr) } /* ====================================================================== */ +cmd_tbl_t U_BOOT_CMD(BOOTELF) = MK_CMD_ENTRY( + "bootelf", 2, 0, do_bootelf, + "bootelf - Boot from an ELF image in memory\n", + " [address] - load address of ELF image.\n" +); + +cmd_tbl_t U_BOOT_CMD(BOOTVX) = MK_CMD_ENTRY( + "bootvx", 2, 0, do_bootvx, + "bootvx - Boot vxWorks from an ELF image\n", + " [address] - load address of vxWorks ELF image.\n" +); + #endif /* CFG_CMD_ELF */ diff --git a/common/cmd_fat.c b/common/cmd_fat.c index 4db70e1c1f..12eb764a9d 100644 --- a/common/cmd_fat.c +++ b/common/cmd_fat.c @@ -26,7 +26,6 @@ */ #include #include -#include #include #include #include diff --git a/common/cmd_fdc.c b/common/cmd_fdc.c index 3ee342fcfc..303075004b 100644 --- a/common/cmd_fdc.c +++ b/common/cmd_fdc.c @@ -47,9 +47,9 @@ #endif -#if (CONFIG_COMMANDS & CFG_CMD_DATE) -#include -#endif +/*#if (CONFIG_COMMANDS & CFG_CMD_DATE) */ +/*#include */ +/*#endif */ #if ((CONFIG_COMMANDS & CFG_CMD_FDC) || (CONFIG_COMMANDS & CFG_CMD_FDOS)) @@ -211,7 +211,7 @@ int wait_for_fdc_int(void) return TRUE; } #endif - + /* Supporting Functions */ /* reads a Register of the FDC */ unsigned char read_fdc_reg(unsigned int addr) @@ -220,14 +220,14 @@ unsigned char read_fdc_reg(unsigned int addr) (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS + (addr * CFG_ISA_IO_STRIDE) + CFG_ISA_IO_OFFSET); - + return val [0]; } /* writes a Register of the FDC */ void write_fdc_reg(unsigned int addr, unsigned char val) { - volatile unsigned char *tmp = + volatile unsigned char *tmp = (volatile unsigned char *)(CFG_ISA_IO_BASE_ADDRESS + (addr * CFG_ISA_IO_STRIDE) + CFG_ISA_IO_OFFSET); @@ -642,7 +642,6 @@ int fdc_check_drive(FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG) } - /************************************************************************** * int fdc_setup * setup the fdc according the datasheet @@ -658,7 +657,7 @@ int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG) #endif #ifdef CFG_FDC_HW_INIT - fdc_hw_init (); + fdc_hw_init (); #endif /* first, we reset the FDC via the DOR */ write_fdc_reg(FDC_DOR,0x00); @@ -716,14 +715,14 @@ int fdc_setup(int drive, FDC_COMMAND_STRUCT *pCMD, FD_GEO_STRUCT *pFG) /************************************************************************** * int fdc_fdos_init -* initialize the FDC layer -* +* initialize the FDC layer +* */ int fdc_fdos_init (int drive) { FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type; FDC_COMMAND_STRUCT *pCMD = &cmd; - + /* setup FDC and scan for drives */ if(fdc_setup(drive,pCMD,pFG)==FALSE) { printf("\n** Error in setup FDC **\n"); @@ -748,19 +747,19 @@ int fdc_fdos_init (int drive) /* read first block */ pCMD->blnr=0; - return TRUE; + return TRUE; } /************************************************************************** * int fdc_fdos_seek -* parameter is a block number +* parameter is a block number */ int fdc_fdos_seek (int where) { FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type; FDC_COMMAND_STRUCT *pCMD = &cmd; - pCMD -> blnr = where ; - return (fdc_seek (pCMD, pFG)); + pCMD -> blnr = where ; + return (fdc_seek (pCMD, pFG)); } /************************************************************************** * int fdc_fdos_read @@ -771,7 +770,7 @@ int fdc_fdos_read (void *buffer, int len) FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type; FDC_COMMAND_STRUCT *pCMD = &cmd; - return (fdc_read_data (buffer, len, pCMD, pFG)); + return (fdc_read_data (buffer, len, pCMD, pFG)); } #endif /* (CONFIG_COMMANDS & CFG_CMD_FDOS) */ @@ -783,7 +782,7 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type; FDC_COMMAND_STRUCT *pCMD = &cmd; - unsigned long addr,imsize; + unsigned long addr,imsize; image_header_t *hdr; /* used for fdc boot */ unsigned char boot_drive; int i,nrofblk; @@ -793,7 +792,7 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) switch (argc) { case 1: addr = CFG_LOAD_ADDR; - boot_drive=CFG_FDC_DRIVE_NUMBER; + boot_drive=CFG_FDC_DRIVE_NUMBER; break; case 2: addr = simple_strtoul(argv[1], NULL, 16); @@ -881,7 +880,17 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } - #endif /* CONFIG_COMMANDS & CFG_CMD_FDC */ +/***************************************************/ + + +#if (CONFIG_COMMANDS & CFG_CMD_FDC) + +cmd_tbl_t U_BOOT_CMD(FDC) = MK_CMD_ENTRY( + "fdcboot", 3, 1, do_fdcboot, + "fdcboot - boot from floppy device\n", + "loadAddr drive\n" +); +#endif diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index 4b411b3d37..8257e703d7 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c @@ -34,7 +34,7 @@ #if (CONFIG_COMMANDS & CFG_CMD_FDOS) /*----------------------------------------------------------------------------- - * do_fdosboot -- + * do_fdosboot -- *----------------------------------------------------------------------------- */ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) @@ -45,53 +45,53 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int rcode = 0; char buf [10]; int drive = CFG_FDC_DRIVE_NUMBER; - + /* pre-set load_addr */ if ((ep = getenv("loadaddr")) != NULL) { - load_addr = simple_strtoul(ep, NULL, 16); + load_addr = simple_strtoul(ep, NULL, 16); } /* pre-set Boot file name */ if ((name = getenv("bootfile")) == NULL) { - name = "uImage"; + name = "uImage"; } switch (argc) { case 1: - break; + break; case 2: /* only one arg - accept two forms: - * just load address, or just boot file name. - * The latter form must be written "filename" here. - */ - if (argv[1][0] == '"') { /* just boot filename */ - name = argv [1]; - } else { /* load address */ - load_addr = simple_strtoul(argv[1], NULL, 16); - } - break; + * just load address, or just boot file name. + * The latter form must be written "filename" here. + */ + if (argv[1][0] == '"') { /* just boot filename */ + name = argv [1]; + } else { /* load address */ + load_addr = simple_strtoul(argv[1], NULL, 16); + } + break; case 3: - load_addr = simple_strtoul(argv[1], NULL, 16); - name = argv [2]; - break; + load_addr = simple_strtoul(argv[1], NULL, 16); + name = argv [2]; + break; default: - printf ("Usage:\n%s\n", cmdtp->usage); - break; + printf ("Usage:\n%s\n", cmdtp->usage); + break; } /* Init physical layer */ if (!fdc_fdos_init (drive)) { - return (-1); + return (-1); } - + /* Open file */ if (dos_open (name) < 0) { - printf ("Unable to open %s\n", name); - return 1; + printf ("Unable to open %s\n", name); + return 1; } if ((size = dos_read (load_addr)) < 0) { - printf ("boot error\n"); - return 1; + printf ("boot error\n"); + return 1; } flush_cache (load_addr, size); @@ -99,47 +99,59 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) setenv("filesize", buf); printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", - size, load_addr); - + size, load_addr); + /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { - char *local_args[2]; - extern int do_bootm (cmd_tbl_t *, int, int, char *[]); - local_args[0] = argv[0]; - local_args[1] = NULL; - printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); - rcode = do_bootm (cmdtp, 0, 1, local_args); + char *local_args[2]; + extern int do_bootm (cmd_tbl_t *, int, int, char *[]); + local_args[0] = argv[0]; + local_args[1] = NULL; + printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); + rcode = do_bootm (cmdtp, 0, 1, local_args); } return rcode; } /*----------------------------------------------------------------------------- - * do_fdosls -- + * do_fdosls -- *----------------------------------------------------------------------------- */ int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *path = ""; int drive = CFG_FDC_DRIVE_NUMBER; - + switch (argc) { case 1: - break; + break; case 2: - path = argv [1]; - break; + path = argv [1]; + break; } /* Init physical layer */ if (!fdc_fdos_init (drive)) { - return (-1); + return (-1); } /* Open directory */ if (dos_open (path) < 0) { - printf ("Unable to open %s\n", path); - return 1; + printf ("Unable to open %s\n", path); + return 1; } return (dos_dir ()); } -#endif +cmd_tbl_t U_BOOT_CMD(FDOS_BOOT) = MK_CMD_ENTRY( + "fdosboot", 3, 0, do_fdosboot, + "fdosboot- boot from a dos floppy file\n", + "[loadAddr] [filename]\n" +); + +cmd_tbl_t U_BOOT_CMD(FDOS_LS) = MK_CMD_ENTRY( + "fdosls", 2, 0, do_fdosls, + "fdosls - list files in a directory\n", + "[directory]\n" +); + +#endif /* CONFIG_COMMANDS & CFG_CMD_FDOS */ diff --git a/common/cmd_flash.c b/common/cmd_flash.c index efc89dc71e..6914f59d5b 100644 --- a/common/cmd_flash.c +++ b/common/cmd_flash.c @@ -26,8 +26,7 @@ */ #include #include -#include -#include + #ifdef CONFIG_HAS_DATAFLASH #include @@ -438,4 +437,41 @@ int flash_sect_protect (int p, ulong addr_first, ulong addr_last) return rcode; } + +/**************************************************/ + +cmd_tbl_t U_BOOT_CMD(FLINFO) = MK_CMD_ENTRY( + "flinfo", 2, 1, do_flinfo, + "flinfo - print FLASH memory information\n", + "\n - print information for all FLASH memory banks\n" + "flinfo N\n - print information for FLASH memory bank # N\n" +); + +cmd_tbl_t U_BOOT_CMD(ERASE) = MK_CMD_ENTRY( + "erase", 3, 1, do_flerase, + "erase - erase FLASH memory\n", + "start end\n" + " - erase FLASH from addr 'start' to addr 'end'\n" + "erase N:SF[-SL]\n - erase sectors SF-SL in FLASH bank # N\n" + "erase bank N\n - erase FLASH bank # N\n" + "erase all\n - erase all FLASH banks\n" +); + +cmd_tbl_t U_BOOT_CMD(PROTECT) = MK_CMD_ENTRY( + "protect", 4, 1, do_protect, + "protect - enable or disable FLASH write protection\n", + "on start end\n" + " - protect FLASH from addr 'start' to addr 'end'\n" + "protect on N:SF[-SL]\n" + " - protect sectors SF-SL in FLASH bank # N\n" + "protect on bank N\n - protect FLASH bank # N\n" + "protect on all\n - protect all FLASH banks\n" + "protect off start end\n" + " - make FLASH from addr 'start' to addr 'end' writable\n" + "protect off N:SF[-SL]\n" + " - make sectors SF-SL writable in FLASH bank # N\n" + "protect off bank N\n - make FLASH bank # N writable\n" + "protect off all\n - make all FLASH banks writable\n" +); + #endif /* CFG_CMD_FLASH */ diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c index 4e4c4abe9d..f8ae52a66e 100644 --- a/common/cmd_fpga.c +++ b/common/cmd_fpga.c @@ -27,11 +27,11 @@ */ #include #include -#include -#include +#include #if (CONFIG_COMMANDS & CFG_CMD_NET) #include #endif +#include #if 0 #define FPGA_DEBUG @@ -155,4 +155,13 @@ static int fpga_get_op( char *opstr ) return op; } +cmd_tbl_t U_BOOT_CMD(FPGA) = MK_CMD_ENTRY( + "fpga", 6, 1, do_fpga, + "fpga - loadable FPGA image support\n", + "fpga [operation type] [device number] [image address] [image size]\n" + "fpga operations:\n" + "\tinfo\tlist known device information.\n" + "\tload\tLoad device from memory buffer.\n" + "\tdump\tLoad device to memory buffer.\n" +); #endif /* CONFIG_FPGA && CONFIG_COMMANDS & CFG_CMD_FPGA */ diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c index fe5841e6ba..203e803a14 100644 --- a/common/cmd_i2c.c +++ b/common/cmd_i2c.c @@ -83,7 +83,6 @@ #include #include -#include #include #include @@ -865,4 +864,61 @@ int do_sdram ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #endif /* CFG_CMD_SDRAM */ + +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(IMD) = MK_CMD_ENTRY( + "imd", 4, 1, do_i2c_md, \ + "imd - i2c memory display\n", \ + "chip address[.0, .1, .2] [# of objects]\n - i2c memory display\n" \ +); + +cmd_tbl_t U_BOOT_CMD(IMM) = MK_CMD_ENTRY( + "imm", 3, 1, do_i2c_mm, + "imm - i2c memory modify (auto-incrementing)\n", + "chip address[.0, .1, .2]\n" + " - memory modify, auto increment address\n" +); +cmd_tbl_t U_BOOT_CMD(INM) = MK_CMD_ENTRY( + "inm", 3, 1, do_i2c_nm, + "inm - memory modify (constant address)\n", + "chip address[.0, .1, .2]\n - memory modify, read and keep address\n" +); + +cmd_tbl_t U_BOOT_CMD(IMW) = MK_CMD_ENTRY( + "imw", 5, 1, do_i2c_mw, + "imw - memory write (fill)\n", + "chip address[.0, .1, .2] value [count]\n - memory write (fill)\n" +); + +cmd_tbl_t U_BOOT_CMD(ICRC) = MK_CMD_ENTRY( + "icrc32", 5, 1, do_i2c_crc, + "icrc32 - checksum calculation\n", + "chip address[.0, .1, .2] count\n - compute CRC32 checksum\n" +); + +cmd_tbl_t U_BOOT_CMD(IPROBE) = MK_CMD_ENTRY( + "iprobe", 1, 1, do_i2c_probe, + "iprobe - probe to discover valid I2C chip addresses\n", + "\n -discover valid I2C chip addresses\n" +); + +/* + * Require full name for "iloop" because it is an infinite loop! + */ +cmd_tbl_t U_BOOT_CMD(ILOOP) = MK_CMD_ENTRY( + "iloop", 5, 1, do_i2c_loop, + "iloop - infinite loop on address range\n", + "chip address[.0, .1, .2] [# of objects]\n" + " - loop, reading a set of addresses\n" +); + +#if (CONFIG_COMMANDS & CFG_CMD_SDRAM) +cmd_tbl_t U_BOOT_CMD(ISDRAM) = MK_CMD_ENTRY( + "isdram", 2, 1, do_sdram, + "isdram - print SDRAM configuration information\n", + "chip\n - print SDRAM configuration information\n" + " (valid chip values 50..57)\n" +); +#endif #endif /* CFG_CMD_I2C */ diff --git a/common/cmd_ide.c b/common/cmd_ide.c index f1b24be684..c1e610ae60 100644 --- a/common/cmd_ide.c +++ b/common/cmd_ide.c @@ -39,7 +39,6 @@ #endif #include #include -#include #include #ifdef CONFIG_STATUS_LED # include @@ -798,7 +797,7 @@ output_data_short(int dev, ulong *sect_buf, int words) { ushort *dbuf; volatile ushort *pbuf; - + pbuf = (ushort *)(ATA_CURR_BASE(dev)+ATA_DATA_REG); dbuf = (ushort *)sect_buf; while (words--) { @@ -828,8 +827,6 @@ input_swap_data(int dev, ulong *sect_buf, int words) #endif /* __PPC__ */ - - #ifdef __PPC__ static void output_data(int dev, ulong *sect_buf, int words) @@ -1381,7 +1378,6 @@ static void ide_led (uchar led, uchar status) */ - #undef ATAPI_DEBUG #ifdef ATAPI_DEBUG @@ -1681,7 +1677,6 @@ error: } - static void atapi_inquiry(block_dev_desc_t * dev_desc) { unsigned char ccb[12]; /* Command descriptor block */ @@ -1816,4 +1811,23 @@ ulong atapi_read (int device, ulong blknr, ulong blkcnt, ulong *buffer) #endif /* CONFIG_ATAPI */ +cmd_tbl_t U_BOOT_CMD(IDE) = MK_CMD_ENTRY( + "ide", 5, 1, do_ide, + "ide - IDE sub-system\n", + "reset - reset IDE controller\n" + "ide info - show available IDE devices\n" + "ide device [dev] - show or set current device\n" + "ide part [dev] - print partition table of one or all IDE devices\n" + "ide read addr blk# cnt\n" + "ide write addr blk# cnt - read/write `cnt'" + " blocks starting at block `blk#'\n" + " to/from memory address `addr'\n" +); + +cmd_tbl_t U_BOOT_CMD(DISK) = MK_CMD_ENTRY( + "diskboot", 3, 1, do_diskboot, + "diskboot- boot from IDE device\n", + "loadAddr dev:part\n" +); + #endif /* CONFIG_COMMANDS & CFG_CMD_IDE */ diff --git a/common/cmd_immap.c b/common/cmd_immap.c index 3eb5895d72..fbb4a7d375 100644 --- a/common/cmd_immap.c +++ b/common/cmd_immap.c @@ -27,7 +27,6 @@ #include #include -#include #if (CONFIG_COMMANDS & CFG_CMD_IMMAP) && \ (defined(CONFIG_8xx) || defined(CONFIG_8260)) @@ -592,4 +591,112 @@ do_mccinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) unimplemented (cmdtp, flag, argc, argv); return 0; } + +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(SIUINFO) = MK_CMD_ENTRY( + "siuinfo", 1, 1, do_siuinfo, + "siuinfo - print System Interface Unit (SIU) registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(MEMCINFO) = MK_CMD_ENTRY( + "memcinfo", 1, 1, do_memcinfo, + "memcinfo- print Memory Controller registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(SITINFO) = MK_CMD_ENTRY( + "sitinfo", 1, 1, do_sitinfo, + "sitinfo - print System Integration Timers (SIT) registers\n", + NULL +); + +#ifdef CONFIG_8260 +cmd_tbl_t U_BOOT_CMD(ICINFO) = MK_CMD_ENTRY( + "icinfo", 1, 1, do_icinfo, + "icinfo - print Interrupt Controller registers\n", + NULL +); +#endif + +cmd_tbl_t U_BOOT_CMD(CARINFO) = MK_CMD_ENTRY( + "carinfo", 1, 1, do_carinfo, + "carinfo - print Clocks and Reset registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(IOPINFO) = MK_CMD_ENTRY( + "iopinfo", 1, 1, do_iopinfo, + "iopinfo - print I/O Port registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(IOPSET) = MK_CMD_ENTRY( + "iopset", 5, 0, do_iopset, + "iopset - set I/O Port registers\n", + "PORT PIN CMD VALUE\nPORT: A-D, PIN: 0-31, CMD: [dat|dir|odr|sor], VALUE: 0|1" +); + +cmd_tbl_t U_BOOT_CMD(DMAINFO) = MK_CMD_ENTRY( + "dmainfo", 1, 1, do_dmainfo, + "dmainfo - print SDMA/IDMA registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(FCCINFO) = MK_CMD_ENTRY( + "fccinfo", 1, 1, do_fccinfo, + "fccinfo - print FCC registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(BRGINFO) = MK_CMD_ENTRY( + "brginfo", 1, 1, do_brginfo, + "brginfo - print Baud Rate Generator (BRG) registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(I2CINFO) = MK_CMD_ENTRY( + "i2cinfo", 1, 1, do_i2cinfo, + "i2cinfo - print I2C registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(SCCINFO) = MK_CMD_ENTRY( + "sccinfo", 1, 1, do_sccinfo, + "sccinfo - print SCC registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(SMCINFO) = MK_CMD_ENTRY( + "smcinfo", 1, 1, do_smcinfo, + "smcinfo - print SMC registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(SPIINFO) = MK_CMD_ENTRY( + "spiinfo", 1, 1, do_spiinfo, + "spiinfo - print Serial Peripheral Interface (SPI) registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(MUXINFO) = MK_CMD_ENTRY( + "muxinfo", 1, 1, do_muxinfo, + "muxinfo - print CPM Multiplexing registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(SIINFO) = MK_CMD_ENTRY( + "siinfo", 1, 1, do_siinfo, + "siinfo - print Serial Interface (SI) registers\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(MCCINFO) = MK_CMD_ENTRY( + "mccinfo", 1, 1, do_mccinfo, + "mccinfo - print MCC registers\n", + NULL +); + + #endif /* CFG_CMD_IMMAP && (CONFIG_8xx || CONFIG_8260) */ diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c index 8df80612a7..e45a2ced00 100644 --- a/common/cmd_jffs2.c +++ b/common/cmd_jffs2.c @@ -26,14 +26,11 @@ */ #include #include -#include -#include #include +#include #include #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) - -#include static int part_num=0; #ifndef CFG_JFFS_CUSTOM_PART @@ -83,6 +80,9 @@ jffs2_part_info(int part_num) int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { + struct part_info* jffs2_part_info(int); + int jffs2_1pass_load(char *, struct part_info *,const char *); + char *filename = "uImage"; ulong offset = CFG_LOAD_ADDR; int size; @@ -120,7 +120,10 @@ do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - char *filename = "/"; + struct part_info* jffs2_part_info(int); + int jffs2_1pass_ls(struct part_info *,char *); + + char *filename = "/"; int ret; struct part_info *part; @@ -140,6 +143,9 @@ do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { + struct part_info* jffs2_part_info(int); + int jffs2_1pass_info(struct part_info *); + int ret; struct part_info *part; @@ -157,8 +163,9 @@ int do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int tmp_part; + struct part_info* jffs2_part_info(int); - if (argc >= 2) { + if (argc >= 2) { tmp_part = simple_strtoul(argv[1], NULL, 16); }else{ printf("Need partition number in argument list\n"); @@ -176,4 +183,34 @@ do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } + +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(JFFS2_FSLOAD) = MK_CMD_ENTRY( + "fsload", 3, 0, do_jffs2_fsload, + "fsload - load binary file from a filesystem image\n", + "[ off ] [ filename ]\n" + " - load binary file from flash bank\n" + " with offset 'off'\n" +); + +cmd_tbl_t U_BOOT_CMD(JFFS2_FSINFO) = MK_CMD_ENTRY( + "fsinfo", 1, 1, do_jffs2_fsinfo, + "fsinfo - print information about filesystems\n", + " - print information about filesystems\n" +); + +cmd_tbl_t U_BOOT_CMD(JFFS2_LS) = MK_CMD_ENTRY( + "ls", 2, 1, do_jffs2_ls, + "ls - list files in a directory (default /)\n", + "[ directory ]\n" + " - list files in a directory.\n" +); + +cmd_tbl_t U_BOOT_CMD(JFFS2_CHPART) = MK_CMD_ENTRY( + "chpart", 2, 0, do_jffs2_chpart, + "chpart - change active partition\n", + " - change active partition\n" +); + #endif /* CFG_CMD_JFFS2 */ diff --git a/common/cmd_load.c b/common/cmd_load.c new file mode 100644 index 0000000000..d784e83728 --- /dev/null +++ b/common/cmd_load.c @@ -0,0 +1,1057 @@ +/* + * (C) Copyright 2000-2003 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * 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 + */ + +/* + * Serial up- and download support + */ +#include +#include +#include +#include +#include +#include + + +#if (CONFIG_COMMANDS & CFG_CMD_LOADS) +static ulong load_serial (ulong offset); +static int read_record (char *buf, ulong len); +# if (CONFIG_COMMANDS & CFG_CMD_SAVES) +static int save_serial (ulong offset, ulong size); +static int write_record (char *buf); +# endif /* CFG_CMD_SAVES */ + +static int do_echo = 1; +#endif /* CFG_CMD_LOADS */ + +/* -------------------------------------------------------------------- */ + +#if (CONFIG_COMMANDS & CFG_CMD_LOADS) +int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + ulong offset = 0; + ulong addr; + int i; + char *env_echo; + int rcode = 0; +#ifdef CFG_LOADS_BAUD_CHANGE + DECLARE_GLOBAL_DATA_PTR; + int load_baudrate, current_baudrate; + + load_baudrate = current_baudrate = gd->baudrate; +#endif + + if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) { + do_echo = 1; + } else { + do_echo = 0; + } + +#ifdef CFG_LOADS_BAUD_CHANGE + if (argc >= 2) { + offset = simple_strtoul(argv[1], NULL, 16); + } + if (argc == 3) { + load_baudrate = (int)simple_strtoul(argv[2], NULL, 10); + + /* default to current baudrate */ + if (load_baudrate == 0) + load_baudrate = current_baudrate; + } + if (load_baudrate != current_baudrate) { + printf ("## Switch baudrate to %d bps and press ENTER ...\n", + load_baudrate); + udelay(50000); + gd->baudrate = load_baudrate; + serial_setbrg (); + udelay(50000); + for (;;) { + if (getc() == '\r') + break; + } + } +#else /* ! CFG_LOADS_BAUD_CHANGE */ + if (argc == 2) { + offset = simple_strtoul(argv[1], NULL, 16); + } +#endif /* CFG_LOADS_BAUD_CHANGE */ + + printf ("## Ready for S-Record download ...\n"); + + addr = load_serial (offset); + + /* + * Gather any trailing characters (for instance, the ^D which + * is sent by 'cu' after sending a file), and give the + * box some time (100 * 1 ms) + */ + for (i=0; i<100; ++i) { + if (serial_tstc()) { + (void) serial_getc(); + } + udelay(1000); + } + + if (addr == ~0) { + printf ("## S-Record download aborted\n"); + rcode = 1; + } else { + printf ("## Start Addr = 0x%08lX\n", addr); + load_addr = addr; + } + +#ifdef CFG_LOADS_BAUD_CHANGE + if (load_baudrate != current_baudrate) { + printf ("## Switch baudrate to %d bps and press ESC ...\n", + current_baudrate); + udelay (50000); + gd->baudrate = current_baudrate; + serial_setbrg (); + udelay (50000); + for (;;) { + if (getc() == 0x1B) /* ESC */ + break; + } + } +#endif + return rcode; +} + +static ulong +load_serial (ulong offset) +{ + char record[SREC_MAXRECLEN + 1]; /* buffer for one S-Record */ + char binbuf[SREC_MAXBINLEN]; /* buffer for binary data */ + int binlen; /* no. of data bytes in S-Rec. */ + int type; /* return code for record type */ + ulong addr; /* load address from S-Record */ + ulong size; /* number of bytes transferred */ + char buf[32]; + ulong store_addr; + ulong start_addr = ~0; + ulong end_addr = 0; + int line_count = 0; + + while (read_record(record, SREC_MAXRECLEN + 1) >= 0) { + type = srec_decode (record, &binlen, &addr, binbuf); + + if (type < 0) { + return (~0); /* Invalid S-Record */ + } + + switch (type) { + case SREC_DATA2: + case SREC_DATA3: + case SREC_DATA4: + store_addr = addr + offset; +#ifndef CFG_NO_FLASH + if (addr2info(store_addr)) { + int rc; + + rc = flash_write((uchar *)binbuf,store_addr,binlen); + if (rc != 0) { + flash_perror (rc); + return (~0); + } + } else +#endif + { + memcpy ((char *)(store_addr), binbuf, binlen); + } + if ((store_addr) < start_addr) + start_addr = store_addr; + if ((store_addr + binlen - 1) > end_addr) + end_addr = store_addr + binlen - 1; + break; + case SREC_END2: + case SREC_END3: + case SREC_END4: + udelay (10000); + size = end_addr - start_addr + 1; + printf ("\n" + "## First Load Addr = 0x%08lX\n" + "## Last Load Addr = 0x%08lX\n" + "## Total Size = 0x%08lX = %ld Bytes\n", + start_addr, end_addr, size, size + ); + flush_cache (addr, size); + sprintf(buf, "%lX", size); + setenv("filesize", buf); + return (addr); + case SREC_START: + break; + default: + break; + } + if (!do_echo) { /* print a '.' every 100 lines */ + if ((++line_count % 100) == 0) + putc ('.'); + } + } + + return (~0); /* Download aborted */ +} + +static int +read_record (char *buf, ulong len) +{ + char *p; + char c; + + --len; /* always leave room for terminating '\0' byte */ + + for (p=buf; p < buf+len; ++p) { + c = serial_getc(); /* read character */ + if (do_echo) + serial_putc (c); /* ... and echo it */ + + switch (c) { + case '\r': + case '\n': + *p = '\0'; + return (p - buf); + case '\0': + case 0x03: /* ^C - Control C */ + return (-1); + default: + *p = c; + } + + /* Check for the console hangup (if any different from serial) */ +#ifdef CONFIG_PPC /* we don't have syscall_tbl anywhere else */ + if (syscall_tbl[SYSCALL_GETC] != serial_getc) { + if (ctrlc()) { + return (-1); + } + } +#endif + } + + /* line too long - truncate */ + *p = '\0'; + return (p - buf); +} + +#if (CONFIG_COMMANDS & CFG_CMD_SAVES) + +int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + ulong offset = 0; + ulong size = 0; +#ifdef CFG_LOADS_BAUD_CHANGE + DECLARE_GLOBAL_DATA_PTR; + int save_baudrate, current_baudrate; + + save_baudrate = current_baudrate = gd->baudrate; +#endif + + if (argc >= 2) { + offset = simple_strtoul(argv[1], NULL, 16); + } +#ifdef CFG_LOADS_BAUD_CHANGE + if (argc >= 3) { + size = simple_strtoul(argv[2], NULL, 16); + } + if (argc == 4) { + save_baudrate = (int)simple_strtoul(argv[3], NULL, 10); + + /* default to current baudrate */ + if (save_baudrate == 0) + save_baudrate = current_baudrate; + } + if (save_baudrate != current_baudrate) { + printf ("## Switch baudrate to %d bps and press ENTER ...\n", + save_baudrate); + udelay(50000); + gd->baudrate = save_baudrate; + serial_setbrg (); + udelay(50000); + for (;;) { + if (getc() == '\r') + break; + } + } +#else /* ! CFG_LOADS_BAUD_CHANGE */ + if (argc == 3) { + size = simple_strtoul(argv[2], NULL, 16); + } +#endif /* CFG_LOADS_BAUD_CHANGE */ + + printf ("## Ready for S-Record upload, press ENTER to proceed ...\n"); + for (;;) { + if (getc() == '\r') + break; + } + if(save_serial (offset, size)) { + printf ("## S-Record upload aborted\n"); + } else { + printf ("## S-Record upload complete\n"); + } +#ifdef CFG_LOADS_BAUD_CHANGE + if (save_baudrate != current_baudrate) { + printf ("## Switch baudrate to %d bps and press ESC ...\n", + (int)current_baudrate); + udelay (50000); + gd->baudrate = current_baudrate; + serial_setbrg (); + udelay (50000); + for (;;) { + if (getc() == 0x1B) /* ESC */ + break; + } + } +#endif + return 0; +} + +#define SREC3_START "S0030000FC\n" +#define SREC3_FORMAT "S3%02X%08lX%s%02X\n" +#define SREC3_END "S70500000000FA\n" +#define SREC_BYTES_PER_RECORD 16 + +static int save_serial (ulong address, ulong count) +{ + int i, c, reclen, checksum, length; + char *hex = "0123456789ABCDEF"; + char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */ + char data[2*SREC_BYTES_PER_RECORD+1]; /* buffer for hex data */ + + reclen = 0; + checksum = 0; + + if(write_record(SREC3_START)) /* write the header */ + return (-1); + do { + if(count) { /* collect hex data in the buffer */ + c = *(volatile uchar*)(address + reclen); /* get one byte */ + checksum += c; /* accumulate checksum */ + data[2*reclen] = hex[(c>>4)&0x0f]; + data[2*reclen+1] = hex[c & 0x0f]; + data[2*reclen+2] = '\0'; + ++reclen; + --count; + } + if(reclen == SREC_BYTES_PER_RECORD || count == 0) { + /* enough data collected for one record: dump it */ + if(reclen) { /* build & write a data record: */ + /* address + data + checksum */ + length = 4 + reclen + 1; + + /* accumulate length bytes into checksum */ + for(i = 0; i < 2; i++) + checksum += (length >> (8*i)) & 0xff; + + /* accumulate address bytes into checksum: */ + for(i = 0; i < 4; i++) + checksum += (address >> (8*i)) & 0xff; + + /* make proper checksum byte: */ + checksum = ~checksum & 0xff; + + /* output one record: */ + sprintf(record, SREC3_FORMAT, length, address, data, checksum); + if(write_record(record)) + return (-1); + } + address += reclen; /* increment address */ + checksum = 0; + reclen = 0; + } + } + while(count); + if(write_record(SREC3_END)) /* write the final record */ + return (-1); + return(0); +} + +static int +write_record (char *buf) +{ + char c; + + while((c = *buf++)) + serial_putc(c); + + /* Check for the console hangup (if any different from serial) */ + + if (ctrlc()) { + return (-1); + } + return (0); +} +# endif /* CFG_CMD_SAVES */ + +#endif /* CFG_CMD_LOADS */ + + +#if (CONFIG_COMMANDS & CFG_CMD_LOADB) /* loadb command (load binary) included */ + +#define XON_CHAR 17 +#define XOFF_CHAR 19 +#define START_CHAR 0x01 +#define ETX_CHAR 0x03 +#define END_CHAR 0x0D +#define SPACE 0x20 +#define K_ESCAPE 0x23 +#define SEND_TYPE 'S' +#define DATA_TYPE 'D' +#define ACK_TYPE 'Y' +#define NACK_TYPE 'N' +#define BREAK_TYPE 'B' +#define tochar(x) ((char) (((x) + SPACE) & 0xff)) +#define untochar(x) ((int) (((x) - SPACE) & 0xff)) + +extern int os_data_count; +extern int os_data_header[8]; + +static void set_kerm_bin_mode(unsigned long *); +static int k_recv(void); +static ulong load_serial_bin (ulong offset); + + +char his_eol; /* character he needs at end of packet */ +int his_pad_count; /* number of pad chars he needs */ +char his_pad_char; /* pad chars he needs */ +char his_quote; /* quote chars he'll use */ + +int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + DECLARE_GLOBAL_DATA_PTR; + + ulong offset = 0; + ulong addr; + int load_baudrate, current_baudrate; + int rcode = 0; + char *s; + + /* pre-set offset from CFG_LOAD_ADDR */ + offset = CFG_LOAD_ADDR; + + /* pre-set offset from $loadaddr */ + if ((s = getenv("loadaddr")) != NULL) { + offset = simple_strtoul(s, NULL, 16); + } + + load_baudrate = current_baudrate = gd->baudrate; + + if (argc >= 2) { + offset = simple_strtoul(argv[1], NULL, 16); + } + if (argc == 3) { + load_baudrate = (int)simple_strtoul(argv[2], NULL, 10); + + /* default to current baudrate */ + if (load_baudrate == 0) + load_baudrate = current_baudrate; + } + + if (load_baudrate != current_baudrate) { + printf ("## Switch baudrate to %d bps and press ENTER ...\n", + load_baudrate); + udelay(50000); + gd->baudrate = load_baudrate; + serial_setbrg (); + udelay(50000); + for (;;) { + if (getc() == '\r') + break; + } + } + + printf ("## Ready for binary (kermit) download " + "to 0x%08lX at %d bps...\n", + offset, + current_baudrate); + addr = load_serial_bin (offset); + + if (addr == ~0) { + load_addr = 0; + printf ("## Binary (kermit) download aborted\n"); + rcode = 1; + } else { + printf ("## Start Addr = 0x%08lX\n", addr); + load_addr = addr; + } + + if (load_baudrate != current_baudrate) { + printf ("## Switch baudrate to %d bps and press ESC ...\n", + current_baudrate); + udelay (50000); + gd->baudrate = current_baudrate; + serial_setbrg (); + udelay (50000); + for (;;) { + if (getc() == 0x1B) /* ESC */ + break; + } + } + +#ifdef CONFIG_AUTOSCRIPT + if (load_addr) { + char *s; + + if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) { + printf("Running autoscript at addr 0x%08lX ...\n", load_addr); + rcode = autoscript (load_addr); + } + } +#endif + return rcode; +} + + +static ulong load_serial_bin (ulong offset) +{ + int size, i; + char buf[32]; + + set_kerm_bin_mode ((ulong *) offset); + size = k_recv (); + + /* + * Gather any trailing characters (for instance, the ^D which + * is sent by 'cu' after sending a file), and give the + * box some time (100 * 1 ms) + */ + for (i=0; i<100; ++i) { + if (serial_tstc()) { + (void) serial_getc(); + } + udelay(1000); + } + + flush_cache (offset, size); + + printf("## Total Size = 0x%08x = %d Bytes\n", size, size); + sprintf(buf, "%X", size); + setenv("filesize", buf); + + return offset; +} + +void send_pad (void) +{ + int count = his_pad_count; + + while (count-- > 0) + serial_putc (his_pad_char); +} + +/* converts escaped kermit char to binary char */ +char ktrans (char in) +{ + if ((in & 0x60) == 0x40) { + return (char) (in & ~0x40); + } else if ((in & 0x7f) == 0x3f) { + return (char) (in | 0x40); + } else + return in; +} + +int chk1 (char *buffer) +{ + int total = 0; + + while (*buffer) { + total += *buffer++; + } + return (int) ((total + ((total >> 6) & 0x03)) & 0x3f); +} + +void s1_sendpacket (char *packet) +{ + send_pad (); + while (*packet) { + serial_putc (*packet++); + } +} + +static char a_b[24]; +void send_ack (int n) +{ + a_b[0] = START_CHAR; + a_b[1] = tochar (3); + a_b[2] = tochar (n); + a_b[3] = ACK_TYPE; + a_b[4] = '\0'; + a_b[4] = tochar (chk1 (&a_b[1])); + a_b[5] = his_eol; + a_b[6] = '\0'; + s1_sendpacket (a_b); +} + +void send_nack (int n) +{ + a_b[0] = START_CHAR; + a_b[1] = tochar (3); + a_b[2] = tochar (n); + a_b[3] = NACK_TYPE; + a_b[4] = '\0'; + a_b[4] = tochar (chk1 (&a_b[1])); + a_b[5] = his_eol; + a_b[6] = '\0'; + s1_sendpacket (a_b); +} + + +/* os_data_* takes an OS Open image and puts it into memory, and + puts the boot header in an array named os_data_header + + if image is binary, no header is stored in os_data_header. +*/ +void (*os_data_init) (void); +void (*os_data_char) (char new_char); +static int os_data_state, os_data_state_saved; +int os_data_count; +static int os_data_count_saved; +static char *os_data_addr, *os_data_addr_saved; +static char *bin_start_address; +int os_data_header[8]; +static void bin_data_init (void) +{ + os_data_state = 0; + os_data_count = 0; + os_data_addr = bin_start_address; +} +static void os_data_save (void) +{ + os_data_state_saved = os_data_state; + os_data_count_saved = os_data_count; + os_data_addr_saved = os_data_addr; +} +static void os_data_restore (void) +{ + os_data_state = os_data_state_saved; + os_data_count = os_data_count_saved; + os_data_addr = os_data_addr_saved; +} +static void bin_data_char (char new_char) +{ + switch (os_data_state) { + case 0: /* data */ + *os_data_addr++ = new_char; + --os_data_count; + break; + } +} +static void set_kerm_bin_mode (unsigned long *addr) +{ + bin_start_address = (char *) addr; + os_data_init = bin_data_init; + os_data_char = bin_data_char; +} + + +/* k_data_* simply handles the kermit escape translations */ +static int k_data_escape, k_data_escape_saved; +void k_data_init (void) +{ + k_data_escape = 0; + os_data_init (); +} +void k_data_save (void) +{ + k_data_escape_saved = k_data_escape; + os_data_save (); +} +void k_data_restore (void) +{ + k_data_escape = k_data_escape_saved; + os_data_restore (); +} +void k_data_char (char new_char) +{ + if (k_data_escape) { + /* last char was escape - translate this character */ + os_data_char (ktrans (new_char)); + k_data_escape = 0; + } else { + if (new_char == his_quote) { + /* this char is escape - remember */ + k_data_escape = 1; + } else { + /* otherwise send this char as-is */ + os_data_char (new_char); + } + } +} + +#define SEND_DATA_SIZE 20 +char send_parms[SEND_DATA_SIZE]; +char *send_ptr; + +/* handle_send_packet interprits the protocol info and builds and + sends an appropriate ack for what we can do */ +void handle_send_packet (int n) +{ + int length = 3; + int bytes; + + /* initialize some protocol parameters */ + his_eol = END_CHAR; /* default end of line character */ + his_pad_count = 0; + his_pad_char = '\0'; + his_quote = K_ESCAPE; + + /* ignore last character if it filled the buffer */ + if (send_ptr == &send_parms[SEND_DATA_SIZE - 1]) + --send_ptr; + bytes = send_ptr - send_parms; /* how many bytes we'll process */ + do { + if (bytes-- <= 0) + break; + /* handle MAXL - max length */ + /* ignore what he says - most I'll take (here) is 94 */ + a_b[++length] = tochar (94); + if (bytes-- <= 0) + break; + /* handle TIME - time you should wait for my packets */ + /* ignore what he says - don't wait for my ack longer than 1 second */ + a_b[++length] = tochar (1); + if (bytes-- <= 0) + break; + /* handle NPAD - number of pad chars I need */ + /* remember what he says - I need none */ + his_pad_count = untochar (send_parms[2]); + a_b[++length] = tochar (0); + if (bytes-- <= 0) + break; + /* handle PADC - pad chars I need */ + /* remember what he says - I need none */ + his_pad_char = ktrans (send_parms[3]); + a_b[++length] = 0x40; /* He should ignore this */ + if (bytes-- <= 0) + break; + /* handle EOL - end of line he needs */ + /* remember what he says - I need CR */ + his_eol = untochar (send_parms[4]); + a_b[++length] = tochar (END_CHAR); + if (bytes-- <= 0) + break; + /* handle QCTL - quote control char he'll use */ + /* remember what he says - I'll use '#' */ + his_quote = send_parms[5]; + a_b[++length] = '#'; + if (bytes-- <= 0) + break; + /* handle QBIN - 8-th bit prefixing */ + /* ignore what he says - I refuse */ + a_b[++length] = 'N'; + if (bytes-- <= 0) + break; + /* handle CHKT - the clock check type */ + /* ignore what he says - I do type 1 (for now) */ + a_b[++length] = '1'; + if (bytes-- <= 0) + break; + /* handle REPT - the repeat prefix */ + /* ignore what he says - I refuse (for now) */ + a_b[++length] = 'N'; + if (bytes-- <= 0) + break; + /* handle CAPAS - the capabilities mask */ + /* ignore what he says - I only do long packets - I don't do windows */ + a_b[++length] = tochar (2); /* only long packets */ + a_b[++length] = tochar (0); /* no windows */ + a_b[++length] = tochar (94); /* large packet msb */ + a_b[++length] = tochar (94); /* large packet lsb */ + } while (0); + + a_b[0] = START_CHAR; + a_b[1] = tochar (length); + a_b[2] = tochar (n); + a_b[3] = ACK_TYPE; + a_b[++length] = '\0'; + a_b[length] = tochar (chk1 (&a_b[1])); + a_b[++length] = his_eol; + a_b[++length] = '\0'; + s1_sendpacket (a_b); +} + +/* k_recv receives a OS Open image file over kermit line */ +static int k_recv (void) +{ + char new_char; + char k_state, k_state_saved; + int sum; + int done; + int length; + int n, last_n; + int z = 0; + int len_lo, len_hi; + + /* initialize some protocol parameters */ + his_eol = END_CHAR; /* default end of line character */ + his_pad_count = 0; + his_pad_char = '\0'; + his_quote = K_ESCAPE; + + /* initialize the k_recv and k_data state machine */ + done = 0; + k_state = 0; + k_data_init (); + k_state_saved = k_state; + k_data_save (); + n = 0; /* just to get rid of a warning */ + last_n = -1; + + /* expect this "type" sequence (but don't check): + S: send initiate + F: file header + D: data (multiple) + Z: end of file + B: break transmission + */ + + /* enter main loop */ + while (!done) { + /* set the send packet pointer to begining of send packet parms */ + send_ptr = send_parms; + + /* With each packet, start summing the bytes starting with the length. + Save the current sequence number. + Note the type of the packet. + If a character less than SPACE (0x20) is received - error. + */ + +#if 0 + /* OLD CODE, Prior to checking sequence numbers */ + /* first have all state machines save current states */ + k_state_saved = k_state; + k_data_save (); +#endif + + /* get a packet */ + /* wait for the starting character or ^C */ + for (;;) { + switch (serial_getc ()) { + case START_CHAR: /* start packet */ + goto START; + case ETX_CHAR: /* ^C waiting for packet */ + return (0); + default: + ; + } + } +START: + /* get length of packet */ + sum = 0; + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + sum += new_char & 0xff; + length = untochar (new_char); + /* get sequence number */ + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + sum += new_char & 0xff; + n = untochar (new_char); + --length; + + /* NEW CODE - check sequence numbers for retried packets */ + /* Note - this new code assumes that the sequence number is correctly + * received. Handling an invalid sequence number adds another layer + * of complexity that may not be needed - yet! At this time, I'm hoping + * that I don't need to buffer the incoming data packets and can write + * the data into memory in real time. + */ + if (n == last_n) { + /* same sequence number, restore the previous state */ + k_state = k_state_saved; + k_data_restore (); + } else { + /* new sequence number, checkpoint the download */ + last_n = n; + k_state_saved = k_state; + k_data_save (); + } + /* END NEW CODE */ + + /* get packet type */ + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + sum += new_char & 0xff; + k_state = new_char; + --length; + /* check for extended length */ + if (length == -2) { + /* (length byte was 0, decremented twice) */ + /* get the two length bytes */ + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + sum += new_char & 0xff; + len_hi = untochar (new_char); + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + sum += new_char & 0xff; + len_lo = untochar (new_char); + length = len_hi * 95 + len_lo; + /* check header checksum */ + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f)) + goto packet_error; + sum += new_char & 0xff; +/* --length; */ /* new length includes only data and block check to come */ + } + /* bring in rest of packet */ + while (length > 1) { + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + sum += new_char & 0xff; + --length; + if (k_state == DATA_TYPE) { + /* pass on the data if this is a data packet */ + k_data_char (new_char); + } else if (k_state == SEND_TYPE) { + /* save send pack in buffer as is */ + *send_ptr++ = new_char; + /* if too much data, back off the pointer */ + if (send_ptr >= &send_parms[SEND_DATA_SIZE]) + --send_ptr; + } + } + /* get and validate checksum character */ + new_char = serial_getc (); + if ((new_char & 0xE0) == 0) + goto packet_error; + if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f)) + goto packet_error; + /* get END_CHAR */ + new_char = serial_getc (); + if (new_char != END_CHAR) { + packet_error: + /* restore state machines */ + k_state = k_state_saved; + k_data_restore (); + /* send a negative acknowledge packet in */ + send_nack (n); + } else if (k_state == SEND_TYPE) { + /* crack the protocol parms, build an appropriate ack packet */ + handle_send_packet (n); + } else { + /* send simple acknowledge packet in */ + send_ack (n); + /* quit if end of transmission */ + if (k_state == BREAK_TYPE) + done = 1; + } + ++z; + } + return ((ulong) os_data_addr - (ulong) bin_start_address); +} +#endif /* CFG_CMD_LOADB */ + +/* -------------------------------------------------------------------- */ + +#if (CONFIG_COMMANDS & CFG_CMD_LOADS) + +#ifdef CFG_LOADS_BAUD_CHANGE +cmd_tbl_t U_BOOT_CMD(LOADS) = MK_CMD_ENTRY( + "loads", 3, 0, do_load_serial, + "loads - load S-Record file over serial line\n", + "[ off ] [ baud ]\n" + " - load S-Record file over serial line" + " with offset 'off' and baudrate 'baud'\n" +); + +#else /* ! CFG_LOADS_BAUD_CHANGE */ +cmd_tbl_t U_BOOT_CMD(LOADS) = MK_CMD_ENTRY( + "loads", 2, 0, do_load_serial, + "loads - load S-Record file over serial line\n", + "[ off ]\n" + " - load S-Record file over serial line with offset 'off'\n" +); +#endif /* CFG_LOADS_BAUD_CHANGE */ + +/* + * SAVES always requires LOADS support, but not vice versa + */ + + +#if (CONFIG_COMMANDS & CFG_CMD_SAVES) +#ifdef CFG_LOADS_BAUD_CHANGE +cmd_tbl_t U_BOOT_CMD(SAVES) = MK_CMD_ENTRY( + "saves", 4, 0, do_save_serial, + "saves - save S-Record file over serial line\n", + "[ off ] [size] [ baud ]\n" + " - save S-Record file over serial line" + " with offset 'off', size 'size' and baudrate 'baud'\n" +); +#else /* ! CFG_LOADS_BAUD_CHANGE */ +cmd_tbl_t U_BOOT_CMD(SAVES) = MK_CMD_ENTRY( + "saves", 3, 0, do_save_serial, + "saves - save S-Record file over serial line\n", + "[ off ] [size]\n" + " - save S-Record file over serial line with offset 'off' and size 'size'\n" +); +#endif /* CFG_LOADS_BAUD_CHANGE */ +#endif /* CFG_CMD_SAVES */ +#endif /* CFG_CMD_LOADS */ + + +#if (CONFIG_COMMANDS & CFG_CMD_LOADB) +cmd_tbl_t U_BOOT_CMD(LOADB) = MK_CMD_ENTRY( + "loadb", 3, 0, do_load_serial_bin, + "loadb - load binary file over serial line (kermit mode)\n", + "[ off ] [ baud ]\n" + " - load binary file over serial line" + " with offset 'off' and baudrate 'baud'\n" +); + +#endif /* CFG_CMD_LOADB */ + +/* -------------------------------------------------------------------- */ + +#if (CONFIG_COMMANDS & CFG_CMD_HWFLOW) +int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + extern int hwflow_onoff(int); + + if (argc == 2) { + if (strcmp(argv[1], "off") == 0) + hwflow_onoff(-1); + else + if (strcmp(argv[1], "on") == 0) + hwflow_onoff(1); + else + printf("Usage: %s\n", cmdtp->usage); + } + printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off"); + return 0; +} + +/* -------------------------------------------------------------------- */ + +cmd_tbl_t U_BOOT_CMD(HWFLOW) = MK_CMD_ENTRY( + "hwflow [on|off]", 2, 0, do_hwflow, + "hwflow - turn the harwdare flow control on/off\n", + "\n - change RTS/CTS hardware flow control over serial line\n" +); + +#endif /* CFG_CMD_HWFLOW */ diff --git a/common/cmd_log.c b/common/cmd_log.c index 84306efc41..b07dc7533c 100644 --- a/common/cmd_log.c +++ b/common/cmd_log.c @@ -195,7 +195,16 @@ int do_log (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } } - +#if defined(CONFIG_LOGBUFFER) +cmd_tbl_t U_BOOT_CMD(LOG) = MK_CMD_ENTRY( + "log", 255, 1, do_log, + "log - manipulate logbuffer\n", + "log info - show pointer details\n" + "log reset - clear contents\n" + "log show - show contents\n" + "log append - append to the logbuffer\n" +); +#endif /* CONFIG_LOGBUFFER */ static int logbuff_printk(const char *line) { int i; diff --git a/common/cmd_mem.c b/common/cmd_mem.c index aca69260ac..944aada1ee 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -29,7 +29,6 @@ #include #include -#include #if (CONFIG_COMMANDS & CFG_CMD_MMC) #include #endif @@ -148,7 +147,7 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } addr += size; } - + } else { /* addr does not correspond to DataFlash */ #endif for (i=0; i #include -#include #include #if (CONFIG_COMMANDS & CFG_CMD_MII) @@ -128,4 +127,15 @@ int do_mii (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return rcode; } +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(MII) = MK_CMD_ENTRY( + "mii", 5, 1, do_mii, + "mii - MII utility commands\n", + "info - display MII PHY info\n" + "mii read - read MII PHY register \n" + "mii write - write MII PHY register \n" +); + + #endif /* CFG_CMD_MII */ diff --git a/common/cmd_misc.c b/common/cmd_misc.c index e3e0e44869..76fe26733a 100644 --- a/common/cmd_misc.c +++ b/common/cmd_misc.c @@ -52,5 +52,22 @@ int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } return 0; } +/* Implemented in $(CPU)/interrupts.c */ +#if (CONFIG_COMMANDS & CFG_CMD_IRQ) +int do_irqinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); + +cmd_tbl_t U_BOOT_CMD(IRQINFO) = MK_CMD_ENTRY( + "irqinfo", 1, 1, do_irqinfo, + "irqinfo - print information about IRQs\n", + NULL +); +#endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */ + +cmd_tbl_t U_BOOT_CMD(MISC) = MK_CMD_ENTRY( + "sleep" , 2, 2, do_sleep, + "sleep - delay execution for some time\n", + "N\n" + " - delay execution for N seconds (N is _decimal_ !!!)\n" +); #endif /* CFG_CMD_MISC */ diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 4b27c77c45..41f84fdc0f 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -98,7 +98,7 @@ int do_nand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) printf ("Usage:\n%s\n", cmdtp->usage); return 1; case 2: - if (strcmp(argv[1],"info") == 0) { + if (strcmp(argv[1],"info") == 0) { int i; putc ('\n'); @@ -376,7 +376,7 @@ int check_block(struct nand_chip* nand, unsigned long pos) return 0; } - + /* print bad blocks in NAND flash */ static void nand_print_bad(struct nand_chip* nand) { @@ -473,7 +473,7 @@ static void nand_print(struct nand_chip *nand) nand->totlen >> 20, nand->erasesize >> 10); } else { - printf("%s at 0x%lx (", nand->chips_name, nand->IO_ADDR); + printf("%s at 0x%lx (", nand->chips_name, nand->IO_ADDR); print_size(nand->totlen, ", "); print_size(nand->erasesize, " sector)\n"); } @@ -599,7 +599,7 @@ static int NanD_IdentChip(struct nand_chip *nand, int floor, int chip) id = READ_NAND(nand->IO_ADDR); - NAND_DISABLE_CE(nand); /* set pin high */ + NAND_DISABLE_CE(nand); /* set pin high */ /* No response - return failure */ if (mfr == 0xff || mfr == 0) { printf("NanD_Command (ReadID) got %d %d\n", mfr, id); @@ -806,7 +806,7 @@ static int nand_read_ecc(struct nand_chip *nand, size_t start, size_t len, goto readdata; /* Send the read command */ NanD_Command(nand, NAND_CMD_READ0); - NanD_Address(nand, ADDR_COLUMN_PAGE, (page << nand->page_shift) + col); + NanD_Address(nand, ADDR_COLUMN_PAGE, (page << nand->page_shift) + col); /* Read in a page + oob data */ NanD_ReadBuf(nand, nand->data_buf, nand->oobblock + nand->oobsize); @@ -873,7 +873,7 @@ readdata: #else /* Send the read command */ NanD_Command(nand, NAND_CMD_READ0); - NanD_Address(nand, ADDR_COLUMN_PAGE, (page << nand->page_shift) + col); + NanD_Address(nand, ADDR_COLUMN_PAGE, (page << nand->page_shift) + col); /* Read the data directly into the return buffer */ if ((*retlen + (nand->oobblock - col)) >= len) { NanD_ReadBuf(nand, buf + *retlen, len - *retlen); @@ -1136,11 +1136,11 @@ static int nand_read_oob(struct nand_chip* nand, size_t ofs, size_t len, *retlen = len; /* Reading the full OOB data drops us off of the end of the page, - * causing the flash device to go into busy mode, so we need - * to wait until ready 11.4.1 and Toshiba TC58256FT nands */ + * causing the flash device to go into busy mode, so we need + * to wait until ready 11.4.1 and Toshiba TC58256FT nands */ ret = NanD_WaitReady(nand); - NAND_DISABLE_CE(nand); /* set pin high */ + NAND_DISABLE_CE(nand); /* set pin high */ return ret; @@ -1244,7 +1244,7 @@ static int nand_erase(struct nand_chip* nand, size_t ofs, size_t len, int clean) if (ofs & (nand->erasesize-1) || len & (nand->erasesize-1)) { printf ("Offset and size must be sector aligned, erasesize = %d\n", - (int) nand->erasesize); + (int) nand->erasesize); return -1; } diff --git a/common/cmd_net.c b/common/cmd_net.c index e8bf0ae9f2..44c86e2cc8 100644 --- a/common/cmd_net.c +++ b/common/cmd_net.c @@ -26,14 +26,11 @@ */ #include #include -#include +#include #include #if (CONFIG_COMMANDS & CFG_CMD_NET) -# if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) -# include -# endif extern int do_bootm (cmd_tbl_t *, int, int, char *[]); @@ -44,21 +41,46 @@ int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return netboot_common (BOOTP, cmdtp, argc, argv); } +cmd_tbl_t U_BOOT_CMD(BOOTP) = MK_CMD_ENTRY( + "bootp", 3, 1, do_bootp, + "bootp - boot image via network using BootP/TFTP protocol\n", + "[loadAddress] [bootfilename]\n" +); + int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { return netboot_common (TFTP, cmdtp, argc, argv); } +cmd_tbl_t U_BOOT_CMD(TFTPB) = MK_CMD_ENTRY( + "tftpboot", 3, 1, do_tftpb, + "tftpboot- boot image via network using TFTP protocol\n" + " and env variables ipaddr and serverip\n", + "[loadAddress] [bootfilename]\n" +); + int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { return netboot_common (RARP, cmdtp, argc, argv); } +cmd_tbl_t U_BOOT_CMD(RARPB) = MK_CMD_ENTRY( + "rarpboot", 3, 1, do_rarpb, + "rarpboot- boot image via network using RARP/TFTP protocol\n", + "[loadAddress] [bootfilename]\n" +); + #if (CONFIG_COMMANDS & CFG_CMD_DHCP) int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { return netboot_common(DHCP, cmdtp, argc, argv); } + +cmd_tbl_t U_BOOT_CMD(DHCP) = MK_CMD_ENTRY( + "dhcp", 3, 1, do_dhcp, + "dhcp - invoke DHCP client to obtain IP/boot params\n", + "\n" +); #endif /* CFG_CMD_DHCP */ static void netboot_update_env(void) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 3c2a553ba7..9cf8b90410 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #if (CONFIG_COMMANDS & CFG_CMD_NET) @@ -534,6 +533,8 @@ int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return (saveenv() ? 1 : 0); } + + #endif @@ -556,3 +557,60 @@ envmatch (uchar *s1, int i2) return(i2); return(-1); } + + +/**************************************************/ + +cmd_tbl_t U_BOOT_CMD(PRINTENV) = MK_CMD_ENTRY( + "printenv", CFG_MAXARGS, 1, do_printenv, + "printenv- print environment variables\n", + "\n - print values of all environment variables\n" + "printenv name ...\n" + " - print value of environment variable 'name'\n" +); + +cmd_tbl_t U_BOOT_CMD(SETENV) = MK_CMD_ENTRY( + "setenv", CFG_MAXARGS, 0, do_setenv, + "setenv - set environment variables\n", + "name value ...\n" + " - set environment variable 'name' to 'value ...'\n" + "setenv name\n" + " - delete environment variable 'name'\n" +); + +#if ((CONFIG_COMMANDS & (CFG_CMD_ENV|CFG_CMD_FLASH)) == (CFG_CMD_ENV|CFG_CMD_FLASH)) + +cmd_tbl_t U_BOOT_CMD(SAVEENV) = MK_CMD_ENTRY( + "saveenv", 1, 0, do_saveenv, + "saveenv - save environment variables to persistent storage\n", + NULL +); + +#endif /* CFG_CMD_ENV */ + +#if (CONFIG_COMMANDS & CFG_CMD_ASKENV) + +cmd_tbl_t U_BOOT_CMD(ASKENV) = MK_CMD_ENTRY( + "askenv", CFG_MAXARGS, 1, do_askenv, + "askenv - get environment variables from stdin\n", + "name [message] [size]\n" + " - get environment variable 'name' from stdin (max 'size' chars)\n" + "askenv name\n" + " - get environment variable 'name' from stdin\n" + "askenv name size\n" + " - get environment variable 'name' from stdin (max 'size' chars)\n" + "askenv name [message] size\n" + " - display 'message' string and get environment variable 'name'" + "from stdin (max 'size' chars)\n" +); +#endif /* CFG_CMD_ASKENV */ + +#if (CONFIG_COMMANDS & CFG_CMD_RUN) +int do_run (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +cmd_tbl_t U_BOOT_CMD(RUN) = MK_CMD_ENTRY( + "run", CFG_MAXARGS, 1, do_run, + "run - run commands in an environment variable\n", + "var [...]\n" + " - run the commands in the environment variable(s) 'var'\n" +); +#endif /* CFG_CMD_RUN */ diff --git a/common/cmd_pci.c b/common/cmd_pci.c index ca712ce725..7641d5c8b7 100644 --- a/common/cmd_pci.c +++ b/common/cmd_pci.c @@ -34,10 +34,8 @@ #ifdef CONFIG_PCI #include -#include #include #include -#include #include #if (CONFIG_COMMANDS & CFG_CMD_PCI) @@ -116,63 +114,63 @@ void pciinfo(int BusNum, int ShortPCIListing) static char *pci_classes_str(u8 class) { switch (class) { - case PCI_CLASS_NOT_DEFINED: - return "Build before PCI Rev2.0"; - break; - case PCI_BASE_CLASS_STORAGE: - return "Mass storage controller"; - break; - case PCI_BASE_CLASS_NETWORK: - return "Network controller"; - break; - case PCI_BASE_CLASS_DISPLAY: - return "Display controller"; - break; - case PCI_BASE_CLASS_MULTIMEDIA: - return "Multimedia device"; - break; - case PCI_BASE_CLASS_MEMORY: - return "Memory controller"; - break; - case PCI_BASE_CLASS_BRIDGE: - return "Bridge device"; - break; - case PCI_BASE_CLASS_COMMUNICATION: - return "Simple comm. controller"; - break; - case PCI_BASE_CLASS_SYSTEM: - return "Base system peripheral"; - break; - case PCI_BASE_CLASS_INPUT: - return "Input device"; - break; - case PCI_BASE_CLASS_DOCKING: - return "Docking station"; - break; - case PCI_BASE_CLASS_PROCESSOR: - return "Processor"; - break; - case PCI_BASE_CLASS_SERIAL: - return "Serial bus controller"; - break; - case PCI_BASE_CLASS_INTELLIGENT: - return "Intelligent controller"; - break; - case PCI_BASE_CLASS_SATELLITE: - return "Satellite controller"; - break; - case PCI_BASE_CLASS_CRYPT: - return "Cryptographic device"; - break; - case PCI_BASE_CLASS_SIGNAL_PROCESSING: - return "DSP"; - break; - case PCI_CLASS_OTHERS: - return "Does not fit any class"; - break; - default: + case PCI_CLASS_NOT_DEFINED: + return "Build before PCI Rev2.0"; + break; + case PCI_BASE_CLASS_STORAGE: + return "Mass storage controller"; + break; + case PCI_BASE_CLASS_NETWORK: + return "Network controller"; + break; + case PCI_BASE_CLASS_DISPLAY: + return "Display controller"; + break; + case PCI_BASE_CLASS_MULTIMEDIA: + return "Multimedia device"; + break; + case PCI_BASE_CLASS_MEMORY: + return "Memory controller"; + break; + case PCI_BASE_CLASS_BRIDGE: + return "Bridge device"; + break; + case PCI_BASE_CLASS_COMMUNICATION: + return "Simple comm. controller"; + break; + case PCI_BASE_CLASS_SYSTEM: + return "Base system peripheral"; + break; + case PCI_BASE_CLASS_INPUT: + return "Input device"; + break; + case PCI_BASE_CLASS_DOCKING: + return "Docking station"; + break; + case PCI_BASE_CLASS_PROCESSOR: + return "Processor"; + break; + case PCI_BASE_CLASS_SERIAL: + return "Serial bus controller"; + break; + case PCI_BASE_CLASS_INTELLIGENT: + return "Intelligent controller"; + break; + case PCI_BASE_CLASS_SATELLITE: + return "Satellite controller"; + break; + case PCI_BASE_CLASS_CRYPT: + return "Cryptographic device"; + break; + case PCI_BASE_CLASS_SIGNAL_PROCESSING: + return "DSP"; + break; + case PCI_CLASS_OTHERS: + return "Does not fit any class"; + break; + default: return "???"; - break; + break; }; } @@ -234,7 +232,7 @@ void pci_header_show(pci_dev_t dev) PRINT (" status register = 0x%.4x\n", word, PCI_STATUS); PRINT (" revision ID = 0x%.2x\n", byte, PCI_REVISION_ID); PRINT2(" class code = 0x%.2x (%s)\n", byte, PCI_CLASS_CODE, - pci_classes_str); + pci_classes_str); PRINT (" sub class code = 0x%.2x\n", byte, PCI_CLASS_SUB_CODE); PRINT (" programming interface = 0x%.2x\n", byte, PCI_CLASS_PROG); PRINT (" cache line = 0x%.2x\n", byte, PCI_CACHE_LINE_SIZE); @@ -259,7 +257,7 @@ void pci_header_show(pci_dev_t dev) PRINT (" min Grant = 0x%.2x\n", byte, PCI_MIN_GNT); PRINT (" max Latency = 0x%.2x\n", byte, PCI_MAX_LAT); break; - + case PCI_HEADER_TYPE_BRIDGE: /* PCI-to-PCI bridge */ PRINT (" base address 1 = 0x%.8x\n", dword, PCI_BASE_ADDRESS_1); @@ -291,7 +289,7 @@ void pci_header_show(pci_dev_t dev) PRINT (" primary bus number = 0x%.2x\n", byte, PCI_CB_PRIMARY_BUS); PRINT (" CardBus number = 0x%.2x\n", byte, PCI_CB_CARD_BUS); PRINT (" subordinate bus number = 0x%.2x\n", byte, PCI_CB_SUBORDINATE_BUS); - PRINT (" CardBus latency timer = 0x%.2x\n", byte, PCI_CB_LATENCY_TIMER); + PRINT (" CardBus latency timer = 0x%.2x\n", byte, PCI_CB_LATENCY_TIMER); PRINT (" CardBus memory base 0 = 0x%.8x\n", dword, PCI_CB_MEMORY_BASE_0); PRINT (" CardBus memory limit 0 = 0x%.8x\n", dword, PCI_CB_MEMORY_LIMIT_0); PRINT (" CardBus memory base 1 = 0x%.8x\n", dword, PCI_CB_MEMORY_BASE_1); @@ -311,10 +309,10 @@ void pci_header_show(pci_dev_t dev) PRINT (" subdevice ID = 0x%.4x\n", word, PCI_CB_SUBSYSTEM_ID); PRINT (" PC Card 16bit base address = 0x%.8x\n", dword, PCI_CB_LEGACY_MODE_BASE); break; - + default: printf("unknown header\n"); - break; + break; } #undef PRINT @@ -547,6 +545,26 @@ int do_pci (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } +/***************************************************/ + + +cmd_tbl_t U_BOOT_CMD(PCI) = MK_CMD_ENTRY( + "pci", 5, 1, do_pci, + "pci - list and access PCI Configuraton Space\n", + "[bus] [long]\n" + " - short or long list of PCI devices on bus 'bus'\n" + "pci header b.d.f\n" + " - show header of PCI device 'bus.device.function'\n" + "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n" + " - display PCI configuration space (CFG)\n" + "pci next[.b, .w, .l] b.d.f address\n" + " - modify, read and keep CFG address\n" + "pci modify[.b, .w, .l] b.d.f address\n" + " - modify, auto increment CFG address\n" + "pci write[.b, .w, .l] b.d.f address value\n" + " - write to CFG address\n" +); + #endif /* (CONFIG_COMMANDS & CFG_CMD_PCI) */ #endif /* CONFIG_PCI */ diff --git a/common/cmd_pcmcia.c b/common/cmd_pcmcia.c index 10ba84c16e..2aa2a23866 100644 --- a/common/cmd_pcmcia.c +++ b/common/cmd_pcmcia.c @@ -57,7 +57,6 @@ #include #include #include -#include #if defined(CONFIG_IDE_8xx_PCCARD) && defined(CONFIG_8xx) #include #endif @@ -669,7 +668,6 @@ static int hardware_enable(int slot) } - #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) static int hardware_disable(int slot) { @@ -698,7 +696,6 @@ static int hardware_disable(int slot) #endif /* CFG_CMD_PCMCIA */ - static int voltage_set(int slot, int vcc, int vpp) { volatile immap_t *immap; @@ -890,7 +887,6 @@ static int hardware_enable(int slot) } - #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) static int hardware_disable(int slot) { @@ -933,7 +929,6 @@ static int hardware_disable(int slot) #endif /* CFG_CMD_PCMCIA */ - static int voltage_set(int slot, int vcc, int vpp) { volatile immap_t *immap; @@ -1206,7 +1201,6 @@ static int hardware_enable(int slot) } - #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) static int hardware_disable(int slot) { @@ -1238,7 +1232,6 @@ static int hardware_disable(int slot) #endif /* CFG_CMD_PCMCIA */ - static int voltage_set(int slot, int vcc, int vpp) { volatile immap_t *immap; @@ -1470,7 +1463,6 @@ static int hardware_enable(int slot) } - #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) static int hardware_disable(int slot) { @@ -1502,7 +1494,6 @@ static int hardware_disable(int slot) #endif /* CFG_CMD_PCMCIA */ - static int voltage_set(int slot, int vcc, int vpp) { volatile immap_t *immap; @@ -1895,7 +1886,6 @@ static int hardware_enable(int slot) } - #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) static int hardware_disable(int slot) { @@ -1926,7 +1916,6 @@ static int hardware_disable(int slot) #endif /* CFG_CMD_PCMCIA */ - static int voltage_set(int slot, int vcc, int vpp) { volatile immap_t *immap; @@ -2115,7 +2104,6 @@ static int hardware_enable(int slot) } - #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) static int hardware_disable(int slot) { @@ -2148,7 +2136,6 @@ static int hardware_disable(int slot) #endif /* CFG_CMD_PCMCIA */ - static int voltage_set(int slot, int vcc, int vpp) { volatile immap_t *immap; @@ -2227,9 +2214,6 @@ static int voltage_set(int slot, int vcc, int vpp) #endif /* KUP4K */ - - - /* -------------------------------------------------------------------- */ /* End of Board Specific Stuff */ /* -------------------------------------------------------------------- */ @@ -2499,3 +2483,14 @@ static int identify (volatile uchar *p) /* -------------------------------------------------------------------- */ #endif /* CFG_CMD_PCMCIA || (CFG_CMD_IDE && CONFIG_IDE_8xx_PCCARD) */ + +/**************************************************/ + +#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) +cmd_tbl_t U_BOOT_CMD(PINIT) = MK_CMD_ENTRY( + "pinit", 2, 1, do_pinit, + "pinit - PCMCIA sub-system\n", + "on - power on PCMCIA socket\n" + "pinit off - power off PCMCIA socket\n" +); +#endif diff --git a/common/cmd_reginfo.c b/common/cmd_reginfo.c index 198b9c7b04..aa9abf9a21 100644 --- a/common/cmd_reginfo.c +++ b/common/cmd_reginfo.c @@ -23,7 +23,6 @@ #include #include -#include #if defined(CONFIG_8xx) #include #elif defined (CONFIG_405GP) @@ -213,3 +212,15 @@ mfdcr(dmacr3), mfdcr(dmact3),mfdcr(dmada3), mfdcr(dmasa3), mfdcr(dmasb3) ); } #endif /* CONFIG_COMMANDS & CFG_CMD_REGINFO */ + + + /**************************************************/ + +#if (defined(CONFIG_8xx) || defined(CONFIG_405GP)) && \ + (CONFIG_COMMANDS & CFG_CMD_REGINFO) + +cmd_tbl_t U_BOOT_CMD(REGINFO) = MK_CMD_ENTRY( + "reginfo", 2, 1, do_reginfo, + "reginfo - print register information\n", +); +#endif diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c index f3d0c72168..c925823cd4 100644 --- a/common/cmd_scsi.c +++ b/common/cmd_scsi.c @@ -30,7 +30,6 @@ #include #include -#include #include #include #include @@ -181,7 +180,6 @@ removable: } - void scsi_init(void) { int busdevfunc; @@ -206,7 +204,6 @@ block_dev_desc_t * scsi_get_dev(int dev) } - /****************************************************************************** * scsi boot command intepreter. Derived from diskboot */ @@ -494,7 +491,6 @@ void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len) } - /* Trim trailing blanks, and NUL-terminate string */ void scsi_trim_trail (unsigned char *str, unsigned int len) @@ -594,5 +590,3 @@ void scsi_setup_inquiry(ccb * pccb) } #endif /* #if (CONFIG_COMMANDS & CFG_CMD_SCSI) */ - - diff --git a/common/cmd_spi.c b/common/cmd_spi.c index d544b27018..82cb673f5f 100644 --- a/common/cmd_spi.c +++ b/common/cmd_spi.c @@ -28,7 +28,6 @@ #include #include #include -#include #if (CONFIG_COMMANDS & CFG_CMD_SPI) @@ -107,11 +106,11 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if ((device < 0) || (device >= spi_chipsel_cnt)) { printf("Invalid device %d, giving up.\n", device); return 1; - } + } if ((bitlen < 0) || (bitlen > (MAX_SPI_BYTES * 8))) { printf("Invalid bitlen %d, giving up.\n", bitlen); return 1; - } + } debug ("spi_chipsel[%d] = %08X\n", device, (uint)spi_chipsel[device]); @@ -130,4 +129,15 @@ int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return rcode; } +/***************************************************/ + +cmd_tbl_t U_BOOT_CMD(SPI) = MK_CMD_ENTRY( + "sspi", 5, 1, do_spi, + "sspi - SPI utility commands\n", + " - Send bits from out the SPI\n" + " - Identifies the chip select of the device\n" + " - Number of bits to send (base 10)\n" + " - Hexadecimal string that gets sent\n" +); + #endif /* CFG_CMD_SPI */ diff --git a/common/cmd_usb.c b/common/cmd_usb.c index 8a3f47113f..d8f2f2cde1 100644 --- a/common/cmd_usb.c +++ b/common/cmd_usb.c @@ -309,7 +309,6 @@ void usb_show_tree(struct usb_device *dev) } - /****************************************************************************** * usb boot command intepreter. Derived from diskboot */ @@ -433,7 +432,6 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #endif /* CONFIG_USB_STORAGE */ - /********************************************************************************* * usb command intepreter */ @@ -594,3 +592,37 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #endif /* (CONFIG_COMMANDS & CFG_CMD_USB) */ +#if (CONFIG_COMMANDS & CFG_CMD_USB) + +#ifdef CONFIG_USB_STORAGE +cmd_tbl_t U_BOOT_CMD(USB) = MK_CMD_ENTRY( + "usb", 5, 1, do_usb, + "usb - USB sub-system\n", + "reset - reset (rescan) USB controller\n" + "usb stop [f] - stop USB [f]=force stop\n" + "usb tree - show USB device tree\n" + "usb info [dev] - show available USB devices\n" + "usb scan - (re-)scan USB bus for storage devices\n" + "usb device [dev] - show or set current USB storage device\n" + "usb part [dev] - print partition table of one or all USB storage devices\n" + "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" + " to memory address `addr'\n" +); + + +cmd_tbl_t U_BOOT_CMD(USBBOOT) = MK_CMD_ENTRY( + "usbboot", 3, 1, do_usbboot, + "usbboot - boot from USB device\n", + "loadAddr dev:part\n" +); + +#else +cmd_tbl_t U_BOOT_CMD(USB) = MK_CMD_ENTRY( + "usb", 5, 1, do_usb, + "usb - USB sub-system\n", + "reset - reset (rescan) USB controller\n" + "usb tree - show USB device tree\n" + "usb info [dev] - show available USB devices\n" +); +#endif +#endif diff --git a/common/cmd_vfd.c b/common/cmd_vfd.c index 3ef1395b2a..61ebe1c45d 100644 --- a/common/cmd_vfd.c +++ b/common/cmd_vfd.c @@ -64,6 +64,13 @@ int do_vfd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) transfer_pic(3, (uchar *)bitmap, VFD_LOGO_HEIGHT, VFD_LOGO_WIDTH); return 0; } + +cmd_tbl_t U_BOOT_CMD(VFD) = MK_CMD_ENTRY( + "vfd", 2, 0, do_vfd, + "vfd - load a bitmap to the VFDs on TRAB\n", + "N\n" + " - load bitmap N to the VFDs (N is _decimal_ !!!)\n" +); #endif /* CFG_CMD_VFD */ #ifdef CONFIG_VFD diff --git a/common/command.c b/common/command.c index 842e784d6a..607c74616a 100644 --- a/common/command.c +++ b/common/command.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2000 + * (C) Copyright 2000-2003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this @@ -27,93 +27,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include /* Floppy support */ -#include /* USB support */ -#include -#include -#include -#include /* 4xx DCR register access */ -#include -#include -#include -#include - -#include /* board special functions */ - -#include -#include - -#include - -#include /* load a bitmap to the VFDs on TRAB */ -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_AMIGAONEG3SE -#include -#include -#endif - -/* - * HELP command - */ -#define CMD_TBL_HELP MK_CMD_TBL_ENTRY( \ - "help", 1, CFG_MAXARGS, 1, do_help, \ - "help - print online help\n", \ - "[command ...]\n" \ - " - show help information (for 'command')\n" \ - "'help' prints online help for the monitor commands.\n\n" \ - "Without arguments, it prints a short usage message for all commands.\n\n" \ - "To get detailed help information for specific commands you can type\n" \ - "'help' with one or more command names as arguments.\n" \ - ), - -#define CMD_TBL_QUES MK_CMD_TBL_ENTRY( \ - "?", 1, CFG_MAXARGS, 1, do_help, \ - "? - alias for 'help'\n", \ - NULL \ - ), - -#define CMD_TBL_VERS MK_CMD_TBL_ENTRY( \ - "version", 4, 1, 1, do_version, \ - "version - print monitor version\n", \ - NULL \ - ), - -#define CMD_TBL_ECHO MK_CMD_TBL_ENTRY( \ - "echo", 4, CFG_MAXARGS, 1, do_echo, \ - "echo - echo args to console\n", \ - "[args..]\n" \ - " - echo args to console; \\c suppresses newline\n" \ - ), int do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) @@ -152,32 +65,59 @@ do_echo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) * Use puts() instead of printf() to avoid printf buffer overflow * for long help messages */ -int -do_help (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_help (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { int i; int rcode = 0; - if (argc == 1) { /* print short help (usage) */ + if (argc == 1) { /*show list of commands */ + + int cmd_items = (((int) &__u_boot_cmd_end) - + ((int) &__u_boot_cmd_start)) / + sizeof (*cmdtp); + int end_sort; + cmd_tbl_t *cmd_array[(cmd_items + 1)]; + int i; + + /* Make list of commands from .uboot_cmd section */ + cmdtp = (cmd_tbl_t *) & __u_boot_cmd_start; + for (i = 1; i <= cmd_items; i++) { + cmd_array[i] = cmdtp; + cmdtp++; + } + /* Sort command list */ + end_sort = 0; + for (i = 1; end_sort != 1 || i <= cmd_items - 1; i++) { + if (i == cmd_items) { /* Last command */ + end_sort = 1; + i = 1; + } + + if (strcmp (cmd_array[i]->name, cmd_array[i + 1]->name) > 0) { + end_sort = 0; + *cmd_array[0] = *cmd_array[i]; + *cmd_array[i] = *cmd_array[i + 1]; + *cmd_array[i + 1] = *cmd_array[0]; + } + } - for (cmdtp=&cmd_tbl[0]; cmdtp->name; cmdtp++) { + /* print short help (usage) */ + for (cmdtp = (cmd_tbl_t *) & __u_boot_cmd_start; + cmdtp != (cmd_tbl_t *) & __u_boot_cmd_end; cmdtp++) { /* allow user abort */ - if (ctrlc()) + if (ctrlc ()) return 1; - if (cmdtp->usage == NULL) continue; puts (cmdtp->usage); } - return 0; } - /* * command help (long version) */ - for (i=1; iname); @@ -196,164 +136,66 @@ do_help (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } else { printf ("Unknown command '%s' - try 'help'" " without arguments for list of all" - " known commands\n\n", - argv[i] - ); + " known commands\n\n", argv[i] + ); rcode = 1; } } return rcode; } + +cmd_tbl_t U_BOOT_CMD(HELP) = MK_CMD_ENTRY( + "help", CFG_MAXARGS, 1, do_help, + "help - print online help\n", + "[command ...]\n" + " - show help information (for 'command')\n" + "'help' prints online help for the monitor commands.\n\n" + "Without arguments, it prints a short usage message for all commands.\n\n" + "To get detailed help information for specific commands you can type\n" + "'help' with one or more command names as arguments.\n" +); + +cmd_tbl_t U_BOOT_CMD(QUES) = MK_CMD_ENTRY( + "?", CFG_MAXARGS, 1, do_help, + "? - alias for 'help'\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(VERS) = MK_CMD_ENTRY( + "version", 1, 1, do_version, + "version - print monitor version\n", + NULL +); + +cmd_tbl_t U_BOOT_CMD(ECHO) = MK_CMD_ENTRY( + "echo", CFG_MAXARGS, 1, do_echo, + "echo - echo args to console\n", + "[args..]\n" + " - echo args to console; \\c suppresses newline\n" +); + /*************************************************************************** * find command table entry for a command */ -cmd_tbl_t *find_cmd(const char *cmd) +cmd_tbl_t *find_cmd (const char *cmd) { cmd_tbl_t *cmdtp; - /* Search command table - Use linear search - it's a small table */ - for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) { - if (strncmp (cmd, cmdtp->name, cmdtp->lmin) == 0) + cmd_tbl_t *cmdtp_temp = &__u_boot_cmd_start; /*Init value */ + int one_cmd_name = 0; + + for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) { + if ((strncmp (cmd, cmdtp->name, strlen (cmd)) == 0) && + (strlen (cmd) == strlen (cmdtp->name))) return cmdtp; + else if (strncmp (cmd, cmdtp->name, strlen (cmd)) == 0) { + cmdtp_temp = cmdtp; + one_cmd_name++; + } else; } - return NULL; /* not found */ -} + if (one_cmd_name == 1) + return cmdtp_temp; -/* - * The commands in this table are sorted alphabetically by the - * command name and in descending order by the command name string - * length. This is to prevent conflicts in command name parsing. - * Please ensure that new commands are added according to that rule. - * Please use $(TOPDIR)/doc/README.commands as a reference AND make - * sure it gets updated. - */ - -cmd_tbl_t cmd_tbl[] = { - CMD_TBL_ASKENV - CMD_TBL_ASM - CMD_TBL_AUTOSCRIPT - CMD_TBL_BASE - CMD_TBL_BDINFO - CMD_TBL_BMP -#ifdef CONFIG_AMIGAONEG3SE - CMD_TBL_BOOTA -#endif - CMD_TBL_BOOTELF - CMD_TBL_BOOTM - CMD_TBL_BOOTP - CMD_TBL_BOOTVX - CMD_TBL_BOOTD - CMD_TBL_BREAK - CMD_TBL_BRGINFO - CMD_TBL_CARINFO - CMD_TBL_JFFS2_CHPART - CMD_TBL_CMP - CMD_TBL_CONINFO - CMD_TBL_CONTINUE - CMD_TBL_CP - CMD_TBL_CRC - CMD_TBL_DATE - CMD_TBL_DCACHE - CMD_TBL_DHCP - CMD_TBL_DIAG - CMD_TBL_DISK - CMD_TBL_DMAINFO - CMD_TBL_DIS - CMD_TBL_DOCBOOT - CMD_TBL_DOC - CMD_TBL_DTT - CMD_TBL_ECHO - CMD_TBL_EEPROM - CMD_TBL_FAT - CMD_TBL_FCCINFO - CMD_TBL_FLERASE - CMD_TBL_FDC - CMD_TBL_FDOS_BOOT - CMD_TBL_FDOS_LS - CMD_TBL_FLINFO - CMD_TBL_FPGA - CMD_TBL_JFFS2_FSINFO - CMD_TBL_JFFS2_FSLOAD - CMD_TBL_GETDCR - CMD_TBL_GO - CMD_TBL_HELP - CMD_TBL_HWFLOW - CMD_TBL_I2CINFO - CMD_TBL_ICACHE -#ifdef CONFIG_8260 - CMD_TBL_ICINFO -#endif - CMD_TBL_IMD - CMD_TBL_IMM - CMD_TBL_INM - CMD_TBL_IMW - CMD_TBL_PORTIO_IN - CMD_TBL_ICRC - CMD_TBL_IPROBE - CMD_TBL_ILOOP - CMD_TBL_ISDRAM - CMD_TBL_IDE - CMD_TBL_IMINFO - CMD_TBL_IOPINFO - CMD_TBL_IOPSET - CMD_TBL_IRQINFO - CMD_TBL_KGDB - CMD_TBL_LOADB - CMD_TBL_LOADS - CMD_TBL_LOG - CMD_TBL_LOOP - CMD_TBL_JFFS2_LS - CMD_TBL_MCCINFO - CMD_TBL_MMC - CMD_TBL_MD - CMD_TBL_MEMCINFO -#ifdef CONFIG_AMIGAONEG3SE - CMD_TBL_MENU -#endif - CMD_TBL_MII - CMD_TBL_MM - CMD_TBL_MTEST - CMD_TBL_MUXINFO - CMD_TBL_MW - CMD_TBL_NAND - CMD_TBL_NANDBOOT - CMD_TBL_NEXT - CMD_TBL_NM - CMD_TBL_PING - CMD_TBL_PORTIO_OUT - CMD_TBL_PCI - CMD_TBL_PRINTENV - CMD_TBL_PROTECT - CMD_TBL_RARPB - CMD_TBL_RDUMP - CMD_TBL_PINIT - CMD_TBL_REGINFO - CMD_TBL_RESET - CMD_TBL_RUN - CMD_TBL_SAVEENV - CMD_TBL_SAVES - CMD_TBL_SCCINFO - CMD_TBL_SCSIBOOT - CMD_TBL_SCSI - CMD_TBL_SETDCR - CMD_TBL_SETENV - CMD_TBL_SIINFO - CMD_TBL_SITINFO - CMD_TBL_SIUINFO - CMD_TBL_MISC /* sleep */ - CMD_TBL_SMCINFO - CMD_TBL_SPIINFO - CMD_TBL_SPI - CMD_TBL_STACK - CMD_TBL_STEP - CMD_TBL_TFTPB - CMD_TBL_USBBOOT - CMD_TBL_USB - CMD_TBL_VERS - CMD_TBL_BSP - CMD_TBL_VFD - CMD_TBL_QUES /* keep this ("help") the last entry */ - /* the following entry terminates this table */ - MK_CMD_TBL_ENTRY( NULL, 0, 0, 0, NULL, NULL, NULL ) -}; + return NULL; /* not found || one_cmd_name >2 */ +} diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 9261507571..0c0487228e 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -9,8 +9,8 @@ * VERSION 2.6.6 Sun Mar 5 19:10:03 2000 Doug Lea (dl at gee) Note: There may be an updated version of this malloc obtainable at - ftp://g.oswego.edu/pub/misc/malloc.c - Check before installing! + ftp://g.oswego.edu/pub/misc/malloc.c + Check before installing! * Why use this malloc? @@ -87,7 +87,7 @@ and status information. Minimum allocated size: 4-byte ptrs: 16 bytes (including 4 overhead) - 8-byte ptrs: 24/32 bytes (including, 4/8 overhead) + 8-byte ptrs: 24/32 bytes (including, 4/8 overhead) When a chunk is freed, 12 (for 4byte ptrs) or 20 (for 8 byte ptrs but 4 byte size) or 24 (for 8/8) additional bytes are @@ -99,7 +99,7 @@ pointer to something of the minimum allocatable size. Maximum allocated size: 4-byte size_t: 2^31 - 8 bytes - 8-byte size_t: 2^63 - 16 bytes + 8-byte size_t: 2^63 - 16 bytes It is assumed that (possibly signed) size_t bit values suffice to represent chunk sizes. `Possibly signed' is due to the fact @@ -115,11 +115,11 @@ make the normal worst-case wastage 15 bytes (i.e., up to 15 more bytes will be allocated than were requested in malloc), with two exceptions: - 1. Because requests for zero bytes allocate non-zero space, - the worst case wastage for a request of zero bytes is 24 bytes. - 2. For requests >= mmap_threshold that are serviced via - mmap(), the worst case wastage is 8 bytes plus the remainder - from a system page (the minimal mmap unit); typically 4096 bytes. + 1. Because requests for zero bytes allocate non-zero space, + the worst case wastage for a request of zero bytes is 24 bytes. + 2. For requests >= mmap_threshold that are serviced via + mmap(), the worst case wastage is 8 bytes plus the remainder + from a system page (the minimal mmap unit); typically 4096 bytes. * Limitations @@ -372,8 +372,8 @@ void* memset(void*, int, size_t); void* memcpy(void*, const void*, size_t); #else #ifdef WIN32 -// On Win32 platforms, 'memset()' and 'memcpy()' are already declared in -// 'windows.h' +/* On Win32 platforms, 'memset()' and 'memcpy()' are already declared in */ +/* 'windows.h' */ #else Void_t* memset(); Void_t* memcpy(); @@ -393,14 +393,14 @@ do { \ if(mzsz <= 9*sizeof(mzsz)) { \ INTERNAL_SIZE_T* mz = (INTERNAL_SIZE_T*) (charp); \ if(mzsz >= 5*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; \ + *mz++ = 0; \ if(mzsz >= 7*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; \ - if(mzsz >= 9*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; }}} \ - *mz++ = 0; \ - *mz++ = 0; \ - *mz = 0; \ + *mz++ = 0; \ + if(mzsz >= 9*sizeof(mzsz)) { *mz++ = 0; \ + *mz++ = 0; }}} \ + *mz++ = 0; \ + *mz++ = 0; \ + *mz = 0; \ } else memset((charp), 0, mzsz); \ } while(0) @@ -411,14 +411,14 @@ do { \ INTERNAL_SIZE_T* mcsrc = (INTERNAL_SIZE_T*) (src); \ INTERNAL_SIZE_T* mcdst = (INTERNAL_SIZE_T*) (dest); \ if(mcsz >= 5*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ + *mcdst++ = *mcsrc++; \ if(mcsz >= 7*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ - if(mcsz >= 9*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; }}} \ - *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ - *mcdst = *mcsrc ; \ + *mcdst++ = *mcsrc++; \ + if(mcsz >= 9*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ + *mcdst++ = *mcsrc++; }}} \ + *mcdst++ = *mcsrc++; \ + *mcdst++ = *mcsrc++; \ + *mcdst = *mcsrc ; \ } else memcpy(dest, src, mcsz); \ } while(0) @@ -558,7 +558,6 @@ do { \ #endif - /* This version of malloc supports the standard SVID/XPG mallinfo @@ -622,7 +621,6 @@ struct mallinfo { #define M_MMAP_MAX -4 - #ifndef DEFAULT_TRIM_THRESHOLD #define DEFAULT_TRIM_THRESHOLD (128 * 1024) #endif @@ -686,11 +684,11 @@ struct mallinfo { retain whenever sbrk is called. It is used in two ways internally: * When sbrk is called to extend the top of the arena to satisfy - a new malloc request, this much padding is added to the sbrk - request. + a new malloc request, this much padding is added to the sbrk + request. * When malloc_trim is called automatically from free(), - it is used as the `pad' argument. + it is used as the `pad' argument. In both cases, the actual amount of padding is rounded so that the end of the arena is always a system page boundary. @@ -736,15 +734,15 @@ struct mallinfo { However, it has the disadvantages that: - 1. The space cannot be reclaimed, consolidated, and then - used to service later requests, as happens with normal chunks. - 2. It can lead to more wastage because of mmap page alignment - requirements - 3. It causes malloc performance to be more dependent on host - system memory management support routines which may vary in - implementation quality and may impose arbitrary - limitations. Generally, servicing a request via normal - malloc steps is faster than going through a system's mmap. + 1. The space cannot be reclaimed, consolidated, and then + used to service later requests, as happens with normal chunks. + 2. It can lead to more wastage because of mmap page alignment + requirements + 3. It causes malloc performance to be more dependent on host + system memory management support routines which may vary in + implementation quality and may impose arbitrary + limitations. Generally, servicing a request via normal + malloc steps is faster than going through a system's mmap. All together, these considerations should lead you to use mmap only for relatively large requests. @@ -753,7 +751,6 @@ struct mallinfo { */ - #ifndef DEFAULT_MMAP_MAX #if HAVE_MMAP #define DEFAULT_MMAP_MAX (64) @@ -766,15 +763,15 @@ struct mallinfo { M_MMAP_MAX is the maximum number of requests to simultaneously service using mmap. This parameter exists because: - 1. Some systems have a limited number of internal tables for - use by mmap. - 2. In most systems, overreliance on mmap can degrade overall - performance. - 3. If a program allocates many large regions, it is probably - better off using normal sbrk-based allocation routines that - can reclaim and reallocate normal heap memory. Using a - small value allows transition into this mode after the - first few allocations. + 1. Some systems have a limited number of internal tables for + use by mmap. + 2. In most systems, overreliance on mmap can degrade overall + performance. + 3. If a program allocates many large regions, it is probably + better off using normal sbrk-based allocation routines that + can reclaim and reallocate normal heap memory. Using a + small value allows transition into this mode after the + first few allocations. Setting to 0 disables all use of mmap. If HAVE_MMAP is not set, the default value is 0, and attempts to set it to non-zero values @@ -782,8 +779,6 @@ struct mallinfo { */ - - /* USE_DL_PREFIX will prefix all public routines with the string 'dl'. Useful to quickly avoid procedure declaration conflicts and linker @@ -794,8 +789,6 @@ struct mallinfo { /* #define USE_DL_PREFIX */ - - /* Special defines for linux libc @@ -1013,7 +1006,7 @@ void gcleanup () rval = VirtualFree ((void*)gAddressBase, gNextAddress - gAddressBase, MEM_DECOMMIT); - assert (rval); + assert (rval); } while (head) { @@ -1038,24 +1031,24 @@ void* findRegion (void* start_address, unsigned long size) return start_address; else { - // Requested region is not available so see if the - // next region is available. Set 'start_address' - // to the next region and call 'VirtualQuery()' - // again. + /* Requested region is not available so see if the */ + /* next region is available. Set 'start_address' */ + /* to the next region and call 'VirtualQuery()' */ + /* again. */ start_address = (char*)info.BaseAddress + info.RegionSize; - // Make sure we start looking for the next region - // on the *next* 64K boundary. Otherwise, even if - // the new region is free according to - // 'VirtualQuery()', the subsequent call to - // 'VirtualAlloc()' (which follows the call to - // this routine in 'wsbrk()') will round *down* - // the requested address to a 64K boundary which - // we already know is an address in the - // unavailable region. Thus, the subsequent call - // to 'VirtualAlloc()' will fail and bring us back - // here, causing us to go into an infinite loop. + /* Make sure we start looking for the next region */ + /* on the *next* 64K boundary. Otherwise, even if */ + /* the new region is free according to */ + /* 'VirtualQuery()', the subsequent call to */ + /* 'VirtualAlloc()' (which follows the call to */ + /* this routine in 'wsbrk()') will round *down* */ + /* the requested address to a 64K boundary which */ + /* we already know is an address in the */ + /* unavailable region. Thus, the subsequent call */ + /* to 'VirtualAlloc()' will fail and bring us back */ + /* here, causing us to go into an infinite loop. */ start_address = (void *) AlignPage64K((unsigned long) start_address); @@ -1092,9 +1085,9 @@ gAllocatedSize)) gAddressBase = gNextAddress = (unsigned int)VirtualAlloc (new_address, new_size, MEM_RESERVE, PAGE_NOACCESS); - // repeat in case of race condition - // The region that we found has been snagged - // by another thread + /* repeat in case of race condition */ + /* The region that we found has been snagged */ + /* by another thread */ } while (gAddressBase == 0); @@ -1182,17 +1175,17 @@ typedef struct malloc_chunk* mchunkptr; chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk, if allocated | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of chunk, in bytes |P| + | Size of previous chunk, if allocated | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of chunk, in bytes |P| mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | User data starts here... . - . . - . (malloc_usable_space() bytes) . - . | + | User data starts here... . + . . + . (malloc_usable_space() bytes) . + . | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Where "chunk" is the front of the chunk for the purpose of most of @@ -1206,20 +1199,20 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Free chunks are stored in circular doubly-linked lists, and look like this: chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of previous chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `head:' | Size of chunk, in bytes |P| mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Forward pointer to next chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Back pointer to previous chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unused space (may be 0 bytes long) . - . . - . | + | Forward pointer to next chunk in list | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Back pointer to previous chunk in list | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unused space (may be 0 bytes long) . + . . + . | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `foot:' | Size of chunk, in bytes | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The P (PREV_INUSE) bit, stored in the unused low-order bit of the chunk size (which is always a multiple of two words), is an in-use @@ -1236,16 +1229,16 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The two exceptions to all this are 1. The special chunk `top', which doesn't bother using the - trailing size field since there is no - next contiguous chunk that would have to index off it. (After - initialization, `top' is forced to always exist. If it would - become less than MINSIZE bytes long, it is replenished via - malloc_extend_top.) + trailing size field since there is no + next contiguous chunk that would have to index off it. (After + initialization, `top' is forced to always exist. If it would + become less than MINSIZE bytes long, it is replenished via + malloc_extend_top.) 2. Chunks allocated via mmap, which have the second-lowest-order - bit (IS_MMAPPED) set in their size fields. Because they are - never merged or traversed from any other chunk, they have no - foot size or inuse information. + bit (IS_MMAPPED) set in their size fields. Because they are + never merged or traversed from any other chunk, they have no + foot size or inuse information. Available chunks are kept in any of several places (all declared below): @@ -1286,12 +1279,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ serviced via calls to mmap, and then later released via munmap. */ - - - - - /* sizes, alignments */ #define SIZE_SZ (sizeof(INTERNAL_SIZE_T)) @@ -1531,7 +1519,7 @@ void malloc_bin_reloc (void) ((((unsigned long)(sz)) >> 9) <= 84) ? 110 + (((unsigned long)(sz)) >> 12): \ ((((unsigned long)(sz)) >> 9) <= 340) ? 119 + (((unsigned long)(sz)) >> 15): \ ((((unsigned long)(sz)) >> 9) <= 1364) ? 124 + (((unsigned long)(sz)) >> 18): \ - 126) + 126) /* bins for chunks < 512 are all spaced 8 bytes apart, and hold identically sized chunks. This is exploited in malloc. @@ -1829,7 +1817,6 @@ static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s; (last_remainder->fd = last_remainder->bk = last_remainder) - @@ -2030,7 +2017,7 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; /* Guarantee the next brk will be at a page boundary */ correction += ((((unsigned long)(brk + sbrk_size))+(pagesz-1)) & - ~(pagesz - 1)) - ((unsigned long)(brk + sbrk_size)); + ~(pagesz - 1)) - ((unsigned long)(brk + sbrk_size)); /* Allocate correction */ new_brk = (char*)(MORECORE (correction)); @@ -2051,20 +2038,20 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; /* If not enough space to do this, then user did something very wrong */ if (old_top_size < MINSIZE) { - set_head(top, PREV_INUSE); /* will force null return from malloc */ - return; + set_head(top, PREV_INUSE); /* will force null return from malloc */ + return; } /* Also keep size a multiple of MALLOC_ALIGNMENT */ old_top_size = (old_top_size - 3*SIZE_SZ) & ~MALLOC_ALIGN_MASK; set_head_size(old_top, old_top_size); chunk_at_offset(old_top, old_top_size )->size = - SIZE_SZ|PREV_INUSE; + SIZE_SZ|PREV_INUSE; chunk_at_offset(old_top, old_top_size + SIZE_SZ)->size = - SIZE_SZ|PREV_INUSE; + SIZE_SZ|PREV_INUSE; /* If possible, release the rest. */ if (old_top_size >= MINSIZE) - fREe(chunk2mem(old_top)); + fREe(chunk2mem(old_top)); } } @@ -2095,43 +2082,43 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; From there, the first successful of the following steps is taken: 1. The bin corresponding to the request size is scanned, and if - a chunk of exactly the right size is found, it is taken. + a chunk of exactly the right size is found, it is taken. 2. The most recently remaindered chunk is used if it is big - enough. This is a form of (roving) first fit, used only in - the absence of exact fits. Runs of consecutive requests use - the remainder of the chunk used for the previous such request - whenever possible. This limited use of a first-fit style - allocation strategy tends to give contiguous chunks - coextensive lifetimes, which improves locality and can reduce - fragmentation in the long run. + enough. This is a form of (roving) first fit, used only in + the absence of exact fits. Runs of consecutive requests use + the remainder of the chunk used for the previous such request + whenever possible. This limited use of a first-fit style + allocation strategy tends to give contiguous chunks + coextensive lifetimes, which improves locality and can reduce + fragmentation in the long run. 3. Other bins are scanned in increasing size order, using a - chunk big enough to fulfill the request, and splitting off - any remainder. This search is strictly by best-fit; i.e., - the smallest (with ties going to approximately the least - recently used) chunk that fits is selected. + chunk big enough to fulfill the request, and splitting off + any remainder. This search is strictly by best-fit; i.e., + the smallest (with ties going to approximately the least + recently used) chunk that fits is selected. 4. If large enough, the chunk bordering the end of memory - (`top') is split off. (This use of `top' is in accord with - the best-fit search rule. In effect, `top' is treated as - larger (and thus less well fitting) than any other available - chunk since it can be extended to be as large as necessary - (up to system limitations). + (`top') is split off. (This use of `top' is in accord with + the best-fit search rule. In effect, `top' is treated as + larger (and thus less well fitting) than any other available + chunk since it can be extended to be as large as necessary + (up to system limitations). 5. If the request size meets the mmap threshold and the - system supports mmap, and there are few enough currently - allocated mmapped regions, and a call to mmap succeeds, - the request is allocated via direct memory mapping. + system supports mmap, and there are few enough currently + allocated mmapped regions, and a call to mmap succeeds, + the request is allocated via direct memory mapping. 6. Otherwise, the top of memory is extended by - obtaining more space from the system (normally using sbrk, - but definable to anything else via the MORECORE macro). - Memory is gathered from the system (in system page-sized - units) in a way that allows chunks obtained across different - sbrk calls to be consolidated, but does not require - contiguous memory. Thus, it should be safe to intersperse - mallocs with other sbrk calls. + obtaining more space from the system (normally using sbrk, + but definable to anything else via the MORECORE macro). + Memory is gathered from the system (in system page-sized + units) in a way that allows chunks obtained across different + sbrk calls to be consolidated, but does not require + contiguous memory. Thus, it should be safe to intersperse + mallocs with other sbrk calls. All allocations are made from the the `lowest' part of any found @@ -2208,16 +2195,16 @@ Void_t* mALLOc(bytes) size_t bytes; if (remainder_size >= (long)MINSIZE) /* too big */ { - --idx; /* adjust to rescan below after checking last remainder */ - break; + --idx; /* adjust to rescan below after checking last remainder */ + break; } else if (remainder_size >= 0) /* exact fit */ { - unlink(victim, bck, fwd); - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); + unlink(victim, bck, fwd); + set_inuse_bit_at_offset(victim, victim_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); } } @@ -2274,8 +2261,8 @@ Void_t* mALLOc(bytes) size_t bytes; block <<= 1; while ((block & binblocks) == 0) { - idx += BINBLOCKWIDTH; - block <<= 1; + idx += BINBLOCKWIDTH; + block <<= 1; } } @@ -2288,34 +2275,34 @@ Void_t* mALLOc(bytes) size_t bytes; /* For each bin in this block ... */ do { - /* Find and use first big enough chunk ... */ - - for (victim = last(bin); victim != bin; victim = victim->bk) - { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long)MINSIZE) /* split */ - { - remainder = chunk_at_offset(victim, nb); - set_head(victim, nb | PREV_INUSE); - unlink(victim, bck, fwd); - link_last_remainder(remainder); - set_head(remainder, remainder_size | PREV_INUSE); - set_foot(remainder, remainder_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - else if (remainder_size >= 0) /* take */ - { - set_inuse_bit_at_offset(victim, victim_size); - unlink(victim, bck, fwd); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - } + /* Find and use first big enough chunk ... */ + + for (victim = last(bin); victim != bin; victim = victim->bk) + { + victim_size = chunksize(victim); + remainder_size = victim_size - nb; + + if (remainder_size >= (long)MINSIZE) /* split */ + { + remainder = chunk_at_offset(victim, nb); + set_head(victim, nb | PREV_INUSE); + unlink(victim, bck, fwd); + link_last_remainder(remainder); + set_head(remainder, remainder_size | PREV_INUSE); + set_foot(remainder, remainder_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + + else if (remainder_size >= 0) /* take */ + { + set_inuse_bit_at_offset(victim, victim_size); + unlink(victim, bck, fwd); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + + } bin = next_bin(bin); @@ -2325,12 +2312,12 @@ Void_t* mALLOc(bytes) size_t bytes; do /* Possibly backtrack to try to clear a partial block */ { - if ((startidx & (BINBLOCKWIDTH - 1)) == 0) - { - binblocks &= ~block; - break; - } - --startidx; + if ((startidx & (BINBLOCKWIDTH - 1)) == 0) + { + binblocks &= ~block; + break; + } + --startidx; q = prev_bin(q); } while (first(q) == q); @@ -2338,14 +2325,14 @@ Void_t* mALLOc(bytes) size_t bytes; if ( (block <<= 1) <= binblocks && (block != 0) ) { - while ((block & binblocks) == 0) - { - idx += BINBLOCKWIDTH; - block <<= 1; - } + while ((block & binblocks) == 0) + { + idx += BINBLOCKWIDTH; + block <<= 1; + } } else - break; + break; } } @@ -2359,7 +2346,7 @@ Void_t* mALLOc(bytes) size_t bytes; #if HAVE_MMAP /* If big and would otherwise need to extend, try to use mmap instead */ if ((unsigned long)nb >= (unsigned long)mmap_threshold && - (victim = mmap_chunk(nb)) != 0) + (victim = mmap_chunk(nb)) != 0) return chunk2mem(victim); #endif @@ -2392,13 +2379,13 @@ Void_t* mALLOc(bytes) size_t bytes; 2. If the chunk was allocated via mmap, it is release via munmap(). 3. If a returned chunk borders the current high end of memory, - it is consolidated into the top, and if the total unused - topmost memory exceeds the trim threshold, malloc_trim is - called. + it is consolidated into the top, and if the total unused + topmost memory exceeds the trim threshold, malloc_trim is + called. 4. Other chunks are consolidated as they arrive, and - placed in corresponding bins. (This includes the case of - consolidating with the current `last_remainder'). + placed in corresponding bins. (This includes the case of + consolidating with the current `last_remainder'). */ @@ -2610,22 +2597,22 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; /* Forward into top only if a remainder */ if (next == top) { - if ((long)(nextsize + newsize) >= (long)(nb + MINSIZE)) - { - newsize += nextsize; - top = chunk_at_offset(oldp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(oldp, nb); - return chunk2mem(oldp); - } + if ((long)(nextsize + newsize) >= (long)(nb + MINSIZE)) + { + newsize += nextsize; + top = chunk_at_offset(oldp, nb); + set_head(top, (newsize - nb) | PREV_INUSE); + set_head_size(oldp, nb); + return chunk2mem(oldp); + } } /* Forward into next chunk */ else if (((long)(nextsize + newsize) >= (long)(nb))) { - unlink(next, bck, fwd); - newsize += nextsize; - goto split; + unlink(next, bck, fwd); + newsize += nextsize; + goto split; } } else @@ -2645,45 +2632,45 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; if (next != 0) { - /* into top */ - if (next == top) - { - if ((long)(nextsize + prevsize + newsize) >= (long)(nb + MINSIZE)) - { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize + nextsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - top = chunk_at_offset(newp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(newp, nb); - return newmem; - } - } - - /* into next chunk */ - else if (((long)(nextsize + prevsize + newsize) >= (long)(nb))) - { - unlink(next, bck, fwd); - unlink(prev, bck, fwd); - newp = prev; - newsize += nextsize + prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; - } + /* into top */ + if (next == top) + { + if ((long)(nextsize + prevsize + newsize) >= (long)(nb + MINSIZE)) + { + unlink(prev, bck, fwd); + newp = prev; + newsize += prevsize + nextsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + top = chunk_at_offset(newp, nb); + set_head(top, (newsize - nb) | PREV_INUSE); + set_head_size(newp, nb); + return newmem; + } + } + + /* into next chunk */ + else if (((long)(nextsize + prevsize + newsize) >= (long)(nb))) + { + unlink(next, bck, fwd); + unlink(prev, bck, fwd); + newp = prev; + newsize += nextsize + prevsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + goto split; + } } /* backward only */ if (prev != 0 && (long)(prevsize + newsize) >= (long)nb) { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; + unlink(prev, bck, fwd); + newp = prev; + newsize += prevsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + goto split; } } @@ -3015,25 +3002,25 @@ int malloc_trim(pad) size_t pad; if (new_brk == (char*)(MORECORE_FAILURE)) /* sbrk failed? */ { - /* Try to figure out what we have */ - current_brk = (char*)(MORECORE (0)); - top_size = current_brk - (char*)top; - if (top_size >= (long)MINSIZE) /* if not, we are very very dead! */ - { - sbrked_mem = current_brk - sbrk_base; - set_head(top, top_size | PREV_INUSE); - } - check_chunk(top); - return 0; + /* Try to figure out what we have */ + current_brk = (char*)(MORECORE (0)); + top_size = current_brk - (char*)top; + if (top_size >= (long)MINSIZE) /* if not, we are very very dead! */ + { + sbrked_mem = current_brk - sbrk_base; + set_head(top, top_size | PREV_INUSE); + } + check_chunk(top); + return 0; } else { - /* Success. Adjust top accordingly. */ - set_head(top, (top_size - extra) | PREV_INUSE); - sbrked_mem -= extra; - check_chunk(top); - return 1; + /* Success. Adjust top accordingly. */ + set_head(top, (top_size - extra) | PREV_INUSE); + sbrked_mem -= extra; + check_chunk(top); + return 1; } } } @@ -3100,9 +3087,9 @@ static void malloc_update_mallinfo() #ifdef DEBUG check_free_chunk(p); for (q = next_chunk(p); - q < top && inuse(q) && (long)(chunksize(q)) >= (long)MINSIZE; - q = next_chunk(q)) - check_inuse_chunk(q); + q < top && inuse(q) && (long)(chunksize(q)) >= (long)MINSIZE; + q = next_chunk(q)) + check_inuse_chunk(q); #endif avail += chunksize(p); navail++; @@ -3141,14 +3128,14 @@ void malloc_stats() { malloc_update_mallinfo(); printf("max system bytes = %10u\n", - (unsigned int)(max_total_mem)); + (unsigned int)(max_total_mem)); printf("system bytes = %10u\n", - (unsigned int)(sbrked_mem + mmapped_mem)); + (unsigned int)(sbrked_mem + mmapped_mem)); printf("in use bytes = %10u\n", - (unsigned int)(current_mallinfo.uordblks + mmapped_mem)); + (unsigned int)(current_mallinfo.uordblks + mmapped_mem)); #if HAVE_MMAP printf("max mmap regions = %10u\n", - (unsigned int)max_n_mmaps); + (unsigned int)max_n_mmaps); #endif } #endif /* 0 */ @@ -3214,17 +3201,17 @@ History: V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee) * return null for negative arguments * Added Several WIN32 cleanups from Martin C. Fong - * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' - (e.g. WIN32 platforms) - * Cleanup up header file inclusion for WIN32 platforms - * Cleanup code to avoid Microsoft Visual C++ compiler complaints - * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing - memory allocation routines - * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) - * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to + * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' + (e.g. WIN32 platforms) + * Cleanup up header file inclusion for WIN32 platforms + * Cleanup code to avoid Microsoft Visual C++ compiler complaints + * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing + memory allocation routines + * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) + * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to usage of 'assert' in non-WIN32 code - * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to - avoid infinite loop + * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to + avoid infinite loop * Always call 'fREe()' rather than 'free()' V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee) @@ -3236,13 +3223,13 @@ History: * Added anonymously donated WIN32 sbrk emulation * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen * malloc_extend_top: fix mask error that caused wastage after - foreign sbrks + foreign sbrks * Add linux mremap support code from HJ Liu V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) * Integrated most documentation with the code. * Add support for mmap, with help from - Wolfram Gloger (Gloger@lrz.uni-muenchen.de). + Wolfram Gloger (Gloger@lrz.uni-muenchen.de). * Use last_remainder in more cases. * Pack bins using idea from colin@nyx10.cs.du.edu * Use ordered bins instead of best-fit threshhold @@ -3250,34 +3237,34 @@ History: * Support another case of realloc via move into top * Fix error occuring when initial sbrk_base not word-aligned. * Rely on page size for units instead of SBRK_UNIT to - avoid surprises about sbrk alignment conventions. + avoid surprises about sbrk alignment conventions. * Add mallinfo, mallopt. Thanks to Raymond Nijssen - (raymond@es.ele.tue.nl) for the suggestion. + (raymond@es.ele.tue.nl) for the suggestion. * Add `pad' argument to malloc_trim and top_pad mallopt parameter. * More precautions for cases where other routines call sbrk, - courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). + courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). * Added macros etc., allowing use in linux libc from - H.J. Lu (hjl@gnu.ai.mit.edu) + H.J. Lu (hjl@gnu.ai.mit.edu) * Inverted this history list V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) * Re-tuned and fixed to behave more nicely with V2.6.0 changes. * Removed all preallocation code since under current scheme - the work required to undo bad preallocations exceeds - the work saved in good cases for most test programs. + the work required to undo bad preallocations exceeds + the work saved in good cases for most test programs. * No longer use return list or unconsolidated bins since - no scheme using them consistently outperforms those that don't - given above changes. + no scheme using them consistently outperforms those that don't + given above changes. * Use best fit for very large chunks to prevent some worst-cases. * Added some support for debugging V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) * Removed footers when chunks are in use. Thanks to - Paul Wilson (wilson@cs.texas.edu) for the suggestion. + Paul Wilson (wilson@cs.texas.edu) for the suggestion. V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) * Added malloc_trim, with help from Wolfram Gloger - (wmglo@Dent.MED.Uni-Muenchen.DE). + (wmglo@Dent.MED.Uni-Muenchen.DE). V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) @@ -3293,11 +3280,11 @@ History: V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) * faster bin computation & slightly different binning * merged all consolidations to one part of malloc proper - (eliminating old malloc_find_space & malloc_clean_bin) + (eliminating old malloc_find_space & malloc_clean_bin) * Scan 2 returns chunks (not just 1) * Propagate failure in realloc if malloc returns 0 * Add stuff to allow compilation on non-ANSI compilers - from kpv@research.att.com + from kpv@research.att.com V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) * removed potential for odd address access in prev_chunk @@ -3305,13 +3292,11 @@ History: * misc cosmetics and a bit more internal documentation * anticosmetics: mangled names in macros to evade debugger strangeness * tested on sparc, hp-700, dec-mips, rs6000 - with gcc & native cc (hp, dec only) allowing - Detlefs & Zorn comparison study (in SIGPLAN Notices.) + with gcc & native cc (hp, dec only) allowing + Detlefs & Zorn comparison study (in SIGPLAN Notices.) Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) * Based loosely on libg++-1.2X malloc. (It retains some of the overall - structure of old version, but most details differ.) + structure of old version, but most details differ.) */ - - diff --git a/common/dlmalloc.src b/common/dlmalloc.src index 12b85bb830..32a38bc70c 100644 --- a/common/dlmalloc.src +++ b/common/dlmalloc.src @@ -8,8 +8,8 @@ * VERSION 2.6.6 Sun Mar 5 19:10:03 2000 Doug Lea (dl at gee) Note: There may be an updated version of this malloc obtainable at - ftp://g.oswego.edu/pub/misc/malloc.c - Check before installing! + ftp://g.oswego.edu/pub/misc/malloc.c + Check before installing! * Why use this malloc? @@ -86,7 +86,7 @@ and status information. Minimum allocated size: 4-byte ptrs: 16 bytes (including 4 overhead) - 8-byte ptrs: 24/32 bytes (including, 4/8 overhead) + 8-byte ptrs: 24/32 bytes (including, 4/8 overhead) When a chunk is freed, 12 (for 4byte ptrs) or 20 (for 8 byte ptrs but 4 byte size) or 24 (for 8/8) additional bytes are @@ -98,7 +98,7 @@ pointer to something of the minimum allocatable size. Maximum allocated size: 4-byte size_t: 2^31 - 8 bytes - 8-byte size_t: 2^63 - 16 bytes + 8-byte size_t: 2^63 - 16 bytes It is assumed that (possibly signed) size_t bit values suffice to represent chunk sizes. `Possibly signed' is due to the fact @@ -114,11 +114,11 @@ make the normal worst-case wastage 15 bytes (i.e., up to 15 more bytes will be allocated than were requested in malloc), with two exceptions: - 1. Because requests for zero bytes allocate non-zero space, - the worst case wastage for a request of zero bytes is 24 bytes. - 2. For requests >= mmap_threshold that are serviced via - mmap(), the worst case wastage is 8 bytes plus the remainder - from a system page (the minimal mmap unit); typically 4096 bytes. + 1. Because requests for zero bytes allocate non-zero space, + the worst case wastage for a request of zero bytes is 24 bytes. + 2. For requests >= mmap_threshold that are serviced via + mmap(), the worst case wastage is 8 bytes plus the remainder + from a system page (the minimal mmap unit); typically 4096 bytes. * Limitations @@ -371,8 +371,8 @@ void* memset(void*, int, size_t); void* memcpy(void*, const void*, size_t); #else #ifdef WIN32 -// On Win32 platforms, 'memset()' and 'memcpy()' are already declared in -// 'windows.h' +/* On Win32 platforms, 'memset()' and 'memcpy()' are already declared in */ +/* 'windows.h' */ #else Void_t* memset(); Void_t* memcpy(); @@ -392,14 +392,14 @@ do { \ if(mzsz <= 9*sizeof(mzsz)) { \ INTERNAL_SIZE_T* mz = (INTERNAL_SIZE_T*) (charp); \ if(mzsz >= 5*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; \ + *mz++ = 0; \ if(mzsz >= 7*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; \ - if(mzsz >= 9*sizeof(mzsz)) { *mz++ = 0; \ - *mz++ = 0; }}} \ - *mz++ = 0; \ - *mz++ = 0; \ - *mz = 0; \ + *mz++ = 0; \ + if(mzsz >= 9*sizeof(mzsz)) { *mz++ = 0; \ + *mz++ = 0; }}} \ + *mz++ = 0; \ + *mz++ = 0; \ + *mz = 0; \ } else memset((charp), 0, mzsz); \ } while(0) @@ -410,14 +410,14 @@ do { \ INTERNAL_SIZE_T* mcsrc = (INTERNAL_SIZE_T*) (src); \ INTERNAL_SIZE_T* mcdst = (INTERNAL_SIZE_T*) (dest); \ if(mcsz >= 5*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ + *mcdst++ = *mcsrc++; \ if(mcsz >= 7*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ - if(mcsz >= 9*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; }}} \ - *mcdst++ = *mcsrc++; \ - *mcdst++ = *mcsrc++; \ - *mcdst = *mcsrc ; \ + *mcdst++ = *mcsrc++; \ + if(mcsz >= 9*sizeof(mcsz)) { *mcdst++ = *mcsrc++; \ + *mcdst++ = *mcsrc++; }}} \ + *mcdst++ = *mcsrc++; \ + *mcdst++ = *mcsrc++; \ + *mcdst = *mcsrc ; \ } else memcpy(dest, src, mcsz); \ } while(0) @@ -557,7 +557,6 @@ do { \ #endif - /* This version of malloc supports the standard SVID/XPG mallinfo @@ -621,7 +620,6 @@ struct mallinfo { #define M_MMAP_MAX -4 - #ifndef DEFAULT_TRIM_THRESHOLD #define DEFAULT_TRIM_THRESHOLD (128 * 1024) #endif @@ -685,11 +683,11 @@ struct mallinfo { retain whenever sbrk is called. It is used in two ways internally: * When sbrk is called to extend the top of the arena to satisfy - a new malloc request, this much padding is added to the sbrk - request. + a new malloc request, this much padding is added to the sbrk + request. * When malloc_trim is called automatically from free(), - it is used as the `pad' argument. + it is used as the `pad' argument. In both cases, the actual amount of padding is rounded so that the end of the arena is always a system page boundary. @@ -735,15 +733,15 @@ struct mallinfo { However, it has the disadvantages that: - 1. The space cannot be reclaimed, consolidated, and then - used to service later requests, as happens with normal chunks. - 2. It can lead to more wastage because of mmap page alignment - requirements - 3. It causes malloc performance to be more dependent on host - system memory management support routines which may vary in - implementation quality and may impose arbitrary - limitations. Generally, servicing a request via normal - malloc steps is faster than going through a system's mmap. + 1. The space cannot be reclaimed, consolidated, and then + used to service later requests, as happens with normal chunks. + 2. It can lead to more wastage because of mmap page alignment + requirements + 3. It causes malloc performance to be more dependent on host + system memory management support routines which may vary in + implementation quality and may impose arbitrary + limitations. Generally, servicing a request via normal + malloc steps is faster than going through a system's mmap. All together, these considerations should lead you to use mmap only for relatively large requests. @@ -752,7 +750,6 @@ struct mallinfo { */ - #ifndef DEFAULT_MMAP_MAX #if HAVE_MMAP #define DEFAULT_MMAP_MAX (64) @@ -765,15 +762,15 @@ struct mallinfo { M_MMAP_MAX is the maximum number of requests to simultaneously service using mmap. This parameter exists because: - 1. Some systems have a limited number of internal tables for - use by mmap. - 2. In most systems, overreliance on mmap can degrade overall - performance. - 3. If a program allocates many large regions, it is probably - better off using normal sbrk-based allocation routines that - can reclaim and reallocate normal heap memory. Using a - small value allows transition into this mode after the - first few allocations. + 1. Some systems have a limited number of internal tables for + use by mmap. + 2. In most systems, overreliance on mmap can degrade overall + performance. + 3. If a program allocates many large regions, it is probably + better off using normal sbrk-based allocation routines that + can reclaim and reallocate normal heap memory. Using a + small value allows transition into this mode after the + first few allocations. Setting to 0 disables all use of mmap. If HAVE_MMAP is not set, the default value is 0, and attempts to set it to non-zero values @@ -781,8 +778,6 @@ struct mallinfo { */ - - /* USE_DL_PREFIX will prefix all public routines with the string 'dl'. Useful to quickly avoid procedure declaration conflicts and linker @@ -793,8 +788,6 @@ struct mallinfo { /* #define USE_DL_PREFIX */ - - /* Special defines for linux libc @@ -998,7 +991,7 @@ void gcleanup () rval = VirtualFree ((void*)gAddressBase, gNextAddress - gAddressBase, MEM_DECOMMIT); - assert (rval); + assert (rval); } while (head) { @@ -1023,24 +1016,24 @@ void* findRegion (void* start_address, unsigned long size) return start_address; else { - // Requested region is not available so see if the - // next region is available. Set 'start_address' - // to the next region and call 'VirtualQuery()' - // again. + /* Requested region is not available so see if the */ + /* next region is available. Set 'start_address' */ + /* to the next region and call 'VirtualQuery()' */ + /* again. */ start_address = (char*)info.BaseAddress + info.RegionSize; - // Make sure we start looking for the next region - // on the *next* 64K boundary. Otherwise, even if - // the new region is free according to - // 'VirtualQuery()', the subsequent call to - // 'VirtualAlloc()' (which follows the call to - // this routine in 'wsbrk()') will round *down* - // the requested address to a 64K boundary which - // we already know is an address in the - // unavailable region. Thus, the subsequent call - // to 'VirtualAlloc()' will fail and bring us back - // here, causing us to go into an infinite loop. + /* Make sure we start looking for the next region */ + /* on the *next* 64K boundary. Otherwise, even if */ + /* the new region is free according to */ + /* 'VirtualQuery()', the subsequent call to */ + /* 'VirtualAlloc()' (which follows the call to */ + /* this routine in 'wsbrk()') will round *down* */ + /* the requested address to a 64K boundary which */ + /* we already know is an address in the */ + /* unavailable region. Thus, the subsequent call */ + /* to 'VirtualAlloc()' will fail and bring us back */ + /* here, causing us to go into an infinite loop. */ start_address = (void *) AlignPage64K((unsigned long) start_address); @@ -1077,9 +1070,9 @@ gAllocatedSize)) gAddressBase = gNextAddress = (unsigned int)VirtualAlloc (new_address, new_size, MEM_RESERVE, PAGE_NOACCESS); - // repeat in case of race condition - // The region that we found has been snagged - // by another thread + /* repeat in case of race condition */ + /* The region that we found has been snagged */ + /* by another thread */ } while (gAddressBase == 0); @@ -1167,17 +1160,17 @@ typedef struct malloc_chunk* mchunkptr; chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk, if allocated | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of chunk, in bytes |P| + | Size of previous chunk, if allocated | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of chunk, in bytes |P| mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | User data starts here... . - . . - . (malloc_usable_space() bytes) . - . | + | User data starts here... . + . . + . (malloc_usable_space() bytes) . + . | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Where "chunk" is the front of the chunk for the purpose of most of @@ -1191,20 +1184,20 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Free chunks are stored in circular doubly-linked lists, and look like this: chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of previous chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `head:' | Size of chunk, in bytes |P| mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Forward pointer to next chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Back pointer to previous chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unused space (may be 0 bytes long) . - . . - . | + | Forward pointer to next chunk in list | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Back pointer to previous chunk in list | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unused space (may be 0 bytes long) . + . . + . | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `foot:' | Size of chunk, in bytes | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The P (PREV_INUSE) bit, stored in the unused low-order bit of the chunk size (which is always a multiple of two words), is an in-use @@ -1221,16 +1214,16 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The two exceptions to all this are 1. The special chunk `top', which doesn't bother using the - trailing size field since there is no - next contiguous chunk that would have to index off it. (After - initialization, `top' is forced to always exist. If it would - become less than MINSIZE bytes long, it is replenished via - malloc_extend_top.) + trailing size field since there is no + next contiguous chunk that would have to index off it. (After + initialization, `top' is forced to always exist. If it would + become less than MINSIZE bytes long, it is replenished via + malloc_extend_top.) 2. Chunks allocated via mmap, which have the second-lowest-order - bit (IS_MMAPPED) set in their size fields. Because they are - never merged or traversed from any other chunk, they have no - foot size or inuse information. + bit (IS_MMAPPED) set in their size fields. Because they are + never merged or traversed from any other chunk, they have no + foot size or inuse information. Available chunks are kept in any of several places (all declared below): @@ -1273,7 +1266,6 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - @@ -1506,7 +1498,7 @@ static mbinptr av_[NAV * 2 + 2] = { ((((unsigned long)(sz)) >> 9) <= 84) ? 110 + (((unsigned long)(sz)) >> 12): \ ((((unsigned long)(sz)) >> 9) <= 340) ? 119 + (((unsigned long)(sz)) >> 15): \ ((((unsigned long)(sz)) >> 9) <= 1364) ? 124 + (((unsigned long)(sz)) >> 18): \ - 126) + 126) /* bins for chunks < 512 are all spaced 8 bytes apart, and hold identically sized chunks. This is exploited in malloc. @@ -1794,7 +1786,6 @@ static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s; (last_remainder->fd = last_remainder->bk = last_remainder) - @@ -1995,7 +1986,7 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; /* Guarantee the next brk will be at a page boundary */ correction += ((((unsigned long)(brk + sbrk_size))+(pagesz-1)) & - ~(pagesz - 1)) - ((unsigned long)(brk + sbrk_size)); + ~(pagesz - 1)) - ((unsigned long)(brk + sbrk_size)); /* Allocate correction */ new_brk = (char*)(MORECORE (correction)); @@ -2016,20 +2007,20 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; /* If not enough space to do this, then user did something very wrong */ if (old_top_size < MINSIZE) { - set_head(top, PREV_INUSE); /* will force null return from malloc */ - return; + set_head(top, PREV_INUSE); /* will force null return from malloc */ + return; } /* Also keep size a multiple of MALLOC_ALIGNMENT */ old_top_size = (old_top_size - 3*SIZE_SZ) & ~MALLOC_ALIGN_MASK; set_head_size(old_top, old_top_size); chunk_at_offset(old_top, old_top_size )->size = - SIZE_SZ|PREV_INUSE; + SIZE_SZ|PREV_INUSE; chunk_at_offset(old_top, old_top_size + SIZE_SZ)->size = - SIZE_SZ|PREV_INUSE; + SIZE_SZ|PREV_INUSE; /* If possible, release the rest. */ if (old_top_size >= MINSIZE) - fREe(chunk2mem(old_top)); + fREe(chunk2mem(old_top)); } } @@ -2060,43 +2051,43 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; From there, the first successful of the following steps is taken: 1. The bin corresponding to the request size is scanned, and if - a chunk of exactly the right size is found, it is taken. + a chunk of exactly the right size is found, it is taken. 2. The most recently remaindered chunk is used if it is big - enough. This is a form of (roving) first fit, used only in - the absence of exact fits. Runs of consecutive requests use - the remainder of the chunk used for the previous such request - whenever possible. This limited use of a first-fit style - allocation strategy tends to give contiguous chunks - coextensive lifetimes, which improves locality and can reduce - fragmentation in the long run. + enough. This is a form of (roving) first fit, used only in + the absence of exact fits. Runs of consecutive requests use + the remainder of the chunk used for the previous such request + whenever possible. This limited use of a first-fit style + allocation strategy tends to give contiguous chunks + coextensive lifetimes, which improves locality and can reduce + fragmentation in the long run. 3. Other bins are scanned in increasing size order, using a - chunk big enough to fulfill the request, and splitting off - any remainder. This search is strictly by best-fit; i.e., - the smallest (with ties going to approximately the least - recently used) chunk that fits is selected. + chunk big enough to fulfill the request, and splitting off + any remainder. This search is strictly by best-fit; i.e., + the smallest (with ties going to approximately the least + recently used) chunk that fits is selected. 4. If large enough, the chunk bordering the end of memory - (`top') is split off. (This use of `top' is in accord with - the best-fit search rule. In effect, `top' is treated as - larger (and thus less well fitting) than any other available - chunk since it can be extended to be as large as necessary - (up to system limitations). + (`top') is split off. (This use of `top' is in accord with + the best-fit search rule. In effect, `top' is treated as + larger (and thus less well fitting) than any other available + chunk since it can be extended to be as large as necessary + (up to system limitations). 5. If the request size meets the mmap threshold and the - system supports mmap, and there are few enough currently - allocated mmapped regions, and a call to mmap succeeds, - the request is allocated via direct memory mapping. + system supports mmap, and there are few enough currently + allocated mmapped regions, and a call to mmap succeeds, + the request is allocated via direct memory mapping. 6. Otherwise, the top of memory is extended by - obtaining more space from the system (normally using sbrk, - but definable to anything else via the MORECORE macro). - Memory is gathered from the system (in system page-sized - units) in a way that allows chunks obtained across different - sbrk calls to be consolidated, but does not require - contiguous memory. Thus, it should be safe to intersperse - mallocs with other sbrk calls. + obtaining more space from the system (normally using sbrk, + but definable to anything else via the MORECORE macro). + Memory is gathered from the system (in system page-sized + units) in a way that allows chunks obtained across different + sbrk calls to be consolidated, but does not require + contiguous memory. Thus, it should be safe to intersperse + mallocs with other sbrk calls. All allocations are made from the the `lowest' part of any found @@ -2173,16 +2164,16 @@ Void_t* mALLOc(bytes) size_t bytes; if (remainder_size >= (long)MINSIZE) /* too big */ { - --idx; /* adjust to rescan below after checking last remainder */ - break; + --idx; /* adjust to rescan below after checking last remainder */ + break; } else if (remainder_size >= 0) /* exact fit */ { - unlink(victim, bck, fwd); - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); + unlink(victim, bck, fwd); + set_inuse_bit_at_offset(victim, victim_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); } } @@ -2239,8 +2230,8 @@ Void_t* mALLOc(bytes) size_t bytes; block <<= 1; while ((block & binblocks) == 0) { - idx += BINBLOCKWIDTH; - block <<= 1; + idx += BINBLOCKWIDTH; + block <<= 1; } } @@ -2253,34 +2244,34 @@ Void_t* mALLOc(bytes) size_t bytes; /* For each bin in this block ... */ do { - /* Find and use first big enough chunk ... */ - - for (victim = last(bin); victim != bin; victim = victim->bk) - { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long)MINSIZE) /* split */ - { - remainder = chunk_at_offset(victim, nb); - set_head(victim, nb | PREV_INUSE); - unlink(victim, bck, fwd); - link_last_remainder(remainder); - set_head(remainder, remainder_size | PREV_INUSE); - set_foot(remainder, remainder_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - else if (remainder_size >= 0) /* take */ - { - set_inuse_bit_at_offset(victim, victim_size); - unlink(victim, bck, fwd); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - } + /* Find and use first big enough chunk ... */ + + for (victim = last(bin); victim != bin; victim = victim->bk) + { + victim_size = chunksize(victim); + remainder_size = victim_size - nb; + + if (remainder_size >= (long)MINSIZE) /* split */ + { + remainder = chunk_at_offset(victim, nb); + set_head(victim, nb | PREV_INUSE); + unlink(victim, bck, fwd); + link_last_remainder(remainder); + set_head(remainder, remainder_size | PREV_INUSE); + set_foot(remainder, remainder_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + + else if (remainder_size >= 0) /* take */ + { + set_inuse_bit_at_offset(victim, victim_size); + unlink(victim, bck, fwd); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + + } bin = next_bin(bin); @@ -2290,12 +2281,12 @@ Void_t* mALLOc(bytes) size_t bytes; do /* Possibly backtrack to try to clear a partial block */ { - if ((startidx & (BINBLOCKWIDTH - 1)) == 0) - { - binblocks &= ~block; - break; - } - --startidx; + if ((startidx & (BINBLOCKWIDTH - 1)) == 0) + { + binblocks &= ~block; + break; + } + --startidx; q = prev_bin(q); } while (first(q) == q); @@ -2303,14 +2294,14 @@ Void_t* mALLOc(bytes) size_t bytes; if ( (block <<= 1) <= binblocks && (block != 0) ) { - while ((block & binblocks) == 0) - { - idx += BINBLOCKWIDTH; - block <<= 1; - } + while ((block & binblocks) == 0) + { + idx += BINBLOCKWIDTH; + block <<= 1; + } } else - break; + break; } } @@ -2324,7 +2315,7 @@ Void_t* mALLOc(bytes) size_t bytes; #if HAVE_MMAP /* If big and would otherwise need to extend, try to use mmap instead */ if ((unsigned long)nb >= (unsigned long)mmap_threshold && - (victim = mmap_chunk(nb)) != 0) + (victim = mmap_chunk(nb)) != 0) return chunk2mem(victim); #endif @@ -2357,13 +2348,13 @@ Void_t* mALLOc(bytes) size_t bytes; 2. If the chunk was allocated via mmap, it is release via munmap(). 3. If a returned chunk borders the current high end of memory, - it is consolidated into the top, and if the total unused - topmost memory exceeds the trim threshold, malloc_trim is - called. + it is consolidated into the top, and if the total unused + topmost memory exceeds the trim threshold, malloc_trim is + called. 4. Other chunks are consolidated as they arrive, and - placed in corresponding bins. (This includes the case of - consolidating with the current `last_remainder'). + placed in corresponding bins. (This includes the case of + consolidating with the current `last_remainder'). */ @@ -2575,22 +2566,22 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; /* Forward into top only if a remainder */ if (next == top) { - if ((long)(nextsize + newsize) >= (long)(nb + MINSIZE)) - { - newsize += nextsize; - top = chunk_at_offset(oldp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(oldp, nb); - return chunk2mem(oldp); - } + if ((long)(nextsize + newsize) >= (long)(nb + MINSIZE)) + { + newsize += nextsize; + top = chunk_at_offset(oldp, nb); + set_head(top, (newsize - nb) | PREV_INUSE); + set_head_size(oldp, nb); + return chunk2mem(oldp); + } } /* Forward into next chunk */ else if (((long)(nextsize + newsize) >= (long)(nb))) { - unlink(next, bck, fwd); - newsize += nextsize; - goto split; + unlink(next, bck, fwd); + newsize += nextsize; + goto split; } } else @@ -2610,45 +2601,45 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; if (next != 0) { - /* into top */ - if (next == top) - { - if ((long)(nextsize + prevsize + newsize) >= (long)(nb + MINSIZE)) - { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize + nextsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - top = chunk_at_offset(newp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(newp, nb); - return newmem; - } - } - - /* into next chunk */ - else if (((long)(nextsize + prevsize + newsize) >= (long)(nb))) - { - unlink(next, bck, fwd); - unlink(prev, bck, fwd); - newp = prev; - newsize += nextsize + prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; - } + /* into top */ + if (next == top) + { + if ((long)(nextsize + prevsize + newsize) >= (long)(nb + MINSIZE)) + { + unlink(prev, bck, fwd); + newp = prev; + newsize += prevsize + nextsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + top = chunk_at_offset(newp, nb); + set_head(top, (newsize - nb) | PREV_INUSE); + set_head_size(newp, nb); + return newmem; + } + } + + /* into next chunk */ + else if (((long)(nextsize + prevsize + newsize) >= (long)(nb))) + { + unlink(next, bck, fwd); + unlink(prev, bck, fwd); + newp = prev; + newsize += nextsize + prevsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + goto split; + } } /* backward only */ if (prev != 0 && (long)(prevsize + newsize) >= (long)nb) { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; + unlink(prev, bck, fwd); + newp = prev; + newsize += prevsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + goto split; } } @@ -2980,25 +2971,25 @@ int malloc_trim(pad) size_t pad; if (new_brk == (char*)(MORECORE_FAILURE)) /* sbrk failed? */ { - /* Try to figure out what we have */ - current_brk = (char*)(MORECORE (0)); - top_size = current_brk - (char*)top; - if (top_size >= (long)MINSIZE) /* if not, we are very very dead! */ - { - sbrked_mem = current_brk - sbrk_base; - set_head(top, top_size | PREV_INUSE); - } - check_chunk(top); - return 0; + /* Try to figure out what we have */ + current_brk = (char*)(MORECORE (0)); + top_size = current_brk - (char*)top; + if (top_size >= (long)MINSIZE) /* if not, we are very very dead! */ + { + sbrked_mem = current_brk - sbrk_base; + set_head(top, top_size | PREV_INUSE); + } + check_chunk(top); + return 0; } else { - /* Success. Adjust top accordingly. */ - set_head(top, (top_size - extra) | PREV_INUSE); - sbrked_mem -= extra; - check_chunk(top); - return 1; + /* Success. Adjust top accordingly. */ + set_head(top, (top_size - extra) | PREV_INUSE); + sbrked_mem -= extra; + check_chunk(top); + return 1; } } } @@ -3064,9 +3055,9 @@ static void malloc_update_mallinfo() #if DEBUG check_free_chunk(p); for (q = next_chunk(p); - q < top && inuse(q) && (long)(chunksize(q)) >= (long)MINSIZE; - q = next_chunk(q)) - check_inuse_chunk(q); + q < top && inuse(q) && (long)(chunksize(q)) >= (long)MINSIZE; + q = next_chunk(q)) + check_inuse_chunk(q); #endif avail += chunksize(p); navail++; @@ -3103,14 +3094,14 @@ void malloc_stats() { malloc_update_mallinfo(); fprintf(stderr, "max system bytes = %10u\n", - (unsigned int)(max_total_mem)); + (unsigned int)(max_total_mem)); fprintf(stderr, "system bytes = %10u\n", - (unsigned int)(sbrked_mem + mmapped_mem)); + (unsigned int)(sbrked_mem + mmapped_mem)); fprintf(stderr, "in use bytes = %10u\n", - (unsigned int)(current_mallinfo.uordblks + mmapped_mem)); + (unsigned int)(current_mallinfo.uordblks + mmapped_mem)); #if HAVE_MMAP fprintf(stderr, "max mmap regions = %10u\n", - (unsigned int)max_n_mmaps); + (unsigned int)max_n_mmaps); #endif } @@ -3173,17 +3164,17 @@ History: V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee) * return null for negative arguments * Added Several WIN32 cleanups from Martin C. Fong - * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' - (e.g. WIN32 platforms) - * Cleanup up header file inclusion for WIN32 platforms - * Cleanup code to avoid Microsoft Visual C++ compiler complaints - * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing - memory allocation routines - * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) - * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to + * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' + (e.g. WIN32 platforms) + * Cleanup up header file inclusion for WIN32 platforms + * Cleanup code to avoid Microsoft Visual C++ compiler complaints + * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing + memory allocation routines + * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) + * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to usage of 'assert' in non-WIN32 code - * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to - avoid infinite loop + * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to + avoid infinite loop * Always call 'fREe()' rather than 'free()' V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee) @@ -3195,13 +3186,13 @@ History: * Added anonymously donated WIN32 sbrk emulation * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen * malloc_extend_top: fix mask error that caused wastage after - foreign sbrks + foreign sbrks * Add linux mremap support code from HJ Liu V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) * Integrated most documentation with the code. * Add support for mmap, with help from - Wolfram Gloger (Gloger@lrz.uni-muenchen.de). + Wolfram Gloger (Gloger@lrz.uni-muenchen.de). * Use last_remainder in more cases. * Pack bins using idea from colin@nyx10.cs.du.edu * Use ordered bins instead of best-fit threshhold @@ -3209,34 +3200,34 @@ History: * Support another case of realloc via move into top * Fix error occuring when initial sbrk_base not word-aligned. * Rely on page size for units instead of SBRK_UNIT to - avoid surprises about sbrk alignment conventions. + avoid surprises about sbrk alignment conventions. * Add mallinfo, mallopt. Thanks to Raymond Nijssen - (raymond@es.ele.tue.nl) for the suggestion. + (raymond@es.ele.tue.nl) for the suggestion. * Add `pad' argument to malloc_trim and top_pad mallopt parameter. * More precautions for cases where other routines call sbrk, - courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). + courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). * Added macros etc., allowing use in linux libc from - H.J. Lu (hjl@gnu.ai.mit.edu) + H.J. Lu (hjl@gnu.ai.mit.edu) * Inverted this history list V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) * Re-tuned and fixed to behave more nicely with V2.6.0 changes. * Removed all preallocation code since under current scheme - the work required to undo bad preallocations exceeds - the work saved in good cases for most test programs. + the work required to undo bad preallocations exceeds + the work saved in good cases for most test programs. * No longer use return list or unconsolidated bins since - no scheme using them consistently outperforms those that don't - given above changes. + no scheme using them consistently outperforms those that don't + given above changes. * Use best fit for very large chunks to prevent some worst-cases. * Added some support for debugging V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) * Removed footers when chunks are in use. Thanks to - Paul Wilson (wilson@cs.texas.edu) for the suggestion. + Paul Wilson (wilson@cs.texas.edu) for the suggestion. V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) * Added malloc_trim, with help from Wolfram Gloger - (wmglo@Dent.MED.Uni-Muenchen.DE). + (wmglo@Dent.MED.Uni-Muenchen.DE). V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) @@ -3252,11 +3243,11 @@ History: V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) * faster bin computation & slightly different binning * merged all consolidations to one part of malloc proper - (eliminating old malloc_find_space & malloc_clean_bin) + (eliminating old malloc_find_space & malloc_clean_bin) * Scan 2 returns chunks (not just 1) * Propagate failure in realloc if malloc returns 0 * Add stuff to allow compilation on non-ANSI compilers - from kpv@research.att.com + from kpv@research.att.com V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) * removed potential for odd address access in prev_chunk @@ -3264,13 +3255,11 @@ History: * misc cosmetics and a bit more internal documentation * anticosmetics: mangled names in macros to evade debugger strangeness * tested on sparc, hp-700, dec-mips, rs6000 - with gcc & native cc (hp, dec only) allowing - Detlefs & Zorn comparison study (in SIGPLAN Notices.) + with gcc & native cc (hp, dec only) allowing + Detlefs & Zorn comparison study (in SIGPLAN Notices.) Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) * Based loosely on libg++-1.2X malloc. (It retains some of the overall - structure of old version, but most details differ.) + structure of old version, but most details differ.) */ - - diff --git a/common/docecc.c b/common/docecc.c index 74ac7411a4..cf45e0f6d9 100644 --- a/common/docecc.c +++ b/common/docecc.c @@ -98,30 +98,30 @@ for(ci=(n)-1;ci >=0;ci--)\ /* generate GF(2**m) from the irreducible polynomial p(X) in Pp[0]..Pp[m] lookup tables: index->polynomial form alpha_to[] contains j=alpha**i; - polynomial form -> index form index_of[j=alpha**i] = i + polynomial form -> index form index_of[j=alpha**i] = i alpha=2 is the primitive element of GF(2**m) HARI's COMMENT: (4/13/94) alpha_to[] can be used as follows: - Let @ represent the primitive element commonly called "alpha" that + Let @ represent the primitive element commonly called "alpha" that is the root of the primitive polynomial p(x). Then in GF(2^m), for any 0 <= i <= 2^m-2, - @^i = a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1) + @^i = a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1) where the binary vector (a(0),a(1),a(2),...,a(m-1)) is the representation of the integer "alpha_to[i]" with a(0) being the LSB and a(m-1) the MSB. Thus for example the polynomial representation of @^5 would be given by the binary representation of the integer "alpha_to[5]". - Similarily, index_of[] can be used as follows: - As above, let @ represent the primitive element of GF(2^m) that is + Similarily, index_of[] can be used as follows: + As above, let @ represent the primitive element of GF(2^m) that is the root of the primitive polynomial p(x). In order to find the power of @ (alpha) that has the polynomial representation - a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1) + a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1) we consider the integer "i" whose binary representation with a(0) being LSB and a(m-1) MSB is (a(0),a(1),...,a(m-1)) and locate the entry "index_of[i]". Now, @^index_of[i] is that element whose polynomial representation is (a(0),a(1),a(2),...,a(m-1)). NOTE: - The element alpha_to[2^m-1] = 0 always signifying that the + The element alpha_to[2^m-1] = 0 always signifying that the representation of "@^infinity" = 0 is (0,0,0,...,0). - Similarily, the element index_of[0] = A0 always signifying + Similarily, the element index_of[0] = A0 always signifying that the power of alpha which has the polynomial representation (0,0,...,0) is "infinity". @@ -183,8 +183,8 @@ generate_gf(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1]) * */ static int eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1], - gf bb[NN - KK + 1], gf eras_val[NN-KK], int eras_pos[NN-KK], - int no_eras) + gf bb[NN - KK + 1], gf eras_val[NN-KK], int eras_pos[NN-KK], + int no_eras) { int deg_lambda, el, deg_omega; int i, j, r,k; @@ -225,7 +225,7 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1], for(i=1;i<=NN-KK;i++) { tmp = Index_of[s[i]]; if (tmp != A0) - tmp = modnn(tmp + 2 * KK * (B0+i-1)*PRIM); + tmp = modnn(tmp + 2 * KK * (B0+i-1)*PRIM); s[i] = tmp; } @@ -412,9 +412,9 @@ eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1], } /* Apply error to data */ if (num1 != 0) { - eras_val[j] = Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])]; + eras_val[j] = Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])]; } else { - eras_val[j] = 0; + eras_val[j] = 0; } } finish: @@ -447,12 +447,12 @@ int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6]) /* init log and exp tables here to save memory. However, it is slower */ Alpha_to = malloc((NN + 1) * sizeof(dtype)); if (!Alpha_to) - return -1; + return -1; Index_of = malloc((NN + 1) * sizeof(dtype)); if (!Index_of) { - free(Alpha_to); - return -1; + free(Alpha_to); + return -1; } generate_gf(Alpha_to, Index_of); @@ -465,48 +465,48 @@ int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6]) bb[3] = ((ecc1[3] & 0xc0) >> 6) | ((ecc1[0] & 0xff) << 2); nb_errors = eras_dec_rs(Alpha_to, Index_of, bb, - error_val, error_pos, 0); + error_val, error_pos, 0); if (nb_errors <= 0) - goto the_end; + goto the_end; /* correct the errors */ for(i=0;i= NB_DATA && pos < KK) { - nb_errors = -1; - goto the_end; - } - if (pos < NB_DATA) { - /* extract bit position (MSB first) */ - pos = 10 * (NB_DATA - 1 - pos) - 6; - /* now correct the following 10 bits. At most two bytes - can be modified since pos is even */ - index = (pos >> 3) ^ 1; - bitpos = pos & 7; - if ((index >= 0 && index < SECTOR_SIZE) || - index == (SECTOR_SIZE + 1)) { - val = error_val[i] >> (2 + bitpos); - parity ^= val; - if (index < SECTOR_SIZE) - sector[index] ^= val; - } - index = ((pos >> 3) + 1) ^ 1; - bitpos = (bitpos + 10) & 7; - if (bitpos == 0) - bitpos = 8; - if ((index >= 0 && index < SECTOR_SIZE) || - index == (SECTOR_SIZE + 1)) { - val = error_val[i] << (8 - bitpos); - parity ^= val; - if (index < SECTOR_SIZE) - sector[index] ^= val; - } - } + pos = error_pos[i]; + if (pos >= NB_DATA && pos < KK) { + nb_errors = -1; + goto the_end; + } + if (pos < NB_DATA) { + /* extract bit position (MSB first) */ + pos = 10 * (NB_DATA - 1 - pos) - 6; + /* now correct the following 10 bits. At most two bytes + can be modified since pos is even */ + index = (pos >> 3) ^ 1; + bitpos = pos & 7; + if ((index >= 0 && index < SECTOR_SIZE) || + index == (SECTOR_SIZE + 1)) { + val = error_val[i] >> (2 + bitpos); + parity ^= val; + if (index < SECTOR_SIZE) + sector[index] ^= val; + } + index = ((pos >> 3) + 1) ^ 1; + bitpos = (bitpos + 10) & 7; + if (bitpos == 0) + bitpos = 8; + if ((index >= 0 && index < SECTOR_SIZE) || + index == (SECTOR_SIZE + 1)) { + val = error_val[i] << (8 - bitpos); + parity ^= val; + if (index < SECTOR_SIZE) + sector[index] ^= val; + } + } } /* use parity to test extra errors */ if ((parity & 0xff) != 0) - nb_errors = -1; + nb_errors = -1; the_end: free(Alpha_to); diff --git a/common/env_common.c b/common/env_common.c index ea08501320..e7ee4991f8 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include diff --git a/common/env_eeprom.c b/common/env_eeprom.c index 9f1d82a798..300af6fcfe 100644 --- a/common/env_eeprom.c +++ b/common/env_eeprom.c @@ -30,7 +30,6 @@ #include #include -#include #include #include diff --git a/common/env_flash.c b/common/env_flash.c index 426d01b19b..af99880e4d 100644 --- a/common/env_flash.c +++ b/common/env_flash.c @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -185,14 +184,14 @@ int saveenv(void) debug ("Data to save 0x%x\n", up_data); if (up_data) { if ((saved_data = malloc(up_data)) == NULL) { - printf("Unable to save the rest of sector (%ld)\n", + printf("Unable to save the rest of sector (%ld)\n", up_data); goto Done; } - memcpy(saved_data, + memcpy(saved_data, (void *)((long)flash_addr_new + CFG_ENV_SIZE), up_data); - debug ("Data (start 0x%x, len 0x%x) saved at 0x%x\n", - (long)flash_addr_new + CFG_ENV_SIZE, + debug ("Data (start 0x%x, len 0x%x) saved at 0x%x\n", + (long)flash_addr_new + CFG_ENV_SIZE, up_data, saved_data); } #endif @@ -209,19 +208,19 @@ int saveenv(void) (ulong)&(flash_addr_new->data), sizeof(env_ptr->data)+(ulong)&(flash_addr_new->data)); if (flash_write(env_ptr->data, - (ulong)&(flash_addr_new->data), + (ulong)&(flash_addr_new->data), sizeof(env_ptr->data)) || flash_write((char *)&(env_ptr->crc), - (ulong)&(flash_addr_new->crc), + (ulong)&(flash_addr_new->crc), sizeof(env_ptr->crc)) || flash_write((char *)&obsolete_flag, - (ulong)&(flash_addr->flags), + (ulong)&(flash_addr->flags), sizeof(flash_addr->flags)) || flash_write((char *)&active_flag, - (ulong)&(flash_addr_new->flags), + (ulong)&(flash_addr_new->flags), sizeof(flash_addr_new->flags))) { flash_perror (rc); @@ -233,8 +232,8 @@ int saveenv(void) if (up_data) { /* restore the rest of sector */ debug ("Restoring the rest of data to 0x%x len 0x%x\n", (long)flash_addr_new + CFG_ENV_SIZE, up_data); - if (flash_write(saved_data, - (long)flash_addr_new + CFG_ENV_SIZE, + if (flash_write(saved_data, + (long)flash_addr_new + CFG_ENV_SIZE, up_data)) { flash_perror(rc); goto Done; @@ -381,8 +380,8 @@ void env_relocate_spec (void) gd->env_valid = 2; flash_sect_protect (0, (ulong)flash_addr_new, end_addr_new); flash_write((char *)&obsolete_flag, - (ulong)&(flash_addr_new->flags), - sizeof(flash_addr_new->flags)); + (ulong)&(flash_addr_new->flags), + sizeof(flash_addr_new->flags)); flash_sect_protect (1, (ulong)flash_addr_new, end_addr_new); } @@ -392,8 +391,8 @@ void env_relocate_spec (void) gd->env_valid = 2; flash_sect_protect (0, (ulong)flash_addr, end_addr); flash_write((char *)&active_flag, - (ulong)&(flash_addr->flags), - sizeof(flash_addr->flags)); + (ulong)&(flash_addr->flags), + sizeof(flash_addr->flags)); flash_sect_protect (1, (ulong)flash_addr, end_addr); } diff --git a/common/env_nvram.c b/common/env_nvram.c index 76e84383d5..2c831d14d7 100644 --- a/common/env_nvram.c +++ b/common/env_nvram.c @@ -46,7 +46,6 @@ #include #include -#include #include #include diff --git a/common/fpga.c b/common/fpga.c index c5975bcf6c..c41c6f89a7 100644 --- a/common/fpga.c +++ b/common/fpga.c @@ -55,7 +55,7 @@ static fpga_desc desc_table[CONFIG_MAX_FPGA_DEVICES]; /* Local static functions */ static const fpga_desc * const fpga_get_desc( int devnum ); static const fpga_desc * const fpga_validate( int devnum, void *buf, - size_t bsize, char *fn ); + size_t bsize, char *fn ); static int fpga_dev_info( int devnum ); @@ -100,7 +100,7 @@ static const fpga_desc * const fpga_get_desc( int devnum ) * generic parameter checking code */ static const fpga_desc * const fpga_validate( int devnum, void *buf, - size_t bsize, char *fn ) + size_t bsize, char *fn ) { const fpga_desc * const desc = fpga_get_desc( devnum ); diff --git a/common/hush.c b/common/hush.c index 19933980e7..dbb952ddba 100644 --- a/common/hush.c +++ b/common/hush.c @@ -94,7 +94,8 @@ #include /* readline */ #include #include /* find_cmd */ -#include /* do_bootd */ +/*cmd_boot.c*/ +extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /* do_bootd */ #endif #ifdef CFG_HUSH_PARSER #ifndef __U_BOOT__ @@ -1048,12 +1049,12 @@ static void get_user_input(struct in_str *i) i->p = the_command; } else { - if (console_buffer[0] != '\n') { - if (strlen(the_command) + strlen(console_buffer) + if (console_buffer[0] != '\n') { + if (strlen(the_command) + strlen(console_buffer) < CFG_CBSIZE) { - n = strlen(the_command); - the_command[n-1] = ' '; - strcpy(&the_command[n],console_buffer); + n = strlen(the_command); + the_command[n-1] = ' '; + strcpy(&the_command[n],console_buffer); } else { the_command[0] = '\n'; @@ -1257,8 +1258,8 @@ static void pseudo_exec(struct child_prog *child) if (p != child->argv[i]) free(p); } child->argv+=i; /* XXX this hack isn't so horrible, since we are about - to exit, and therefore don't need to keep data - structures consistent for free() use. */ + to exit, and therefore don't need to keep data + structures consistent for free() use. */ /* If a variable is assigned in a forest, and nobody listens, * was it ever really set? */ @@ -1648,14 +1649,18 @@ static int run_pipe_real(struct pipe *pi) child->argv[i]); return -1; } - /* Look up command in command table */ + /* Look up command in command table */ + + if ((cmdtp = find_cmd(child->argv[i])) == NULL) { printf ("Unknown command '%s' - try 'help'\n", child->argv[i]); return -1; /* give up after bad command */ } else { int rcode; #if (CONFIG_COMMANDS & CFG_CMD_BOOTD) - /* avoid "bootd" recursion */ + extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); + + /* avoid "bootd" recursion */ if (cmdtp->cmd == do_bootd) { if (flag & CMD_FLAG_BOOTD) { printf ("'bootd' recursion detected\n"); @@ -1665,7 +1670,7 @@ static int run_pipe_real(struct pipe *pi) flag |= CMD_FLAG_BOOTD; } #endif /* CFG_CMD_BOOTD */ - /* found - check max args */ + /* found - check max args */ if ((child->argc - i) > cmdtp->maxargs) { printf ("Usage:\n%s\n", cmdtp->usage); return -1; @@ -1676,15 +1681,20 @@ static int run_pipe_real(struct pipe *pi) rcode = x->function(child); #else /* OK - call function to do the command */ + rcode = (cmdtp->cmd) - (cmdtp, flag,child->argc-i,&child->argv[i]); +(cmdtp, flag,child->argc-i,&child->argv[i]); if ( !cmdtp->repeatable ) flag_repeat = 0; + + #endif child->argv-=i; /* XXX restore hack so free() can work right */ #ifndef __U_BOOT__ + restore_redirects(squirrel); #endif + return rcode; } } @@ -1965,11 +1975,11 @@ static int free_pipe(struct pipe *pi, int indent) #ifndef __U_BOOT__ globfree(&child->glob_result); #else - for (a = child->argc;a >= 0;a--) { - free(child->argv[a]); - } + for (a = child->argc;a >= 0;a--) { + free(child->argv[a]); + } free(child->argv); - child->argc = 0; + child->argc = 0; #endif child->argv=NULL; } else if (child->group) { @@ -2103,17 +2113,17 @@ static int xglob(o_string *dest, int flags, glob_t *pglob) { int gr; - /* short-circuit for null word */ + /* short-circuit for null word */ /* we can code this better when the debug_printf's are gone */ - if (dest->length == 0) { - if (dest->nonnull) { - /* bash man page calls this an "explicit" null */ - gr = globhack(dest->data, flags, pglob); - debug_printf("globhack returned %d\n",gr); - } else { + if (dest->length == 0) { + if (dest->nonnull) { + /* bash man page calls this an "explicit" null */ + gr = globhack(dest->data, flags, pglob); + debug_printf("globhack returned %d\n",gr); + } else { return 0; } - } else if (glob_needed(dest->data)) { + } else if (glob_needed(dest->data)) { gr = glob(dest->data, flags, NULL, pglob); debug_printf("glob returned %d\n",gr); if (gr == GLOB_NOMATCH) { @@ -2462,7 +2472,7 @@ static int done_word(o_string *dest, struct p_context *ctx) } #ifndef __U_BOOT__ glob_target = &child->glob_result; - if (child->argv) flags |= GLOB_APPEND; + if (child->argv) flags |= GLOB_APPEND; #else for (cnt = 1, s = dest->data; s && *s; s++) { if (*s == '\\') s++; @@ -2522,9 +2532,9 @@ static int done_command(struct p_context *ctx) struct child_prog *prog=ctx->child; if (prog && prog->group == NULL - && prog->argv == NULL + && prog->argv == NULL #ifndef __U_BOOT__ - && prog->redirects == NULL) { + && prog->redirects == NULL) { #else ) { #endif @@ -3339,7 +3349,7 @@ int hush_main(int argc, char **argv) debug_printf("\ninteractive=%d\n", interactive); if (interactive) { /* Looks like they want an interactive shell */ -#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET +#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET printf( "\n\n" BB_BANNER " hush - the humble shell v0.01 (testing)\n"); printf( "Enter 'help' for a list of built-in commands.\n\n"); #endif diff --git a/common/kgdb.c b/common/kgdb.c index b563094d54..73fd9a8cd4 100644 --- a/common/kgdb.c +++ b/common/kgdb.c @@ -573,6 +573,20 @@ do_kgdb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } +cmd_tbl_t U_BOOT_CMD(KGDB) = MK_CMD_ENTRY( + "kgdb", CFG_MAXARGS, 1, do_kgdb, + "kgdb - enter gdb remote debug mode\n", + "[arg0 arg1 .. argN]\n" + " - executes a breakpoint so that kgdb mode is\n" + " entered via the exception handler. To return\n" + " to the monitor, the remote gdb debugger must\n" + " execute a \"continue\" or \"quit\" command.\n" + "\n" + " if a program is loaded by the remote gdb, any args\n" + " passed to the kgdb command are given to the loaded\n" + " program if it is executed (see the \"hello_world\"\n" + " example program in the U-Boot examples directory)." +); #else int kgdb_not_configured = 1; diff --git a/common/main.c b/common/main.c index f538870d5c..f7830a1f3d 100644 --- a/common/main.c +++ b/common/main.c @@ -26,17 +26,19 @@ #include #include #include -#include -#include #include -#if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY) -#include /* for do_reset() prototype */ -#endif #ifdef CFG_HUSH_PARSER #include #endif +#if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY) +extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /* for do_reset() prototype */ +#endif + +extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); + + #define MAX_DELAY_STOP_STR 32 static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen); @@ -143,7 +145,7 @@ static __inline__ int abortboot(int bootdelay) if (delaykey[i].len > 0 && presskey_len >= delaykey[i].len && memcmp (presskey + presskey_len - delaykey[i].len, - delaykey[i].str, + delaykey[i].str, delaykey[i].len) == 0) { # if DEBUG_BOOTKEYS printf("got %skey\n", @@ -196,17 +198,17 @@ static __inline__ int abortboot(int bootdelay) #endif #if defined CONFIG_ZERO_BOOTDELAY_CHECK - /* - * Check if key already pressed - * Don't check if bootdelay < 0 - */ + /* + * Check if key already pressed + * Don't check if bootdelay < 0 + */ if (bootdelay >= 0) { if (tstc()) { /* we got a key press */ (void) getc(); /* consume input */ printf ("\b\b\b 0\n"); return 1; /* don't auto boot */ } - } + } #endif while (bootdelay > 0) { @@ -633,7 +635,7 @@ static void process_macros (const char *input, char *output) int state = 0; /* 0 = waiting for '$' */ /* 1 = waiting for '(' */ /* 2 = waiting for ')' */ - /* 3 = waiting for ''' */ + /* 3 = waiting for ''' */ #ifdef DEBUG_PARSER char *output_start = output; @@ -652,7 +654,7 @@ static void process_macros (const char *input, char *output) if (inputcnt-- == 0) break; prev = c; - c = *input++; + c = *input++; } } diff --git a/common/miiphybb.c b/common/miiphybb.c index dfc19922b1..8d18919a34 100644 --- a/common/miiphybb.c +++ b/common/miiphybb.c @@ -228,4 +228,3 @@ int miiphy_write(unsigned char addr, } #endif /* CONFIG_BITBANGMII */ - diff --git a/common/soft_i2c.c b/common/soft_i2c.c index dc26d6f508..9a10b3126c 100644 --- a/common/soft_i2c.c +++ b/common/soft_i2c.c @@ -267,10 +267,10 @@ static uchar read_byte(int ack) void i2c_init (int speed, int slaveaddr) { /* - * WARNING: Do NOT save speed in a static variable: if the - * I2C routines are called before RAM is initialized (to read - * the DIMM SPD, for instance), RAM won't be usable and your - * system will crash. + * WARNING: Do NOT save speed in a static variable: if the + * I2C routines are called before RAM is initialized (to read + * the DIMM SPD, for instance), RAM won't be usable and your + * system will crash. */ send_reset (); } diff --git a/common/soft_spi.c b/common/soft_spi.c index b9a8fa8d5f..00a57de8aa 100644 --- a/common/soft_spi.c +++ b/common/soft_spi.c @@ -40,7 +40,6 @@ #endif - /*=====================================================================*/ /* Public Functions */ /*=====================================================================*/ @@ -132,4 +131,3 @@ int spi_xfer(spi_chipsel_type chipsel, int bitlen, uchar *dout, uchar *din) } #endif /* CONFIG_SOFT_SPI */ - diff --git a/common/spartan2.c b/common/spartan2.c index dcda0c4948..279a426184 100644 --- a/common/spartan2.c +++ b/common/spartan2.c @@ -438,11 +438,11 @@ static int Spartan2_sp_reloc (Xilinx_desc * desc, ulong reloc_offset) static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) { - int ret_val = FPGA_FAIL; /* assume the worst */ + int ret_val = FPGA_FAIL; /* assume the worst */ Xilinx_Spartan2_Slave_Serial_fns *fn = desc->iface_fns; - int i; - char val; - + int i; + char val; + PRINTF ("%s: start with interface functions @ 0x%p\n", __FUNCTION__, fn); @@ -460,8 +460,8 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) "clk:\t0x%p\n" "wr:\t0x%p\n" "done:\t0x%p\n\n", - __FUNCTION__, &fn, fn, fn->pgm, fn->init, - fn->clk, fn->wr, fn->done); + __FUNCTION__, &fn, fn, fn->pgm, fn->init, + fn->clk, fn->wr, fn->done); #ifdef CFG_FPGA_PROG_FEEDBACK printf ("Loading FPGA Device %d...\n", cookie); #endif @@ -476,7 +476,7 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) /* Establish the initial state */ (*fn->pgm) (TRUE, TRUE, cookie); /* Assert the program, commit */ - /* Wait for INIT state (init low) */ + /* Wait for INIT state (init low) */ ts = get_timer (0); /* get current time */ do { CONFIG_FPGA_DELAY (); @@ -485,7 +485,7 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) return FPGA_FAIL; } } while (!(*fn->init) (cookie)); - + /* Get ready for the burn */ CONFIG_FPGA_DELAY (); (*fn->pgm) (FALSE, TRUE, cookie); /* Deassert the program, commit */ @@ -502,29 +502,29 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) /* Load the data */ while (bytecount < bsize) { - - /* Xilinx detects an error if INIT goes low (active) - while DONE is low (inactive) */ - if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) { - puts ("** CRC error during FPGA load.\n"); - return (FPGA_FAIL); - } - val = data [bytecount ++]; - i = 8; - do { - /* Deassert the clock */ - (*fn->clk) (FALSE, TRUE, cookie); - CONFIG_FPGA_DELAY (); - /* Write data */ - (*fn->wr) ((val < 0), TRUE, cookie); - CONFIG_FPGA_DELAY (); - /* Assert the clock */ - (*fn->clk) (TRUE, TRUE, cookie); - CONFIG_FPGA_DELAY (); - val <<= 1; - i --; - } while (i > 0); - + + /* Xilinx detects an error if INIT goes low (active) + while DONE is low (inactive) */ + if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) { + puts ("** CRC error during FPGA load.\n"); + return (FPGA_FAIL); + } + val = data [bytecount ++]; + i = 8; + do { + /* Deassert the clock */ + (*fn->clk) (FALSE, TRUE, cookie); + CONFIG_FPGA_DELAY (); + /* Write data */ + (*fn->wr) ((val < 0), TRUE, cookie); + CONFIG_FPGA_DELAY (); + /* Assert the clock */ + (*fn->clk) (TRUE, TRUE, cookie); + CONFIG_FPGA_DELAY (); + val <<= 1; + i --; + } while (i > 0); + #ifdef CFG_FPGA_PROG_FEEDBACK if (bytecount % (bsize / 40) == 0) putc ('.'); /* let them know we are alive */ @@ -540,7 +540,7 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) /* now check for done signal */ ts = get_timer (0); /* get current time */ ret_val = FPGA_SUCCESS; - (*fn->wr) (TRUE, TRUE, cookie); + (*fn->wr) (TRUE, TRUE, cookie); while (! (*fn->done) (cookie)) { /* XXX - we should have a check in here somewhere to @@ -551,8 +551,8 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) CONFIG_FPGA_DELAY (); (*fn->clk) (TRUE, TRUE, cookie); /* Assert the clock pin */ - putc ('*'); - + putc ('*'); + if (get_timer (ts) > CFG_FPGA_WAIT) { /* check the time */ puts ("** Timeout waiting for DONE to clear.\n"); ret_val = FPGA_FAIL; @@ -579,8 +579,8 @@ static int Spartan2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize) static int Spartan2_ss_dump (Xilinx_desc * desc, void *buf, size_t bsize) { - /* Readback is only available through the Slave Parallel and */ - /* boundary-scan interfaces. */ + /* Readback is only available through the Slave Parallel and */ + /* boundary-scan interfaces. */ printf ("%s: Slave Serial Dumping is unavailable\n", __FUNCTION__); return FPGA_FAIL; diff --git a/common/usb.c b/common/usb.c index a5b29a56b4..9474abee4d 100644 --- a/common/usb.c +++ b/common/usb.c @@ -47,7 +47,6 @@ #endif - #undef USB_DEBUG #ifdef USB_DEBUG diff --git a/common/usb_kbd.c b/common/usb_kbd.c index ad7e6100e2..56c21660fa 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -402,7 +402,6 @@ struct hid_item { #define HID_ITEM_TAG_LONG 15 - static struct usb_hid_descriptor usb_kbd_hid_desc; void usb_kbd_display_hid(struct usb_hid_descriptor *hid) @@ -541,7 +540,6 @@ static int fetch_item(unsigned char *start,unsigned char *end, struct hid_item * #define HID_LOCAL_ITEM_TAG_DELIMITER 10 - static void usb_kbd_show_item(struct hid_item *item) { switch(item->type) { @@ -666,7 +664,6 @@ static void usb_kbd_show_item(struct hid_item *item) } - static int usb_kbd_get_hid_desc(struct usb_device *dev) { unsigned char buffer[256]; @@ -729,6 +726,3 @@ static int usb_kbd_get_hid_desc(struct usb_device *dev) #endif #endif /* CONFIG_USB_KEYBOARD */ - -/* eof */ - diff --git a/common/usb_storage.c b/common/usb_storage.c index b1347219af..a7944b5737 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -32,7 +32,6 @@ */ - #include #include #include @@ -107,16 +106,11 @@ struct us_data { static struct us_data usb_stor[USB_MAX_STOR_DEV]; - #define USB_STOR_TRANSPORT_GOOD 0 #define USB_STOR_TRANSPORT_FAILED -1 #define USB_STOR_TRANSPORT_ERROR -2 - - - - int usb_stor_get_info(struct usb_device *dev, struct us_data *us, block_dev_desc_t *dev_desc); int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,struct us_data *ss); unsigned long usb_stor_read(int device, unsigned long blknr, unsigned long blkcnt, unsigned long *buffer); @@ -529,7 +523,6 @@ do_retry: } - static int usb_inquiry(ccb *srb,struct us_data *ss) { int retry,i; @@ -890,6 +883,3 @@ int usb_stor_get_info(struct usb_device *dev,struct us_data *ss,block_dev_desc_t #endif #endif /* CONFIG_USB_STORAGE */ - - - -- cgit v1.2.1