[COMMIT osv master] [PATCH 3/4] arm on firecracker: clean cmdline from early console artifacts

3 views
Skip to first unread message

Commit Bot

unread,
Jun 27, 2020, 11:33:14 AM6/27/20
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

[PATCH 3/4] arm on firecracker: clean cmdline from early console artifacts

In order to enable early console on firecracker, we have
to prepend the command line with 'console=...' name,value pair.
Firecracker then appends extra name,value pair containing
memory address of the console base register in form of 'earlycon='

We actually do not need to parse this information from command line,
instead we get it from DTB which one of the previous patches
addresses. So all in all, the only purpose of this patch
is to remove this irrelevant information if present so that
command line contains normal OSv boot parameters.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/arch/aarch64/arch-setup.cc b/arch/aarch64/arch-setup.cc
--- a/arch/aarch64/arch-setup.cc
+++ b/arch/aarch64/arch-setup.cc
@@ -115,6 +115,7 @@ void arch_setup_free_memory()
arch_setup_pci();

// get rid of the command line, before memory is unmapped
+ console::mmio_isa_serial_console::clean_cmdline(cmdline);
osv::parse_cmdline(cmdline);

mmu::switch_to_runtime_page_tables();
diff --git a/drivers/mmio-isa-serial.cc b/drivers/mmio-isa-serial.cc
--- a/drivers/mmio-isa-serial.cc
+++ b/drivers/mmio-isa-serial.cc
@@ -35,6 +35,42 @@ void mmio_isa_serial_console::memory_map()
}
}

+static void remove_property_name_value(char *cmdline, const char *prefix)
+{
+ char *prefix_pos = strstr(cmdline, prefix);
+ if (!prefix_pos)
+ return;
+
+ // Verify that 1st preceding character is a white space
+ if (prefix_pos > cmdline && !isspace(*(prefix_pos - 1)))
+ return;
+
+ // Find first white-character or null as an end of the property value
+ char *next_char_pos = prefix_pos + strlen(prefix);
+ while (*next_char_pos && !isspace(*next_char_pos))
+ next_char_pos++;
+
+ // Remove any space characters before
+ while (prefix_pos > cmdline && isspace(*(prefix_pos - 1))) {
+ prefix_pos--;
+ };
+
+ // Remove entire name=value pair from cmdline by copying over the remaining part
+ do {
+ *prefix_pos = *next_char_pos++;
+ } while (*prefix_pos++);
+}
+
+#define CONSOLE_PREFIX "console="
+#define MMIO_ISA_CONSOLE_PREFIX "earlycon="
+void mmio_isa_serial_console::clean_cmdline(char *cmdline)
+{
+ if (_phys_mmio_address) {
+ remove_property_name_value(cmdline, CONSOLE_PREFIX);
+ remove_property_name_value(cmdline, MMIO_ISA_CONSOLE_PREFIX);
+ }
+}
+
void mmio_isa_serial_console::dev_start() {
_irq.reset(new spi_interrupt(gic::irq_type::IRQ_TYPE_EDGE, irqid,
[&] { return true; },
diff --git a/drivers/mmio-isa-serial.hh b/drivers/mmio-isa-serial.hh
--- a/drivers/mmio-isa-serial.hh
+++ b/drivers/mmio-isa-serial.hh
@@ -17,6 +17,7 @@ public:
void set_irqid(int irqid) { this->irqid = irqid; }
static void early_init(u64 mmio_phys_address);
static void memory_map();
+ static void clean_cmdline(char *cmdline);
static mmioaddr_t _addr_mmio;
static u64 _phys_mmio_address;
private:
Reply all
Reply to author
Forward
0 new messages