Boot from flash
Posted: Tue Nov 12, 2013 6:09 am
Hi,
I have built my custom boot loader that loads a 64-bit kernel, and it is working fine on emulated/virtualized environments: QEMU/KVM, Bochs, and Virtual Box.
The boot loader is installed on a virtual floppy image. My kernel image got relatively big about 15 KB, so what the bootloader does is that it loads the next 17 sectors to the boot sector from the floppy, and then changes the head and loads the next 18 sectos
Now I would like to boot my os from a real laptop that does not have a floppy and I would like to install everything on a bootable USB flash that can start my computer up like in qemu.
So my questions are:
1. What do I need to change in the above code to accomodate that.
2. My laptop supports USB in FDD mode, and if so do I still have do worry about #1. It also suppots HDD mode so which way should i go.
3. Can you please direct me to a tutorial or a diocumentation on how to convert a floppy image and install it on a flash and make it bootable using linux tools?
What I would like to acheive is atlease compile the babystep2 http://wiki.osdev.org/Babystep2 on osdev tutorials and put it on a flash drive that I can start my real laptop on. I already have this tutorial up compiled and writting on floppy.img and working well on emulated/virtualized environments.
I have tried a somethings like writing my floppy.img on the flash using dd but the computer did not even boot and displayed the initial welcome message from my bootloader (I mean before even loading or jumping to my kernel code)
Thanks for the help
Karim.
I have built my custom boot loader that loads a 64-bit kernel, and it is working fine on emulated/virtualized environments: QEMU/KVM, Bochs, and Virtual Box.
The boot loader is installed on a virtual floppy image. My kernel image got relatively big about 15 KB, so what the bootloader does is that it loads the next 17 sectors to the boot sector from the floppy, and then changes the head and loads the next 18 sectos
Code: Select all
;----------Second Stage Boot Loader----------;
SecondStage:
mov ah, 0 ; RESET-command
int 13h ; Call interrupt 13h
mov [drive], dl ; Store boot disk
or ah, ah ; Check for error code after interrupt for reset
jnz cannot_read_sector ; Try again if ah != 0 -> failure on reset
mov ax, 0x0
mov es, ax
mov bx, 0xA000 ; Destination address to store my kernle at 0000:A000
mov ah, 02h ; READ SECTOR-command
mov al, 11h ; Number of sectors to read (0x11 = 17 sectors)
mov dl, [drive] ; Load boot disk
mov ch, 0 ; Cylinder = 0
mov cl, 2 ; Starting Sector = 3
mov dh, 0 ; Head = 1
int 13h ; Call interrupt 13h
jnz cannot_read_sector ; print error message if failed to read
mov ax, 0
mov es, ax
add bx, 0x2200 ; Add to the destination address 17*512 bytes whic is 2200h Destination address now is 0000:C200 where the rest of my code will resiode
mov ah, 02h ; READ SECTOR-command
mov al, 12h ; Number of sectors to read (0x12 = 18 sectors)
mov dl, [drive] ; Load boot disk
mov ch, 0 ; Cylinder = 0
mov cl, 1 ; Starting Sector = 3
mov dh, 1 ; Head = 2
int 13h ; Call interrupt 13h
or ah, ah ; Check for error code
jnz cannot_read_sector ; print error message if failed to read
ret
So my questions are:
1. What do I need to change in the above code to accomodate that.
2. My laptop supports USB in FDD mode, and if so do I still have do worry about #1. It also suppots HDD mode so which way should i go.
3. Can you please direct me to a tutorial or a diocumentation on how to convert a floppy image and install it on a flash and make it bootable using linux tools?
What I would like to acheive is atlease compile the babystep2 http://wiki.osdev.org/Babystep2 on osdev tutorials and put it on a flash drive that I can start my real laptop on. I already have this tutorial up compiled and writting on floppy.img and working well on emulated/virtualized environments.
I have tried a somethings like writing my floppy.img on the flash using dd but the computer did not even boot and displayed the initial welcome message from my bootloader (I mean before even loading or jumping to my kernel code)
Thanks for the help
Karim.