[U-Boot] Makefile cleanup and u-boot size reduction

Hi,
1)The following patchset will continue the move of conditional compile to Makefile and do some file location move
2) It will merge the current list implementation for common/device & co to linux list.h in order to reduce u-boot size. During test It did show the the patch will reduce u-boot size by 1KB min.
Best Regards, J.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - lib_generic/Makefile | 1 + {common => lib_generic}/gunzip.c | 0 3 files changed, 1 insertions(+), 1 deletions(-) rename {common => lib_generic}/gunzip.c (100%)
diff --git a/common/Makefile b/common/Makefile index 944b1c0..d974823 100644 --- a/common/Makefile +++ b/common/Makefile @@ -36,7 +36,6 @@ COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o COBJS-y += image.o -COBJS-y += gunzip.o COBJS-y += cmd_boot.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-y += cmd_bootm.o diff --git a/lib_generic/Makefile b/lib_generic/Makefile index bf0e31d..a820f97 100644 --- a/lib_generic/Makefile +++ b/lib_generic/Makefile @@ -34,6 +34,7 @@ COBJS-y += crc32.o COBJS-y += ctype.o COBJS-y += display_options.o COBJS-y += div64.o +COBJS-y += gunzip.o COBJS-y += lmb.o COBJS-y += ldiv.o COBJS-$(CONFIG_MD5) += md5.o diff --git a/common/gunzip.c b/lib_generic/gunzip.c similarity index 100% rename from common/gunzip.c rename to lib_generic/gunzip.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - drivers/i2c/Makefile | 1 + {common => drivers/i2c}/soft_i2c.c | 0 3 files changed, 1 insertions(+), 1 deletions(-) rename {common => drivers/i2c}/soft_i2c.c (100%)
diff --git a/common/Makefile b/common/Makefile index d974823..faeac86 100644 --- a/common/Makefile +++ b/common/Makefile @@ -137,7 +137,6 @@ COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o -COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o ifdef CONFIG_CMD_USB COBJS-y += usb.o diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 1f25afb..6079c05 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -29,6 +29,7 @@ COBJS-$(CONFIG_FSL_I2C) += fsl_i2c.o COBJS-$(CONFIG_I2C_MXC) += mxc_i2c.o COBJS-$(CONFIG_DRIVER_OMAP1510_I2C) += omap1510_i2c.o COBJS-$(CONFIG_DRIVER_OMAP24XX_I2C) += omap24xx_i2c.o +COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
COBJS := $(COBJS-y) diff --git a/common/soft_i2c.c b/drivers/i2c/soft_i2c.c similarity index 100% rename from common/soft_i2c.c rename to drivers/i2c/soft_i2c.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - drivers/spi/Makefile | 3 ++- {common => drivers/spi}/soft_spi.c | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {common => drivers/spi}/soft_spi.c (100%)
diff --git a/common/Makefile b/common/Makefile index faeac86..3e4829f 100644 --- a/common/Makefile +++ b/common/Makefile @@ -137,7 +137,6 @@ COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o -COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o ifdef CONFIG_CMD_USB COBJS-y += usb.o COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 4f7b679..15e0f7a 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -25,9 +25,10 @@ include $(TOPDIR)/config.mk
LIB := $(obj)libspi.a
-COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o +COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o +COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/common/soft_spi.c b/drivers/spi/soft_spi.c similarity index 100% rename from common/soft_spi.c rename to drivers/spi/soft_spi.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - drivers/net/Makefile | 1 + {common => drivers/net}/miiphybb.c | 0 3 files changed, 1 insertions(+), 1 deletions(-) rename {common => drivers/net}/miiphybb.c (100%)
diff --git a/common/Makefile b/common/Makefile index 3e4829f..ff2e6c6 100644 --- a/common/Makefile +++ b/common/Makefile @@ -133,7 +133,6 @@ COBJS-$(CONFIG_LCD) += lcd.o COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o COBJS-y += memsize.o -COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/drivers/net/Makefile b/drivers/net/Makefile index bcf31cb..0e86b72 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -41,6 +41,7 @@ COBJS-$(CONFIG_DRIVER_KS8695ETH) += ks8695eth.o COBJS-$(CONFIG_DRIVER_LAN91C96) += lan91c96.o COBJS-$(CONFIG_MACB) += macb.o COBJS-$(CONFIG_MCFFEC) += mcffec.o +COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-$(CONFIG_NATSEMI) += natsemi.o ifeq ($(CONFIG_DRIVER_NE2000),y) COBJS-y += ne2000.o diff --git a/common/miiphybb.c b/drivers/net/miiphybb.c similarity index 100% rename from common/miiphybb.c rename to drivers/net/miiphybb.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - lib_generic/Makefile | 1 + {common => lib_generic}/crc16.c | 0 3 files changed, 1 insertions(+), 1 deletions(-) rename {common => lib_generic}/crc16.c (100%)
diff --git a/common/Makefile b/common/Makefile index ff2e6c6..0c8ef5b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -141,7 +141,6 @@ COBJS-y += usb.o COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o endif COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o -COBJS-y += crc16.o COBJS-y += xyzModem.o COBJS-y += cmd_mac.o COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o diff --git a/lib_generic/Makefile b/lib_generic/Makefile index a820f97..7df5a2c 100644 --- a/lib_generic/Makefile +++ b/lib_generic/Makefile @@ -30,6 +30,7 @@ COBJS-y += bzlib_crctable.o COBJS-y += bzlib_decompress.o COBJS-y += bzlib_randtable.o COBJS-y += bzlib_huffman.o +COBJS-y += crc16.o COBJS-y += crc32.o COBJS-y += ctype.o COBJS-y += display_options.o diff --git a/common/crc16.c b/lib_generic/crc16.c similarity index 100% rename from common/crc16.c rename to lib_generic/crc16.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 3 +- common/{cmd_autoscript.c => autoscript.c} | 44 -------- common/cmd_autoscript.c | 158 ----------------------------- 3 files changed, 2 insertions(+), 203 deletions(-) copy common/{cmd_autoscript.c => autoscript.c} (79%)
diff --git a/common/Makefile b/common/Makefile index 0c8ef5b..92d7a9e 100644 --- a/common/Makefile +++ b/common/Makefile @@ -31,7 +31,8 @@ COBJS-y += main.o COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o -COBJS-y += cmd_autoscript.o +COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += autoscript.o +COBJS-$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o diff --git a/common/cmd_autoscript.c b/common/autoscript.c similarity index 79% copy from common/cmd_autoscript.c copy to common/autoscript.c index 13af93e..e1d4103 100644 --- a/common/cmd_autoscript.c +++ b/common/autoscript.c @@ -47,8 +47,6 @@ #include <hush.h> #endif
-#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT) - int autoscript (ulong addr, const char *fit_uname) { @@ -199,45 +197,3 @@ autoscript (ulong addr, const char *fit_uname) free (cmd); return rcode; } - -#endif - -/**************************************************/ -#if defined(CONFIG_CMD_AUTOSCRIPT) -int -do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - ulong addr; - int rcode; - const char *fit_uname = NULL; - - /* Find script image */ - if (argc < 2) { - addr = CFG_LOAD_ADDR; - debug ("* autoscr: default load address = 0x%08lx\n", addr); -#if defined(CONFIG_FIT) - } else if (fit_parse_subimage (argv[1], load_addr, &addr, &fit_uname)) { - debug ("* autoscr: subimage '%s' from FIT image at 0x%08lx\n", - fit_uname, addr); -#endif - } else { - addr = simple_strtoul(argv[1], NULL, 16); - debug ("* autoscr: cmdline image address = 0x%08lx\n", addr); - } - - printf ("## Executing script at %08lx\n", addr); - rcode = autoscript (addr, fit_uname); - return rcode; -} - -U_BOOT_CMD( - 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" -#if defined(CONFIG_FIT) - "For FIT format uImage addr must include subimage\n" - "unit name in the form of addr:<subimg_uname>\n" -#endif -); -#endif diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index 13af93e..2b6a525 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -47,163 +47,6 @@ #include <hush.h> #endif
-#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT) - -int -autoscript (ulong addr, const char *fit_uname) -{ - ulong len; - image_header_t *hdr; - ulong *data; - char *cmd; - int rcode = 0; - int verify; -#if defined(CONFIG_FIT) - const void* fit_hdr; - int noffset; - const void *fit_data; - size_t fit_len; -#endif - - verify = getenv_yesno ("verify"); - - switch (genimg_get_format ((void *)addr)) { - case IMAGE_FORMAT_LEGACY: - hdr = (image_header_t *)addr; - - if (!image_check_magic (hdr)) { - puts ("Bad magic number\n"); - return 1; - } - - if (!image_check_hcrc (hdr)) { - puts ("Bad header crc\n"); - return 1; - } - - if (verify) { - if (!image_check_dcrc (hdr)) { - puts ("Bad data crc\n"); - return 1; - } - } - - if (!image_check_type (hdr, IH_TYPE_SCRIPT)) { - puts ("Bad image type\n"); - return 1; - } - - /* get length of script */ - data = (ulong *)image_get_data (hdr); - - if ((len = uimage_to_cpu (*data)) == 0) { - puts ("Empty Script\n"); - return 1; - } - - /* - * scripts are just multi-image files with one component, seek - * past the zero-terminated sequence of image lengths to get - * to the actual image data - */ - while (*data++); - break; -#if defined(CONFIG_FIT) - case IMAGE_FORMAT_FIT: - if (fit_uname == NULL) { - puts ("No FIT subimage unit name\n"); - return 1; - } - - fit_hdr = (const void *)addr; - if (!fit_check_format (fit_hdr)) { - puts ("Bad FIT image format\n"); - return 1; - } - - /* get script component image node offset */ - noffset = fit_image_get_node (fit_hdr, fit_uname); - if (noffset < 0) { - printf ("Can't find '%s' FIT subimage\n", fit_uname); - return 1; - } - - if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) { - puts ("Not a image image\n"); - return 1; - } - - /* verify integrity */ - if (verify) { - if (!fit_image_check_hashes (fit_hdr, noffset)) { - puts ("Bad Data Hash\n"); - return 1; - } - } - - /* get script subimage data address and length */ - if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) { - puts ("Could not find script subimage data\n"); - return 1; - } - - data = (ulong *)fit_data; - len = (ulong)fit_len; - break; -#endif - default: - puts ("Wrong image format for autoscript\n"); - return 1; - } - - debug ("** Script length: %ld\n", len); - - if ((cmd = malloc (len + 1)) == NULL) { - return 1; - } - - /* make sure cmd is null terminated */ - memmove (cmd, (char *)data, len); - *(cmd + len) = 0; - -#ifdef CFG_HUSH_PARSER /*?? */ - rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON); -#else - { - char *line = cmd; - char *next = cmd; - - /* - * break into individual lines, - * and execute each line; - * terminate on error. - */ - while (*next) { - if (*next == '\n') { - *next = '\0'; - /* run only non-empty commands */ - if ((next - line) > 1) { - debug ("** exec: "%s"\n", - line); - if (run_command (line, 0) < 0) { - rcode = 1; - break; - } - } - line = next + 1; - } - ++next; - } - } -#endif - free (cmd); - return rcode; -} - -#endif - -/**************************************************/ -#if defined(CONFIG_CMD_AUTOSCRIPT) int do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { @@ -240,4 +83,3 @@ U_BOOT_CMD( "unit name in the form of addr:<subimg_uname>\n" #endif ); -#endif

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 2 +- common/miiphyutil.c | 2 -- 2 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 92d7a9e..7db70f5 100644 --- a/common/Makefile +++ b/common/Makefile @@ -85,6 +85,7 @@ COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o COBJS-y += cmd_load.o COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o COBJS-y += cmd_mem.o +COBJS-$(CONFIG_MII)$(CONFIG_CMD_MII) += miiphyutil.o COBJS-$(CONFIG_CMD_MII) += cmd_mii.o COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o @@ -134,7 +135,6 @@ COBJS-$(CONFIG_LCD) += lcd.o COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o COBJS-y += memsize.o -COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o ifdef CONFIG_CMD_USB diff --git a/common/miiphyutil.c b/common/miiphyutil.c index eac8275..5ef4a33 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -29,7 +29,6 @@ #include <common.h> #include <miiphy.h>
-#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) #include <asm/types.h> #include <linux/list.h> #include <malloc.h> @@ -487,4 +486,3 @@ int miiphy_link (char *devname, unsigned char addr) } } #endif -#endif /* CONFIG_MII */

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 71 +++++++++++++++++++++++++++++------------------------- 1 files changed, 38 insertions(+), 33 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 7db70f5..99781fe 100644 --- a/common/Makefile +++ b/common/Makefile @@ -27,16 +27,41 @@ LIB = $(obj)libcommon.a
AOBJS =
+# core COBJS-y += main.o -COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o +COBJS-y += console.o +COBJS-y += command.o +COBJS-y += devices.o +COBJS-y += dlmalloc.o +COBJS-y += exports.o +COBJS-y += hush.o +COBJS-y += image.o +COBJS-y += lists.o +COBJS-y += memsize.o +COBJS-y += s_record.o +COBJS-y += serial.o +COBJS-y += xyzModem.o + +# environment +COBJS-y += environment.o +COBJS-y += env_common.o +COBJS-y += env_dataflash.o +COBJS-y += env_eeprom.o +COBJS-y += env_flash.o +COBJS-y += env_nand.o +COBJS-y += env_nvram.o +COBJS-y += env_onenand.o +COBJS-y += env_sf.o +COBJS-y += env_nowhere.o + +# command COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += autoscript.o COBJS-$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o -COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o +COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o -COBJS-y += image.o COBJS-y += cmd_boot.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-y += cmd_bootm.o @@ -84,11 +109,14 @@ COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o COBJS-y += cmd_load.o COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o +COBJS-y += cmd_mac.o COBJS-y += cmd_mem.o +COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o COBJS-$(CONFIG_MII)$(CONFIG_CMD_MII) += miiphyutil.o COBJS-$(CONFIG_CMD_MII) += cmd_mii.o COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o +COBJS-$(CONFIG_MP) += cmd_mp.o COBJS-y += cmd_nand.o COBJS-$(CONFIG_CMD_NET) += cmd_net.o COBJS-y += cmd_nvedit.o @@ -102,53 +130,30 @@ COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o +COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o COBJS-$(CONFIG_CMD_SETEXPR) += cmd_setexpr.o COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o -COBJS-$(CONFIG_CMD_USB) += cmd_usb.o +ifdef CONFIG_CMD_USB +COBJS-y += cmd_usb.o +COBJS-y += usb.o +COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o +endif COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o COBJS-y += cmd_vfd.o -COBJS-y += command.o -COBJS-y += console.o -COBJS-y += devices.o -COBJS-y += dlmalloc.o COBJS-$(CONFIG_CMD_DOC) += docecc.o -COBJS-y += environment.o -COBJS-y += env_common.o -COBJS-y += env_nand.o -COBJS-y += env_dataflash.o -COBJS-y += env_flash.o -COBJS-y += env_eeprom.o -COBJS-y += env_onenand.o -COBJS-y += env_sf.o -COBJS-y += env_nvram.o -COBJS-y += env_nowhere.o -COBJS-y += exports.o COBJS-y += flash.o -COBJS-y += hush.o COBJS-y += kgdb.o COBJS-$(CONFIG_LCD) += lcd.o -COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o -COBJS-y += memsize.o -COBJS-y += s_record.o -COBJS-y += serial.o -ifdef CONFIG_CMD_USB -COBJS-y += usb.o -COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o -endif COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o -COBJS-y += xyzModem.o -COBJS-y += cmd_mac.o -COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o -COBJS-$(CONFIG_MP) += cmd_mp.o -COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
+COBJS-y += $(COBJS-yy) COBJS := $(COBJS-y) SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/cmd_terminal.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c index 8871607..57943c1 100644 --- a/common/cmd_terminal.c +++ b/common/cmd_terminal.c @@ -28,8 +28,6 @@ #include <command.h> #include <devices.h>
-#if defined(CONFIG_CMD_TERMINAL) - int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { int i, l; @@ -98,5 +96,3 @@ U_BOOT_CMD( "terminal - start terminal emulator\n", "" ); - -#endif /* CONFIG_CMD_TERMINAL */

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- include/linux/list.h | 506 +++++++++++++++++++++++++++++++++++++++++++----- include/linux/poison.h | 13 ++ 2 files changed, 474 insertions(+), 45 deletions(-) create mode 100644 include/linux/poison.h
diff --git a/include/linux/list.h b/include/linux/list.h index e6492f7..aeeeb21 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -1,6 +1,9 @@ #ifndef _LINUX_LIST_H #define _LINUX_LIST_H
+#include <linux/stddef.h> +#include <linux/poison.h> + #ifndef ARCH_HAS_PREFETCH #define ARCH_HAS_PREFETCH static inline void prefetch(const void *x) {;} @@ -25,9 +28,11 @@ struct list_head { #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name)
-#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) +static inline void INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list; + list->prev = list; +}
/* * Insert a new entry between two known consecutive entries. @@ -87,13 +92,37 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) /** * list_del - deletes entry from list. * @entry: the element to delete from the list. - * Note: list_empty on entry does not return true after this, the entry is in an undefined state. + * Note: list_empty() on entry does not return true after this, the entry is + * in an undefined state. */ static inline void list_del(struct list_head *entry) { __list_del(entry->prev, entry->next); - entry->next = (void *) 0; - entry->prev = (void *) 0; + entry->next = LIST_POISON1; + entry->prev = LIST_POISON2; +} + +/** + * list_replace - replace old entry by new one + * @old : the element to be replaced + * @new : the new element to insert + * + * If @old was empty, it will be overwritten. + */ +static inline void list_replace(struct list_head *old, + struct list_head *new) +{ + new->next = old->next; + new->next->prev = new; + new->prev = old->prev; + new->prev->next = new; +} + +static inline void list_replace_init(struct list_head *old, + struct list_head *new) +{ + list_replace(old, new); + INIT_LIST_HEAD(old); }
/** @@ -130,37 +159,129 @@ static inline void list_move_tail(struct list_head *list, }
/** + * list_is_last - tests whether @list is the last entry in list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_last(const struct list_head *list, + const struct list_head *head) +{ + return list->next == head; +} + +/** * list_empty - tests whether a list is empty * @head: the list to test. */ -static inline int list_empty(struct list_head *head) +static inline int list_empty(const struct list_head *head) { return head->next == head; }
-static inline void __list_splice(struct list_head *list, - struct list_head *head) +/** + * list_empty_careful - tests whether a list is empty and not being modified + * @head: the list to test + * + * Description: + * tests whether a list is empty _and_ checks that no other CPU might be + * in the process of modifying either member (next or prev) + * + * NOTE: using list_empty_careful() without synchronization + * can only be safe if the only activity that can happen + * to the list entry is list_del_init(). Eg. it cannot be used + * if another CPU could re-list_add() it. + */ +static inline int list_empty_careful(const struct list_head *head) +{ + struct list_head *next = head->next; + return (next == head) && (next == head->prev); +} + +/** + * list_is_singular - tests whether a list has just one entry. + * @head: the list to test. + */ +static inline int list_is_singular(const struct list_head *head) +{ + return !list_empty(head) && (head->next == head->prev); +} + +static inline void __list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + struct list_head *new_first = entry->next; + list->next = head->next; + list->next->prev = list; + list->prev = entry; + entry->next = list; + head->next = new_first; + new_first->prev = head; +} + +/** + * list_cut_position - cut a list into two + * @list: a new list to add all removed entries + * @head: a list with entries + * @entry: an entry within head, could be the head itself + * and if so we won't cut the list + * + * This helper moves the initial part of @head, up to and + * including @entry, from @head to @list. You should + * pass on @entry an element you know is on @head. @list + * should be an empty list or a list you do not care about + * losing its data. + * + */ +static inline void list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + if (list_empty(head)) + return; + if (list_is_singular(head) && + (head->next != entry && head != entry)) + return; + if (entry == head) + INIT_LIST_HEAD(list); + else + __list_cut_position(list, head, entry); +} + +static inline void __list_splice(const struct list_head *list, + struct list_head *prev, + struct list_head *next) { struct list_head *first = list->next; struct list_head *last = list->prev; - struct list_head *at = head->next;
- first->prev = head; - head->next = first; + first->prev = prev; + prev->next = first;
- last->next = at; - at->prev = last; + last->next = next; + next->prev = last; }
/** - * list_splice - join two lists + * list_splice - join two lists, this is designed for stacks * @list: the new list to add. * @head: the place to add it in the first list. */ -static inline void list_splice(struct list_head *list, struct list_head *head) +static inline void list_splice(const struct list_head *list, + struct list_head *head) { if (!list_empty(list)) - __list_splice(list, head); + __list_splice(list, head, head->next); +} + +/** + * list_splice_tail - join two lists, each list being a queue + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static inline void list_splice_tail(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) + __list_splice(list, head->prev, head); }
/** @@ -174,7 +295,24 @@ static inline void list_splice_init(struct list_head *list, struct list_head *head) { if (!list_empty(list)) { - __list_splice(list, head); + __list_splice(list, head, head->next); + INIT_LIST_HEAD(list); + } +} + +/** + * list_splice_tail_init - join two lists and reinitialise the emptied list + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * Each of the lists is a queue. + * The list at @list is reinitialised + */ +static inline void list_splice_tail_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + __list_splice(list, head->prev, head); INIT_LIST_HEAD(list); } } @@ -186,28 +324,53 @@ static inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + container_of(ptr, type, member) + +/** + * list_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_struct within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member)
/** * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. + * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list. */ #define list_for_each(pos, head) \ - for (pos = (head)->next, prefetch(pos->next); pos != (head); \ - pos = pos->next, prefetch(pos->next)) + for (pos = (head)->next; prefetch(pos->next), pos != (head); \ + pos = pos->next) + +/** + * __list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop cursor. + * @head: the head for your list. + * + * This variant differs from list_for_each() in that it's the + * simplest possible list iteration code, no prefetching is done. + * Use this for code that knows the list to be very short (empty + * or 1 entry) most of the time. + */ +#define __list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + /** * list_for_each_prev - iterate over a list backwards - * @pos: the &struct list_head to use as a loop counter. + * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list. */ #define list_for_each_prev(pos, head) \ - for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \ - pos = pos->prev, prefetch(pos->prev)) + for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ + pos = pos->prev)
/** - * list_for_each_safe - iterate over a list safe against removal of list entry - * @pos: the &struct list_head to use as a loop counter. + * list_for_each_safe - iterate over a list safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. * @n: another &struct list_head to use as temporary storage * @head: the head for your list. */ @@ -216,43 +379,296 @@ static inline void list_splice_init(struct list_head *list, pos = n, n = pos->next)
/** + * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_prev_safe(pos, n, head) \ + for (pos = (head)->prev, n = pos->prev; \ + prefetch(pos->prev), pos != (head); \ + pos = n, n = pos->prev) + +/** * list_for_each_entry - iterate over list of given type - * @pos: the type * to use as a loop counter. + * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_struct within the struct. */ #define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - prefetch(pos->member.next); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next)) + for (pos = list_entry((head)->next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_reverse - iterate backwards over list of given type. + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member); \ + prefetch(pos->member.prev), &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +/** + * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() + * @pos: the type * to use as a start point + * @head: the head of the list + * @member: the name of the list_struct within the struct. + * + * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). + */ +#define list_prepare_entry(pos, head, member) \ + ((pos) ? : list_entry(head, typeof(*pos), member)) + +/** + * list_for_each_entry_continue - continue iteration over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Continue to iterate over list of given type, continuing after + * the current position. + */ +#define list_for_each_entry_continue(pos, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_continue_reverse - iterate backwards from the given point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Start to iterate over list of given type backwards, continuing after + * the current position. + */ +#define list_for_each_entry_continue_reverse(pos, head, member) \ + for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ + prefetch(pos->member.prev), &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +/** + * list_for_each_entry_from - iterate over list of given type from the current point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type, continuing from current position. + */ +#define list_for_each_entry_from(pos, head, member) \ + for (; prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member))
/** * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry - * @pos: the type * to use as a loop counter. + * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_struct within the struct. */ #define list_for_each_entry_safe(pos, n, head, member) \ for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member))
/** - * list_for_each_entry_continue - iterate over list of given type - * continuing after existing point - * @pos: the type * to use as a loop counter. + * list_for_each_entry_safe_continue + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type, continuing after current point, + * safe against removal of list entry. + */ +#define list_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_from + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type from current point, safe against + * removal of list entry. + */ +#define list_for_each_entry_safe_from(pos, n, head, member) \ + for (n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_reverse + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate backwards over list of given type, safe against removal + * of list entry. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + +#define HLIST_HEAD_INIT { .first = NULL } +#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } +#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) +static inline void INIT_HLIST_NODE(struct hlist_node *h) +{ + h->next = NULL; + h->pprev = NULL; +} + +static inline int hlist_unhashed(const struct hlist_node *h) +{ + return !h->pprev; +} + +static inline int hlist_empty(const struct hlist_head *h) +{ + return !h->first; +} + +static inline void __hlist_del(struct hlist_node *n) +{ + struct hlist_node *next = n->next; + struct hlist_node **pprev = n->pprev; + *pprev = next; + if (next) + next->pprev = pprev; +} + +static inline void hlist_del(struct hlist_node *n) +{ + __hlist_del(n); + n->next = LIST_POISON1; + n->pprev = LIST_POISON2; +} + +static inline void hlist_del_init(struct hlist_node *n) +{ + if (!hlist_unhashed(n)) { + __hlist_del(n); + INIT_HLIST_NODE(n); + } +} + +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + n->next = first; + if (first) + first->pprev = &n->next; + h->first = n; + n->pprev = &h->first; +} + +/* next must be != NULL */ +static inline void hlist_add_before(struct hlist_node *n, + struct hlist_node *next) +{ + n->pprev = next->pprev; + n->next = next; + next->pprev = &n->next; + *(n->pprev) = n; +} + +static inline void hlist_add_after(struct hlist_node *n, + struct hlist_node *next) +{ + next->next = n->next; + n->next = next; + next->pprev = &n->next; + + if(next->next) + next->next->pprev = &next->next; +} + +#define hlist_entry(ptr, type, member) container_of(ptr,type,member) + +#define hlist_for_each(pos, head) \ + for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \ + pos = pos->next) + +#define hlist_for_each_safe(pos, n, head) \ + for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ + pos = n) + +/** + * hlist_for_each_entry - iterate over list of given type + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(tpos, pos, head, member) \ + for (pos = (head)->first; \ + pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_continue - iterate over a hlist continuing after current point + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_continue(tpos, pos, member) \ + for (pos = (pos)->next; \ + pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_from - iterate over a hlist continuing from current point + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_from(tpos, pos, member) \ + for (; pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @n: another &struct hlist_node to use as temporary storage + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. */ -#define list_for_each_entry_continue(pos, head, member) \ - for (pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next)) +#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ + for (pos = (head)->first; \ + pos && ({ n = pos->next; 1; }) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = n)
#endif diff --git a/include/linux/poison.h b/include/linux/poison.h new file mode 100644 index 0000000..ba7ff84 --- /dev/null +++ b/include/linux/poison.h @@ -0,0 +1,13 @@ +#ifndef _LINUX_POISON_H +#define _LINUX_POISON_H + +/********** include/linux/list.h **********/ +/* + * These are non-NULL pointers that will result in page faults + * under normal circumstances, used to verify that nobody uses + * non-initialized list entries. + */ +#define LIST_POISON1 ((void *) 0x00100100) +#define LIST_POISON2 ((void *) 0x00200200) + +#endif

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - common/cmd_console.c | 9 +- common/cmd_terminal.c | 10 +- common/console.c | 62 ++--- common/devices.c | 79 +++--- common/lists.c | 734 ------------------------------------------------- common/usb_kbd.c | 14 +- include/devices.h | 8 +- include/lists.h | 77 ----- 9 files changed, 87 insertions(+), 907 deletions(-) delete mode 100644 common/lists.c delete mode 100644 include/lists.h
diff --git a/common/Makefile b/common/Makefile index 99781fe..102259d 100644 --- a/common/Makefile +++ b/common/Makefile @@ -37,7 +37,6 @@ COBJS-y += dlmalloc.o COBJS-y += exports.o COBJS-y += hush.o COBJS-y += image.o -COBJS-y += lists.o COBJS-y += memsize.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/common/cmd_console.c b/common/cmd_console.c index 50ddb01..e2bc2a3 100644 --- a/common/cmd_console.c +++ b/common/cmd_console.c @@ -31,14 +31,17 @@ extern void _do_coninfo (void); int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; + int l; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev;
/* Scan for valid output and input devices */
puts ("List of available devices:\n");
- for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list);
printf ("%-8s %08x %c%c%c ", dev->name, diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c index 57943c1..67a2546 100644 --- a/common/cmd_terminal.c +++ b/common/cmd_terminal.c @@ -27,10 +27,10 @@ #include <common.h> #include <command.h> #include <devices.h> +#include <serial.h>
int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; int last_tilde = 0; device_t *dev = NULL;
@@ -38,13 +38,7 @@ int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) return -1;
/* Scan for selected output/input device */ - for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *tmp = ListGetPtrToItem (devlist, i); - if (!strcmp(tmp->name, argv[1])) { - dev = tmp; - break; - } - } + dev = device_get_by_name(argv[1]); if (!dev) return -1;
diff --git a/common/console.c b/common/console.c index 1b095b1..cfcaeb8 100644 --- a/common/console.c +++ b/common/console.c @@ -325,9 +325,22 @@ inline void dbg(const char *fmt, ...)
/** U-Boot INIT FUNCTIONS *************************************************/
+device_t *search_device (int flags, char *name) +{ + device_t *dev; + + dev = device_get_by_name(name); + + if(dev && (dev->flags & flags)) + return dev; + + return NULL; +} + int console_assign (int file, char *devname) { - int flag, i; + int flag; + device_t *dev;
/* Check for valid file */ switch (file) { @@ -344,16 +357,10 @@ int console_assign (int file, char *devname)
/* Check for valid device name */
- for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); - - if (strcmp (devname, dev->name) == 0) { - if (dev->flags & flag) - return console_setfile (file, dev); + dev = search_device(flag, devname);
- return -1; - } - } + if(dev) + return console_setfile (file, dev);
return -1; } @@ -371,27 +378,6 @@ int console_init_f (void) return (0); }
-#if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE) -/* search a device */ -device_t *search_device (int flags, char *name) -{ - int i, items; - device_t *dev = NULL; - - items = ListNumItems (devlist); - if (name == NULL) - return dev; - - for (i = 1; i <= items; i++) { - dev = ListGetPtrToItem (devlist, i); - if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) { - break; - } - } - return dev; -} -#endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */ - #ifdef CFG_CONSOLE_IS_IN_ENV /* Called after the relocation - use desired console functions */ int console_init_r (void) @@ -488,7 +474,10 @@ int console_init_r (void) int console_init_r (void) { device_t *inputdev = NULL, *outputdev = NULL; - int i, items = ListNumItems (devlist); + int i; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev;
#ifdef CONFIG_SPLASH_SCREEN /* suppress all output if splash screen is enabled and we have @@ -498,11 +487,8 @@ int console_init_r (void) #endif
/* Scan devices looking for input and output devices */ - for (i = 1; - (i <= items) && ((inputdev == NULL) || (outputdev == NULL)); - i++ - ) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list);
if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; @@ -510,6 +496,8 @@ int console_init_r (void) if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } + if(inputdev && outputdev) + break; }
/* Initializes output console first */ diff --git a/common/devices.c b/common/devices.c index 9cc963a..2977436 100644 --- a/common/devices.c +++ b/common/devices.c @@ -36,7 +36,7 @@
DECLARE_GLOBAL_DATA_PTR;
-list_t devlist = 0; +static device_t devs; device_t *stdio_devices[] = { NULL, NULL, NULL }; char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
@@ -48,18 +48,18 @@ char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; #ifdef CFG_DEVICE_NULLDEV void nulldev_putc(const char c) { - /* nulldev is empty! */ + /* nulldev is empty! */ }
void nulldev_puts(const char *s) { - /* nulldev is empty! */ + /* nulldev is empty! */ }
int nulldev_input(void) { - /* nulldev is empty! */ - return 0; + /* nulldev is empty! */ + return 0; } #endif
@@ -108,10 +108,32 @@ static void drv_system_init (void) * DEVICES ************************************************************************** */ +struct list_head* device_get_list(void) +{ + return &(devs.list); +} + +device_t* device_get_by_name(char* name) +{ + struct list_head *pos; + device_t *dev; + + if(!name) + return NULL; + + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); + if(strcmp(dev->name, name) == 0) + return dev; + } + + return NULL; +} +
int device_register (device_t * dev) { - ListInsertItem (devlist, dev, LIST_END); + list_add(&(dev->list), &(devs.list)); return 0; }
@@ -121,20 +143,15 @@ int device_register (device_t * dev) #ifdef CFG_DEVICE_DEREGISTER int device_deregister(char *devname) { - int i,l,dev_index; - device_t *dev = NULL; + int l; + struct list_head *pos; + device_t *dev; char temp_names[3][8];
- dev_index = -1; - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); - if(strcmp(dev->name,devname)==0) { - dev_index=i; - break; - } - } - if(dev_index<0) /* device not found */ - return 0; + dev = device_get_by_name(devname); + + if(!dev) /* device not found */ + return -1; /* get stdio devices (ListRemoveItem changes the dev list) */ for (l=0 ; l< MAX_FILES; l++) { if (stdio_devices[l] == dev) { @@ -145,14 +162,15 @@ int device_deregister(char *devname) stdio_devices[l]->name, sizeof(stdio_devices[l]->name)); } - ListRemoveItem(devlist,NULL,dev_index); + + list_del(&(dev->list)); + /* reassign Device list */ - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); for (l=0 ; l< MAX_FILES; l++) { - if(strcmp(dev->name,temp_names[l])==0) { + if(strcmp(dev->name, temp_names[l]) == 0) stdio_devices[l] = dev; - } } } return 0; @@ -161,7 +179,7 @@ int device_deregister(char *devname)
int devices_init (void) { -#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ +#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ ulong relocation_offset = gd->reloc_off; int i;
@@ -173,12 +191,8 @@ int devices_init (void) #endif
/* Initialize the list */ - devlist = ListCreate (sizeof (device_t)); + INIT_LIST_HEAD(&(devs.list));
- if (devlist == NULL) { - eputs ("Cannot initialize the list of devices!\n"); - return -1; - } #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); #endif @@ -207,10 +221,3 @@ int devices_init (void)
return (0); } - -int devices_done (void) -{ - ListDispose (devlist); - - return 0; -} diff --git a/common/lists.c b/common/lists.c deleted file mode 100644 index 0dc090a..0000000 --- a/common/lists.c +++ /dev/null @@ -1,734 +0,0 @@ -#include <common.h> -#include <malloc.h> -#include <lists.h> - -#define MAX(a,b) (((a)>(b)) ? (a) : (b)) -#define MIN(a,b) (((a)<(b)) ? (a) : (b)) -#define CAT4CHARS(a,b,c,d) ((a<<24) | (b<<16) | (c<<8) | d) - -/* increase list size by 10% every time it is full */ -#define kDefaultAllocationPercentIncrease 10 - -/* always increase list size by 4 items when it is full */ -#define kDefaultAllocationminNumItemsIncrease 4 - -/* - * how many items to expand the list by when it becomes full - * = current listSize (in items) + (hiword percent of list size) + loword - */ -#define NUMITEMSPERALLOC(list) MAX(((*list)->listSize * \ - ((*list)->percentIncrease + 100)) / 100, \ - (*list)->minNumItemsIncrease ) - -#define ITEMPTR(list,item) &(((char *)&(*list)->itemList)[(*(list))->itemSize * (item)]) - -#define LIST_SIGNATURE CAT4CHARS('L', 'I', 'S', 'T'); - -#define calloc(size,num) malloc(size*num) - -/********************************************************************/ - -Handle NewHandle (unsigned int numBytes) -{ - void *memPtr; - HandleRecord *hanPtr; - - memPtr = calloc (numBytes, 1); - hanPtr = (HandleRecord *) calloc (sizeof (HandleRecord), 1); - if (hanPtr && (memPtr || numBytes == 0)) { - hanPtr->ptr = memPtr; - hanPtr->size = numBytes; - return (Handle) hanPtr; - } else { - free (memPtr); - free (hanPtr); - return NULL; - } -} -/********************************************************************/ - -void DisposeHandle (Handle handle) -{ - if (handle) { - free (*handle); - free ((void *) handle); - } -} -/********************************************************************/ - -unsigned int GetHandleSize (Handle handle) -{ - return ((HandleRecord *) handle)->size; -} -/********************************************************************/ - -int SetHandleSize (Handle handle, unsigned int newSize) -{ - HandleRecord *hanRecPtr = (HandleRecord *) handle; - void *newPtr, *oldPtr; - unsigned int oldSize; - - - oldPtr = hanRecPtr->ptr; - oldSize = hanRecPtr->size; - - if (oldSize == newSize) - return 1; - - if (oldPtr == NULL) { - newPtr = malloc (newSize); - } else { - newPtr = realloc (oldPtr, newSize); - } - if (newPtr || (newSize == 0)) { - hanRecPtr->ptr = newPtr; - hanRecPtr->size = newSize; - if (newSize > oldSize) - memset ((char *) newPtr + oldSize, 0, newSize - oldSize); - return 1; - } else - return 0; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* Used to compare list elements by their raw data contents */ -static int ListMemBlockCmp (void *a, void *b, int size) -{ - return memcmp (a, b, size); -} - -/***************************************************************************/ - -/* - * Binary search numElements of size elementSize in array for a match - * to the. item. Return the index of the element that matches - * (0 - numElements - 1). If no match is found return the -i-1 where - * i is the index (0 - numElements) where the item should be placed. - * (*theCmp)(a,b) should return <0 if a<b, 0 if a==b, >0 if a>b. - * - * This function is like the C-Library function bsearch() except that - * this function returns the index where the item should be placed if - * it is not found. - */ -int BinSearch ( void *array, int numElements, int elementSize, - void *itemPtr, CompareFunction compareFunction) -{ - int low, high, mid, cmp; - void *arrayItemPtr; - - for (low = 0, high = numElements - 1, mid = 0, cmp = -1; low <= high;) { - mid = (low + high) >> 1; - - arrayItemPtr = (void *) (((char *) array) + (mid * elementSize)); - cmp = compareFunction - ? compareFunction (itemPtr, arrayItemPtr) - : ListMemBlockCmp (itemPtr, arrayItemPtr, elementSize); - if (cmp == 0) { - return mid; - } else if (cmp < 0) { - high = mid - 1; - } else { - low = mid + 1; - } - } - if (cmp > 0) - mid++; - - return -mid - 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************************************************************/ - -/* - * If numNewItems == 0 then expand the list by the number of items - * indicated by its allocation policy. - * If numNewItems > 0 then expand the list by exactly the number of - * items indicated. - * If numNewItems < 0 then expand the list by the absolute value of - * numNewItems plus the number of items indicated by its allocation - * policy. - * Returns 1 for success, 0 if out of memory -*/ -static int ExpandListSpace (list_t list, int numNewItems) -{ - if (numNewItems == 0) { - numNewItems = NUMITEMSPERALLOC (list); - } else if (numNewItems < 0) { - numNewItems = (-numNewItems) + NUMITEMSPERALLOC (list); - } - - if (SetHandleSize ((Handle) list, - sizeof (ListStruct) + - ((*list)->listSize + - numNewItems) * (*list)->itemSize)) { - (*list)->listSize += numNewItems; - return 1; - } else { - return 0; - } -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* - * This function reallocate the list, minus any currently unused - * portion of its allotted memory. - */ -void ListCompact (list_t list) -{ - - if (!SetHandleSize ((Handle) list, - sizeof (ListStruct) + - (*list)->numItems * (*list)->itemSize)) { - return; - } - - (*list)->listSize = (*list)->numItems; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -list_t ListCreate (int elementSize) -{ - list_t list; - - list = (list_t) (NewHandle (sizeof (ListStruct))); /* create empty list */ - if (list) { - (*list)->signature = LIST_SIGNATURE; - (*list)->numItems = 0; - (*list)->listSize = 0; - (*list)->itemSize = elementSize; - (*list)->percentIncrease = kDefaultAllocationPercentIncrease; - (*list)->minNumItemsIncrease = - kDefaultAllocationminNumItemsIncrease; - } - - return list; -} - -/*******************************/ - -void ListSetAllocationPolicy (list_t list, int minItemsPerAlloc, - int percentIncreasePerAlloc) -{ - (*list)->percentIncrease = percentIncreasePerAlloc; - (*list)->minNumItemsIncrease = minItemsPerAlloc; -} - -/*******************************/ - -void ListDispose (list_t list) -{ - DisposeHandle ((Handle) list); -} -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListDisposePtrList (list_t list) -{ - int index; - int numItems; - - if (list) { - numItems = ListNumItems (list); - - for (index = 1; index <= numItems; index++) - free (*(void **) ListGetPtrToItem (list, index)); - - ListDispose (list); - } -} - -/*******************************/ - -/* - * keeps memory, resets the number of items to 0 - */ -void ListClear (list_t list) -{ - if (!list) - return; - (*list)->numItems = 0; -} - -/*******************************/ - -/* - * copy is only as large as necessary - */ -list_t ListCopy (list_t originalList) -{ - list_t tempList = NULL; - int numItems; - - if (!originalList) - return NULL; - - tempList = ListCreate ((*originalList)->itemSize); - if (tempList) { - numItems = ListNumItems (originalList); - - if (!SetHandleSize ((Handle) tempList, - sizeof (ListStruct) + - numItems * (*tempList)->itemSize)) { - ListDispose (tempList); - return NULL; - } - - (*tempList)->numItems = (*originalList)->numItems; - (*tempList)->listSize = (*originalList)->numItems; - (*tempList)->itemSize = (*originalList)->itemSize; - (*tempList)->percentIncrease = (*originalList)->percentIncrease; - (*tempList)->minNumItemsIncrease = - (*originalList)->minNumItemsIncrease; - - memcpy (ITEMPTR (tempList, 0), ITEMPTR (originalList, 0), - numItems * (*tempList)->itemSize); - } - - return tempList; -} - -/********************************/ - -/* - * list1 = list1 + list2 - */ -int ListAppend (list_t list1, list_t list2) -{ - int numItemsL1, numItemsL2; - - if (!list2) - return 1; - - if (!list1) - return 0; - if ((*list1)->itemSize != (*list2)->itemSize) - return 0; - - numItemsL1 = ListNumItems (list1); - numItemsL2 = ListNumItems (list2); - - if (numItemsL2 == 0) - return 1; - - if (!SetHandleSize ((Handle) list1, - sizeof (ListStruct) + (numItemsL1 + numItemsL2) * - (*list1)->itemSize)) { - return 0; - } - - (*list1)->numItems = numItemsL1 + numItemsL2; - (*list1)->listSize = numItemsL1 + numItemsL2; - - memmove (ITEMPTR (list1, numItemsL1), - ITEMPTR (list2, 0), - numItemsL2 * (*list2)->itemSize); - - return 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -/* - * returns 1 if the item is inserted, returns 0 if out of memory or - * bad arguments were passed. - */ -int ListInsertItem (list_t list, void *ptrToItem, int itemPosition) -{ - return ListInsertItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -int ListInsertItems (list_t list, void *ptrToItems, int firstItemPosition, - int numItemsToInsert) -{ - int numItems = (*list)->numItems; - - if (firstItemPosition == numItems + 1) - firstItemPosition = LIST_END; - else if (firstItemPosition > numItems) - return 0; - - if ((*list)->numItems >= (*list)->listSize) { - if (!ExpandListSpace (list, -numItemsToInsert)) - return 0; - } - - if (firstItemPosition == LIST_START) { - if (numItems == 0) { - /* special case for empty list */ - firstItemPosition = LIST_END; - } else { - firstItemPosition = 1; - } - } - - if (firstItemPosition == LIST_END) { /* add at the end of the list */ - if (ptrToItems) - memcpy (ITEMPTR (list, numItems), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, numItems), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } else { /* move part of list up to make room for new item */ - memmove (ITEMPTR (list, firstItemPosition - 1 + numItemsToInsert), - ITEMPTR (list, firstItemPosition - 1), - (numItems + 1 - firstItemPosition) * (*list)->itemSize); - - if (ptrToItems) - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, firstItemPosition - 1), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } - - return 1; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/*******************************/ - -int ListEqual (list_t list1, list_t list2) -{ - if (list1 == list2) - return 1; - - if (list1 == NULL || list2 == NULL) - return 0; - - if ((*list1)->itemSize == (*list1)->itemSize) { - if ((*list1)->numItems == (*list2)->numItems) { - return (memcmp (ITEMPTR (list1, 0), ITEMPTR (list2, 0), - (*list1)->itemSize * (*list1)->numItems) == 0); - } - } - - return 0; -} - -/*******************************/ - -/* - * The item pointed to by ptrToItem is copied over the current item - * at itemPosition - */ -void ListReplaceItem (list_t list, void *ptrToItem, int itemPosition) -{ - ListReplaceItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -/* - * The item pointed to by ptrToItems is copied over the current item - * at itemPosition - */ -void ListReplaceItems ( list_t list, void *ptrToItems, - int firstItemPosition, int numItemsToReplace) -{ - - if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - else if (firstItemPosition == LIST_START) - firstItemPosition = 1; - - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToReplace); -} - -/*******************************/ - -void ListGetItem (list_t list, void *itemDestination, int itemPosition) -{ - ListGetItems (list, itemDestination, itemPosition, 1); -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -#if defined(CFG_ALL_LIST_FUNCTIONS) || defined(CFG_DEVICE_DEREGISTER) - -void ListRemoveItem (list_t list, void *itemDestination, int itemPosition) -{ - ListRemoveItems (list, itemDestination, itemPosition, 1); -} - -/*******************************/ - -void ListRemoveItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToRemove) -{ - int firstItemAfterChunk, numToMove; - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - if (itemsDestination != NULL) - memcpy (itemsDestination, ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToRemove); - - firstItemAfterChunk = firstItemPosition + numItemsToRemove; - numToMove = (*list)->numItems - (firstItemAfterChunk - 1); - - if (numToMove > 0) { - /* - * move part of list down to cover hole left by removed item - */ - memmove (ITEMPTR (list, firstItemPosition - 1), - ITEMPTR (list, firstItemAfterChunk - 1), - (*list)->itemSize * numToMove); - } - - (*list)->numItems -= numItemsToRemove; -} -#endif /* CFG_ALL_LIST_FUNCTIONS || CFG_DEVICE_DEREGISTER */ - -/*******************************/ - -void ListGetItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToGet) -{ - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - memcpy (itemsDestination, - ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToGet); -} - -/*******************************/ - -/* - * Returns a pointer to the item at itemPosition. returns null if an - * errors occurred. - */ -void *ListGetPtrToItem (list_t list, int itemPosition) -{ - if (itemPosition == LIST_START) - itemPosition = 1; - else if (itemPosition == LIST_END) - itemPosition = (*list)->numItems; - - return ITEMPTR (list, itemPosition - 1); -} - -/*******************************/ - -/* - * returns a pointer the lists data (abstraction violation for - * optimization) - */ -void *ListGetDataPtr (list_t list) -{ - return &((*list)->itemList[0]); -} - -/********************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -int ListApplyToEach (list_t list, int ascending, - ListApplicationFunc funcToApply, - void *callbackData) -{ - int result = 0, index; - - if (!list || !funcToApply) - goto Error; - - if (ascending) { - for (index = 1; index <= ListNumItems (list); index++) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } else { - for (index = ListNumItems (list); - index > 0 && index <= ListNumItems (list); - index--) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } - -Error: - return result; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/********************************/ - -int ListGetItemSize (list_t list) -{ - return (*list)->itemSize; -} - -/********************************/ - -int ListNumItems (list_t list) -{ - return (*list)->numItems; -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListRemoveDuplicates (list_t list, CompareFunction compareFunction) -{ - int numItems, index, startIndexForFind, duplicatesIndex; - - numItems = ListNumItems (list); - - for (index = 1; index < numItems; index++) { - startIndexForFind = index + 1; - while (startIndexForFind <= numItems) { - duplicatesIndex = - ListFindItem (list, - ListGetPtrToItem (list, index), - startIndexForFind, - compareFunction); - if (duplicatesIndex > 0) { - ListRemoveItem (list, NULL, duplicatesIndex); - numItems--; - startIndexForFind = duplicatesIndex; - } else { - break; - } - } - } -} - -/*******************************/ - - -/*******************************/ - -int ListFindItem (list_t list, void *ptrToItem, int startingPosition, - CompareFunction compareFunction) -{ - int numItems, size, index, cmp; - void *listItemPtr; - - if ((numItems = (*list)->numItems) == 0) - return 0; - - size = (*list)->itemSize; - - if (startingPosition == LIST_START) - startingPosition = 1; - else if (startingPosition == LIST_END) - startingPosition = numItems; - - for (index = startingPosition; index <= numItems; index++) { - listItemPtr = ITEMPTR (list, index - 1); - cmp = compareFunction - ? compareFunction (ptrToItem, listItemPtr) - : ListMemBlockCmp (ptrToItem, listItemPtr, size); - if (cmp == 0) - return index; - } - - return 0; -} - -/*******************************/ - -int ShortCompare (void *a, void *b) -{ - if (*(short *) a < *(short *) b) - return -1; - if (*(short *) a > *(short *) b) - return 1; - return 0; -} - -/*******************************/ - -int IntCompare (void *a, void *b) -{ - if (*(int *) a < *(int *) b) - return -1; - if (*(int *) a > *(int *) b) - return 1; - return 0; -} - -/*******************************/ - -int CStringCompare (void *a, void *b) -{ - return strcmp (*(char **) a, *(char **) b); -} - -/*******************************/ - - -int ListBinSearch (list_t list, void *ptrToItem, - CompareFunction compareFunction) -{ - int index; - - index = BinSearch (ITEMPTR (list, 0), - (int) (*list)->numItems, - (int) (*list)->itemSize, ptrToItem, - compareFunction); - - if (index >= 0) - index++; /* lists start from 1 */ - else - index = 0; /* item not found */ - - return index; -} - -/**************************************************************************/ - -/* - * Reserves memory for numItems in the list. If it succeeds then - * numItems items can be inserted without possibility of an out of - * memory error (useful to simplify error recovery in complex - * functions). Returns 1 if success, 0 if out of memory. - */ -int ListPreAllocate (list_t list, int numItems) -{ - if ((*list)->listSize - (*list)->numItems < numItems) { - return ExpandListSpace (list, - numItems - ((*list)->listSize - - (*list)->numItems)); - } else { - return 1; /* enough items are already pre-allocated */ - } -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 04d9730..108bd60 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -152,7 +152,7 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum); /* search for keyboard and register it if found */ int drv_usb_kbd_init(void) { - int error,i,index; + int error,i; device_t usb_kbd_dev,*old_dev; struct usb_device *dev; char *stdinname = getenv ("stdin"); @@ -166,13 +166,11 @@ int drv_usb_kbd_init(void) if(usb_kbd_probe(dev,0)==1) { /* Ok, we found a keyboard */ /* check, if it is already registered */ USB_KBD_PRINTF("USB KBD found set up device.\n"); - for (index=1; index<=ListNumItems(devlist); index++) { - old_dev = ListGetPtrToItem(devlist, index); - if(strcmp(old_dev->name,DEVNAME)==0) { - /* ok, already registered, just return ok */ - USB_KBD_PRINTF("USB KBD is already registered.\n"); - return 1; - } + old_dev = device_get_by_name(DEVNAME); + if(old_dev) { + /* ok, already registered, just return ok */ + USB_KBD_PRINTF("USB KBD is already registered.\n"); + return 1; } /* register the keyboard */ USB_KBD_PRINTF("USB KBD register.\n"); diff --git a/include/devices.h b/include/devices.h index 2d9e282..490016b 100644 --- a/include/devices.h +++ b/include/devices.h @@ -21,7 +21,7 @@ * MA 02111-1307 USA */
-#include <lists.h> +#include <linux/list.h>
#ifndef _DEVICES_H_ #define _DEVICES_H_ @@ -59,6 +59,7 @@ typedef struct { /* Other functions */
void *priv; /* Private extensions */ + struct list_head list; } device_t;
/* @@ -82,7 +83,6 @@ typedef struct { /* * VARIABLES */ -extern list_t devlist; extern device_t *stdio_devices[]; extern char *stdio_names[MAX_FILES];
@@ -91,8 +91,10 @@ extern char *stdio_names[MAX_FILES]; */ int device_register (device_t * dev); int devices_init (void); -int devices_done (void); int device_deregister(char *devname); +struct list_head* device_get_list(void); +device_t* device_get_by_name(char* name); + #ifdef CONFIG_LCD int drv_lcd_init (void); #endif diff --git a/include/lists.h b/include/lists.h deleted file mode 100644 index 10a2a19..0000000 --- a/include/lists.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef _LISTS_H_ -#define _LISTS_H_ - -#define LIST_START -1 /* Handy Constants that substitute for item positions */ -#define LIST_END 0 /* END_OF_LIST means one past current length of list when */ - /* inserting. Otherwise it refers the last item in the list. */ - -typedef struct - { - void *ptr; - unsigned int size; - } HandleRecord; - -typedef void **Handle; - -typedef int (*CompareFunction)(void *data1, void *data2) ; - -typedef struct ListStructTag - { - int signature; /* debugging aid */ - int percentIncrease; /* %of current size to increase by when list is out of space */ - int minNumItemsIncrease; /* fixed number of items to increase by when list is out of space */ - int listSize; /* number of items than can fit in the currently allocated memory */ - int itemSize; /* the size of each item in the list (same for every item) */ - int numItems; /* number of items currently in the list */ - unsigned char itemList[1]; /* resizable array of list elements */ - } ListStruct; - -typedef struct ListStructTag **list_t; /* The list abstract data type */ -typedef int ( * ListApplicationFunc)(int index, void *ptrToItem, void *callbackData); - -/* Basic List Operations */ -list_t ListCreate(int elementSize); -int ListNumItems(list_t list); -int ListInsertItem(list_t list, void *ptrToItem, int itemPosition); -int ListInsertItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToInsert); -void ListDispose(list_t list); -void *ListGetPtrToItem(list_t list, int itemPosition); -void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); -void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); - -#if 0 /* rarely ever used; kept here for reference just in case ... */ -void ListDisposePtrList(list_t list); -void ListGetItem(list_t list, void *itemDestination, int itemPosition); -void ListReplaceItem(list_t list, void *ptrToItem, int itemPosition); -void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); -void ListGetItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToGet); -void ListReplaceItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToReplace); -void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); -list_t ListCopy(list_t originalList); -int ListAppend(list_t list1, list_t list2); -void ListClear(list_t list); -int ListEqual(list_t list1, list_t list2); -int ListInsertInOrder(list_t list, void *ptrToItem, CompareFunction compareFunction); -void *ListGetDataPtr(list_t list); -int ListApplyToEach(list_t list, int ascending, ListApplicationFunc funcToApply, void *callbackData); - -/* List Searching and Sorting */ -int ListFindItem(list_t list, void *ptrToItem, int startingPosition, CompareFunction compareFunction); -void ListRemoveDuplicates(list_t list, CompareFunction compareFunction); -int ListBinSearch(list_t list, void *itemPtr, CompareFunction compareFunction); -void ListQuickSort(list_t list, CompareFunction compareFunction); -void ListHeapSort(list_t list, CompareFunction compareFunction); -void ListInsertionSort(list_t list, CompareFunction compareFunction); -int ListIsSorted(list_t list, CompareFunction compareFunction); - -/* Advanced List Functions */ -void ListSetAllocationPolicy(list_t list, int minItemsPerAlloc, int percentIncreasePerAlloc); -void ListCompact(list_t list); -int ListPreAllocate(list_t list, int numItems); -int ListGetItemSize(list_t list); -int GetIntListFromParmInfo(va_list parmInfo, int numIntegers, list_t *integerList); -int ListInsertAfterItem(list_t list, void *ptrToItem, void *ptrToItemToInsertAfter, CompareFunction compareFunction); -int ListInsertBeforeItem(list_t list, void *ptrToItem, void *ptrToItemToInsertBefore, CompareFunction compareFunction); -#endif /* 0 */ - -#endif /* _LISTS_H_ */

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- fs/Makefile | 10 +++++++++- fs/cramfs/Makefile | 7 ++++--- fs/cramfs/cramfs.c | 5 ----- fs/cramfs/uncompress.c | 4 ---- fs/ext2/Makefile | 6 +++--- fs/ext2/dev.c | 3 --- fs/ext2/ext2fs.c | 4 ---- fs/fat/Makefile | 6 +++--- fs/fat/fat.c | 4 ---- fs/fat/file.c | 4 ---- fs/fdos/Makefile | 6 +++--- fs/fdos/dev.c | 5 ----- fs/fdos/fat.c | 4 ---- fs/fdos/fdos.c | 5 +---- fs/fdos/fs.c | 4 ---- fs/fdos/subdir.c | 3 --- fs/fdos/vfat.c | 5 ----- fs/jffs2/Makefile | 8 +++++--- fs/jffs2/compr_lzari.c | 3 --- fs/jffs2/compr_lzo.c | 4 ---- fs/jffs2/compr_rtime.c | 4 ---- fs/jffs2/compr_rubin.c | 4 ---- fs/jffs2/compr_zlib.c | 4 ---- fs/jffs2/jffs2_1pass.c | 5 ----- fs/jffs2/jffs2_nand_1pass.c | 2 +- fs/jffs2/mini_inflate.c | 5 ----- fs/reiserfs/Makefile | 6 +++--- fs/reiserfs/dev.c | 4 ---- fs/reiserfs/mode_string.c | 3 --- fs/reiserfs/reiserfs.c | 4 ---- 30 files changed, 32 insertions(+), 109 deletions(-)
diff --git a/fs/Makefile b/fs/Makefile index 95ac0e9..8bbd563 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -22,7 +22,15 @@ # #
-SUBDIRS := jffs2 cramfs fdos fat reiserfs ext2 yaffs2 +subdirs-$(CONFIG_CMD_CRAMFS) := cramfs +subdirs-$(CONFIG_CMD_EXT2) += ext2 +subdirs-$(CONFIG_CMD_FAT) += fat +subdirs-$(CONFIG_CMD_FDOS) += fdos +subdirs-$(CONFIG_CMD_JFFS2) += jffs2 +subdirs-$(CONFIG_CMD_REISER) += reiserfs +subdirs-$(CONFIG_YAFFS2) += yaffs2 + +SUBDIRS := $(subdirs-y)
$(obj).depend all: @for dir in $(SUBDIRS) ; do \ diff --git a/fs/cramfs/Makefile b/fs/cramfs/Makefile index 13c043f..7b6cc0a 100644 --- a/fs/cramfs/Makefile +++ b/fs/cramfs/Makefile @@ -26,10 +26,11 @@ include $(TOPDIR)/config.mk LIB = $(obj)libcramfs.a
AOBJS = -COBJS = cramfs.o uncompress.o +COBJS-$(CONFIG_CMD_CRAMFS) := cramfs.o +COBJS-$(CONFIG_CMD_CRAMFS) += uncompress.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c index e53c783..2956d39 100644 --- a/fs/cramfs/cramfs.c +++ b/fs/cramfs/cramfs.c @@ -26,9 +26,6 @@
#include <common.h> #include <malloc.h> - -#if defined(CONFIG_CMD_CRAMFS) - #include <asm/byteorder.h> #include <linux/stat.h> #include <jffs2/jffs2.h> @@ -343,5 +340,3 @@ int cramfs_check (struct part_info *info) } return 1; } - -#endif /* CFG_FS_CRAMFS */ diff --git a/fs/cramfs/uncompress.c b/fs/cramfs/uncompress.c index cf67967..39dd275 100644 --- a/fs/cramfs/uncompress.c +++ b/fs/cramfs/uncompress.c @@ -25,8 +25,6 @@ #include <watchdog.h> #include <zlib.h>
-#if defined(CONFIG_CMD_CRAMFS) - static z_stream stream;
void *zalloc(void *, unsigned, unsigned); @@ -86,5 +84,3 @@ int cramfs_uncompress_exit (void) inflateEnd (&stream); return 0; } - -#endif /* CFG_FS_CRAMFS */ diff --git a/fs/ext2/Makefile b/fs/ext2/Makefile index 8313cdc..712e348 100644 --- a/fs/ext2/Makefile +++ b/fs/ext2/Makefile @@ -30,10 +30,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libext2fs.a
AOBJS = -COBJS = ext2fs.o dev.o +COBJS-$(CONFIG_CMD_EXT2) := ext2fs.o dev.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/ext2/dev.c b/fs/ext2/dev.c index 1728b34..3b49650 100644 --- a/fs/ext2/dev.c +++ b/fs/ext2/dev.c @@ -25,8 +25,6 @@
#include <common.h> -#if defined(CONFIG_CMD_EXT2) - #include <config.h> #include <ext2fs.h>
@@ -139,4 +137,3 @@ int ext2fs_devread (int sector, int byte_offset, int byte_len, char *buf) { } return (1); } -#endif diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c index 7833551..436f4a4 100644 --- a/fs/ext2/ext2fs.c +++ b/fs/ext2/ext2fs.c @@ -24,8 +24,6 @@ */
#include <common.h> - -#if defined(CONFIG_CMD_EXT2) #include <ext2fs.h> #include <malloc.h> #include <asm/byteorder.h> @@ -874,5 +872,3 @@ fail: ext2fs_root = NULL; return (0); } - -#endif diff --git a/fs/fat/Makefile b/fs/fat/Makefile index 87af73b..b711460 100644 --- a/fs/fat/Makefile +++ b/fs/fat/Makefile @@ -24,10 +24,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libfat.a
AOBJS = -COBJS = fat.o file.o +COBJS-$(CONFIG_CMD_FAT) := fat.o file.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
all: $(LIB) $(AOBJS)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 49c78ed..2f0bd8c 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -31,8 +31,6 @@ #include <asm/byteorder.h> #include <part.h>
-#if defined(CONFIG_CMD_FAT) - /* * Convert a string to lowercase. */ @@ -1024,5 +1022,3 @@ file_fat_read(const char *filename, void *buffer, unsigned long maxsize) printf("reading %s\n",filename); return do_fat_read(filename, buffer, maxsize, LS_NO); } - -#endif diff --git a/fs/fat/file.c b/fs/fat/file.c index 514dbae..e870734 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -32,8 +32,6 @@ #include <linux/stat.h> #include <linux/time.h>
-#if defined(CONFIG_CMD_FAT) - /* Supported filesystems */ static const struct filesystem filesystems[] = { { file_fat_detectfs, file_fat_ls, file_fat_read, "FAT" }, @@ -204,5 +202,3 @@ file_read(const char *filename, void *buffer, unsigned long maxsize)
return filesystems[current_filesystem].read(arg, buffer, maxsize); } - -#endif diff --git a/fs/fdos/Makefile b/fs/fdos/Makefile index 2dba0fb..fce2032 100644 --- a/fs/fdos/Makefile +++ b/fs/fdos/Makefile @@ -31,10 +31,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libfdos.a
AOBJS = -COBJS = fat.o vfat.o dev.o fdos.o fs.o subdir.o +COBJS-$(CONFIG_CMD_FDOS) := fat.o vfat.o dev.o fdos.o fs.o subdir.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/fdos/dev.c b/fs/fdos/dev.c index 271d0e7..b55b6ed 100644 --- a/fs/fdos/dev.c +++ b/fs/fdos/dev.c @@ -28,8 +28,6 @@ #include "dos.h" #include "fdos.h"
-#if defined(CONFIG_CMD_FDOS) - #define NB_HEADS 2 #define NB_TRACKS 80 #define NB_SECTORS 18 @@ -190,6 +188,3 @@ int check_dev (BootSector_t *boot, Fs_t *fs)
return (0); } - - -#endif diff --git a/fs/fdos/fat.c b/fs/fdos/fat.c index 2e2d2b8..5707c19 100644 --- a/fs/fdos/fat.c +++ b/fs/fdos/fat.c @@ -26,8 +26,6 @@ #include <config.h> #include <malloc.h>
-#if defined(CONFIG_CMD_FDOS) - #include "dos.h" #include "fdos.h"
@@ -138,5 +136,3 @@ int read_fat (BootSector_t *boot, Fs_t *fs) } return (0); } - -#endif diff --git a/fs/fdos/fdos.c b/fs/fdos/fdos.c index 5be6a96..db58562 100644 --- a/fs/fdos/fdos.c +++ b/fs/fdos/fdos.c @@ -24,9 +24,8 @@
#include <common.h> #include <config.h> - -#if defined(CONFIG_CMD_FDOS) #include <malloc.h> + #include "dos.h" #include "fdos.h"
@@ -171,5 +170,3 @@ int dos_dir (void) free (name); return (0); } - -#endif diff --git a/fs/fdos/fs.c b/fs/fdos/fs.c index aded670..5acf123 100644 --- a/fs/fdos/fs.c +++ b/fs/fdos/fs.c @@ -26,8 +26,6 @@ #include <config.h> #include <malloc.h>
-#if defined(CONFIG_CMD_FDOS) - #include "dos.h" #include "fdos.h"
@@ -114,5 +112,3 @@ int fs_init (Fs_t *fs) free (boot); return (0); } - -#endif diff --git a/fs/fdos/subdir.c b/fs/fdos/subdir.c index 497f554..5e96b0a 100644 --- a/fs/fdos/subdir.c +++ b/fs/fdos/subdir.c @@ -26,8 +26,6 @@ #include <config.h> #include <malloc.h>
-#if defined(CONFIG_CMD_FDOS) - #include "dos.h" #include "fdos.h"
@@ -345,4 +343,3 @@ int read_file (Fs_t *fs, } return (read); } -#endif diff --git a/fs/fdos/vfat.c b/fs/fdos/vfat.c index 0e7883b..9f357a6 100644 --- a/fs/fdos/vfat.c +++ b/fs/fdos/vfat.c @@ -24,8 +24,6 @@
#include <common.h> #include <config.h> - -#if defined(CONFIG_CMD_FDOS) #include <linux/ctype.h>
#include "dos.h" @@ -352,6 +350,3 @@ static char *conv_name (char *name, char *ext, char Case, char *ans) } return (ans); } - - -#endif diff --git a/fs/jffs2/Makefile b/fs/jffs2/Makefile index a071af1..fd6a105 100644 --- a/fs/jffs2/Makefile +++ b/fs/jffs2/Makefile @@ -26,13 +26,15 @@ include $(TOPDIR)/config.mk LIB = $(obj)libjffs2.a
AOBJS = -COBJS-y += jffs2_1pass.o +ifdef CONFIG_CMD_JFFS2 +COBJS-$(CONFIG_JFFS2_LZO_LZARI) += compr_lzari.o +COBJS-$(CONFIG_JFFS2_LZO_LZARI) += compr_lzo.o COBJS-y += compr_rtime.o COBJS-y += compr_rubin.o COBJS-y += compr_zlib.o +COBJS-y += jffs2_1pass.o COBJS-y += mini_inflate.o -COBJS-y += compr_lzo.o -COBJS-y += compr_lzari.o +endif
COBJS := $(COBJS-y) SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/fs/jffs2/compr_lzari.c b/fs/jffs2/compr_lzari.c index f64bc74..6a29608 100644 --- a/fs/jffs2/compr_lzari.c +++ b/fs/jffs2/compr_lzari.c @@ -50,8 +50,6 @@ All rights reserved. Permission granted for non-commercial use.
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_LZO_LZARI) - #include <linux/stddef.h> #include <jffs2/jffs2.h>
@@ -259,4 +257,3 @@ int lzari_decompress(unsigned char *data_in, unsigned char *cpage_out, { return Decode(data_in, cpage_out, srclen, destlen); } -#endif diff --git a/fs/jffs2/compr_lzo.c b/fs/jffs2/compr_lzo.c index a32b993..e648ec4 100644 --- a/fs/jffs2/compr_lzo.c +++ b/fs/jffs2/compr_lzo.c @@ -67,8 +67,6 @@
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_LZO_LZARI) - #include <linux/stddef.h> #include <jffs2/jffs2.h> #include <jffs2/compr_rubin.h> @@ -401,5 +399,3 @@ int lzo_decompress(unsigned char *data_in, unsigned char *cpage_out, lzo_uint outlen = destlen; return lzo1x_decompress (data_in, srclen, cpage_out, &outlen, NULL); } - -#endif diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c index 144263c..89b9f2f 100644 --- a/fs/jffs2/compr_rtime.c +++ b/fs/jffs2/compr_rtime.c @@ -46,8 +46,6 @@ */
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h>
void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, @@ -87,5 +85,3 @@ void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, } } } - -#endif diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c index f6f3fa1..9ff2217 100644 --- a/fs/jffs2/compr_rubin.c +++ b/fs/jffs2/compr_rubin.c @@ -39,8 +39,6 @@ */
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h> #include <jffs2/compr_rubin.h>
@@ -122,5 +120,3 @@ void dynrubin_decompress(unsigned char *data_in, unsigned char *cpage_out,
rubin_do_decompress(bits, data_in+8, cpage_out, dstlen); } - -#endif diff --git a/fs/jffs2/compr_zlib.c b/fs/jffs2/compr_zlib.c index 29dfe1b..d306b6d 100644 --- a/fs/jffs2/compr_zlib.c +++ b/fs/jffs2/compr_zlib.c @@ -37,8 +37,6 @@
#include <common.h> #include <config.h> -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h> #include <jffs2/mini_inflate.h>
@@ -48,5 +46,3 @@ long zlib_decompress(unsigned char *data_in, unsigned char *cpage_out, return (decompress_block(cpage_out, data_in + 2, (void *) ldr_memcpy));
} - -#endif diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c index b5e7ab8..5d22dd7 100644 --- a/fs/jffs2/jffs2_1pass.c +++ b/fs/jffs2/jffs2_1pass.c @@ -117,9 +117,6 @@ #include <linux/stat.h> #include <linux/time.h> #include <watchdog.h> - -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h> #include <jffs2/jffs2_1pass.h>
@@ -1394,5 +1391,3 @@ jffs2_1pass_info(struct part_info * part) } return 1; } - -#endif diff --git a/fs/jffs2/jffs2_nand_1pass.c b/fs/jffs2/jffs2_nand_1pass.c index 9f6de7d..e288d5a 100644 --- a/fs/jffs2/jffs2_nand_1pass.c +++ b/fs/jffs2/jffs2_nand_1pass.c @@ -1,6 +1,6 @@ #include <common.h>
-#if !defined(CONFIG_NAND_LEGACY) && defined(CONFIG_CMD_JFFS2) +#if !defined(CONFIG_NAND_LEGACY)
#include <malloc.h> #include <linux/stat.h> diff --git a/fs/jffs2/mini_inflate.c b/fs/jffs2/mini_inflate.c index 4c50fc3..bd40a57 100644 --- a/fs/jffs2/mini_inflate.c +++ b/fs/jffs2/mini_inflate.c @@ -24,9 +24,6 @@ */
#include <config.h> - -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/mini_inflate.h>
/* The order that the code lengths in section 3.2.7 are in */ @@ -392,5 +389,3 @@ long decompress_block(unsigned char *dest, unsigned char *source, #endif return stream.error ? -stream.error : stream.decoded; } - -#endif diff --git a/fs/reiserfs/Makefile b/fs/reiserfs/Makefile index e8711a4..9cef8ee 100644 --- a/fs/reiserfs/Makefile +++ b/fs/reiserfs/Makefile @@ -30,10 +30,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libreiserfs.a
AOBJS = -COBJS = reiserfs.o dev.o mode_string.o +COBJS-$(CONFIG_CMD_REISER) := reiserfs.o dev.o mode_string.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/reiserfs/dev.c b/fs/reiserfs/dev.c index 46dc414..1facfaf 100644 --- a/fs/reiserfs/dev.c +++ b/fs/reiserfs/dev.c @@ -19,8 +19,6 @@
#include <common.h> -#if defined(CONFIG_CMD_REISER) - #include <config.h> #include <reiserfs.h>
@@ -119,5 +117,3 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
return 1; } - -#endif diff --git a/fs/reiserfs/mode_string.c b/fs/reiserfs/mode_string.c index 3e57ee4..801263d 100644 --- a/fs/reiserfs/mode_string.c +++ b/fs/reiserfs/mode_string.c @@ -25,7 +25,6 @@
#include <common.h> -#if defined(CONFIG_CMD_REISER) #include <linux/stat.h>
#if ( S_ISUID != 04000 ) || ( S_ISGID != 02000 ) || ( S_ISVTX != 01000 ) \ @@ -137,5 +136,3 @@ const char *bb_mode_string(int mode) }
#endif - -#endif diff --git a/fs/reiserfs/reiserfs.c b/fs/reiserfs/reiserfs.c index aa96361..d84fb20 100644 --- a/fs/reiserfs/reiserfs.c +++ b/fs/reiserfs/reiserfs.c @@ -29,8 +29,6 @@ */
#include <common.h> -#if defined(CONFIG_CMD_REISER) - #include <malloc.h> #include <linux/ctype.h> #include <linux/time.h> @@ -982,5 +980,3 @@ reiserfs_open (char *filename) } return filemax; } - -#endif

