Skip to contentSkip to conversation

pandaboard boot issue

PATCH Applied Fabian van der Werf 2 participants 4 messages Oct 8, 2011 – Oct 9, 2011 libata

lore
Share & tools
lore
#0 lore raw

Hi,

I ran into problems trying to boot the pandaboard, which I think is the same others reported on this list. After printing the pandaboard revision number execution simply stops. I traced the problem to an unaligned access in disk_register_partitions(). Barebox loads first sector of the disk in memory. The offset of the partition table is 446 (decimal) which causes the entire partition table to be unaligned.

Below is a simple patch. Though, I am not sure whether this is the right fix, because this would affect all arm platforms and I would expect that such a bug would be noted earlier. I fiddled a little with the alignment bit in the System Control Register, but without success. I have to admit that I don't yet fully understand the behaviour of this bit.

Does someone else have any ideas? Or is my patch acceptable?

Kind regards,

Fabian van der Werf

From f98e14b971e0269251d8694be4c7b0254a30bc52 Mon Sep 17 00:00:00 2001
From: Fabian van der Werf <[email protected]>
Date: Sat, 8 Oct 2011 13:34:30 +0200
Subject: [PATCH] Fixed unaligned access

---
 drivers/ata/disk_drive.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
drivers/ata/disk_drive.c +1 -0
index 14b5e66..6a5dc87 100644
@@ -38,6 +38,7 @@
 #include <malloc.h>
 #include <common.h>
 #include <block.h>
