{"id":2216033,"url":"http://patchwork.ozlabs.org/api/patches/2216033/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20260325165431.1027591-10-sjg@chromium.org/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260325165431.1027591-10-sjg@chromium.org>","list_archive_url":null,"date":"2026-03-25T16:54:18","name":"[09/13] boot: Move image-decompression into a separate function","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f71796ade2c7b74c828b170d95e4862d684c9c6b","submitter":{"id":6170,"url":"http://patchwork.ozlabs.org/api/people/6170/?format=json","name":"Simon Glass","email":"sjg@chromium.org"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20260325165431.1027591-10-sjg@chromium.org/mbox/","series":[{"id":497475,"url":"http://patchwork.ozlabs.org/api/series/497475/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=497475","date":"2026-03-25T16:54:09","name":"boot: Make fit_image_load() easier to maintain","version":1,"mbox":"http://patchwork.ozlabs.org/series/497475/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2216033/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2216033/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256\n header.s=google header.b=VHE7O4un;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=85.214.62.61; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=chromium.org","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=chromium.org header.i=@chromium.org\n header.b=\"VHE7O4un\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=chromium.org","phobos.denx.de;\n spf=pass smtp.mailfrom=sjg@chromium.org"],"Received":["from phobos.denx.de (phobos.denx.de [85.214.62.61])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fgtNr5JKkz1y1K\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 26 Mar 2026 03:57:00 +1100 (AEDT)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 2A95A84073;\n\tWed, 25 Mar 2026 17:55:54 +0100 (CET)","by phobos.denx.de (Postfix, from userid 109)\n id 1359783FC6; Wed, 25 Mar 2026 17:55:53 +0100 (CET)","from mail-oi1-x235.google.com (mail-oi1-x235.google.com\n [IPv6:2607:f8b0:4864:20::235])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id C07128406D\n for <u-boot@lists.denx.de>; Wed, 25 Mar 2026 17:55:50 +0100 (CET)","by mail-oi1-x235.google.com with SMTP id\n 5614622812f47-464ba2bb3aeso708713b6e.1\n for <u-boot@lists.denx.de>; Wed, 25 Mar 2026 09:55:50 -0700 (PDT)","from chromium.org ([73.34.74.121]) by smtp.gmail.com with ESMTPSA id\n 5614622812f47-46a7099df08sm30481b6e.15.2026.03.25.09.55.47\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 25 Mar 2026 09:55:47 -0700 (PDT)"],"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,DKIMWL_WL_HIGH,\n DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,\n RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham\n autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=chromium.org; s=google; t=1774457749; x=1775062549; darn=lists.denx.de;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=OVf8oOj4tPW/YL1dCIS0G+uZRc1VnyGv1WkxRUKHY0A=;\n b=VHE7O4un8mt40hMBvGTtOeAQf85gXrCWNQSE0Q57YLxt+w2y5A8zC8KFcJqiNxhVDs\n 1hodj22lYql9DcGXSuTYOmdbm7TFJCLYxsLOx8zLl9NjI0nvDW24q9QNpCbYQZX/xv68\n H6eVjl85AYRQTwAIUqSbYVn1OLY92n3jTwVGo=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774457749; x=1775062549;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=OVf8oOj4tPW/YL1dCIS0G+uZRc1VnyGv1WkxRUKHY0A=;\n b=hCKNNdw7MpeoclNZXE/pkz0Rq2jA3C9Z5hqHOVqTMC8QSEDhaxVqmI+Ou4KykgtfEI\n PmmWS1FRX/nLUgXUqnlwua3EmlkSmQn0156SgqdVebsTIvyQ8oAfQGseSy6l8XvF5fE3\n 9VvuiGCh/YLyCHdn7yfMaBlhuzIjPy38aJY3ISvZpn3GntisFM4UatxD9gkw+YOshWRs\n 7Mu3FW/Nd/pdhja8+H7XBbJyLSftZYsw0Jqn+rkcbkuL5iAh6cGKKFxsuPBtqxAtByI/\n iNB48uPHg+EZ3pin/qFu4NpplHb7PoYM6q8gjFAy5pMQhCd98AesVbxu6xUHqzJy13WB\n YTmA==","X-Gm-Message-State":"AOJu0YwC4E+cnTA4bVuAFiW9Tb0PsmpM+4hAOnU6cIjaINNbbPAjIDam\n 0FSBjuWlIDyomWNpUNOu2xxW74NiVExgW1mpPEWdnf8hrcoLtV4edeMnmjESiMjZVHvG16ZSrT/\n +mNQSsw==","X-Gm-Gg":"ATEYQzyoHMmrBxg5WNSpMGacNiBOIPVY14ihZnweDrKAxdPOp9ysRwSdx/9Pwm9ihV+\n ya/QmARsvM5/yiWJ+ygOnHw+8zdL25DJzlyym9Ut1I0pZlZpBsjqlFHgwT0QxKBNaXheZYC9NJ1\n kX4uQq6aYCk3gulYbUw+9b5W+akLex6K7C2Tudt7KBElE6FmVxxmj4gj3wxB+0c5ZMbU1XF2L1f\n G43sbxeZIwY2OHEF35JPBA5H0Tj9TgFzGuZWdmD74WE9eGQE4x4KHBeuH8vyHzVY7uptbTeR2bk\n wboyL+7J9XZ0CWpjY5lDh72j0FiRkjIK3IaVk9+Jzwpu9la6fGIa3gPAh1CwbWIreUHcl8nRs8v\n v4s6G1shrzm/pdxuWLMzezCXn8KlnSjftrslpyvX2lH8e7Lxgus0vc5vBA2yKq/UX2V6hs1W+6u\n 0wCXY/pZ+eJiEMtqQ2Y/hqS8HEm7j8","X-Received":"by 2002:a05:6808:509e:b0:467:fb12:c9f6 with SMTP id\n 5614622812f47-46a0cdc14b5mr4355955b6e.14.1774457748684;\n Wed, 25 Mar 2026 09:55:48 -0700 (PDT)","From":"Simon Glass <sjg@chromium.org>","To":"u-boot@lists.denx.de","Cc":"Simon Glass <sjg@chromium.org>,\n James Hilliard <james.hilliard1@gmail.com>,\n Marek Vasut <marek.vasut+renesas@mailbox.org>,\n Quentin Schulz <quentin.schulz@cherry.de>, Tom Rini <trini@konsulko.com>","Subject":"[PATCH 09/13] boot: Move image-decompression into a separate function","Date":"Wed, 25 Mar 2026 10:54:18 -0600","Message-ID":"<20260325165431.1027591-10-sjg@chromium.org>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260325165431.1027591-1-sjg@chromium.org>","References":"<20260325165431.1027591-1-sjg@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Move handling of decompression (or perhaps relocation) of the image into\na separate function, to slim down fit_image_load() a little more.\n\nMove the bootstage_mark() call in there too.\n\nPass the load address by reference since it may be updated when the\nimage is relocated for alignment.\n\nSigned-off-by: Simon Glass <sjg@chromium.org>\n---\n\n boot/image-fit.c | 154 ++++++++++++++++++++++++++++++++---------------\n 1 file changed, 104 insertions(+), 50 deletions(-)","diff":"diff --git a/boot/image-fit.c b/boot/image-fit.c\nindex 0a880863063..a59226d42c5 100644\n--- a/boot/image-fit.c\n+++ b/boot/image-fit.c\n@@ -2288,6 +2288,104 @@ static int obtain_data(const void *fit, int noffset, const char *prop_name,\n \treturn 0;\n }\n \n+/**\n+ * decomp_image() - Decompress / relocate the image\n+ *\n+ * If the image is compressed, decompress it to the provided load address,\n+ * making sure it fits within the allowed space.\n+ *\n+ * If the image is not compressed, copy it (to the load address) if needed.\n+ *\n+ * Kernels are not decompressed here, since that is handled in bootm_load_os()\n+ *\n+ * Compression is ignored on ramdisks, although a warning is provided. Since the\n+ * ramdisk normally uses its own compression, doing additional compression at\n+ * the FIT level is counter-productive.\n+ *\n+ * For devicetree, check that the image is actually a devicetree\n+ *\n+ * @fit: FIT to check\n+ * @noffset: Node offset of the image being loaded\n+ * @prop_name: Property name (in the configuration node) indicating the image\n+ * that was loaded\n+ * @buf: Pointer to image (within the FIT)\n+ * @size: Size of the image in bytes\n+ * @image_type: Type of the image\n+ * @load_op: Load operation to process\n+ * @bootstage_id: ID of starting bootstage to use for progress updates\n+ * @data: Data buffer\n+ * @loadp: On entry, the address to which the data should be loaded. Updated\n+ *\tif the data is relocated (e.g. for alignment)\n+ * @sizep: On entry, the size of the image in bytes. Updated if the image is\n+ *\tdecompressed\n+ * @load_end: End address of the data-loading location\n+ * Return: 0 if OK, -ve on error\n+ */\n+static int decomp_image(const void *fit, int noffset, const char *prop_name,\n+\t\t\tvoid *buf, enum image_type_t image_type,\n+\t\t\tenum fit_load_op load_op, int bootstage_id, ulong data,\n+\t\t\tulong *loadp, ulong *sizep, ulong load_end)\n+{\n+\tulong load = *loadp;\n+\tulong size = *sizep;\n+\tvoid *loadbuf;\n+\tuint8_t comp;\n+\n+\tcomp = IH_COMP_NONE;\n+\tloadbuf = buf;\n+\t/* Kernel images get decompressed later in bootm_load_os(). */\n+\tif (!fit_image_get_comp(fit, noffset, &comp) &&\n+\t    comp != IH_COMP_NONE &&\n+\t    load_op != FIT_LOAD_IGNORED &&\n+\t    !(image_type == IH_TYPE_KERNEL ||\n+\t      image_type == IH_TYPE_KERNEL_NOLOAD ||\n+\t      image_type == IH_TYPE_RAMDISK)) {\n+\t\tulong max_decomp_len = size * 20;\n+\n+\t\tlog_debug(\"decompressing image\\n\");\n+\t\tif (load == data) {\n+\t\t\tloadbuf = aligned_alloc(8, max_decomp_len);\n+\t\t\tload = map_to_sysmem(loadbuf);\n+\t\t} else {\n+\t\t\tloadbuf = map_sysmem(load, max_decomp_len);\n+\t\t}\n+\t\tif (image_decomp(comp, load, data, image_type, loadbuf, buf,\n+\t\t\t\t size, max_decomp_len, &load_end)) {\n+\t\t\tprintf(\"Error decompressing %s\\n\", prop_name);\n+\n+\t\t\treturn -ENOEXEC;\n+\t\t}\n+\t\tsize = load_end - load;\n+\t} else if (load_op != FIT_LOAD_IGNORED &&\n+\t\t   image_type == IH_TYPE_FLATDT &&\n+\t\t   ((uintptr_t)buf & 7)) {\n+\t\tloadbuf = aligned_alloc(8, size);\n+\t\tload = map_to_sysmem(loadbuf);\n+\t\tmemcpy(loadbuf, buf, size);\n+\t} else if (load != data) {\n+\t\tlog_debug(\"copying\\n\");\n+\t\tloadbuf = map_sysmem(load, size);\n+\t\tmemcpy(loadbuf, buf, size);\n+\t}\n+\t*loadp = load;\n+\t*sizep = size;\n+\n+\tif (image_type == IH_TYPE_RAMDISK && comp != IH_COMP_NONE)\n+\t\tputs(\"WARNING: 'compression' nodes for ramdisks are deprecated,\"\n+\t\t     \" please fix your .its file!\\n\");\n+\n+\t/* verify that image data is a proper FDT blob */\n+\tif (load_op != FIT_LOAD_IGNORED && image_type == IH_TYPE_FLATDT &&\n+\t    fdt_check_header(loadbuf)) {\n+\t\tputs(\"Subimage data is not a FDT\\n\");\n+\t\treturn -ENOEXEC;\n+\t}\n+\n+\tbootstage_mark(bootstage_id + BOOTSTAGE_SUB_LOAD);\n+\n+\treturn 0;\n+}\n+\n /**\n  * handle_load_op() - Handle the load operation\n  *\n@@ -2369,9 +2467,8 @@ int fit_image_load(struct bootm_headers *images, ulong addr,\n \tconst char *fit_base_uname_config;\n \tconst void *fit;\n \tvoid *buf;\n-\tvoid *loadbuf;\n \tulong load, load_end, data, len;\n-\tuint8_t comp, os_arch;\n+\tuint8_t os_arch;\n \tconst char *prop_name;\n \tint ret;\n \n@@ -2404,54 +2501,11 @@ int fit_image_load(struct bootm_headers *images, ulong addr,\n \tif (ret)\n \t\treturn ret;\n \n-\tcomp = IH_COMP_NONE;\n-\tloadbuf = buf;\n-\t/* Kernel images get decompressed later in bootm_load_os(). */\n-\tif (!fit_image_get_comp(fit, noffset, &comp) &&\n-\t    comp != IH_COMP_NONE &&\n-\t    load_op != FIT_LOAD_IGNORED &&\n-\t    !(image_type == IH_TYPE_KERNEL ||\n-\t      image_type == IH_TYPE_KERNEL_NOLOAD ||\n-\t      image_type == IH_TYPE_RAMDISK)) {\n-\t\tulong max_decomp_len = len * 20;\n-\n-\t\tlog_debug(\"decompressing image\\n\");\n-\t\tif (load == data) {\n-\t\t\tloadbuf = aligned_alloc(8, max_decomp_len);\n-\t\t\tload = map_to_sysmem(loadbuf);\n-\t\t} else {\n-\t\t\tloadbuf = map_sysmem(load, max_decomp_len);\n-\t\t}\n-\t\tif (image_decomp(comp, load, data, image_type,\n-\t\t\t\tloadbuf, buf, len, max_decomp_len, &load_end)) {\n-\t\t\tprintf(\"Error decompressing %s\\n\", prop_name);\n-\n-\t\t\treturn -ENOEXEC;\n-\t\t}\n-\t\tlen = load_end - load;\n-\t} else if (load_op != FIT_LOAD_IGNORED && image_type == IH_TYPE_FLATDT &&\n-\t\t   ((uintptr_t)buf & 7)) {\n-\t\tloadbuf = aligned_alloc(8, len);\n-\t\tload = map_to_sysmem(loadbuf);\n-\t\tmemcpy(loadbuf, buf, len);\n-\t} else if (load != data) {\n-\t\tlog_debug(\"copying\\n\");\n-\t\tloadbuf = map_sysmem(load, len);\n-\t\tmemcpy(loadbuf, buf, len);\n-\t}\n-\n-\tif (image_type == IH_TYPE_RAMDISK && comp != IH_COMP_NONE)\n-\t\tputs(\"WARNING: 'compression' nodes for ramdisks are deprecated,\"\n-\t\t     \" please fix your .its file!\\n\");\n-\n-\t/* verify that image data is a proper FDT blob */\n-\tif (load_op != FIT_LOAD_IGNORED && image_type == IH_TYPE_FLATDT &&\n-\t    fdt_check_header(loadbuf)) {\n-\t\tputs(\"Subimage data is not a FDT\\n\");\n-\t\treturn -ENOEXEC;\n-\t}\n-\n-\tbootstage_mark(bootstage_id + BOOTSTAGE_SUB_LOAD);\n+\tret = decomp_image(fit, noffset, prop_name, buf, image_type,\n+\t\t\t   load_op, bootstage_id, data, &load, &len,\n+\t\t\t   load_end);\n+\tif (ret)\n+\t\treturn ret;\n \n \tupl_add_image(fit, noffset, load, len);\n \n","prefixes":["09/13"]}