From patchwork Wed Nov 30 22:30:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 701259 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3tTZrz3h6kz9t1L for ; Thu, 1 Dec 2016 09:31:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="CSGcnAVa"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DEA43A7581; Wed, 30 Nov 2016 23:31:24 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N5s8cObR4bv3; Wed, 30 Nov 2016 23:31:24 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F2E89A75AB; Wed, 30 Nov 2016 23:31:16 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8DA88A7593 for ; Wed, 30 Nov 2016 23:31:10 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X8VUIehwvTar for ; Wed, 30 Nov 2016 23:31:10 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-yw0-f169.google.com (mail-yw0-f169.google.com [209.85.161.169]) by theia.denx.de (Postfix) with ESMTPS id 233AFA7576 for ; Wed, 30 Nov 2016 23:31:06 +0100 (CET) Received: by mail-yw0-f169.google.com with SMTP id r204so170370334ywb.0 for ; Wed, 30 Nov 2016 14:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uftaufKayjMzRRmNxkJ4I+yQK49n9klttedU0U4aw/A=; b=CSGcnAVaRmPO2a4R+ngbh5PbWDP9hTMPZQvcSRlc2xxNTmlgsaHMQFGRQ6tSkdVRRt bmsgXbvKcnL9lF50fKkfwZeOqHmAs2PoJvggAoPAwBsU8e/L1mTJUXABa/OFueIR8hp7 R/S2OuURHWfrOrFtAVoMIdsrQzIMdMzdJrgYK6dlWLbreZA695QxEUIZpltvlEFFqb4g nLu9fbDAta+3CS5OLWA2DO2i/cfxzvlwG8Fhya+V14zfLzqxVkZAMKPVF5VMiTMLmz4I YGYFGFz0Gax2+ImC/YfVaqkwkj0xbK6GVmHuHFq1X+mX5NrhLG0rbSVpP+5/bY/ykYig mAVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uftaufKayjMzRRmNxkJ4I+yQK49n9klttedU0U4aw/A=; b=ImK/Ps+po64gC4EB9tXYUovCuZZvxFbFwG16I8zvi1Va2N3UNzZYaMpP8Umooh14Ry Bi+ByhS+e3S6zZzxrCWAlCE/9vIhN1oJaRMeY+u/DVVI9WDk8OIeCtgPAR7Dcj3vSCTl MRbU7OeshTAZQkjIzNvaLO7S4+Wk07uP89xdOXNg3NROsKAgPNH3D3Sp96qLAFTyL5yA JUv3d9W/mrAGmrWoR56u18iPPkNc8xO8X6KXY3VZD7C3Rwou+FMsp2TZTyZ9anTchE4G VxQHXDKSZDKMFQgZhq6QrK9EdgBnyAN7T6oLXrMveIspiYlUZ71HA/YEtRpzVOoXyP8d S/og== X-Gm-Message-State: AKaTC00xZKueGaBeLcHK8FK4z0lcA2MOA16hk1IGgJSVNwyAOlI36UfiWLcsd8fcgXJvZFBM X-Received: by 10.202.79.79 with SMTP id d76mr17204182oib.201.1480545065731; Wed, 30 Nov 2016 14:31:05 -0800 (PST) Received: from kaki.bld.corp.google.com ([100.100.197.48]) by smtp.gmail.com with ESMTPSA id 31sm21111017oth.21.2016.11.30.14.31.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Nov 2016 14:31:05 -0800 (PST) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id AE3434039C; Wed, 30 Nov 2016 15:31:04 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Wed, 30 Nov 2016 15:30:51 -0700 Message-Id: <1480545056-17704-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1480545056-17704-2-git-send-email-sjg@chromium.org> References: <1480545056-17704-2-git-send-email-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH v2 3/8] spl: Move the loading code into its own function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Create a boot_from_devices() function to handle trying each device. This helps to reduce the size of the already-large board_init_r() function. Signed-off-by: Simon Glass --- Changes in v2: - Drop incorrect use of ARRAY_SIZE in boot_from_devices() - Add a function comment to boot_from_devices() common/spl/spl.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/common/spl/spl.c b/common/spl/spl.c index 9c11ab1..f97d5b4 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -374,12 +374,36 @@ static int spl_load_image(struct spl_image_info *spl_image, u32 boot_device) bootdev.boot_device = boot_device; bootdev.boot_device_name = NULL; - if (loader) - return loader->load_image(spl_image, &bootdev); + return loader->load_image(spl_image, &bootdev); +} + +/** + * boot_from_devices() - Try loading an booting U-Boot from a list of devices + * + * @spl_image: Place to put the image details if successful + * @spl_boot_list: List of boot devices to try + * @count: Number of elements in spl_boot_list + * @return 0 if OK, -ve on error + */ +static int boot_from_devices(struct spl_image_info *spl_image, + u32 spl_boot_list[], int count) +{ + int i; + + for (i = 0; i < count && spl_boot_list[i] != BOOT_DEVICE_NONE; i++) { + struct spl_image_loader *loader; + + announce_boot_device(spl_boot_list[i]); + loader = spl_ll_find_loader(spl_boot_list[i]); #if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT) - puts("SPL: Unsupported Boot Device!\n"); + if (!loader) + puts("SPL: Unsupported Boot Device!\n"); #endif + if (loader && !spl_load_image(spl_image, spl_boot_list[i])) + return 0; + } + return -ENODEV; } @@ -393,7 +417,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2) BOOT_DEVICE_NONE, }; struct spl_image_info spl_image; - int i; debug(">>spl:board_init_r()\n"); @@ -420,15 +443,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2) memset(&spl_image, '\0', sizeof(spl_image)); board_boot_order(spl_boot_list); - for (i = 0; i < ARRAY_SIZE(spl_boot_list) && - spl_boot_list[i] != BOOT_DEVICE_NONE; i++) { - announce_boot_device(spl_boot_list[i]); - if (!spl_load_image(&spl_image, spl_boot_list[i])) - break; - } - if (i == ARRAY_SIZE(spl_boot_list) || - spl_boot_list[i] == BOOT_DEVICE_NONE) { + if (boot_from_devices(&spl_image, spl_boot_list, + ARRAY_SIZE(spl_boot_list))) { puts("SPL: failed to boot from all boot devices\n"); hang(); }