Dear Jean-Christophe PLAGNIOL-VILLARD,
In message 1219919251-3644-10-git-send-email-plagnioj@jcrosoft.com you wrote:
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com
include/linux/list.h | 506 +++++++++++++++++++++++++++++++++++++++++++----- include/linux/poison.h | 13 ++
Do we really need this?
diff --git a/include/linux/poison.h b/include/linux/poison.h new file mode 100644 index 0000000..ba7ff84 --- /dev/null +++ b/include/linux/poison.h @@ -0,0 +1,13 @@ +#ifndef _LINUX_POISON_H +#define _LINUX_POISON_H
+/********** include/linux/list.h **********/ +/*
- These are non-NULL pointers that will result in page faults
- under normal circumstances, used to verify that nobody uses
- non-initialized list entries.
- */
+#define LIST_POISON1 ((void *) 0x00100100) +#define LIST_POISON2 ((void *) 0x00200200)
I think this will not work at all in U-Boot, so we can leave it out as well.
Best regards,
Wolfgang Denk

Hi Jean-Chritophe,
On Thu, 2008-08-28 at 12:27 +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com
common/Makefile | 3 +- common/{cmd_autoscript.c => autoscript.c} | 44 -------- common/cmd_autoscript.c | 158 ----------------------------- 3 files changed, 2 insertions(+), 203 deletions(-) copy common/{cmd_autoscript.c => autoscript.c} (79%)
diff --git a/common/Makefile b/common/Makefile index 0c8ef5b..92d7a9e 100644 --- a/common/Makefile +++ b/common/Makefile @@ -31,7 +31,8 @@ COBJS-y += main.o COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o -COBJS-y += cmd_autoscript.o +COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += autoscript.o
Will we run into problems when both CONFIG_AUTOSCRIPT and CONFIG_CMD_AUTOSCRIPT are defined? Adding the following should account for that situation:
COBJS-y += $(COBJS-yy)
+COBJS-$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o
Best, Peter

