OSDev.org
https://forum.osdev.org/

Making a bootable image
https://forum.osdev.org/viewtopic.php?f=1&t=37405
Page 5 of 7

Author:  Bonfra [ Tue Nov 03, 2020 11:35 am ]
Post subject:  Re: Making a bootable image

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

Author:  MichaelPetch [ Tue Nov 03, 2020 11:44 am ]
Post subject:  Re: Making a bootable image

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:
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.

Author:  Bonfra [ Tue Nov 03, 2020 12:11 pm ]
Post subject:  Re: Making a bootable image

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:
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

Author:  MichaelPetch [ Tue Nov 03, 2020 12:51 pm ]
Post subject:  Re: Making a bootable image

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.

Author:  bzt [ Tue Nov 03, 2020 1:02 pm ]
Post subject:  Re: Making a bootable image

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

Author:  MichaelPetch [ Tue Nov 03, 2020 1:16 pm ]
Post subject:  Re: Making a bootable image

Chrysocome DD specifically added the `od=` (and `id=`) options and why I recommended the latest beta release that has that option.

Author:  bzt [ Tue Nov 03, 2020 1:20 pm ]
Post subject:  Re: Making a bootable image

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

Author:  Bonfra [ Tue Nov 03, 2020 2:19 pm ]
Post subject:  Re: Making a bootable image

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

Author:  Bonfra [ Tue Nov 03, 2020 2:26 pm ]
Post subject:  Re: Making a bootable image

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.

Author:  MichaelPetch [ Tue Nov 03, 2020 2:33 pm ]
Post subject:  Re: Making a bootable image

Can you humour me and do this.In your MBR you have
Code:
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:
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.

Author:  MichaelPetch [ Tue Nov 03, 2020 2:39 pm ]
Post subject:  Re: Making a bootable image

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.

Author:  MichaelPetch [ Tue Nov 03, 2020 2:44 pm ]
Post subject:  Re: Making a bootable image

One other thing. Do you actually see the message 'VBR loaded!` displayed before it apparently hangs?

Author:  Bonfra [ Tue Nov 03, 2020 2:46 pm ]
Post subject:  Re: Making a bootable image

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...

Author:  MichaelPetch [ Tue Nov 03, 2020 3:05 pm ]
Post subject:  Re: Making a bootable image

As an experiment what do you get if you make this code your VBR:
Code:
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.

Author:  Bonfra [ Tue Nov 03, 2020 3:19 pm ]
Post subject:  Re: Making a bootable image

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.

Page 5 of 7 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/