From patchwork Sun Jun 5 22:18:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teddy Reed X-Patchwork-Id: 630623 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3rNBzs6pxBz9t4P for ; Mon, 6 Jun 2016 08:18:16 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=et7hB0UL; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 623604BA3B; Mon, 6 Jun 2016 00:18:12 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1fZ-58SrTb3Y; Mon, 6 Jun 2016 00:18:12 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F24CD4B9B0; Mon, 6 Jun 2016 00:18:11 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A45264B9B0 for ; Mon, 6 Jun 2016 00:18:09 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oaGCi9mtpKLY for ; Mon, 6 Jun 2016 00:18:09 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f67.google.com (mail-pa0-f67.google.com [209.85.220.67]) by theia.denx.de (Postfix) with ESMTPS id 24F394B9AD for ; Mon, 6 Jun 2016 00:18:05 +0200 (CEST) Received: by mail-pa0-f67.google.com with SMTP id ug1so310719pab.1 for ; Sun, 05 Jun 2016 15:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=i/wx5yvOiFXsgH7ck55Bw6LnIph8VFw+uXjhHfs+rY8=; b=et7hB0ULr0dujENLHHNsOiru857PQQQvUhZPdw49n3buyORx7h2Y5tRpEYiHK2tzW0 o39RkNO/xjtQ98JWohhZC7sH9MckZ6qrsLsLo7K/vA72bzUooYjQeUI5m1wYwV/8f82R YdVvxlL7HBk6AMs8IiSAdaLD/H4Q/E+n5qt9ImjinKRe5dVIzOsgEWpTmq7alWx92g4R xhFMfBucqciae8ZbSXQIZpH8hbe/BG2Pi6VypKe5adNPcJIy786O48B7iAo+XSoFhobQ qmOGvSrI26+YNag8S2KgzsNzMLq02x1D6edxKfi7BQU/LPe5WraFj5lfS6Nb9wwyal8N qFtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=i/wx5yvOiFXsgH7ck55Bw6LnIph8VFw+uXjhHfs+rY8=; b=T16QnT9mDtzvuA+KK2tGxf/HORoMpeR+awgglKaMuTU+c9B9z69bwEz6tm4FAao0cA WcE759A+OFpjJOJXMFEeskpmee4veCgWh6bbMaeetYe907kH4+wseQ5/QBsGHCyA4MaT HEKi1cG7I/5UojH8p1ODlMVoD6es6gR32Jak3P8iLkLyaErE5v/V0UglHToQsDNRttpl HQa0bt3ZJ4V/Ttbn14zsUhC50fOqMhEqZtoshcBpsmSHu6Xnh3BXSuxMTdZACYYnDha4 sSMQd17adtIzyVYu6Do5JoajtdZqCFdouLkaVVcPD7Cvg44+HFb3/ptyfHI8cGxO6U99 pXPg== X-Gm-Message-State: ALyK8tLDGdeZ0E/F/f3N9I7aTw6H7Gq2g2yb+tL5eA5bwugLOqaD6W/Dvl2AJMgX9k4l5g== X-Received: by 10.66.170.168 with SMTP id an8mr20580973pac.47.1465165083941; Sun, 05 Jun 2016 15:18:03 -0700 (PDT) Received: from maverics (c-24-6-55-56.hsd1.ca.comcast.net. [24.6.55.56]) by smtp.gmail.com with ESMTPSA id d71sm22416024pfd.80.2016.06.05.15.18.02 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 05 Jun 2016 15:18:03 -0700 (PDT) Date: Sun, 5 Jun 2016 15:18:02 -0700 From: Teddy Reed To: u-boot@lists.denx.de Message-Id: <20160605151802.248f0184beb7f986629dab67@gmail.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Mime-Version: 1.0 Subject: [U-Boot] [PATCH v2] mkimage: fit: spl: Add an optional static offset for external data X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" When building a FIT with external data (-E), an SPL may require absolute positioning for executing the external firmware. To acheive this use the (-p) switch, which will replace the amended 'data-offset' with 'data-position' indicating the absolute position of external data. It is considered an error if the requested absolute position overlaps with the initial data required for the compact FIT. Cc: Simon Glass --- Changes in v2: - Add -p argument to mkimage.1 - Add -E, -p arguments to mkimage usage text - Add notes for static position within uImage.FIT docs - Rebased onto master doc/mkimage.1 | 6 ++++++ doc/uImage.FIT/source_file_format.txt | 4 ++++ tools/fit_image.c | 19 ++++++++++++++++++- tools/imagetool.h | 1 + tools/mkimage.c | 13 +++++++++++-- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/doc/mkimage.1 b/doc/mkimage.1 index 4b3a255..ffa7d60 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -152,6 +152,12 @@ verification. Typically the file here is the device tree binary used by CONFIG_OF_CONTROL in U-Boot. .TP +.BI "\-p [" "external position" "]" +Place external data at a static external position. See \-E. Instead of writing +a 'data-offset' property defining the offset from the end of the FIT, \-p will +use 'data-position' as the absolute position from the base of the FIT. + +.TP .BI "\-r Specifies that keys used to sign the FIT are required. This means that they must be verified for the image to boot. Without this option, the verification diff --git a/doc/uImage.FIT/source_file_format.txt b/doc/uImage.FIT/source_file_format.txt index 3f54180..ee72740 100644 --- a/doc/uImage.FIT/source_file_format.txt +++ b/doc/uImage.FIT/source_file_format.txt @@ -282,6 +282,10 @@ In this case the 'data' property is omitted. Instead you can use: aligned to a 4-byte boundary. - data-size : size of the data in bytes +The 'data-offset' property can be substituted with 'data-position', which +defines a static position or address from the base of the FIT as the offset. +A static position is helpful when booting U-Boot proper before performing +relocation. 9) Examples ----------- diff --git a/tools/fit_image.c b/tools/fit_image.c index 0551572..76a6de4 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -416,7 +416,13 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) ret = -EPERM; goto err_munmap; } - fdt_setprop_u32(fdt, node, "data-offset", buf_ptr); + if (params->external_offset > 0) { + /* An external offset positions the data absolutely. */ + fdt_setprop_u32(fdt, node, "data-position", + params->external_offset + buf_ptr); + } else { + fdt_setprop_u32(fdt, node, "data-offset", buf_ptr); + } fdt_setprop_u32(fdt, node, "data-size", len); buf_ptr += (len + 3) & ~3; @@ -437,6 +443,17 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) ret = -EIO; goto err; } + + /* Check if an offset for the external data was set. */ + if (params->external_offset > 0) { + if (params->external_offset < new_size) { + debug("External offset %x overlaps FIT length %x", + params->external_offset, new_size); + ret = -EINVAL; + goto err; + } + new_size = params->external_offset; + } if (lseek(fd, new_size, SEEK_SET) < 0) { debug("%s: Failed to seek to end of file: %s\n", __func__, strerror(errno)); diff --git a/tools/imagetool.h b/tools/imagetool.h index a3ed0f4..1f2161c 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -74,6 +74,7 @@ struct image_tool_params { struct content_info *content_tail; bool external_data; /* Store data outside the FIT */ bool quiet; /* Don't output text in normal operation */ + unsigned int external_offset; /* Add padding to external data */ }; /* diff --git a/tools/mkimage.c b/tools/mkimage.c index aefe22f..ff3024a 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -93,11 +93,13 @@ static void usage(const char *msg) " -f => input filename for FIT source\n"); #ifdef CONFIG_FIT_SIGNATURE fprintf(stderr, - "Signing / verified boot options: [-k keydir] [-K dtb] [ -c ] [-r]\n" + "Signing / verified boot options: [-E] [-k keydir] [-K dtb] [ -c ] [-p addr] [-r]\n" + " -E => place data outside of the FIT structure\n" " -k => set directory containing private keys\n" " -K => write public keys to this .dtb file\n" " -c => add comment in signature node\n" " -F => re-sign existing FIT image\n" + " -p => place external data at a static position\n" " -r => mark keys used as 'required' in dtb\n"); #else fprintf(stderr, @@ -136,7 +138,7 @@ static void process_args(int argc, char **argv) int opt; while ((opt = getopt(argc, argv, - "a:A:b:cC:d:D:e:Ef:Fk:K:ln:O:rR:qsT:vVx")) != -1) { + "a:A:b:cC:d:D:e:Ef:Fk:K:ln:p:O:rR:qsT:vVx")) != -1) { switch (opt) { case 'a': params.addr = strtoull(optarg, &ptr, 16); @@ -216,6 +218,13 @@ static void process_args(int argc, char **argv) if (params.os < 0) usage("Invalid operating system"); break; + case 'p': + params.external_offset = strtoull(optarg, &ptr, 16); + if (*ptr) { + fprintf(stderr, "%s: invalid offset size %s\n", + params.cmdname, optarg); + exit(EXIT_FAILURE); + } case 'q': params.quiet = 1; break;