From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C63C6C07E9B for ; Mon, 19 Jul 2021 12:27:45 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 522A560FDC for ; Mon, 19 Jul 2021 12:27:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 522A560FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nic.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AE81482DDA; Mon, 19 Jul 2021 14:24:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="B7aGuRZv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1570482D50; Mon, 19 Jul 2021 14:22:43 +0200 (CEST) Received: from mail.nic.cz (lists.nic.cz [IPv6:2001:1488:800:400::400]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 60B7482C90 for ; Mon, 19 Jul 2021 14:22:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.behun@nic.cz Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:8747:7254:5571:3010]) by mail.nic.cz (Postfix) with ESMTPSA id 0068A13FD0A; Mon, 19 Jul 2021 14:22:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1626697346; bh=Pz7/63jS77FB3/OjYx/J0/HKCeXlmF7S9hT9Gad2VWw=; h=From:To:Date; b=B7aGuRZvobw4v4rbTiOkw7ZGHUFQJbUCa8sqn32Fu7BHdhuUjzhMg8y2lcsH7JHWw M0FLlhIWjCQHcfrDVDA25Xz2wHs/IHOWXD6aWCLiOhU9o9ajtMu85qbXNswBrDUSWn WJsafaNKXj1Q0Ae8HbWrkLzui9JVTN1SBaggcGTY= From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: u-boot@lists.denx.de, Chris Packham , Stefan Roese , Baruch Siach , Dirk Eibach , Chris Packham Cc: Dennis Gilmore , Mario Six , Jon Nettleton , =?UTF-8?q?Pali=20Roh=C3=A1r?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-mvebu v2 33/41] SPL: Add support for specifying offset between header and image Date: Mon, 19 Jul 2021 14:20:56 +0200 Message-Id: <20210719122104.29698-34-marek.behun@nic.cz> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719122104.29698-1-marek.behun@nic.cz> References: <20210719122104.29698-1-marek.behun@nic.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Pali Rohár Some image types (e.g. kwbimage v1) store the offset to SPL binary and offset to main U-Boot binary in their headers. To avoid reading SPL binary when loading main U-Boot, add support for specifying offset in struct spl_image_info, which defines the offset from the beginning of the header and the beginning of the executable data. Initial support is added only for SPI, MMC and SATA code. We can extend it later if needed. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- common/spl/spl_mmc.c | 16 +++++++++++++++- common/spl/spl_sata.c | 12 +++++++++++- common/spl/spl_spi.c | 2 +- include/spl.h | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index add2785b4e..5605f1820d 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -20,26 +20,40 @@ static int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc, ulong sector, struct image_header *header) { + u32 image_offset_sectors; u32 image_size_sectors; unsigned long count; + u32 image_offset; int ret; ret = spl_parse_image_header(spl_image, header); if (ret) return ret; + /* convert offset to sectors - round down */ + image_offset_sectors = spl_image->offset / mmc->read_bl_len; + /* calculate remaining offset */ + image_offset = spl_image->offset % mmc->read_bl_len; + /* convert size to sectors - round up */ image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) / mmc->read_bl_len; /* Read the header too to avoid extra memcpy */ - count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors, + count = blk_dread(mmc_get_blk_desc(mmc), + sector + image_offset_sectors, + image_size_sectors, (void *)(ulong)spl_image->load_addr); debug("read %x sectors to %lx\n", image_size_sectors, spl_image->load_addr); if (count != image_size_sectors) return -EIO; + if (image_offset) + memmove((void *)(ulong)spl_image->load_addr, + (void *)(ulong)spl_image->load_addr + image_offset, + spl_image->size); + return 0; } diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index e108af0576..535a9219ef 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -36,6 +36,8 @@ static int spl_sata_load_image_raw(struct spl_image_info *spl_image, struct image_header *header; unsigned long count; u32 image_size_sectors; + u32 image_offset_sectors; + u32 image_offset; int ret; header = spl_get_load_buffer(-sizeof(*header), stor_dev->blksz); @@ -48,11 +50,19 @@ static int spl_sata_load_image_raw(struct spl_image_info *spl_image, return ret; image_size_sectors = DIV_ROUND_UP(spl_image->size, stor_dev->blksz); - count = blk_dread(stor_dev, sector, image_size_sectors, + image_offset_sectors = spl_image->offset / stor_dev->blksz; + image_offset = spl_image->offset % stor_dev->blksz; + count = blk_dread(stor_dev, sector + image_offset_sectors, + image_size_sectors, (void *)spl_image->load_addr); if (count != image_size_sectors) return -EIO; + if (image_offset) + memmove((void *)spl_image->load_addr, + (void *)spl_image->load_addr + image_offset, + spl_image->size); + return 0; } diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index 6a4e033287..9884e7c185 100644 --- a/common/spl/spl_spi.c +++ b/common/spl/spl_spi.c @@ -159,7 +159,7 @@ static int spl_spi_load_image(struct spl_image_info *spl_image, err = spl_parse_image_header(spl_image, header); if (err) return err; - err = spi_flash_read(flash, payload_offs, + err = spi_flash_read(flash, payload_offs + spl_image->offset, spl_image->size, (void *)spl_image->load_addr); } diff --git a/include/spl.h b/include/spl.h index cee9a42ddb..3df923a813 100644 --- a/include/spl.h +++ b/include/spl.h @@ -198,6 +198,7 @@ struct spl_image_info { void *fdt_addr; #endif u32 boot_device; + u32 offset; u32 size; u32 flags; void *arg; -- 2.31.1