Jonathan Zhang has uploaded this change for review.

View Change

[RFC]mb/ocp/deltalake: append Linuxboot command line option

If Linuxboot is used as payload, and if corresponding VPD variable
is set, use the value to append Linuxboot command line option as
defined at build time.

With this, user can customize linuxboot boot behavior without needing
a different image. For example, user can increase log level.

Note that this code should not be in mainboard, I hope to get
community feedback on where it should be.

TESTED=tested on DeltaLake, with this VPD setting:
vpd -f build/coreboot.rom -i RW_VPD -s linux_command_line="loglevel=7 cpuidle.off=1"

Signed-off-by: Jonathan Zhang <jonzhang@fb.com>
Signed-off-by: Bryant Ou <Bryant.Ou.Q@gmail.com>
Change-Id: I5f5cde3957c2716864f55d70f18f47b493164ed8
---
M src/mainboard/ocp/deltalake/ramstage.c
M src/mainboard/ocp/deltalake/vpd.h
2 files changed, 49 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/55/47055/1
diff --git a/src/mainboard/ocp/deltalake/ramstage.c b/src/mainboard/ocp/deltalake/ramstage.c
index 9d57090..800ad5a 100644
--- a/src/mainboard/ocp/deltalake/ramstage.c
+++ b/src/mainboard/ocp/deltalake/ramstage.c
@@ -5,11 +5,13 @@
#include <bootstate.h>
#include <drivers/ipmi/ipmi_ops.h>
#include <drivers/ocp/dmi/ocp_dmi.h>
+#include <drivers/vpd/vpd.h>
#include <gpio.h>
#include <soc/lewisburg_pch_gpio_defs.h>
#include <soc/ramstage.h>
#include <soc/soc_util.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <smbios.h>
#include <device/pci_def.h>
@@ -18,10 +20,15 @@
#include <hob_iiouds.h>
#include <hob_memmap.h>
#include <cpxsp_dl_gpio.h>
+#include <program_loading.h>

#include "ipmi.h"
+#include "vpd.h"

#define SLOT_ID_LEN 2
+/* copied from util/cbfstool/linux_trampoline.h */
+#define COMMAND_LINE_LOC 0x91000
+#define LINUX_CMD_LEN 72

extern struct fru_info_str fru_strings;
static char slot_id_str[SLOT_ID_LEN];
@@ -307,3 +314,42 @@
}

BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, pull_post_complete_pin, NULL);
+
+#if CONFIG_PAYLOAD_LINUX
+/*
+ * If Linuxboot is the payload, and if LINUX_COMMAND_LINE is defined as VPD
+ * variable, use the value to append original Linux command line option as
+ * defined at build time
+ */
+void platform_segment_loaded(uintptr_t start, size_t size, int flags)
+{
+ if (start != COMMAND_LINE_LOC)
+ return;
+
+ char cmdline[LINUX_CMD_LEN] = "";
+ if (!vpd_gets(LINUX_COMMAND_LINE, cmdline, LINUX_CMD_LEN, VPD_RW_THEN_RO))
+ return;
+
+ char *orig_cmdline = strdup((char *)start);
+ char *new_cmdline = NULL;
+ size_t new_cmdline_len;
+ printk(BIOS_INFO, "Build time defined Linux command line: %s\n",
+ orig_cmdline);
+ printk(BIOS_INFO, "VPD defined Linux command line: %s\n", cmdline);
+
+ new_cmdline = strconcat(orig_cmdline, " ");
+ new_cmdline = strconcat(new_cmdline, cmdline);
+ new_cmdline_len = strlen(new_cmdline);
+ printk(BIOS_INFO, "Updated Linux command line: %s, len: %ld\n", new_cmdline, new_cmdline_len);
+ if (new_cmdline_len >= size) {
+ printk(BIOS_ERR, "Updated Linux command line has size %ld bigger than %ld.\n",
+ new_cmdline_len, size);
+ free(new_cmdline);
+ return;
+ }
+
+ memset((uint8_t *)start, 0, size);
+ memcpy((uint8_t *)start, new_cmdline, strlen(new_cmdline));
+ free(new_cmdline);
+}
+#endif
diff --git a/src/mainboard/ocp/deltalake/vpd.h b/src/mainboard/ocp/deltalake/vpd.h
index 43070c2..cb9588b 100644
--- a/src/mainboard/ocp/deltalake/vpd.h
+++ b/src/mainboard/ocp/deltalake/vpd.h
@@ -36,4 +36,7 @@
#define COREBOOT_LOG_LEVEL "coreboot_log_level"
#define COREBOOT_LOG_LEVEL_DEFAULT 4

+/* Linuxboot kernel command line */
+#define LINUX_COMMAND_LINE "linux_command_line"
+
#endif

To view, visit change 47055. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I5f5cde3957c2716864f55d70f18f47b493164ed8
Gerrit-Change-Number: 47055
Gerrit-PatchSet: 1
Gerrit-Owner: Jonathan Zhang <jonzhang@fb.com>
Gerrit-MessageType: newchange