Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3843483ybf; Tue, 3 Mar 2020 14:03:00 -0800 (PST) X-Google-Smtp-Source: ADFU+vunkKZ8AS7LMUDsy8PuRokqtPE4v7rgKSfHrMtcMun8PrCM7+4nhSUh0rTlP0PVe+6lLref X-Received: by 2002:a54:4396:: with SMTP id u22mr488645oiv.128.1583272980417; Tue, 03 Mar 2020 14:03:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583272980; cv=none; d=google.com; s=arc-20160816; b=qb/EW+wsCW+caY8lTwuJzW8GmqMOAcmlXsOnTSwulScyit43jwjCOGJNSsRxKOuJE5 g9dzORoWbxxHYsh4TCiWTXcK2a6lmFouSIDRvebCPzjI9RcW0Wq3xmSZGu2sDeCM6Bs1 QpxrNpUTFxCqXuhmUuaGRDvsav2Iqf4yeNKfyd9a/6K5ZRitb5ZHrOWCzcHCDAubRVTY P1WMnxmBDyyNeqWNdFVZOQ8apV8G7h/tbUCb/9CXECjhsT//88viDNol4PODAzeldQuZ dEXs/PK4/9xGp8hnVfGS9ocaX4Rv3lhyQDGEvFoiq2HiMAk+LheHpoqdGp+t/Y29bogU QWxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rWUW/hFw9l9361bhE4imeaEyL7jHn9L6GXzM5ESAseU=; b=vcDFmZi5hgDuW8s2xrs20pM/cg+mWGvcW1MydWiXo1kAxIycDtG5PfBca4WrQlt06x /5+dfaauTnYt4WzNR4a441njU9RIAi7PWz06YIDeY56nDvAcuI81I2UWr/D/wd4ivYRd O657uilA/v95bGOv0UlSBSIIFWBh6pBj4d6+1JnSAxB0551pjn8dmDqTV4YHPJiXVJ3v KvOaAf/BK3h1XogdZ74N8ewWN0oUYAAflEUgOPpgWJVpLVF8Fe1F5W0/PXteXJuRMs4z 0sYp/aBJYfjMT4vpk6g9GlGs7naCRPmY9nJShmZH0vwkNKKy9o/WYm8pY6Oe3B3Kj+U9 HrPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="BhVxK+/L"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si6203498ota.39.2020.03.03.14.02.47; Tue, 03 Mar 2020 14:03:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="BhVxK+/L"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727304AbgCCWBt (ORCPT + 99 others); Tue, 3 Mar 2020 17:01:49 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:46754 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727112AbgCCWBs (ORCPT ); Tue, 3 Mar 2020 17:01:48 -0500 Received: by mail-pf1-f195.google.com with SMTP id o24so2166110pfp.13 for ; Tue, 03 Mar 2020 14:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=rWUW/hFw9l9361bhE4imeaEyL7jHn9L6GXzM5ESAseU=; b=BhVxK+/LHYafxOQAfuMTX9d/TRms7HTjQhUgidQSpDOh3ucN0yhwgG0GsR08VaGqe0 p1rUfVpFAaPgmoZck/OAGk2CoNPI1Y3b+68nSVd5nPpHFc/O55nkwEB9c9/gEjh7S5qs nBGJ/2dqPhhvdC3KJfeWbrkVaGXje+y9JxV/bVIoy6u9P88L181uPzNtb45O2Al29D/W ukEjGV9OazJXP9shM9rlBFZZ7Hz8U7deISs7AzcO/Pp0mst4G0D88hbAuWUmSU94hP/t puyyPjM6DLwJMJW9HG1C6KF5RditipoQDM1oz6sPzZKFzEo5w23TwVwIdGbecoujEfua Y8DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=rWUW/hFw9l9361bhE4imeaEyL7jHn9L6GXzM5ESAseU=; b=XNyzTXDS2jAOVPDub0p8uZcVhg/EeMlHxJ9JhbIsHo+4fNJYbQW1BISDlO/7ER6djI GB3VKZBhXD4Zyop1BN52/99QY+SfhV3bcSP0cgCXsEOKD4sqt5aN9mNr12DNXECO4IA+ xzry3kx4eJ0Q+xCOqYKMdMgRPJR27eYHfB+qk6U75F6fXkvQ36+bmuh0Q4zc+LvT1/En 38OcTHbYyTfhbutx3rkVp4zVWgXkaeVEzB6gNLWLgRzpAyxd2K7IquKhAoTbk84BOaaF 4lP04J+WpmBf6rkwIyd3Alc++Zox24k6GICaH/Q5wWcW7IpOrNPloaC8B+KEcq00QfJ9 ODiA== X-Gm-Message-State: ANhLgQ3C9wtBn21x1jav9/KTomhVWJsi9j7IUCnf5pMEhx2sRclPYUam 2+ttiieOdBxrN63V0oTYoqQEbg== X-Received: by 2002:a63:e803:: with SMTP id s3mr5803839pgh.237.1583272906003; Tue, 03 Mar 2020 14:01:46 -0800 (PST) Received: from minitux (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id x12sm16305062pfi.122.2020.03.03.14.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 14:01:45 -0800 (PST) Date: Tue, 3 Mar 2020 14:01:42 -0800 From: Bjorn Andersson To: Clement Leger Cc: Ohad Ben-Cohen , Jonathan Corbet , Shawn Guo , Sascha Hauer , linux-remoteproc@vger.kernel.org, Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Andy Gross , Patrice Chotard , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Arnaud Pouliquen , Loic PALLARDY , s-anna , Mathieu Poirier Subject: Re: [PATCH v5 8/8] remoteproc: Adapt coredump to generate correct elf type Message-ID: <20200303220142.GU1214176@minitux> References: <20200210162209.23149-1-cleger@kalray.eu> <20200302093902.27849-1-cleger@kalray.eu> <20200302093902.27849-9-cleger@kalray.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200302093902.27849-9-cleger@kalray.eu> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 02 Mar 01:39 PST 2020, Clement Leger wrote: > Now that remoteproc can load an elf64, coredump elf class should be > the same as the loaded elf class. In order to do that, add a > elf_class field to rproc with default values. If an elf is loaded > successfully, this field will be updated with the loaded elf class. > Then, the coredump core code has been modified to use the generic elf > macro in order to create an elf file with correct class. > > Signed-off-by: Clement Leger Reviewed-by: Bjorn Andersson > --- > drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++-------------- > drivers/remoteproc/remoteproc_elf_loader.c | 3 ++ > include/linux/remoteproc.h | 1 + > 3 files changed, 39 insertions(+), 32 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index b932a64a2be2..f923355aa3f9 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -38,6 +38,7 @@ > #include > > #include "remoteproc_internal.h" > +#include "remoteproc_elf_helpers.h" > > #define HIGH_BITS_MASK 0xFFFFFFFF00000000ULL > > @@ -1566,20 +1567,21 @@ EXPORT_SYMBOL(rproc_coredump_add_custom_segment); > static void rproc_coredump(struct rproc *rproc) > { > struct rproc_dump_segment *segment; > - struct elf32_phdr *phdr; > - struct elf32_hdr *ehdr; > + void *phdr; > + void *ehdr; > size_t data_size; > size_t offset; > void *data; > void *ptr; > + u8 class = rproc->elf_class; > int phnum = 0; > > if (list_empty(&rproc->dump_segments)) > return; > > - data_size = sizeof(*ehdr); > + data_size = elf_size_of_hdr(class); > list_for_each_entry(segment, &rproc->dump_segments, node) { > - data_size += sizeof(*phdr) + segment->size; > + data_size += elf_size_of_phdr(class) + segment->size; > > phnum++; > } > @@ -1590,33 +1592,33 @@ static void rproc_coredump(struct rproc *rproc) > > ehdr = data; > > - memset(ehdr, 0, sizeof(*ehdr)); > - memcpy(ehdr->e_ident, ELFMAG, SELFMAG); > - ehdr->e_ident[EI_CLASS] = ELFCLASS32; > - ehdr->e_ident[EI_DATA] = ELFDATA2LSB; > - ehdr->e_ident[EI_VERSION] = EV_CURRENT; > - ehdr->e_ident[EI_OSABI] = ELFOSABI_NONE; > - ehdr->e_type = ET_CORE; > - ehdr->e_machine = EM_NONE; > - ehdr->e_version = EV_CURRENT; > - ehdr->e_entry = rproc->bootaddr; > - ehdr->e_phoff = sizeof(*ehdr); > - ehdr->e_ehsize = sizeof(*ehdr); > - ehdr->e_phentsize = sizeof(*phdr); > - ehdr->e_phnum = phnum; > - > - phdr = data + ehdr->e_phoff; > - offset = ehdr->e_phoff + sizeof(*phdr) * ehdr->e_phnum; > + memset(ehdr, 0, elf_size_of_hdr(class)); > + /* e_ident field is common for both elf32 and elf64 */ > + elf_hdr_init_ident(ehdr, class); > + > + elf_hdr_set_e_type(class, ehdr, ET_CORE); > + elf_hdr_set_e_machine(class, ehdr, EM_NONE); > + elf_hdr_set_e_version(class, ehdr, EV_CURRENT); > + elf_hdr_set_e_entry(class, ehdr, rproc->bootaddr); > + elf_hdr_set_e_phoff(class, ehdr, elf_size_of_hdr(class)); > + elf_hdr_set_e_ehsize(class, ehdr, elf_size_of_hdr(class)); > + elf_hdr_set_e_phentsize(class, ehdr, elf_size_of_phdr(class)); > + elf_hdr_set_e_phnum(class, ehdr, phnum); > + > + phdr = data + elf_hdr_get_e_phoff(class, ehdr); > + offset = elf_hdr_get_e_phoff(class, ehdr); > + offset += elf_size_of_phdr(class) * elf_hdr_get_e_phnum(class, ehdr); > + > list_for_each_entry(segment, &rproc->dump_segments, node) { > - memset(phdr, 0, sizeof(*phdr)); > - phdr->p_type = PT_LOAD; > - phdr->p_offset = offset; > - phdr->p_vaddr = segment->da; > - phdr->p_paddr = segment->da; > - phdr->p_filesz = segment->size; > - phdr->p_memsz = segment->size; > - phdr->p_flags = PF_R | PF_W | PF_X; > - phdr->p_align = 0; > + memset(phdr, 0, elf_size_of_phdr(class)); > + elf_phdr_set_p_type(class, phdr, PT_LOAD); > + elf_phdr_set_p_offset(class, phdr, offset); > + elf_phdr_set_p_vaddr(class, phdr, segment->da); > + elf_phdr_set_p_paddr(class, phdr, segment->da); > + elf_phdr_set_p_filesz(class, phdr, segment->size); > + elf_phdr_set_p_memsz(class, phdr, segment->size); > + elf_phdr_set_p_flags(class, phdr, PF_R | PF_W | PF_X); > + elf_phdr_set_p_align(class, phdr, 0); > > if (segment->dump) { > segment->dump(rproc, segment, data + offset); > @@ -1632,8 +1634,8 @@ static void rproc_coredump(struct rproc *rproc) > } > } > > - offset += phdr->p_filesz; > - phdr++; > + offset += elf_phdr_get_p_filesz(class, phdr); > + phdr += elf_size_of_phdr(class); > } > > dev_coredumpv(&rproc->dev, data, data_size, GFP_KERNEL); > @@ -2031,6 +2033,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, > rproc->name = name; > rproc->priv = &rproc[1]; > rproc->auto_boot = true; > + rproc->elf_class = ELFCLASS32; > > device_initialize(&rproc->dev); > rproc->dev.parent = dev; > diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c > index 4869fb7d8fe4..16e2c496fd45 100644 > --- a/drivers/remoteproc/remoteproc_elf_loader.c > +++ b/drivers/remoteproc/remoteproc_elf_loader.c > @@ -248,6 +248,9 @@ int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw) > memset(ptr + filesz, 0, memsz - filesz); > } > > + if (ret == 0) > + rproc->elf_class = class; > + > return ret; > } > EXPORT_SYMBOL(rproc_elf_load_segments); > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h > index 1683d6c386a6..ed127b2d35ca 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -514,6 +514,7 @@ struct rproc { > bool auto_boot; > struct list_head dump_segments; > int nb_vdev; > + u8 elf_class; > }; > > /** > -- > 2.15.0.276.g89ea799 >