kexec: Update to 2.0.26, add framebuffer tracing

Update kexec to 2.0.26.  Add tracing to framebuffer initialization.  In
particular, the driver name is traced if not recognized, and messages
about kernel config are shown if the kernel doesn't provide the
framebuffer pointer.

Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
This commit is contained in:
Jonathon Hall 2023-04-19 14:16:38 -04:00
parent a75ecdfc8d
commit 353e836dc1
No known key found for this signature in database
GPG Key ID: 1E9C3CA91AE25114
3 changed files with 163 additions and 93 deletions

View File

@ -1,10 +1,10 @@
modules-$(CONFIG_KEXEC) += kexec
kexec_version := 2.0.22
kexec_version := 2.0.26
kexec_dir := kexec-tools-$(kexec_version)
kexec_tar := kexec-tools-$(kexec_version).tar.gz
kexec_url := https://kernel.org/pub/linux/utils/kernel/kexec/$(kexec_tar)
kexec_hash := 40623d4321be2865ef9ea2cd6ec998d31dcf93d0f74353cbd3aa06d8821e3e41
kexec_hash := 89bdd941542c64fec16311858df304ed3a3908c1a60874d69df5d9bf1611e062
kexec_configure := \
CFLAGS="-g -Os -fno-strict-aliasing -Wall -Wstrict-prototypes" \

View File

