From patchwork Fri May 18 07:56:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keguang Zhang X-Patchwork-Id: 916180 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="T1UHardD"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40nPd210jNz9s2k for ; Fri, 18 May 2018 20:32:36 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 67473C21F95; Fri, 18 May 2018 10:32:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3114DC21EAE; Fri, 18 May 2018 10:32:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AE0F2C21DF8; Fri, 18 May 2018 07:58:02 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) by lists.denx.de (Postfix) with ESMTPS id 6B967C21E38 for ; Fri, 18 May 2018 07:57:58 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id ay10-v6so4130328plb.1 for ; Fri, 18 May 2018 00:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=bX1NZUKDak4Xh2OK+/5UtNe8sZRtJjTDxYUU3p6yL5U=; b=T1UHardDpbLUhow8WccVNACNwj+m6BTyCETbbdjRUqbxNO4ewYbAZcObApQvcaxqvt 7YT8lhZI1boQlQUCmNUcQXl7Qm+dog9uJr+yonQuxaAtBOHTTNc8WqbF7ijokTu0HFKy re9w75gq8xhUzjJ4CNxKq5osLfKnrMI6GgpBZ1d+AG2cq4qWv+eYHRYHWwIWVfXIZsHI QkLGkBrFU75p1Bt6hQQWr8DNx+bTkpElI9+uJRwYZrVcuFSWGCjC9HUeFxRGvL17883X rIANKSyBjHGOn4dcFnaTgGilQMcpFENgpf7zPDu4K8UBt9/D62xugddptRODlc/oVSlF 5M/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bX1NZUKDak4Xh2OK+/5UtNe8sZRtJjTDxYUU3p6yL5U=; b=BdGbUVaaG8MsP6B+bgeo7PWzoUVMIWslFh6yZm3jsMHRSFxI68cuX6G2hmzYpi/ORV VgE9fjfJHOY1IV9jSVAkeyd1z7pf6bEoOa8bvHg18F157sI26RViNRfYgIght82YcULj iBgFwxIKDSoWqfPqX+91tNlyAqD5JpIR4oRVHtfu3u2epXyGSroCAJSwkjcWm5LWmiou zDRuphwRx2mn9N27fpOpXyXq/+yspqL5/KmRIiWVl71oz8rHzuqPiXn7HnCah1b9z6S+ jC+iOlSAqNluu8QogsMJlLLqNK85vKLp57XAnonYFnQUtzBeg/HMZEdjgUr85qRb858t WJ3Q== X-Gm-Message-State: ALKqPwf0IHdxfnqLJapqvpp0ZjCRfzhDGLNxWPxlIBOx1mqjGLzm3466 CzH07nEYgF135wkXYj56HvRgfIcgB8w= X-Google-Smtp-Source: AB8JxZo9gD0aQID1zXIYbVpA2wh4ygp0seccvxeE7jWRuVtWmikFBOeDt/yPeMWZPsoR5DhhS3EVUQ== X-Received: by 2002:a17:902:20e5:: with SMTP id v34-v6mr8502963plg.127.1526630276655; Fri, 18 May 2018 00:57:56 -0700 (PDT) Received: from localhost.localdomain ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id a5-v6sm16453139pff.8.2018.05.18.00.57.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 May 2018 00:57:56 -0700 (PDT) From: Kelvin Cheung To: u-boot@lists.denx.de Date: Fri, 18 May 2018 15:56:22 +0800 Message-Id: <1526630192-11723-1-git-send-email-keguang.zhang@gmail.com> X-Mailer: git-send-email 1.9.1 X-Mailman-Approved-At: Fri, 18 May 2018 10:32:26 +0000 Cc: Andre Przywara , Pantelis Antoniou , Michal Simek , Kelvin Cheung , Franklin Subject: [U-Boot] [PATCH v2] add FIT data-position & data-offset property support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add FIT data-position & data-offset property support for bootm, which were already supported in SPL. Signed-off-by: Kelvin Cheung Reviewed-by: Simon Glass --- Changes for v2: create fit_image_get_data_and_size() to remove duplicated code --- common/image-fit.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- include/image.h | 2 ++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 5b93dce..bc22d8f 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -391,7 +391,7 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) fit_image_get_comp(fit, image_noffset, &comp); printf("%s Compression: %s\n", p, genimg_get_comp_name(comp)); - ret = fit_image_get_data(fit, image_noffset, &data, &size); + ret = fit_image_get_data_and_size(fit, image_noffset, &data, &size); #ifndef USE_HOSTCC printf("%s Data Start: ", p); @@ -856,6 +856,54 @@ int fit_image_get_data_size(const void *fit, int noffset, int *data_size) } /** + * fit_image_get_data - get data and its size including + * both embedded and external data + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @data: double pointer to void, will hold data property's data address + * @size: pointer to size_t, will hold data property's data size + * + * fit_image_get_data() finds data and its size including + * both embedded and external data. If the property is found + * its data start address and size are returned to the caller. + * + * returns: + * 0, on success + * otherwise, on failure + */ +int fit_image_get_data_and_size(const void *fit, int noffset, + const void **data, size_t *size) +{ + bool external_data = false; + int offset; + int len; + int ret; + + if (!fit_image_get_data_position(fit, noffset, &offset)) { + external_data = true; + } else if (!fit_image_get_data_offset(fit, noffset, &offset)) { + external_data = true; + /* + * For FIT with external data, figure out where + * the external images start. This is the base + * for the data-offset properties in each image. + */ + offset += ((fdt_totalsize(fit) + 3) & ~3); + } + + if (external_data) { + debug("External Data\n"); + ret = fit_image_get_data_size(fit, noffset, &len); + *data = fit + offset; + *size = len; + } else { + ret = fit_image_get_data(fit, noffset, data, size); + } + + return ret; +} + +/** * fit_image_hash_get_algo - get hash algorithm name * @fit: pointer to the FIT format image header * @noffset: hash node offset @@ -1153,7 +1201,7 @@ int fit_image_verify(const void *fit, int image_noffset) char *err_msg = ""; /* Get image data and data length */ - if (fit_image_get_data(fit, image_noffset, &data, &size)) { + if (fit_image_get_data_and_size(fit, image_noffset, &data, &size)) { err_msg = "Can't get image data/size"; printf("error!\n%s for '%s' hash node in '%s' image node\n", err_msg, fit_get_name(fit, noffset, NULL), @@ -1875,7 +1923,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr, bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL_OK); /* get image data address and length */ - if (fit_image_get_data(fit, noffset, &buf, &size)) { + if (fit_image_get_data_and_size(fit, noffset, &buf, &size)) { printf("Could not find %s subimage data!\n", prop_name); bootstage_error(bootstage_id + BOOTSTAGE_SUB_GET_DATA); return -ENOENT; diff --git a/include/image.h b/include/image.h index df701e3..1aed910 100644 --- a/include/image.h +++ b/include/image.h @@ -987,6 +987,8 @@ int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset); int fit_image_get_data_position(const void *fit, int noffset, int *data_position); int fit_image_get_data_size(const void *fit, int noffset, int *data_size); +int fit_image_get_data_and_size(const void *fit, int noffset, + const void **data, size_t *size); int fit_image_hash_get_algo(const void *fit, int noffset, char **algo); int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,