From: Nikunj A Dadhania <hidden> Date: 2015-06-25 06:46:37
Following patchset implements some improvements and cleanup for the
GPT booting code:
patch 1: Simplify the gpt detection code with lesser scopes and add
comments.
patch 2: Introduce 8byte LE helpers: x@-le and x!-le
patch 3: Rename block / read-sector to indicate it a allocated buffer
patch 4: As we need to detect FAT partition, implement a helper that
can be used both from GPT code and "fat-bootblock?"
patch 5: Implement GPT FAT for LVM suport and make GPT detection code
robust
Nikunj A Dadhania (5):
disk-label: simplify gpt-prep-partition? routine
introduce 8-byte LE helpers
disk-label: rename confusing "block" word
disk-label: introduce helper to check fat filesystem
disk-label: add support for booting from GPT FAT partition
slof/fs/little-endian.fs | 6 ++
slof/fs/packages/disk-label.fs | 209 +++++++++++++++++++++++++----------------
2 files changed, 136 insertions(+), 79 deletions(-)
--
2.4.3
@@ -352,42 +352,32 @@ CONSTANT /gpt-part-entrydrop0;-\ Check for GPT PReP partition GUID-9E1A2D38CONSTANTGPT-PREP-PARTITION-1-C612CONSTANTGPT-PREP-PARTITION-2-4316CONSTANTGPT-PREP-PARTITION-3-AA26CONSTANTGPT-PREP-PARTITION-4-8B49521E5A8BCONSTANTGPT-PREP-PARTITION-5+\ Check for GPT PReP partition GUID. Only first 3 blocks are+\ byte-swapped treating last two blocks as contigous for simplifying+\ comparison+9E1A2D38CONSTANTGPT-PREP-PARTITION-1+C612CONSTANTGPT-PREP-PARTITION-2+4316CONSTANTGPT-PREP-PARTITION-3+AA268B49521E5A8BCONSTANTGPT-PREP-PARTITION-4:gpt-prep-partition?( -- true|false )-blockgpt-part-entry>part-type-guidl@-leGPT-PREP-PARTITION-1=IF-blockgpt-part-entry>part-type-guid4+w@-le-GPT-PREP-PARTITION-2=IF-blockgpt-part-entry>part-type-guid6+w@-le-GPT-PREP-PARTITION-3=IF-blockgpt-part-entry>part-type-guid8+w@-GPT-PREP-PARTITION-4=IF-blockgpt-part-entry>part-type-guida+w@-blockgpt-part-entry>part-type-guidc+l@swaplxjoin-GPT-PREP-PARTITION-5=IF-TRUEEXIT-THEN-THEN-THEN-THEN-THEN-FALSE+blockgpt-part-entry>part-type-guid+dupl@-leGPT-PREP-PARTITION-1<>IFdropfalseEXITTHEN+dup4+w@-leGPT-PREP-PARTITION-2<>IFdropfalseEXITTHEN+dup6+w@-leGPT-PREP-PARTITION-3<>IFdropfalseEXITTHEN+8+x@GPT-PREP-PARTITION-4<>IFfalseEXITTHEN+true;:load-from-gpt-prep-partition( addr -- size )-no-gpt?IFdropFALSEEXITTHEN+no-gpt?IFdropfalseEXITTHENdebug-disk-label?IFcr."GPT partition found "crTHEN1read-sectorblockgpt>part-entry-lbal@-leblock-size*toseek-posblockgpt>part-entry-sizel@-letogpt-part-size-blockgpt>num-part-entryl@-ledup0=IFFALSEEXITTHEN+blockgpt>num-part-entryl@-ledup0=IFfalseEXITTHEN1+1?DOseek-pos0seekdropblockgpt-part-sizereaddropgpt-prep-partition?IF
@@ -405,7 +395,7 @@ AA26 CONSTANT GPT-PREP-PARTITION-4THENseek-posgpt-part-sizei*+toseek-posLOOP-FALSE+false;\ Extract the boot loader path from a bootinfo.txt file
From: Nikunj A Dadhania <hidden> Date: 2015-06-25 06:46:39
"block" word is not a block number, actually its an allocated host
address. Rename it to disk-buf along with a associated
size(disk-buf-size=4096) for using during allocation/free.
Also renaming the helper routine read-sector to read-disk-buf. This
routine assumes the address to be disk-buf and only takes sector number
as argument.
Signed-off-by: Nikunj A Dadhania <redacted>
---
slof/fs/packages/disk-label.fs | 78 ++++++++++++++++++++++--------------------
1 file changed, 41 insertions(+), 37 deletions(-)
@@ -126,11 +127,11 @@ CONSTANT /gpt-part-entry;-\ read sector to array "block"-:read-sector( sector-number -- )+\ read sector to array "disk-buf"+:read-disk-buf( sector-number -- )\ block-size is 0x200 on disks, 0x800 on cdrom drivesblock-size*0seekdrop\ seek to sector-blockblock-sizereaddrop\ read sector+disk-bufblock-sizereaddrop\ read sector;:(.part-entry)( part-entry )
@@ -149,35 +150,35 @@ CONSTANT /gpt-part-entry:(.name)r@begincell-dup@<colon>=UNTILxt>namecrtypespace;-:init-block( -- )+:init-disk-buf( -- )s"block-size"[']$call-parentCATCHIFABORT"parenthasnoblock-size."THENtoblock-size-d#4096alloc-mem-dupd#4096erase-toblock+disk-buf-sizealloc-mem+dupdisk-buf-sizeerase+todisk-bufdebug-disk-label?IF-."init-block: block-size="block-size.d."block=0x"blocku.cr+."init-disk-buf: block-size="block-size.d."disk-buf=0x"disk-bufu.crTHEN;:partition>part-entry( partition -- part-entry )-1-/partition-entry*blockmbr>partition-table++1-/partition-entry*disk-bufmbr>partition-table+;:partition>start-sector( partition -- sector-offset )partition>part-entrypart-entry>sector-offsetl@-le;-\ This word returns true if the currently loaded block has _NO_ MBR magic+\ This word returns true if the currently loaded disk-buf has _NO_ MBR magic:no-mbr?( -- true|false )-0read-sector+0read-disk-buf1partition>part-entrypart-entry>idc@ee=IFTRUEEXITTHEN\ GPT partition found-blockmbr>magicw@-leaa55<>+disk-bufmbr>magicw@-leaa55<>;-\ This word returns true if the currently loaded block has _NO_ GPT partition id+\ This word returns true if the currently loaded disk-buf has _NO_ GPT partition id:no-gpt?( -- true|false )-0read-sector+0read-disk-buf1partition>part-entrypart-entry>idc@ee<>;
@@ -197,7 +198,7 @@ CONSTANT /gpt-part-entrypart-entry>sector-offsetl@-le( current sector )duptopart-starttolpart-start( current )BEGIN-part-startread-sector\ read EBR+part-startread-disk-buf\ read EBR1partition>start-sectorIF\ ." Logical Partition found at " part-start .d cr1+
@@ -240,7 +241,7 @@ CONSTANT /gpt-part-entrypart-entry>sector-offsetl@-le( log-part current sector )duptopart-starttolpart-start( log-part current )BEGIN-part-startread-sector\ read EBR+part-startread-disk-buf\ read EBR1partition>start-sectorIF\ first partition entry1+2dup=IF( log-part current )2drop
@@ -306,13 +307,13 @@ CONSTANT /gpt-part-entry:has-iso9660-filesystem( -- TRUE|FALSE )\ Seek to the beginning of logical 2048-byte sector 16\ refer to Chapter C.11.1 in PAPR 2.0 Spec-\ was: 10 read-sector, but this might cause trouble if you+\ was: 10 read-disk-buf, but this might cause trouble if you\ try booting an ISO image from a device with 512b sectors.10800*0seekdrop\ seek to sector-block800readdrop\ read sector+disk-buf800readdrop\ read sector\ Check for CD-ROM volume magic:-blockc@1=-block1+5s"CD001"str=+disk-bufc@1=+disk-buf1+5s"CD001"str=anddupIF800toblock-sizeTHEN;
@@ -374,18 +375,18 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4debug-disk-label?IFcr."GPT partition found "crTHEN-1read-sectorblockgpt>part-entry-lbal@-le+1read-disk-bufdisk-bufgpt>part-entry-lbal@-leblock-size*toseek-pos-blockgpt>part-entry-sizel@-letogpt-part-size-blockgpt>num-part-entryl@-ledup0=IFfalseEXITTHEN+disk-bufgpt>part-entry-sizel@-letogpt-part-size+disk-bufgpt>num-part-entryl@-ledup0=IFfalseEXITTHEN1+1?DOseek-pos0seekdrop-blockgpt-part-sizereaddropgpt-prep-partition?IF+disk-bufgpt-part-sizereaddropgpt-prep-partition?IFdebug-disk-label?IF."GPT PReP partition found "crTHEN-blockgpt-part-entry>first-lbax@-le-blockgpt-part-entry>last-lbax@-le+disk-bufgpt-part-entry>first-lbax@-le+disk-bufgpt-part-entry>last-lbax@-leover-1+( addr offset len )swap( addr len offset )block-size*topart-offset
@@ -548,12 +549,12 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4:try-dos-files( -- found? )no-mbr?IFfalseEXITTHEN-\ block 0 byte 0-2 is a jump instruction in all FAT+\ disk-buf 0 byte 0-2 is a jump instruction in all FAT\ filesystems.\ e9 and eb are jump instructions in x86 assembler.-blockc@e9<>IF-blockc@eb<>-block2+c@90<>or+disk-bufc@e9<>IF+disk-bufc@eb<>+disk-buf2+c@90<>orIFfalseEXITTHENTHENs"fat-files"(interpose-filesystem)
@@ -321,6 +321,14 @@ CONSTANT /gpt-part-entry\ Load from first active DOS boot partition.+:fat-bootblock?( addr -- flag )+\ byte 0-2 of the bootblock is a jump instruction in+\ all FAT filesystems.+\ e9 and eb are jump instructions in x86 assembler.+dupc@e9=IFdroptrueEXITTHEN+dupc@eb=swap2+c@90=and+;+\ NOTE: block-size is always 512 bytes for DOS partition tables.:load-from-dos-boot-partition( addr -- size )
@@ -549,14 +557,7 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4:try-dos-files( -- found? )no-mbr?IFfalseEXITTHEN-\ disk-buf 0 byte 0-2 is a jump instruction in all FAT-\ filesystems.-\ e9 and eb are jump instructions in x86 assembler.-disk-bufc@e9<>IF-disk-bufc@eb<>-disk-buf2+c@90<>or-IFfalseEXITTHEN-THEN+disk-buffat-bootblock?0=IFfalseEXITTHENs"fat-files"(interpose-filesystem)true;
From: Nikunj A Dadhania <hidden> Date: 2015-06-25 06:46:42
For a GPT+LVM combination disk, older bootloader that does not support
LVM, cannot load kernel from LVM.
The patch adds support to read from BASIC_DATA UUID partitions for the
case that the OS installer has installed the CHRP-BOOT config on a FAT
file system.
Makes GPT detection robust
* Check for Protective MBR Magic
* Check for valid GPT Signature
* Boundary check for allocated block size before reading into the
buffer
Signed-off-by: Nikunj A Dadhania <redacted>
---
slof/fs/packages/disk-label.fs | 96 +++++++++++++++++++++++++++++++++---------
1 file changed, 76 insertions(+), 20 deletions(-)
@@ -179,7 +179,8 @@ CONSTANT /gpt-part-entry\ This word returns true if the currently loaded disk-buf has _NO_ GPT partition id:no-gpt?( -- true|false )0read-disk-buf-1partition>part-entrypart-entry>idc@ee<>+1partition>part-entrypart-entry>idc@ee<>IFtrueEXITTHEN+disk-bufmbr>magicw@-leaa55<>;:pc-extended-partition?( part-entry-addr -- true|false )
@@ -267,7 +268,10 @@ CONSTANT /gpt-part-entry:try-dos-partition( -- okay? )\ Read partition table and check magic.-no-mbr?IFcr."No DOS disk-label found."crfalseEXITTHEN+no-mbr?IF+debug-disk-label?IFcr."No DOS disk-label found."crTHEN+falseEXIT+THENcount-dos-logical-partitionsTOdos-logical-partitions
@@ -378,29 +382,80 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4true;-:load-from-gpt-prep-partition( addr -- size )-no-gpt?IFdropfalseEXITTHEN-debug-disk-label?IF-cr."GPT partition found "cr-THEN-1read-disk-bufdisk-bufgpt>part-entry-lbal@-le+\ Check for GPT MSFT BASIC DATA GUID - fat based+EBD0A0A2CONSTANTGPT-BASIC-DATA-PARTITION-1+B9E5CONSTANTGPT-BASIC-DATA-PARTITION-2+4433CONSTANTGPT-BASIC-DATA-PARTITION-3+87C068B6B72699C7CONSTANTGPT-BASIC-DATA-PARTITION-4++:gpt-basic-data-partition?( -- true|false )+disk-bufgpt-part-entry>part-type-guid+dupl@-leGPT-BASIC-DATA-PARTITION-1<>IFdropfalseEXITTHEN+dup4+w@-leGPT-BASIC-DATA-PARTITION-2<>IFdropfalseEXITTHEN+dup6+w@-leGPT-BASIC-DATA-PARTITION-3<>IFdropfalseEXITTHEN+8+x@GPT-BASIC-DATA-PARTITION-4<>IFfalseEXITTHEN+true+;++\+\ GPT Signature+\ ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h)+\+4546492050415254CONSTANTGPT-SIGNATURE++:verify-gpt-partition( -- true | false )+no-gpt?IFfalseEXITTHEN+debug-disk-label?IFcr."GPT partition found "crTHEN+1read-disk-buf+disk-bufgpt>part-entry-lbax@-leblock-size*toseek-posdisk-bufgpt>part-entry-sizel@-letogpt-part-size-disk-bufgpt>num-part-entryl@-ledup0=IFfalseEXITTHEN+gpt-part-sizedisk-buf-size>IF+cr."GPT part size exceeds buffer allocated "cr+falseexit+THEN+disk-bufgpt>signaturex@GPT-SIGNATURE=+;++:load-from-gpt-prep-partition( addr -- size )+verify-gpt-partition0=IFfalseEXITTHEN+disk-bufgpt>num-part-entryl@-ledup0=IFfalseexitTHEN1+1?DOseek-pos0seekdropdisk-bufgpt-part-sizereaddropgpt-prep-partition?IF-debug-disk-label?IF-."GPT PReP partition found "cr-THEN-disk-bufgpt-part-entry>first-lbax@-le-disk-bufgpt-part-entry>last-lbax@-le-over-1+( addr offset len )-swap( addr len offset )-block-size*topart-offset-00seekdrop( addr len )-block-size*read( size )+debug-disk-label?IF."GPT PReP partition found "crTHEN+disk-bufgpt-part-entry>first-lbax@-le( addr first-lba )+disk-bufgpt-part-entry>last-lbax@-le( addr first-lba last-lba)+over-1+( addr first-lba blocks )+swap( addr blocks )+block-size*topart-offset( addr blocks )+00seekdrop( addr blocks )+block-size*read( size )UNLOOPEXIT+THEN+seek-posgpt-part-sizei*+toseek-pos+LOOP+false+;++:try-gpt-dos-partition( -- true | false )+verify-gpt-partition0=IFfalseEXITTHEN+disk-bufgpt>num-part-entryl@-ledup0=IFfalseEXITTHEN+1+1?DO+seek-pos0seekdrop+disk-bufgpt-part-sizereaddrop+gpt-basic-data-partition?IF+debug-disk-label?IF."GPT LINUX DATA partition found "crTHEN+disk-bufgpt-part-entry>first-lbax@-le( first-lba )+duptopart-start( first-lba )+disk-bufgpt-part-entry>last-lbax@-le( first-lba last-lba )+over-1+( first-lba s1 )+block-size*topart-size( first-lba )+block-size*topart-offset( )+00seekdrop( )+disk-bufblock-sizereaddrop( )+disk-buffat-bootblock?0=IFfalseUNLOOPEXITTHEN+trueUNLOOPEXITTHENseek-posgpt-part-sizei*+toseek-posLOOP
From: Thomas Huth <hidden> Date: 2015-06-29 08:44:21
On Thu, 25 Jun 2015 12:15:27 +0530
Nikunj A Dadhania [off-list ref] wrote:
"block" word is not a block number, actually its an allocated host
address. Rename it to disk-buf along with a associated
size(disk-buf-size=4096) for using during allocation/free.
Also renaming the helper routine read-sector to read-disk-buf. This
routine assumes the address to be disk-buf and only takes sector number
as argument.
Signed-off-by: Nikunj A Dadhania <redacted>
---
slof/fs/packages/disk-label.fs | 78 ++++++++++++++++++++++--------------------
1 file changed, 41 insertions(+), 37 deletions(-)
@@ -321,6 +321,14 @@ CONSTANT /gpt-part-entry\ Load from first active DOS boot partition.+:fat-bootblock?( addr -- flag )+\ byte 0-2 of the bootblock is a jump instruction in+\ all FAT filesystems.+\ e9 and eb are jump instructions in x86 assembler.+dupc@e9=IFdroptrueEXITTHEN+dupc@eb=swap2+c@90=and+;+\ NOTE: block-size is always 512 bytes for DOS partition tables.:load-from-dos-boot-partition( addr -- size )
@@ -549,14 +557,7 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4:try-dos-files( -- found? )no-mbr?IFfalseEXITTHEN-\ disk-buf 0 byte 0-2 is a jump instruction in all FAT-\ filesystems.-\ e9 and eb are jump instructions in x86 assembler.-disk-bufc@e9<>IF-disk-bufc@eb<>-disk-buf2+c@90<>or-IFfalseEXITTHEN-THEN+disk-buffat-bootblock?0=IFfalseEXITTHENs"fat-files"(interpose-filesystem)true;
From: Thomas Huth <hidden> Date: 2015-06-29 09:17:34
On Thu, 25 Jun 2015 12:15:29 +0530
Nikunj A Dadhania [off-list ref] wrote:
quoted hunk
For a GPT+LVM combination disk, older bootloader that does not support
LVM, cannot load kernel from LVM.
The patch adds support to read from BASIC_DATA UUID partitions for the
case that the OS installer has installed the CHRP-BOOT config on a FAT
file system.
Makes GPT detection robust
* Check for Protective MBR Magic
* Check for valid GPT Signature
* Boundary check for allocated block size before reading into the
buffer
Signed-off-by: Nikunj A Dadhania <redacted>
---
slof/fs/packages/disk-label.fs | 96 +++++++++++++++++++++++++++++++++---------
1 file changed, 76 insertions(+), 20 deletions(-)
I'd prefer if you could write "true|false" without spaces around the
"|" so that it is clear at a glance that there is only one item on the
stack.
Could you maybe also add a comment above the function that it sets up
gpt-part-size with the size of partition entry and seek-pos with the
position of the partition entry? ...since these are non-obvious
side-effect of this function... All in all, maybe you should also name
the function differently, since it does more than just verifying.
+ no-gpt? IF false EXIT THEN
+ debug-disk-label? IF cr ." GPT partition found " cr THEN
+ 1 read-disk-buf
+ disk-buf gpt>part-entry-lba x@-le
block-size * to seek-pos
disk-buf gpt>part-entry-size l@-le to gpt-part-size
- disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
+ gpt-part-size disk-buf-size > IF
+ cr ." GPT part size exceeds buffer allocated " cr
+ false exit
+ THEN
+ disk-buf gpt>signature x@ GPT-SIGNATURE =
+;
+
+: load-from-gpt-prep-partition ( addr -- size )
+ verify-gpt-partition 0= IF false EXIT THEN
+ disk-buf gpt>num-part-entry l@-le dup 0= IF false exit THEN
1+ 1 ?DO
seek-pos 0 seek drop
disk-buf gpt-part-size read drop gpt-prep-partition? IF
- debug-disk-label? IF
- ." GPT PReP partition found " cr
- THEN
- disk-buf gpt-part-entry>first-lba x@-le
- disk-buf gpt-part-entry>last-lba x@-le
- over - 1+ ( addr offset len )
- swap ( addr len offset )
- block-size * to part-offset
- 0 0 seek drop ( addr len )
- block-size * read ( size )
+ debug-disk-label? IF ." GPT PReP partition found " cr THEN
+ disk-buf gpt-part-entry>first-lba x@-le ( addr first-lba )
+ disk-buf gpt-part-entry>last-lba x@-le ( addr first-lba last-lba)
+ over - 1+ ( addr first-lba blocks )
+ swap ( addr blocks )
The stack comment looks wrong here, should this be:
( addr blocks first-lba )
?
+ verify-gpt-partition 0= IF false EXIT THEN
+ disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
+ 1+ 1 ?DO
+ seek-pos 0 seek drop
+ disk-buf gpt-part-size read drop
+ gpt-basic-data-partition? IF
+ debug-disk-label? IF ." GPT LINUX DATA partition found " cr THEN
I think that string should maybe rather talk about "basic data
partition" instead of "LINUX data partition" ?
+ disk-buf gpt-part-entry>first-lba x@-le ( first-lba )
+ dup to part-start ( first-lba )
+ disk-buf gpt-part-entry>last-lba x@-le ( first-lba last-lba )
+ over - 1+ ( first-lba s1 )
+ block-size * to part-size ( first-lba )
+ block-size * to part-offset ( )
+ 0 0 seek drop ( )
+ disk-buf block-size read drop ( )
+ disk-buf fat-bootblock? 0= IF false UNLOOP EXIT THEN
+ true UNLOOP EXIT
You could simplify the above two lines to:
disk-buf fat-bootblock?
UNLOOP EXIT
quoted hunk
THEN
seek-pos gpt-part-size i * + to seek-pos
LOOP
@@ -492,7 +547,7 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4 debug-disk-label? IF ." Trying CHRP boot " .s cr THEN 1 disk-chrp-boot !- dup load-chrp-boot-file ?dup 0 <> IF .s cr nip EXIT THEN+ dup load-chrp-boot-file ?dup 0 <> IF nip EXIT THEN 0 disk-chrp-boot ! debug-disk-label? IF ." Trying GPT boot " .s cr THEN
@@ -592,6 +647,7 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4 : try-partitions ( -- found? ) try-dos-partition IF try-files EXIT THEN+ try-gpt-dos-partition IF try-files EXIT THEN \ try-iso9660-partition IF try-files EXIT THEN \ ... more partition types here... false
From: Nikunj A Dadhania <hidden> Date: 2015-06-29 11:14:39
Thomas Huth [off-list ref] writes:
On Thu, 25 Jun 2015 12:15:29 +0530
Nikunj A Dadhania [off-list ref] wrote:
quoted
For a GPT+LVM combination disk, older bootloader that does not support
LVM, cannot load kernel from LVM.
The patch adds support to read from BASIC_DATA UUID partitions for the
case that the OS installer has installed the CHRP-BOOT config on a FAT
file system.
Makes GPT detection robust
* Check for Protective MBR Magic
* Check for valid GPT Signature
* Boundary check for allocated block size before reading into the
buffer
Signed-off-by: Nikunj A Dadhania <redacted>
---
slof/fs/packages/disk-label.fs | 96 +++++++++++++++++++++++++++++++++---------
1 file changed, 76 insertions(+), 20 deletions(-)
I'd prefer if you could write "true|false" without spaces around the
"|" so that it is clear at a glance that there is only one item on the
stack.
Sure.
Could you maybe also add a comment above the function that it sets up
gpt-part-size with the size of partition entry and seek-pos with the
position of the partition entry? ...since these are non-obvious
side-effect of this function... All in all, maybe you should also name
the function differently, since it does more than just verifying.
Yes, I was thinking to have this out of verify-gpt-partition, but then
it would be duplication, will rename and add comments accordingly.
quoted
+ no-gpt? IF false EXIT THEN
+ debug-disk-label? IF cr ." GPT partition found " cr THEN
+ 1 read-disk-buf
+ disk-buf gpt>part-entry-lba x@-le
block-size * to seek-pos
disk-buf gpt>part-entry-size l@-le to gpt-part-size
- disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
+ gpt-part-size disk-buf-size > IF
+ cr ." GPT part size exceeds buffer allocated " cr
+ false exit
+ THEN
+ disk-buf gpt>signature x@ GPT-SIGNATURE =
+;
+
+: load-from-gpt-prep-partition ( addr -- size )
+ verify-gpt-partition 0= IF false EXIT THEN
+ disk-buf gpt>num-part-entry l@-le dup 0= IF false exit THEN
1+ 1 ?DO
seek-pos 0 seek drop
disk-buf gpt-part-size read drop gpt-prep-partition? IF
- debug-disk-label? IF
- ." GPT PReP partition found " cr
- THEN
- disk-buf gpt-part-entry>first-lba x@-le
- disk-buf gpt-part-entry>last-lba x@-le
- over - 1+ ( addr offset len )
- swap ( addr len offset )
- block-size * to part-offset
- 0 0 seek drop ( addr len )
- block-size * read ( size )
+ debug-disk-label? IF ." GPT PReP partition found " cr THEN
+ disk-buf gpt-part-entry>first-lba x@-le ( addr first-lba )
+ disk-buf gpt-part-entry>last-lba x@-le ( addr first-lba last-lba)
+ over - 1+ ( addr first-lba blocks )
+ swap ( addr blocks )
The stack comment looks wrong here, should this be:
( addr blocks first-lba )
?
+ verify-gpt-partition 0= IF false EXIT THEN
+ disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
+ 1+ 1 ?DO
+ seek-pos 0 seek drop
+ disk-buf gpt-part-size read drop
+ gpt-basic-data-partition? IF
+ debug-disk-label? IF ." GPT LINUX DATA partition found " cr THEN
I think that string should maybe rather talk about "basic data
partition" instead of "LINUX data partition" ?
Ok
quoted
+ disk-buf gpt-part-entry>first-lba x@-le ( first-lba )
+ dup to part-start ( first-lba )
+ disk-buf gpt-part-entry>last-lba x@-le ( first-lba last-lba )
+ over - 1+ ( first-lba s1 )
+ block-size * to part-size ( first-lba )
+ block-size * to part-offset ( )
+ 0 0 seek drop ( )
+ disk-buf block-size read drop ( )
+ disk-buf fat-bootblock? 0= IF false UNLOOP EXIT THEN
+ true UNLOOP EXIT
You could simplify the above two lines to:
disk-buf fat-bootblock?
UNLOOP EXIT
Right, as we exit in both cases.
quoted
THEN
seek-pos gpt-part-size i * + to seek-pos
LOOP
@@ -492,7 +547,7 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4 debug-disk-label? IF ." Trying CHRP boot " .s cr THEN 1 disk-chrp-boot !- dup load-chrp-boot-file ?dup 0 <> IF .s cr nip EXIT THEN+ dup load-chrp-boot-file ?dup 0 <> IF nip EXIT THEN 0 disk-chrp-boot ! debug-disk-label? IF ." Trying GPT boot " .s cr THEN
@@ -592,6 +647,7 @@ AA268B49521E5A8B CONSTANT GPT-PREP-PARTITION-4 : try-partitions ( -- found? ) try-dos-partition IF try-files EXIT THEN+ try-gpt-dos-partition IF try-files EXIT THEN \ try-iso9660-partition IF try-files EXIT THEN \ ... more partition types here... false