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 061A3C433F5 for ; Sun, 26 Sep 2021 01:48:23 +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 7D22E60184 for ; Sun, 26 Sep 2021 01:48:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7D22E60184 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 75596835E1; Sun, 26 Sep 2021 03:47:28 +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="inmjB5TS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B155B835D5; Sun, 26 Sep 2021 03:45:21 +0200 (CEST) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (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 AFDFA835E6 for ; Sun, 26 Sep 2021 03:44:15 +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-ot1-x331.google.com with SMTP id o59-20020a9d2241000000b0054745f28c69so16860178ota.13 for ; Sat, 25 Sep 2021 18:44:15 -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=ukO5l3E+Yxn6vmvt8zKkSF/BygD0P0cPFD+wI+78/WA=; b=inmjB5TSbUI/Lv0v+Gw8wzsI5ySaRbaZN9SQOfAqD9EtR2t2Xdc0guStLGck5pNuMh ecBGbo6t5ubQ3g1zvROBcx91rUbOvEAEciAKzff6UTXC7O4kZNUEFcR2V9m/otkdwyqU xlUETLNAH7HtrPzviqcro/Wl1zKks4McW7t5U= 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=ukO5l3E+Yxn6vmvt8zKkSF/BygD0P0cPFD+wI+78/WA=; b=43aIvz27Rgv3LpIqbD+HkR2xOznS5OF5HjPeFAlUQ74oGm4hTjEKnNHJIGEyvfFfv8 8EEJBG2wuAswZM7QTUloHtqNCMlbVzHOeTL9a/A6iIuLzpTX9WjEihCzzFvJtx+EOKzC L6Ki8cqDeRbBW/ShTO/iJUpedEsRs8f9EirUqnxcwsVPWJVjf08MQ1IP149mEqCpk6dx VKAVZKpA0vclMzvA1VRcaftlRwD2ZkGgoftztMLLktQviEGmK/d2/XW4+Y9SBRkpKnIY P6fvIxdLe12zKvcYc7TgtQ1RBFcZeGUAxIXAVGTI6OVKw1vXxQhRdM9IJC0dMsDpDUQe ZQ5Q== X-Gm-Message-State: AOAM533CZjebsMYiS6iOmUM5XDqSXDXLpAE66deodITh9naxekJlFZk9 E1gxTXNBlv9NYriytns6Fo09D1qvngUZ3A== X-Google-Smtp-Source: ABdhPJwZWY2cGwqBFNohLu/9v68kESnDL18nzSMyC67LUQDhkItjpTk4HtRlyV2Q6fJ4n8cA6428Gw== X-Received: by 2002:a05:6830:4b8:: with SMTP id l24mr11614057otd.334.1632620654123; Sat, 25 Sep 2021 18:44:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Sep 2021 18:44:13 -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 24/29] image: Split up boot_get_ramdisk() Date: Sat, 25 Sep 2021 19:43:37 -0600 Message-Id: <20210926014342.127913-18-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 ramdisk into a separate function. Leave the code indented as it was for easier review. The next patch cleans this up along with checkpatch violations. Signed-off-by: Simon Glass --- Changes in v5: - Drop rd_load since it is not used Changes in v2: - Drop unnecessary setting of rd_len, etc. common/image-board.c | 149 +++++++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 63 deletions(-) diff --git a/common/image-board.c b/common/image-board.c index 0c9500829a1..fecc4bf6365 100644 --- a/common/image-board.c +++ b/common/image-board.c @@ -313,57 +313,21 @@ int genimg_has_config(bootm_headers_t *images) } /** - * boot_get_ramdisk - main ramdisk handling routine - * @argc: command argument count - * @argv: command argument list + * select_ramdisk() - Select and locate the ramdisk to use + * * @images: pointer to the bootm images structure + * @select: name of ramdisk to select, or NULL for any * @arch: expected ramdisk architecture - * @rd_start: pointer to a ulong variable, will hold ramdisk start address - * @rd_end: pointer to a ulong variable, will hold ramdisk end - * - * boot_get_ramdisk() is responsible for finding a valid ramdisk image. - * Currently supported are the following ramdisk sources: - * - multicomponent kernel/ramdisk image, - * - commandline provided address of decicated ramdisk image. - * - * returns: - * 0, if ramdisk image was found and valid, or skiped - * rd_start and rd_end are set to ramdisk start/end addresses if - * ramdisk image is found and valid - * - * 1, if ramdisk image is found but corrupted, or invalid - * rd_start and rd_end are set to 0 if no ramdisk exists + * @rd_datap: pointer to a ulong variable, will hold ramdisk pointer + * @rd_lenp: pointer to a ulong variable, will hold ramdisk length + * @return 0 if OK, -ENOPKG if no ramdisk (but an error should not be reported), + * other -ve value on other error */ -int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, - u8 arch, ulong *rd_start, ulong *rd_end) +static int select_ramdisk(bootm_headers_t *images, const char *select, u8 arch, + ulong *rd_datap, ulong *rd_lenp) { - ulong rd_data, rd_len; - void *buf; - const char *select = NULL; - - *rd_start = 0; - *rd_end = 0; - - if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { - /* Look for an Android boot image */ - buf = map_sysmem(images->os.start, 0); - if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) - select = (argc == 0) ? env_get("loadaddr") : argv[0]; - } - - if (argc >= 2) - select = argv[1]; - - /* - * Look for a '-' which indicates to ignore the - * ramdisk argument - */ - if (select && strcmp(select, "-") == 0) { - debug("## Skipping init Ramdisk\n"); - rd_len = 0; - rd_data = 0; - } else if (select || genimg_has_config(images)) { - ulong rd_addr, rd_load; + ulong rd_addr; + char *buf; #if CONFIG_IS_ENABLED(FIT) const char *fit_uname_config = images->fit_uname_cfg; @@ -403,16 +367,16 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, } else { /* use FIT configuration provided in first bootm * command argument. If the property is not defined, - * quit silently. + * quit silently (with -ENOPKG) */ rd_addr = map_to_sysmem(images->fit_hdr_os); rd_noffset = fit_get_node_from_config(images, FIT_RAMDISK_PROP, rd_addr); if (rd_noffset == -ENOENT) - return 0; + return -ENOPKG; else if (rd_noffset < 0) - return 1; + return rd_noffset; } #endif @@ -435,11 +399,10 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, images->verify); if (!rd_hdr) - return 1; + return -ENOENT; - rd_data = image_get_data(rd_hdr); - rd_len = image_get_data_size(rd_hdr); - rd_load = image_get_load(rd_hdr); + *rd_datap = image_get_data(rd_hdr); + *rd_lenp = image_get_data_size(rd_hdr); break; } #endif @@ -451,9 +414,9 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, IH_TYPE_RAMDISK, BOOTSTAGE_ID_FIT_RD_START, FIT_LOAD_OPTIONAL_NON_ZERO, - &rd_data, &rd_len); + rd_datap, rd_lenp); if (rd_noffset < 0) - return 1; + return rd_noffset; images->fit_hdr_rd = map_sysmem(rd_addr, 0); images->fit_uname_rd = fit_uname_ramdisk; @@ -463,7 +426,7 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, #ifdef CONFIG_ANDROID_BOOT_IMAGE case IMAGE_FORMAT_ANDROID: android_image_get_ramdisk((void *)images->os.start, - &rd_data, &rd_len); + rd_datap, rd_lenp); break; #endif default: @@ -473,17 +436,77 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, if (select) end = strchr(select, ':'); if (end) { - rd_len = hextoul(++end, NULL); - rd_data = rd_addr; + *rd_lenp = hextoul(++end, NULL); + *rd_datap = rd_addr; break; } } puts("Wrong Ramdisk Image Format\n"); - rd_data = 0; - rd_len = 0; - rd_load = 0; - return 1; + return -EINVAL; } + + return 0; +} + +/** + * boot_get_ramdisk - main ramdisk handling routine + * @argc: command argument count + * @argv: command argument list + * @images: pointer to the bootm images structure + * @arch: expected ramdisk architecture + * @rd_start: pointer to a ulong variable, will hold ramdisk start address + * @rd_end: pointer to a ulong variable, will hold ramdisk end + * + * boot_get_ramdisk() is responsible for finding a valid ramdisk image. + * Currently supported are the following ramdisk sources: + * - multicomponent kernel/ramdisk image, + * - commandline provided address of decicated ramdisk image. + * + * returns: + * 0, if ramdisk image was found and valid, or skiped + * rd_start and rd_end are set to ramdisk start/end addresses if + * ramdisk image is found and valid + * + * 1, if ramdisk image is found but corrupted, or invalid + * rd_start and rd_end are set to 0 if no ramdisk exists + */ +int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, + u8 arch, ulong *rd_start, ulong *rd_end) +{ + ulong rd_data, rd_len; + const char *select = NULL; + + *rd_start = 0; + *rd_end = 0; + + if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { + char *buf; + + /* Look for an Android boot image */ + buf = map_sysmem(images->os.start, 0); + if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) + select = (argc == 0) ? env_get("loadaddr") : argv[0]; + } + + if (argc >= 2) + select = argv[1]; + + /* + * Look for a '-' which indicates to ignore the + * ramdisk argument + */ + if (select && strcmp(select, "-") == 0) { + debug("## Skipping init Ramdisk\n"); + rd_len = 0; + rd_data = 0; + } else if (select || genimg_has_config(images)) { + int ret; + + ret = select_ramdisk(images, select, arch, &rd_data, &rd_len); + if (ret == -ENOPKG) + return 0; + else if (ret) + return ret; } else if (images->legacy_hdr_valid && image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { -- 2.33.0.685.g46640cef36-goog