[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCHv6 22/37] plat/kvm: Parse command line from device tree for Arm64


  • To: <minios-devel@xxxxxxxxxxxxxxxxxxxx>, <simon.kuenzer@xxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Fri, 14 Sep 2018 07:56:55 +0000
  • Authentication-results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=bestguesspass action=none header.from=arm.com;
  • Cc: Kaly.Xin@xxxxxxx, nd@xxxxxxx, wei.chen@xxxxxxx
  • Delivery-date: Fri, 14 Sep 2018 07:58:29 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Nodisclaimer: True
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

From: Wei Chen <Wei.Chen@xxxxxxx>

Device tree has a "chosen" node, this node can be used to pass
parameters to virtual machine through bootargs property. We can
use this feature to pass command line to unikraft application,
and then parse it from device tree for further usage.

The command line will be modified in uk_argparse, but the memory
attribute of DTB is readonly, we need a copy of this command line.

Signed-off-by: Wei Chen <Wei.Chen@xxxxxxx>
Reviewed-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 plat/kvm/arm/setup.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/plat/kvm/arm/setup.c b/plat/kvm/arm/setup.c
index 40d104b..d59956a 100644
--- a/plat/kvm/arm/setup.c
+++ b/plat/kvm/arm/setup.c
@@ -24,6 +24,9 @@
 
 void *_libkvmplat_dtb;
 
+#define MAX_CMDLINE_SIZE 1024
+static char cmdline[MAX_CMDLINE_SIZE];
+
 static void _init_dtb(void *dtb_pointer)
 {
        int ret;
@@ -35,10 +38,39 @@ static void _init_dtb(void *dtb_pointer)
        uk_printd(DLVL_INFO, "Found device tree on: %p\n", dtb_pointer);
 }
 
+static void _dtb_get_cmdline(char *cmdline, size_t maxlen)
+{
+       int fdtchosen, len;
+       const char *fdtcmdline;
+
+       /* TODO: Proper error handling */
+       fdtchosen = fdt_path_offset(_libkvmplat_dtb, "/chosen");
+       if (!fdtchosen)
+               goto enocmdl;
+       fdtcmdline = fdt_getprop(_libkvmplat_dtb, fdtchosen, "bootargs", &len);
+       if (!fdtcmdline || (len <= 0))
+               goto enocmdl;
+
+       strncpy(cmdline, fdtcmdline, MIN(maxlen, (unsigned int) len));
+       /* ensure null termination */
+       cmdline[((unsigned int) len - 1) <= (maxlen - 1) ?
+               ((unsigned int) len - 1) : (maxlen - 1)] = '\0';
+
+       uk_printd(DLVL_INFO, "Command line: %s\n", cmdline);
+       return;
+
+enocmdl:
+       uk_printd(DLVL_INFO, "No command line found\n");
+       strcpy(cmdline, CONFIG_UK_NAME);
+}
+
 void _libkvmplat_start(void *dtb_pointer)
 {
        _init_dtb(dtb_pointer);
        _libkvmplat_init_console();
 
-       UK_BUG();
+       uk_printd(DLVL_INFO, "Entering from KVM (arm64)...\n");
+
+       /* Get command line from DTB */
+       _dtb_get_cmdline(cmdline, sizeof(cmdline));
 }
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.