From patchwork Thu Oct 22 12:01:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kiryanov X-Patchwork-Id: 534378 X-Patchwork-Delegate: panto@antoniou-consulting.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 0310F14131E for ; Thu, 22 Oct 2015 23:02:19 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=compulab.co.il header.i=@compulab.co.il header.b=EdZkK6aF; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 81190A7472; Thu, 22 Oct 2015 14:02:03 +0200 (CEST) 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 UxSuoDD-CXdw; Thu, 22 Oct 2015 14:02:03 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 50319A7474; Thu, 22 Oct 2015 14:01:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0F1A94B892 for ; Thu, 22 Oct 2015 14:01:31 +0200 (CEST) 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 78VrgdcfDbmP for ; Thu, 22 Oct 2015 14:01:30 +0200 (CEST) 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 compulab.co.il (softlayer.compulab.co.il [50.23.254.55]) by theia.denx.de (Postfix) with ESMTPS id 25F324B894 for ; Thu, 22 Oct 2015 14:01:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=compulab.co.il; s=default; h=References:In-Reply-To:Message-Id:Date:Subject :Cc:To:From; bh=zNhI5tuRf6I73ZqyanR7b7WiC3JbDFFzsyUx4Pqcmcg=; b=EdZkK6aFWNvJb R5GNAVHQJ/Nhx6tfhvWM4BvCkpXtqS8hRhUw4gXsXOiAIwsuf5WrSLZQPgokJib5lsA4UFgqdwGlB 4vLHCJbFuDgpo1bI5dPUc8J4ifwG7PSeErBingsfj7PQJDd1MfeB4pzSEyJi4ouNAMpqt46WiBsLN 3Z2I=; Received: from [62.90.235.247] (port=45924 helo=zimbra-mta.compulab.co.il) by softlayer.compulab.co.il with esmtp (Exim 4.86) (envelope-from ) id 1ZpEYf-0001iy-TU; Thu, 22 Oct 2015 15:01:26 +0300 Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 0E56948D582; Thu, 22 Oct 2015 15:01:25 +0300 (IDT) Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id x2nhaUGhpJ4s; Thu, 22 Oct 2015 15:01:23 +0300 (IDT) Received: from localhost (localhost [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 8E77B48D56B; Thu, 22 Oct 2015 15:01:23 +0300 (IDT) X-Virus-Scanned: amavisd-new at zimbra-mta.compulab.co.il Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 6hw3SftoipWe; Thu, 22 Oct 2015 15:01:23 +0300 (IDT) Received: from skynet.compulab.local (nikita-pc.compulab.local [192.168.11.211]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 6F83548D562; Thu, 22 Oct 2015 15:01:23 +0300 (IDT) From: Nikita Kiryanov To: u-boot@lists.denx.de Date: Thu, 22 Oct 2015 15:01:11 +0300 Message-Id: <1445515280-21389-4-git-send-email-nikita@compulab.co.il> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445515280-21389-1-git-send-email-nikita@compulab.co.il> References: <1445515280-21389-1-git-send-email-nikita@compulab.co.il> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - softlayer.compulab.co.il X-AntiAbuse: Original Domain - lists.denx.de X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - compulab.co.il X-Get-Message-Sender-Via: softlayer.compulab.co.il: acl_c_recent_authed_mail_ips_text_entry: nikita@compulab.co.il|compulab.co.il X-Authenticated-Sender: softlayer.compulab.co.il: nikita@compulab.co.il Cc: Tom Rini , Pantelis Antoniou Subject: [U-Boot] [PATCH 03/12] spl: mmc: refactor device location code to 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" Simplify spl_mmc_load_image() code by moving the part that finds the mmc device into its own function spl_mmc_find_device(), available in two flavors: DM and non-DM. This refactor fixes a bug in which an error in the device location sequence does not necessarily aborts the rest of the code. With this refactor, we fail the moment there is an error. Signed-off-by: Nikita Kiryanov Cc: Igor Grinberg Cc: Paul Kocialkowski Cc: Pantelis Antoniou Cc: Tom Rini Cc: Simon Glass --- common/spl/spl_mmc.c | 77 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index e831970..cfbda1a 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,58 @@ end: return 0; } +#ifdef CONFIG_DM_MMC +static int spl_mmc_find_device(struct mmc **mmc) +{ + struct udevice *dev; + int err; + + err = mmc_initialize(NULL); + if (err) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("spl: could not initialize mmc. error: %d\n", err); +#endif + return err; + } + + err = uclass_get_device(UCLASS_MMC, 0, &dev); + if (err) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + puts("spl: could not find mmc device. error: %d\n", err); +#endif + return err; + } + + *mmc = NULL; + *mmc = mmc_get_mmc_dev(dev); + return *mmc != NULL ? 0 : -ENODEV; +} +#else +static int spl_mmc_find_device(struct mmc **mmc) +{ + int err; + + err = mmc_initialize(gd->bd); + if (err) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("spl: could not initialize mmc. error: %d\n", err); +#endif + return err; + } + + /* We register only one device. So, the dev id is always 0 */ + *mmc = find_mmc_device(0); + if (!*mmc) { +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + puts("spl: mmc device not found\n"); +#endif + return -ENODEV; + } + + return 0; +} +#endif + #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) { @@ -110,30 +163,10 @@ void spl_mmc_load_image(void) int err = 0; __maybe_unused int part; -#ifdef CONFIG_DM_MMC - struct udevice *dev; - - mmc_initialize(NULL); - err = uclass_get_device(UCLASS_MMC, 0, &dev); - mmc = NULL; - if (!err) - mmc = mmc_get_mmc_dev(dev); -#else - mmc_initialize(gd->bd); - - /* We register only one device. So, the dev id is always 0 */ - mmc = find_mmc_device(0); - if (!mmc) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT - puts("spl: mmc device not found\n"); -#endif + if (spl_mmc_find_device(&mmc)) hang(); - } -#endif - - if (!err) - err = mmc_init(mmc); + err = mmc_init(mmc); if (err) { #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf("spl: mmc init failed with error: %d\n", err);