misc: Makefile fixes and update README.md

This commit is contained in:
mintsuki 2021-03-08 08:09:15 +01:00
parent 32aa82a1bd
commit 271ac85197
6 changed files with 154 additions and 102 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/bin
/build
/toolchain
/gnu-efi
/ovmf

View File

@ -8,7 +8,10 @@ PATH := $(shell pwd)/toolchain/bin:$(PATH)
.PHONY: all clean install distclean limine-bios limine-uefi limine-bios-clean limine-uefi-clean stage23-bios stage23-bios-clean stage23-uefi stage23-uefi-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test iso9660-test
all: limine-uefi | limine-bios bin/limine-install
all:
$(MAKE) limine-uefi
$(MAKE) limine-bios
$(MAKE) bin/limine-install
bin/limine-install: limine-install.c limine-hdd.o
$(CC) $(CFLAGS) -std=c11 limine-hdd.o limine-install.c -o $@
@ -35,7 +38,9 @@ limine-bios: stage23-bios decompressor
cd stage1/pxe && nasm bootsect.asm -fbin -o ../../bin/limine-pxe.bin
cp build/stage23-bios/limine.sys ./bin/
limine-uefi: | gnu-efi stage23-uefi
limine-uefi:
$(MAKE) gnu-efi
$(MAKE) stage23-uefi
mkdir -p bin
cp build/stage23-uefi/BOOTX64.EFI ./bin/
@ -72,7 +77,14 @@ test-clean:
rm -rf test_image test.hdd test.iso
toolchain:
scripts/make_toolchain.sh "`realpath ./toolchain`" -j`nproc`
$(MAKE) toolchain-bios
$(MAKE) toolchain-uefi
toolchain-bios:
scripts/make_toolchain_bios.sh "`realpath ./toolchain`" -j`nproc`
toolchain-uefi:
scripts/make_toolchain_uefi.sh "`realpath ./toolchain`" -j`nproc`
gnu-efi:
git clone https://git.code.sf.net/p/gnu-efi/code --branch=3.0.12 --depth=1 $@
@ -89,7 +101,11 @@ test.hdd:
parted -s test.hdd mklabel gpt
parted -s test.hdd mkpart primary 2048s 100%
echfs-test: | test-clean test.hdd limine-bios
echfs-test:
$(MAKE) test-clean
$(MAKE) test.hdd
$(MAKE) limine-bios
$(MAKE) bin/limine-install
$(MAKE) -C test
echfs-utils -g -p0 test.hdd quick-format 512 > part_guid
sed "s/@GUID@/`cat part_guid`/g" < test/limine.cfg > limine.cfg.tmp
@ -101,7 +117,11 @@ echfs-test: | test-clean test.hdd limine-bios
bin/limine-install test.hdd
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
ext2-test: | test-clean test.hdd limine-bios
ext2-test:
$(MAKE) test-clean
$(MAKE) test.hdd
$(MAKE) limine-bios
$(MAKE) bin/limine-install
$(MAKE) -C test
rm -rf test_image/
mkdir test_image
@ -118,7 +138,11 @@ ext2-test: | test-clean test.hdd limine-bios
bin/limine-install test.hdd
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
fat32-test: | test-clean test.hdd limine-bios
fat32-test:
$(MAKE) test-clean
$(MAKE) test.hdd
$(MAKE) limine-bios
$(MAKE) bin/limine-install
$(MAKE) -C test
rm -rf test_image/
mkdir test_image
@ -135,7 +159,10 @@ fat32-test: | test-clean test.hdd limine-bios
bin/limine-install test.hdd
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
iso9660-test: | test-clean test.hdd limine-bios
iso9660-test:
$(MAKE) test-clean
$(MAKE) test.hdd
$(MAKE) limine-bios
$(MAKE) -C test
rm -rf test_image/
mkdir -p test_image/boot
@ -143,7 +170,11 @@ iso9660-test: | test-clean test.hdd limine-bios
genisoimage -no-emul-boot -b boot/limine-cd.bin -boot-load-size 4 -boot-info-table -o test.iso test_image/
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -cdrom test.iso -debugcon stdio
uefi-test: ovmf | test-clean test.hdd limine-uefi
uefi-test:
$(MAKE) ovmf
$(MAKE) test-clean
$(MAKE) test.hdd
$(MAKE) limine-uefi
$(MAKE) -C test
rm -rf test_image/
mkdir test_image