Hi Jean-Christophe, (Sorry for misspelling your name in the last email;)
On Thu, 2008-08-28 at 10:26 -0500, Peter Tyser wrote:
Hi Jean-Chritophe,
On Thu, 2008-08-28 at 12:27 +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com
common/Makefile | 3 +- common/{cmd_autoscript.c => autoscript.c} | 44 -------- common/cmd_autoscript.c | 158 ----------------------------- 3 files changed, 2 insertions(+), 203 deletions(-) copy common/{cmd_autoscript.c => autoscript.c} (79%)
diff --git a/common/Makefile b/common/Makefile index 0c8ef5b..92d7a9e 100644 --- a/common/Makefile +++ b/common/Makefile @@ -31,7 +31,8 @@ COBJS-y += main.o COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o -COBJS-y += cmd_autoscript.o +COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += autoscript.o
Will we run into problems when both CONFIG_AUTOSCRIPT and CONFIG_CMD_AUTOSCRIPT are defined? Adding the following should account for that situation:
COBJS-y += $(COBJS-yy)
+COBJS-$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o
Forget that last comment - it looks like you made the fix later in the patch series ([PATCH 08/12] common/Makefile: order by functionality). It might be good to move the addition of "COBJS-y += $(COBJS-yy)" to [PATCH 06/12] so that compiles don't break between those 2 commits when bisecting in the future.
Sorry for the noise.
Best, Peter

