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

Re: [Minios-devel] [UNIKRAFT PATCHv4 31/43] plat/kvm: Parse command line from device tree for Arm64



Hi Julien,

> -----Original Message-----
> From: Julien Grall <julien.grall@xxxxxxx>
> Sent: 2018年7月16日 21:01
> To: Wei Chen <Wei.Chen@xxxxxxx>; minios-devel@xxxxxxxxxxxxxxxxxxxx;
> simon.kuenzer@xxxxxxxxx
> Cc: Kaly Xin <Kaly.Xin@xxxxxxx>; nd <nd@xxxxxxx>
> Subject: Re: [Minios-devel] [UNIKRAFT PATCHv4 31/43] plat/kvm: Parse command
> line from device tree for Arm64
> 
> Hi Wei,
> 
> On 06/07/18 10:03, Wei Chen wrote:
> > QEMU/KVM can pass parameters to virtual machine through command
> > line. For Arm64, this command line has been stored in device
> > tree. We should parse it from device tree for further usage.
> 
> I don't think this code is KVM specific :).
> 

Haha, Yes, it's not KVM or Arm64 specific.

> >
> > Signed-off-by: Wei Chen <Wei.Chen@xxxxxxx>
> > ---
> >   plat/kvm/arm/setup.c | 32 ++++++++++++++++++++++++++++++++
> >   1 file changed, 32 insertions(+)
> >
> > diff --git a/plat/kvm/arm/setup.c b/plat/kvm/arm/setup.c
> > index 892a0a9..a881152 100644
> > --- a/plat/kvm/arm/setup.c
> > +++ b/plat/kvm/arm/setup.c
> > @@ -36,6 +36,9 @@
> >   #include <uk/assert.h>
> >   #include <uk/essentials.h>
> >
> > +#define MAX_CMDLINE_SIZE 1024
> > +static char cmdline[MAX_CMDLINE_SIZE];
> > +
> >   void *_libkvmplat_dtb;
> >
> >   static void _init_dtb(void *dtb_pointer)
> > @@ -49,6 +52,32 @@ 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';
> 
> I don't think you need to copy the command line in an internal buffer.
> Device-Tree string are null terminated and AFAICT you keep the DT around
> for ever.
> 
> So how about turning cmdline to a pointer?
> 

Ok, that makes sense.

> > +
> > +   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);
> > +}
> > +
> >   static void _init_cpufeatures(void)
> >   {
> >     /* TODO */
> > @@ -61,4 +90,7 @@ void _libkvmplat_start(void *dtb_pointer)
> >     _libkvmplat_init_console();
> >
> >     uk_printd(DLVL_INFO, "Entering from KVM (arm64)...\n");
> > +
> > +   /* Get command line from DTB */
> > +   _dtb_get_cmdline(cmdline, sizeof(cmdline));
> >   }
> >
> 
> Cheers,
> 
> --
> Julien Grall
_______________________________________________
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®.