All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Francis <alistair.francis@xilinx.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: alistair.francis@xilinx.com, crosthwaitepeter@gmail.com,
	armbru@redhat.com, cov@codeaurora.org, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v11 1/8] loader: Allow ELF loader to auto-detect the ELF arch
Date: Tue, 20 Sep 2016 07:54:09 -0700	[thread overview]
Message-ID: <f2d70b47fcad31445f947f8817a0e146d80a046b.1474331683.git.alistair.francis@xilinx.com> (raw)
In-Reply-To: <cover.1474331683.git.alistair.francis@xilinx.com>

If the caller didn't specify an architecture for the ELF machine
the load_elf() function will auto detect it based on the ELF file.

Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
V10:
 - Base checks on the EM_NONE macro
V9:
 - Update documentation
V8:
 - Move into load_elf64/load_elf32
V7:
 - Fix typo

 include/hw/elf_ops.h | 5 +++++
 include/hw/loader.h  | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index f510e7e..5038c7f 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -280,6 +280,11 @@ static int glue(load_elf, SZ)(const char *name, int fd,
         glue(bswap_ehdr, SZ)(&ehdr);
     }
 
+    if (elf_machine <= EM_NONE) {
+        /* The caller didn't specify an ARCH, we can figure it out */
+        elf_machine = ehdr.e_machine;
+    }
+
     switch (elf_machine) {
         case EM_PPC64:
             if (ehdr.e_machine != EM_PPC64) {
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 4879b63..c59673d 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -68,6 +68,8 @@ const char *load_elf_strerror(int error);
  * load will fail if the target ELF does not match. Some architectures
  * have some architecture-specific behaviours that come into effect when
  * their particular values for @elf_machine are set.
+ * If @elf_machine is EM_NONE then the machine type will be read from the
+ * ELF header and no checks will be carried out against the machine type.
  */
 
 int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
-- 
2.7.4

  reply	other threads:[~2016-09-20 15:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-20 14:54 [Qemu-devel] [PATCH v11 0/8] Add a generic loader Alistair Francis
2016-09-20 14:54 ` Alistair Francis [this message]
2016-09-20 14:54 ` [Qemu-devel] [PATCH v11 2/8] loader: Use the specified MemoryRegion Alistair Francis
2016-09-20 14:54 ` [Qemu-devel] [PATCH v11 3/8] loader: Allow a custom AddressSpace when loading ROMs Alistair Francis
2016-09-20 14:54 ` [Qemu-devel] [PATCH v11 4/8] loader: Add AddressSpace loading support to ELFs Alistair Francis
2016-09-20 14:54 ` [Qemu-devel] [PATCH v11 5/8] loader: Add AddressSpace loading support to uImages Alistair Francis
2016-09-20 14:54 ` [Qemu-devel] [PATCH v11 6/8] loader: Add AddressSpace loading support to targphys Alistair Francis
2016-09-20 14:54 ` [Qemu-devel] [PATCH v11 7/8] generic-loader: Add a generic loader Alistair Francis
2016-09-20 14:54 ` [Qemu-devel] [PATCH v11 8/8] docs: Add a generic loader explanation document Alistair Francis
2016-09-20 17:41 ` [Qemu-devel] [PATCH v11 0/8] Add a generic loader Peter Maydell
2016-09-20 18:22   ` Alistair Francis
2016-09-21  6:05 ` Markus Armbruster
2016-09-21 15:46   ` Alistair Francis
2016-09-21 15:53     ` Paolo Bonzini
2016-09-22  9:19       ` Markus Armbruster
2016-09-22  9:22         ` Paolo Bonzini
2016-09-22 11:50           ` Markus Armbruster
2016-09-22 14:01             ` Peter Maydell
2016-09-23  8:10               ` Markus Armbruster
2016-09-23  8:18                 ` Paolo Bonzini
2016-09-27 13:28                   ` Markus Armbruster
2016-09-27 14:14                     ` Paolo Bonzini
2016-09-27 15:40                       ` Markus Armbruster
2016-09-27 16:24                         ` Alistair Francis
2016-09-28  2:04                           ` Markus Armbruster
2016-09-28 22:48                             ` Alistair Francis
2016-09-27 15:17                     ` Peter Maydell
2016-09-21 15:54   ` Daniel P. Berrange

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=f2d70b47fcad31445f947f8817a0e146d80a046b.1474331683.git.alistair.francis@xilinx.com \
    --to=alistair.francis@xilinx.com \
    --cc=armbru@redhat.com \
    --cc=cov@codeaurora.org \
    --cc=crosthwaitepeter@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.