View File

@ -2,7 +2,7 @@
### What is Limine?
Limine is an advanced x86/x86_64 BIOS Bootloader which supports *modern* PC features
Limine is an advanced x86/x86_64 BIOS/UEFI Bootloader which supports *modern* PC features
such as Long Mode, 5-level paging, and SMP (multicore), to name a few.
### Limine's boot menu
@ -68,19 +68,11 @@ make toolchain
After that is done, the bootloader itself can be built with:
```bash
make bootloader
make
```
The generated bootloader files are going to be in `bin`.
### Compiling `limine-install`
`limine-install` is a tool that installs Limine's stage 1 and 2 to either
an MBR or a GPT hard disk device or image.
To build the `limine-install` program, simply run `make` in the root of the repo.
This will embed the `limine-hdd.bin` bootloader image from the `bin` directory into
`limine-install`, ready to be deployed to a USB/hard drive (or disk image).
### Installing Limine binaries
This step is optional as the bootloader binaries can be used from the `bin`
directory just fine. This step will only install them in a `share` and `bin`
@ -91,7 +83,17 @@ Use `make install` to install Limine binaries, optionally specifying a prefix wi
## How to use
### MBR
### UEFI
The `BOOTX64.EFI` file is a vaild EFI application that can be simply copied to the
`/EFI/BOOT` directory of a FAT32 formatted EFI system partition. This file can be
installed there and coexist with a BIOS installation of Limine (see below) so that
the disk will be bootable by both BIOS and UEFI.
The boot device must to contain the `limine.cfg` file in
either the root or the `boot` directory of one of the partitions, formatted
with a supported file system (the ESP partition is recommended).
### BIOS/MBR
In order to install Limine on a MBR device (which can just be a raw image file),
run `limine-install` as such:
@ -103,7 +105,7 @@ The boot device must to contain the `limine.sys` and `limine.cfg` files in
either the root or the `boot` directory of one of the partitions, formatted
with a supported file system.
### GPT
### BIOS/GPT
If using a GPT formatted device, there are 2 options one can follow for installation:
* Specifying a dedicated stage 2 partition.
* Letting `limine-install` attempt to embed stage 2 within GPT structures.
@ -124,7 +126,7 @@ The boot device must to contain the `limine.sys` and `limine.cfg` files in
either the root or the `boot` directory of one of the partitions, formatted
with a supported file system.
### CD-ROM ISO creation
### BIOS CD-ROM ISO creation
In order to create a bootable ISO with Limine, place the `limine-cd.bin`,
`limine.sys`, and `limine.cfg` files into a directory which will serve as the root
of the created ISO.
@ -144,7 +146,7 @@ the root directory.
For example, if it was copied in `<root directory>/boot/limine-cd.bin`, it would be
`boot/limine-cd.bin`.
### PXE boot
### BIOS/PXE boot
The `limine-pxe.bin` binary is a valid PXE boot image.
In order to boot Limine from PXE it is necessary to setup a DHCP server with
support for PXE booting. This can either be accomplished using a single DHCP server

View File

