diff options
author | Ronald G. Minnich <rminnich@gmail.com> | 2018-09-14 01:21:05 -0700 |
---|---|---|
committer | Ronald G. Minnich <rminnich@gmail.com> | 2018-09-14 09:59:17 +0000 |
commit | 95c331b94b1d04ea34b480c83613c2141a02697e (patch) | |
tree | c21c9753964d6d70e8fec85e9b6f075cac87883f /payloads/linuxcheck | |
parent | 374d992fc831300377216fd3f7c3137d4b53ab36 (diff) | |
download | coreboot-95c331b94b1d04ea34b480c83613c2141a02697e.tar.xz |
rampayload: Add the linuxcheck payload
The i386.c file uses standard 3f8 UART for some simple diagnostic
prints, and the libpayload console otherwise.
This payload was used to debug Linux as a rampayload and was very helpful
for that work.
Change-Id: I1cce5528780cd825fd91a88137fa70abd9f218e7
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-on: https://review.coreboot.org/28600
Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'payloads/linuxcheck')
-rw-r--r-- | payloads/linuxcheck/Makefile | 37 | ||||
-rw-r--r-- | payloads/linuxcheck/i386.c | 48 | ||||
-rw-r--r-- | payloads/linuxcheck/linuxcheck.c | 52 | ||||
-rw-r--r-- | payloads/linuxcheck/linuxcheck.h | 22 |
4 files changed, 159 insertions, 0 deletions
diff --git a/payloads/linuxcheck/Makefile b/payloads/linuxcheck/Makefile new file mode 100644 index 0000000000..b967369e1a --- /dev/null +++ b/payloads/linuxcheck/Makefile @@ -0,0 +1,37 @@ +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 -Werror -Os -ffreestanding -nostdinc -nostdlib +ifeq ($(CONFIG_ARCH_X86),y) +TARGETARCH = i386 +endif + +all: linuxcheck.elf + +$(LIBPAYLOAD_DIR): + $(MAKE) -C ../libpayload $(LPOPTS) defconfig + $(MAKE) -C ../libpayload $(LPOPTS) + $(MAKE) -C ../libpayload $(LPOPTS) install + +ifneq ($(strip $(wildcard libpayload)),) +include $(XCOMPILE) +LPGCC = CC="$(GCC_CC_x86_32)" "$(LIBPAYLOAD_DIR)/bin/lpgcc" +%.elf: %.c Makefile + $(LPGCC) $(CFLAGS) -o $*.elf $*.c $(TARGETARCH).c +else +# If libpayload is not found, first build libpayload, +# then do the make, this time it'll find libpayload +# and generate the linuxcheck.elf target +%.elf: $(LIBPAYLOAD_DIR) + $(MAKE) all +endif + +clean: + rm -f linuxcheck.elf + +distclean: clean + rm -rf build libpayload .config .config.old + +.PHONY: all clean distclean diff --git a/payloads/linuxcheck/i386.c b/payloads/linuxcheck/i386.c new file mode 100644 index 0000000000..2b4b541f1e --- /dev/null +++ b/payloads/linuxcheck/i386.c @@ -0,0 +1,48 @@ +/* + * This file is part of the coreinfo project. + * + * Copyright (C) 2018 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <libpayload-config.h> +#include <libpayload.h> +#include "linuxcheck.h" + +void buts(char *s) +{ + int i; + for (i = 0; i < strlen(s); i++) + outb(s[i], 0x3f8); +} + +void hex4(u8 c) +{ + static char *hex = "0123456789abcdef"; + outb(hex[c & 0xf], 0x3f8); +} + +void hex8(u8 c) +{ + hex4(c >> 4); + hex4(c); +} + +void hex16(u16 c) +{ + hex8((u8)(c >> 8)); + hex8((u8)c); +} +void hex32(u32 c) +{ + hex16((u16)(c >> 16)); + hex16((u16)c); +} diff --git a/payloads/linuxcheck/linuxcheck.c b/payloads/linuxcheck/linuxcheck.c new file mode 100644 index 0000000000..5e0fdba703 --- /dev/null +++ b/payloads/linuxcheck/linuxcheck.c @@ -0,0 +1,52 @@ +/* + * This file is part of the coreinfo project. + * + * Copyright (C) 2018 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <libpayload-config.h> +#include <libpayload.h> +#include "linuxcheck.h" + +extern struct console_output_driver *console_out; +extern struct sysinfo_t lib_sysinfo; + +int main(void) +{ + int ret, i; + + buts("Greetings from linuxcheck, via hard-coded calls to serial functions.\n"); + if (console_out == NULL) + buts("Bad news: console_out is NULL\n"); + if (lib_sysinfo.serial == NULL) + buts("Bad news: lib_sysinfo.serial is NULL. Very little will work well.\n"); + ret = lib_get_sysinfo(); + if (ret) { + buts("lib_get_sysinfo() is non-zero"); + hex32(ret); + buts("\n"); + } + + buts("The next line should be puts works\n"); + puts("puts works\n"); + buts("If you did not see puts works, then you have a console issues\n"); + buts("The next line should be 'printf works'\n"); + printf("printf works\n"); + buts(" ... if you did not see printf works, then you have a printf issue\n"); + 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); + } + buts("Now we will halt. Bye"); + halt(); + return 0; +} diff --git a/payloads/linuxcheck/linuxcheck.h b/payloads/linuxcheck/linuxcheck.h new file mode 100644 index 0000000000..b707876556 --- /dev/null +++ b/payloads/linuxcheck/linuxcheck.h @@ -0,0 +1,22 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2018 Google Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* buts is a programmed IO byte puts, which you need to write for all platforms. */ +void buts(char *s); + +void hex4(u8 c); +void hex8(u8 c); +void hex16(u16 c); +void hex32(u32 c); |