Skip to contentSkip to conversation

miscellaneous cleanup patches

U-Boot-Users New Grant Likely 2 participants 7 messages Feb 14, 2007 Arm/Zynq architecture

lore
Share & tools
lore
#0 lore raw

Here's a bunch of cleanup patches from my local tree. I've cherry-picked the ones that I think are ready to be merged. I've got a bunch more in the works; but I figure it will be less painless if I send them in smaller chunks.

I've tested these changes on my xilinx ppc405 platform, and on a lite5200b.

Can someone who has a Dataflash part test the print_buffer patch for me? There shouldn't be any functional changes, but I don't have the board to test it.

These patches can also be pulled from the merge branch of my git tree:

git://git.secretlab.ca/srv/git-trees/public/git/u-boot.git#merge
--or--
http://git.secretlab.ca/git/u-boot.git#merge

Thanks,
g.

board/esd/common/auto_update.c          |    3 +-
board/mcc200/auto_update.c              |    3 +-
board/mpl/mip405/mip405.c               |    3 -
board/trab/auto_update.c                |    1 -
board/xilinx/ml300/Makefile             |    2 +-
board/xilinx/ml300/ml300.c              |    2 +-
board/xilinx/ml300/serial.c             |    3 +-
board/xilinx/xilinx_enet/emac_adapter.c |    2 +-
board/xilinx/xilinx_enet/xemac.h        |    2 +-
board/xilinx/xilinx_enet/xemac_g.c      |    2 +-
board/xilinx/xilinx_iic/iic_adapter.c   |    2 +-
common/cmd_ext2.c                       |   40 +----------------
common/cmd_fat.c                        |   37 +----------------
common/cmd_ide.c                        |    8 +++-
common/cmd_mem.c                        |   64 ++++++----------------------
common/cmd_reiser.c                     |   40 +----------------
common/cmd_scsi.c                       |    2 +-
common/cmd_usb.c                        |    1 +
common/ft_build.c                       |    6 +--
common/usb_storage.c                    |    3 +-
cpu/pxa/mmc.c                           |    2 +-
disk/part.c                             |   49 +++++++++++++++++++++
include/common.h                        |    2 +
include/ide.h                           |    6 +-
include/part.h                          |    9 ++++
lib_generic/display_options.c           |   70 +++++++++++++++++++++++++++++++
26 files changed, 176 insertions(+), 188 deletions(-)
#1 lore raw

PATCH 1/4 Merge common get_dev() routines for block devices

Each of the filesystem drivers duplicate the get_dev routine. This change merges them into a single function in part.c

---
 board/esd/common/auto_update.c |    3 +-
 board/mcc200/auto_update.c     |    3 +-
 board/mpl/mip405/mip405.c      |    3 --
 board/trab/auto_update.c       |    1 -
 common/cmd_ext2.c              |   40 ++------------------------------
 common/cmd_fat.c               |   37 +-----------------------------
 common/cmd_ide.c               |    8 +++++-
 common/cmd_reiser.c            |   40 ++------------------------------
 common/cmd_scsi.c              |    2 +-
 common/cmd_usb.c               |    1 +
 common/usb_storage.c           |    3 +-
 cpu/pxa/mmc.c                  |    2 +-
 disk/part.c                    |   49 ++++++++++++++++++++++++++++++++++++++++
 include/ide.h                  |    6 ++--
 include/part.h                 |    9 +++++++
 15 files changed, 82 insertions(+), 125 deletions(-)
board/esd/common/auto_update.c +1 -2
index 5cd3423..001fd68 100644
@@ -33,6 +33,7 @@ #include <image.h>
 #include <asm/byteorder.h>
 #include <linux/mtd/nand_legacy.h>
 #include <fat.h>
+#include <part.h>
 
 #include "auto_update.h"
 
@@ -71,8 +72,6 @@ #endif
 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 */
board/mcc200/auto_update.c +1 -2
index f1bb721..d67ad83 100644
@@ -23,6 +23,7 @@ #include <malloc.h>
 #include <image.h>
 #include <asm/byteorder.h>
 #include <usb.h>
+#include <part.h>
 
 #ifdef CFG_HUSH_PARSER
 #include <hush.h>
@@ -134,8 +135,6 @@ extern int i2c_read (unsigned char, unsi
 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)