Forget that last comment - it looks like you made the fix later in the patch series ([PATCH 08/12] common/Makefile: order by functionality). It might be good to move the addition of "COBJS-y += $(COBJS-yy)" to [PATCH 06/12] so that compiles don't break between those 2 commits when bisecting in the future.
Moved
Best Regards, J.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 4 +- common/{cmd_autoscript.c => autoscript.c} | 44 -------- common/cmd_autoscript.c | 158 ----------------------------- 3 files changed, 3 insertions(+), 203 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 0c8ef5b..56cc764 100644 --- a/common/Makefile +++ b/common/Makefile @@ -31,7 +31,8 @@ COBJS-y += main.o COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o -COBJS-y += cmd_autoscript.o +COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += autoscript.o +COBJS-$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o @@ -148,6 +149,7 @@ COBJS-$(CONFIG_MP) += cmd_mp.o COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
+COBJS-y += $(COBJS-yy) COBJS := $(COBJS-y) SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) diff --git a/common/cmd_autoscript.c b/common/autoscript.c similarity index 79% copy from common/cmd_autoscript.c copy to common/autoscript.c index 13af93e..e1d4103 100644 --- a/common/cmd_autoscript.c +++ b/common/autoscript.c @@ -47,8 +47,6 @@ #include <hush.h> #endif
-#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT) - int autoscript (ulong addr, const char *fit_uname) { @@ -199,45 +197,3 @@ autoscript (ulong addr, const char *fit_uname) free (cmd); return rcode; } - -#endif - -/**************************************************/ -#if defined(CONFIG_CMD_AUTOSCRIPT) -int -do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) -{ - ulong addr; - int rcode; - const char *fit_uname = NULL; - - /* Find script image */ - if (argc < 2) { - addr = CFG_LOAD_ADDR; - debug ("* autoscr: default load address = 0x%08lx\n", addr); -#if defined(CONFIG_FIT) - } else if (fit_parse_subimage (argv[1], load_addr, &addr, &fit_uname)) { - debug ("* autoscr: subimage '%s' from FIT image at 0x%08lx\n", - fit_uname, addr); -#endif - } else { - addr = simple_strtoul(argv[1], NULL, 16); - debug ("* autoscr: cmdline image address = 0x%08lx\n", addr); - } - - printf ("## Executing script at %08lx\n", addr); - rcode = autoscript (addr, fit_uname); - return rcode; -} - -U_BOOT_CMD( - 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" -#if defined(CONFIG_FIT) - "For FIT format uImage addr must include subimage\n" - "unit name in the form of addr:<subimg_uname>\n" -#endif -); -#endif diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index 13af93e..2b6a525 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -47,163 +47,6 @@ #include <hush.h> #endif
-#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT) - -int -autoscript (ulong addr, const char *fit_uname) -{ - ulong len; - image_header_t *hdr; - ulong *data; - char *cmd; - int rcode = 0; - int verify; -#if defined(CONFIG_FIT) - const void* fit_hdr; - int noffset; - const void *fit_data; - size_t fit_len; -#endif - - verify = getenv_yesno ("verify"); - - switch (genimg_get_format ((void *)addr)) { - case IMAGE_FORMAT_LEGACY: - hdr = (image_header_t *)addr; - - if (!image_check_magic (hdr)) { - puts ("Bad magic number\n"); - return 1; - } - - if (!image_check_hcrc (hdr)) { - puts ("Bad header crc\n"); - return 1; - } - - if (verify) { - if (!image_check_dcrc (hdr)) { - puts ("Bad data crc\n"); - return 1; - } - } - - if (!image_check_type (hdr, IH_TYPE_SCRIPT)) { - puts ("Bad image type\n"); - return 1; - } - - /* get length of script */ - data = (ulong *)image_get_data (hdr); - - if ((len = uimage_to_cpu (*data)) == 0) { - puts ("Empty Script\n"); - return 1; - } - - /* - * scripts are just multi-image files with one component, seek - * past the zero-terminated sequence of image lengths to get - * to the actual image data - */ - while (*data++); - break; -#if defined(CONFIG_FIT) - case IMAGE_FORMAT_FIT: - if (fit_uname == NULL) { - puts ("No FIT subimage unit name\n"); - return 1; - } - - fit_hdr = (const void *)addr; - if (!fit_check_format (fit_hdr)) { - puts ("Bad FIT image format\n"); - return 1; - } - - /* get script component image node offset */ - noffset = fit_image_get_node (fit_hdr, fit_uname); - if (noffset < 0) { - printf ("Can't find '%s' FIT subimage\n", fit_uname); - return 1; - } - - if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) { - puts ("Not a image image\n"); - return 1; - } - - /* verify integrity */ - if (verify) { - if (!fit_image_check_hashes (fit_hdr, noffset)) { - puts ("Bad Data Hash\n"); - return 1; - } - } - - /* get script subimage data address and length */ - if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) { - puts ("Could not find script subimage data\n"); - return 1; - } - - data = (ulong *)fit_data; - len = (ulong)fit_len; - break; -#endif - default: - puts ("Wrong image format for autoscript\n"); - return 1; - } - - debug ("** Script length: %ld\n", len); - - if ((cmd = malloc (len + 1)) == NULL) { - return 1; - } - - /* make sure cmd is null terminated */ - memmove (cmd, (char *)data, len); - *(cmd + len) = 0; - -#ifdef CFG_HUSH_PARSER /*?? */ - rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON); -#else - { - char *line = cmd; - char *next = cmd; - - /* - * break into individual lines, - * and execute each line; - * terminate on error. - */ - while (*next) { - if (*next == '\n') { - *next = '\0'; - /* run only non-empty commands */ - if ((next - line) > 1) { - debug ("** exec: "%s"\n", - line); - if (run_command (line, 0) < 0) { - rcode = 1; - break; - } - } - line = next + 1; - } - ++next; - } - } -#endif - free (cmd); - return rcode; -} - -#endif - -/**************************************************/ -#if defined(CONFIG_CMD_AUTOSCRIPT) int do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { @@ -240,4 +83,3 @@ U_BOOT_CMD( "unit name in the form of addr:<subimg_uname>\n" #endif ); -#endif

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 70 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 37 insertions(+), 33 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 68aded6..99781fe 100644 --- a/common/Makefile +++ b/common/Makefile @@ -27,16 +27,41 @@ LIB = $(obj)libcommon.a
AOBJS =
+# core COBJS-y += main.o -COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o +COBJS-y += console.o +COBJS-y += command.o +COBJS-y += devices.o +COBJS-y += dlmalloc.o +COBJS-y += exports.o +COBJS-y += hush.o +COBJS-y += image.o +COBJS-y += lists.o +COBJS-y += memsize.o +COBJS-y += s_record.o +COBJS-y += serial.o +COBJS-y += xyzModem.o + +# environment +COBJS-y += environment.o +COBJS-y += env_common.o +COBJS-y += env_dataflash.o +COBJS-y += env_eeprom.o +COBJS-y += env_flash.o +COBJS-y += env_nand.o +COBJS-y += env_nvram.o +COBJS-y += env_onenand.o +COBJS-y += env_sf.o +COBJS-y += env_nowhere.o + +# command COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += autoscript.o COBJS-$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o -COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o +COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o -COBJS-y += image.o COBJS-y += cmd_boot.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-y += cmd_bootm.o @@ -84,11 +109,14 @@ COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o COBJS-y += cmd_load.o COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o +COBJS-y += cmd_mac.o COBJS-y += cmd_mem.o +COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o COBJS-$(CONFIG_MII)$(CONFIG_CMD_MII) += miiphyutil.o COBJS-$(CONFIG_CMD_MII) += cmd_mii.o COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o +COBJS-$(CONFIG_MP) += cmd_mp.o COBJS-y += cmd_nand.o COBJS-$(CONFIG_CMD_NET) += cmd_net.o COBJS-y += cmd_nvedit.o @@ -102,51 +130,27 @@ COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o +COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o COBJS-$(CONFIG_CMD_SETEXPR) += cmd_setexpr.o COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o -COBJS-$(CONFIG_CMD_USB) += cmd_usb.o +ifdef CONFIG_CMD_USB +COBJS-y += cmd_usb.o +COBJS-y += usb.o +COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o +endif COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o COBJS-y += cmd_vfd.o -COBJS-y += command.o -COBJS-y += console.o -COBJS-y += devices.o -COBJS-y += dlmalloc.o COBJS-$(CONFIG_CMD_DOC) += docecc.o -COBJS-y += environment.o -COBJS-y += env_common.o -COBJS-y += env_nand.o -COBJS-y += env_dataflash.o -COBJS-y += env_flash.o -COBJS-y += env_eeprom.o -COBJS-y += env_onenand.o -COBJS-y += env_sf.o -COBJS-y += env_nvram.o -COBJS-y += env_nowhere.o -COBJS-y += exports.o COBJS-y += flash.o -COBJS-y += hush.o COBJS-y += kgdb.o COBJS-$(CONFIG_LCD) += lcd.o -COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o -COBJS-y += memsize.o -COBJS-y += s_record.o -COBJS-y += serial.o -ifdef CONFIG_CMD_USB -COBJS-y += usb.o -COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o -endif COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o -COBJS-y += xyzModem.o -COBJS-y += cmd_mac.o -COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o -COBJS-$(CONFIG_MP) += cmd_mp.o -COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
COBJS-y += $(COBJS-yy)

Dear Jean-Christophe PLAGNIOL-VILLARD,
In message 1220005348-19536-1-git-send-email-plagnioj@jcrosoft.com you wrote:
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com
common/Makefile | 4 +- common/{cmd_autoscript.c => autoscript.c} | 44 -------- common/cmd_autoscript.c | 158 ----------------------------- 3 files changed, 3 insertions(+), 203 deletions(-)
Patch description (Mode conditional compilation to Makefile) and patch content (major code reorganisation) don't match.
What is th eintention of splitting up cmd_autoscript.c into two files? This makes no sense to me.
Also, when we reorganize this, than including the preparations to rename the command as planned.
I suggest we just do that the SUbject says, i. e. deal with the Makefile changes, and leave the rest for now.
Please clean up and resubmit.
Best regards,
Wolfgang Denk

Jean-Christophe PLAGNIOL-VILLARD wrote:
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com
common/Makefile | 1 - drivers/net/Makefile | 1 + {common => drivers/net}/miiphybb.c | 0 3 files changed, 1 insertions(+), 1 deletions(-) rename {common => drivers/net}/miiphybb.c (100%)
diff --git a/common/Makefile b/common/Makefile index 3e4829f..ff2e6c6 100644 --- a/common/Makefile +++ b/common/Makefile @@ -133,7 +133,6 @@ COBJS-$(CONFIG_LCD) += lcd.o COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o COBJS-y += memsize.o -COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/drivers/net/Makefile b/drivers/net/Makefile index bcf31cb..0e86b72 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -41,6 +41,7 @@ COBJS-$(CONFIG_DRIVER_KS8695ETH) += ks8695eth.o COBJS-$(CONFIG_DRIVER_LAN91C96) += lan91c96.o COBJS-$(CONFIG_MACB) += macb.o COBJS-$(CONFIG_MCFFEC) += mcffec.o +COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-$(CONFIG_NATSEMI) += natsemi.o ifeq ($(CONFIG_DRIVER_NE2000),y) COBJS-y += ne2000.o diff --git a/common/miiphybb.c b/drivers/net/miiphybb.c similarity index 100% rename from common/miiphybb.c rename to drivers/net/miiphybb.c
I'd prefer for the PHY CONFIGs to be a separate list from the controller list.
regards, Ben

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- Makefile | 1 + common/Makefile | 1 - drivers/net/phy/Makefile | 46 ++++++++++++++++++++++++++++++++ {common => drivers/net/phy}/miiphybb.c | 0 4 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile index 89fea72..9129300 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,7 @@ LIBS += drivers/mtd/nand_legacy/libnand_legacy.a LIBS += drivers/mtd/onenand/libonenand.a LIBS += drivers/mtd/spi/libspi_flash.a LIBS += drivers/net/libnet.a +LIBS += drivers/net/phy/libphy.a LIBS += drivers/net/sk98lin/libsk98lin.a LIBS += drivers/pci/libpci.a LIBS += drivers/pcmcia/libpcmcia.a diff --git a/common/Makefile b/common/Makefile index 3e4829f..ff2e6c6 100644 --- a/common/Makefile +++ b/common/Makefile @@ -133,7 +133,6 @@ COBJS-$(CONFIG_LCD) += lcd.o COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o COBJS-y += memsize.o -COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile new file mode 100644 index 0000000..10dc082 --- /dev/null +++ b/drivers/net/phy/Makefile @@ -0,0 +1,46 @@ +# +# (C) Copyright 2006 +# 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 +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libphy.a + +COBJS-$(CONFIG_BITBANGMII) += miiphybb.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/common/miiphybb.c b/drivers/net/phy/miiphybb.c similarity index 100% rename from common/miiphybb.c rename to drivers/net/phy/miiphybb.c

Jean-Christophe PLAGNIOL-VILLARD wrote:
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com
Acked-by: Ben Warren biggerbadderben@gmail.com
Makefile | 1 + common/Makefile | 1 - drivers/net/phy/Makefile | 46 ++++++++++++++++++++++++++++++++ {common => drivers/net/phy}/miiphybb.c | 0 4 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile index 89fea72..9129300 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,7 @@ LIBS += drivers/mtd/nand_legacy/libnand_legacy.a LIBS += drivers/mtd/onenand/libonenand.a LIBS += drivers/mtd/spi/libspi_flash.a LIBS += drivers/net/libnet.a +LIBS += drivers/net/phy/libphy.a LIBS += drivers/net/sk98lin/libsk98lin.a LIBS += drivers/pci/libpci.a LIBS += drivers/pcmcia/libpcmcia.a diff --git a/common/Makefile b/common/Makefile index 3e4829f..ff2e6c6 100644 --- a/common/Makefile +++ b/common/Makefile @@ -133,7 +133,6 @@ COBJS-$(CONFIG_LCD) += lcd.o COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o COBJS-y += memsize.o -COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile new file mode 100644 index 0000000..10dc082 --- /dev/null +++ b/drivers/net/phy/Makefile @@ -0,0 +1,46 @@ +# +# (C) Copyright 2006 +# 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 +#
+include $(TOPDIR)/config.mk
+LIB := $(obj)libphy.a
+COBJS-$(CONFIG_BITBANGMII) += miiphybb.o
+COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS))
+all: $(LIB)
+$(LIB): $(obj).depend $(OBJS)
- $(AR) $(ARFLAGS) $@ $(OBJS)
+#########################################################################
+# defines $(obj).depend target +include $(SRCTREE)/rules.mk
+sinclude $(obj).depend
+######################################################################### diff --git a/common/miiphybb.c b/drivers/net/phy/miiphybb.c similarity index 100% rename from common/miiphybb.c rename to drivers/net/phy/miiphybb.c

On 12:26 Thu 28 Aug , Jean-Christophe PLAGNIOL-VILLARD wrote:
Hi,
1)The following patchset will continue the move of conditional compile to Makefile and do some file location move
- It will merge the current list implementation for common/device &
co to linux list.h in order to reduce u-boot size. During test It did show the the patch will reduce u-boot size by 1KB min.
It's available on git://git.denx.de/u-boot-arm.git branch Makefile
Best Regards, J.

Hi Wolfgang Please pull The following changes since commit 33aa4eac66b71c797bbc13b3afe432a2132947d4: Wolfgang Denk (1): Merge branch 'master' of /home/wd/git/u-boot/custodians
are available in the git repository at:
git://git.denx.de/u-boot-arm.git Makefile
Jean-Christophe PLAGNIOL-VILLARD (12): gunzip: move to lib_generic soft_i2c: move to drivers/i2c soft_spi: move to drivers/spi miiphybb: move to drivers/net/phy crc16: move to lib_generic autoscript: Move conditional compilation to Makefile miiphyutil: Move conditional compilation to Makefile common/Makefile: order by functionality cmd_terminal: remove no need ifdef update linux/list devices: merge to list_head fs: Move conditional compilation to Makefile
Makefile | 1 + common/Makefile | 80 ++-- common/autoscript.c | 199 +++++++++ common/cmd_autoscript.c | 158 ------- common/cmd_console.c | 9 +- common/cmd_terminal.c | 14 +- common/console.c | 62 ++-- common/devices.c | 79 ++-- common/lists.c | 734 -------------------------------- common/miiphyutil.c | 2 - common/usb_kbd.c | 14 +- drivers/i2c/Makefile | 1 + {common => drivers/i2c}/soft_i2c.c | 0 drivers/net/phy/Makefile | 46 ++ {common => drivers/net/phy}/miiphybb.c | 0 drivers/spi/Makefile | 3 +- {common => drivers/spi}/soft_spi.c | 0 fs/Makefile | 10 +- fs/cramfs/Makefile | 7 +- fs/cramfs/cramfs.c | 5 - fs/cramfs/uncompress.c | 4 - fs/ext2/Makefile | 6 +- fs/ext2/dev.c | 3 - fs/ext2/ext2fs.c | 4 - fs/fat/Makefile | 6 +- fs/fat/fat.c | 4 - fs/fat/file.c | 4 - fs/fdos/Makefile | 6 +- fs/fdos/dev.c | 5 - fs/fdos/fat.c | 4 - fs/fdos/fdos.c | 5 +- fs/fdos/fs.c | 4 - fs/fdos/subdir.c | 3 - fs/fdos/vfat.c | 5 - fs/jffs2/Makefile | 8 +- fs/jffs2/compr_lzari.c | 3 - fs/jffs2/compr_lzo.c | 4 - fs/jffs2/compr_rtime.c | 4 - fs/jffs2/compr_rubin.c | 4 - fs/jffs2/compr_zlib.c | 4 - fs/jffs2/jffs2_1pass.c | 5 - fs/jffs2/jffs2_nand_1pass.c | 2 +- fs/jffs2/mini_inflate.c | 5 - fs/reiserfs/Makefile | 6 +- fs/reiserfs/dev.c | 4 - fs/reiserfs/mode_string.c | 3 - fs/reiserfs/reiserfs.c | 4 - include/devices.h | 8 +- include/linux/list.h | 506 ++++++++++++++++++++-- include/linux/poison.h | 13 + include/lists.h | 77 ---- lib_generic/Makefile | 2 + {common => lib_generic}/crc16.c | 0 {common => lib_generic}/gunzip.c | 0 54 files changed, 884 insertions(+), 1265 deletions(-) create mode 100644 common/autoscript.c delete mode 100644 common/lists.c rename {common => drivers/i2c}/soft_i2c.c (100%) create mode 100644 drivers/net/phy/Makefile rename {common => drivers/net/phy}/miiphybb.c (100%) rename {common => drivers/spi}/soft_spi.c (100%) create mode 100644 include/linux/poison.h delete mode 100644 include/lists.h rename {common => lib_generic}/crc16.c (100%) rename {common => lib_generic}/gunzip.c (100%)
Best Regards, J.

Dear Jean-Christophe PLAGNIOL-VILLARD,
In message 20080829103205.GD30743@game.jcrosoft.org you wrote:
Hi Wolfgang Please pull The following changes since commit 33aa4eac66b71c797bbc13b3afe432a2132947d4: Wolfgang Denk (1): Merge branch 'master' of /home/wd/git/u-boot/custodians
are available in the git repository at:
Please cleanup as requested first, then rebase your tree.
Thanks.
Best regards,
Wolfgang Denk