@ -1,91 +0,0 @@
diff --git a/Makefile.in b/Makefile.in
index fb01134..bf1973e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -157,12 +157,12 @@ include $(srcdir)/kexec/Makefile
# vmcore-dmesg (read dmesg from a vmcore)
#
-include $(srcdir)/vmcore-dmesg/Makefile
+#include $(srcdir)/vmcore-dmesg/Makefile
#
# kexec_test (test program)
#
-include $(srcdir)/kexec_test/Makefile
+#include $(srcdir)/kexec_test/Makefile
SPEC=$(PACKAGE_NAME).spec
GENERATED_SRCS:= $(SPEC)
diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index 057ee14..43e017a 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -137,7 +137,9 @@ static int setup_linux_vesafb(struct x86_linux_param_header *real_mode)
goto out;
if (-1 == ioctl(fd, FBIOGET_VSCREENINFO, &var))
goto out;
- if (0 == strcmp(fix.id, "VESA VGA")) {
+ if (0 == strcmp(fix.id, "VESA VGA")
+ || 0 == strcmp(fix.id, "inteldrmfb")
+ || 0 == strcmp(fix.id, "i915drmfb")) {
/* VIDEO_TYPE_VLFB */
real_mode->orig_video_isVGA = 0x23;
} else if (0 == strcmp(fix.id, "EFI VGA")) {
diff --git a/kexec/kexec.c b/kexec/kexec.c
index bc6ab3d..b82725b 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -805,6 +805,27 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
if (sort_segments(&info) < 0) {
return -1;
}
+
+#if 1
+ // force segment 0 to have memsz == bufsz
+ // so that it won't overwrite EBDA
+ if (info.segment[0].mem == 0)
+ {
+ if (kexec_debug)
+ printf("hack ebda into segment 0!\n");
+
+ uint8_t * ebda = calloc(1, info.segment[0].memsz);
+ memcpy(ebda, info.segment[0].buf, info.segment[0].bufsz);
+ info.segment[0].bufsz = info.segment[0].memsz;
+ info.segment[0].buf = ebda;
+
+ // install some default EBDA values that are off scale,
+ // which will force Xen to use the multiboot info
+ *(uint16_t*)(ebda + 0x40e) = 0xFFFF; // segment
+ *(uint16_t*)(ebda + 0x413) = 0xFFFF; // size
+ }
+#endif
+
/* if purgatory is loaded update it */
update_purgatory(&info);
if (entry)
diff --git a/purgatory/Makefile b/purgatory/Makefile
index 2dd6c47..2de8f07 100644
--- a/purgatory/Makefile
+++ b/purgatory/Makefile
@@ -44,7 +44,6 @@ purgatory/sha256.o: $(srcdir)/util_lib/sha256.c
mkdir -p $(@D)
$(COMPILE.c) -o $@ $^
-$(PURGATORY): CC=$(TARGET_CC)
$(PURGATORY): CFLAGS=$(PURGATORY_EXTRA_CFLAGS) \
$($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
-Os -fno-builtin -ffreestanding \
diff --git a/util/Makefile b/util/Makefile
index 948ee63..833a897 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -2,7 +2,7 @@ BIN_TO_HEX:= bin/bin-to-hex
$(BIN_TO_HEX): $(srcdir)/util/bin-to-hex.c
@$(MKDIR) -p $(@D)
- $(LINK.o) $(CFLAGS) -o $@ $^
+ $(BUILD_CC) $(BUILD_CFLAGS) -o $@ $^
$(BIN_TO_HEX): CC=$(BUILD_CC)
$(BIN_TO_HEX): CFLAGS=$(BUILD_CFLAGS)

161
patches/kexec-2.0.26.patch Normal file
View File

@ -0,0 +1,161 @@
diff --git a/Makefile.in b/Makefile.in
index 09bbd5c..500ad35 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -167,12 +167,12 @@ include $(srcdir)/kexec/Makefile
# vmcore-dmesg (read dmesg from a vmcore)
#
-include $(srcdir)/vmcore-dmesg/Makefile
+#include $(srcdir)/vmcore-dmesg/Makefile
#
# kexec_test (test program)
#
-include $(srcdir)/kexec_test/Makefile
+#include $(srcdir)/kexec_test/Makefile
SPEC=$(PACKAGE_NAME).spec
GENERATED_SRCS:= $(SPEC)
diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index 14263b0..55291d6 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -138,31 +138,76 @@ static int setup_linux_vesafb(struct x86_linux_param_header *real_mode)
if (-1 == fd)
return -1;
- if (-1 == ioctl(fd, FBIOGET_FSCREENINFO, &fix))
+ if (-1 == ioctl(fd, FBIOGET_FSCREENINFO, &fix)) {
+ dbgprintf("%s: FBIOGET_FSCREENINFO failed, can't provide framebuffer\n",
+ __func__);
goto out;
- if (-1 == ioctl(fd, FBIOGET_VSCREENINFO, &var))
+ }
+ if (-1 == ioctl(fd, FBIOGET_VSCREENINFO, &var)) {
+ dbgprintf("%s: FBIOGET_FSCREENINFO failed, can't provide framebuffer\n",
+ __func__);
goto out;
- if (0 == strcmp(fix.id, "VESA VGA")) {
+ }
+ /*
+ * If we can get a framebuffer from the host kernel, provide it to the
+ * target kernel. This does not work for all drivers - we have to be
+ * able to get the framebuffer address, and the framebuffer must be a
+ * plain flat framebuffer. This should work for VESA framebuffers
+ * since that is the only type of framebuffer it creates.
+ *
+ * Since Linux 4.20, getting the framebuffer address requires
+ * CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM and
+ * drm_kms_helper.drm_leak_fbdev_smem=1 on the command line.
+ *
+ * Since Linux 5.8, i915 often uses a compressed framebuffer, this must
+ * be disabled with i915.enable_fbc=0 on the kernel command line.
+ *
+ * This does not work with ast ("astdrmfb") currently as it uses a
+ * shadow buffer internally in the kernel, and there is no way to get
+ * the real framebuffer address.
+ */
+ if (0 == strcmp(fix.id, "VESA VGA")
+ || 0 == strcmp(fix.id, "inteldrmfb")
+ || 0 == strcmp(fix.id, "i915drmfb")) {
/* VIDEO_TYPE_VLFB */
real_mode->orig_video_isVGA = 0x23;
+ dbgprintf("%s: Found driver %s, providing VIDEO_TYPE_VLFB\n",
+ __func__, fix.id);
} else if (0 == strcmp(fix.id, "EFI VGA")) {
/* VIDEO_TYPE_EFI */
real_mode->orig_video_isVGA = 0x70;
+ dbgprintf("%s: Found driver %s, providing VIDEO_TYPE_EFI\n",
+ __func__, fix.id);
} else if (arch_options.reuse_video_type) {
int err;
off_t offset = offsetof(typeof(*real_mode), orig_video_isVGA);
/* blindly try old boot time video type */
err = get_bootparam(&real_mode->orig_video_isVGA, offset, 1);
- if (err)
+ if (err) {
+ dbgprintf("%s: Can't get booted video type, can't provide framebuffer\n",
+ __func__);
goto out;
+ }
+ dbgprintf("%s: Reusing video type %d\n",
+ __func__, real_mode->orig_video_isVGA);
} else {
+ dbgprintf("%s: Unknown driver %s, can't provide framebuffer\n",
+ __func__, fix.id);
real_mode->orig_video_isVGA = 0;
close(fd);
return 0;
}
close(fd);
+ if (!fix.smem_start) {
+ dbgprintf("%s: Kernel did not provide framebuffer address\n",
+ __func__);
+ dbgprintf("%s: Try enabling CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM and "
+ "drm_kms_helper.drm_leak_fbdev_smem\n",
+ __func__);
+ }
+
real_mode->lfb_width = var.xres;
real_mode->lfb_height = var.yres;
real_mode->lfb_depth = var.bits_per_pixel;
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 0e92d96..f7984a8 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -807,6 +807,27 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
if (sort_segments(&info) < 0) {
return -1;
}
+
+#if 1
+ // force segment 0 to have memsz == bufsz
+ // so that it won't overwrite EBDA
+ if (info.segment[0].mem == 0)
+ {
+ if (kexec_debug)
+ printf("hack ebda into segment 0!\n");
+
+ uint8_t * ebda = calloc(1, info.segment[0].memsz);
+ memcpy(ebda, info.segment[0].buf, info.segment[0].bufsz);
+ info.segment[0].bufsz = info.segment[0].memsz;
+ info.segment[0].buf = ebda;
+
+ // install some default EBDA values that are off scale,
+ // which will force Xen to use the multiboot info
+ *(uint16_t*)(ebda + 0x40e) = 0xFFFF; // segment
+ *(uint16_t*)(ebda + 0x413) = 0xFFFF; // size
+ }
+#endif
+
/* if purgatory is loaded update it */
update_purgatory(&info);
if (entry)
diff --git a/purgatory/Makefile b/purgatory/Makefile
index 4d2d071..ee5c642 100644
--- a/purgatory/Makefile
+++ b/purgatory/Makefile
@@ -45,7 +45,6 @@ purgatory/sha256.o: $(srcdir)/util_lib/sha256.c
mkdir -p $(@D)
$(COMPILE.c) -o $@ $^
-$(PURGATORY): CC=$(TARGET_CC)
$(PURGATORY): CFLAGS=$(PURGATORY_EXTRA_CFLAGS) \
$($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
-Os -fno-builtin -ffreestanding \
diff --git a/util/Makefile b/util/Makefile
index 948ee63..833a897 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -2,7 +2,7 @@ BIN_TO_HEX:= bin/bin-to-hex
$(BIN_TO_HEX): $(srcdir)/util/bin-to-hex.c
@$(MKDIR) -p $(@D)
- $(LINK.o) $(CFLAGS) -o $@ $^
+ $(BUILD_CC) $(BUILD_CFLAGS) -o $@ $^
$(BIN_TO_HEX): CC=$(BUILD_CC)
$(BIN_TO_HEX): CFLAGS=$(BUILD_CFLAGS)