linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Clement Leger <cleger@kalray.eu>
Cc: Ohad Ben-Cohen <ohad@wizery.com>,
	Jonathan Corbet <corbet@lwn.net>, Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	linux-remoteproc@vger.kernel.org,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Andy Gross <agross@kernel.org>,
	Patrice Chotard <patrice.chotard@st.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org,
	Arnaud Pouliquen <arnaud.pouliquen@st.com>,
	Loic PALLARDY <loic.pallardy@st.com>, s-anna <s-anna@ti.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Subject: Re: [PATCH v5 4/8] remoteproc: Add elf helpers to access elf64 and elf32 fields
Date: Mon, 2 Mar 2020 15:12:36 -0800	[thread overview]
Message-ID: <20200302231236.GD262924@yoga> (raw)
In-Reply-To: <20200302093902.27849-5-cleger@kalray.eu>

On Mon 02 Mar 01:38 PST 2020, Clement Leger wrote:

> elf32 and elf64 mainly differ by their types. In order to avoid
> copy/pasting the whole loader code, generate static inline functions
> which will access values according to the elf class. It allows to
> keep a common loader basis.
> In order to accommodate both elf types sizes, the maximum size for a
> elf header member is chosen using the maximum value of the field for
> both elf class.
> 
> Signed-off-by: Clement Leger <cleger@kalray.eu>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---
>  drivers/remoteproc/remoteproc_elf_helpers.h | 96 +++++++++++++++++++++++++++++
>  1 file changed, 96 insertions(+)
>  create mode 100644 drivers/remoteproc/remoteproc_elf_helpers.h
> 
> diff --git a/drivers/remoteproc/remoteproc_elf_helpers.h b/drivers/remoteproc/remoteproc_elf_helpers.h
> new file mode 100644
> index 000000000000..4b6be7b6bf4d
> --- /dev/null
> +++ b/drivers/remoteproc/remoteproc_elf_helpers.h
> @@ -0,0 +1,96 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Remote processor elf helpers defines
> + *
> + * Copyright (C) 2020 Kalray, Inc.
> + */
> +
> +#ifndef REMOTEPROC_ELF_LOADER_H
> +#define REMOTEPROC_ELF_LOADER_H
> +
> +#include <linux/elf.h>
> +#include <linux/types.h>
> +
> +/**
> + * fw_elf_get_class - Get elf class
> + * @fw: the ELF firmware image
> + *
> + * Note that we use and elf32_hdr to access the class since the start of the
> + * struct is the same for both elf class
> + *
> + * Return: elf class of the firmware
> + */
> +static inline u8 fw_elf_get_class(const struct firmware *fw)
> +{
> +	struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;
> +
> +	return ehdr->e_ident[EI_CLASS];
> +}
> +
> +static inline void elf_hdr_init_ident(struct elf32_hdr *hdr, u8 class)
> +{
> +	memcpy(hdr->e_ident, ELFMAG, SELFMAG);
> +	hdr->e_ident[EI_CLASS] = class;
> +	hdr->e_ident[EI_DATA] = ELFDATA2LSB;
> +	hdr->e_ident[EI_VERSION] = EV_CURRENT;
> +	hdr->e_ident[EI_OSABI] = ELFOSABI_NONE;
> +}
> +
> +/* Generate getter and setter for a specific elf struct/field */
> +#define ELF_GEN_FIELD_GET_SET(__s, __field, __type) \
> +static inline __type elf_##__s##_get_##__field(u8 class, const void *arg) \
> +{ \
> +	if (class == ELFCLASS32) \
> +		return (__type) ((const struct elf32_##__s *) arg)->__field; \
> +	else \
> +		return (__type) ((const struct elf64_##__s *) arg)->__field; \
> +} \
> +static inline void elf_##__s##_set_##__field(u8 class, void *arg, \
> +					     __type value) \
> +{ \
> +	if (class == ELFCLASS32) \
> +		((struct elf32_##__s *) arg)->__field = (__type) value; \
> +	else \
> +		((struct elf64_##__s *) arg)->__field = (__type) value; \
> +}
> +
> +ELF_GEN_FIELD_GET_SET(hdr, e_entry, u64)
> +ELF_GEN_FIELD_GET_SET(hdr, e_phnum, u16)
> +ELF_GEN_FIELD_GET_SET(hdr, e_shnum, u16)
> +ELF_GEN_FIELD_GET_SET(hdr, e_phoff, u64)
> +ELF_GEN_FIELD_GET_SET(hdr, e_shoff, u64)
> +ELF_GEN_FIELD_GET_SET(hdr, e_shstrndx, u16)
> +ELF_GEN_FIELD_GET_SET(hdr, e_machine, u16)
> +ELF_GEN_FIELD_GET_SET(hdr, e_type, u16)
> +ELF_GEN_FIELD_GET_SET(hdr, e_version, u32)
> +ELF_GEN_FIELD_GET_SET(hdr, e_ehsize, u32)
> +ELF_GEN_FIELD_GET_SET(hdr, e_phentsize, u16)
> +
> +ELF_GEN_FIELD_GET_SET(phdr, p_paddr, u64)
> +ELF_GEN_FIELD_GET_SET(phdr, p_vaddr, u64)
> +ELF_GEN_FIELD_GET_SET(phdr, p_filesz, u64)
> +ELF_GEN_FIELD_GET_SET(phdr, p_memsz, u64)
> +ELF_GEN_FIELD_GET_SET(phdr, p_type, u32)
> +ELF_GEN_FIELD_GET_SET(phdr, p_offset, u64)
> +ELF_GEN_FIELD_GET_SET(phdr, p_flags, u32)
> +ELF_GEN_FIELD_GET_SET(phdr, p_align, u64)
> +
> +ELF_GEN_FIELD_GET_SET(shdr, sh_size, u64)
> +ELF_GEN_FIELD_GET_SET(shdr, sh_offset, u64)
> +ELF_GEN_FIELD_GET_SET(shdr, sh_name, u32)
> +ELF_GEN_FIELD_GET_SET(shdr, sh_addr, u64)
> +
> +#define ELF_STRUCT_SIZE(__s) \
> +static inline unsigned long elf_size_of_##__s(u8 class) \
> +{ \
> +	if (class == ELFCLASS32)\
> +		return sizeof(struct elf32_##__s); \
> +	else \
> +		return sizeof(struct elf64_##__s); \
> +}
> +
> +ELF_STRUCT_SIZE(shdr)
> +ELF_STRUCT_SIZE(phdr)
> +ELF_STRUCT_SIZE(hdr)
> +
> +#endif /* REMOTEPROC_ELF_LOADER_H */
> -- 
> 2.15.0.276.g89ea799
> 

  reply	other threads:[~2020-03-02 23:12 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200129163013.GA16538@xps15>
2020-02-04 14:33 ` [PATCH v2 1/2] remoteproc: Use u64 len for da_to_va Clement Leger
2020-02-04 14:33   ` [PATCH v2 2/2] remoteproc: Add elf64 support in elf loader Clement Leger
2020-02-04 16:27   ` [PATCH v2 1/2] remoteproc: Use u64 len for da_to_va Arnaud POULIQUEN
2020-02-04 17:10     ` Clément Leger
2020-02-04 17:42       ` Arnaud POULIQUEN
2020-02-04 17:44 ` [PATCH v3 0/2] remoteproc: Add elf64 support to elf loader Clement Leger
2020-02-04 17:44   ` [PATCH v3 1/2] remoteproc: Use u64 len for da_to_va Clement Leger
2020-02-05 21:06     ` Mathieu Poirier
2020-02-04 17:44   ` [PATCH v3 2/2] remoteproc: Add elf64 support in elf loader Clement Leger
2020-02-05 22:49     ` Mathieu Poirier
2020-02-06  8:37       ` Clément Leger
2020-02-06 15:05         ` Clément Leger
2020-02-06 17:48           ` Mathieu Poirier
2020-02-07  7:57             ` Clément Leger
2020-02-10 16:22               ` [PATCH v4 0/5] remoteproc: Add elf64 support Clement Leger
2020-02-10 16:22                 ` [PATCH v4 1/5] remoteproc: Use u64 len for da_to_va Clement Leger
2020-02-11 15:53                   ` Arnaud POULIQUEN
2020-02-11 16:39                     ` Clément Leger
2020-02-11 17:24                       ` Arnaud POULIQUEN
2020-02-11 22:37                       ` Mathieu Poirier
2020-02-12 10:37                         ` Clément Leger
2020-02-12 21:59                           ` Mathieu Poirier
2020-02-18 10:10                             ` Clément Leger
2020-02-18 17:01                               ` Mathieu Poirier
2020-02-10 16:22                 ` [PATCH v4 2/5] remoteproc: Use u64 type for boot_addr Clement Leger
2020-02-10 16:22                 ` [PATCH v4 3/5] remoteproc: Add elf helpers to access elf64 and elf32 fields Clement Leger
2020-02-10 16:22                 ` [PATCH v4 4/5] remoteproc: Add elf64 support in elf loader Clement Leger
2020-02-10 16:22                 ` [PATCH v4 5/5] remoteproc: Adapt coredump to generate correct elf type Clement Leger
2020-02-11 23:11                   ` Mathieu Poirier
2020-02-11 15:57                 ` [PATCH v4 0/5] remoteproc: Add elf64 support Arnaud POULIQUEN
2020-02-11 23:12                   ` Mathieu Poirier
2020-02-12  8:15                     ` Arnaud POULIQUEN
2020-03-02  9:38                 ` [PATCH v5 0/8] " Clement Leger
2020-03-02  9:38                   ` [PATCH v5 1/8] remoteproc: Use size_t type for len in da_to_va Clement Leger
2020-03-02 23:06                     ` Bjorn Andersson
2020-03-09 17:52                     ` Mathieu Poirier
2020-03-27  7:37                     ` Oleksij Rempel
2020-03-02  9:38                   ` [PATCH v5 2/8] remoteproc: Use size_t instead of int for rproc_mem_entry len Clement Leger
2020-03-02 23:07                     ` Bjorn Andersson
2020-03-09 19:21                     ` Mathieu Poirier
2020-03-02  9:38                   ` [PATCH v5 3/8] remoteproc: Use u64 type for boot_addr Clement Leger
2020-03-02 23:08                     ` Bjorn Andersson
2020-03-09 19:52                     ` Mathieu Poirier
2020-03-10  7:59                       ` Clément Leger
2020-03-10 19:32                         ` Bjorn Andersson
2020-03-02  9:38                   ` [PATCH v5 4/8] remoteproc: Add elf helpers to access elf64 and elf32 fields Clement Leger
2020-03-02 23:12                     ` Bjorn Andersson [this message]
2020-03-09 19:56                     ` Mathieu Poirier
2020-03-02  9:38                   ` [PATCH v5 5/8] remoteproc: Rename rproc_elf_sanity_check for elf32 Clement Leger
2020-03-02 23:13                     ` Bjorn Andersson
2020-03-03  8:02                       ` Clément Leger
2020-03-10  0:00                         ` Bjorn Andersson
2020-03-10 15:20                           ` Mathieu Poirier
2020-03-10 15:38                             ` Clément Leger
2020-03-10 19:18                               ` Mathieu Poirier
2020-03-10 19:30                               ` Bjorn Andersson
2020-03-02  9:39                   ` [PATCH v5 6/8] remoteproc: Add elf64 support in elf loader Clement Leger
2020-03-02  9:39                   ` [PATCH v5 7/8] remoteproc: Allow overriding only sanity_check Clement Leger
2020-03-02  9:39                   ` [PATCH v5 8/8] remoteproc: Adapt coredump to generate correct elf type Clement Leger
2020-03-03 22:01                     ` Bjorn Andersson
2020-03-09 20:32                     ` Mathieu Poirier
2020-03-09 23:57                       ` Bjorn Andersson
2020-03-10  8:12                         ` Clément Leger

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=20200302231236.GD262924@yoga \
    --to=bjorn.andersson@linaro.org \
    --cc=agross@kernel.org \
    --cc=arnaud.pouliquen@st.com \
    --cc=cleger@kalray.eu \
    --cc=corbet@lwn.net \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=loic.pallardy@st.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=ohad@wizery.com \
    --cc=patrice.chotard@st.com \
    --cc=s-anna@ti.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).