On 15:22 Fri 29 Aug , Wolfgang Denk wrote:
Dear Jean-Christophe PLAGNIOL-VILLARD,
In message 20080829103205.GD30743@game.jcrosoft.org you wrote:
Hi Wolfgang Please pull The following changes since commit 33aa4eac66b71c797bbc13b3afe432a2132947d4: Wolfgang Denk (1): Merge branch 'master' of /home/wd/git/u-boot/custodians
are available in the git repository at:
Please cleanup as requested first, then rebase your tree.
Thanks.
done as your comment in V3 reply to this mail
add please pull
The following changes since commit 33aa4eac66b71c797bbc13b3afe432a2132947d4: Wolfgang Denk (1): Merge branch 'master' of /home/wd/git/u-boot/custodians
are available in the git repository at:
git://git.denx.de/u-boot-arm.git Makefile
Jean-Christophe PLAGNIOL-VILLARD (12): gunzip: move to lib_generic soft_i2c: move to drivers/i2c soft_spi: move to drivers/spi miiphybb: move to drivers/net/phy crc16: move to lib_generic autoscript: Move conditional compilation to Makefile miiphyutil: Move conditional compilation to Makefile common/Makefile: order by functionality cmd_terminal: remove no need ifdef update linux/list devices: merge to list_head fs: Move conditional compilation to Makefile
Makefile | 1 + common/Makefile | 79 ++-- common/cmd_autoscript.c | 4 - common/cmd_console.c | 9 +- common/cmd_terminal.c | 14 +- common/console.c | 62 ++-- common/devices.c | 79 ++-- common/lists.c | 734 -------------------------------- common/miiphyutil.c | 2 - common/usb_kbd.c | 14 +- drivers/i2c/Makefile | 1 + {common => drivers/i2c}/soft_i2c.c | 0 drivers/net/phy/Makefile | 46 ++ {common => drivers/net/phy}/miiphybb.c | 0 drivers/spi/Makefile | 3 +- {common => drivers/spi}/soft_spi.c | 0 fs/Makefile | 10 +- fs/cramfs/Makefile | 7 +- fs/cramfs/cramfs.c | 5 - fs/cramfs/uncompress.c | 4 - fs/ext2/Makefile | 6 +- fs/ext2/dev.c | 3 - fs/ext2/ext2fs.c | 4 - fs/fat/Makefile | 6 +- fs/fat/fat.c | 4 - fs/fat/file.c | 4 - fs/fdos/Makefile | 6 +- fs/fdos/dev.c | 5 - fs/fdos/fat.c | 4 - fs/fdos/fdos.c | 5 +- fs/fdos/fs.c | 4 - fs/fdos/subdir.c | 3 - fs/fdos/vfat.c | 5 - fs/jffs2/Makefile | 8 +- fs/jffs2/compr_lzari.c | 3 - fs/jffs2/compr_lzo.c | 4 - fs/jffs2/compr_rtime.c | 4 - fs/jffs2/compr_rubin.c | 4 - fs/jffs2/compr_zlib.c | 4 - fs/jffs2/jffs2_1pass.c | 5 - fs/jffs2/jffs2_nand_1pass.c | 2 +- fs/jffs2/mini_inflate.c | 5 - fs/reiserfs/Makefile | 6 +- fs/reiserfs/dev.c | 4 - fs/reiserfs/mode_string.c | 3 - fs/reiserfs/reiserfs.c | 4 - include/devices.h | 8 +- include/linux/list.h | 506 ++++++++++++++++++++-- include/linux/poison.h | 11 + include/lists.h | 77 ---- lib_generic/Makefile | 2 + {common => lib_generic}/crc16.c | 0 {common => lib_generic}/gunzip.c | 0 53 files changed, 682 insertions(+), 1111 deletions(-) delete mode 100644 common/lists.c rename {common => drivers/i2c}/soft_i2c.c (100%) create mode 100644 drivers/net/phy/Makefile rename {common => drivers/net/phy}/miiphybb.c (100%) rename {common => drivers/spi}/soft_spi.c (100%) create mode 100644 include/linux/poison.h delete mode 100644 include/lists.h rename {common => lib_generic}/crc16.c (100%) rename {common => lib_generic}/gunzip.c (100%)
Best Regards, J.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - lib_generic/Makefile | 1 + {common => lib_generic}/gunzip.c | 0 3 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 944b1c0..d974823 100644 --- a/common/Makefile +++ b/common/Makefile @@ -36,7 +36,6 @@ COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o COBJS-y += image.o -COBJS-y += gunzip.o COBJS-y += cmd_boot.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-y += cmd_bootm.o diff --git a/lib_generic/Makefile b/lib_generic/Makefile index bf0e31d..a820f97 100644 --- a/lib_generic/Makefile +++ b/lib_generic/Makefile @@ -34,6 +34,7 @@ COBJS-y += crc32.o COBJS-y += ctype.o COBJS-y += display_options.o COBJS-y += div64.o +COBJS-y += gunzip.o COBJS-y += lmb.o COBJS-y += ldiv.o COBJS-$(CONFIG_MD5) += md5.o diff --git a/common/gunzip.c b/lib_generic/gunzip.c similarity index 100% rename from common/gunzip.c rename to lib_generic/gunzip.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - drivers/i2c/Makefile | 1 + {common => drivers/i2c}/soft_i2c.c | 0 3 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/Makefile b/common/Makefile index d974823..faeac86 100644 --- a/common/Makefile +++ b/common/Makefile @@ -137,7 +137,6 @@ COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o -COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o ifdef CONFIG_CMD_USB COBJS-y += usb.o diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 1f25afb..6079c05 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -29,6 +29,7 @@ COBJS-$(CONFIG_FSL_I2C) += fsl_i2c.o COBJS-$(CONFIG_I2C_MXC) += mxc_i2c.o COBJS-$(CONFIG_DRIVER_OMAP1510_I2C) += omap1510_i2c.o COBJS-$(CONFIG_DRIVER_OMAP24XX_I2C) += omap24xx_i2c.o +COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
COBJS := $(COBJS-y) diff --git a/common/soft_i2c.c b/drivers/i2c/soft_i2c.c similarity index 100% rename from common/soft_i2c.c rename to drivers/i2c/soft_i2c.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - drivers/spi/Makefile | 3 ++- {common => drivers/spi}/soft_spi.c | 0 3 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/Makefile b/common/Makefile index faeac86..3e4829f 100644 --- a/common/Makefile +++ b/common/Makefile @@ -137,7 +137,6 @@ COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o -COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o ifdef CONFIG_CMD_USB COBJS-y += usb.o COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 4f7b679..15e0f7a 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -25,9 +25,10 @@ include $(TOPDIR)/config.mk
LIB := $(obj)libspi.a
-COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o +COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o +COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/common/soft_spi.c b/drivers/spi/soft_spi.c similarity index 100% rename from common/soft_spi.c rename to drivers/spi/soft_spi.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- Makefile | 1 + common/Makefile | 1 - drivers/net/phy/Makefile | 46 ++++++++++++++++++++++++++++++++ {common => drivers/net/phy}/miiphybb.c | 0 4 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile index 0f82e71..a00195c 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,7 @@ LIBS += drivers/mtd/nand_legacy/libnand_legacy.a LIBS += drivers/mtd/onenand/libonenand.a LIBS += drivers/mtd/spi/libspi_flash.a LIBS += drivers/net/libnet.a +LIBS += drivers/net/phy/libphy.a LIBS += drivers/net/sk98lin/libsk98lin.a LIBS += drivers/pci/libpci.a LIBS += drivers/pcmcia/libpcmcia.a diff --git a/common/Makefile b/common/Makefile index 3e4829f..ff2e6c6 100644 --- a/common/Makefile +++ b/common/Makefile @@ -133,7 +133,6 @@ COBJS-$(CONFIG_LCD) += lcd.o COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o COBJS-y += memsize.o -COBJS-$(CONFIG_BITBANGMII) += miiphybb.o COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile new file mode 100644 index 0000000..10dc082 --- /dev/null +++ b/drivers/net/phy/Makefile @@ -0,0 +1,46 @@ +# +# (C) Copyright 2006 +# 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 +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libphy.a + +COBJS-$(CONFIG_BITBANGMII) += miiphybb.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/common/miiphybb.c b/drivers/net/phy/miiphybb.c similarity index 100% rename from common/miiphybb.c rename to drivers/net/phy/miiphybb.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - lib_generic/Makefile | 1 + {common => lib_generic}/crc16.c | 0 3 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/Makefile b/common/Makefile index ff2e6c6..0c8ef5b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -141,7 +141,6 @@ COBJS-y += usb.o COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o endif COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o -COBJS-y += crc16.o COBJS-y += xyzModem.o COBJS-y += cmd_mac.o COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o diff --git a/lib_generic/Makefile b/lib_generic/Makefile index a820f97..7df5a2c 100644 --- a/lib_generic/Makefile +++ b/lib_generic/Makefile @@ -30,6 +30,7 @@ COBJS-y += bzlib_crctable.o COBJS-y += bzlib_decompress.o COBJS-y += bzlib_randtable.o COBJS-y += bzlib_huffman.o +COBJS-y += crc16.o COBJS-y += crc32.o COBJS-y += ctype.o COBJS-y += display_options.o diff --git a/common/crc16.c b/lib_generic/crc16.c similarity index 100% rename from common/crc16.c rename to lib_generic/crc16.c

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 3 ++- common/cmd_autoscript.c | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 0c8ef5b..918b908 100644 --- a/common/Makefile +++ b/common/Makefile @@ -31,7 +31,7 @@ COBJS-y += main.o COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o -COBJS-y += cmd_autoscript.o +COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o @@ -148,6 +148,7 @@ COBJS-$(CONFIG_MP) += cmd_mp.o COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
+COBJS-y += $(COBJS-yy) COBJS := $(COBJS-y) SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index 13af93e..c2e7e66 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -47,8 +47,6 @@ #include <hush.h> #endif
-#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT) - int autoscript (ulong addr, const char *fit_uname) { @@ -200,8 +198,6 @@ autoscript (ulong addr, const char *fit_uname) return rcode; }
-#endif - /**************************************************/ #if defined(CONFIG_CMD_AUTOSCRIPT) int

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 2 +- common/miiphyutil.c | 2 -- drivers/net/phy/Makefile | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 918b908..6ba20c0 100644 --- a/common/Makefile +++ b/common/Makefile @@ -84,6 +84,7 @@ COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o COBJS-y += cmd_load.o COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o COBJS-y += cmd_mem.o +COBJS-$(CONFIG_MII)$(CONFIG_CMD_MII) += miiphyutil.o COBJS-$(CONFIG_CMD_MII) += cmd_mii.o COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o @@ -133,7 +134,6 @@ COBJS-$(CONFIG_LCD) += lcd.o COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o COBJS-y += memsize.o -COBJS-y += miiphyutil.o COBJS-y += s_record.o COBJS-y += serial.o ifdef CONFIG_CMD_USB diff --git a/common/miiphyutil.c b/common/miiphyutil.c index eac8275..5ef4a33 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -29,7 +29,6 @@ #include <common.h> #include <miiphy.h>
-#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) #include <asm/types.h> #include <linux/list.h> #include <malloc.h> @@ -487,4 +486,3 @@ int miiphy_link (char *devname, unsigned char addr) } } #endif -#endif /* CONFIG_MII */ diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 10dc082..4fe3b05 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -1,5 +1,5 @@ # -# (C) Copyright 2006 +# (C) Copyright 2008 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. # # See file CREDITS for list of people who contributed to this

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 70 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 37 insertions(+), 33 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 6ba20c0..6365fae 100644 --- a/common/Makefile +++ b/common/Makefile @@ -27,15 +27,40 @@ LIB = $(obj)libcommon.a
AOBJS =
+# core COBJS-y += main.o -COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o +COBJS-y += console.o +COBJS-y += command.o +COBJS-y += devices.o +COBJS-y += dlmalloc.o +COBJS-y += exports.o +COBJS-y += hush.o +COBJS-y += image.o +COBJS-y += lists.o +COBJS-y += memsize.o +COBJS-y += s_record.o +COBJS-y += serial.o +COBJS-y += xyzModem.o + +# environment +COBJS-y += environment.o +COBJS-y += env_common.o +COBJS-y += env_dataflash.o +COBJS-y += env_eeprom.o +COBJS-y += env_flash.o +COBJS-y += env_nand.o +COBJS-y += env_nvram.o +COBJS-y += env_onenand.o +COBJS-y += env_sf.o +COBJS-y += env_nowhere.o + +# command COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o -COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o +COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o -COBJS-y += image.o COBJS-y += cmd_boot.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-y += cmd_bootm.o @@ -83,11 +108,14 @@ COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o COBJS-y += cmd_load.o COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o +COBJS-y += cmd_mac.o COBJS-y += cmd_mem.o +COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o COBJS-$(CONFIG_MII)$(CONFIG_CMD_MII) += miiphyutil.o COBJS-$(CONFIG_CMD_MII) += cmd_mii.o COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o +COBJS-$(CONFIG_MP) += cmd_mp.o COBJS-y += cmd_nand.o COBJS-$(CONFIG_CMD_NET) += cmd_net.o COBJS-y += cmd_nvedit.o @@ -101,51 +129,27 @@ COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o +COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o COBJS-$(CONFIG_CMD_SETEXPR) += cmd_setexpr.o COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o -COBJS-$(CONFIG_CMD_USB) += cmd_usb.o +ifdef CONFIG_CMD_USB +COBJS-y += cmd_usb.o +COBJS-y += usb.o +COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o +endif COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o COBJS-y += cmd_vfd.o -COBJS-y += command.o -COBJS-y += console.o -COBJS-y += devices.o -COBJS-y += dlmalloc.o COBJS-$(CONFIG_CMD_DOC) += docecc.o -COBJS-y += environment.o -COBJS-y += env_common.o -COBJS-y += env_nand.o -COBJS-y += env_dataflash.o -COBJS-y += env_flash.o -COBJS-y += env_eeprom.o -COBJS-y += env_onenand.o -COBJS-y += env_sf.o -COBJS-y += env_nvram.o -COBJS-y += env_nowhere.o -COBJS-y += exports.o COBJS-y += flash.o -COBJS-y += hush.o COBJS-y += kgdb.o COBJS-$(CONFIG_LCD) += lcd.o -COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o -COBJS-y += memsize.o -COBJS-y += s_record.o -COBJS-y += serial.o -ifdef CONFIG_CMD_USB -COBJS-y += usb.o -COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o -endif COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o -COBJS-y += xyzModem.o -COBJS-y += cmd_mac.o -COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o -COBJS-$(CONFIG_MP) += cmd_mp.o -COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
COBJS-y += $(COBJS-yy)

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/cmd_terminal.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c index 8871607..57943c1 100644 --- a/common/cmd_terminal.c +++ b/common/cmd_terminal.c @@ -28,8 +28,6 @@ #include <command.h> #include <devices.h>
-#if defined(CONFIG_CMD_TERMINAL) - int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { int i, l; @@ -98,5 +96,3 @@ U_BOOT_CMD( "terminal - start terminal emulator\n", "" ); - -#endif /* CONFIG_CMD_TERMINAL */

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- include/linux/list.h | 506 +++++++++++++++++++++++++++++++++++++++++++----- include/linux/poison.h | 13 ++ 2 files changed, 474 insertions(+), 45 deletions(-)
diff --git a/include/linux/list.h b/include/linux/list.h index e6492f7..aeeeb21 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -1,6 +1,9 @@ #ifndef _LINUX_LIST_H #define _LINUX_LIST_H
+#include <linux/stddef.h> +#include <linux/poison.h> + #ifndef ARCH_HAS_PREFETCH #define ARCH_HAS_PREFETCH static inline void prefetch(const void *x) {;} @@ -25,9 +28,11 @@ struct list_head { #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name)
-#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) +static inline void INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list; + list->prev = list; +}
/* * Insert a new entry between two known consecutive entries. @@ -87,13 +92,37 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) /** * list_del - deletes entry from list. * @entry: the element to delete from the list. - * Note: list_empty on entry does not return true after this, the entry is in an undefined state. + * Note: list_empty() on entry does not return true after this, the entry is + * in an undefined state. */ static inline void list_del(struct list_head *entry) { __list_del(entry->prev, entry->next); - entry->next = (void *) 0; - entry->prev = (void *) 0; + entry->next = LIST_POISON1; + entry->prev = LIST_POISON2; +} + +/** + * list_replace - replace old entry by new one + * @old : the element to be replaced + * @new : the new element to insert + * + * If @old was empty, it will be overwritten. + */ +static inline void list_replace(struct list_head *old, + struct list_head *new) +{ + new->next = old->next; + new->next->prev = new; + new->prev = old->prev; + new->prev->next = new; +} + +static inline void list_replace_init(struct list_head *old, + struct list_head *new) +{ + list_replace(old, new); + INIT_LIST_HEAD(old); }
/** @@ -130,37 +159,129 @@ static inline void list_move_tail(struct list_head *list, }
/** + * list_is_last - tests whether @list is the last entry in list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_last(const struct list_head *list, + const struct list_head *head) +{ + return list->next == head; +} + +/** * list_empty - tests whether a list is empty * @head: the list to test. */ -static inline int list_empty(struct list_head *head) +static inline int list_empty(const struct list_head *head) { return head->next == head; }
-static inline void __list_splice(struct list_head *list, - struct list_head *head) +/** + * list_empty_careful - tests whether a list is empty and not being modified + * @head: the list to test + * + * Description: + * tests whether a list is empty _and_ checks that no other CPU might be + * in the process of modifying either member (next or prev) + * + * NOTE: using list_empty_careful() without synchronization + * can only be safe if the only activity that can happen + * to the list entry is list_del_init(). Eg. it cannot be used + * if another CPU could re-list_add() it. + */ +static inline int list_empty_careful(const struct list_head *head) +{ + struct list_head *next = head->next; + return (next == head) && (next == head->prev); +} + +/** + * list_is_singular - tests whether a list has just one entry. + * @head: the list to test. + */ +static inline int list_is_singular(const struct list_head *head) +{ + return !list_empty(head) && (head->next == head->prev); +} + +static inline void __list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + struct list_head *new_first = entry->next; + list->next = head->next; + list->next->prev = list; + list->prev = entry; + entry->next = list; + head->next = new_first; + new_first->prev = head; +} + +/** + * list_cut_position - cut a list into two + * @list: a new list to add all removed entries + * @head: a list with entries + * @entry: an entry within head, could be the head itself + * and if so we won't cut the list + * + * This helper moves the initial part of @head, up to and + * including @entry, from @head to @list. You should + * pass on @entry an element you know is on @head. @list + * should be an empty list or a list you do not care about + * losing its data. + * + */ +static inline void list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + if (list_empty(head)) + return; + if (list_is_singular(head) && + (head->next != entry && head != entry)) + return; + if (entry == head) + INIT_LIST_HEAD(list); + else + __list_cut_position(list, head, entry); +} + +static inline void __list_splice(const struct list_head *list, + struct list_head *prev, + struct list_head *next) { struct list_head *first = list->next; struct list_head *last = list->prev; - struct list_head *at = head->next;
- first->prev = head; - head->next = first; + first->prev = prev; + prev->next = first;
- last->next = at; - at->prev = last; + last->next = next; + next->prev = last; }
/** - * list_splice - join two lists + * list_splice - join two lists, this is designed for stacks * @list: the new list to add. * @head: the place to add it in the first list. */ -static inline void list_splice(struct list_head *list, struct list_head *head) +static inline void list_splice(const struct list_head *list, + struct list_head *head) { if (!list_empty(list)) - __list_splice(list, head); + __list_splice(list, head, head->next); +} + +/** + * list_splice_tail - join two lists, each list being a queue + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static inline void list_splice_tail(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) + __list_splice(list, head->prev, head); }
/** @@ -174,7 +295,24 @@ static inline void list_splice_init(struct list_head *list, struct list_head *head) { if (!list_empty(list)) { - __list_splice(list, head); + __list_splice(list, head, head->next); + INIT_LIST_HEAD(list); + } +} + +/** + * list_splice_tail_init - join two lists and reinitialise the emptied list + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * Each of the lists is a queue. + * The list at @list is reinitialised + */ +static inline void list_splice_tail_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + __list_splice(list, head->prev, head); INIT_LIST_HEAD(list); } } @@ -186,28 +324,53 @@ static inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + container_of(ptr, type, member) + +/** + * list_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_struct within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member)
/** * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. + * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list. */ #define list_for_each(pos, head) \ - for (pos = (head)->next, prefetch(pos->next); pos != (head); \ - pos = pos->next, prefetch(pos->next)) + for (pos = (head)->next; prefetch(pos->next), pos != (head); \ + pos = pos->next) + +/** + * __list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop cursor. + * @head: the head for your list. + * + * This variant differs from list_for_each() in that it's the + * simplest possible list iteration code, no prefetching is done. + * Use this for code that knows the list to be very short (empty + * or 1 entry) most of the time. + */ +#define __list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + /** * list_for_each_prev - iterate over a list backwards - * @pos: the &struct list_head to use as a loop counter. + * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list. */ #define list_for_each_prev(pos, head) \ - for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \ - pos = pos->prev, prefetch(pos->prev)) + for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ + pos = pos->prev)
/** - * list_for_each_safe - iterate over a list safe against removal of list entry - * @pos: the &struct list_head to use as a loop counter. + * list_for_each_safe - iterate over a list safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. * @n: another &struct list_head to use as temporary storage * @head: the head for your list. */ @@ -216,43 +379,296 @@ static inline void list_splice_init(struct list_head *list, pos = n, n = pos->next)
/** + * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_prev_safe(pos, n, head) \ + for (pos = (head)->prev, n = pos->prev; \ + prefetch(pos->prev), pos != (head); \ + pos = n, n = pos->prev) + +/** * list_for_each_entry - iterate over list of given type - * @pos: the type * to use as a loop counter. + * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_struct within the struct. */ #define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - prefetch(pos->member.next); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next)) + for (pos = list_entry((head)->next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_reverse - iterate backwards over list of given type. + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member); \ + prefetch(pos->member.prev), &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +/** + * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() + * @pos: the type * to use as a start point + * @head: the head of the list + * @member: the name of the list_struct within the struct. + * + * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). + */ +#define list_prepare_entry(pos, head, member) \ + ((pos) ? : list_entry(head, typeof(*pos), member)) + +/** + * list_for_each_entry_continue - continue iteration over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Continue to iterate over list of given type, continuing after + * the current position. + */ +#define list_for_each_entry_continue(pos, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_continue_reverse - iterate backwards from the given point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Start to iterate over list of given type backwards, continuing after + * the current position. + */ +#define list_for_each_entry_continue_reverse(pos, head, member) \ + for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ + prefetch(pos->member.prev), &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +/** + * list_for_each_entry_from - iterate over list of given type from the current point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type, continuing from current position. + */ +#define list_for_each_entry_from(pos, head, member) \ + for (; prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member))
/** * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry - * @pos: the type * to use as a loop counter. + * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_struct within the struct. */ #define list_for_each_entry_safe(pos, n, head, member) \ for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member))
/** - * list_for_each_entry_continue - iterate over list of given type - * continuing after existing point - * @pos: the type * to use as a loop counter. + * list_for_each_entry_safe_continue + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type, continuing after current point, + * safe against removal of list entry. + */ +#define list_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_from + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type from current point, safe against + * removal of list entry. + */ +#define list_for_each_entry_safe_from(pos, n, head, member) \ + for (n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_reverse + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate backwards over list of given type, safe against removal + * of list entry. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + +#define HLIST_HEAD_INIT { .first = NULL } +#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } +#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) +static inline void INIT_HLIST_NODE(struct hlist_node *h) +{ + h->next = NULL; + h->pprev = NULL; +} + +static inline int hlist_unhashed(const struct hlist_node *h) +{ + return !h->pprev; +} + +static inline int hlist_empty(const struct hlist_head *h) +{ + return !h->first; +} + +static inline void __hlist_del(struct hlist_node *n) +{ + struct hlist_node *next = n->next; + struct hlist_node **pprev = n->pprev; + *pprev = next; + if (next) + next->pprev = pprev; +} + +static inline void hlist_del(struct hlist_node *n) +{ + __hlist_del(n); + n->next = LIST_POISON1; + n->pprev = LIST_POISON2; +} + +static inline void hlist_del_init(struct hlist_node *n) +{ + if (!hlist_unhashed(n)) { + __hlist_del(n); + INIT_HLIST_NODE(n); + } +} + +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + n->next = first; + if (first) + first->pprev = &n->next; + h->first = n; + n->pprev = &h->first; +} + +/* next must be != NULL */ +static inline void hlist_add_before(struct hlist_node *n, + struct hlist_node *next) +{ + n->pprev = next->pprev; + n->next = next; + next->pprev = &n->next; + *(n->pprev) = n; +} + +static inline void hlist_add_after(struct hlist_node *n, + struct hlist_node *next) +{ + next->next = n->next; + n->next = next; + next->pprev = &n->next; + + if(next->next) + next->next->pprev = &next->next; +} + +#define hlist_entry(ptr, type, member) container_of(ptr,type,member) + +#define hlist_for_each(pos, head) \ + for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \ + pos = pos->next) + +#define hlist_for_each_safe(pos, n, head) \ + for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ + pos = n) + +/** + * hlist_for_each_entry - iterate over list of given type + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(tpos, pos, head, member) \ + for (pos = (head)->first; \ + pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_continue - iterate over a hlist continuing after current point + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_continue(tpos, pos, member) \ + for (pos = (pos)->next; \ + pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_from - iterate over a hlist continuing from current point + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_from(tpos, pos, member) \ + for (; pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @n: another &struct hlist_node to use as temporary storage + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. */ -#define list_for_each_entry_continue(pos, head, member) \ - for (pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next)) +#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ + for (pos = (head)->first; \ + pos && ({ n = pos->next; 1; }) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = n)
#endif diff --git a/include/linux/poison.h b/include/linux/poison.h new file mode 100644 index 0000000..ba7ff84 --- /dev/null +++ b/include/linux/poison.h @@ -0,0 +1,13 @@ +#ifndef _LINUX_POISON_H +#define _LINUX_POISON_H + +/********** include/linux/list.h **********/ +/* + * These are non-NULL pointers that will result in page faults + * under normal circumstances, used to verify that nobody uses + * non-initialized list entries. + */ +#define LIST_POISON1 ((void *) 0x00100100) +#define LIST_POISON2 ((void *) 0x00200200) + +#endif

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - common/cmd_console.c | 9 +- common/cmd_terminal.c | 10 +- common/console.c | 62 ++--- common/devices.c | 79 +++--- common/lists.c | 734 ------------------------------------------------ common/usb_kbd.c | 14 +- include/devices.h | 8 +- include/linux/poison.h | 8 +- include/lists.h | 77 ----- 10 files changed, 90 insertions(+), 912 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 6365fae..0fe9c8b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -37,7 +37,6 @@ COBJS-y += dlmalloc.o COBJS-y += exports.o COBJS-y += hush.o COBJS-y += image.o -COBJS-y += lists.o COBJS-y += memsize.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/common/cmd_console.c b/common/cmd_console.c index 50ddb01..e2bc2a3 100644 --- a/common/cmd_console.c +++ b/common/cmd_console.c @@ -31,14 +31,17 @@ extern void _do_coninfo (void); int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; + int l; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev;
/* Scan for valid output and input devices */
puts ("List of available devices:\n");
- for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list);
printf ("%-8s %08x %c%c%c ", dev->name, diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c index 57943c1..67a2546 100644 --- a/common/cmd_terminal.c +++ b/common/cmd_terminal.c @@ -27,10 +27,10 @@ #include <common.h> #include <command.h> #include <devices.h> +#include <serial.h>
int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; int last_tilde = 0; device_t *dev = NULL;
@@ -38,13 +38,7 @@ int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) return -1;
/* Scan for selected output/input device */ - for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *tmp = ListGetPtrToItem (devlist, i); - if (!strcmp(tmp->name, argv[1])) { - dev = tmp; - break; - } - } + dev = device_get_by_name(argv[1]); if (!dev) return -1;
diff --git a/common/console.c b/common/console.c index 1b095b1..cfcaeb8 100644 --- a/common/console.c +++ b/common/console.c @@ -325,9 +325,22 @@ inline void dbg(const char *fmt, ...)
/** U-Boot INIT FUNCTIONS *************************************************/
+device_t *search_device (int flags, char *name) +{ + device_t *dev; + + dev = device_get_by_name(name); + + if(dev && (dev->flags & flags)) + return dev; + + return NULL; +} + int console_assign (int file, char *devname) { - int flag, i; + int flag; + device_t *dev;
/* Check for valid file */ switch (file) { @@ -344,16 +357,10 @@ int console_assign (int file, char *devname)
/* Check for valid device name */
- for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); - - if (strcmp (devname, dev->name) == 0) { - if (dev->flags & flag) - return console_setfile (file, dev); + dev = search_device(flag, devname);
- return -1; - } - } + if(dev) + return console_setfile (file, dev);
return -1; } @@ -371,27 +378,6 @@ int console_init_f (void) return (0); }
-#if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE) -/* search a device */ -device_t *search_device (int flags, char *name) -{ - int i, items; - device_t *dev = NULL; - - items = ListNumItems (devlist); - if (name == NULL) - return dev; - - for (i = 1; i <= items; i++) { - dev = ListGetPtrToItem (devlist, i); - if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) { - break; - } - } - return dev; -} -#endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */ - #ifdef CFG_CONSOLE_IS_IN_ENV /* Called after the relocation - use desired console functions */ int console_init_r (void) @@ -488,7 +474,10 @@ int console_init_r (void) int console_init_r (void) { device_t *inputdev = NULL, *outputdev = NULL; - int i, items = ListNumItems (devlist); + int i; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev;
#ifdef CONFIG_SPLASH_SCREEN /* suppress all output if splash screen is enabled and we have @@ -498,11 +487,8 @@ int console_init_r (void) #endif
/* Scan devices looking for input and output devices */ - for (i = 1; - (i <= items) && ((inputdev == NULL) || (outputdev == NULL)); - i++ - ) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list);
if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; @@ -510,6 +496,8 @@ int console_init_r (void) if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } + if(inputdev && outputdev) + break; }
/* Initializes output console first */ diff --git a/common/devices.c b/common/devices.c index 9cc963a..2977436 100644 --- a/common/devices.c +++ b/common/devices.c @@ -36,7 +36,7 @@
DECLARE_GLOBAL_DATA_PTR;
-list_t devlist = 0; +static device_t devs; device_t *stdio_devices[] = { NULL, NULL, NULL }; char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
@@ -48,18 +48,18 @@ char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; #ifdef CFG_DEVICE_NULLDEV void nulldev_putc(const char c) { - /* nulldev is empty! */ + /* nulldev is empty! */ }
void nulldev_puts(const char *s) { - /* nulldev is empty! */ + /* nulldev is empty! */ }
int nulldev_input(void) { - /* nulldev is empty! */ - return 0; + /* nulldev is empty! */ + return 0; } #endif
@@ -108,10 +108,32 @@ static void drv_system_init (void) * DEVICES ************************************************************************** */ +struct list_head* device_get_list(void) +{ + return &(devs.list); +} + +device_t* device_get_by_name(char* name) +{ + struct list_head *pos; + device_t *dev; + + if(!name) + return NULL; + + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); + if(strcmp(dev->name, name) == 0) + return dev; + } + + return NULL; +} +
int device_register (device_t * dev) { - ListInsertItem (devlist, dev, LIST_END); + list_add(&(dev->list), &(devs.list)); return 0; }
@@ -121,20 +143,15 @@ int device_register (device_t * dev) #ifdef CFG_DEVICE_DEREGISTER int device_deregister(char *devname) { - int i,l,dev_index; - device_t *dev = NULL; + int l; + struct list_head *pos; + device_t *dev; char temp_names[3][8];
- dev_index = -1; - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); - if(strcmp(dev->name,devname)==0) { - dev_index=i; - break; - } - } - if(dev_index<0) /* device not found */ - return 0; + dev = device_get_by_name(devname); + + if(!dev) /* device not found */ + return -1; /* get stdio devices (ListRemoveItem changes the dev list) */ for (l=0 ; l< MAX_FILES; l++) { if (stdio_devices[l] == dev) { @@ -145,14 +162,15 @@ int device_deregister(char *devname) stdio_devices[l]->name, sizeof(stdio_devices[l]->name)); } - ListRemoveItem(devlist,NULL,dev_index); + + list_del(&(dev->list)); + /* reassign Device list */ - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); for (l=0 ; l< MAX_FILES; l++) { - if(strcmp(dev->name,temp_names[l])==0) { + if(strcmp(dev->name, temp_names[l]) == 0) stdio_devices[l] = dev; - } } } return 0; @@ -161,7 +179,7 @@ int device_deregister(char *devname)
int devices_init (void) { -#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ +#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ ulong relocation_offset = gd->reloc_off; int i;
@@ -173,12 +191,8 @@ int devices_init (void) #endif
/* Initialize the list */ - devlist = ListCreate (sizeof (device_t)); + INIT_LIST_HEAD(&(devs.list));
- if (devlist == NULL) { - eputs ("Cannot initialize the list of devices!\n"); - return -1; - } #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); #endif @@ -207,10 +221,3 @@ int devices_init (void)
return (0); } - -int devices_done (void) -{ - ListDispose (devlist); - - return 0; -} diff --git a/common/lists.c b/common/lists.c deleted file mode 100644 index 0dc090a..0000000 --- a/common/lists.c +++ /dev/null @@ -1,734 +0,0 @@ -#include <common.h> -#include <malloc.h> -#include <lists.h> - -#define MAX(a,b) (((a)>(b)) ? (a) : (b)) -#define MIN(a,b) (((a)<(b)) ? (a) : (b)) -#define CAT4CHARS(a,b,c,d) ((a<<24) | (b<<16) | (c<<8) | d) - -/* increase list size by 10% every time it is full */ -#define kDefaultAllocationPercentIncrease 10 - -/* always increase list size by 4 items when it is full */ -#define kDefaultAllocationminNumItemsIncrease 4 - -/* - * how many items to expand the list by when it becomes full - * = current listSize (in items) + (hiword percent of list size) + loword - */ -#define NUMITEMSPERALLOC(list) MAX(((*list)->listSize * \ - ((*list)->percentIncrease + 100)) / 100, \ - (*list)->minNumItemsIncrease ) - -#define ITEMPTR(list,item) &(((char *)&(*list)->itemList)[(*(list))->itemSize * (item)]) - -#define LIST_SIGNATURE CAT4CHARS('L', 'I', 'S', 'T'); - -#define calloc(size,num) malloc(size*num) - -/********************************************************************/ - -Handle NewHandle (unsigned int numBytes) -{ - void *memPtr; - HandleRecord *hanPtr; - - memPtr = calloc (numBytes, 1); - hanPtr = (HandleRecord *) calloc (sizeof (HandleRecord), 1); - if (hanPtr && (memPtr || numBytes == 0)) { - hanPtr->ptr = memPtr; - hanPtr->size = numBytes; - return (Handle) hanPtr; - } else { - free (memPtr); - free (hanPtr); - return NULL; - } -} -/********************************************************************/ - -void DisposeHandle (Handle handle) -{ - if (handle) { - free (*handle); - free ((void *) handle); - } -} -/********************************************************************/ - -unsigned int GetHandleSize (Handle handle) -{ - return ((HandleRecord *) handle)->size; -} -/********************************************************************/ - -int SetHandleSize (Handle handle, unsigned int newSize) -{ - HandleRecord *hanRecPtr = (HandleRecord *) handle; - void *newPtr, *oldPtr; - unsigned int oldSize; - - - oldPtr = hanRecPtr->ptr; - oldSize = hanRecPtr->size; - - if (oldSize == newSize) - return 1; - - if (oldPtr == NULL) { - newPtr = malloc (newSize); - } else { - newPtr = realloc (oldPtr, newSize); - } - if (newPtr || (newSize == 0)) { - hanRecPtr->ptr = newPtr; - hanRecPtr->size = newSize; - if (newSize > oldSize) - memset ((char *) newPtr + oldSize, 0, newSize - oldSize); - return 1; - } else - return 0; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* Used to compare list elements by their raw data contents */ -static int ListMemBlockCmp (void *a, void *b, int size) -{ - return memcmp (a, b, size); -} - -/***************************************************************************/ - -/* - * Binary search numElements of size elementSize in array for a match - * to the. item. Return the index of the element that matches - * (0 - numElements - 1). If no match is found return the -i-1 where - * i is the index (0 - numElements) where the item should be placed. - * (*theCmp)(a,b) should return <0 if a<b, 0 if a==b, >0 if a>b. - * - * This function is like the C-Library function bsearch() except that - * this function returns the index where the item should be placed if - * it is not found. - */ -int BinSearch ( void *array, int numElements, int elementSize, - void *itemPtr, CompareFunction compareFunction) -{ - int low, high, mid, cmp; - void *arrayItemPtr; - - for (low = 0, high = numElements - 1, mid = 0, cmp = -1; low <= high;) { - mid = (low + high) >> 1; - - arrayItemPtr = (void *) (((char *) array) + (mid * elementSize)); - cmp = compareFunction - ? compareFunction (itemPtr, arrayItemPtr) - : ListMemBlockCmp (itemPtr, arrayItemPtr, elementSize); - if (cmp == 0) { - return mid; - } else if (cmp < 0) { - high = mid - 1; - } else { - low = mid + 1; - } - } - if (cmp > 0) - mid++; - - return -mid - 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************************************************************/ - -/* - * If numNewItems == 0 then expand the list by the number of items - * indicated by its allocation policy. - * If numNewItems > 0 then expand the list by exactly the number of - * items indicated. - * If numNewItems < 0 then expand the list by the absolute value of - * numNewItems plus the number of items indicated by its allocation - * policy. - * Returns 1 for success, 0 if out of memory -*/ -static int ExpandListSpace (list_t list, int numNewItems) -{ - if (numNewItems == 0) { - numNewItems = NUMITEMSPERALLOC (list); - } else if (numNewItems < 0) { - numNewItems = (-numNewItems) + NUMITEMSPERALLOC (list); - } - - if (SetHandleSize ((Handle) list, - sizeof (ListStruct) + - ((*list)->listSize + - numNewItems) * (*list)->itemSize)) { - (*list)->listSize += numNewItems; - return 1; - } else { - return 0; - } -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* - * This function reallocate the list, minus any currently unused - * portion of its allotted memory. - */ -void ListCompact (list_t list) -{ - - if (!SetHandleSize ((Handle) list, - sizeof (ListStruct) + - (*list)->numItems * (*list)->itemSize)) { - return; - } - - (*list)->listSize = (*list)->numItems; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -list_t ListCreate (int elementSize) -{ - list_t list; - - list = (list_t) (NewHandle (sizeof (ListStruct))); /* create empty list */ - if (list) { - (*list)->signature = LIST_SIGNATURE; - (*list)->numItems = 0; - (*list)->listSize = 0; - (*list)->itemSize = elementSize; - (*list)->percentIncrease = kDefaultAllocationPercentIncrease; - (*list)->minNumItemsIncrease = - kDefaultAllocationminNumItemsIncrease; - } - - return list; -} - -/*******************************/ - -void ListSetAllocationPolicy (list_t list, int minItemsPerAlloc, - int percentIncreasePerAlloc) -{ - (*list)->percentIncrease = percentIncreasePerAlloc; - (*list)->minNumItemsIncrease = minItemsPerAlloc; -} - -/*******************************/ - -void ListDispose (list_t list) -{ - DisposeHandle ((Handle) list); -} -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListDisposePtrList (list_t list) -{ - int index; - int numItems; - - if (list) { - numItems = ListNumItems (list); - - for (index = 1; index <= numItems; index++) - free (*(void **) ListGetPtrToItem (list, index)); - - ListDispose (list); - } -} - -/*******************************/ - -/* - * keeps memory, resets the number of items to 0 - */ -void ListClear (list_t list) -{ - if (!list) - return; - (*list)->numItems = 0; -} - -/*******************************/ - -/* - * copy is only as large as necessary - */ -list_t ListCopy (list_t originalList) -{ - list_t tempList = NULL; - int numItems; - - if (!originalList) - return NULL; - - tempList = ListCreate ((*originalList)->itemSize); - if (tempList) { - numItems = ListNumItems (originalList); - - if (!SetHandleSize ((Handle) tempList, - sizeof (ListStruct) + - numItems * (*tempList)->itemSize)) { - ListDispose (tempList); - return NULL; - } - - (*tempList)->numItems = (*originalList)->numItems; - (*tempList)->listSize = (*originalList)->numItems; - (*tempList)->itemSize = (*originalList)->itemSize; - (*tempList)->percentIncrease = (*originalList)->percentIncrease; - (*tempList)->minNumItemsIncrease = - (*originalList)->minNumItemsIncrease; - - memcpy (ITEMPTR (tempList, 0), ITEMPTR (originalList, 0), - numItems * (*tempList)->itemSize); - } - - return tempList; -} - -/********************************/ - -/* - * list1 = list1 + list2 - */ -int ListAppend (list_t list1, list_t list2) -{ - int numItemsL1, numItemsL2; - - if (!list2) - return 1; - - if (!list1) - return 0; - if ((*list1)->itemSize != (*list2)->itemSize) - return 0; - - numItemsL1 = ListNumItems (list1); - numItemsL2 = ListNumItems (list2); - - if (numItemsL2 == 0) - return 1; - - if (!SetHandleSize ((Handle) list1, - sizeof (ListStruct) + (numItemsL1 + numItemsL2) * - (*list1)->itemSize)) { - return 0; - } - - (*list1)->numItems = numItemsL1 + numItemsL2; - (*list1)->listSize = numItemsL1 + numItemsL2; - - memmove (ITEMPTR (list1, numItemsL1), - ITEMPTR (list2, 0), - numItemsL2 * (*list2)->itemSize); - - return 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -/* - * returns 1 if the item is inserted, returns 0 if out of memory or - * bad arguments were passed. - */ -int ListInsertItem (list_t list, void *ptrToItem, int itemPosition) -{ - return ListInsertItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -int ListInsertItems (list_t list, void *ptrToItems, int firstItemPosition, - int numItemsToInsert) -{ - int numItems = (*list)->numItems; - - if (firstItemPosition == numItems + 1) - firstItemPosition = LIST_END; - else if (firstItemPosition > numItems) - return 0; - - if ((*list)->numItems >= (*list)->listSize) { - if (!ExpandListSpace (list, -numItemsToInsert)) - return 0; - } - - if (firstItemPosition == LIST_START) { - if (numItems == 0) { - /* special case for empty list */ - firstItemPosition = LIST_END; - } else { - firstItemPosition = 1; - } - } - - if (firstItemPosition == LIST_END) { /* add at the end of the list */ - if (ptrToItems) - memcpy (ITEMPTR (list, numItems), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, numItems), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } else { /* move part of list up to make room for new item */ - memmove (ITEMPTR (list, firstItemPosition - 1 + numItemsToInsert), - ITEMPTR (list, firstItemPosition - 1), - (numItems + 1 - firstItemPosition) * (*list)->itemSize); - - if (ptrToItems) - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, firstItemPosition - 1), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } - - return 1; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/*******************************/ - -int ListEqual (list_t list1, list_t list2) -{ - if (list1 == list2) - return 1; - - if (list1 == NULL || list2 == NULL) - return 0; - - if ((*list1)->itemSize == (*list1)->itemSize) { - if ((*list1)->numItems == (*list2)->numItems) { - return (memcmp (ITEMPTR (list1, 0), ITEMPTR (list2, 0), - (*list1)->itemSize * (*list1)->numItems) == 0); - } - } - - return 0; -} - -/*******************************/ - -/* - * The item pointed to by ptrToItem is copied over the current item - * at itemPosition - */ -void ListReplaceItem (list_t list, void *ptrToItem, int itemPosition) -{ - ListReplaceItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -/* - * The item pointed to by ptrToItems is copied over the current item - * at itemPosition - */ -void ListReplaceItems ( list_t list, void *ptrToItems, - int firstItemPosition, int numItemsToReplace) -{ - - if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - else if (firstItemPosition == LIST_START) - firstItemPosition = 1; - - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToReplace); -} - -/*******************************/ - -void ListGetItem (list_t list, void *itemDestination, int itemPosition) -{ - ListGetItems (list, itemDestination, itemPosition, 1); -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -#if defined(CFG_ALL_LIST_FUNCTIONS) || defined(CFG_DEVICE_DEREGISTER) - -void ListRemoveItem (list_t list, void *itemDestination, int itemPosition) -{ - ListRemoveItems (list, itemDestination, itemPosition, 1); -} - -/*******************************/ - -void ListRemoveItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToRemove) -{ - int firstItemAfterChunk, numToMove; - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - if (itemsDestination != NULL) - memcpy (itemsDestination, ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToRemove); - - firstItemAfterChunk = firstItemPosition + numItemsToRemove; - numToMove = (*list)->numItems - (firstItemAfterChunk - 1); - - if (numToMove > 0) { - /* - * move part of list down to cover hole left by removed item - */ - memmove (ITEMPTR (list, firstItemPosition - 1), - ITEMPTR (list, firstItemAfterChunk - 1), - (*list)->itemSize * numToMove); - } - - (*list)->numItems -= numItemsToRemove; -} -#endif /* CFG_ALL_LIST_FUNCTIONS || CFG_DEVICE_DEREGISTER */ - -/*******************************/ - -void ListGetItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToGet) -{ - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - memcpy (itemsDestination, - ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToGet); -} - -/*******************************/ - -/* - * Returns a pointer to the item at itemPosition. returns null if an - * errors occurred. - */ -void *ListGetPtrToItem (list_t list, int itemPosition) -{ - if (itemPosition == LIST_START) - itemPosition = 1; - else if (itemPosition == LIST_END) - itemPosition = (*list)->numItems; - - return ITEMPTR (list, itemPosition - 1); -} - -/*******************************/ - -/* - * returns a pointer the lists data (abstraction violation for - * optimization) - */ -void *ListGetDataPtr (list_t list) -{ - return &((*list)->itemList[0]); -} - -/********************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -int ListApplyToEach (list_t list, int ascending, - ListApplicationFunc funcToApply, - void *callbackData) -{ - int result = 0, index; - - if (!list || !funcToApply) - goto Error; - - if (ascending) { - for (index = 1; index <= ListNumItems (list); index++) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } else { - for (index = ListNumItems (list); - index > 0 && index <= ListNumItems (list); - index--) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } - -Error: - return result; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/********************************/ - -int ListGetItemSize (list_t list) -{ - return (*list)->itemSize; -} - -/********************************/ - -int ListNumItems (list_t list) -{ - return (*list)->numItems; -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListRemoveDuplicates (list_t list, CompareFunction compareFunction) -{ - int numItems, index, startIndexForFind, duplicatesIndex; - - numItems = ListNumItems (list); - - for (index = 1; index < numItems; index++) { - startIndexForFind = index + 1; - while (startIndexForFind <= numItems) { - duplicatesIndex = - ListFindItem (list, - ListGetPtrToItem (list, index), - startIndexForFind, - compareFunction); - if (duplicatesIndex > 0) { - ListRemoveItem (list, NULL, duplicatesIndex); - numItems--; - startIndexForFind = duplicatesIndex; - } else { - break; - } - } - } -} - -/*******************************/ - - -/*******************************/ - -int ListFindItem (list_t list, void *ptrToItem, int startingPosition, - CompareFunction compareFunction) -{ - int numItems, size, index, cmp; - void *listItemPtr; - - if ((numItems = (*list)->numItems) == 0) - return 0; - - size = (*list)->itemSize; - - if (startingPosition == LIST_START) - startingPosition = 1; - else if (startingPosition == LIST_END) - startingPosition = numItems; - - for (index = startingPosition; index <= numItems; index++) { - listItemPtr = ITEMPTR (list, index - 1); - cmp = compareFunction - ? compareFunction (ptrToItem, listItemPtr) - : ListMemBlockCmp (ptrToItem, listItemPtr, size); - if (cmp == 0) - return index; - } - - return 0; -} - -/*******************************/ - -int ShortCompare (void *a, void *b) -{ - if (*(short *) a < *(short *) b) - return -1; - if (*(short *) a > *(short *) b) - return 1; - return 0; -} - -/*******************************/ - -int IntCompare (void *a, void *b) -{ - if (*(int *) a < *(int *) b) - return -1; - if (*(int *) a > *(int *) b) - return 1; - return 0; -} - -/*******************************/ - -int CStringCompare (void *a, void *b) -{ - return strcmp (*(char **) a, *(char **) b); -} - -/*******************************/ - - -int ListBinSearch (list_t list, void *ptrToItem, - CompareFunction compareFunction) -{ - int index; - - index = BinSearch (ITEMPTR (list, 0), - (int) (*list)->numItems, - (int) (*list)->itemSize, ptrToItem, - compareFunction); - - if (index >= 0) - index++; /* lists start from 1 */ - else - index = 0; /* item not found */ - - return index; -} - -/**************************************************************************/ - -/* - * Reserves memory for numItems in the list. If it succeeds then - * numItems items can be inserted without possibility of an out of - * memory error (useful to simplify error recovery in complex - * functions). Returns 1 if success, 0 if out of memory. - */ -int ListPreAllocate (list_t list, int numItems) -{ - if ((*list)->listSize - (*list)->numItems < numItems) { - return ExpandListSpace (list, - numItems - ((*list)->listSize - - (*list)->numItems)); - } else { - return 1; /* enough items are already pre-allocated */ - } -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 04d9730..108bd60 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -152,7 +152,7 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum); /* search for keyboard and register it if found */ int drv_usb_kbd_init(void) { - int error,i,index; + int error,i; device_t usb_kbd_dev,*old_dev; struct usb_device *dev; char *stdinname = getenv ("stdin"); @@ -166,13 +166,11 @@ int drv_usb_kbd_init(void) if(usb_kbd_probe(dev,0)==1) { /* Ok, we found a keyboard */ /* check, if it is already registered */ USB_KBD_PRINTF("USB KBD found set up device.\n"); - for (index=1; index<=ListNumItems(devlist); index++) { - old_dev = ListGetPtrToItem(devlist, index); - if(strcmp(old_dev->name,DEVNAME)==0) { - /* ok, already registered, just return ok */ - USB_KBD_PRINTF("USB KBD is already registered.\n"); - return 1; - } + old_dev = device_get_by_name(DEVNAME); + if(old_dev) { + /* ok, already registered, just return ok */ + USB_KBD_PRINTF("USB KBD is already registered.\n"); + return 1; } /* register the keyboard */ USB_KBD_PRINTF("USB KBD register.\n"); diff --git a/include/devices.h b/include/devices.h index 2d9e282..490016b 100644 --- a/include/devices.h +++ b/include/devices.h @@ -21,7 +21,7 @@ * MA 02111-1307 USA */
-#include <lists.h> +#include <linux/list.h>
#ifndef _DEVICES_H_ #define _DEVICES_H_ @@ -59,6 +59,7 @@ typedef struct { /* Other functions */
void *priv; /* Private extensions */ + struct list_head list; } device_t;
/* @@ -82,7 +83,6 @@ typedef struct { /* * VARIABLES */ -extern list_t devlist; extern device_t *stdio_devices[]; extern char *stdio_names[MAX_FILES];
@@ -91,8 +91,10 @@ extern char *stdio_names[MAX_FILES]; */ int device_register (device_t * dev); int devices_init (void); -int devices_done (void); int device_deregister(char *devname); +struct list_head* device_get_list(void); +device_t* device_get_by_name(char* name); + #ifdef CONFIG_LCD int drv_lcd_init (void); #endif diff --git a/include/linux/poison.h b/include/linux/poison.h index ba7ff84..b3d873b 100644 --- a/include/linux/poison.h +++ b/include/linux/poison.h @@ -3,11 +3,9 @@
/********** include/linux/list.h **********/ /* - * These are non-NULL pointers that will result in page faults - * under normal circumstances, used to verify that nobody uses - * non-initialized list entries. + * used to verify that nobody uses non-initialized list entries. */ -#define LIST_POISON1 ((void *) 0x00100100) -#define LIST_POISON2 ((void *) 0x00200200) +#define LIST_POISON1 ((void *) 0x0) +#define LIST_POISON2 ((void *) 0x0)
#endif diff --git a/include/lists.h b/include/lists.h deleted file mode 100644 index 10a2a19..0000000 --- a/include/lists.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef _LISTS_H_ -#define _LISTS_H_ - -#define LIST_START -1 /* Handy Constants that substitute for item positions */ -#define LIST_END 0 /* END_OF_LIST means one past current length of list when */ - /* inserting. Otherwise it refers the last item in the list. */ - -typedef struct - { - void *ptr; - unsigned int size; - } HandleRecord; - -typedef void **Handle; - -typedef int (*CompareFunction)(void *data1, void *data2) ; - -typedef struct ListStructTag - { - int signature; /* debugging aid */ - int percentIncrease; /* %of current size to increase by when list is out of space */ - int minNumItemsIncrease; /* fixed number of items to increase by when list is out of space */ - int listSize; /* number of items than can fit in the currently allocated memory */ - int itemSize; /* the size of each item in the list (same for every item) */ - int numItems; /* number of items currently in the list */ - unsigned char itemList[1]; /* resizable array of list elements */ - } ListStruct; - -typedef struct ListStructTag **list_t; /* The list abstract data type */ -typedef int ( * ListApplicationFunc)(int index, void *ptrToItem, void *callbackData); - -/* Basic List Operations */ -list_t ListCreate(int elementSize); -int ListNumItems(list_t list); -int ListInsertItem(list_t list, void *ptrToItem, int itemPosition); -int ListInsertItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToInsert); -void ListDispose(list_t list); -void *ListGetPtrToItem(list_t list, int itemPosition); -void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); -void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); - -#if 0 /* rarely ever used; kept here for reference just in case ... */ -void ListDisposePtrList(list_t list); -void ListGetItem(list_t list, void *itemDestination, int itemPosition); -void ListReplaceItem(list_t list, void *ptrToItem, int itemPosition); -void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); -void ListGetItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToGet); -void ListReplaceItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToReplace); -void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); -list_t ListCopy(list_t originalList); -int ListAppend(list_t list1, list_t list2); -void ListClear(list_t list); -int ListEqual(list_t list1, list_t list2); -int ListInsertInOrder(list_t list, void *ptrToItem, CompareFunction compareFunction); -void *ListGetDataPtr(list_t list); -int ListApplyToEach(list_t list, int ascending, ListApplicationFunc funcToApply, void *callbackData); - -/* List Searching and Sorting */ -int ListFindItem(list_t list, void *ptrToItem, int startingPosition, CompareFunction compareFunction); -void ListRemoveDuplicates(list_t list, CompareFunction compareFunction); -int ListBinSearch(list_t list, void *itemPtr, CompareFunction compareFunction); -void ListQuickSort(list_t list, CompareFunction compareFunction); -void ListHeapSort(list_t list, CompareFunction compareFunction); -void ListInsertionSort(list_t list, CompareFunction compareFunction); -int ListIsSorted(list_t list, CompareFunction compareFunction); - -/* Advanced List Functions */ -void ListSetAllocationPolicy(list_t list, int minItemsPerAlloc, int percentIncreasePerAlloc); -void ListCompact(list_t list); -int ListPreAllocate(list_t list, int numItems); -int ListGetItemSize(list_t list); -int GetIntListFromParmInfo(va_list parmInfo, int numIntegers, list_t *integerList); -int ListInsertAfterItem(list_t list, void *ptrToItem, void *ptrToItemToInsertAfter, CompareFunction compareFunction); -int ListInsertBeforeItem(list_t list, void *ptrToItem, void *ptrToItemToInsertBefore, CompareFunction compareFunction); -#endif /* 0 */ - -#endif /* _LISTS_H_ */

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- fs/Makefile | 10 +++++++++- fs/cramfs/Makefile | 7 ++++--- fs/cramfs/cramfs.c | 5 ----- fs/cramfs/uncompress.c | 4 ---- fs/ext2/Makefile | 6 +++--- fs/ext2/dev.c | 3 --- fs/ext2/ext2fs.c | 4 ---- fs/fat/Makefile | 6 +++--- fs/fat/fat.c | 4 ---- fs/fat/file.c | 4 ---- fs/fdos/Makefile | 6 +++--- fs/fdos/dev.c | 5 ----- fs/fdos/fat.c | 4 ---- fs/fdos/fdos.c | 5 +---- fs/fdos/fs.c | 4 ---- fs/fdos/subdir.c | 3 --- fs/fdos/vfat.c | 5 ----- fs/jffs2/Makefile | 8 +++++--- fs/jffs2/compr_lzari.c | 3 --- fs/jffs2/compr_lzo.c | 4 ---- fs/jffs2/compr_rtime.c | 4 ---- fs/jffs2/compr_rubin.c | 4 ---- fs/jffs2/compr_zlib.c | 4 ---- fs/jffs2/jffs2_1pass.c | 5 ----- fs/jffs2/jffs2_nand_1pass.c | 2 +- fs/jffs2/mini_inflate.c | 5 ----- fs/reiserfs/Makefile | 6 +++--- fs/reiserfs/dev.c | 4 ---- fs/reiserfs/mode_string.c | 3 --- fs/reiserfs/reiserfs.c | 4 ---- 30 files changed, 32 insertions(+), 109 deletions(-)
diff --git a/fs/Makefile b/fs/Makefile index 95ac0e9..8bbd563 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -22,7 +22,15 @@ # #
-SUBDIRS := jffs2 cramfs fdos fat reiserfs ext2 yaffs2 +subdirs-$(CONFIG_CMD_CRAMFS) := cramfs +subdirs-$(CONFIG_CMD_EXT2) += ext2 +subdirs-$(CONFIG_CMD_FAT) += fat +subdirs-$(CONFIG_CMD_FDOS) += fdos +subdirs-$(CONFIG_CMD_JFFS2) += jffs2 +subdirs-$(CONFIG_CMD_REISER) += reiserfs +subdirs-$(CONFIG_YAFFS2) += yaffs2 + +SUBDIRS := $(subdirs-y)
$(obj).depend all: @for dir in $(SUBDIRS) ; do \ diff --git a/fs/cramfs/Makefile b/fs/cramfs/Makefile index 13c043f..7b6cc0a 100644 --- a/fs/cramfs/Makefile +++ b/fs/cramfs/Makefile @@ -26,10 +26,11 @@ include $(TOPDIR)/config.mk LIB = $(obj)libcramfs.a
AOBJS = -COBJS = cramfs.o uncompress.o +COBJS-$(CONFIG_CMD_CRAMFS) := cramfs.o +COBJS-$(CONFIG_CMD_CRAMFS) += uncompress.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c index e53c783..2956d39 100644 --- a/fs/cramfs/cramfs.c +++ b/fs/cramfs/cramfs.c @@ -26,9 +26,6 @@
#include <common.h> #include <malloc.h> - -#if defined(CONFIG_CMD_CRAMFS) - #include <asm/byteorder.h> #include <linux/stat.h> #include <jffs2/jffs2.h> @@ -343,5 +340,3 @@ int cramfs_check (struct part_info *info) } return 1; } - -#endif /* CFG_FS_CRAMFS */ diff --git a/fs/cramfs/uncompress.c b/fs/cramfs/uncompress.c index cf67967..39dd275 100644 --- a/fs/cramfs/uncompress.c +++ b/fs/cramfs/uncompress.c @@ -25,8 +25,6 @@ #include <watchdog.h> #include <zlib.h>
-#if defined(CONFIG_CMD_CRAMFS) - static z_stream stream;
void *zalloc(void *, unsigned, unsigned); @@ -86,5 +84,3 @@ int cramfs_uncompress_exit (void) inflateEnd (&stream); return 0; } - -#endif /* CFG_FS_CRAMFS */ diff --git a/fs/ext2/Makefile b/fs/ext2/Makefile index 8313cdc..712e348 100644 --- a/fs/ext2/Makefile +++ b/fs/ext2/Makefile @@ -30,10 +30,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libext2fs.a
AOBJS = -COBJS = ext2fs.o dev.o +COBJS-$(CONFIG_CMD_EXT2) := ext2fs.o dev.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/ext2/dev.c b/fs/ext2/dev.c index 1728b34..3b49650 100644 --- a/fs/ext2/dev.c +++ b/fs/ext2/dev.c @@ -25,8 +25,6 @@
#include <common.h> -#if defined(CONFIG_CMD_EXT2) - #include <config.h> #include <ext2fs.h>
@@ -139,4 +137,3 @@ int ext2fs_devread (int sector, int byte_offset, int byte_len, char *buf) { } return (1); } -#endif diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c index 7833551..436f4a4 100644 --- a/fs/ext2/ext2fs.c +++ b/fs/ext2/ext2fs.c @@ -24,8 +24,6 @@ */
#include <common.h> - -#if defined(CONFIG_CMD_EXT2) #include <ext2fs.h> #include <malloc.h> #include <asm/byteorder.h> @@ -874,5 +872,3 @@ fail: ext2fs_root = NULL; return (0); } - -#endif diff --git a/fs/fat/Makefile b/fs/fat/Makefile index 87af73b..b711460 100644 --- a/fs/fat/Makefile +++ b/fs/fat/Makefile @@ -24,10 +24,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libfat.a
AOBJS = -COBJS = fat.o file.o +COBJS-$(CONFIG_CMD_FAT) := fat.o file.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
all: $(LIB) $(AOBJS)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 49c78ed..2f0bd8c 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -31,8 +31,6 @@ #include <asm/byteorder.h> #include <part.h>
-#if defined(CONFIG_CMD_FAT) - /* * Convert a string to lowercase. */ @@ -1024,5 +1022,3 @@ file_fat_read(const char *filename, void *buffer, unsigned long maxsize) printf("reading %s\n",filename); return do_fat_read(filename, buffer, maxsize, LS_NO); } - -#endif diff --git a/fs/fat/file.c b/fs/fat/file.c index 514dbae..e870734 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -32,8 +32,6 @@ #include <linux/stat.h> #include <linux/time.h>
-#if defined(CONFIG_CMD_FAT) - /* Supported filesystems */ static const struct filesystem filesystems[] = { { file_fat_detectfs, file_fat_ls, file_fat_read, "FAT" }, @@ -204,5 +202,3 @@ file_read(const char *filename, void *buffer, unsigned long maxsize)
return filesystems[current_filesystem].read(arg, buffer, maxsize); } - -#endif diff --git a/fs/fdos/Makefile b/fs/fdos/Makefile index 2dba0fb..fce2032 100644 --- a/fs/fdos/Makefile +++ b/fs/fdos/Makefile @@ -31,10 +31,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libfdos.a
AOBJS = -COBJS = fat.o vfat.o dev.o fdos.o fs.o subdir.o +COBJS-$(CONFIG_CMD_FDOS) := fat.o vfat.o dev.o fdos.o fs.o subdir.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/fdos/dev.c b/fs/fdos/dev.c index 271d0e7..b55b6ed 100644 --- a/fs/fdos/dev.c +++ b/fs/fdos/dev.c @@ -28,8 +28,6 @@ #include "dos.h" #include "fdos.h"
-#if defined(CONFIG_CMD_FDOS) - #define NB_HEADS 2 #define NB_TRACKS 80 #define NB_SECTORS 18 @@ -190,6 +188,3 @@ int check_dev (BootSector_t *boot, Fs_t *fs)
return (0); } - - -#endif diff --git a/fs/fdos/fat.c b/fs/fdos/fat.c index 2e2d2b8..5707c19 100644 --- a/fs/fdos/fat.c +++ b/fs/fdos/fat.c @@ -26,8 +26,6 @@ #include <config.h> #include <malloc.h>
-#if defined(CONFIG_CMD_FDOS) - #include "dos.h" #include "fdos.h"
@@ -138,5 +136,3 @@ int read_fat (BootSector_t *boot, Fs_t *fs) } return (0); } - -#endif diff --git a/fs/fdos/fdos.c b/fs/fdos/fdos.c index 5be6a96..db58562 100644 --- a/fs/fdos/fdos.c +++ b/fs/fdos/fdos.c @@ -24,9 +24,8 @@
#include <common.h> #include <config.h> - -#if defined(CONFIG_CMD_FDOS) #include <malloc.h> + #include "dos.h" #include "fdos.h"
@@ -171,5 +170,3 @@ int dos_dir (void) free (name); return (0); } - -#endif diff --git a/fs/fdos/fs.c b/fs/fdos/fs.c index aded670..5acf123 100644 --- a/fs/fdos/fs.c +++ b/fs/fdos/fs.c @@ -26,8 +26,6 @@ #include <config.h> #include <malloc.h>
-#if defined(CONFIG_CMD_FDOS) - #include "dos.h" #include "fdos.h"
@@ -114,5 +112,3 @@ int fs_init (Fs_t *fs) free (boot); return (0); } - -#endif diff --git a/fs/fdos/subdir.c b/fs/fdos/subdir.c index 497f554..5e96b0a 100644 --- a/fs/fdos/subdir.c +++ b/fs/fdos/subdir.c @@ -26,8 +26,6 @@ #include <config.h> #include <malloc.h>
-#if defined(CONFIG_CMD_FDOS) - #include "dos.h" #include "fdos.h"
@@ -345,4 +343,3 @@ int read_file (Fs_t *fs, } return (read); } -#endif diff --git a/fs/fdos/vfat.c b/fs/fdos/vfat.c index 0e7883b..9f357a6 100644 --- a/fs/fdos/vfat.c +++ b/fs/fdos/vfat.c @@ -24,8 +24,6 @@
#include <common.h> #include <config.h> - -#if defined(CONFIG_CMD_FDOS) #include <linux/ctype.h>
#include "dos.h" @@ -352,6 +350,3 @@ static char *conv_name (char *name, char *ext, char Case, char *ans) } return (ans); } - - -#endif diff --git a/fs/jffs2/Makefile b/fs/jffs2/Makefile index a071af1..fd6a105 100644 --- a/fs/jffs2/Makefile +++ b/fs/jffs2/Makefile @@ -26,13 +26,15 @@ include $(TOPDIR)/config.mk LIB = $(obj)libjffs2.a
AOBJS = -COBJS-y += jffs2_1pass.o +ifdef CONFIG_CMD_JFFS2 +COBJS-$(CONFIG_JFFS2_LZO_LZARI) += compr_lzari.o +COBJS-$(CONFIG_JFFS2_LZO_LZARI) += compr_lzo.o COBJS-y += compr_rtime.o COBJS-y += compr_rubin.o COBJS-y += compr_zlib.o +COBJS-y += jffs2_1pass.o COBJS-y += mini_inflate.o -COBJS-y += compr_lzo.o -COBJS-y += compr_lzari.o +endif
COBJS := $(COBJS-y) SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/fs/jffs2/compr_lzari.c b/fs/jffs2/compr_lzari.c index f64bc74..6a29608 100644 --- a/fs/jffs2/compr_lzari.c +++ b/fs/jffs2/compr_lzari.c @@ -50,8 +50,6 @@ All rights reserved. Permission granted for non-commercial use.
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_LZO_LZARI) - #include <linux/stddef.h> #include <jffs2/jffs2.h>
@@ -259,4 +257,3 @@ int lzari_decompress(unsigned char *data_in, unsigned char *cpage_out, { return Decode(data_in, cpage_out, srclen, destlen); } -#endif diff --git a/fs/jffs2/compr_lzo.c b/fs/jffs2/compr_lzo.c index a32b993..e648ec4 100644 --- a/fs/jffs2/compr_lzo.c +++ b/fs/jffs2/compr_lzo.c @@ -67,8 +67,6 @@
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_LZO_LZARI) - #include <linux/stddef.h> #include <jffs2/jffs2.h> #include <jffs2/compr_rubin.h> @@ -401,5 +399,3 @@ int lzo_decompress(unsigned char *data_in, unsigned char *cpage_out, lzo_uint outlen = destlen; return lzo1x_decompress (data_in, srclen, cpage_out, &outlen, NULL); } - -#endif diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c index 144263c..89b9f2f 100644 --- a/fs/jffs2/compr_rtime.c +++ b/fs/jffs2/compr_rtime.c @@ -46,8 +46,6 @@ */
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h>
void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, @@ -87,5 +85,3 @@ void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, } } } - -#endif diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c index f6f3fa1..9ff2217 100644 --- a/fs/jffs2/compr_rubin.c +++ b/fs/jffs2/compr_rubin.c @@ -39,8 +39,6 @@ */
#include <config.h> -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h> #include <jffs2/compr_rubin.h>
@@ -122,5 +120,3 @@ void dynrubin_decompress(unsigned char *data_in, unsigned char *cpage_out,
rubin_do_decompress(bits, data_in+8, cpage_out, dstlen); } - -#endif diff --git a/fs/jffs2/compr_zlib.c b/fs/jffs2/compr_zlib.c index 29dfe1b..d306b6d 100644 --- a/fs/jffs2/compr_zlib.c +++ b/fs/jffs2/compr_zlib.c @@ -37,8 +37,6 @@
#include <common.h> #include <config.h> -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h> #include <jffs2/mini_inflate.h>
@@ -48,5 +46,3 @@ long zlib_decompress(unsigned char *data_in, unsigned char *cpage_out, return (decompress_block(cpage_out, data_in + 2, (void *) ldr_memcpy));
} - -#endif diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c index b5e7ab8..5d22dd7 100644 --- a/fs/jffs2/jffs2_1pass.c +++ b/fs/jffs2/jffs2_1pass.c @@ -117,9 +117,6 @@ #include <linux/stat.h> #include <linux/time.h> #include <watchdog.h> - -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/jffs2.h> #include <jffs2/jffs2_1pass.h>
@@ -1394,5 +1391,3 @@ jffs2_1pass_info(struct part_info * part) } return 1; } - -#endif diff --git a/fs/jffs2/jffs2_nand_1pass.c b/fs/jffs2/jffs2_nand_1pass.c index 9f6de7d..e288d5a 100644 --- a/fs/jffs2/jffs2_nand_1pass.c +++ b/fs/jffs2/jffs2_nand_1pass.c @@ -1,6 +1,6 @@ #include <common.h>
-#if !defined(CONFIG_NAND_LEGACY) && defined(CONFIG_CMD_JFFS2) +#if !defined(CONFIG_NAND_LEGACY)
#include <malloc.h> #include <linux/stat.h> diff --git a/fs/jffs2/mini_inflate.c b/fs/jffs2/mini_inflate.c index 4c50fc3..bd40a57 100644 --- a/fs/jffs2/mini_inflate.c +++ b/fs/jffs2/mini_inflate.c @@ -24,9 +24,6 @@ */
#include <config.h> - -#if defined(CONFIG_CMD_JFFS2) - #include <jffs2/mini_inflate.h>
/* The order that the code lengths in section 3.2.7 are in */ @@ -392,5 +389,3 @@ long decompress_block(unsigned char *dest, unsigned char *source, #endif return stream.error ? -stream.error : stream.decoded; } - -#endif diff --git a/fs/reiserfs/Makefile b/fs/reiserfs/Makefile index e8711a4..9cef8ee 100644 --- a/fs/reiserfs/Makefile +++ b/fs/reiserfs/Makefile @@ -30,10 +30,10 @@ include $(TOPDIR)/config.mk LIB = $(obj)libreiserfs.a
AOBJS = -COBJS = reiserfs.o dev.o mode_string.o +COBJS-$(CONFIG_CMD_REISER) := reiserfs.o dev.o mode_string.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) -OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) +SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) +OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
diff --git a/fs/reiserfs/dev.c b/fs/reiserfs/dev.c index 46dc414..1facfaf 100644 --- a/fs/reiserfs/dev.c +++ b/fs/reiserfs/dev.c @@ -19,8 +19,6 @@
#include <common.h> -#if defined(CONFIG_CMD_REISER) - #include <config.h> #include <reiserfs.h>
@@ -119,5 +117,3 @@ int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
return 1; } - -#endif diff --git a/fs/reiserfs/mode_string.c b/fs/reiserfs/mode_string.c index 3e57ee4..801263d 100644 --- a/fs/reiserfs/mode_string.c +++ b/fs/reiserfs/mode_string.c @@ -25,7 +25,6 @@
#include <common.h> -#if defined(CONFIG_CMD_REISER) #include <linux/stat.h>
#if ( S_ISUID != 04000 ) || ( S_ISGID != 02000 ) || ( S_ISVTX != 01000 ) \ @@ -137,5 +136,3 @@ const char *bb_mode_string(int mode) }
#endif - -#endif diff --git a/fs/reiserfs/reiserfs.c b/fs/reiserfs/reiserfs.c index aa96361..d84fb20 100644 --- a/fs/reiserfs/reiserfs.c +++ b/fs/reiserfs/reiserfs.c @@ -29,8 +29,6 @@ */
#include <common.h> -#if defined(CONFIG_CMD_REISER) - #include <malloc.h> #include <linux/ctype.h> #include <linux/time.h> @@ -982,5 +980,3 @@ reiserfs_open (char *filename) } return filemax; } - -#endif

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- common/Makefile | 1 - common/cmd_console.c | 9 +- common/cmd_terminal.c | 10 +- common/console.c | 62 ++--- common/devices.c | 79 +++--- common/lists.c | 734 ------------------------------------------------- common/usb_kbd.c | 14 +- include/devices.h | 8 +- include/lists.h | 77 ----- 9 files changed, 87 insertions(+), 907 deletions(-) delete mode 100644 common/lists.c delete mode 100644 include/lists.h
diff --git a/common/Makefile b/common/Makefile index 6365fae..0fe9c8b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -37,7 +37,6 @@ COBJS-y += dlmalloc.o COBJS-y += exports.o COBJS-y += hush.o COBJS-y += image.o -COBJS-y += lists.o COBJS-y += memsize.o COBJS-y += s_record.o COBJS-y += serial.o diff --git a/common/cmd_console.c b/common/cmd_console.c index 50ddb01..e2bc2a3 100644 --- a/common/cmd_console.c +++ b/common/cmd_console.c @@ -31,14 +31,17 @@ extern void _do_coninfo (void); int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; + int l; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev;
/* Scan for valid output and input devices */
puts ("List of available devices:\n");
- for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list);
printf ("%-8s %08x %c%c%c ", dev->name, diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c index 57943c1..67a2546 100644 --- a/common/cmd_terminal.c +++ b/common/cmd_terminal.c @@ -27,10 +27,10 @@ #include <common.h> #include <command.h> #include <devices.h> +#include <serial.h>
int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; int last_tilde = 0; device_t *dev = NULL;
@@ -38,13 +38,7 @@ int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) return -1;
/* Scan for selected output/input device */ - for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *tmp = ListGetPtrToItem (devlist, i); - if (!strcmp(tmp->name, argv[1])) { - dev = tmp; - break; - } - } + dev = device_get_by_name(argv[1]); if (!dev) return -1;
diff --git a/common/console.c b/common/console.c index 1b095b1..cfcaeb8 100644 --- a/common/console.c +++ b/common/console.c @@ -325,9 +325,22 @@ inline void dbg(const char *fmt, ...)
/** U-Boot INIT FUNCTIONS *************************************************/
+device_t *search_device (int flags, char *name) +{ + device_t *dev; + + dev = device_get_by_name(name); + + if(dev && (dev->flags & flags)) + return dev; + + return NULL; +} + int console_assign (int file, char *devname) { - int flag, i; + int flag; + device_t *dev;
/* Check for valid file */ switch (file) { @@ -344,16 +357,10 @@ int console_assign (int file, char *devname)
/* Check for valid device name */
- for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); - - if (strcmp (devname, dev->name) == 0) { - if (dev->flags & flag) - return console_setfile (file, dev); + dev = search_device(flag, devname);
- return -1; - } - } + if(dev) + return console_setfile (file, dev);
return -1; } @@ -371,27 +378,6 @@ int console_init_f (void) return (0); }
-#if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE) -/* search a device */ -device_t *search_device (int flags, char *name) -{ - int i, items; - device_t *dev = NULL; - - items = ListNumItems (devlist); - if (name == NULL) - return dev; - - for (i = 1; i <= items; i++) { - dev = ListGetPtrToItem (devlist, i); - if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) { - break; - } - } - return dev; -} -#endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */ - #ifdef CFG_CONSOLE_IS_IN_ENV /* Called after the relocation - use desired console functions */ int console_init_r (void) @@ -488,7 +474,10 @@ int console_init_r (void) int console_init_r (void) { device_t *inputdev = NULL, *outputdev = NULL; - int i, items = ListNumItems (devlist); + int i; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev;
#ifdef CONFIG_SPLASH_SCREEN /* suppress all output if splash screen is enabled and we have @@ -498,11 +487,8 @@ int console_init_r (void) #endif
/* Scan devices looking for input and output devices */ - for (i = 1; - (i <= items) && ((inputdev == NULL) || (outputdev == NULL)); - i++ - ) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list);
if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; @@ -510,6 +496,8 @@ int console_init_r (void) if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } + if(inputdev && outputdev) + break; }
/* Initializes output console first */ diff --git a/common/devices.c b/common/devices.c index 9cc963a..2977436 100644 --- a/common/devices.c +++ b/common/devices.c @@ -36,7 +36,7 @@
DECLARE_GLOBAL_DATA_PTR;
-list_t devlist = 0; +static device_t devs; device_t *stdio_devices[] = { NULL, NULL, NULL }; char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
@@ -48,18 +48,18 @@ char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; #ifdef CFG_DEVICE_NULLDEV void nulldev_putc(const char c) { - /* nulldev is empty! */ + /* nulldev is empty! */ }
void nulldev_puts(const char *s) { - /* nulldev is empty! */ + /* nulldev is empty! */ }
int nulldev_input(void) { - /* nulldev is empty! */ - return 0; + /* nulldev is empty! */ + return 0; } #endif
@@ -108,10 +108,32 @@ static void drv_system_init (void) * DEVICES ************************************************************************** */ +struct list_head* device_get_list(void) +{ + return &(devs.list); +} + +device_t* device_get_by_name(char* name) +{ + struct list_head *pos; + device_t *dev; + + if(!name) + return NULL; + + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); + if(strcmp(dev->name, name) == 0) + return dev; + } + + return NULL; +} +
int device_register (device_t * dev) { - ListInsertItem (devlist, dev, LIST_END); + list_add(&(dev->list), &(devs.list)); return 0; }
@@ -121,20 +143,15 @@ int device_register (device_t * dev) #ifdef CFG_DEVICE_DEREGISTER int device_deregister(char *devname) { - int i,l,dev_index; - device_t *dev = NULL; + int l; + struct list_head *pos; + device_t *dev; char temp_names[3][8];
- dev_index = -1; - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); - if(strcmp(dev->name,devname)==0) { - dev_index=i; - break; - } - } - if(dev_index<0) /* device not found */ - return 0; + dev = device_get_by_name(devname); + + if(!dev) /* device not found */ + return -1; /* get stdio devices (ListRemoveItem changes the dev list) */ for (l=0 ; l< MAX_FILES; l++) { if (stdio_devices[l] == dev) { @@ -145,14 +162,15 @@ int device_deregister(char *devname) stdio_devices[l]->name, sizeof(stdio_devices[l]->name)); } - ListRemoveItem(devlist,NULL,dev_index); + + list_del(&(dev->list)); + /* reassign Device list */ - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); for (l=0 ; l< MAX_FILES; l++) { - if(strcmp(dev->name,temp_names[l])==0) { + if(strcmp(dev->name, temp_names[l]) == 0) stdio_devices[l] = dev; - } } } return 0; @@ -161,7 +179,7 @@ int device_deregister(char *devname)
int devices_init (void) { -#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ +#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ ulong relocation_offset = gd->reloc_off; int i;
@@ -173,12 +191,8 @@ int devices_init (void) #endif
/* Initialize the list */ - devlist = ListCreate (sizeof (device_t)); + INIT_LIST_HEAD(&(devs.list));
- if (devlist == NULL) { - eputs ("Cannot initialize the list of devices!\n"); - return -1; - } #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); #endif @@ -207,10 +221,3 @@ int devices_init (void)
return (0); } - -int devices_done (void) -{ - ListDispose (devlist); - - return 0; -} diff --git a/common/lists.c b/common/lists.c deleted file mode 100644 index 0dc090a..0000000 --- a/common/lists.c +++ /dev/null @@ -1,734 +0,0 @@ -#include <common.h> -#include <malloc.h> -#include <lists.h> - -#define MAX(a,b) (((a)>(b)) ? (a) : (b)) -#define MIN(a,b) (((a)<(b)) ? (a) : (b)) -#define CAT4CHARS(a,b,c,d) ((a<<24) | (b<<16) | (c<<8) | d) - -/* increase list size by 10% every time it is full */ -#define kDefaultAllocationPercentIncrease 10 - -/* always increase list size by 4 items when it is full */ -#define kDefaultAllocationminNumItemsIncrease 4 - -/* - * how many items to expand the list by when it becomes full - * = current listSize (in items) + (hiword percent of list size) + loword - */ -#define NUMITEMSPERALLOC(list) MAX(((*list)->listSize * \ - ((*list)->percentIncrease + 100)) / 100, \ - (*list)->minNumItemsIncrease ) - -#define ITEMPTR(list,item) &(((char *)&(*list)->itemList)[(*(list))->itemSize * (item)]) - -#define LIST_SIGNATURE CAT4CHARS('L', 'I', 'S', 'T'); - -#define calloc(size,num) malloc(size*num) - -/********************************************************************/ - -Handle NewHandle (unsigned int numBytes) -{ - void *memPtr; - HandleRecord *hanPtr; - - memPtr = calloc (numBytes, 1); - hanPtr = (HandleRecord *) calloc (sizeof (HandleRecord), 1); - if (hanPtr && (memPtr || numBytes == 0)) { - hanPtr->ptr = memPtr; - hanPtr->size = numBytes; - return (Handle) hanPtr; - } else { - free (memPtr); - free (hanPtr); - return NULL; - } -} -/********************************************************************/ - -void DisposeHandle (Handle handle) -{ - if (handle) { - free (*handle); - free ((void *) handle); - } -} -/********************************************************************/ - -unsigned int GetHandleSize (Handle handle) -{ - return ((HandleRecord *) handle)->size; -} -/********************************************************************/ - -int SetHandleSize (Handle handle, unsigned int newSize) -{ - HandleRecord *hanRecPtr = (HandleRecord *) handle; - void *newPtr, *oldPtr; - unsigned int oldSize; - - - oldPtr = hanRecPtr->ptr; - oldSize = hanRecPtr->size; - - if (oldSize == newSize) - return 1; - - if (oldPtr == NULL) { - newPtr = malloc (newSize); - } else { - newPtr = realloc (oldPtr, newSize); - } - if (newPtr || (newSize == 0)) { - hanRecPtr->ptr = newPtr; - hanRecPtr->size = newSize; - if (newSize > oldSize) - memset ((char *) newPtr + oldSize, 0, newSize - oldSize); - return 1; - } else - return 0; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* Used to compare list elements by their raw data contents */ -static int ListMemBlockCmp (void *a, void *b, int size) -{ - return memcmp (a, b, size); -} - -/***************************************************************************/ - -/* - * Binary search numElements of size elementSize in array for a match - * to the. item. Return the index of the element that matches - * (0 - numElements - 1). If no match is found return the -i-1 where - * i is the index (0 - numElements) where the item should be placed. - * (*theCmp)(a,b) should return <0 if a<b, 0 if a==b, >0 if a>b. - * - * This function is like the C-Library function bsearch() except that - * this function returns the index where the item should be placed if - * it is not found. - */ -int BinSearch ( void *array, int numElements, int elementSize, - void *itemPtr, CompareFunction compareFunction) -{ - int low, high, mid, cmp; - void *arrayItemPtr; - - for (low = 0, high = numElements - 1, mid = 0, cmp = -1; low <= high;) { - mid = (low + high) >> 1; - - arrayItemPtr = (void *) (((char *) array) + (mid * elementSize)); - cmp = compareFunction - ? compareFunction (itemPtr, arrayItemPtr) - : ListMemBlockCmp (itemPtr, arrayItemPtr, elementSize); - if (cmp == 0) { - return mid; - } else if (cmp < 0) { - high = mid - 1; - } else { - low = mid + 1; - } - } - if (cmp > 0) - mid++; - - return -mid - 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************************************************************/ - -/* - * If numNewItems == 0 then expand the list by the number of items - * indicated by its allocation policy. - * If numNewItems > 0 then expand the list by exactly the number of - * items indicated. - * If numNewItems < 0 then expand the list by the absolute value of - * numNewItems plus the number of items indicated by its allocation - * policy. - * Returns 1 for success, 0 if out of memory -*/ -static int ExpandListSpace (list_t list, int numNewItems) -{ - if (numNewItems == 0) { - numNewItems = NUMITEMSPERALLOC (list); - } else if (numNewItems < 0) { - numNewItems = (-numNewItems) + NUMITEMSPERALLOC (list); - } - - if (SetHandleSize ((Handle) list, - sizeof (ListStruct) + - ((*list)->listSize + - numNewItems) * (*list)->itemSize)) { - (*list)->listSize += numNewItems; - return 1; - } else { - return 0; - } -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* - * This function reallocate the list, minus any currently unused - * portion of its allotted memory. - */ -void ListCompact (list_t list) -{ - - if (!SetHandleSize ((Handle) list, - sizeof (ListStruct) + - (*list)->numItems * (*list)->itemSize)) { - return; - } - - (*list)->listSize = (*list)->numItems; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -list_t ListCreate (int elementSize) -{ - list_t list; - - list = (list_t) (NewHandle (sizeof (ListStruct))); /* create empty list */ - if (list) { - (*list)->signature = LIST_SIGNATURE; - (*list)->numItems = 0; - (*list)->listSize = 0; - (*list)->itemSize = elementSize; - (*list)->percentIncrease = kDefaultAllocationPercentIncrease; - (*list)->minNumItemsIncrease = - kDefaultAllocationminNumItemsIncrease; - } - - return list; -} - -/*******************************/ - -void ListSetAllocationPolicy (list_t list, int minItemsPerAlloc, - int percentIncreasePerAlloc) -{ - (*list)->percentIncrease = percentIncreasePerAlloc; - (*list)->minNumItemsIncrease = minItemsPerAlloc; -} - -/*******************************/ - -void ListDispose (list_t list) -{ - DisposeHandle ((Handle) list); -} -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListDisposePtrList (list_t list) -{ - int index; - int numItems; - - if (list) { - numItems = ListNumItems (list); - - for (index = 1; index <= numItems; index++) - free (*(void **) ListGetPtrToItem (list, index)); - - ListDispose (list); - } -} - -/*******************************/ - -/* - * keeps memory, resets the number of items to 0 - */ -void ListClear (list_t list) -{ - if (!list) - return; - (*list)->numItems = 0; -} - -/*******************************/ - -/* - * copy is only as large as necessary - */ -list_t ListCopy (list_t originalList) -{ - list_t tempList = NULL; - int numItems; - - if (!originalList) - return NULL; - - tempList = ListCreate ((*originalList)->itemSize); - if (tempList) { - numItems = ListNumItems (originalList); - - if (!SetHandleSize ((Handle) tempList, - sizeof (ListStruct) + - numItems * (*tempList)->itemSize)) { - ListDispose (tempList); - return NULL; - } - - (*tempList)->numItems = (*originalList)->numItems; - (*tempList)->listSize = (*originalList)->numItems; - (*tempList)->itemSize = (*originalList)->itemSize; - (*tempList)->percentIncrease = (*originalList)->percentIncrease; - (*tempList)->minNumItemsIncrease = - (*originalList)->minNumItemsIncrease; - - memcpy (ITEMPTR (tempList, 0), ITEMPTR (originalList, 0), - numItems * (*tempList)->itemSize); - } - - return tempList; -} - -/********************************/ - -/* - * list1 = list1 + list2 - */ -int ListAppend (list_t list1, list_t list2) -{ - int numItemsL1, numItemsL2; - - if (!list2) - return 1; - - if (!list1) - return 0; - if ((*list1)->itemSize != (*list2)->itemSize) - return 0; - - numItemsL1 = ListNumItems (list1); - numItemsL2 = ListNumItems (list2); - - if (numItemsL2 == 0) - return 1; - - if (!SetHandleSize ((Handle) list1, - sizeof (ListStruct) + (numItemsL1 + numItemsL2) * - (*list1)->itemSize)) { - return 0; - } - - (*list1)->numItems = numItemsL1 + numItemsL2; - (*list1)->listSize = numItemsL1 + numItemsL2; - - memmove (ITEMPTR (list1, numItemsL1), - ITEMPTR (list2, 0), - numItemsL2 * (*list2)->itemSize); - - return 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -/* - * returns 1 if the item is inserted, returns 0 if out of memory or - * bad arguments were passed. - */ -int ListInsertItem (list_t list, void *ptrToItem, int itemPosition) -{ - return ListInsertItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -int ListInsertItems (list_t list, void *ptrToItems, int firstItemPosition, - int numItemsToInsert) -{ - int numItems = (*list)->numItems; - - if (firstItemPosition == numItems + 1) - firstItemPosition = LIST_END; - else if (firstItemPosition > numItems) - return 0; - - if ((*list)->numItems >= (*list)->listSize) { - if (!ExpandListSpace (list, -numItemsToInsert)) - return 0; - } - - if (firstItemPosition == LIST_START) { - if (numItems == 0) { - /* special case for empty list */ - firstItemPosition = LIST_END; - } else { - firstItemPosition = 1; - } - } - - if (firstItemPosition == LIST_END) { /* add at the end of the list */ - if (ptrToItems) - memcpy (ITEMPTR (list, numItems), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, numItems), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } else { /* move part of list up to make room for new item */ - memmove (ITEMPTR (list, firstItemPosition - 1 + numItemsToInsert), - ITEMPTR (list, firstItemPosition - 1), - (numItems + 1 - firstItemPosition) * (*list)->itemSize); - - if (ptrToItems) - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, firstItemPosition - 1), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } - - return 1; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/*******************************/ - -int ListEqual (list_t list1, list_t list2) -{ - if (list1 == list2) - return 1; - - if (list1 == NULL || list2 == NULL) - return 0; - - if ((*list1)->itemSize == (*list1)->itemSize) { - if ((*list1)->numItems == (*list2)->numItems) { - return (memcmp (ITEMPTR (list1, 0), ITEMPTR (list2, 0), - (*list1)->itemSize * (*list1)->numItems) == 0); - } - } - - return 0; -} - -/*******************************/ - -/* - * The item pointed to by ptrToItem is copied over the current item - * at itemPosition - */ -void ListReplaceItem (list_t list, void *ptrToItem, int itemPosition) -{ - ListReplaceItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -/* - * The item pointed to by ptrToItems is copied over the current item - * at itemPosition - */ -void ListReplaceItems ( list_t list, void *ptrToItems, - int firstItemPosition, int numItemsToReplace) -{ - - if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - else if (firstItemPosition == LIST_START) - firstItemPosition = 1; - - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToReplace); -} - -/*******************************/ - -void ListGetItem (list_t list, void *itemDestination, int itemPosition) -{ - ListGetItems (list, itemDestination, itemPosition, 1); -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -#if defined(CFG_ALL_LIST_FUNCTIONS) || defined(CFG_DEVICE_DEREGISTER) - -void ListRemoveItem (list_t list, void *itemDestination, int itemPosition) -{ - ListRemoveItems (list, itemDestination, itemPosition, 1); -} - -/*******************************/ - -void ListRemoveItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToRemove) -{ - int firstItemAfterChunk, numToMove; - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - if (itemsDestination != NULL) - memcpy (itemsDestination, ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToRemove); - - firstItemAfterChunk = firstItemPosition + numItemsToRemove; - numToMove = (*list)->numItems - (firstItemAfterChunk - 1); - - if (numToMove > 0) { - /* - * move part of list down to cover hole left by removed item - */ - memmove (ITEMPTR (list, firstItemPosition - 1), - ITEMPTR (list, firstItemAfterChunk - 1), - (*list)->itemSize * numToMove); - } - - (*list)->numItems -= numItemsToRemove; -} -#endif /* CFG_ALL_LIST_FUNCTIONS || CFG_DEVICE_DEREGISTER */ - -/*******************************/ - -void ListGetItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToGet) -{ - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - memcpy (itemsDestination, - ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToGet); -} - -/*******************************/ - -/* - * Returns a pointer to the item at itemPosition. returns null if an - * errors occurred. - */ -void *ListGetPtrToItem (list_t list, int itemPosition) -{ - if (itemPosition == LIST_START) - itemPosition = 1; - else if (itemPosition == LIST_END) - itemPosition = (*list)->numItems; - - return ITEMPTR (list, itemPosition - 1); -} - -/*******************************/ - -/* - * returns a pointer the lists data (abstraction violation for - * optimization) - */ -void *ListGetDataPtr (list_t list) -{ - return &((*list)->itemList[0]); -} - -/********************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -int ListApplyToEach (list_t list, int ascending, - ListApplicationFunc funcToApply, - void *callbackData) -{ - int result = 0, index; - - if (!list || !funcToApply) - goto Error; - - if (ascending) { - for (index = 1; index <= ListNumItems (list); index++) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } else { - for (index = ListNumItems (list); - index > 0 && index <= ListNumItems (list); - index--) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } - -Error: - return result; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/********************************/ - -int ListGetItemSize (list_t list) -{ - return (*list)->itemSize; -} - -/********************************/ - -int ListNumItems (list_t list) -{ - return (*list)->numItems; -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListRemoveDuplicates (list_t list, CompareFunction compareFunction) -{ - int numItems, index, startIndexForFind, duplicatesIndex; - - numItems = ListNumItems (list); - - for (index = 1; index < numItems; index++) { - startIndexForFind = index + 1; - while (startIndexForFind <= numItems) { - duplicatesIndex = - ListFindItem (list, - ListGetPtrToItem (list, index), - startIndexForFind, - compareFunction); - if (duplicatesIndex > 0) { - ListRemoveItem (list, NULL, duplicatesIndex); - numItems--; - startIndexForFind = duplicatesIndex; - } else { - break; - } - } - } -} - -/*******************************/ - - -/*******************************/ - -int ListFindItem (list_t list, void *ptrToItem, int startingPosition, - CompareFunction compareFunction) -{ - int numItems, size, index, cmp; - void *listItemPtr; - - if ((numItems = (*list)->numItems) == 0) - return 0; - - size = (*list)->itemSize; - - if (startingPosition == LIST_START) - startingPosition = 1; - else if (startingPosition == LIST_END) - startingPosition = numItems; - - for (index = startingPosition; index <= numItems; index++) { - listItemPtr = ITEMPTR (list, index - 1); - cmp = compareFunction - ? compareFunction (ptrToItem, listItemPtr) - : ListMemBlockCmp (ptrToItem, listItemPtr, size); - if (cmp == 0) - return index; - } - - return 0; -} - -/*******************************/ - -int ShortCompare (void *a, void *b) -{ - if (*(short *) a < *(short *) b) - return -1; - if (*(short *) a > *(short *) b) - return 1; - return 0; -} - -/*******************************/ - -int IntCompare (void *a, void *b) -{ - if (*(int *) a < *(int *) b) - return -1; - if (*(int *) a > *(int *) b) - return 1; - return 0; -} - -/*******************************/ - -int CStringCompare (void *a, void *b) -{ - return strcmp (*(char **) a, *(char **) b); -} - -/*******************************/ - - -int ListBinSearch (list_t list, void *ptrToItem, - CompareFunction compareFunction) -{ - int index; - - index = BinSearch (ITEMPTR (list, 0), - (int) (*list)->numItems, - (int) (*list)->itemSize, ptrToItem, - compareFunction); - - if (index >= 0) - index++; /* lists start from 1 */ - else - index = 0; /* item not found */ - - return index; -} - -/**************************************************************************/ - -/* - * Reserves memory for numItems in the list. If it succeeds then - * numItems items can be inserted without possibility of an out of - * memory error (useful to simplify error recovery in complex - * functions). Returns 1 if success, 0 if out of memory. - */ -int ListPreAllocate (list_t list, int numItems) -{ - if ((*list)->listSize - (*list)->numItems < numItems) { - return ExpandListSpace (list, - numItems - ((*list)->listSize - - (*list)->numItems)); - } else { - return 1; /* enough items are already pre-allocated */ - } -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 04d9730..108bd60 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -152,7 +152,7 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum); /* search for keyboard and register it if found */ int drv_usb_kbd_init(void) { - int error,i,index; + int error,i; device_t usb_kbd_dev,*old_dev; struct usb_device *dev; char *stdinname = getenv ("stdin"); @@ -166,13 +166,11 @@ int drv_usb_kbd_init(void) if(usb_kbd_probe(dev,0)==1) { /* Ok, we found a keyboard */ /* check, if it is already registered */ USB_KBD_PRINTF("USB KBD found set up device.\n"); - for (index=1; index<=ListNumItems(devlist); index++) { - old_dev = ListGetPtrToItem(devlist, index); - if(strcmp(old_dev->name,DEVNAME)==0) { - /* ok, already registered, just return ok */ - USB_KBD_PRINTF("USB KBD is already registered.\n"); - return 1; - } + old_dev = device_get_by_name(DEVNAME); + if(old_dev) { + /* ok, already registered, just return ok */ + USB_KBD_PRINTF("USB KBD is already registered.\n"); + return 1; } /* register the keyboard */ USB_KBD_PRINTF("USB KBD register.\n"); diff --git a/include/devices.h b/include/devices.h index 2d9e282..490016b 100644 --- a/include/devices.h +++ b/include/devices.h @@ -21,7 +21,7 @@ * MA 02111-1307 USA */
-#include <lists.h> +#include <linux/list.h>
#ifndef _DEVICES_H_ #define _DEVICES_H_ @@ -59,6 +59,7 @@ typedef struct { /* Other functions */
void *priv; /* Private extensions */ + struct list_head list; } device_t;
/* @@ -82,7 +83,6 @@ typedef struct { /* * VARIABLES */ -extern list_t devlist; extern device_t *stdio_devices[]; extern char *stdio_names[MAX_FILES];
@@ -91,8 +91,10 @@ extern char *stdio_names[MAX_FILES]; */ int device_register (device_t * dev); int devices_init (void); -int devices_done (void); int device_deregister(char *devname); +struct list_head* device_get_list(void); +device_t* device_get_by_name(char* name); + #ifdef CONFIG_LCD int drv_lcd_init (void); #endif diff --git a/include/lists.h b/include/lists.h deleted file mode 100644 index 10a2a19..0000000 --- a/include/lists.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef _LISTS_H_ -#define _LISTS_H_ - -#define LIST_START -1 /* Handy Constants that substitute for item positions */ -#define LIST_END 0 /* END_OF_LIST means one past current length of list when */ - /* inserting. Otherwise it refers the last item in the list. */ - -typedef struct - { - void *ptr; - unsigned int size; - } HandleRecord; - -typedef void **Handle; - -typedef int (*CompareFunction)(void *data1, void *data2) ; - -typedef struct ListStructTag - { - int signature; /* debugging aid */ - int percentIncrease; /* %of current size to increase by when list is out of space */ - int minNumItemsIncrease; /* fixed number of items to increase by when list is out of space */ - int listSize; /* number of items than can fit in the currently allocated memory */ - int itemSize; /* the size of each item in the list (same for every item) */ - int numItems; /* number of items currently in the list */ - unsigned char itemList[1]; /* resizable array of list elements */ - } ListStruct; - -typedef struct ListStructTag **list_t; /* The list abstract data type */ -typedef int ( * ListApplicationFunc)(int index, void *ptrToItem, void *callbackData); - -/* Basic List Operations */ -list_t ListCreate(int elementSize); -int ListNumItems(list_t list); -int ListInsertItem(list_t list, void *ptrToItem, int itemPosition); -int ListInsertItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToInsert); -void ListDispose(list_t list); -void *ListGetPtrToItem(list_t list, int itemPosition); -void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); -void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); - -#if 0 /* rarely ever used; kept here for reference just in case ... */ -void ListDisposePtrList(list_t list); -void ListGetItem(list_t list, void *itemDestination, int itemPosition); -void ListReplaceItem(list_t list, void *ptrToItem, int itemPosition); -void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); -void ListGetItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToGet); -void ListReplaceItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToReplace); -void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); -list_t ListCopy(list_t originalList); -int ListAppend(list_t list1, list_t list2); -void ListClear(list_t list); -int ListEqual(list_t list1, list_t list2); -int ListInsertInOrder(list_t list, void *ptrToItem, CompareFunction compareFunction); -void *ListGetDataPtr(list_t list); -int ListApplyToEach(list_t list, int ascending, ListApplicationFunc funcToApply, void *callbackData); - -/* List Searching and Sorting */ -int ListFindItem(list_t list, void *ptrToItem, int startingPosition, CompareFunction compareFunction); -void ListRemoveDuplicates(list_t list, CompareFunction compareFunction); -int ListBinSearch(list_t list, void *itemPtr, CompareFunction compareFunction); -void ListQuickSort(list_t list, CompareFunction compareFunction); -void ListHeapSort(list_t list, CompareFunction compareFunction); -void ListInsertionSort(list_t list, CompareFunction compareFunction); -int ListIsSorted(list_t list, CompareFunction compareFunction); - -/* Advanced List Functions */ -void ListSetAllocationPolicy(list_t list, int minItemsPerAlloc, int percentIncreasePerAlloc); -void ListCompact(list_t list); -int ListPreAllocate(list_t list, int numItems); -int ListGetItemSize(list_t list); -int GetIntListFromParmInfo(va_list parmInfo, int numIntegers, list_t *integerList); -int ListInsertAfterItem(list_t list, void *ptrToItem, void *ptrToItemToInsertAfter, CompareFunction compareFunction); -int ListInsertBeforeItem(list_t list, void *ptrToItem, void *ptrToItemToInsertBefore, CompareFunction compareFunction); -#endif /* 0 */ - -#endif /* _LISTS_H_ */

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- include/linux/list.h | 506 +++++++++++++++++++++++++++++++++++++++++++----- include/linux/poison.h | 11 + 2 files changed, 472 insertions(+), 45 deletions(-) create mode 100644 include/linux/poison.h
diff --git a/include/linux/list.h b/include/linux/list.h index e6492f7..aeeeb21 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -1,6 +1,9 @@ #ifndef _LINUX_LIST_H #define _LINUX_LIST_H
+#include <linux/stddef.h> +#include <linux/poison.h> + #ifndef ARCH_HAS_PREFETCH #define ARCH_HAS_PREFETCH static inline void prefetch(const void *x) {;} @@ -25,9 +28,11 @@ struct list_head { #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name)
-#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) +static inline void INIT_LIST_HEAD(struct list_head *list) +{ + list->next = list; + list->prev = list; +}
/* * Insert a new entry between two known consecutive entries. @@ -87,13 +92,37 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) /** * list_del - deletes entry from list. * @entry: the element to delete from the list. - * Note: list_empty on entry does not return true after this, the entry is in an undefined state. + * Note: list_empty() on entry does not return true after this, the entry is + * in an undefined state. */ static inline void list_del(struct list_head *entry) { __list_del(entry->prev, entry->next); - entry->next = (void *) 0; - entry->prev = (void *) 0; + entry->next = LIST_POISON1; + entry->prev = LIST_POISON2; +} + +/** + * list_replace - replace old entry by new one + * @old : the element to be replaced + * @new : the new element to insert + * + * If @old was empty, it will be overwritten. + */ +static inline void list_replace(struct list_head *old, + struct list_head *new) +{ + new->next = old->next; + new->next->prev = new; + new->prev = old->prev; + new->prev->next = new; +} + +static inline void list_replace_init(struct list_head *old, + struct list_head *new) +{ + list_replace(old, new); + INIT_LIST_HEAD(old); }
/** @@ -130,37 +159,129 @@ static inline void list_move_tail(struct list_head *list, }
/** + * list_is_last - tests whether @list is the last entry in list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_last(const struct list_head *list, + const struct list_head *head) +{ + return list->next == head; +} + +/** * list_empty - tests whether a list is empty * @head: the list to test. */ -static inline int list_empty(struct list_head *head) +static inline int list_empty(const struct list_head *head) { return head->next == head; }
-static inline void __list_splice(struct list_head *list, - struct list_head *head) +/** + * list_empty_careful - tests whether a list is empty and not being modified + * @head: the list to test + * + * Description: + * tests whether a list is empty _and_ checks that no other CPU might be + * in the process of modifying either member (next or prev) + * + * NOTE: using list_empty_careful() without synchronization + * can only be safe if the only activity that can happen + * to the list entry is list_del_init(). Eg. it cannot be used + * if another CPU could re-list_add() it. + */ +static inline int list_empty_careful(const struct list_head *head) +{ + struct list_head *next = head->next; + return (next == head) && (next == head->prev); +} + +/** + * list_is_singular - tests whether a list has just one entry. + * @head: the list to test. + */ +static inline int list_is_singular(const struct list_head *head) +{ + return !list_empty(head) && (head->next == head->prev); +} + +static inline void __list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + struct list_head *new_first = entry->next; + list->next = head->next; + list->next->prev = list; + list->prev = entry; + entry->next = list; + head->next = new_first; + new_first->prev = head; +} + +/** + * list_cut_position - cut a list into two + * @list: a new list to add all removed entries + * @head: a list with entries + * @entry: an entry within head, could be the head itself + * and if so we won't cut the list + * + * This helper moves the initial part of @head, up to and + * including @entry, from @head to @list. You should + * pass on @entry an element you know is on @head. @list + * should be an empty list or a list you do not care about + * losing its data. + * + */ +static inline void list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + if (list_empty(head)) + return; + if (list_is_singular(head) && + (head->next != entry && head != entry)) + return; + if (entry == head) + INIT_LIST_HEAD(list); + else + __list_cut_position(list, head, entry); +} + +static inline void __list_splice(const struct list_head *list, + struct list_head *prev, + struct list_head *next) { struct list_head *first = list->next; struct list_head *last = list->prev; - struct list_head *at = head->next;
- first->prev = head; - head->next = first; + first->prev = prev; + prev->next = first;
- last->next = at; - at->prev = last; + last->next = next; + next->prev = last; }
/** - * list_splice - join two lists + * list_splice - join two lists, this is designed for stacks * @list: the new list to add. * @head: the place to add it in the first list. */ -static inline void list_splice(struct list_head *list, struct list_head *head) +static inline void list_splice(const struct list_head *list, + struct list_head *head) { if (!list_empty(list)) - __list_splice(list, head); + __list_splice(list, head, head->next); +} + +/** + * list_splice_tail - join two lists, each list being a queue + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static inline void list_splice_tail(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) + __list_splice(list, head->prev, head); }
/** @@ -174,7 +295,24 @@ static inline void list_splice_init(struct list_head *list, struct list_head *head) { if (!list_empty(list)) { - __list_splice(list, head); + __list_splice(list, head, head->next); + INIT_LIST_HEAD(list); + } +} + +/** + * list_splice_tail_init - join two lists and reinitialise the emptied list + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * Each of the lists is a queue. + * The list at @list is reinitialised + */ +static inline void list_splice_tail_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + __list_splice(list, head->prev, head); INIT_LIST_HEAD(list); } } @@ -186,28 +324,53 @@ static inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + container_of(ptr, type, member) + +/** + * list_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_struct within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member)
/** * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. + * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list. */ #define list_for_each(pos, head) \ - for (pos = (head)->next, prefetch(pos->next); pos != (head); \ - pos = pos->next, prefetch(pos->next)) + for (pos = (head)->next; prefetch(pos->next), pos != (head); \ + pos = pos->next) + +/** + * __list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop cursor. + * @head: the head for your list. + * + * This variant differs from list_for_each() in that it's the + * simplest possible list iteration code, no prefetching is done. + * Use this for code that knows the list to be very short (empty + * or 1 entry) most of the time. + */ +#define __list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + /** * list_for_each_prev - iterate over a list backwards - * @pos: the &struct list_head to use as a loop counter. + * @pos: the &struct list_head to use as a loop cursor. * @head: the head for your list. */ #define list_for_each_prev(pos, head) \ - for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \ - pos = pos->prev, prefetch(pos->prev)) + for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ + pos = pos->prev)
/** - * list_for_each_safe - iterate over a list safe against removal of list entry - * @pos: the &struct list_head to use as a loop counter. + * list_for_each_safe - iterate over a list safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. * @n: another &struct list_head to use as temporary storage * @head: the head for your list. */ @@ -216,43 +379,296 @@ static inline void list_splice_init(struct list_head *list, pos = n, n = pos->next)
/** + * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry + * @pos: the &struct list_head to use as a loop cursor. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_prev_safe(pos, n, head) \ + for (pos = (head)->prev, n = pos->prev; \ + prefetch(pos->prev), pos != (head); \ + pos = n, n = pos->prev) + +/** * list_for_each_entry - iterate over list of given type - * @pos: the type * to use as a loop counter. + * @pos: the type * to use as a loop cursor. * @head: the head for your list. * @member: the name of the list_struct within the struct. */ #define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - prefetch(pos->member.next); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next)) + for (pos = list_entry((head)->next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_reverse - iterate backwards over list of given type. + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member); \ + prefetch(pos->member.prev), &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +/** + * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() + * @pos: the type * to use as a start point + * @head: the head of the list + * @member: the name of the list_struct within the struct. + * + * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). + */ +#define list_prepare_entry(pos, head, member) \ + ((pos) ? : list_entry(head, typeof(*pos), member)) + +/** + * list_for_each_entry_continue - continue iteration over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Continue to iterate over list of given type, continuing after + * the current position. + */ +#define list_for_each_entry_continue(pos, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member)) + +/** + * list_for_each_entry_continue_reverse - iterate backwards from the given point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Start to iterate over list of given type backwards, continuing after + * the current position. + */ +#define list_for_each_entry_continue_reverse(pos, head, member) \ + for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ + prefetch(pos->member.prev), &pos->member != (head); \ + pos = list_entry(pos->member.prev, typeof(*pos), member)) + +/** + * list_for_each_entry_from - iterate over list of given type from the current point + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type, continuing from current position. + */ +#define list_for_each_entry_from(pos, head, member) \ + for (; prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry(pos->member.next, typeof(*pos), member))
/** * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry - * @pos: the type * to use as a loop counter. + * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_struct within the struct. */ #define list_for_each_entry_safe(pos, n, head, member) \ for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member))
/** - * list_for_each_entry_continue - iterate over list of given type - * continuing after existing point - * @pos: the type * to use as a loop counter. + * list_for_each_entry_safe_continue + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage * @head: the head for your list. * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type, continuing after current point, + * safe against removal of list entry. + */ +#define list_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_from + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate over list of given type from current point, safe against + * removal of list entry. + */ +#define list_for_each_entry_safe_from(pos, n, head, member) \ + for (n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** + * list_for_each_entry_safe_reverse + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + * + * Iterate backwards over list of given type, safe against removal + * of list entry. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + +#define HLIST_HEAD_INIT { .first = NULL } +#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } +#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) +static inline void INIT_HLIST_NODE(struct hlist_node *h) +{ + h->next = NULL; + h->pprev = NULL; +} + +static inline int hlist_unhashed(const struct hlist_node *h) +{ + return !h->pprev; +} + +static inline int hlist_empty(const struct hlist_head *h) +{ + return !h->first; +} + +static inline void __hlist_del(struct hlist_node *n) +{ + struct hlist_node *next = n->next; + struct hlist_node **pprev = n->pprev; + *pprev = next; + if (next) + next->pprev = pprev; +} + +static inline void hlist_del(struct hlist_node *n) +{ + __hlist_del(n); + n->next = LIST_POISON1; + n->pprev = LIST_POISON2; +} + +static inline void hlist_del_init(struct hlist_node *n) +{ + if (!hlist_unhashed(n)) { + __hlist_del(n); + INIT_HLIST_NODE(n); + } +} + +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + n->next = first; + if (first) + first->pprev = &n->next; + h->first = n; + n->pprev = &h->first; +} + +/* next must be != NULL */ +static inline void hlist_add_before(struct hlist_node *n, + struct hlist_node *next) +{ + n->pprev = next->pprev; + n->next = next; + next->pprev = &n->next; + *(n->pprev) = n; +} + +static inline void hlist_add_after(struct hlist_node *n, + struct hlist_node *next) +{ + next->next = n->next; + n->next = next; + next->pprev = &n->next; + + if(next->next) + next->next->pprev = &next->next; +} + +#define hlist_entry(ptr, type, member) container_of(ptr,type,member) + +#define hlist_for_each(pos, head) \ + for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \ + pos = pos->next) + +#define hlist_for_each_safe(pos, n, head) \ + for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ + pos = n) + +/** + * hlist_for_each_entry - iterate over list of given type + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(tpos, pos, head, member) \ + for (pos = (head)->first; \ + pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_continue - iterate over a hlist continuing after current point + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_continue(tpos, pos, member) \ + for (pos = (pos)->next; \ + pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_from - iterate over a hlist continuing from current point + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry_from(tpos, pos, member) \ + for (; pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) + +/** + * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry + * @tpos: the type * to use as a loop cursor. + * @pos: the &struct hlist_node to use as a loop cursor. + * @n: another &struct hlist_node to use as temporary storage + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. */ -#define list_for_each_entry_continue(pos, head, member) \ - for (pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next)) +#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ + for (pos = (head)->first; \ + pos && ({ n = pos->next; 1; }) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = n)
#endif diff --git a/include/linux/poison.h b/include/linux/poison.h new file mode 100644 index 0000000..b3d873b --- /dev/null +++ b/include/linux/poison.h @@ -0,0 +1,11 @@ +#ifndef _LINUX_POISON_H +#define _LINUX_POISON_H + +/********** include/linux/list.h **********/ +/* + * used to verify that nobody uses non-initialized list entries. + */ +#define LIST_POISON1 ((void *) 0x0) +#define LIST_POISON2 ((void *) 0x0) + +#endif