+#include <asm/unaligned.h>
 
 /**
  * Description of one partition table entry (D*S type)
@@ -97,25 +98,29 @@ static int disk_register_partitions(struct device_d

*dev, struct partition_entry

     int part_order[4] = {0, 1, 2, 3};
     int i, rc;
     char drive_name[16], partition_name[19];

+ u32 partition_start, partition_size;

     /* TODO order the partitions */

     for (i = 0; i < 4; i++) {

+ partition_start =
get_unaligned(&table[part_order[i]].partition_start);
+ partition_size =
get_unaligned(&table[part_order[i]].partition_size); +

         sprintf(drive_name, "%s%d", dev->name, dev->id);
         sprintf(partition_name, "%s%d.%d", dev->name, dev->id, i);

- if (table[part_order[i]].partition_start != 0) {
+ if (partition_start != 0) {
#if 1
/* ignore partitions we can't handle due to 32 bit limits */
- if (table[part_order[i]].partition_start > 0x7fffff)
+ if (partition_start > 0x7fffff)

                 continue;
-            if (table[part_order[i]].partition_size > 0x7fffff)
+            if (partition_size > 0x7fffff)
                 continue;
 #endif
             dev_dbg(dev, "Registering partition %s to drive %s\n",
                 partition_name, drive_name);
             rc = devfs_add_partition(drive_name,
-                table[part_order[i]].partition_start * SECTOR_SIZE,
-                table[part_order[i]].partition_size * SECTOR_SIZE,
+                partition_start * SECTOR_SIZE,
+                partition_size * SECTOR_SIZE,
                 DEVFS_PARTITION_FIXED, partition_name);
             if (rc != 0)
                 dev_err(dev, "Failed to register partition %s (%d)\n",

partition_name, rc);

Signature · 1 line
1.7.0.4

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw
Quoted 10 lines · Fabian van der Werf

Hi,

I ran into problems trying to boot the pandaboard, which I think is the same others reported on this list. After printing the pandaboard revision number execution simply stops. I traced the problem to an unaligned access in disk_register_partitions(). Barebox loads first sector of the disk in memory. The offset of the partition table is 446 (decimal) which causes the entire partition table to be unaligned.

Quoted 7 lines

Below is a simple patch. Though, I am not sure whether this is the right fix, because this would affect all arm platforms and I would expect that such a bug would be noted earlier. I fiddled a little with the alignment bit in the System Control Register, but without success. I have to admit that I don't yet fully understand the behaviour of this bit.

Does someone else have any ideas? Or is my patch acceptable?

The patch looks good to me. Unfortunately your mailer wraps the lines so your patch won't apply. Can you fix and resend this?

Thanks
Sascha

Quoted 74 lines

Kind regards,

Fabian van der Werf

From f98e14b971e0269251d8694be4c7b0254a30bc52 Mon Sep 17 00:00:00 2001
From: Fabian van der Werf <[email protected]>
Date: Sat, 8 Oct 2011 13:34:30 +0200
Subject: [PATCH] Fixed unaligned access

---
 drivers/ata/disk_drive.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
drivers/ata/disk_drive.c +10 -5
index 14b5e66..6a5dc87 100644
@@ -38,6 +38,7 @@
 #include <malloc.h>
 #include <common.h>
 #include <block.h>
+#include <asm/unaligned.h>
 
 /**
  * Description of one partition table entry (D*S type)
@@ -97,25 +98,29 @@ static int disk_register_partitions(struct device_d
 *dev, struct partition_entry
     int part_order[4] = {0, 1, 2, 3};
     int i, rc;
     char drive_name[16], partition_name[19];
+    u32 partition_start, partition_size;
 
     /* TODO order the partitions */
 
     for (i = 0; i < 4; i++) {
+        partition_start =
 get_unaligned(&table[part_order[i]].partition_start);
+        partition_size  =
 get_unaligned(&table[part_order[i]].partition_size);
+
         sprintf(drive_name, "%s%d", dev->name, dev->id);
         sprintf(partition_name, "%s%d.%d", dev->name, dev->id, i);
-        if (table[part_order[i]].partition_start != 0) {
+        if (partition_start != 0) {
 #if 1
 /* ignore partitions we can't handle due to 32 bit limits */
-            if (table[part_order[i]].partition_start > 0x7fffff)
+            if (partition_start > 0x7fffff)
                 continue;
-            if (table[part_order[i]].partition_size > 0x7fffff)
+            if (partition_size > 0x7fffff)
                 continue;
 #endif
             dev_dbg(dev, "Registering partition %s to drive %s\n",
                 partition_name, drive_name);
             rc = devfs_add_partition(drive_name,
-                table[part_order[i]].partition_start * SECTOR_SIZE,
-                table[part_order[i]].partition_size * SECTOR_SIZE,
+                partition_start * SECTOR_SIZE,
+                partition_size * SECTOR_SIZE,
                 DEVFS_PARTITION_FIXED, partition_name);
             if (rc != 0)
                 dev_err(dev, "Failed to register partition %s (%d)\n",

partition_name, rc);

Signature · 6 lines
1.7.0.4

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 1/1 Fixed unaligned access

---
 drivers/ata/disk_drive.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
drivers/ata/disk_drive.c +10 -5
index 14b5e66..6a5dc87 100644
@@ -38,6 +38,7 @@
 #include <malloc.h>
 #include <common.h>
 #include <block.h>
+#include <asm/unaligned.h>
 
 /**
  * Description of one partition table entry (D*S type)
@@ -97,25 +98,29 @@ static int disk_register_partitions(struct device_d *dev, struct partition_entry
 	int part_order[4] = {0, 1, 2, 3};
 	int i, rc;
 	char drive_name[16], partition_name[19];
+	u32 partition_start, partition_size;
 
 	/* TODO order the partitions */
 
 	for (i = 0; i < 4; i++) {
+		partition_start = get_unaligned(&table[part_order[i]].partition_start);
+		partition_size  = get_unaligned(&table[part_order[i]].partition_size);
+
 		sprintf(drive_name, "%s%d", dev->name, dev->id);
 		sprintf(partition_name, "%s%d.%d", dev->name, dev->id, i);
-		if (table[part_order[i]].partition_start != 0) {
+		if (partition_start != 0) {
 #if 1
 /* ignore partitions we can't handle due to 32 bit limits */
-			if (table[part_order[i]].partition_start > 0x7fffff)
+			if (partition_start > 0x7fffff)
 				continue;
-			if (table[part_order[i]].partition_size > 0x7fffff)
+			if (partition_size > 0x7fffff)
 				continue;
 #endif
 			dev_dbg(dev, "Registering partition %s to drive %s\n",
 				partition_name, drive_name);
 			rc = devfs_add_partition(drive_name,
-				table[part_order[i]].partition_start * SECTOR_SIZE,
-				table[part_order[i]].partition_size * SECTOR_SIZE,
+				partition_start * SECTOR_SIZE,
+				partition_size * SECTOR_SIZE,
 				DEVFS_PARTITION_FIXED, partition_name);
 			if (rc != 0)
 				dev_err(dev, "Failed to register partition %s (%d)\n", partition_name, rc);
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#3 lore raw

Re: [PATCH] Fixed unaligned access

Quoted 3 lines · Fabian van der Werf
---
 drivers/ata/disk_drive.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

Applied to master.

Sascha

Quoted 52 lines
drivers/ata/disk_drive.c +10 -5
index 14b5e66..6a5dc87 100644
@@ -38,6 +38,7 @@
 #include <malloc.h>
 #include <common.h>
 #include <block.h>
+#include <asm/unaligned.h>
 
 /**
  * Description of one partition table entry (D*S type)
@@ -97,25 +98,29 @@ static int disk_register_partitions(struct device_d *dev, struct partition_entry
 	int part_order[4] = {0, 1, 2, 3};
 	int i, rc;
 	char drive_name[16], partition_name[19];
+	u32 partition_start, partition_size;
 
 	/* TODO order the partitions */
 
 	for (i = 0; i < 4; i++) {
+		partition_start = get_unaligned(&table[part_order[i]].partition_start);
+		partition_size  = get_unaligned(&table[part_order[i]].partition_size);
+
 		sprintf(drive_name, "%s%d", dev->name, dev->id);
 		sprintf(partition_name, "%s%d.%d", dev->name, dev->id, i);
-		if (table[part_order[i]].partition_start != 0) {
+		if (partition_start != 0) {
 #if 1
 /* ignore partitions we can't handle due to 32 bit limits */
-			if (table[part_order[i]].partition_start > 0x7fffff)
+			if (partition_start > 0x7fffff)
 				continue;
-			if (table[part_order[i]].partition_size > 0x7fffff)
+			if (partition_size > 0x7fffff)
 				continue;
 #endif
 			dev_dbg(dev, "Registering partition %s to drive %s\n",
 				partition_name, drive_name);
 			rc = devfs_add_partition(drive_name,
-				table[part_order[i]].partition_start * SECTOR_SIZE,
-				table[part_order[i]].partition_size * SECTOR_SIZE,
+				partition_start * SECTOR_SIZE,
+				partition_size * SECTOR_SIZE,
 				DEVFS_PARTITION_FIXED, partition_name);
 			if (rc != 0)
 				dev_err(dev, "Failed to register partition %s (%d)\n", partition_name, rc);
Signature · 1 line
1.7.0.4
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox