Skip to content
This repository has been archived by the owner on May 17, 2020. It is now read-only.

Commit

Permalink
Docs: Improve documentation and add QEMU generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Apr 29, 2020
1 parent 2ff1675 commit ef5b175
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
2 changes: 2 additions & 0 deletions BootLoader/bin/BootInstall.command
@@ -1,5 +1,7 @@
#!/bin/bash

# Install booter on physical disk.

cd "$(dirname "$0")"
diskutil list
echo "Enter disk number to install to:"
Expand Down
75 changes: 75 additions & 0 deletions BootLoader/bin/QemuBuild.command
@@ -0,0 +1,75 @@
#!/bin/bash

# Build QEMU image, example:
# qemu-system-x86_64 -drive file=$QEMU_IMAGE/OpenCore.RO.raw -serial stdio \
# -usb -device usb-kbd -device usb-mouse -s -m 8192

cd "$(dirname "$0")"

if [ "$(which qemu-img)" = "" ]; then
echo "QEMU installation missing"
exit 1
fi

if [ ! -d ROOT ]; then
echo "No ROOT directory with ESP partition contents"
exit 1
fi

rm -f OpenCore.dmg.sparseimage OpenCore.RO.raw OpenCore.RO.dmg
hdiutil create -size 200m -layout "UNIVERSAL HD" -type SPARSE -o OpenCore.dmg
newDevice=$(hdiutil attach -nomount OpenCore.dmg.sparseimage )
newDevice=$(echo $newDevice | awk '{print $1}')
echo $newDevice

diskutil partitionDisk $newDevice 1 MBR fat32 TEST R

# boot install script
diskutil list
N=$(echo $newDevice | tr -dc '0-9')
echo $N


if [[ ! $(diskutil info disk${N} | sed -n 's/.*Device Node: *//p') ]]
then
echo Disk $N not found
exit
fi

FS=$(diskutil info disk${N}s1 | sed -n 's/.*File System Personality: *//p')
echo $FS

if [ "$FS" != "MS-DOS FAT32" ]
then
echo "No FAT32 partition to install"
exit
fi

# Write MBR
sudo fdisk -f boot0 -u /dev/rdisk${N}

diskutil umount disk${N}s1
sudo dd if=/dev/rdisk${N}s1 count=1 of=origbs
cp -v boot1f32 newbs
sudo dd if=origbs of=newbs skip=3 seek=3 bs=1 count=87 conv=notrunc
dd if=/dev/random of=newbs skip=496 seek=496 bs=1 count=14 conv=notrunc
sudo dd if=newbs of=/dev/rdisk${N}s1
diskutil mount disk${N}s1

cp -v boot "$(diskutil info disk${N}s1 | sed -n 's/.*Mount Point: *//p')"
cp -rv ROOT/* "$(diskutil info disk${N}s1 | sed -n 's/.*Mount Point: *//p')"

if [ $(diskutil info disk${N} | sed -n 's/.*Content (IOContent): *//p') == "FDisk_partition_scheme" ]
then
sudo fdisk -e /dev/rdisk$N <<-MAKEACTIVE
p
f 1
w
y
q
MAKEACTIVE
fi

hdiutil detach $newDevice
hdiutil convert -format UDRO OpenCore.dmg.sparseimage -o OpenCore.RO.dmg
qemu-img convert -f dmg -O raw OpenCore.RO.dmg OpenCore.RO.raw
2 changes: 1 addition & 1 deletion BootLoader/boot1f32.nasm
Expand Up @@ -182,7 +182,7 @@ gExtInfo times 25 db 0
gFileName db "BOOT " ; Used as a magic string in boot0

;--------------------------------------------------------------------------
; Boot code is loaded at 0:7C00h.
; Boot code is loaded at 0:E000h.
;
start:
;
Expand Down
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -15,6 +15,30 @@ Acidanthera variant of DuetPkg. Specialties:
- Always loads from bootstrapped volume first.
- Some changes inherited from Clover EFI bootloader.

## Simplified bootstrap process

1. `boot0` is loaded by BIOS from MBR at `7C00h`.
2. `boot0` finds active MBR or ESP GPT partition.
3. `boot0` loads `boot1` from found partition at `9000h`.
4. `boot1` finds `boot` file at partition root.
5. `boot1` loads `boot` at `20000h` (begins with `StartX64` or `StartIA32`).
6. `Start` enables paging (prebuilt for `X64` or generated for `IA32`).
7. `Start` switches to native CPU mode (`X64` or `IA32`) with paging.
8. `Start` jumps to concatentated `EfiXX` at `21000h` (`Efi64` or `Efi32`).
9. `EfiXX` loads `EfiLdr` (concatenated after `EfiXX`) at `10000h`.
10. `EfiLdr` decompresses and maps `DUETFV`, `DxeIpl`, `DxeCore`.
11. `EfiLdr` jumps to `DxeIpl`, which starts `DxeCore` from `DUETFV`.
12. `DxeCore` starts BDS, which loads `EFI/OC/OpenCore.efi`.

| Name | PHYS | VIRT |
|:----------|:------------|:------------|
| `boot0` | `7C00h` | |
| `boot1` | `9000h` | |
| `Start` | `20000h` | `20000h` |
| `EfiXX` | `21000h` | `21000h` |
| `EfiLdr` | `22000h` | `10000h` |
| `DxeIpl`+ | `22000h+` | `???` |

## Error codes

- `BOOT MISMATCH!` - Bootstrap partition signature identification failed.
Expand Down

0 comments on commit ef5b175

Please sign in to comment.