board/mpl/mip405/mip405.c +0 -3
index 34f3289..1324978 100644
@@ -73,9 +73,6 @@ #include <rtc.h>
 
 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
board/trab/auto_update.c +0 -1
index d2c8d44..f4074ae 100644
@@ -203,7 +203,6 @@ extern int flash_write (char *, ulong, u
 /* 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
common/cmd_ext2.c +3 -37
index 5db42f2..94bd9b6 100644
@@ -33,6 +33,7 @@
  * Ext2fs support
  */
 #include <common.h>
+#include <part.h>
 
 #if (CONFIG_COMMANDS & CFG_CMD_EXT2)
 #include <config.h>
@@ -57,41 +58,6 @@ #else
 #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 fla
 		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 f
 	}
 
 	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);
common/cmd_fat.c +1 -36
index 6844c10..afaf299 100644
@@ -29,6 +29,7 @@ #include <command.h>
 #include <s_record.h>
 #include <net.h>
 #include <ata.h>
+#include <part.h>
 
 #if (CONFIG_COMMANDS & CFG_CMD_FAT)
 
@@ -37,42 +38,6 @@ #undef	DEBUG
 #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;
common/cmd_ide.c +7 -1
index a415502..ebc080c 100644
@@ -31,20 +31,26 @@ #include <watchdog.h>
 #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 @@ #endif
 
 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;
 }
 
 
common/cmd_reiser.c +3 -37
index 508ffcb..09c86e6 100644
@@ -35,6 +35,7 @@ #include <image.h>
 #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
@@ -48,41 +49,6 @@ #else
 #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 f
 		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
 	}
 
 	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;
common/cmd_scsi.c +1 -1
index cc08743..b17bebb 100644
@@ -194,7 +194,7 @@ #endif
 
 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;
 }
 
 
common/cmd_usb.c +1 -0
index 28c05aa..904df71 100644
@@ -28,6 +28,7 @@
 #include <common.h>
 #include <command.h>
 #include <asm/byteorder.h>
+#include <part.h>
 
 #if (CONFIG_COMMANDS & CFG_CMD_USB)
 
common/usb_storage.c +2 -1
index 06ea99b..b4b7914 100644
@@ -56,6 +56,7 @@ #include <asm/processor.h>
 
 
 #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;
 }
 
 
cpu/pxa/mmc.c +1 -1
index f7020ee..c57d0d5 100644
@@ -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;
 }
 
 /*
disk/part.c +49 -0

61 lines not on this page · raw message

include/ide.h +3 -3
index dfef32f..e29ed36 100644
@@ -48,8 +48,8 @@ #endif
  * 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 */
include/part.h +9 -0
index 318aa3c..f89ebc6 100644
@@ -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);
Signature · 1 line
1.4.3.rc2.g0503
#2 lore raw

PATCH 2/4 Use config.h, not xparameters.h, for xilinx targets

Change the xilinx device drivers and board code to include config.h instead of xparameters.h directly. config.h always includes the correct xparameters file. This change reduces the posibility of including the wrong file when adding a new xilinx board port

---
 board/xilinx/ml300/Makefile             |    2 +-
 board/xilinx/ml300/ml300.c              |    2 +-
 board/xilinx/ml300/serial.c             |    3 +--
 board/xilinx/xilinx_enet/emac_adapter.c |    2 +-
 board/xilinx/xilinx_enet/xemac.h        |    2 +-
 board/xilinx/xilinx_enet/xemac_g.c      |    2 +-
 board/xilinx/xilinx_iic/iic_adapter.c   |    2 +-
 7 files changed, 7 insertions(+), 8 deletions(-)
board/xilinx/ml300/Makefile +1 -1
index 02c22fb..05ad235 100644
@@ -28,7 +28,7 @@ ifneq ($(OBJTREE),$(SRCTREE))
 $(shell mkdir -p $(obj)../xilinx_iic)
 endif
 
-INCS		:= -I../ml300 -I../common -I../xilinx_enet -I../xilinx_iic
+INCS		:= -I../common -I../xilinx_enet -I../xilinx_iic
 CFLAGS		+= $(INCS)
 HOST_CFLAGS	+= $(INCS)
 
board/xilinx/ml300/ml300.c +1 -1
index dad562f..60f0bc2 100644
@@ -38,9 +38,9 @@
  *
  */
 
