]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
[PATCH 1_4] Merge common get_dev() routines for block devices
authorGrant Likely <grant.likely@secretlab.ca>
Tue, 20 Feb 2007 08:04:34 +0000 (09:04 +0100)
committerStefan Roese <sr@denx.de>
Tue, 20 Feb 2007 08:04:34 +0000 (09:04 +0100)
Each of the filesystem drivers duplicate the get_dev routine.  This change
merges them into a single function in part.c

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
15 files changed:
board/esd/common/auto_update.c
board/mcc200/auto_update.c
board/mpl/mip405/mip405.c
board/trab/auto_update.c
common/cmd_ext2.c
common/cmd_fat.c
common/cmd_ide.c
common/cmd_reiser.c
common/cmd_scsi.c
common/cmd_usb.c
common/usb_storage.c
cpu/pxa/mmc.c
disk/part.c
include/ide.h
include/part.h

index 5cd342332f51fd3bdb6a3ab9e1c239e1f4430cc7..001fd68da42e0bbea25e6b5930067b5283eb1991 100644 (file)
@@ -33,6 +33,7 @@
 #include <asm/byteorder.h>
 #include <linux/mtd/nand_legacy.h>
 #include <fat.h>
+#include <part.h>
 
 #include "auto_update.h"
 
@@ -71,8 +72,6 @@ extern int transfer_pic(unsigned char, unsigned char *, int, int);
 extern int flash_sect_erase(ulong, ulong);
 extern int flash_sect_protect (int, ulong, ulong);
 extern int flash_write (char *, ulong, ulong);
-/* change char* to void* to shutup the compiler */
-extern block_dev_desc_t *get_dev (char*, int);
 
 #if (CONFIG_COMMANDS & CFG_CMD_NAND) && defined(CFG_NAND_LEGACY)
 /* references to names in cmd_nand.c */
index 12091fd7821406679e5df1ca2b1e7a3a7524cb6d..df003fe8bee9f762a72858303ddea8ec221eecac 100644 (file)
@@ -23,6 +23,7 @@
 #include <image.h>
 #include <asm/byteorder.h>
 #include <usb.h>
+#include <part.h>
 
 #ifdef CFG_HUSH_PARSER
 #include <hush.h>
@@ -128,8 +129,6 @@ extern int i2c_read (unsigned char, unsigned int, int , unsigned char* , int);
 extern int flash_sect_erase(ulong, ulong);
 extern int flash_sect_protect (int, ulong, ulong);
 extern int flash_write (char *, ulong, ulong);
-/* change char* to void* to shutup the compiler */
-extern block_dev_desc_t *get_dev (char*, int);
 extern int u_boot_hush_start(void);
 
 int au_check_cksum_valid(int idx, long nbytes)
index 34f328999d1d27b7ac8df257a791e3cd3be20964..13249787db00e2cc2af1ed4e89540175e1fc7e5a 100644 (file)
@@ -73,9 +73,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-extern block_dev_desc_t * scsi_get_dev(int dev);
-extern block_dev_desc_t * ide_get_dev(int dev);
-
 #undef SDRAM_DEBUG
 #define ENABLE_ECC /* for ecc boards */
 #define FALSE           0
index d2c8d44a79f87188ac87383da844491700a40474..f4074aecb11e45eee39723d66f4b5d89a803d8b0 100644 (file)
@@ -203,7 +203,6 @@ extern int flash_write (char *, ulong, ulong);
 /* change char* to void* to shutup the compiler */
 extern int i2c_write_multiple (uchar, uint, int, void *, int);
 extern int i2c_read_multiple (uchar, uint, int, void *, int);
-extern block_dev_desc_t *get_dev (char*, int);
 extern int u_boot_hush_start(void);
 
 int
index 5db42f2b0d65e79e9d3b546b1864abb4ba26799a..94bd9b61e6779a01f241700817fba6c817478348 100644 (file)
@@ -33,6 +33,7 @@
  * Ext2fs support
  */
 #include <common.h>
+#include <part.h>
 
 #if (CONFIG_COMMANDS & CFG_CMD_EXT2)
 #include <config.h>
 #define PRINTF(fmt,args...)
 #endif
 
