flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Simple Booter Questions

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
I used "jmp $ nop", which produced 3 bytes like edfed and you recommended, but it still gave me the "no bootable partition in table" message. Apparently I need some sort of table (I'll research what edfed told me) and try it with that. I'd hate to have to slim down my bootloader just because of a table at the end Sad. BTW, I never made a list of my goals:

1) Just plain boot it!

2) Initialize 32-bit PMode

3) Load Kernel files (on flash drive)

Pretty simple, but then again I don't have a clue how to load data from a flash drive, nonetheless get the bootloader to even work! I'll go research tables...
Post 29 Mar 2008, 06:16
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17715
Location: In your JS exploiting you and your system
revolution
No, I suggested "jmp word $", you have used a 2-byte jump followed by a nop, that is not a 3-byte jump.
Post 29 Mar 2008, 07:14
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Well, it's not making much of a difference... I made a partition table starting at offset 0x1BE, set the first byte to 0x80 (bootable partition), but it still gives me the "no bootable partiton in table) error when trying to boot. The rest of the partition table is NULLLL, and I don't know how many cyclinders a flash drive has, so I can't make much of a difference there Smile. Here's the basic code so far:
Code:
 use16
 org 0x7c00

    jmp word $

; ---------------------------------------------------------------------------
;
; partition tables
; ---------------------------------------------------------------------------

 rb 446-($-$$)

; partition 1 data table -> 0x1BE

 db 0x80 ; boot indicator = bootable partition
 rb 15

; partition 2 data table -> 0x1CE

 rb 16

; partition 3 data table -> 0x1DE

 rb 16

; partition 4 data table -> 0x1EE

 rb 16

; bootloader signature   -> 0x1FE

 dw 0xaa55
    
Post 29 Mar 2008, 07:32
View user's profile Send private message Visit poster's website Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
AlexP wrote:
I just got a BIOS error when trying to boot from my USB bootloader code, it said "No bootable partiton in table". Yes, it's spelled wrong.
Sounds like its looking for an active MBR partition table, ie one that starts with 80h. A bootable USB device I have uses a MBR but boots as a USB floppy under the BIOS (64MB floppy) Smile
The MBR points at the bootable sector. Mind you it's an oldish BIOS, maybe it works a bit differently from yours.
Post 29 Mar 2008, 07:44
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
... so is there any way to get it my USB booting to work? That's what I'm trying to figure out now...

[edit]: So do I really need to make an entire MBR, tables and all just to get it to load the code into memory?