+#include <config.h>
 #include <common.h>
 #include <asm/processor.h>
-#include "xparameters.h"
 
 #ifdef CFG_ENV_IS_IN_EEPROM
 extern void convert_env(void);
board/xilinx/ml300/serial.c +1 -2
index c204b88..9b03f89 100644
@@ -40,8 +40,7 @@ #include <asm/u-boot.h>
 #include <asm/processor.h>
 #include <common.h>
 #include <command.h>
-#include <configs/ml300.h>
-#include "xparameters.h"
+#include <config.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
board/xilinx/xilinx_enet/emac_adapter.c +1 -1
index b30e897..f159cb6 100644
@@ -37,9 +37,9 @@
 *
 ******************************************************************************/
 
+#include <config.h>
 #include <common.h>
 #include <net.h>
-#include "xparameters.h"
 #include "xemac.h"
 
 #if defined(XPAR_EMAC_0_DEVICE_ID)
board/xilinx/xilinx_enet/xemac.h +1 -1
index ed704bf..584cb7a 100644
@@ -257,9 +257,9 @@ #define XEMAC_H			/* by using protection
 
 /***************************** Include Files *********************************/
 
+#include <config.h>
 #include "xbasic_types.h"
 #include "xstatus.h"
-#include "xparameters.h"
 #include "xpacket_fifo_v1_00_b.h"	/* Uses v1.00b of Packet Fifo */
 #include "xdma_channel.h"
 
board/xilinx/xilinx_enet/xemac_g.c +1 -1
index 9340f91..d985157 100644
@@ -43,7 +43,7 @@
 *
 *******************************************************************/
 
-#include "xparameters.h"
+#include <config.h>
 #include "xemac.h"
 
 /*
board/xilinx/xilinx_iic/iic_adapter.c +1 -1
index 163fe15..37dce03 100644
@@ -37,10 +37,10 @@
 *
 ******************************************************************************/
 
+#include <config.h>
 #include <common.h>
 #include <environment.h>
 #include <net.h>
-#include "xparameters.h"
 
 #ifdef CFG_ENV_IS_IN_EEPROM
 #include <i2c.h>
Signature · 1 line
1.4.3.rc2.g0503
#3 lore raw

PATCH 3/4 Move buffer print code from md command to common function

Printing a buffer is a darn useful thing. Move the buffer print code into print_buffer() in lib_generic/

---

 common/cmd_mem.c              |   64 ++++++++-----------------------------
 include/common.h              |    2 +
 lib_generic/display_options.c |   70 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 50 deletions(-)
common/cmd_mem.c +14 -50
index d0fae6b..9fc3d1e 100644
@@ -92,8 +92,9 @@ #define DISP_LINE_LEN	16
 int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	ulong	addr, length;
-	ulong	i, nbytes, linebytes;
-	u_char	*cp;
+#if defined(CONFIG_HAS_DATAFLASH)
+	ulong	nbytes, linebytes;
+#endif
 	int	size;
 	int rc = 0;
 
@@ -128,6 +129,7 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int fl
 			length = simple_strtoul(argv[2], NULL, 16);
 	}
 
+#if defined(CONFIG_HAS_DATAFLASH)
 	/* Print the lines.
 	 *
 	 * We buffer all read data, so we can make sure data is read only
@@ -136,64 +138,26 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int fl
 	nbytes = length * size;
 	do {
 		char	linebuf[DISP_LINE_LEN];
-		uint	*uip = (uint   *)linebuf;
-		ushort	*usp = (ushort *)linebuf;
-		u_char	*ucp = (u_char *)linebuf;
-#ifdef CONFIG_HAS_DATAFLASH
-		int rc;
-#endif
-		printf("%08lx:", addr);
 		linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
-
-#ifdef CONFIG_HAS_DATAFLASH
 		if ((rc = read_dataflash(addr, (linebytes/size)*size, linebuf)) == DATAFLASH_OK){
-			/* if outside dataflash */
-			/*if (rc != 1) {
-				dataflash_perror (rc);
-				return (1);
-			}*/
-			for (i=0; i<linebytes; i+= size) {
-				if (size == 4) {
-					printf(" %08x", *uip++);
-				} else if (size == 2) {
-					printf(" %04x", *usp++);
-				} else {
-					printf(" %02x", *ucp++);
-				}
-				addr += size;
-			}
-
+			print_buffer(addr, linebuf, size, linebytes/size,
+			             DISP_LINE_LEN/size);
 		} else {	/* addr does not correspond to DataFlash */
-#endif
-		for (i=0; i<linebytes; i+= size) {
-			if (size == 4) {
-				printf(" %08x", (*uip++ = *((uint *)addr)));
-			} else if (size == 2) {
-				printf(" %04x", (*usp++ = *((ushort *)addr)));
-			} else {
-				printf(" %02x", (*ucp++ = *((u_char *)addr)));
-			}
-			addr += size;
-		}
-#ifdef CONFIG_HAS_DATAFLASH
+			print_buffer(addr, (void*)addr, size, linebytes/size,
+			             DISP_LINE_LEN/size);
 		}