Dear Jean-Christophe PLAGNIOL-VILLARD,
In message 20080829200121.GA6190@game.jcrosoft.org you wrote:
The following changes since commit 33aa4eac66b71c797bbc13b3afe432a2132947d4: Wolfgang Denk (1): Merge branch 'master' of /home/wd/git/u-boot/custodians
are available in the git repository at:
git://git.denx.de/u-boot-arm.git Makefile
Jean-Christophe PLAGNIOL-VILLARD (12): gunzip: move to lib_generic soft_i2c: move to drivers/i2c soft_spi: move to drivers/spi miiphybb: move to drivers/net/phy crc16: move to lib_generic autoscript: Move conditional compilation to Makefile miiphyutil: Move conditional compilation to Makefile common/Makefile: order by functionality cmd_terminal: remove no need ifdef update linux/list devices: merge to list_head fs: Move conditional compilation to Makefile
Makefile | 1 + common/Makefile | 79 ++-- common/cmd_autoscript.c | 4 - common/cmd_console.c | 9 +- common/cmd_terminal.c | 14 +- common/console.c | 62 ++-- common/devices.c | 79 ++-- common/lists.c | 734 -------------------------------- common/miiphyutil.c | 2 - common/usb_kbd.c | 14 +- drivers/i2c/Makefile | 1 + {common => drivers/i2c}/soft_i2c.c | 0 drivers/net/phy/Makefile | 46 ++ {common => drivers/net/phy}/miiphybb.c | 0 drivers/spi/Makefile | 3 +- {common => drivers/spi}/soft_spi.c | 0 fs/Makefile | 10 +- fs/cramfs/Makefile | 7 +- fs/cramfs/cramfs.c | 5 - fs/cramfs/uncompress.c | 4 - fs/ext2/Makefile | 6 +- fs/ext2/dev.c | 3 - fs/ext2/ext2fs.c | 4 - fs/fat/Makefile | 6 +- fs/fat/fat.c | 4 - fs/fat/file.c | 4 - fs/fdos/Makefile | 6 +- fs/fdos/dev.c | 5 - fs/fdos/fat.c | 4 - fs/fdos/fdos.c | 5 +- fs/fdos/fs.c | 4 - fs/fdos/subdir.c | 3 - fs/fdos/vfat.c | 5 - fs/jffs2/Makefile | 8 +- fs/jffs2/compr_lzari.c | 3 - fs/jffs2/compr_lzo.c | 4 - fs/jffs2/compr_rtime.c | 4 - fs/jffs2/compr_rubin.c | 4 - fs/jffs2/compr_zlib.c | 4 - fs/jffs2/jffs2_1pass.c | 5 - fs/jffs2/jffs2_nand_1pass.c | 2 +- fs/jffs2/mini_inflate.c | 5 - fs/reiserfs/Makefile | 6 +- fs/reiserfs/dev.c | 4 - fs/reiserfs/mode_string.c | 3 - fs/reiserfs/reiserfs.c | 4 - include/devices.h | 8 +- include/linux/list.h | 506 ++++++++++++++++++++-- include/linux/poison.h | 11 + include/lists.h | 77 ---- lib_generic/Makefile | 2 + {common => lib_generic}/crc16.c | 0 {common => lib_generic}/gunzip.c | 0 53 files changed, 682 insertions(+), 1111 deletions(-) delete mode 100644 common/lists.c rename {common => drivers/i2c}/soft_i2c.c (100%) create mode 100644 drivers/net/phy/Makefile rename {common => drivers/net/phy}/miiphybb.c (100%) rename {common => drivers/spi}/soft_spi.c (100%) create mode 100644 include/linux/poison.h delete mode 100644 include/lists.h rename {common => lib_generic}/crc16.c (100%) rename {common => lib_generic}/gunzip.c (100%)
Done, thanks.
Best regards,
Wolfgang Denk
participants (4)
-
Ben Warren
-
Jean-Christophe PLAGNIOL-VILLARD
-
Peter Tyser
-
Wolfgang Denk