From patchwork Mon May 3 23:11:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1473526 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=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=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=cgw8tSS7; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FYzTS6kvmz9sCD for ; Tue, 4 May 2021 09:19:56 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6878382CDD; Tue, 4 May 2021 01:18:35 +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="cgw8tSS7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCC7F82E31; Tue, 4 May 2021 01:18:28 +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.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) (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 B02CD82D3D for ; Tue, 4 May 2021 01:12:35 +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-io1-xd36.google.com with SMTP id b9so5492896iod.13 for ; Mon, 03 May 2021 16:12:35 -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=+k8lgzRdkBsiU+A7KtWPWVUug79uE2VKCrGGN0Yesec=; b=cgw8tSS7nUql+dqX51fP1zqKXM1WLLPK2y5vW98P67Z+zJ4GFZubsH4OK0iqGoabNI 6LC03M4ZeTXeEITtAlt/8Yj0i2EmjW7iNyOFkNGQlyQ3fvLBzKMfGUHW+061/Y1ABpys 3RCWkTwvvAo3Xc7Y82pkjA26nh1d1JpkZ+kWI= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=+k8lgzRdkBsiU+A7KtWPWVUug79uE2VKCrGGN0Yesec=; b=LDgT9uqquAE2mtivqj67T6ckbZ8dIC1tcf4stYja/iURmnB74Y+OMydO6jdQcBSoY8 LYnoMWuRUu62oyAVHxiyBD80ArMO35Aqn9Z0JyWe9BLjcXUwydBqbtWbyJW0crJBpU4Z mXb7UKZIv0ZsJZ1JDbsVAnH6jUTsVSzOuxk5xNS5LpnsSE7GQHCfV+RKbDvqcTfi1KXx vVei4QCiJN1mPYbzwF/ve/5qhSJAsX2TrK58HBqYaM8rpM27SO5qlUg+yPGCfSZXY+qP tywDKgbw6PoudrkR7VezVY2ccdCWk0AbdnezEPZO+MvfwSr20xi7F0xG8gqHQ/sOttkX wb3Q== X-Gm-Message-State: AOAM530/AJxEiUJ2Mw69g/VcnHxrezbjSel9GAjFbljTSYL8OsYMPu7v gd9UBJjlFhWl8CHGJ62viF2R+bfp25SfEg== X-Google-Smtp-Source: ABdhPJz7MDYlwrL3pmi3ymi///Qt0XB1qb2wM777e2wvhCkedtX+5epL4HAomnz3MWVZb7ILmemdOA== X-Received: by 2002:a5d:9682:: with SMTP id m2mr17175856ion.20.1620083554152; Mon, 03 May 2021 16:12:34 -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 o6sm422727ioa.21.2021.05.03.16.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 16:12:33 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Bin Meng , Robert Marko , Andre Przywara , Masahiro Yamada , Simon Glass , Joe Hershberger , Marek Vasut , Naoki Hayama , Stefan Roese Subject: [PATCH 44/49] image: Split up boot_get_ramdisk() Date: Mon, 3 May 2021 17:11:31 -0600 Message-Id: <20210503231136.744283-17-sjg@chromium.org> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog In-Reply-To: <20210503231136.744283-1-sjg@chromium.org> References: <20210503231136.744283-1-sjg@chromium.org> MIME-Version: 1.0 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.102.4 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 --- (no changes since v1) common/image-board.c | 147 +++++++++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 60 deletions(-) diff --git a/common/image-board.c b/common/image-board.c index f0ef426d1c9..c32fff96ece 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, rd_load; + 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,10 +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_datap = image_get_data(rd_hdr); + *rd_lenp = image_get_data_size(rd_hdr); rd_load = image_get_load(rd_hdr); break; } @@ -451,9 +415,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 +427,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,15 +437,78 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images, if (select) end = strchr(select, ':'); if (end) { - rd_len = simple_strtoul(++end, NULL, 16); - rd_data = rd_addr; + *rd_lenp = simple_strtoul(++end, NULL, 16); + *rd_datap = rd_addr; break; } } puts("Wrong Ramdisk Image Format\n"); - rd_data = rd_len = rd_load = 0; - return 1; + *rd_datap = *rd_lenp = rd_load = 0; + 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)) {