@ -1,80 +0,0 @@
#!/bin/sh
set -e
set -x
TARGET="i386-elf x86_64-elf"
BINUTILSVERSION=2.36.1
GCCVERSION=10.2.0
NASMVERSION=2.15.05
GZIPVERSION=1.10
mkdir -p "$1" && cd "$1"
PREFIX="$(pwd)"
export MAKEFLAGS="$2"
export PATH="$PREFIX/bin:$PATH"
if [ ! -f binutils-$BINUTILSVERSION.tar.gz ]; then
wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz
fi
if [ ! -f gcc-$GCCVERSION.tar.xz ]; then
wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz
fi
if [ ! -f nasm-$NASMVERSION.tar.gz ]; then
wget https://www.nasm.us/pub/nasm/releasebuilds/$NASMVERSION/nasm-$NASMVERSION.tar.gz
fi
if [ ! -f gzip-$GZIPVERSION.tar.gz ]; then
wget https://ftp.gnu.org/gnu/gzip/gzip-$GZIPVERSION.tar.gz
fi
rm -rf build
mkdir build
cd build
tar -xf ../binutils-$BINUTILSVERSION.tar.gz
tar -xf ../gcc-$GCCVERSION.tar.gz
tar -xf ../nasm-$NASMVERSION.tar.gz
tar -xf ../gzip-$GZIPVERSION.tar.gz
for i in $TARGET; do
rm -rf build-binutils
mkdir build-binutils
cd build-binutils
../binutils-$BINUTILSVERSION/configure --target=$i --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror $([ $i = "x86_64-elf" ] && echo --enable-targets=x86_64-elf,x86_64-pe) --enable-64-bit-bfd
make
make install
cd ..
done
cd gcc-$GCCVERSION
contrib/download_prerequisites
cd ..
for i in $TARGET; do
rm -rf build-gcc
mkdir build-gcc
cd build-gcc
../gcc-$GCCVERSION/configure --target=$i --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
cd ..
done
mkdir build-nasm
cd build-nasm
../nasm-$NASMVERSION/configure --prefix="$PREFIX"
make
make install
cd ..
mkdir build-gzip
cd build-gzip
../gzip-$GZIPVERSION/configure --prefix="$PREFIX"
make
make install
cd ..
wget 'https://github.com/managarm/mlibc/raw/1f84a68500a2939f8dccd4083f8c111b2610cba6/options/elf/include/elf.h' -O "$PREFIX/lib/gcc/x86_64-elf/$GCCVERSION/include/elf.h"

48
scripts/make_toolchain_bios.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/sh
set -e
set -x
TARGET=i386-elf
BINUTILSVERSION=2.36.1
GCCVERSION=10.2.0
mkdir -p "$1" && cd "$1"
PREFIX="$(pwd)"
export MAKEFLAGS="$2"
export PATH="$PREFIX/bin:$PATH"
if [ ! -f binutils-$BINUTILSVERSION.tar.gz ]; then
wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz
fi
if [ ! -f gcc-$GCCVERSION.tar.gz ]; then
wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz
fi
rm -rf build
mkdir build
cd build
tar -xf ../binutils-$BINUTILSVERSION.tar.gz
tar -xf ../gcc-$GCCVERSION.tar.gz
mkdir build-binutils
cd build-binutils
../binutils-$BINUTILSVERSION/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror --enable-64-bit-bfd
make
make install
cd ..
cd gcc-$GCCVERSION
contrib/download_prerequisites
cd ..
mkdir build-gcc
cd build-gcc
../gcc-$GCCVERSION/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
cd ..

50
scripts/make_toolchain_uefi.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/sh
set -e
set -x
TARGET=x86_64-elf
BINUTILSVERSION=2.36.1
GCCVERSION=10.2.0
mkdir -p "$1" && cd "$1"
PREFIX="$(pwd)"
export MAKEFLAGS="$2"
export PATH="$PREFIX/bin:$PATH"
if [ ! -f binutils-$BINUTILSVERSION.tar.gz ]; then
wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz
fi
if [ ! -f gcc-$GCCVERSION.tar.gz ]; then
wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz
fi
rm -rf build
mkdir build
cd build
tar -xf ../binutils-$BINUTILSVERSION.tar.gz
tar -xf ../gcc-$GCCVERSION.tar.gz
mkdir build-binutils
cd build-binutils
../binutils-$BINUTILSVERSION/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror --enable-targets=x86_64-elf,x86_64-pe --enable-64-bit-bfd
make
make install
cd ..
cd gcc-$GCCVERSION
contrib/download_prerequisites
cd ..
mkdir build-gcc
cd build-gcc
../gcc-$GCCVERSION/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
cd ..
wget 'https://github.com/managarm/mlibc/raw/1f84a68500a2939f8dccd4083f8c111b2610cba6/options/elf/include/elf.h' -O "$PREFIX/lib/gcc/x86_64-elf/$GCCVERSION/include/elf.h"