Skip to content

Commit

Permalink
Update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruhlmann committed Jul 15, 2024
1 parent 0c0f6b9 commit d9329ee
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 6 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
name: Build UEFI Application

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up environment
run: |
sudo apt-get update
sudo apt-get install -y build-essential gcc gnu-efi mtools grub-efi-amd64-bin
sudo apt-get install -y build-essential gcc gnu-efi mtools parted ovmf qemu-system-x86
- name: Determine system paths
id: system-paths
run: |
echo "INCLUDE_DIRS=$(dirname $(find /usr/include -name efi.h | head -n 1))" >> $GITHUB_OUTPUT
echo "LD_OBJ=$(find /usr/lib -name crt0-efi-x86_64.o | head -n 1)" >> $GITHUB_OUTPUT
echo "EFI_LDS=$(find /usr/lib -name elf_x86_64_efi.lds | head -n 1)" >> $GITHUB_OUTPUT
echo "BIOS_FD=$(find /usr/share -name OVMF.fd | head -n 1)" >> $GITHUB_OUTPUT
- name: Build UEFI application
run: make all
run: |
make \
INCLUDE_DIRS="${{ steps.system-paths.outputs.INCLUDE_DIRS }}" \
LD_OBJ="${{ steps.system-paths.outputs.LD_OBJ }}" \
EFI_LDS="${{ steps.system-paths.outputs.EFI_LDS }}" \
BIOS_FD="${{ steps.system-paths.outputs.BIOS_FD }}"
- name: Archive build artifacts
uses: actions/upload-artifact@v2
with:
name: reboot-efi
path: reboot.efi
- name: Archive build artifacts
uses: actions/upload-artifact@v2
with:
name: reboot-img
path: reboot.img
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ EFI_LDS ?= /usr/lib/elf_x86_64_efi.lds
BIOS_FD ?= /usr/share/OVMF/FV/OVMF.fd
DISK_BLOCK_COUNT ?= 204800
DISK_BLOCK_SIZE_BYTES ?= 512
DISK_SIZE_MiB := $(shell echo $$(($(DISK_BLOCK_COUNT) * $(DISK_BLOCK_SIZE_BYTES) / 1024)))

CFLAGS := -c -fno-stack-protector -fpic -fshort-wchar -mno-red-zone -DEFI_FUNCTION_WRAPPER $(addprefix -I,$(INCLUDE_DIRS))
LDFLAGS := -nostdlib -znocombreloc -T $(EFI_LDS) -shared -Bsymbolic -L ./ -l:libgnuefi.a -l:libefi.a
QEMUFLAGS := -bios $(BIOS_FD) -nographic -serial mon:stdio

.PHONY: all
all: reboot.efi
all: reboot.efi reboot.img

.PHONY: run
run: reboot.img
Expand Down
85 changes: 83 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
# re-bootloader
# Re-Bootloader

UEFI bootloader, which instantly reboots.
This project implements a simple UEFI bootloader that immediately reboots the system.

Useful as a fall-back disk install in case machines that rely on PXE cannot be configured to auto-retry.

## Dependencies

This project requires the following tools and libraries:

- GCC
- GNU-EFI
- Parted
- mtools
- QEMU + OVMF (for running locally)

### Installing Dependencies

#### Ubuntu/Debian:

```sh
sudo apt-get install gcc gnu-efi parted mtools qemu-system-x86 ovmf
```

#### Fedora/CentOS:

```sh
sudo dnf install gcc gnu-efi parted mtools qemu-system-x86 ovmf
```

#### Arch Linux:

```sh
sudo pacman -S gcc gnu-efi parted mtools qemu ovmf
```

## Building

To build the project, simply run:

```sh
make
```

This will create `reboot.efi` (the UEFI application) and `reboot.img` (a disk image containing the bootloader).

## Running

To test the bootloader in QEMU, run:

```
make run
```

## Customization

The Makefile supports several variables that can be overridden:

- `INCLUDE_DIRS`: Directories to search for header files (default: `/usr/lib`)
- `LD_OBJ`: Path to the UEFI crt0 object file (default: `/usr/lib/crt0-efi-x86_64.o`)
- `EFI_LDS`: Path to the UEFI linker script (default: `/usr/lib/elf_x86_64_efi.lds`)
- `BIOS_FD`: Path to the OVMF BIOS image for QEMU (default: `/usr/share/OVMF/FV/OVMF.fd`)
- `DISK_BLOCK_COUNT`: Number of blocks in the disk image (default: 204800)
- `DISK_BLOCK_SIZE_BYTES`: Size of each block in bytes (default: 512)

Example usage:

```sh
make INCLUDE_DIRS="/path/to/efi/headers" LD_OBJ="/path/to/crt0.o"
```

## Writing to a Disk

To write the bootloader image to a physical disk (use with caution!):

```sh
sudo dd if=reboot.img of=/dev/sdX bs=4M status=progress
```

Replace `/dev/sdX` with the appropriate disk device. Be absolutely certain you're writing to the correct disk, as this will overwrite all existing data.

## How it Works

The bootloader is a minimal UEFI application that calls the UEFI firmware's ResetSystem function to immediately reboot the system. The Makefile compiles this application and creates a GPT-formatted disk image containing an EFI System Partition with the bootloader installed.

0 comments on commit d9329ee

Please sign in to comment.