-static block_dev_desc_t *get_dev (char* ifname, int dev)
-{
-#if (CONFIG_COMMANDS & CFG_CMD_IDE)
-       if (strncmp(ifname,"ide",3)==0) {
-               extern block_dev_desc_t * ide_get_dev(int dev);
-               return((dev >= CFG_IDE_MAXDEVICE) ? NULL : ide_get_dev(dev));
-       }
-#endif
-#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
-       if (strncmp(ifname,"scsi",4)==0) {
-               extern block_dev_desc_t * scsi_get_dev(int dev);
-               return((dev >= CFG_SCSI_MAXDEVICE) ? NULL : scsi_get_dev(dev));
-       }
-#endif
-#if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
-       if (strncmp(ifname,"usb",3)==0) {
-               extern block_dev_desc_t * usb_stor_get_dev(int dev);
-               return((dev >= USB_MAX_STOR_DEV) ? NULL : usb_stor_get_dev(dev));
-       }
-#endif
-#if defined(CONFIG_MMC)
-       if (strncmp(ifname,"mmc",3)==0) {
-               extern block_dev_desc_t *  mmc_get_dev(int dev);
-               return((dev >= 1) ? NULL : mmc_get_dev(dev));
-       }
-#endif
-#if defined(CONFIG_SYSTEMACE)
-       if (strcmp(ifname,"ace")==0) {
-               extern block_dev_desc_t *  systemace_get_dev(int dev);
-               return((dev >= 1) ? NULL : systemace_get_dev(dev));
-       }
-#endif
-       return(NULL);
-}
-
 int do_ext2ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        char *filename = "/";
@@ -106,7 +72,7 @@ int do_ext2ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return(1);
        }
        dev = (int)simple_strtoul (argv[2], &ep, 16);