-#endif
-		puts ("    ");
-		cp = (u_char *)linebuf;
-		for (i=0; i<linebytes; i++) {
-			if ((*cp < 0x20) || (*cp > 0x7e))
-				putc ('.');
-			else
-				printf("%c", *cp);
-			cp++;
-		}
-		putc ('\n');
 		nbytes -= linebytes;
+		addr += linebytes;
 		if (ctrlc()) {
 			rc = 1;
 			break;
 		}
 	} while (nbytes > 0);
+#else
+	/* Print the lines. */
+	print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
+	addr += size*length;
+#endif
 
 	dp_last_addr = addr;
 	dp_last_length = length;
include/common.h +2 -0
index 982d6a8..5b2e71c 100644
@@ -187,6 +187,8 @@ void	hang		(void) __attribute__ ((noretu
 long int initdram (int);
 int	display_options (void);
 void	print_size (ulong, const char *);
+int	print_buffer (ulong addr, void* data, uint width, uint count,
+                      uint linelen);
 
 /* common/main.c */
 void	main_loop	(void);
lib_generic/display_options.c +70 -0

80 lines not on this page · raw message

Signature · 1 line
1.4.3.rc2.g0503
#4 lore raw

PATCH 4/4 Remove local implementation of isprint() in ft_build.c

isprint is already defined in ctype.c

---
 common/ft_build.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
common/ft_build.c +1 -5
index 980e40f..5a0575e 100644
@@ -29,6 +29,7 @@ #include <asm/errno.h>
 #include <stddef.h>
 
 #include <ft_build.h>
+#include <linux/ctype.h>
 
 #undef DEBUG
 
@@ -180,11 +181,6 @@ void ft_finalize_tree(struct ft_cxt *cxt
 	bph->dt_strings_size = cxt->p_end - cxt->p;
 }
 
-static inline int isprint(int c)
-{
-	return c >= 0x20 && c <= 0x7e;
-}
-
 static int is_printable_string(const void *data, int len)
 {
 	const char *s = data;
Signature · 1 line
1.4.3.rc2.g0503
#5 lore raw

PATCH 3/4 Move buffer print code from md commandto common function

In reply to Grant Likely

Looks like your code boils down to:

if ((rc = read_dataflash(addr, (linebytes/size)*size, linebuf)) == DATAFLASH_OK){
print_buffer(addr, linebuf, size, linebytes/size,
DISP_LINE_LEN/size);
} else { /* addr does not correspond to DataFlash */
print_buffer(addr, (void*)addr, size, linebytes/size,
DISP_LINE_LEN/size);
}

Would it not generate less (better) code if you do something like:

rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
p = (rc == DATAFLASH_OK)? linebuf : (void*)addr; /* or an if statement */
print_buffer(addr, p, size, linebytes/size,DISP_LINE_LEN/size);

Best Regards
Ulf Samuelsson

#6 lore raw

PATCH 3/4 Move buffer print code from md commandto common function

Quoted 6 lines · Ulf Samuelsson

Would it not generate less (better) code if you do something like:

rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
p = (rc == DATAFLASH_OK)? linebuf : (void*)addr; /* or an if statement */
print_buffer(addr, p, size, linebytes/size,DISP_LINE_LEN/size);

Yep, that would work. I can make that change.

g.

Signature · 4 lines
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
grant.likely at secretlab.ca
(403) 399-0195