Export to GitHub

grub4dos-chenall - issue #153

Request : Force LBA mode option when accessing drives reported as CHS mode.


Posted on Sep 14, 2013 by Quick Bear

What steps will reproduce the problem?

It may produced by some of 'buggy' BIOSes only. I used ASRock's ConRoe865PE mainboard which this problem occur. It simulates USB Mass storage as floppy or hard drive, but it uses CHS mode for any size of disk. It reports read error when accessing over-8GB region of disk.

What is the expected output? What do you see instead?

With 100GB USB type external hard disk:

grub> geometry (hd0) drive 0x80(CHS): C/H/S=12162/255/63, Sector Count/Size=195382530/512 Partition num: 0, active, Filesystem type is fat16, partition type 0x0C Partition num: 1, Filesystem type is xfs, partition type 0x83 grub> cat --hex (hd0)33000000+1

Error 25: Disk read error

This BIOS supports LBA48 for internal hard disk drive, thus it must be readable with LBA function. There is output with other computer which supports LBA mode for USB stroage (expected result) :

grub> geometry (hd0) drive 0x80(LBA): C/H/S=12162/255/63, Sector Count/Size=195382530/512 Partition num: 0, active, Filesystem type is fat16, partition type 0x0C Partition num: 1, Filesystem type is xfs, partition type 0x83

grub> cat --hex (hd0)33000000+1 00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................ . . .

What version of the product are you using? On what operating system?

GRUB4DOS 0.4.6a 2013-04-06, GRUB4DOS 0.4.6a 2013-07-24

Please provide any additional information below.

Comment #1

Posted on Sep 14, 2013 by Massive Kangaroo

First, you have not proved your mainboard supports LBA for your USB device. What you have proved is that the usb device can be accessed via LBA on another machine. And those two things are completely different.

Your mainboard have no LBA mode access on this usb device, although it might support LBA for all of your internal hard drives.

Nothing special. What you have reported is a common knowledge.

Secondly, and indeed, there exists a varible force_lba to force LBA access for all devices. See code and comments in asm.S. But it is not likely it would have any help for your buggy BIOS.

Comment #2

Posted on Sep 15, 2013 by Quick Bear

There's no problem reading 100GB USB External HDD with LBA function under my 'buggy' BIOS. Please fix this issue. It's maybe bug on GRUB4DOS not in BIOS LBA code.

For checking if my 'buggy' BIOS supports LBA access for USB drives, I installed FreeDOS Kernel in that HDD(1st partition, is accessible via CHS), then boot from it using GRUB4DOS, run DEBUG and create small function performs LBA access. There is list of code.

0B68:0100 MOV AH, 42 ; LBA EXTENDED READ 0B68:0102 MOV DL, 80 ; DRIVE NUMBER 0B68:0104 MOV SI, 0109 ; PACKET ADDRESS 0B68:0107 INT 13 0B68:0109 DB 10 ; PACKET SIZE 0B68:010A DB 00 ; RESERVED 0B68:010B DB 01 00 ; # of block to transfer : 0x0001 (1 sector) 0B68:010D DB 00 02 68 0B ; Transfer buffer Address (0B68:0200) 0B68:0111 DB 00 00 00 04 00 00 00 00 ; Starting absolute block number ; (0x04000000 = 67108864)

-d200 0B68:0200 28 1E 35 AA 93 B6 ... (garbage values for test)

results: -g=100 109 AX=0000 BX=0000 CX=0000 DX=0080 SP=FFFE BP=0000 SI=0109 DI=0000 DS=0B68 ES=0B68 SS=0B68 CS=0B68 IP=0109 NV UP EI NG NZ NA PE NC 0B68:0109 1000 ADC [BX+SI],AL DS:0109=10

-d200 0B68:0200 00 00 00 04 00 .... (marked as LBA 67108864)

I find out there's a BIOS bug that it doesn't return error when trying read sector beyond drive's capacity(I tried 1st absolute sector number to 0x1000000000(68719476736, 32 TiB), it doesn't return error, but read buffer doesn't change), but it isn't important thing because GRUB4DOS returns error. I tried to read numerous sectors, it worked correctly.

Comment #3

Posted on Sep 15, 2013 by Quick Bear

I think that when checking drive access mode, it should be try read with LBA function first if drive capacity exceeds 8-GB CHS limit, reutrn CHS if it doesn't read correctly. it may help under some buggy bios like mine.

Comment #4

Posted on Sep 15, 2013 by Massive Kangaroo

OK, please do an additional test on int13/ah=41h.

Comment #5

Posted on Sep 15, 2013 by Quick Bear

Comment deleted

Comment #6

Posted on Sep 15, 2013 by Quick Bear

Comment deleted

Comment #7

Posted on Sep 15, 2013 by Quick Bear

Comment deleted

Comment #8

Posted on Sep 15, 2013 by Quick Bear

Code:

0B68:0100 MOV AH, 41 0B68:0102 MOV BX, 55AA 0B68:0105 MOV DH, 80 0B68:0107 INT 13

result:

-g=100 109 AX=3000 BX=AA55 CX=0004 DX=0080 SP=FFFE BP=0000 SI=0000 DI=0000 DS=0B68 ES=0B68 SS=0B68 CS=0B68 IP=0109 NV UP EI NG NZ NA PE NC 0B68:0109 7365 JAE 0170

According to Ralf Brown's Interrupt list (http://www.ctyme.com/intr/rb-0706.htm), Extension version is EDD-3.0(AH = 0x30), and it marked only supports EDD functions(AH=48h,AH=4Eh) as bit 2 of CX register set. Although it says this drive doesn't support extended disk access functions (AH=42h-44h,47h,48h) (bit 0 of CX register), but it really does, as I tested before.

I checked AH=0x43(LBA Write function), too. It works correctly despite of bit 0 of CX register isn't set.

With internal 36GB SATA HDD(0x81), that function returns CX=0005 as expected.

Comment #9

Posted on Sep 15, 2013 by Quick Bear

I'm sorry for many modification of that comment... it changes typing error, etc.

Comment #10

Posted on Sep 16, 2013 by Massive Kangaroo

It seems you still have a typo on "MOV DH, 80". I think it should be "MOV DL, 80".

Comment #11

Posted on Sep 16, 2013 by Massive Kangaroo

force_lba is an internal variable of grub4dos. In fact, it only occupies 1 bit field, i.e., the lowest bit of the byte at physical address 0x8211. By default, force_lba is zero.

Before you try to access any drive, you can set it to 1. Concretely, you may place this statement at the very beginning of your preset-menu:

calc *0x8210=*0x8210|0x100

which will set force_lba to 1.

Note that the preset-menu will gain control before all the on-disk menu.lst files.

In case you want to clear force_lba, you can do it in this way:

calc *0x8210=*0x8210&0xFFFFFFFFFFFFFEFF

Note that the calc command uses 64-bit values. Take care.

Please tell if the problem could be solved by setting force_lba to 1 (as explained above). If yes, we would close this issue, and the code in grub4dos kernel need not change.

Comment #12

Posted on Sep 16, 2013 by Quick Bear

Yes, you're right. it should be "MOV DL, 80"... T.T

force_lba setting works, but it can't apply to boot drive. I guess GRUB4DOS's internal menu.lst script causes this. It automatically scans menu.lst in connected drives, and set geometry information for scanned drives.

I tested that cases:

1) External HDD = 0x80(boot drive)

It doesn't work. cat command reports error, too. geometry (0x80) returns "Drive 0x80(CHS)".

2) USB memory stick = 0x80 (with menu.lst), External HDD = 0x81

It works. geometry (0x81) returns "Drive 0x81(LBA)".

3) USB memory stick = 0x80 (without menu.lst), External HDD = 0x81

It doesn't work as case 1. geometry (0x81) returns "Drive 0x81(CHS)".

Once drive access mode set as LBA, it works after force_lba set to 0.

Can you implement geometry command option like --set-access-mode=LBA? I think that changing default value of force_lba variable is dangerous under BIOSes which isn't supports ANY LBA function with USB drives.

Comment #13

Posted on Sep 16, 2013 by Quick Bear

Or, it should ignore functionality information reported by BIOS and test LBA functionality for large disks by default.

Comment #14

Posted on Sep 17, 2013 by Massive Kangaroo

Try this build:

http://bbs.wuyou.com/forum.php?mod=viewthread&tid=315614&extra=page%3D1

and feed back please.

Note that you need not touch the force_lba variable.

Comment #15

Posted on Sep 17, 2013 by Quick Bear

Good! It works fine with USB HDD, Flash memory, etc. But, there's some bug on GRUB4DOS' read sector function, geometry command, and internal pager.

Used flash memory I tested has 30702592 LBA sectors, but GRUB4DOS says some error messages when reading sectors above LBA 30702504.

grub> geometry (0x82) drive 0x82(LBA): C/H/S=1912/255/63, Sector Count/Size=30716280/512

grub> cat --hex (0x82)30702503+1 00000000: 00 00 00 00 ... . . .

It says "Hit Q to quit" (internal pager) and it works.

grub> cat --hex (0x82)30702504+1

Fatal! Inconsistent data read from (0x82)30702504+127

Fatal! Inconsistent data read from (0x82)30702504+127

Fatal! Inconsistent data read from (0x82)30702504+127 00000000: 00 00 00 00 ...

Fatal! Inconsistent data read from (0x82)30702504+127 00000010: 00 00 00 00 ... . . .

It says "Hit Q to quit" (same as above case), but it doesn't. It prints until last line...

Printed contents mixed with error messages is correct(I marked last sector and try to read), but I think that it shouldn't report any errors because I requested only 1 sector. It seems to be read 127 sectors(I guess it is for transfer speed, right?), but there is only 88 sectors to read! Why it doesn't report any error when reading sector 30702503? there is not 127 sectors but only 89 sectors.

I tried to read internal HDD (4500/255/63, reports 72292500 sectors), but it has 72303840 sectors. When I tried to read sector 72303839, it hangs. Reading sector 72292500, 72292501 works.

There is no ANY problems with LBA BIOS call on DEBUG. For any cases, it works correctly as expected.

And, I tested INT13/AH=48H to get drive parameters. It reports correct # of total LBA sector for all drives. Why not GRUB4DOS use this value for geometry command instead of multiples of tuned CHS value? That values are available even extension ver. 1.x!

I'm sorry about this bug reports without create new issue.

Comment #16

Posted on Sep 17, 2013 by Massive Kangaroo

Thank you for your confirmation on the successful test.

Contraposed your additional reports and suggestions, I think it is not time to deal with them. At this moment, you should avoid using those sectors near the end of the device. And int13/ah=48h could cause hangup on some buggy BIOSes, so we must avoid using it.

Close this issue now.

Status: Verified

Labels:
Type-Defect Priority-Medium