From aed48d856ad540ffaf98ccf097b0091cf996307b Mon Sep 17 00:00:00 2001 From: bzt Date: Sun, 13 Sep 2020 22:53:30 +0200 Subject: [PATCH] Initial coreboot support --- .gitignore | 4 +- OLVASSEL.md | 3 + README.md | 3 + aarch64-cb/Makefile | 43 +++ aarch64-cb/OLVASSEL.md | 82 +++++ aarch64-cb/README.md | 82 +++++ aarch64-cb/bootboot.c | 68 ++++ coreboot/payloads/external/BOOTBOOT/Kconfig | 6 + .../payloads/external/BOOTBOOT/Kconfig.name | 8 + coreboot/payloads/external/BOOTBOOT/Makefile | 48 +++ coreboot/payloads/external/Makefile.inc | 311 ++++++++++++++++++ x86_64-cb/Makefile | 43 +++ x86_64-cb/OLVASSEL.md | 84 +++++ x86_64-cb/README.md | 83 +++++ x86_64-cb/bootboot.c | 54 +++ 15 files changed, 921 insertions(+), 1 deletion(-) create mode 100644 aarch64-cb/Makefile create mode 100644 aarch64-cb/OLVASSEL.md create mode 100644 aarch64-cb/README.md create mode 100644 aarch64-cb/bootboot.c create mode 100644 coreboot/payloads/external/BOOTBOOT/Kconfig create mode 100644 coreboot/payloads/external/BOOTBOOT/Kconfig.name create mode 100644 coreboot/payloads/external/BOOTBOOT/Makefile create mode 100644 coreboot/payloads/external/Makefile.inc create mode 100644 x86_64-cb/Makefile create mode 100644 x86_64-cb/OLVASSEL.md create mode 100644 x86_64-cb/README.md create mode 100644 x86_64-cb/bootboot.c diff --git a/.gitignore b/.gitignore index 0bd838f..ac5b778 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,10 @@ aarch64-rpi/*.bin aarch64-rpi/*.dat aarch64-rpi/*.elf +dist/bootbootcb.elf + mkbootimg/*.o mkbootimg/mkbootimg mykernel-rust/target -mykernel-rust/Cargo.lock \ No newline at end of file +mykernel-rust/Cargo.lock diff --git a/OLVASSEL.md b/OLVASSEL.md index cb11d5b..fe1018a 100644 --- a/OLVASSEL.md +++ b/OLVASSEL.md @@ -25,6 +25,9 @@ memórialeképezéseket kezel, ami az 1-es protokoll szintnek felel meg. Gyors kipróbáláshoz találsz bootolható képfájlokat az [images](https://gitlab.com/bztsrc/bootboot/tree/master/images) mappában. +BOOTBOOT lefordítható [coreboot](https://coreboot.org) payloadként is, lásd *x86_64-cb* és *aarch64-cb*, de mivel ezek szorosan +kapcsolódnak a libpayload-hoz, nincs belőlük előre fordított bináris. + BOOTBOOT Protokoll ================== diff --git a/README.md b/README.md index c92e3fa..915cecb 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ static mappings which makes it a level 1 loader. For a quick test, you can find example bootable disk [images](https://gitlab.com/bztsrc/bootboot/tree/master/images) too. +BOOTBOOT can also be compiled as a [coreboot](https://coreboot.org) payload, see *x86_64-cb* and *aarch64-cb*, but since +they are tied strongly with libpayload, I do not provide binaries for those. + BOOTBOOT Protocol ================= diff --git a/aarch64-cb/Makefile b/aarch64-cb/Makefile new file mode 100644 index 0000000..9b8c5e0 --- /dev/null +++ b/aarch64-cb/Makefile @@ -0,0 +1,43 @@ +TARGET=../dist/bootbootcb.elf + +# get build environment +ifndef LIBCONFIG_PATH +LIBCONFIG_PATH := ../../coreboot/payloads/libpayload +ifeq ($(wildcard $(LIBCONFIG_PATH)/*),) +LIBCONFIG_PATH := ../../../../libpayload +endif +endif +LIBPAYLOAD_DIR=$(CURDIR)/libpayload +XCOMPILE=$(LIBPAYLOAD_DIR)/libpayload.xcompile +# build libpayload and put .config file in $(CURDIR) instead of ../libpayload +# to avoid pollute the libpayload source directory and possible conflicts +LPOPTS=obj="$(CURDIR)/build" DESTDIR="$(CURDIR)" DOTCONFIG="$(CURDIR)/.config" +CFLAGS += -Wall -Wvla -Werror -Os -ffreestanding -nostdinc -nostdlib + +all: $(TARGET) + +$(LIBPAYLOAD_DIR): + $(MAKE) -C $(LIBCONFIG_PATH) $(LPOPTS) defconfig + $(MAKE) -C $(LIBCONFIG_PATH) $(LPOPTS) + $(MAKE) -C $(LIBCONFIG_PATH) $(LPOPTS) install + +ifneq ($(strip $(wildcard libpayload)),) +include $(XCOMPILE) +LPGCC = CC="$(GCC_CC_aarch64)" "$(LIBPAYLOAD_DIR)/bin/lpgcc" +$(TARGET): + $(LPGCC) $(CFLAGS) -o $(TARGET) bootboot.c +else +# If libpayload is not found, first build libpayload, +# then do the make, this time it'll find libpayload +# and generate the elf target +$(TARGET): $(LIBPAYLOAD_DIR) + $(MAKE) all +endif + +clean: + rm -f $(TARGET) + +distclean: clean + rm -rf build libpayload .config .config.old + +.PHONY: all clean distclean diff --git a/aarch64-cb/OLVASSEL.md b/aarch64-cb/OLVASSEL.md new file mode 100644 index 0000000..c824a06 --- /dev/null +++ b/aarch64-cb/OLVASSEL.md @@ -0,0 +1,82 @@ +BOOTBOOT Coreboot ARM64 Implementáció +===================================== + +Általános leírásért lásd a [BOOTBOOT Protokoll](https://gitlab.com/bztsrc/bootboot)t. + +Ez [coreboot](https://coreboot.org) payloadként implementálja a BOOTBOOT Protokollt. Jelenleg __FEJLESZTÉS ALATT__. +A coreboot fordítási környezetben fordítandó. + +Fordítás +-------- + +### 1. lépés - Függőségek telepítése + +Először is, telepíteni kell a [coreboot függőségei](https://doc.coreboot.org/tutorial/part1.html)t: bison, build-essentials, curl, +flex, git, gnat, libncurses5-dev, m4, zlib. A legfrissebb listáért nézd meg a linkelt dokumentumot. + +### 2. lépés - A coreboot beszerzése + +Töltsd le a coreboot-ot minden almoduljával együtt +```sh +$ git clone https://review.coreboot.org/coreboot +$ cd coreboot +$ git submodule update --init +``` +Nagyon fontos, hogy inicializáld az almodulokat, máskülönben nem fog lefordulni a coreboot. + +### 3. lépés - Fordítókörnyezet (toolchain) létrehozása + +Ez el fog tartani egy jódarabig. A *$(nproc)* helyett add meg, hogy hány CPU core-od van. +```sh +$ make crossgcc-aarch64 CPUS=$(nproc) +``` + +### 4. lépés - A coreboot pecselése és konfigurálása + +Másold át és írd felül a [../coreboot könyvtár](https://gitlab.com/bztsrc/bootboot/tree/master/coreboot) fájlait a +coreboot projekted munkakönyvtárába. Ez frissíteni fogja a coreboot konfigurációs rendszerét. + +Ezután be kell konfigurálnod a coreboot-ot, hogy milyen alaplapot (vagy qemu-t) kezeljen, és hogy BOOTBOOT-al induljon. +```sh +$ make menuconfig + válaszd a 'Mainboard' menüt + alatta a 'Mainboard vendor' legyen '(Emulation)' + alatta a 'Mainboard model' legyen 'QEMU AArch64' + válaszd az 'Exit'-t + válaszd a 'Payload' menüt + válaszd az 'Add a Payload' opciót + válaszd ki a 'BOOTBOOT'-ot + válaszd az 'Exit'-t + válaszd az 'Exit'-t + válaszd a 'Yes'-t +``` + +### 5. lépés - A coreboot fordítása + +```sh +$ make +``` + +### 6. lépés - A frissen fordított ROM tesztelése QEMU-n + +Bővebb információért lásd a [coreboot dokumentáció](https://doc.coreboot.org/mainboard/emulation/qemu-aarch64.html)t. +```sh +$ qemu-system-aarch64 -bios $(COREBOOT)/build/coreboot.rom -M virt,secure=on,virtualization=on -cpu cortex-a53 -m 1024M \ + -drive file=$(BOOTBOOT)/images/disk-rpi.img,format=raw -serial stdio +``` + +Gép állapot +----------- + +A kód felügyeleti módban, EL1-en fut minden processzoron. + +Telepítés +--------- + +Miután lefordítottad a coreboot ROM-ot BOOTBOOT payloaddal, [flashelheted a build/coreboot.rom](https://doc.coreboot.org/flash_tutorial/index.html) +fájlt az alaplapodra. + +Limitációk +---------- + + - Csak a SHA-XOR-CBC titkosítást ismeri, nincs AES diff --git a/aarch64-cb/README.md b/aarch64-cb/README.md new file mode 100644 index 0000000..1bb3311 --- /dev/null +++ b/aarch64-cb/README.md @@ -0,0 +1,82 @@ +BOOTBOOT Coreboot ARM64 Implementation +====================================== + +See [BOOTBOOT Protocol](https://gitlab.com/bztsrc/bootboot) for common details. + +Implements the BOOTBOOT Protocol as a [coreboot](https://coreboot.org) payload. Currently __EXPERIMENTAL__. +Must be compiled using the coreboot build environment. + +Compilation +----------- + +### Step 1 - Install dependencies + +First, install the [coreboot dependencies](https://doc.coreboot.org/tutorial/part1.html): bison, build-essentials, curl, +flex, git, gnat, libncurses5-dev, m4, zlib. Please refer to the linked doc for up-to-date list of dependencies. + +### Step 2 - Get coreboot + +Download coreboot and its submodules +```sh +$ git clone https://review.coreboot.org/coreboot +$ cd coreboot +$ git submodule update --init +``` +It is very important to initialize submodules, otherwise you won't be able to compile coreboot. + +### Step 3 - Create toolchain + +This step could take a while. Replace *$(nproc)* with the number of CPU cores you have. +```sh +$ make crossgcc-aarch64 CPUS=$(nproc) +``` + +### Step 4 - Patch coreboot and configure + +Copy and overwrite files from [../coreboot directory](https://gitlab.com/bztsrc/bootboot/tree/master/coreboot) to the +coreboot working directory. This will update the coreboot configuration system. + +Now configure coreboot for your motherboard (or qemu) and BOOTBOOT. +```sh +$ make menuconfig + select 'Mainboard' menu + Beside 'Mainboard vendor' should be '(Emulation)' + Beside 'Mainboard model' should be 'QEMU AArch64' + select 'Exit' + select 'Payload' menu + select 'Add a Payload' + choose 'BOOTBOOT' + select 'Exit' + select 'Exit' + select 'Yes' +``` + +### Step 5 - Build coreboot + +```sh +$ make +``` + +### Step 6 - Test the newly compiled ROM in QEMU + +For more information, read [coreboot docs](https://doc.coreboot.org/mainboard/emulation/qemu-aarch64.html). +```sh +$ qemu-system-aarch64 -bios $(COREBOOT)/build/coreboot.rom -M virt,secure=on,virtualization=on -cpu cortex-a53 -m 1024M \ + -drive file=$(BOOTBOOT)/images/disk-rpi.img,format=raw -serial stdio +``` + +Machine state +------------- + +Code is running in supervisor mode, at EL1 on all cores. + +Installation +------------ + +Once you have compiled a coreboot ROM with the BOOTBOOT payload, you can +[flash the build/coreboot.rom](https://doc.coreboot.org/flash_tutorial/index.html) file to your mainboard. + +Limitations +----------- + + - Only supports SHA-XOR-CBC, no AES diff --git a/aarch64-cb/bootboot.c b/aarch64-cb/bootboot.c new file mode 100644 index 0000000..e04a1f0 --- /dev/null +++ b/aarch64-cb/bootboot.c @@ -0,0 +1,68 @@ +/* + * aarch64-cb/bootboot.c + * + * Copyright (C) 2017 - 2020 bzt (bztsrc@gitlab) + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * This file is part of the BOOTBOOT Protocol package. + * @brief Boot loader for the AArch64 coreboot payload + * + */ + +#define BBDEBUG 1 + +/* + +unfortunately currently you cannot compile libpayload for ARM64. It gives this error: + +$ cd libpayload +$ make + CC arch/arm64/main.libc.o +: error: "_LP64" redefined [-Werror] +: note: this is the location of the previous definition +cc1: error: unrecognized command line option '-Wno-address-of-packed-member' [-Werror] +cc1: all warnings being treated as errors +make: *** [Makefile:270: build/arch/arm64/main.libc.o] Error 1 +*/ + +#include +#include + +extern struct sysinfo_t lib_sysinfo; + +int main(void) +{ + int ret, i; + + printf("Hello World!\n"); + + ret = lib_get_sysinfo(); + if (ret) halt(); + + printf("Number of memory ranges: %d\n", lib_sysinfo.n_memranges); + for (i = 0; i < lib_sysinfo.n_memranges; i++) { + printf("%d: base 0x%08llx size 0x%08llx type 0x%x\n", i, lib_sysinfo.memrange[i].base, lib_sysinfo.memrange[i].size, lib_sysinfo.memrange[i].type); + } + printf("Now we will halt. Bye\n"); + halt(); + return 0; +} diff --git a/coreboot/payloads/external/BOOTBOOT/Kconfig b/coreboot/payloads/external/BOOTBOOT/Kconfig new file mode 100644 index 0000000..c9d7133 --- /dev/null +++ b/coreboot/payloads/external/BOOTBOOT/Kconfig @@ -0,0 +1,6 @@ +if PAYLOAD_BOOTBOOT + +config PAYLOAD_FILE + default "payloads/external/BOOTBOOT/bootboot/dist/bootbootcb.elf" + +endif diff --git a/coreboot/payloads/external/BOOTBOOT/Kconfig.name b/coreboot/payloads/external/BOOTBOOT/Kconfig.name new file mode 100644 index 0000000..082a9b1 --- /dev/null +++ b/coreboot/payloads/external/BOOTBOOT/Kconfig.name @@ -0,0 +1,8 @@ +config PAYLOAD_BOOTBOOT + bool "BOOTBOOT" + depends on ARCH_X86 || ARCH_ARM64 + help + Select this option if you want to build a coreboot image + with a BOOTBOOT Protocol payload. + + See https://gitlab.com/bztsrc/bootboot for more information. diff --git a/coreboot/payloads/external/BOOTBOOT/Makefile b/coreboot/payloads/external/BOOTBOOT/Makefile new file mode 100644 index 0000000..9c369d8 --- /dev/null +++ b/coreboot/payloads/external/BOOTBOOT/Makefile @@ -0,0 +1,48 @@ +project_git_repo=https://gitlab.com/bztsrc/bootboot.git +project_dir=bootboot +ifeq ($(CONFIG_COREBOOT_BUILD),) +include ../../../.config +endif +ifeq ($(CONFIG_ARCH_ARM64),y) +loader_dir=$(project_dir)/aarch64-cb +else +loader_dir=$(project_dir)/x86_64-cb +endif + +unexport KCONFIG_AUTOHEADER +unexport KCONFIG_AUTOCONFIG +unexport KCONFIG_DEPENDENCIES +unexport KCONFIG_SPLITCONFIG +unexport KCONFIG_TRISTATE +unexport KCONFIG_NEGATIVES + +all: bootboot + +checkout: + echo " GIT BOOTBOOT $(loader_dir)" + @test -d ../../../../bootboot && ln -s ../../../../bootboot 2>/dev/null || true + test -L $(project_dir) || ( \ + ( test -d $(project_dir) || \ + git clone $(project_git_repo) $(project_dir) ) && \ + ( cd $(project_dir) && \ + git checkout master && \ + git remote update ) ) + +bootboot: libpayload + echo " MAKE $(loader_dir)" + $(MAKE) -C $(loader_dir) LIBCONFIG_PATH=../../../libpayload + +libpayload: checkout + cd ../../libpayload && $(MAKE) defconfig && \ + $(MAKE) && $(MAKE) DESTDIR=../external/FILO/filo/build install + +clean: + test -d $(loader_dir) && $(MAKE) -C $(loader_dir) clean || exit 0 + +distclean: + rm -rf $(project_dir) + +print-repo-info: + echo "$(project_git_repo) $(project_dir)" + +.PHONY: checkout bootboot libpayload clean distclean print-repo-info diff --git a/coreboot/payloads/external/Makefile.inc b/coreboot/payloads/external/Makefile.inc new file mode 100644 index 0000000..15d7348 --- /dev/null +++ b/coreboot/payloads/external/Makefile.inc @@ -0,0 +1,311 @@ +################################################################################ +## +## +## Copyright (C) 2009-2010 coresystems GmbH +## Copyright (C) 2015 Google Inc. +## Copyright (C) 2017 Facebook Inc. +## +## SPDX-License-Identifier: GPL-2.0-only + +# set up payload config and version files for later inclusion +ifeq ($(CONFIG_PAYLOAD_SEABIOS),y) +PAYLOAD_CONFIG=payloads/external/SeaBIOS/seabios/.config +PAYLOAD_VERSION=payloads/external/SeaBIOS/seabios/out/autoversion.h +endif +ifeq ($(CONFIG_PAYLOAD_FILO),y) +PAYLOAD_CONFIG=payloads/external/FILO/filo/.config +PAYLOAD_VERSION=payloads/external/FILO/filo/build/version.h +endif +ifeq ($(CONFIG_PAYLOAD_DEPTHCHARGE),y) +PAYLOAD_CONFIG=payloads/external/depthcharge/depthcharge/.config +$(PAYLOAD_CONFIG): payloads/external/depthcharge/depthcharge/build/depthcharge.elf +ifeq ($(call strip_quotes,$(CONFIG_MAINBOARD_DEPTHCHARGE)),) + BOARD=$(call ws_to_under,$(call strip_quotes,$(call tolower,$(CONFIG_MAINBOARD_PART_NUMBER)))) +else + BOARD=$(CONFIG_MAINBOARD_DEPTHCHARGE) +endif +#TODO: Figure out version +endif + +ifeq ($(CONFIG_PAYLOAD_LINUX)$(CONFIG_PAYLOAD_LINUXBOOT),y) +ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),) + ADDITIONAL_PAYLOAD_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE) +endif +ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),) +ifneq ($(CONFIG_LINUXBOOT_ARM64),y) + ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) + prebuilt-files += $(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))) +endif +endif +endif +ifneq ($(strip $(call strip_quotes,$(CONFIG_PAYLOAD_OPTIONS))),) + ADDITIONAL_PAYLOAD_CONFIG+=$(strip $(call strip_quotes,$(CONFIG_PAYLOAD_OPTIONS))) +endif + +cbfs-files-y += $(CONFIG_CBFS_PREFIX)/payload +$(CONFIG_CBFS_PREFIX)/payload-file := $(CONFIG_PAYLOAD_FILE) +ifeq ($(CONFIG_PAYLOAD_IS_FLAT_BINARY),y) +$(CONFIG_CBFS_PREFIX)/payload-type := flat-binary +else +$(CONFIG_CBFS_PREFIX)/payload-type := payload +endif +$(CONFIG_CBFS_PREFIX)/payload-compression := $(CBFS_PAYLOAD_COMPRESS_FLAG) +$(CONFIG_CBFS_PREFIX)/payload-options := $(ADDITIONAL_PAYLOAD_CONFIG) + +cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += payload_config +payload_config-file := $(PAYLOAD_CONFIG) +payload_config-type := raw + +cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += payload_revision +payload_revision-file := $(PAYLOAD_VERSION) +payload_revision-type := raw + +cbfs-files-$(CONFIG_GRUB2_INCLUDE_RUNTIME_CONFIG_FILE) += etc/grub.cfg +etc/grub.cfg-file := $(CONFIG_GRUB2_RUNTIME_CONFIG_FILE) +etc/grub.cfg-type := raw +etc/grub.cfg-required := the GRUB runtime configuration file ($(CONFIG_GRUB2_RUNTIME_CONFIG_FILE)) + +# SeaBIOS + +SEABIOS_CC_OFFSET=$(if $(filter %ccache,$(HOSTCC)),2,1) +payloads/external/SeaBIOS/seabios/out/bios.bin.elf: $(DOTCONFIG) + $(MAKE) -C payloads/external/SeaBIOS \ + HOSTCC="$(HOSTCC)" \ + CC=$(word $(SEABIOS_CC_OFFSET),$(CC_x86_32)) \ + CFLAGS="$(patsubst $(word $(SEABIOS_CC_OFFSET),$(CC_x86_32))%,,$(wordlist $(SEABIOS_CC_OFFSET),9999,$(CC_x86_32)))" \ + LD=$(word 1,$(LD_x86_32)) LDFLAGS="$(patsubst $(word 1,$(LD_x86_32))%,,$(LD_x86_32))" \ + OBJDUMP="$(OBJDUMP_x86_32)" \ + OBJCOPY="$(OBJCOPY_x86_32)" STRIP="$(STRIP_x86_32)" \ + AS="$(AS_x86_32)" IASL="$(IASL)" \ + CONFIG_SEABIOS_MASTER=$(CONFIG_SEABIOS_MASTER) \ + CONFIG_SEABIOS_STABLE=$(CONFIG_SEABIOS_STABLE) \ + CONFIG_SEABIOS_REVISION=$(CONFIG_SEABIOS_REVISION) \ + CONFIG_SEABIOS_REVISION_ID=$(CONFIG_SEABIOS_REVISION_ID) \ + CONFIG_PAYLOAD_CONFIGFILE=$(CONFIG_PAYLOAD_CONFIGFILE) \ + CONFIG_SEABIOS_THREAD_OPTIONROMS=$(CONFIG_SEABIOS_THREAD_OPTIONROMS) \ + CONFIG_SEABIOS_VGA_COREBOOT=$(CONFIG_SEABIOS_VGA_COREBOOT) \ + CONFIG_DRIVERS_UART_8250IO=$(CONFIG_DRIVERS_UART_8250IO) \ + CONFIG_DRIVERS_UART_8250MEM=$(CONFIG_DRIVERS_UART_8250MEM) \ + CONFIG_HUDSON_UART=$(CONFIG_HUDSON_UART) \ + CONFIG_CONSOLE_SERIAL=$(CONFIG_CONSOLE_SERIAL) \ + CONFIG_TTYS0_BASE=$(CONFIG_TTYS0_BASE) \ + CONFIG_SEABIOS_DEBUG_LEVEL=$(CONFIG_SEABIOS_DEBUG_LEVEL) \ + CONFIG_DRIVERS_UART_8250MEM_32=$(CONFIG_DRIVERS_UART_8250MEM_32) \ + CONFIG_ENABLE_HSUART=$(CONFIG_ENABLE_HSUART) \ + CONFIG_CONSOLE_UART_BASE_ADDRESS=$(CONFIG_CONSOLE_UART_BASE_ADDRESS) \ + CONFIG_SEABIOS_HARDWARE_IRQ=$(CONFIG_SEABIOS_HARDWARE_IRQ) + +payloads/external/SeaBIOS/seabios/out/vgabios.bin: payloads/external/SeaBIOS/seabios/out/bios.bin.elf +payloads/external/SeaBIOS/seabios/.config: payloads/external/SeaBIOS/seabios/out/bios.bin.elf +payloads/external/SeaBIOS/seabios/out/autoversion.h: payloads/external/SeaBIOS/seabios/out/bios.bin.elf + +# add a SeaBIOS bootorder file +ifneq ($(strip $(CONFIG_SEABIOS_BOOTORDER_FILE)),) +cbfs-files-y += bootorder +bootorder-file := $(strip $(CONFIG_SEABIOS_BOOTORDER_FILE)) +bootorder-type := raw +endif + +# Depthcharge + +payloads/external/depthcharge/depthcharge/build/depthcharge.elf depthcharge: $(DOTCONFIG) $(CBFSTOOL) + $(MAKE) -C payloads/external/depthcharge \ + BOARD=$(BOARD) \ + MFLAGS= MAKEFLAGS= \ + DEPTHCHARGE_MASTER=$(CONFIG_DEPTHCHARGE_MASTER) \ + DEPTHCHARGE_STABLE=$(CONFIG_DEPTHCHARGE_STABLE) \ + DEPTHCHARGE_REVISION=$(CONFIG_DEPTHCHARGE_REVISION) \ + DEPTHCHARGE_REVISION_ID=$(CONFIG_DEPTHCHARGE_REVISION_ID) \ + OVERRIDE_DEFCONFIG=$(CONFIG_LP_DEFCONFIG_OVERRIDE) + +# Tianocore + +payloads/external/tianocore/tianocore/Build/UEFIPAYLOAD.fd tianocore: $(DOTCONFIG) + $(MAKE) -C payloads/external/tianocore all \ + HOSTCC="$(HOSTCC)" \ + CC="$(HOSTCC)" \ + CONFIG_TIANOCORE_REVISION_ID=$(CONFIG_TIANOCORE_REVISION_ID) \ + CONFIG_TIANOCORE_DEBUG=$(CONFIG_TIANOCORE_DEBUG) \ + CONFIG_TIANOCORE_TARGET_IA32=$(CONFIG_TIANOCORE_TARGET_IA32) \ + CONFIG_TIANOCORE_USE_8254_TIMER=$(CONFIG_TIANOCORE_USE_8254_TIMER) \ + CONFIG_TIANOCORE_BOOTSPLASH_FILE=$(CONFIG_TIANOCORE_BOOTSPLASH_FILE) \ + CONFIG_TIANOCORE_UEFIPAYLOAD=$(CONFIG_TIANOCORE_UEFIPAYLOAD) \ + CONFIG_TIANOCORE_COREBOOTPAYLOAD=$(CONFIG_TIANOCORE_COREBOOTPAYLOAD) \ + CONFIG_MMCONF_BASE_ADDRESS=$(CONFIG_MMCONF_BASE_ADDRESS) \ + GCC_CC_x86_32=$(GCC_CC_x86_32) \ + GCC_CC_x86_64=$(GCC_CC_x86_64) \ + GCC_CC_arm=$(GCC_CC_arm) \ + GCC_CC_arm64=$(GCC_CC_arm64) \ + OBJCOPY_x86_32=$(OBJCOPY_x86_32) \ + OBJCOPY_x86_64=$(OBJCOPY_x86_64) \ + OBJCOPY_arm=$(OBJCOPY_arm) \ + OBJCOPY_arm64=$(OBJCOPY_arm64) \ + MFLAGS= MAKEFLAGS= + +# FILO + +filo: + $(MAKE) -C payloads/external/FILO \ + HOSTCC="$(HOSTCC)" \ + CC="$(CC_x86_32)" LD="$(LD_x86_32)" OBJDUMP="$(OBJDUMP_x86_32)" \ + OBJCOPY="$(OBJCOPY_x86_32)" STRIP="$(STRIP_x86_32)" \ + CONFIG_FILO_MASTER=$(CONFIG_FILO_MASTER) \ + CONFIG_FILO_STABLE=$(CONFIG_FILO_STABLE) + +payloads/external/FILO/filo/build/filo.elf: filo +payloads/external/FILO/filo/.config: filo +payloads/external/FILO/filo/build/version.h: filo + +# Grub + +grub2: $(obj)/config.h + $(MAKE) -C payloads/external/GRUB2 \ + HOSTCC="$(HOSTCC)" \ + CC="$(CC_x86_32)" LD="$(LD_x86_32)" \ + OBJCOPY="$(OBJCOPY_x86_32)" STRIP="$(STRIP_x86_32)" \ + CONFIG_DEP="$(abspath $(obj)/config.h)" \ + CONFIG_GRUB2_STABLE=$(CONFIG_GRUB2_STABLE) \ + CONFIG_GRUB2_MASTER=$(CONFIG_GRUB2_MASTER) \ + CONFIG_GRUB2_REVISION=$(CONFIG_GRUB2_REVISION) \ + CONFIG_GRUB2_REVISION_ID=$(CONFIG_GRUB2_REVISION_ID) \ + CONFIG_GRUB2_EXTRA_MODULES=$(CONFIG_GRUB2_EXTRA_MODULES) + +payloads/external/GRUB2/grub2/build/default_payload.elf: grub2 + +# U-Boot + +payloads/external/U-Boot/u-boot/u-boot-dtb.bin u-boot: $(DOTCONFIG) + $(MAKE) -C payloads/external/U-Boot \ + CONFIG_UBOOT_MASTER=$(CONFIG_UBOOT_MASTER) \ + CONFIG_UBOOT_STABLE=$(CONFIG_UBOOT_STABLE) + +# TINT + +payloads/external/tint/tint/tint.elf tint: + $(MAKE) -C payloads/external/tint + +cbfs-files-$(CONFIG_TINT_SECONDARY_PAYLOAD) += img/tint +img/tint-file := payloads/external/tint/tint/tint.elf +img/tint-type := payload +img/tint-compression := $(CBFS_SECONDARY_PAYLOAD_COMPRESS_FLAG) + +# Memtest86+ + +cbfs-files-$(CONFIG_MEMTEST_SECONDARY_PAYLOAD) += img/memtest +img/memtest-file := payloads/external/Memtest86Plus/memtest86plus/memtest +img/memtest-type := payload +img/memtest-compression := $(CBFS_SECONDARY_PAYLOAD_COMPRESS_FLAG) + +ifeq ($(CONFIG_CONSOLE_SERIAL)$(CONFIG_DRIVERS_UART_8250IO),yy) + MEMTEST_SERIAL_OPTIONS=SERIAL_CONSOLE_DEFAULT=1 \ + SERIAL_TTY=$(CONFIG_UART_FOR_CONSOLE) \ + SERIAL_BAUD_RATE=$(CONFIG_TTYS0_BAUD) +endif + +payloads/external/Memtest86Plus/memtest86plus/memtest: $(DOTCONFIG) + $(MAKE) -C payloads/external/Memtest86Plus all \ + CC="$(CC_x86_32)" \ + LD="$(LD_x86_32)" \ + OBJCOPY="$(OBJCOPY_x86_32)" \ + AS="$(AS_x86_32)" \ + CONFIG_MEMTEST_REVISION=$(CONFIG_MEMTEST_REVISION) \ + CONFIG_MEMTEST_REVISION_ID=$(CONFIG_MEMTEST_REVISION_ID) \ + CONFIG_MEMTEST_MASTER=$(CONFIG_MEMTEST_MASTER) \ + CONFIG_MEMTEST_STABLE=$(CONFIG_MEMTEST_STABLE) \ + $(MEMTEST_SERIAL_OPTIONS) \ + MFLAGS= MAKEFLAGS= + +# iPXE + +PXE_ROM_PCI_ID:=$(subst $(comma),,$(CONFIG_PXE_ROM_ID)) + +ifeq ($(CONFIG_PXE_ROM),y) +PXE_ROM_FILE:=$(CONFIG_PXE_ROM_FILE) +endif +ifeq ($(CONFIG_BUILD_IPXE),y) +PXE_ROM_FILE:=payloads/external/iPXE/ipxe/ipxe.rom +endif +ifeq ($(CONFIG_PXE_ADD_SCRIPT),y) +PXE_CONFIG_SCRIPT:=$(abspath $(patsubst "%",%,$(CONFIG_PXE_SCRIPT))) +endif +ifeq ($(CONFIG_CONSOLE_SERIAL)$(CONFIG_DRIVERS_UART_8250IO),yy) +IPXE_UART=COM$(call int-add,$(CONFIG_UART_FOR_CONSOLE) 1) +endif + +ifeq ($(CONFIG_PXE_SERIAL_CONSOLE),y) +IPXE_SERIAL_CONSOLE = $(CONFIG_CONSOLE_SERIAL)$(CONFIG_DRIVERS_UART_8250IO) +else +IPXE_SERIAL_CONSOLE = n +endif + +cbfs-files-$(CONFIG_PXE_ROM)$(CONFIG_BUILD_IPXE) += pci$(CONFIG_PXE_ROM_ID).rom +pci$(CONFIG_PXE_ROM_ID).rom-file := $(PXE_ROM_FILE) +pci$(CONFIG_PXE_ROM_ID).rom-type := raw + +payloads/external/iPXE/ipxe/ipxe.rom ipxe: $(DOTCONFIG) $(PXE_CONFIG_SCRIPT) + $(MAKE) -C payloads/external/iPXE all \ + CROSS_COMPILE="$(CROSS_COMPILE_$(ARCH-ramstage-y))" \ + PXE_ROM_PCI_ID=$(PXE_ROM_PCI_ID) \ + CONFIG_IPXE_MASTER=$(CONFIG_IPXE_MASTER) \ + CONFIG_IPXE_STABLE=$(CONFIG_IPXE_STABLE) \ + CONSOLE_SERIAL=$(IPXE_SERIAL_CONSOLE) \ + IPXE_UART=$(IPXE_UART) \ + CONFIG_TTYS0_BAUD=$(CONFIG_TTYS0_BAUD) \ + CONFIG_SCRIPT=$(PXE_CONFIG_SCRIPT) \ + CONFIG_HAS_SCRIPT=$(CONFIG_PXE_ADD_SCRIPT) \ + CONFIG_PXE_NO_PROMPT=$(CONFIG_PXE_NO_PROMPT) \ + CONFIG_PXE_HAS_HTTPS=$(CONFIG_PXE_HAS_HTTPS) \ + MFLAGS= MAKEFLAGS= + +# LinuxBoot + +linuxboot: + $(MAKE) -C payloads/external/LinuxBoot \ + CPUS=$(CPUS) \ + CONFIG_LINUXBOOT_X86_64=$(CONFIG_LINUXBOOT_X86_64) \ + CONFIG_LINUXBOOT_X86=$(CONFIG_LINUXBOOT_X86) \ + CONFIG_LINUXBOOT_ARM64=$(CONFIG_LINUXBOOT_ARM64) \ + CONFIG_LINUXBOOT_KERNEL=$(CONFIG_PAYLOAD_FILE) \ + CONFIG_LINUXBOOT_INITRAMFS=$(CONFIG_LINUX_INITRD) \ + CONFIG_LINUXBOOT_INITRAMFS_SUFFIX=$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) \ + CONFIG_LINUXBOOT_COMPILE_KERNEL=$(CONFIG_LINUXBOOT_COMPILE_KERNEL) \ + CONFIG_LINUXBOOT_BUILD_INITRAMFS=$(CONFIG_LINUXBOOT_BUILD_INITRAMFS) \ + CONFIG_LINUXBOOT_KERNEL_MAINLINE=$(CONFIG_LINUXBOOT_KERNEL_MAINLINE) \ + CONFIG_LINUXBOOT_KERNEL_STABLE=$(CONFIG_LINUXBOOT_KERNEL_STABLE) \ + CONFIG_LINUXBOOT_KERNEL_LONGTERM=$(CONFIG_LINUXBOOT_KERNEL_LONGTERM) \ + CONFIG_LINUXBOOT_KERNEL_CUSTOM=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM) \ + CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION) \ + CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG) \ + CONFIG_LINUXBOOT_KERNEL_BZIMAGE=$(CONFIG_LINUXBOOT_KERNEL_BZIMAGE) \ + CONFIG_LINUXBOOT_KERNEL_UIMAGE=$(CONFIG_LINUXBOOT_KERNEL_UIMAGE) \ + CONFIG_LINUXBOOT_KERNEL_CONFIGFILE=$(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) \ + CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ=$(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ) \ + CONFIG_LINUXBOOT_UROOT=$(CONFIG_LINUXBOOT_UROOT) \ + CONFIG_LINUXBOOT_UROOT_VERSION=$(CONFIG_LINUXBOOT_UROOT_VERSION) \ + CONFIG_LINUXBOOT_UROOT_FORMAT=$(CONFIG_LINUXBOOT_UROOT_FORMAT) \ + CONFIG_LINUXBOOT_UROOT_INITCMD=$(CONFIG_LINUXBOOT_UROOT_INITCMD) \ + CONFIG_LINUXBOOT_UROOT_SHELL=$(CONFIG_LINUXBOOT_UROOT_SHELL) \ + CONFIG_LINUXBOOT_UROOT_COMMANDS=$(CONFIG_LINUXBOOT_UROOT_COMMANDS) \ + CONFIG_LINUXBOOT_UROOT_FILES=$(CONFIG_LINUXBOOT_UROOT_FILES) \ + CONFIG_LINUXBOOT_DTB_FILE=$(CONFIG_LINUXBOOT_DTB_FILE) + +payloads/external/LinuxBoot/linuxboot/bzImage: linuxboot +payloads/external/LinuxBoot/linuxboot/uImage: linuxboot +payloads/external/LinuxBoot/linuxboot/initramfs_u-root.cpio: linuxboot + +# Yabits + +payloads/external/Yabits/uefi/build/uefi.elf yabits: + $(MAKE) -C payloads/external/Yabits all \ + XGCCPATH="$(XGCCPATH)" \ + CONFIG_YABITS_REVISION=$(CONFIG_YABITS_REVISION) \ + CONFIG_YABITS_REVISION_ID=$(CONFIG_YABITS_REVISION_ID) \ + CONFIG_YABITS_MASTER=$(CONFIG_YABITS_MASTER) \ + CONFIG_YABITS_STABLE=$(CONFIG_YABITS_STABLE) \ + MFLAGS= MAKEFLAGS= + +# BOOTBOOT + +payloads/external/BOOTBOOT/bootboot/dist/bootbootcb.elf: + $(MAKE) -C payloads/external/BOOTBOOT all + diff --git a/x86_64-cb/Makefile b/x86_64-cb/Makefile new file mode 100644 index 0000000..d6dceec --- /dev/null +++ b/x86_64-cb/Makefile @@ -0,0 +1,43 @@ +TARGET=../dist/bootbootcb.elf + +# get build environment +ifndef LIBCONFIG_PATH +LIBCONFIG_PATH := ../../coreboot/payloads/libpayload +ifeq ($(wildcard $(LIBCONFIG_PATH)/*),) +LIBCONFIG_PATH := ../../../../libpayload +endif +endif +LIBPAYLOAD_DIR=$(CURDIR)/libpayload +XCOMPILE=$(LIBPAYLOAD_DIR)/libpayload.xcompile +# build libpayload and put .config file in $(CURDIR) instead of ../libpayload +# to avoid pollute the libpayload source directory and possible conflicts +LPOPTS=obj="$(CURDIR)/build" DESTDIR="$(CURDIR)" DOTCONFIG="$(CURDIR)/.config" +CFLAGS += -Wall -Wvla -Werror -Os -ffreestanding -nostdinc -nostdlib + +all: $(TARGET) + +$(LIBPAYLOAD_DIR): + $(MAKE) -C $(LIBCONFIG_PATH) $(LPOPTS) defconfig + $(MAKE) -C $(LIBCONFIG_PATH) $(LPOPTS) + $(MAKE) -C $(LIBCONFIG_PATH) $(LPOPTS) install + +ifneq ($(strip $(wildcard libpayload)),) +include $(XCOMPILE) +LPGCC = CC="$(GCC_CC_x86_32)" "$(LIBPAYLOAD_DIR)/bin/lpgcc" +$(TARGET): + $(LPGCC) $(CFLAGS) -o $(TARGET) bootboot.c +else +# If libpayload is not found, first build libpayload, +# then do the make, this time it'll find libpayload +# and generate the elf target +$(TARGET): $(LIBPAYLOAD_DIR) + $(MAKE) all +endif + +clean: + rm -f $(TARGET) + +distclean: clean + rm -rf build libpayload .config .config.old + +.PHONY: all clean distclean diff --git a/x86_64-cb/OLVASSEL.md b/x86_64-cb/OLVASSEL.md new file mode 100644 index 0000000..62a3a5f --- /dev/null +++ b/x86_64-cb/OLVASSEL.md @@ -0,0 +1,84 @@ +BOOTBOOT Coreboot x86_64 Implementáció +====================================== + +Általános leírásért lásd a [BOOTBOOT Protokoll](https://gitlab.com/bztsrc/bootboot)t. + +Ez [coreboot](https://coreboot.org) payloadként implementálja a BOOTBOOT Protokollt. Jelenleg __FEJLESZTÉS ALATT__. +A coreboot fordítási környezetben fordítandó. + +Fordítás +-------- + +### 1. lépés - Függőségek telepítése + +Először is, telepíteni kell a [coreboot függőségei](https://doc.coreboot.org/tutorial/part1.html)t: bison, build-essentials, curl, +flex, git, gnat, libncurses5-dev, m4, zlib. A legfrissebb listáért nézd meg a linkelt dokumentumot. + +### 2. lépés - A coreboot beszerzése + +Töltsd le a coreboot-ot minden almoduljával együtt +```sh +$ git clone https://review.coreboot.org/coreboot +$ cd coreboot +$ git submodule update --init +``` +Nagyon fontos, hogy inicializáld az almodulokat, máskülönben nem fog lefordulni a coreboot. + +### 3. lépés - Fordítókörnyezet (toolchain) létrehozása + +Ez el fog tartani egy jódarabig. A *$(nproc)* helyett add meg, hogy hány CPU core-od van. +```sh +$ make crossgcc-i386 CPUS=$(nproc) +``` + +### 4. lépés - A coreboot pecselése és konfigurálása + +Másold át és írd felül a [../coreboot könyvtár](https://gitlab.com/bztsrc/bootboot/tree/master/coreboot) fájlait a +coreboot projekted munkakönyvtárába. Ez frissíteni fogja a coreboot konfigurációs rendszerét. + +Ezután be kell konfigurálnod a coreboot-ot, hogy milyen alaplapot (vagy qemu-t) kezeljen, és hogy BOOTBOOT-al induljon. +```sh +$ make menuconfig + válaszd a 'Mainboard' menüt + alatta a 'Mainboard vendor' legyen '(Emulation)' + alatta a 'Mainboard model' legyen 'QEMU x86 i440fx/piix4' + válaszd az 'Exit'-t + válaszd a 'Payload' menüt + válaszd az 'Add a Payload' opciót + válaszd ki a 'BOOTBOOT'-ot + válaszd az 'Exit'-t + válaszd az 'Exit'-t + válaszd a 'Yes'-t +``` + +### 5. lépés - A coreboot fordítása + +```sh +$ make +``` + +### 6. lépés - A frissen fordított ROM tesztelése QEMU-n + +Bővebb információért lásd a [coreboot dokumentáció](https://doc.coreboot.org/mainboard/emulation/qemu-i440fx.html)t. +```sh +$ qemu-system-x86_64 -bios $(COREBOOT)/build/coreboot.rom -drive file=$(BOOTBOOT)/images/disk-x86.img,format=raw -serial stdio +``` + +Gép állapot +----------- + +IRQ-k letiltva, GDT nincs meghatározva, de érvényes, IDT nincs beállítva. SSE, SMP engedélyezve. Kód felügyeleti módban, 0-ás gyűrűn +fut minden processzormagon. + +Telepítés +--------- + +Miután lefordítottad a coreboot ROM-ot BOOTBOOT payloaddal, [flashelheted a build/coreboot.rom](https://doc.coreboot.org/flash_tutorial/index.html) +fájlt az alaplapodra. + +Limitációk +---------- + + - Mivel védett módban indul, csak az első 4G-nyi RAM-ot képezi le. + - A CMOS nvram nem tárol időzónát, ezért mindig GMT+0 kerül a bootboot.timezone-ba. + - Csak a SHA-XOR-CBC titkosítást ismeri, nincs AES diff --git a/x86_64-cb/README.md b/x86_64-cb/README.md new file mode 100644 index 0000000..df3b9a3 --- /dev/null +++ b/x86_64-cb/README.md @@ -0,0 +1,83 @@ +BOOTBOOT Coreboot x86_64 Implementation +======================================= + +See [BOOTBOOT Protocol](https://gitlab.com/bztsrc/bootboot) for common details. + +Implements the BOOTBOOT Protocol as a [coreboot](https://coreboot.org) payload. Currently __EXPERIMENTAL__. +Must be compiled using the coreboot build environment. + +Compilation +----------- + +### Step 1 - Install dependencies + +First, install the [coreboot dependencies](https://doc.coreboot.org/tutorial/part1.html): bison, build-essentials, curl, +flex, git, gnat, libncurses5-dev, m4, zlib. Please refer to the linked doc for up-to-date list of dependencies. + +### Step 2 - Get coreboot + +Download coreboot and its submodules +```sh +$ git clone https://review.coreboot.org/coreboot +$ cd coreboot +$ git submodule update --init +``` +It is very important to initialize submodules, otherwise you won't be able to compile coreboot. + +### Step 3 - Create toolchain + +This step could take a while. Replace *$(nproc)* with the number of CPU cores you have. +```sh +$ make crossgcc-i386 CPUS=$(nproc) +``` + +### Step 4 - Patch coreboot and configure + +Copy and overwrite files from [../coreboot directory](https://gitlab.com/bztsrc/bootboot/tree/master/coreboot) to the +coreboot working directory. This will update the coreboot configuration system. + +Now configure coreboot for your motherboard (or qemu) and BOOTBOOT. +```sh +$ make menuconfig + select 'Mainboard' menu + Beside 'Mainboard vendor' should be '(Emulation)' + Beside 'Mainboard model' should be 'QEMU x86 i440fx/piix4' + select 'Exit' + select 'Payload' menu + select 'Add a Payload' + choose 'BOOTBOOT' + select 'Exit' + select 'Exit' + select 'Yes' +``` + +### Step 5 - Build coreboot + +```sh +$ make +``` + +### Step 6 - Test the newly compiled ROM in QEMU + +For more information, read [coreboot docs](https://doc.coreboot.org/mainboard/emulation/qemu-i440fx.html). +```sh +$ qemu-system-x86_64 -bios $(COREBOOT)/build/coreboot.rom -drive file=$(BOOTBOOT)/images/disk-x86.img,format=raw -serial stdio +``` + +Machine state +------------- + +IRQs masked. GDT unspecified, but valid, IDT unset. SSE, SMP enabled. Code is running in supervisor mode in ring 0 on all cores. + +Installation +------------ + +Once you have compiled a coreboot ROM with the BOOTBOOT payload, you can +[flash the build/coreboot.rom](https://doc.coreboot.org/flash_tutorial/index.html) file to your mainboard. + +Limitations +----------- + + - As it boots in protected mode, it only maps the first 4G of RAM. + - The CMOS nvram does not store timezone, so always GMT+0 returned in bootboot.timezone. + - Only supports SHA-XOR-CBC, no AES diff --git a/x86_64-cb/bootboot.c b/x86_64-cb/bootboot.c new file mode 100644 index 0000000..07bf909 --- /dev/null +++ b/x86_64-cb/bootboot.c @@ -0,0 +1,54 @@ +/* + * x86_64-cb/bootboot.c + * + * Copyright (C) 2017 - 2020 bzt (bztsrc@gitlab) + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * This file is part of the BOOTBOOT Protocol package. + * @brief Boot loader for the x86_64 coreboot payload + * + */ + +#define BBDEBUG 1 + +#include +#include + +extern struct sysinfo_t lib_sysinfo; + +int main(void) +{ + int ret, i; + + printf("Hello World!\n"); + + ret = lib_get_sysinfo(); + if (ret) halt(); + + printf("Number of memory ranges: %d\n", lib_sysinfo.n_memranges); + for (i = 0; i < lib_sysinfo.n_memranges; i++) { + printf("%d: base 0x%08llx size 0x%08llx type 0x%x\n", i, lib_sysinfo.memrange[i].base, lib_sysinfo.memrange[i].size, lib_sysinfo.memrange[i].type); + } + printf("Now we will halt. Bye\n"); + halt(); + return 0; +}