[edit2]: I just re-formatted the drive for FAT, to dump the bootloader and see what it has. I can tell the jump, with offset 3c, then a nop, then quite a bit of sporatic strings for about 50 bytes or so including "MSDOS5.0" , "L.K.NO NAME" (I've seen that, drive label or something), and "FAT16". This must be the MBR or something, and following that is code, and then user strings until a couple of bytes from 0x55aa. Thought it would help, I can't make anything of it though.

[edit3]: I am woeful to report that my BIOS gives the same error when I tried booting from a FAT16 flash drive. I think this should happen anyways, but I would really love to know if there is ANY way to boot an OS from a flash drive.
Post 29 Mar 2008, 07:49
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17715
Location: In your JS exploiting you and your system
revolution
If your BIOS is also looking for a valid table then just make a dummy table of any size drive (but not zero size) and see if it helps.
Post 29 Mar 2008, 09:12
View user's profile Send private message Visit poster's website Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
The BIOS I have just looks for the partition entry in the MBR on the usb flash. No MBR code is executed. Then it loads the boot sector indicated by the partition table. Might be an idea to check your disk geometry reported by the BIOS. The norm seems to be to have partitions start at start of new cylinder ie cylinder xx, head 0, sector 1. Place your boot sector here (as pointed to by the MBR partition table). Note that geometry reported by windows/BIOS may not be the same. For my 64MB flash, BIOS reports Cyl=11, HD=247 and SPT=47 Shocked
Hope this helps.
Post 29 Mar 2008, 09:35
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
just imagine the future:

the bio$ only accepts a NTFS formated with VISTAHHHHHHHHHHHH.

what an horror!

_________________________________________________________________________

64 MB flash??? but it's at least a 3 years old drive! now the minimal capacity is 1GB. be carefull, a flash drive can be writen only 100 000 times, after, the grids of the MOS-FET are dead.
Post 29 Mar 2008, 14:07
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Here what i have found, first it no good you puting a marker as a bootable partion and then no info to where the partion is.
Here is a example of loading from a partion in DexOS
Code:
 ;----------------------------------------------------; ; Test for FAT16/32.                                 ; ;----------------------------------------------------; mov   esi,MBRFat16n32 ; place in memory where MBR is  add   esi,450 mov   al,byte[ds:esi]     mov   byte[SysID],al  mov   byte[FatID],16  cmp   al,0x04                                   ; we check for Fat16 (offset 450)     je    SysIdOk cmp   al,0x06 je    SysIdOk cmp   al,0x0E je    SysIdOk mov   byte[FatID],32  cmp   al,0x0B                                   ; Fat32       je    SysIdOk cmp   al,0x0C jne   LoadMbrErrorIDSysIdOk: ;----------------------------------------------------; ; Find first partion.                                ; ;----------------------------------------------------;         mov   esi,MBRFat16n32 add   esi,446 mov   al,byte[ds:esi]     cmp   al,80h  jne   LoadMbrError    mov   dx,word[ds:esi]         ; these are used for int 13h read   mov   cx,word[ds:esi+2] ;----------------------------------------------------; ; Store partition start cluster.                     ; ;----------------------------------------------------;        push  eax     mov   esi,MBRFat16n32 add   esi,454 mov   eax,dword[ds:esi]   mov   [partition_start_cluster],eax ;start of partion clust is here   pop   eax     mov   [countHdd],0int13hloop1:  call  FddRead  ; call int 13h  (also convert to LBA to cHs )  jc    HddTryAgain1                                          


So you need to add more info so it know Fat? and the address to load the boot sector from.
I have also heard that it will not boot unless it has a certain OEM ID, i do not know if its true.
See here:
Quote:

offset 3 (OEM ID) must be db "NTFS"
or
offset 24 (Sectors Per Track) must be non zero
offset 26 (Number Of Heads) must be non zero
offset 53 (File System Type) must be db "FAT"

I haven't tried all possible file system acronyms, but it seems
strange that the bios would require a file system identifier in
order for the media to be bootable.


See here for the full code:
http://board.flatassembler.net/topic.php?p=51973#51973

I find the best and easist way is (under win98) format the usb as FAT and click add sys files, this makes it into a startup type disk, you can then add your OS to the autoexe.bat and it will boot it (if its a com or exe file).
Post 29 Mar 2008, 14:21
View user's profile Send private message Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
Alex, if it helps maybe it would be better to FAT format the usb then read sector 0 (MBR) dword offset 1C6 to get the boot sector number. Then you can overwrite it with your own code at the jump offset if you want to keep the FAT file system or just write over the whole boot sector with your own boot sector if you don't.

For instance FAT16 (FS=06) Partition 1 example
Code:
        |   Start    |    |    End     |
    |Act| HD |Cyl/Sec| FS | HD |Cyl/Sec| Sectors B4  | No. Sectors |
1BE |80 | 01 |  0001 | 06 | XX |  XXXX | 3F 00 00 00 | XX XX XX XX |    
The very first partition is normally at cyl 0, head 1, sector 1 but don't worry about that, you can just use the 'sectors before' to work out where the partition starts, in the above case '3F'(63) sectors before so the bootsector will be at absolute sector 63 (the 64th sector).

edfed wrote:
just imagine the future:

the bio$ only accepts a NTFS formated with VISTAHHHHHHHHHHHH.

what an horror!
hehe... I thought things where supposed to be moving towards Extensible Firmware Interface (EFI) for the BIOS and GUID Partition Table (GPT) to replace the MBR. Anybody on here used it yet, what's it like to use / modify?

edfed wrote:
64 MB flash??? but it's at least a 3 years old drive! now the minimal capacity is 1GB. be carefull, a flash drive can be writen only 100 000 times, after, the grids of the MOS-FET are dead.
Yeah, older than 3 years as is most of my stuff Sad Trying to convince myself to buy a new T9300 / Blueray notebook but since I don't really push this PIII to it's limits it's a bit hard to justify other than having a chance to play with 64bit code.
Post 29 Mar 2008, 15:25
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
a good usb drive is the model from cibox (from 1G to 8G), it is supported by 98, then, it is the best choice
Imagei'm not payed by this company, it's not an add, just a suggestion

not expensive, the 1G model cost 7 € in a supermarket.

then, one other way to have it working canbe to read the mbr, save the PT, overwrite the begining with a short boot loader, and a fun is thet you have at least 10 sectors after MBR that are not used by FAT, then, it can contain a little kernel.
it's what i do with my USB KEY.
the MBR is an *autentic* fat mbr.
but as the sectors appears as empty, i wrie on them for testings. and it works, the drive is not in danger. it is both fat, and in hidden, it have a prototype file system.
Post 29 Mar 2008, 16:59
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
I formatted in FAT32, and used
, but I got the same BIOS error: No bootable partition in table. I did as was instructed i that thread, but unfortunately it didn't work.

Can I use an external floppy drive, aka one that connects via USB? I think that would be a heck of a lot easier than fooling around with file systems in a flash drive.
Post 29 Mar 2008, 17:47
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
That depends on your BIOS etc (it may need to emulate as floppy not sure ), i have had many coders, say that my OS works fine with a ext usb floppy drive, but i have not tryed it myself.
Your more than welcome to try my OS, if you have a usb floppy, but my OS has two floppy drivers one that goes to and from realmode and a pmode one, that why it work with USB.
As it works with usb by using int 13h, so you will need to load the whole OS in unrealmode or go to and from realmode from pmode .
http://www.dex4u.com/
Post 29 Mar 2008, 18:56
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Yes, I've seen your OS. I will put the project to the side for now, it was scheduled for many weeks later anyway. I just wanted to get a simple boot going, and I'll re-try later. Thanks everyone!
Post 29 Mar 2008, 19:28
View user's profile Send private message Visit poster's website Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
Alex try this, it's a bit messy but hopefully your USB will boot with 'USB Boot' displayed.
Code:
times 1beh db 0

 db 80h             ;Active
 db 1               ;Start head
 dw 1               ;Start Cyl 0, Sec 1
 db 0BBh            ;File System
 db 0fh             ;End Head
 dw 3fh             ;End Cyl 0, Sec 63
 dd 3fh             ;63 Sectors before
 dd 63*16-1         ;number of sectors
                    ;Size is 500k
 times 510-($-$$) db 0
 dw 0AA55h

 times 63*512-512 db 0

org 7c00h           ;Boot Sector
jmp near Start
times $$-$+11 db 0
BPB:
 dw 512             ;Bytes/sect
 db 1               ;Sect/cluster
 dw 1               ;Reserved Sectors
 db 0               ;Fattys
 dw 0               ;Rootys
 dw 63*16-1         ;few sectors
 db 0f8h            ;Media type
 dw 0               ;Sect/Fat
 dw 63              ;Sect/track
 dw 16              ;Heads
 dd 63              ;Sectors before
 dd 0               ;lots of sectors
 db 0               ;Drive No.
Mess    db 0dh,0ah,'USB Boot',0dh,0ah
MessL=$-Mess

Start:
 mov ax,cs
 mov ds,ax
 mov es,ax
 mov cx,MessL
 mov si,Mess
@@:
 mov ah,0eh
 lodsb
 int 10h
 dec cx
 jnz @b
 mov ah,0
 int 16h
 int 19h

 times 510-($-$$) db 0
 dw 0AA55h    
Don't worry about the size, you can always change that later.
Post 29 Mar 2008, 21:18
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Okay, I'll try it

[edit] I tried it in all three USB modes offered by my BIOS, none worked. Same error.

BIOS = Some Pheonix, I'll find specifics next time

Modes of booting allowed:
1) USB Flash
2) USB Optical Drive
3) USB Hard DIsk Drive
4) INternal Hard Drive
5) Internal Optical Drive
6) Floppy Disk Drive (I have none)
7) Network

