From: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
To: Andre Przywara <andre.przywara@arm.com>
Cc: <will.deacon@arm.com>, <kvm@vger.kernel.org>
Subject: Re: [RFC PATCH 2/2] Makefile: use xxd for converting guest/init
Date: Wed, 24 Jun 2015 10:53:17 +0200 [thread overview]
Message-ID: <20150624085317.GA30052@alberich> (raw)
In-Reply-To: <1435071987-7543-3-git-send-email-andre.przywara@arm.com>
On Tue, Jun 23, 2015 at 04:06:27PM +0100, Andre Przywara wrote:
> Currently we use ld to convert the static guest/init binary back
> into an object file, which we can embed as a binary blob into our
> lkvm binary. This works fine as long as compiler and linker use the
> same ELF target format, which seems to be not true for most of the
> MIPS toolchains.
> Use a different approach instead, which converts the guest/init
> binary into a C array, from which the compiler generates an .o
> representation. As the compiler is now the same, this naturally links
> together fine on all architectures.
> We use the "xxd" tool for generating a C array representation out of
> the binary file. If this turns out to be not widely installed (it
> seems to be part of the vim package in most distributions), we could
> think about switching to a scripted implementation using "od" or some
> printf trickery.
Works for me. (tested with an octeon-sdk toolchain)
Thanks,
Andreas
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> Makefile | 4 ++--
> builtin-run.c | 8 ++++----
> builtin-setup.c | 8 ++++----
> 3 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index b9480ff..7f2a0ea 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -365,8 +365,8 @@ $(PROGRAM_ALIAS): $(PROGRAM)
> $(Q) ln -f $< $@
>
> $(GUEST_OBJS): $(GUEST_INIT)
> - $(E) " LINK " $@
> - $(Q) $(LD) $(LDFLAGS) -r -b binary -o $@ $<
> + $(E) " CONVERT " $@
> + $(Q) xxd -i $< | $(CC) -c -x c - -o $@
>
> $(GUEST_INIT): guest/init.c
> $(E) " CC " $@
> diff --git a/builtin-run.c b/builtin-run.c
> index 1ee75ad..0a48663 100644
> --- a/builtin-run.c
> +++ b/builtin-run.c
> @@ -59,8 +59,8 @@ static int kvm_run_wrapper;
>
> bool do_debug_print = false;
>
> -extern char _binary_guest_init_start;
> -extern char _binary_guest_init_size;
> +extern char guest_init;
> +extern char guest_init_len;
>
> static const char * const run_usage[] = {
> "lkvm run [<options>] [<kernel image>]",
> @@ -354,8 +354,8 @@ static int kvm_setup_guest_init(struct kvm *kvm)
> char *data;
>
> /* Setup /virt/init */
> - size = (size_t)&_binary_guest_init_size;
> - data = (char *)&_binary_guest_init_start;
> + size = (size_t)&guest_init_len;
> + data = (char *)&guest_init;
> snprintf(tmp, PATH_MAX, "%s%s/virt/init", kvm__get_dir(), rootfs);
> remove(tmp);
> fd = open(tmp, O_CREAT | O_WRONLY, 0755);
> diff --git a/builtin-setup.c b/builtin-setup.c
> index 8b45c56..fd7ca54 100644
> --- a/builtin-setup.c
> +++ b/builtin-setup.c
> @@ -16,8 +16,8 @@
> #include <sys/mman.h>
> #include <fcntl.h>
>
> -extern char _binary_guest_init_start;
> -extern char _binary_guest_init_size;
> +extern char guest_init;
> +extern char guest_init_len;
>
> static const char *instance_name;
>
> @@ -131,8 +131,8 @@ static int copy_init(const char *guestfs_name)
> int fd, ret;
> char *data;
>
> - size = (size_t)&_binary_guest_init_size;
> - data = (char *)&_binary_guest_init_start;
> + size = (size_t)&guest_init;
> + data = (char *)&guest_init_len;
> snprintf(path, PATH_MAX, "%s%s/virt/init", kvm__get_dir(), guestfs_name);
> remove(path);
> fd = open(path, O_CREAT | O_WRONLY, 0755);
> --
> 2.3.5
>
prev parent reply other threads:[~2015-06-24 9:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-23 15:06 [RFC PATCH 0/2] kvmtool: Rework guest/init integration Andre Przywara
2015-06-23 15:06 ` [RFC PATCH 1/2] Makefile: cleanup guest/init generation Andre Przywara
2015-06-23 15:06 ` [RFC PATCH 2/2] Makefile: use xxd for converting guest/init Andre Przywara
2015-06-24 8:53 ` Andreas Herrmann [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150624085317.GA30052@alberich \
--to=andreas.herrmann@caviumnetworks.com \
--cc=andre.przywara@arm.com \
--cc=kvm@vger.kernel.org \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox