Making a bootable image

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Making a bootable image

Post by Bonfra »

MichaelPetch wrote:You don't actually print out an error message if you load a sector successfully
Ok I fixed it, the updated code is on github. But still in the real hardware hangs forever.
MichaelPetch wrote:How do you write your image to the USB stick?
I use Rufus
Regards, Bonfra.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making a bootable image

Post by MichaelPetch »

Did you add an error message when the 0xaa55 signature wasn't found? Did it actually find the disk signature of the VBR? Hanging doesn't tell me anything but it is important to know that the sector read actually contains the VBR before jumping to the VBR. If you read garbage into memory (all zeroes or whatever) and jump to it then who knows what it will do.

I don't know anything about RUFUS. Is it writing things as an ISO image? I really don't know. On Windows if I have to write directly to a USB stick I use Chrysocome DD that can be found here http://www.chrysocome.net/dd and in particular this version http://www.chrysocome.net/downloads/dd-0.6beta3.zip which supports an `od=` parameter.

Something like:

Code: Select all

dd if=disk.img od=x: 
where disk.img is the name of your disk image and x: is the actual drive letter you want to write to (make sure you write to the correct drive!). You will have to have admin privileges in Windows for this to work correctly.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Making a bootable image

Post by Bonfra »

MichaelPetch wrote:Did you add an error message when the 0xaa55 signature wasn't found?
Yes, where was just a jump to error now is a jump to a specific error with a print:

Code: Select all

cmp WORD [0x7DFE], 0xAA55   ; Check Boot Signature
jne error.noBootSignature  ; Error if not Boot Signature

...

.noBootSignature:
        mov si, Message.Error.NoBootSignature
        call BiosPrint
        jmp hang
MichaelPetch wrote:Did it actually find the disk signature of the VBR?
Yes it does not print the error so I think it jumps.
MichaelPetch wrote:I don't know anything about RUFUS. Is it writing things as an ISO image?
I used it only for burning ISOs and Floppy images so it could be.

I tryied dd for windows and this is the result:
Image
Yes the prompt is in administrator
Regards, Bonfra.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making a bootable image

Post by MichaelPetch »

Regarding the USB writing problem, I have seen that before as well. You may have to wipe out what is on the USB stick when it comes to existing partitioning info. Follow this guide: https://www.howtogeek.com/235824/how-to ... -problems/ and when finished the `clean` command in the diskpart tool you are finished and you can type `exit` to return back to the command prompt. Try DD after that.

As for it finding the signature but not doing anything after jumping I really don't know. That makes very little sense. If that was the case then I almost wonder if you have the right code in the VBR. The only other thing I can think of is that the original bootloader at 0x7c00 was still present and never replaced by the disk read.
Last edited by MichaelPetch on Tue Nov 03, 2020 1:14 pm, edited 1 time in total.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Making a bootable image

Post by bzt »

Bonfra wrote:
MichaelPetch wrote:How do you write your image to the USB stick?
I use Rufus
If "dd" doesn't work for you (it should), give a try to USBImager. Portable executable, no installation required, about 300K only. But it's a GUI app, so unlike "dd" you can't use it from a Makefile.

About the "dd", instead of "od=i:" does "of=\\.\PhysicalDrive1" work? Just a guess, I'm not a Win expert. Use 0 for the first disk, 1 for the second etc. So if you have three fixed disks, then the USB stick going to be "\\.\PhysicalDrive3".

Cheers,
bzt
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making a bootable image

Post by MichaelPetch »

Chrysocome DD specifically added the `od=` (and `id=`) options and why I recommended the latest beta release that has that option.
Last edited by MichaelPetch on Tue Nov 03, 2020 1:44 pm, edited 1 time in total.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Making a bootable image

Post by bzt »

MichaelPetch wrote:of=\\.\PhysicalDrive1 won't work. It will attempt to access things relative to the volume and not the beginning of the drive.
I seriously doubt that. "PhysicalDrive" has nothing to do with volumes, it reflects the raw drive.
MichaelPetch wrote:This was a common problem for people wanting to overwrite the MBR.
That works with USBImager perfectly. Tested by many users.
MichaelPetch wrote:That was the reason Chrysocome DD specifically added the `od=` (and `id=`) options.
I get that (and it is a pretty cool addition to dd on Win). How about "seek" and "skip"? Specially in combination with "PhysicalDrive" (Just a guess)?

Cheers,
bzt
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Making a bootable image

Post by Bonfra »

bzt wrote: give a try to USBImager
Same problem as rufus, the image is written but the bootloader does not work.
MichaelPetch wrote:You may have to wipe out what is on the USB stick when it comes to existing partitioning info
Following the guide and cleaning the USB stick, change a bit the result, before it failed instantly, (In the previous screenshot 1M) now it advance to a higher number but still stops at some point.
MichaelPetch wrote:I almost wonder if you have the right code in the VBR
The code is in ./boot/boot.asm in the github repo. But if works in QEMU and is just a print it should work.
MichaelPetch wrote: The only other thing I can think of is that the original bootloader at 0x7c00 was still present and never replaced by the disk read.
If this was the case (and has been due to some bugs that I've fixed) it should loop the successful read message since it jumps to itself.

I'm asking a friend to test in his own hardware I'll let you know if it works
Regards, Bonfra.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Making a bootable image

Post by Bonfra »

Bonfra wrote:I'm asking a friend to test in his own hardware I'll let you know if it works
He used his own sandisk USB stick and an old compaq but the problem persist, no "Hello, World!" printed. He used rufus.
Regards, Bonfra.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making a bootable image

Post by MichaelPetch »

Can you humour me and do this.In your MBR you have

Code: Select all

LBA_Packet:
    .packet_size     db 0x10   ; use_transfer_64 ? 10h : 18h
    .reserved        db 0x00   ; always zero    
    .block_cout      dw 0x01   ; number of sectors to read
    .transfer_buffer dd 0x7C00 ; address to load in ram
    .lba_value       dq 0x0    ; LBA addres value 
Change it so it is:

Code: Select all

align 4
LBA_Packet:
    .packet_size     db 0x10   ; use_transfer_64 ? 10h : 18h
    .reserved        db 0x00   ; always zero    
    .block_cout      dw 0x01   ; number of sectors to read
    .transfer_buffer dd 0x7C00 ; address to load in ram
    .lba_value       dq 0x0    ; LBA addres value 
I have added `align 4` before the structure.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making a bootable image

Post by MichaelPetch »

Can you do me a favor. Take your disk image that you burned and add it to your Github project (zip it if you like to save space). I'd like to take a look at the actual disk image that isn't working for you.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making a bootable image

Post by MichaelPetch »

One other thing. Do you actually see the message 'VBR loaded!` displayed before it apparently hangs?
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Making a bootable image

Post by Bonfra »

MichaelPetch wrote:Take your disk image that you burned and add it to your Github project .
Sure, just pushed. I've also added the align 4 but nothing changed...
Regards, Bonfra.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Making a bootable image

Post by MichaelPetch »

As an experiment what do you get if you make this code your VBR:

Code: Select all

bits 16
org 0x7c00

jmp short boot
nop

biosParameterBlock:
times 0x52-($-$$) db 0 ; BPB 7.1 FAT32 ends at 0x52.

boot:
    mov ax, 0xb800
    mov es, ax
    mov word [es:0], (0x57 << 8) | 'T'
    mov word [es:2], (0x57 << 8) | 'E'
    mov word [es:4], (0x57 << 8) | 'S'
    mov word [es:6], (0x57 << 8) | 'T'
    cli
.hltloop:
    hlt
    jmp .hltloop

TIMES 510-($-$$) db 0x00
dw 0xaa55
This should print TEST in the upper left of the display with white on magenta.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Making a bootable image

Post by Bonfra »

Just the code that you posted does not work, moving the cli to the first line of boot, in QEMU it works as you sayed but in the real hardware doesn't work.
Regards, Bonfra.
Post Reply