-       dev_desc=get_dev(argv[1],dev);
+       dev_desc = get_dev(argv[1],dev);
 
        if (dev_desc == NULL) {
                printf ("\n** Block device %s %d not supported\n", argv[1], dev);
@@ -210,7 +176,7 @@ int do_ext2load (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        }
 
        dev = (int)simple_strtoul (argv[2], &ep, 16);
-       dev_desc=get_dev(argv[1],dev);
+       dev_desc = get_dev(argv[1],dev);
        if (dev_desc==NULL) {
                printf ("\n** Block device %s %d not supported\n", argv[1], dev);
                return(1);
index 6844c103f22290fa70f6fe46a3397684bbf5e07a..afaf299569bf612b891ae04917585d28d7a2c3f3 100644 (file)
@@ -29,6 +29,7 @@
 #include <s_record.h>
 #include <net.h>
 #include <ata.h>
+#include <part.h>
 
 #if (CONFIG_COMMANDS & CFG_CMD_FAT)
 
 #include <fat.h>
 
 
-block_dev_desc_t *get_dev (char* ifname, int dev)
-{
-#if (CONFIG_COMMANDS & CFG_CMD_IDE)
-       if (strncmp(ifname,"ide",3)==0) {
-               extern block_dev_desc_t * ide_get_dev(int dev);
-               return(ide_get_dev(dev));
-       }
-#endif
-#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
-       if (strncmp(ifname,"scsi",4)==0) {
-               extern block_dev_desc_t * scsi_get_dev(int dev);
-               return(scsi_get_dev(dev));
-       }
-#endif
-#if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
-       if (strncmp(ifname,"usb",3)==0) {
-               extern block_dev_desc_t * usb_stor_get_dev(int dev);
-               return(usb_stor_get_dev(dev));
-       }
-#endif
-#if defined(CONFIG_MMC)
-       if (strncmp(ifname,"mmc",3)==0) {
-               extern block_dev_desc_t *  mmc_get_dev(int dev);
-               return(mmc_get_dev(dev));
-       }
-#endif
-#if defined(CONFIG_SYSTEMACE)
-       if (strcmp(ifname,"ace")==0) {
-               extern block_dev_desc_t *  systemace_get_dev(int dev);
-               return(systemace_get_dev(dev));
-       }
-#endif
-       return NULL;
-}
-
-
 int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        long size;
index a4155029a7b8ddb7755619056af7c5c29a1e0ef7..ebc080c72afdbf97cc4866bddb65c5a047b537b5 100644 (file)
 #include <command.h>
 #include <image.h>
 #include <asm/byteorder.h>
+
 #if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA)
 # include <pcmcia.h>
 #endif
+
 #ifdef CONFIG_8xx
 # include <mpc8xx.h>
 #endif
+
 #ifdef CONFIG_MPC5xxx
 #include <mpc5xxx.h>
 #endif
+
 #include <ide.h>
 #include <ata.h>
+
 #ifdef CONFIG_STATUS_LED
 # include <status_led.h>
 #endif
+
 #ifndef __PPC__
 #include <asm/io.h>
 #ifdef __MIPS__
@@ -697,7 +703,7 @@ void ide_init (void)
 
 block_dev_desc_t * ide_get_dev(int dev)
 {
-       return ((block_dev_desc_t *)&ide_dev_desc[dev]);
+       return (dev < CFG_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL;
 }
 
 
index 508ffcbdac8eb4e3dfd04c7ae5ddb7fcfe375714..09c86e66d76fe56477565cb70666ba2b5fbe97b0 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <reiserfs.h>
+#include <part.h>
 
 #ifndef CONFIG_DOS_PARTITION
 #error DOS partition support must be selected
 #define PRINTF(fmt,args...)
 #endif
 
-static block_dev_desc_t *get_dev (char* ifname, int dev)
-{
-#if (CONFIG_COMMANDS & CFG_CMD_IDE)
-       if (strncmp(ifname,"ide",3)==0) {
-               extern block_dev_desc_t * ide_get_dev(int dev);
-               return((dev >= CFG_IDE_MAXDEVICE) ? NULL : ide_get_dev(dev));
-       }
-#endif
-#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
-       if (strncmp(ifname,"scsi",4)==0) {
-               extern block_dev_desc_t * scsi_get_dev(int dev);
-               return((dev >= CFG_SCSI_MAXDEVICE) ? NULL : scsi_get_dev(dev));
-       }
-#endif
-#if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
-       if (strncmp(ifname,"usb",3)==0) {
-               extern block_dev_desc_t * usb_stor_get_dev(int dev);
-               return((dev >= USB_MAX_STOR_DEV) ? NULL : usb_stor_get_dev(dev));
-       }
-#endif
-#if defined(CONFIG_MMC)
-       if (strncmp(ifname,"mmc",3)==0) {
-               extern block_dev_desc_t *  mmc_get_dev(int dev);
-               return((dev >= 1) ? NULL : mmc_get_dev(dev));
-       }
-#endif
-#if defined(CONFIG_SYSTEMACE)
-       if (strcmp(ifname,"ace")==0) {
-               extern block_dev_desc_t *  systemace_get_dev(int dev);
-               return((dev >= 1) ? NULL : systemace_get_dev(dev));
-       }
-#endif
-       return NULL;
-}
-
 int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        char *filename = "/";
@@ -97,7 +63,7 @@ int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return 1;
        }
        dev = (int)simple_strtoul (argv[2], &ep, 16);
-       dev_desc=get_dev(argv[1],dev);
+       dev_desc = get_dev(argv[1],dev);
 
        if (dev_desc == NULL) {
                printf ("\n** Block device %s %d not supported\n", argv[1], dev);
@@ -196,7 +162,7 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        }
 
        dev = (int)simple_strtoul (argv[2], &ep, 16);
-       dev_desc=get_dev(argv[1],dev);
+       dev_desc = get_dev(argv[1],dev);
        if (dev_desc==NULL) {
                printf ("\n** Block device %s %d not supported\n", argv[1], dev);
                return 1;
index cc08743d5dcc7a42a8c5030a04a9bce4d017dfc4..b17bebbacf6e8d9e5bab37dc5ba8a54c16955309 100644 (file)
@@ -194,7 +194,7 @@ void scsi_init(void)
 
 block_dev_desc_t * scsi_get_dev(int dev)
 {
-       return((block_dev_desc_t *)&scsi_dev_desc[dev]);
+       return (dev < CFG_SCSI_MAX_DEVICE) ? &scsi_dev_desc[dev] : NULL;
 }
 
 
index 28c05aa20eaf69afa8a4145a61a293c0ae0f6f4a..904df7159f42c7b5960717bcfbd6ad1df80c1ae8 100644 (file)
@@ -28,6 +28,7 @@
 #include <common.h>
 #include <command.h>
 #include <asm/byteorder.h>
+#include <part.h>
 
 #if (CONFIG_COMMANDS & CFG_CMD_USB)
 
index 06ea99b2f1a750d441db8e13999970d76ceaa825..b4b79140899a0f039a4506a0744ccc697099b3df 100644 (file)
@@ -56,6 +56,7 @@
 
 
 #if (CONFIG_COMMANDS & CFG_CMD_USB)
+#include <part.h>
 #include <usb.h>
 
 #ifdef CONFIG_USB_STORAGE
@@ -174,7 +175,7 @@ void uhci_show_temp_int_td(void);
 
 block_dev_desc_t *usb_stor_get_dev(int index)
 {
-       return &usb_dev_desc[index];
+       return (index < USB_MAX_STOR_DEV) ? &usb_dev_desc[index] : NULL;
 }
 
 
index f7020eec951398fadc349d4e40df67c93ee19d3d..c57d0d5c32c1ddc24be6fce0403e53d62cfd83b0 100644 (file)
@@ -37,7 +37,7 @@ static block_dev_desc_t mmc_dev;
 
 block_dev_desc_t * mmc_get_dev(int dev)
 {
-       return ((block_dev_desc_t *)&mmc_dev);
+       return (dev == 0) ? &mmc_dev : NULL;
 }
 
 /*
index 2255e726cf5c687994e7e7d7c138413bc2acd374..f1026c5ef21987cdada20db52fcf15b3268173e4 100644 (file)
@@ -24,6 +24,7 @@
 #include <common.h>
 #include <command.h>
 #include <ide.h>
+#include <part.h>
 
 #undef PART_DEBUG
 
 #define PRINTF(fmt,args...)
 #endif
 
+#if ((CONFIG_COMMANDS & CFG_CMD_IDE)   || \
+     (CONFIG_COMMANDS & CFG_CMD_SCSI)  || \
+     (CONFIG_COMMANDS & CFG_CMD_USB)   || \
+     defined(CONFIG_MMC) || \
+     defined(CONFIG_SYSTEMACE) )
+
+struct block_drvr {
+       char *name;
+       block_dev_desc_t* (*get_dev)(int dev);
+};
+
+static const struct block_drvr block_drvr[] = {
+#if (CONFIG_COMMANDS & CFG_CMD_IDE)
+       { .name = "ide", .get_dev = ide_get_dev, },
+#endif
+#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
+       { .name = "scsi", .get_dev = scsi_get_dev, },
+#endif
+#if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
+       { .name = "usb", .get_dev = usb_stor_get_dev, },
+#endif
+#if defined(CONFIG_MMC)
+       { .name = "mmc", .get_dev = mmc_get_dev, },
+#endif
+#if defined(CONFIG_SYSTEMACE)
+       { .name = "ace", .get_dev = systemace_get_dev, },
+#endif
+       { },
+};
+
+block_dev_desc_t *get_dev(char* ifname, int dev)
+{
+       const struct block_drvr *drvr = block_drvr;
+
+       while (drvr->name) {
+               if (strncmp(ifname, drvr->name, strlen(drvr->name)) == 0)
+                       return drvr->get_dev(dev);
+               drvr++;
+       }
+       return NULL;
+}
+#else
+block_dev_desc_t *get_dev(char* ifname, int dev)
+{
+       return NULL;
+}
+#endif
+
 #if ((CONFIG_COMMANDS & CFG_CMD_IDE)   || \
      (CONFIG_COMMANDS & CFG_CMD_SCSI)  || \
      (CONFIG_COMMANDS & CFG_CMD_USB)   || \
index dfef32f267d1316fcd8a811e90013249f5fc72cb..e29ed36de0c76e418c336c24192d8dd2449525c0 100644 (file)
@@ -48,8 +48,8 @@ typedef ulong lbaint_t;
  * Function Prototypes
  */
 
-void  ide_init  (void);
-ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer);
-ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, ulong *buffer);
+void ide_init(void);
+ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, ulong *buffer);
+ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, ulong *buffer);
 
 #endif /* _IDE_H */
index 318aa3cb3ff3348f5724ba14344156c0a5bd702c..f89ebc6e731a5029c98b40fbb3ab00df98c9d2d0 100644 (file)
@@ -22,6 +22,7 @@
  */
 #ifndef _PART_H
 #define _PART_H
+
 #include <ide.h>
 
 typedef struct block_dev_desc {
@@ -83,6 +84,14 @@ typedef struct disk_partition {
        uchar   type[32];       /* string type description              */
 } disk_partition_t;
 
+/* Misc _get_dev functions */
+block_dev_desc_t* get_dev(char* ifname, int dev);
+block_dev_desc_t* ide_get_dev(int dev);
+block_dev_desc_t* scsi_get_dev(int dev);
+block_dev_desc_t* usb_stor_get_dev(int dev);
+block_dev_desc_t* mmc_get_dev(int dev);
+block_dev_desc_t* systemace_get_dev(int dev);
+
 /* disk/part.c */
 int get_partition_info (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
 void print_part (block_dev_desc_t *dev_desc);