This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

redboot ide tweaks


Speed up boot when IDE controller has no devices attached.
Also workaround toolchain problem with optimizing an
unaligned 4-byte memcpy into a 32-bit load.

--Mark


diff -u -p -5 -r1.210 ChangeLog
--- redboot/current/ChangeLog	25 Sep 2004 10:49:42 -0000	1.210
+++ redboot/current/ChangeLog	27 Sep 2004 18:34:23 -0000
@@ -1,5 +1,11 @@
+2004-09-27  Mark Salter  <msalter@redhat.com>
+
+	* src/fs/ide.c (ide_presence_detect): New function.
+	* src/fs/disk.c (u32_unaligned): New function to read unaligned words.
+	(find_dos_partitions): Use u32_unaligned instead of memcpy.
+
 2004-9-25   Andrew Lunn <andrew.lunn@ascom.ch>
 
 	* doc/redboot_install.sgml: Added installation information for the
 	Atmel AT91 JTST board provided by Andrea Michelotti
 	
Index: redboot/current/src/fs/disk.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/fs/disk.c,v
retrieving revision 1.10
diff -u -p -5 -r1.10 disk.c
--- redboot/current/src/fs/disk.c	18 Jul 2002 20:05:23 -0000	1.10
+++ redboot/current/src/fs/disk.c	27 Sep 2004 18:34:23 -0000
@@ -6,11 +6,11 @@
 //
 //==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
-// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Red Hat, Inc.
 // Copyright (C) 2002 Gary Thomas
 //
 // eCos 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 or (at your option) any later version.
@@ -72,10 +72,24 @@ RedBoot_cmd("disks", 
     );
 
 static disk_t disk_table[CYGNUM_REDBOOT_MAX_DISKS];
 static int    disk_count = 0;
 
+static inline cyg_uint32
+u32_unaligned(void *p)
+{
+    cyg_uint32 val;
+    char *d = (char *)&val;
+    char *s = p;
+    int i;
+
+    for (i = 0; i < 4; i++)
+	*d++ = *s++;
+
+    return val;
+}
+
 static int
 find_dos_partitions(disk_t *d, cyg_uint8 *mbr)
 {
     cyg_uint32 s, n, tmp;
     struct mbr_partition *p;
@@ -84,15 +98,12 @@ find_dos_partitions(disk_t *d, cyg_uint8
     p = (struct mbr_partition *)(mbr + MBR_PTABLE_OFFSET);
 
     // Look for primary partitions
     for (i = 0; i < 4 && i < CYGNUM_REDBOOT_MAX_PARTITIONS; i++) {
 
-	// Have to use memcpy because of alignment
-	memcpy(&tmp, p->start_sect, 4);
-	s = SWAB_LE32(tmp);
-	memcpy(&tmp, p->nr_sects, 4);
-	n = SWAB_LE32(tmp);
+	s = SWAB_LE32(u32_unaligned(p->start_sect));
+	n = SWAB_LE32(u32_unaligned(p->nr_sects));
 
 	if (s && n) {
 	    ++found;
 	    d->partitions[i].disk = d;
 	    d->partitions[i].start_sector = s;
@@ -127,15 +138,12 @@ find_dos_partitions(disk_t *d, cyg_uint8
 		    if (SWAB_LE16(magic) != MBR_MAGIC)
 			break;
 
 		    p = (struct mbr_partition *)((char *)buf + MBR_PTABLE_OFFSET);
 
-		    // Have to use memcpy because of alignment
-		    memcpy(&tmp, p->start_sect, 4);
-		    s = SWAB_LE32(tmp);
-		    memcpy(&tmp, p->nr_sects, 4);
-		    n = SWAB_LE32(tmp);
+		    s = SWAB_LE32(u32_unaligned(p->start_sect));
+		    n = SWAB_LE32(u32_unaligned(p->nr_sects));
 
 		    if (s && n) {
 			++found;
 			d->partitions[nextp].disk = d;
 			d->partitions[nextp].start_sector = s + xoffset;
@@ -143,14 +151,12 @@ find_dos_partitions(disk_t *d, cyg_uint8
 			d->partitions[nextp].systype = p->sys_ind;
 			d->partitions[nextp].bootflag = p->boot_ind;
 		    }
 		    ++p;
 
-		    memcpy(&tmp, p->start_sect, 4);
-		    s = SWAB_LE32(tmp);
-		    memcpy(&tmp, p->nr_sects, 4);
-		    n = SWAB_LE32(tmp);
+		    s = SWAB_LE32(u32_unaligned(p->start_sect));
+		    n = SWAB_LE32(u32_unaligned(p->nr_sects));
 
 		    // more extended partitions?
 		    if (p->sys_ind != SYSTYPE_EXTENDED || !s || !n)
 			break;
 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]