From patchwork Fri Apr 22 17:38:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1621051 X-Patchwork-Delegate: van.freenix@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.a=rsa-sha256 header.s=selector1 header.b=y9wJT4D4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KlM9m3t8Jz9s0w for ; Sat, 23 Apr 2022 03:39:56 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 90DBC83942; Fri, 22 Apr 2022 19:39:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="y9wJT4D4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E2C5383DE2; Fri, 22 Apr 2022 19:38:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20602.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::602]) (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 5B1CD83DB7 for ; Fri, 22 Apr 2022 19:38:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dtO1KwgV/oskMFkWsuqW2v7m9mh66c1W2acs+jjvBLNeyOYiSQ1PeYlA2YBjGqViGmX2ZLaXPzw4r7NSxTgb4YQyUgwDMc3fs6KADJGYI8lrINJNlAzQjW5z/hhGKSleegFP6AxpUhwVpX/7va+jg44/sy9Z/hGVzzz0iiW8J3Morss0POAbCqfQfly39Clc3ZR26hAnYGaoSGG9Ip8rAdglGf3DCjx6LtOEygyvpb+Ta33Pt/qrQUs+KqNvM8QUougfmBpSd93xAz2dQi5KeZ3qOKXiVXXQuLMS4OwcKLWl3zvJolfxl7CTuwQzzJBcLnOL/nElzKn53Ve+XOQ1gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Kq6fL4JIjDXK+aSqCytf8RWna+nvnJ1uQg0mGiV67IY=; b=IZarmw9QvdyqX9mw27O2dS7LPF0d40W6q7OFiMkwuz2V5Cl1YMGbzHluI+sPCkv8tl9g1+FVoLca6zv23ta3CumIaTQYebotAkhj2a5CG2+w5lro86wVCD5ldDBbyLl3vrht20Dfp9sHX6GZm/HaKmb3Flde0W5PIyHEgSjydfkqqwbSDCebravAIV+iJpFp7ayKIK28qnxhEM3G1/7OrOBskSBIJDWVZ7x5BzdZVrNE2KxpUQT8CZcK1G779dzviIS0Rt8cQQcU5/Fomq6yFwYQuxWMs00AQwIa1VndEGMBFWqLRd7X5z2x4m6ne1xPdkjiBZOe0cKrs+kxz3fAwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Kq6fL4JIjDXK+aSqCytf8RWna+nvnJ1uQg0mGiV67IY=; b=y9wJT4D46Bzeln52BE0PJPpo7JtiJf6jucmenaPQhhrew3E1kPkrDDfnFgQn6W9yqETB3Kfe7IlVX99cBc/JBR3S066EL4OxQN1cy7su8wMMSJBjOTiA//3tJtqvFe2LrcbI1QrxTSWoDlIox+TF7UWt0lsio3/hb9GfahfR7dxNqi/vzRIqesMWFTxsBmtWQfy6M9BBd6J0CwOpUg4oEOF9GkrJxCnbORBRGCX/XQwr+GsPXQ3yWtQ+8ZSiEc3FWGzEBG3C5VhSMuKpcHawT51qCsnf63Dk1+oBSkX9UIurxBEOM3SU+rLWQrDSuB1+XEB/TDowVq45CLDMGJItcg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by PAXPR03MB7806.eurprd03.prod.outlook.com (2603:10a6:102:201::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Fri, 22 Apr 2022 17:38:54 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::714d:2b6:a995:51bd]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::714d:2b6:a995:51bd%4]) with mapi id 15.20.5186.015; Fri, 22 Apr 2022 17:38:54 +0000 From: Sean Anderson To: Joe Hershberger , Ramon Fried , u-boot@lists.denx.de Cc: Simon Glass , Priyanka Jain , York Sun , Sean Anderson , Alexandru Gagniuc , Heinrich Schuchardt Subject: [PATCH v2 2/6] image: fit: Add some helpers for getting data Date: Fri, 22 Apr 2022 13:38:36 -0400 Message-Id: <20220422173840.2260582-3-sean.anderson@seco.com> X-Mailer: git-send-email 2.35.1.1320.gc452695387.dirty In-Reply-To: <20220422173840.2260582-1-sean.anderson@seco.com> References: <20220422173840.2260582-1-sean.anderson@seco.com> X-ClientProxiedBy: MN2PR18CA0009.namprd18.prod.outlook.com (2603:10b6:208:23c::14) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 192a4225-b97a-4394-926e-08da2486f893 X-MS-TrafficTypeDiagnostic: PAXPR03MB7806:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xljhuifiCoUrLnW+jXz+It599J6MuNU42uXN4AMah81o0Mclveq+f4ClVGCUFDJqQo4KZut9Eci4OJnslXSVtt254O5nYfCg4qS3EUWw/IKzCz/1SHsQ3HmZXWjGJ4Del41H8ktMjJxcNxvW5wzB60nG28Wn2TBzTWE7/3+DbHTe4Mfox441QsQ92w8EfnzPEZzUWz5/M8TxbKKWYQPKIX7rn5izRi4Tmnqj5nkfz4wPyyT/4SfsOdo3ODwLBjb2eZBO0BjUTmcTuwYDH5F4V61bfRpPkd+H1r0U7l+H1HRyN8GDUHPi5nbcUZdMAjXaGzJAb+EaoiLiSA07BW8HbgaVyyvUaFeMbQ94xRMHUY74iXbNIHHJaic4otjtiQYq67iRrTAPsd0797HTwgmsN2r9LdZZqutXg4mT6YL/uupmGX1ycyusZoTES4+dxmBx/lYdbZgSMY3gpxkPh0qg6aRa+9UbRjmx+B0kkh6rLU37atqoeN8v36ux7ETboZsEx/Ay+5Wom/UxhkUWPnJLpVOrXG5Pu6cOgA9beRcQQsxL/qIotUlSGVpqiunPBDPByyVHycdb4F9Q8OKWsIzQK2i16y3grtR7/IkQUvrhD9FW8plBgcCA/46iuPmKHYiiZPVQqt0sJm3C9/r33vz0hT3RcTpLf2iub3CERhAUcfPvO9l5mOnXN9/MfRJE41slfNrLdlSyYMvd8W3+offlcw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(83380400001)(6486002)(5660300002)(38350700002)(52116002)(2906002)(86362001)(6666004)(26005)(6512007)(8936002)(6506007)(508600001)(186003)(1076003)(66946007)(66476007)(8676002)(66556008)(4326008)(2616005)(38100700002)(110136005)(44832011)(54906003)(316002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2kccP4BqXvJzJIhtfz6HmJy/AMQ7pananYayy7cZLcvnpH3NtW7/ypzA1iF44PzW+7HmHdfgAxPBanAzmq6VHHcE4KEWC5ruEd5bUInd5t+Ws/KcBFIgc8MK+MazUCno7sWzcqTERMpceDjF9t/PktbImMSx7OCM5cm3f/QzY7WFP0hJRphgyvnMY00skfRtNjkG8Hai0c2tXATzgTlRj/p108Nz3U+4aauHnr1y9Mc+wMY+RIqpKDP061LONZOSpzzqs2Bb3lJKOeZMhnuFxZ6ePe4pZr15ht7s9fOCrZqUcoAX5f8o3AmOMxTC/QKFJ80W4m5VtUBVl2y2BXku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heaSMRhxSfzL/LF3B7bhCu1VDwjzotNnlccoNmu1Z/ArQf9OV1+kd6+/O1vmhXhjTPjxmb+yyUgArGK4ikgkux92+n2N3kOjHK9StZno2elajXQTK/IykKXcdY6FLoFts+HA7Fk4j9XJJnGVwaloAl67L2L93aLohs89XkCaZZVmHMm8XJ9E3l/IwFkV7diNk1Ck/Y3QW8bsYO9VU9uGipaFV8yi9CBmushQ+JgTS5yOL7plnzzQtLWFBbEWmUv9e04y4aMtNa9DbfTDu+TpeOfyO2jNCfOLmQWhZjBKv3cy8Q205+Y2yKmnGQc0Z60tQftCACc0s4fwUdIgeGLgL5wCUoahslvwQ168q5o= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 192a4225-b97a-4394-926e-08da2486f893 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 17:38:54.2078 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +hsLMj7st56AiN4s9AsTCA6qkld6yoQIzeE/OZbThjFZdYE/P8EdVir/ttvGyvITxiyuvUsFTQqmw9/CjHFKcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR03MB7806 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean Several different firmware users have repetitive code to extract the firmware data from a FIT. Add some helper functions to reduce the amount of repetition. fit_conf_get_prop_node (eventually) calls fdt_check_node_offset_, so we can avoid an explicit if. In general, this version avoids printing on error because the callers are typically library functions, and because the FIT code generally has (debug) prints of its own. One difference in these helpers is that they use fit_image_get_data_and_size instead of fit_image_get_data, as the former handles external data correctly. Signed-off-by: Sean Anderson --- Changes in v2: - Document helpers boot/image-fit.c | 37 +++++++++++++++++++++++++ include/image.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/boot/image-fit.c b/boot/image-fit.c index 6610035d0a..b87378cbf6 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -1919,6 +1919,43 @@ int fit_conf_get_prop_node(const void *fit, int noffset, return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0); } +static int fit_get_data_tail(const void *fit, int noffset, + const void **data, size_t *size) +{ + char *desc; + + if (noffset < 0) + return noffset; + + if (!fit_image_verify(fit, noffset)) + return -EINVAL; + + if (fit_image_get_data_and_size(fit, noffset, data, size)) + return -ENOENT; + + if (!fit_get_desc(fit, noffset, &desc)) + printf("%s\n", desc); + + return 0; +} + +int fit_get_data_node(const void *fit, const char *image_uname, + const void **data, size_t *size) +{ + int noffset = fit_image_get_node(fit, image_uname); + + return fit_get_data_tail(fit, noffset, data, size); +} + +int fit_get_data_conf_prop(const void *fit, const char *prop_name, + const void **data, size_t *size) +{ + int noffset = fit_conf_get_node(fit, NULL); + + noffset = fit_conf_get_prop_node(fit, noffset, prop_name); + return fit_get_data_tail(fit, noffset, data, size); +} + static int fit_image_select(const void *fit, int rd_noffset, int verify) { fit_image_print(fit, rd_noffset, " "); diff --git a/include/image.h b/include/image.h index e4c6a50b88..d7d756c645 100644 --- a/include/image.h +++ b/include/image.h @@ -1014,6 +1014,76 @@ int fit_image_get_data_size_unciphered(const void *fit, int noffset, int fit_image_get_data_and_size(const void *fit, int noffset, const void **data, size_t *size); +/** + * fit_get_data_node() - Get verified image data for an image + * @fit: Pointer to the FIT format image header + * @image_uname: The name of the image node + * @data: A pointer which will be filled with the location of the image data + * @size: A pointer which will be filled with the size of the image data + * + * This function looks up the location and size of an image specified by its + * name. For example, if you had a FIT like:: + * + * images { + * my-firmware { + * ... + * }; + * }; + * + * Then you could look up the data location and size of the my-firmware image + * by calling this function with @image_uname set to "my-firmware". This + * function also verifies the image data (if enabled) before returning. The + * image description is printed out on success. @data and @size will not be + * modified on faulure. + * + * Return: + * * 0 on success + * * -EINVAL if the image could not be verified + * * -ENOENT if there was a problem getting the data/size + * * Another negative error if there was a problem looking up the image node. + */ +int fit_get_data_node(const void *fit, const char *image_uname, + const void **data, size_t *size); + +/** + * fit_get_data_conf_prop() - Get verified image data for a property in /conf + * @fit: Pointer to the FIT format image header + * @prop_name: The name of the property in /conf referencing the image + * @data: A pointer which will be filled with the location of the image data + * @size: A pointer which will be filled with the size of the image data + * + * This function looks up the location and size of an image specified by a + * property in /conf. For example, if you had a FIT like:: + * + * images { + * my-firmware { + * ... + * }; + * }; + * + * configurations { + * default = "conf-1"; + * conf-1 { + * some-firmware = "my-firmware"; + * }; + * }; + * + * Then you could look up the data location and size of the my-firmware image + * by calling this function with @prop_name set to "some-firmware". This + * function also verifies the image data (if enabled) before returning. The + * image description is printed out on success. @data and @size will not be + * modified on faulure. + * + * Return: + * * 0 on success + * * -EINVAL if the image could not be verified + * * -ENOENT if there was a problem getting the data/size + * * Another negative error if there was a problem looking up the configuration + * or image node. + */ +int fit_get_data_conf_prop(const void *fit, const char *prop_name, + const void **data, size_t *size); + int fit_image_hash_get_algo(const void *fit, int noffset, const char **algo); int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, int *value_len);