Skip to contentSkip to conversation

rombios: add support for special CHS layout (spt=32)

PATCH DuanZhenzhong 2 participants 3 messages Dec 7, 2012 – Dec 10, 2012

lore
Share & tools
lore
#0 lore raw

When booting up windows VM which converted by dd scsi disk, it fails with "Error Loading Operating System", root cause is rombios doesn't simulate disk's logical CHS properly. Real bios uses spt=32 here.

tools/firmware/rombios/rombios.c +28 -8
@@ -2674,6 +2674,8 @@ void ata_detect( )
      Bit32u sectors_low, sectors_high;
      Bit16u cylinders, heads, spt, blksize;
      Bit8u  translation, removable, mode;
+      Bit8u i;
+      Bit8u *p;
 
      // default mode to PIO16
      mode = ATA_MODE_PIO16;
@@ -2738,14 +2740,32 @@ void ata_detect( )
        case ATA_TRANSLATION_NONE:
          break;
        case ATA_TRANSLATION_LBA:
-          spt = 63;
-          sectors_low /= 63;
-          heads = sectors_low / 1024;
-          if (heads>128) heads = 255;
-          else if (heads>64) heads = 128;
-          else if (heads>32) heads = 64;
-          else if (heads>16) heads = 32;
-          else heads=16;
+          spt = heads = 0;
+          if (ata_cmd_data_in(device,ATA_CMD_READ_SECTORS, 1, 0, 0, 1, 0L, 0L, get_SS(),buffer) !=0 )
+            BX_PANIC("ata-detect: Failed to read first sector\n");
+          for(i=0; i<4; i++) {
+            p = buffer + 0x1be + i * 16;
+            if (read_dword(get_SS(), p+12) && read_byte(get_SS(), p+5)) {
+              /* We make the assumption that the partition terminates on
+                 a cylinder boundary */
+              heads = read_byte(get_SS(), p+5) + 1;
+              spt = read_byte(get_SS(), p+6) & 63;
+              if (spt != 0)
+                break;
+            }
+          }
+          if (spt == 32) {
+            sectors_low /= spt;
+          } else {
+            spt = 63;
+            sectors_low /= 63;
+            heads = sectors_low / 1024;
+            if (heads>128) heads = 255;
+            else if (heads>64) heads = 128;
+            else if (heads>32) heads = 64;
+            else if (heads>16) heads = 32;
+            else heads=16;
+          }
          cylinders = sectors_low / heads;
          break;
        case ATA_TRANSLATION_RECHS:
#1 lore raw
Quoted 28 lines
Quoted 1 line
Quoted 1 line · DuanZhenzhong

When booting up windows VM which converted by dd scsi disk, it fails with "Error Loading Operating System", root cause is rombios doesn't simulate disk's
logical CHS properly. Real bios uses spt=32 here.

tools/firmware/rombios/rombios.c +2 -6
@@ -2674,6 +2674,8 @@ void ata_detect( )
       Bit32u sectors_low, sectors_high;
       Bit16u cylinders, heads, spt, blksize;
       Bit8u  translation, removable, mode;
+      Bit8u i;
+      Bit8u *p;
 
       // default mode to PIO16
       mode = ATA_MODE_PIO16;
@@ -2738,14 +2740,32 @@ void ata_detect( )
         case ATA_TRANSLATION_NONE:
           break;
         case ATA_TRANSLATION_LBA:
-          spt = 63;
-          sectors_low /= 63;
-          heads = sectors_low / 1024;
-          if (heads>128) heads = 255;
-          else if (heads>64) heads = 128;
-          else if (heads>32) heads = 64;

tools/firmware/rombios/rombios.c void ata_detect( ) · line 2750

Quoted 10 lines
tools/firmware/rombios/rombios.c +8 -2
-          else if (heads>16) heads = 32;
-          else heads=16;
+          spt = heads = 0;
+          if (ata_cmd_data_in(device,ATA_CMD_READ_SECTORS, 1, 0, 0, 1, 0L, 0L, get_SS(),buffer) !=0 )
+            BX_PANIC("ata-detect: Failed to read first sector\n");
+          for(i=0; i<4; i++) {
+            p = buffer + 0x1be + i * 16;
+            if (read_dword(get_SS(), p+12) && read_byte(get_SS(), p+5)) {
+              /* We make the assumption that the partition terminates on
+                 a cylinder boundary */

Which certainly isn't a generally correct assumption, so I strongly recommend against basing any decisions on that.

Jan

Quoted 27 lines
tools/firmware/rombios/rombios.c +18 -0
+              heads = read_byte(get_SS(), p+5) + 1;
+              spt = read_byte(get_SS(), p+6) & 63;
+              if (spt != 0)
+                break;
+            }
+          }
+          if (spt == 32) {
+            sectors_low /= spt;
+          } else {
+            spt = 63;
+            sectors_low /= 63;
+            heads = sectors_low / 1024;
+            if (heads>128) heads = 255;
+            else if (heads>64) heads = 128;
+            else if (heads>32) heads = 64;
+            else if (heads>16) heads = 32;
+            else heads=16;
+          }
           cylinders = sectors_low / heads;
           break;
         case ATA_TRANSLATION_RECHS:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 41 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · DuanZhenzhong

When booting up windows VM which converted by dd scsi disk, it fails with "Error Loading Operating System", root cause is rombios doesn't simulate disk's
logical CHS properly. Real bios uses spt=32 here.

tools/firmware/rombios/rombios.c +2 -6
@@ -2674,6 +2674,8 @@ void ata_detect( )
        Bit32u sectors_low, sectors_high;
        Bit16u cylinders, heads, spt, blksize;
        Bit8u  translation, removable, mode;
+      Bit8u i;
+      Bit8u *p;
 
        // default mode to PIO16
        mode = ATA_MODE_PIO16;
@@ -2738,14 +2740,32 @@ void ata_detect( )
          case ATA_TRANSLATION_NONE:
            break;
          case ATA_TRANSLATION_LBA:
-          spt = 63;
-          sectors_low /= 63;
-          heads = sectors_low / 1024;
-          if (heads>128) heads = 255;
-          else if (heads>64) heads = 128;
-          else if (heads>32) heads = 64;

tools/firmware/rombios/rombios.c void ata_detect( ) · line 2750

Quoted 10 lines
tools/firmware/rombios/rombios.c +8 -2
-          else if (heads>16) heads = 32;
-          else heads=16;
+          spt = heads = 0;
+          if (ata_cmd_data_in(device,ATA_CMD_READ_SECTORS, 1, 0, 0, 1, 0L, 0L, get_SS(),buffer) !=0 )
+            BX_PANIC("ata-detect: Failed to read first sector\n");
+          for(i=0; i<4; i++) {
+            p = buffer + 0x1be + i * 16;
+            if (read_dword(get_SS(), p+12) && read_byte(get_SS(), p+5)) {
+              /* We make the assumption that the partition terminates on
+                 a cylinder boundary */

Which certainly isn't a generally correct assumption, so I strongly recommend against basing any decisions on that.

Quoted 1 line

Jan

Thanks for comment. Are we the first facing this bug? Is there any workaround for this issue?
zduan