From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BBF2C433EF for ; Sun, 26 Sep 2021 01:49:42 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0980E60184 for ; Sun, 26 Sep 2021 01:49:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0980E60184 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5473583626; Sun, 26 Sep 2021 03:47:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PfSYxjT0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A9A34835FE; Sun, 26 Sep 2021 03:45:31 +0200 (CEST) Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E5E9E835F3 for ; Sun, 26 Sep 2021 03:44:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x236.google.com with SMTP id t189so20292260oie.7 for ; Sat, 25 Sep 2021 18:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V1oRzRBFLBknqNEOEPED5pZWkysrK2mAOIko9UsSvUM=; b=PfSYxjT0IP0/xl1JvFFplKMImTNoz1e6i/9Xzr0OlO6pdxpKtKuMLqRYSzDlpW8H2W cXzqNha70AvqrBcTh9kIjXKDpVHtm64ZA2plBSPrj41wAjzh/HlUe6kVkers6t68oNpT Rb5Jj/YRZeopV9fub+YDJYheX85Un2VFbQzIQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V1oRzRBFLBknqNEOEPED5pZWkysrK2mAOIko9UsSvUM=; b=yZKvtr9qdUnezgr3YyH8Ge2gH9vYnvkcEpB7elO0rM64cYQB6sYTAeOetkPW6e1eNa xXI8j1soxuP+gbr3PnrM1sShOKe1I0dpyb07TlScAy5D5jx9w4NMPH3a1xJ53YjngOm/ TgdkPpwVKIFLh5zslpk1hbwycMerL2wUJsp4QoCiaNHJkEyz1nyEpQAVittqZa2TRp7e iwgS6b/IEJLTQdvZC4pJzdT3vrx1z8CEFKzQQf5nvwrchWqxDGltJIph4nFFI7GxqyEv Kl/CTsb/IMRfgqarNesk+xiOxdcvSs/R4Yg0nzT+gU+hXEsS8BHzcLvgI2ScMpybcD1B 6fjg== X-Gm-Message-State: AOAM532C5rHibgRwwuJ6GsaniJdiRgEDLauCBAkk2LrE/JcuamtE+3+N FGfzWH22Kg4JlQuQqae1ykkSGPOQaAd80A== X-Google-Smtp-Source: ABdhPJyOk/sdeOcBUOKEUWWE9lIGBVVD3CSc8GvKkyIpWusGdcO+/dDXQwNcQOGrgtwSkYjO5VBvuA== X-Received: by 2002:a05:6808:118c:: with SMTP id j12mr6875753oil.65.1632620658277; Sat, 25 Sep 2021 18:44:18 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id c18sm330378otr.72.2021.09.25.18.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Sep 2021 18:44:17 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Alexandru Gagniuc , Andre Przywara , Rasmus Villemoes , Robert Marko , Masahiro Yamada , Tom Rini , Simon Glass , Joe Hershberger , Marek Vasut Subject: [PATCH v5 28/29] image: Split up boot_get_fdt() Date: Sat, 25 Sep 2021 19:43:41 -0600 Message-Id: <20210926014342.127913-22-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog In-Reply-To: <20210926014342.127913-1-sjg@chromium.org> References: <20210926014342.127913-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean This function is far too long. Before trying to remove #ifdefs, split out the code that deals with selecting the FDT into a separate function. Signed-off-by: Simon Glass --- Changes in v5: - Rebase to next common/image-fdt.c | 226 +++++++++++++++++++++++++-------------------- 1 file changed, 126 insertions(+), 100 deletions(-) diff --git a/common/image-fdt.c b/common/image-fdt.c index 78c1e5b1a9a..c894f61b229 100644 --- a/common/image-fdt.c +++ b/common/image-fdt.c @@ -252,53 +252,29 @@ error: } /** - * boot_get_fdt - main fdt handling routine - * @argc: command argument count - * @argv: command argument list - * @arch: architecture (IH_ARCH_...) - * @images: pointer to the bootm images structure - * @of_flat_tree: pointer to a char* variable, will hold fdt start address - * @of_size: pointer to a ulong variable, will hold fdt length - * - * boot_get_fdt() is responsible for finding a valid flat device tree image. - * Curently supported are the following ramdisk sources: - * - multicomponent kernel/ramdisk image, - * - commandline provided address of decicated ramdisk image. - * - * returns: - * 0, if fdt image was found and valid, or skipped - * of_flat_tree and of_size are set to fdt start address and length if - * fdt image is found and valid + * select_fdt() - Select and locate the FDT to use * - * 1, if fdt image is found but corrupted - * of_flat_tree and of_size are set to 0 if no fdt exists + * @images: pointer to the bootm images structure + * @select: name of FDT to select, or NULL for any + * @arch: expected FDT architecture + * @fdt_addrp: pointer to a ulong variable, will hold FDT pointer + * @return 0 if OK, -ENOPKG if no FDT (but an error should not be reported), + * other -ve value on other error */ -int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, - bootm_headers_t *images, char **of_flat_tree, ulong *of_size) -{ - ulong img_addr; - ulong fdt_addr; - char *fdt_blob = NULL; - void *buf; - const char *select = NULL; - - *of_flat_tree = NULL; - *of_size = 0; - img_addr = (argc == 0) ? image_load_addr : - hextoul(argv[0], NULL); - buf = map_sysmem(img_addr, 0); +static int select_fdt(bootm_headers_t *images, const char *select, u8 arch, + ulong *fdt_addrp) +{ + const char *buf; + ulong fdt_addr; - if (argc > 2) - select = argv[2]; - if (select || genimg_has_config(images)) { #if CONFIG_IS_ENABLED(FIT) - const char *fit_uname_config = images->fit_uname_cfg; - const char *fit_uname_fdt = NULL; - ulong default_addr; - int fdt_noffset; + const char *fit_uname_config = images->fit_uname_cfg; + const char *fit_uname_fdt = NULL; + ulong default_addr; + int fdt_noffset; - if (select) { + if (select) { /* * If the FDT blob comes from the FIT image and the * FIT image address is omitted in the command line @@ -312,48 +288,47 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, else default_addr = image_load_addr; - if (fit_parse_conf(select, default_addr, - &fdt_addr, &fit_uname_config)) { + if (fit_parse_conf(select, default_addr, &fdt_addr, + &fit_uname_config)) { debug("* fdt: config '%s' from image at 0x%08lx\n", fit_uname_config, fdt_addr); - } else if (fit_parse_subimage(select, default_addr, - &fdt_addr, &fit_uname_fdt)) { + } else if (fit_parse_subimage(select, default_addr, &fdt_addr, + &fit_uname_fdt)) { debug("* fdt: subimage '%s' from image at 0x%08lx\n", fit_uname_fdt, fdt_addr); } else #endif - { - fdt_addr = hextoul(select, NULL); - debug("* fdt: cmdline image address = 0x%08lx\n", - fdt_addr); - } -#if CONFIG_IS_ENABLED(FIT) - } else { - /* use FIT configuration provided in first bootm - * command argument - */ - fdt_addr = map_to_sysmem(images->fit_hdr_os); - fdt_noffset = fit_get_node_from_config(images, - FIT_FDT_PROP, - fdt_addr); - if (fdt_noffset == -ENOENT) - return 0; - else if (fdt_noffset < 0) - return 1; + { + fdt_addr = hextoul(select, NULL); + debug("* fdt: cmdline image address = 0x%08lx\n", + fdt_addr); } -#endif - debug("## Checking for 'FDT'/'FDT Image' at %08lx\n", - fdt_addr); - - /* - * Check if there is an FDT image at the - * address provided in the second bootm argument - * check image type, for FIT images get a FIT node. +#if CONFIG_IS_ENABLED(FIT) + } else { + /* use FIT configuration provided in first bootm + * command argument */ - buf = map_sysmem(fdt_addr, 0); - switch (genimg_get_format(buf)) { + fdt_addr = map_to_sysmem(images->fit_hdr_os); + fdt_noffset = fit_get_node_from_config(images, FIT_FDT_PROP, + fdt_addr); + if (fdt_noffset == -ENOENT) + return -ENOPKG; + else if (fdt_noffset < 0) + return fdt_noffset; + } +#endif + debug("## Checking for 'FDT'/'FDT Image' at %08lx\n", + fdt_addr); + + /* + * Check if there is an FDT image at the + * address provided in the second bootm argument + * check image type, for FIT images get a FIT node. + */ + buf = map_sysmem(fdt_addr, 0); + switch (genimg_get_format(buf)) { #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) - case IMAGE_FORMAT_LEGACY: { + case IMAGE_FORMAT_LEGACY: { const image_header_t *fdt_hdr; ulong load, load_end; ulong image_start, image_data, image_end; @@ -363,7 +338,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, fdt_addr); fdt_hdr = image_get_fdt(fdt_addr); if (!fdt_hdr) - goto no_fdt; + return -ENOPKG; /* * move image data to the load address, @@ -384,7 +359,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, if ((load < image_end) && (load_end > image_start)) { fdt_error("fdt overwritten"); - goto error; + return -EFAULT; } debug(" Loading FDT from 0x%08lx to 0x%08lx\n", @@ -398,24 +373,24 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, break; } #endif - case IMAGE_FORMAT_FIT: - /* - * This case will catch both: new uImage format - * (libfdt based) and raw FDT blob (also libfdt - * based). - */ + case IMAGE_FORMAT_FIT: + /* + * This case will catch both: new uImage format + * (libfdt based) and raw FDT blob (also libfdt + * based). + */ #if CONFIG_IS_ENABLED(FIT) /* check FDT blob vs FIT blob */ if (!fit_check_format(buf, IMAGE_SIZE_INVAL)) { ulong load, len; - fdt_noffset = boot_get_fdt_fit(images, - fdt_addr, &fit_uname_fdt, - &fit_uname_config, - arch, &load, &len); + fdt_noffset = boot_get_fdt_fit(images, fdt_addr, + &fit_uname_fdt, + &fit_uname_config, + arch, &load, &len); if (fdt_noffset < 0) - goto error; + return -ENOENT; images->fit_hdr_fdt = map_sysmem(fdt_addr, 0); images->fit_uname_fdt = fit_uname_fdt; @@ -423,22 +398,73 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, fdt_addr = load; break; - } else + } else #endif - { - /* - * FDT blob - */ - debug("* fdt: raw FDT blob\n"); - printf("## Flattened Device Tree blob at %08lx\n", - (long)fdt_addr); - } - break; - default: - puts("ERROR: Did not find a cmdline Flattened Device Tree\n"); - goto error; + { + /* + * FDT blob + */ + debug("* fdt: raw FDT blob\n"); + printf("## Flattened Device Tree blob at %08lx\n", + (long)fdt_addr); } + break; + default: + puts("ERROR: Did not find a cmdline Flattened Device Tree\n"); + return -ENOENT; + } + *fdt_addrp = fdt_addr; + + return 0; +} +/** + * boot_get_fdt - main fdt handling routine + * @argc: command argument count + * @argv: command argument list + * @arch: architecture (IH_ARCH_...) + * @images: pointer to the bootm images structure + * @of_flat_tree: pointer to a char* variable, will hold fdt start address + * @of_size: pointer to a ulong variable, will hold fdt length + * + * boot_get_fdt() is responsible for finding a valid flat device tree image. + * Currently supported are the following ramdisk sources: + * - multicomponent kernel/ramdisk image, + * - commandline provided address of decicated ramdisk image. + * + * returns: + * 0, if fdt image was found and valid, or skipped + * of_flat_tree and of_size are set to fdt start address and length if + * fdt image is found and valid + * + * 1, if fdt image is found but corrupted + * of_flat_tree and of_size are set to 0 if no fdt exists + */ +int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, + bootm_headers_t *images, char **of_flat_tree, ulong *of_size) +{ + ulong img_addr; + ulong fdt_addr; + char *fdt_blob = NULL; + void *buf; + const char *select = NULL; + + *of_flat_tree = NULL; + *of_size = 0; + + img_addr = (argc == 0) ? image_load_addr : hextoul(argv[0], NULL); + buf = map_sysmem(img_addr, 0); + + if (argc > 2) + select = argv[2]; + if (select || genimg_has_config(images)) { + int ret; + + ret = select_fdt(images, select, arch, &fdt_addr); + if (ret == -ENOPKG) + goto no_fdt; + else if (ret) + return 1; printf(" Booting using the fdt blob at %#08lx\n", fdt_addr); fdt_blob = map_sysmem(fdt_addr, 0); } else if (images->legacy_hdr_valid && -- 2.33.0.685.g46640cef36-goog