From patchwork Fri Jun 10 02:38: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: 633484 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 3rQmZ001dPz9sR8 for ; Fri, 10 Jun 2016 12:38: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=oq68Y8/J; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B8466A7651; Fri, 10 Jun 2016 04:38:13 +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 umAOlN1Q9pUd; Fri, 10 Jun 2016 04:38:13 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 58AC1A762F; Fri, 10 Jun 2016 04:38:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9816FA762F for ; Fri, 10 Jun 2016 04:38:10 +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 JVB_FJfis67M for ; Fri, 10 Jun 2016 04:38:10 +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-f68.google.com (mail-pa0-f68.google.com [209.85.220.68]) by theia.denx.de (Postfix) with ESMTPS id 07CA4A7541 for ; Fri, 10 Jun 2016 04:38:05 +0200 (CEST) Received: by mail-pa0-f68.google.com with SMTP id di3so3982695pab.0 for ; Thu, 09 Jun 2016 19:38: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=JZGm2+tTMaiEP23RLqm75WyezFQSdzBlIYGLbmt5DPc=; b=oq68Y8/JIzi7y6nRM0ON9mDxnmdcAc7bsCS3JWFaI2xQIuC7ejgAmHngWlcragDeM6 BHpn27IFiqdzHOv1i45rvSPtKllq1w3DMMMXnebOTxxwvD0ooUEFFKfNyF0ni0cK5XI+ Bf+SD9IZQBWnTLWZME4p+BGQO4m6172PAXLqiEVNcHYTAnB4vhu4/sriNmJJOdnauMfn qHBm41Wt35kYs7W5gAKQvPKqqSrJxHmAO+arRj0JcyntkRivW2QHJl2A0q4WAYCpLq7P FTO1bY8BESxv/BwNbe5t2ts3sYGp968kUva/uiXY9JpJnOc9dmAKvrlw7xh9+0BLuL1b bgeg== 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=JZGm2+tTMaiEP23RLqm75WyezFQSdzBlIYGLbmt5DPc=; b=lNp6datvIGIH0Xxpt7+0hy0SysdTQb2jEnH/bGqyS2RxZRKBuWUVHoaN5tPPKJAQPP +vpCerdXL6uqF3tm5DBi+KB1kcq1gL2kbD+1m8eDq8fvFykU+VHSBV43py7yp5r+DFJB 7wQ6xheA9C5LzrRh7sTUyqygU298Oo94FbPksi/4krh/18Ws7Y479QvYhOllWBVSX17b NxVVY9eevsRfW9I7pj0y2lMwb/9Mob8Sq0ug4bJmXrukqRy+RlQDR+lgXSTzMOp6RAql TFrAt0+Voc6qHG7C04Dz7wJaO4el6026CeNZ1QNpD7EGnrGO8HC4bFAlujku9rP69nLH b3JQ== X-Gm-Message-State: ALyK8tJzwxuwxvYeGuIidLPEPro9HPyxSxXKEMbn4qBUwIiT2e9Z6BqCBYIm++MaDd2B3w== X-Received: by 10.66.251.2 with SMTP id zg2mr16041735pac.32.1465526283564; Thu, 09 Jun 2016 19:38: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 o22sm7364574pfa.15.2016.06.09.19.38.02 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 09 Jun 2016 19:38:03 -0700 (PDT) Date: Thu, 9 Jun 2016 19:38:02 -0700 From: Teddy Reed To: u-boot@lists.denx.de Message-Id: <20160609193802.5f71f2cf6819f66bcbfb29db@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 v3] 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), U-Boot proper 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. Signed-off-by: Teddy Reed --- Changes in v3: - Improved documentation 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 | 3 +++ tools/fit_image.c | 19 ++++++++++++++++++- tools/imagetool.h | 1 + tools/mkimage.c | 13 +++++++++++-- 5 files changed, 39 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..91aa89a 100644 --- a/doc/uImage.FIT/source_file_format.txt +++ b/doc/uImage.FIT/source_file_format.txt @@ -282,6 +282,9 @@ 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 an absolute position or address as the offset. This 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;