PS: Someone told me that 0x1BE actually refers to 0x1BD, because of the 0 offset.

THe utiilty "hex workshop" doesn't let me copy & paste the file, I tried burning using DD before but I don't know if it worked..,.
Post 29 Mar 2008, 22:05
View user's profile Send private message Visit poster's website Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
1) USB Flash should be OK.
0x1BE is an absolute offset and refers to 0x1BE. If you count bytes from offset 0 it would be the 0x1BF byte. If you mean in the statement 'times 1beh db 0' then yes, that would write upto and including offset 0x1BD.
I have not used "hex workshop" or even Vista, so it's hard for me to guess what is going wrong on your system. Windows used to come with it's own crude disk editor in the support tools called dskprobe.exe, don't know if Vista supports this. If you can use it, be very careful not to write to the wrong disk as you could lose some/all of your data. Hopefully you do regular backups. Wink Another utility you may be interested in is PTEDIT32 which will show you if the partition table looks correct and if you set the file system to FAT on the MBR, the boot sector BPB as well.
The dump you sent earlier of the boot sector was 192 bytes out of sync so that the first part was missing. If it was actually like that, and not a slip of the cut and paste, then it would not have worked. Another utility you might try just to get that USB to the boot stage is PeToUSB.

ftp://ftp.symantec.com/public/english_us_canada/tools/pq/utilities/PTEDIT32.zip
http://gocoding.com/projects/petousb/8F0P5/PeToUSB_3.0.0.7.zip
Post 30 Mar 2008, 06:34
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
just for clarification of a normative usage:

the fact that the first element is zero is the "zero based" convention.
there are many others conventions, as the "one based", "three based", "what you want based". etc.

for example, the boot sector is one based in chs, zero based in lba and 07c00h based in the RAM. then, many dumbs errors are made in assembly because of this (don't depend on the level of the coder, just it's not a natural convention). then, take a good care about the base convention, as well in asm and electronics.

it is really one of the main causes of errors.
Post 30 Mar 2008, 06:46
View user's profile Send private message Visit poster's website Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
I had met someone in an IRC called #osdev, and they told me that the offsets were wrong because of the zero-base, I didn't think so though... Apparently the dump is off, I will try the utilities alphonso mentioned, and it looks like the dump is a little off. I used the 'dd' software,
http://www.chrysocome.net/dd
Which writes to a disk starting at the base.

Alphonso: How is it 192 bytes off? I wrote the 512 bytes directly to the base address, and the 'partition table' is supposed to be near the end of that. Well, I'll definitely try some of those utilities. Thanks

[edit]: The first program I tried had an error, "#5 PowerQuest" or something, and the second one cannot find my USB drive! I formatted the USB to Fat (16 kb) with Windows, then restarted the program, and it still could not find it. Windows XP/2003 is required for another utility that website offers, a DOS booter, and it appears they used the same code for both to find the drive. I have Vista so I believe that is the problem.

[anotheredit]: Okay, I poured over MSDN docs, online stuff, and I wrote this to test:
Code:
; ---------------------------------------------------------------------------
;
; AdvEnSta-OS Flash Drive (USB External) Bootloader
;
; Current features:
;
;  - basic boot, string printing
;
; Future add-ons:
;
;  - string writing
;  - 32-bit protected mode conversion
;  - kernel files loading into memory
;
; ---------------------------------------------------------------------------

  use16

; Apparently the MBR goes here? *partition tables

 db 80h             ;Active
 db 1               ;Start head 
 dw 1               ;Start Cyl 0, Sec 1 
 db 0BBh            ;File System 
 db 0fh             ;End Head 
 dw 3fh             ;End Cyl 0, Sec 63 
 dd 3fh             ;63 Sectors before 
 dd 63*16-1         ;number of sectors 
                    ;Size is 500k 

 times 510-($-$$) db 0
 dw 0xaa55

; And here is the partition that the MBR references to load

  times 63*512-512 db 0
  org 0x7c00 ; is this right for partition load?  I don't think so...

; three-byte jump to start of code

    jmp word start

; OEM ID

 db 'MSWIN6.0' ; I don't know...

; BPB (BIOS Parameter Block)

 dw 512        ; Bytes Per Sector
 db 8          ; Sector Per Cluster (test value)
 dw 1          ; Reserved Sectors
 db 2          ; FATs (test value, normally 2)
 dw 512        ; Root Entries
 dw 0          ; Small Sectors
 db 0xF0       ; Media Descriptor (3.5-inch, 2-sided, 18-sector)
 dw 1          ; Sectors Per FAT (test value)
 dw 63         ; Sectors Per Track (test value)
 dw 16         ; Heads
 dd 63         ; Hidden Sectors
 dd 63         ; Large Sectors

; start bootloader code section in sector 63

start:

    mov ax, 0
    mov ds, ax

    mov si, boot_str
@@: mov ah, 0x0e
    lodsb
    or al, al
    jz @f
    int 0x10
    jmp @b

@@: jmp $

boot_str:
 db 'Boot',0

; first FAT goes here I believe. 
    

The first part is from Alphonso, Smile, but I threw in some random values for other parts. I will give you the BIOS name in a second, along with whether it worked. The compiled code was written directly to the base of the drive, double-checked with two utilities for the sector 63 code.

[edit] The code posted above does not work. I selected "USB Flash" in the BIOS, but it reported the same error message. I did, however, get the BIOS name and version:

Name: Phoenix TrustedCore
Version: R0130J9
Post 30 Mar 2008, 14:21
View user's profile Send private message Visit poster's website Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
AlexP wrote:
Alphonso: How is it 192 bytes off? I wrote the 512 bytes directly to the base address, and the 'partition table' is supposed to be near the end of that.
It was late, and I may have slipped with the cut & paste myself, however there was enough to see that it was a boot sector and not a MBR with partition table.

I don't know why those programs didn't work for you, according to what I read they should work with root/admin privilege under Vista, sorry about that.

Okay Alex, I tried DD with the 32k bin file from the source code posted earlier, and it worked Okay for this system. Hardisk1 was my 64MB flash drive.
Code:
dd if=d:\code.bin of=\\?\Device\Harddisk1\Partition0 bs=32k count=1    

AFAIK FAT16 file system is the mostly accepted file system for a USB bootable drive although others will work with certain systems. I really would have thought you would have got to a ntldr missing or other message with just formating the USB with FAT.

Not familiar with your BIOS, but there seems to be an "External Drive Boot" Enable/Disable option, is there also a USB legacy enable? Another thing you can do is try the BOOT MENU function key (at start of bootup), maybe F11 or F8/F12/ESC? etc. You should then see your USB flash if it's recognised by the machine.

You've probably done all those things anyway, just thought I'd mention it.
Post 30 Mar 2008, 17:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.