From patchwork Wed Sep 25 14:11:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1167268 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="L5QUAZIY"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46dgCg3byhz9sNx for ; Thu, 26 Sep 2019 00:18:55 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 241FFC21FC7; Wed, 25 Sep 2019 14:15:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id AA05CC22011; Wed, 25 Sep 2019 14:14:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0A13CC22003; Wed, 25 Sep 2019 14:12:21 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id AAEBFC21FFD for ; Wed, 25 Sep 2019 14:12:20 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id h144so14162086iof.7 for ; Wed, 25 Sep 2019 07:12:20 -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=//nAbut82G1XgXSneVkXPwtChGzfxCFGvoWMhibV1Bs=; b=L5QUAZIY1MgCTijWf9xuW2bGd0xZZypohr/qeKeSN+A+xtWcU/bht7ePAVnW0gxahg KDNzLZRKJeD/c6EBLQmmxjhXCVUvBozhzOAGel5lHo366KSK30mrp1FkCWFKJI2PtEJg eElfzx1WkZxpm5PjCQGArhrjBNDWqVLRRVZN4= 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=//nAbut82G1XgXSneVkXPwtChGzfxCFGvoWMhibV1Bs=; b=la96qRL2xMT5ljTELkgdhZ3QBzjsPXg+SdaOeKw6rNsU9aVLCM/xR8QaaIDxsmYYdG bOHXoQT7X7IBnbhzbdUCIDrTWeLR8iEPDyEjdKyLKU89HJdtt9Q1zP3J+B19u0N2gnEg erLRFLekwgzXizbee+Fn+lInYpdlG/zXMnF2P1pjhyWl7/ENai+mvEOIvROkYK8NC39S R/fTY0pQfxPjxsIWiVtabUOsuJgosFjbcD4lIb+cyOEYnpt8CvgLKRd+md5f2bLxigfn OOmXYGGiTLlR9/BGFN8SMOUlxp+bt44MBGrwzgyWBGAK6YGqdKMIk9dNjz/hZ3JOvy5S jMPQ== X-Gm-Message-State: APjAAAWZWEKN94NkQKvMJNxmDGWMWvy9YFIEZPQycT3werKAvvfvdFHS m3JuJcciKsVgzo1i/2hHjOU02Ou3RXc= X-Google-Smtp-Source: APXvYqy2NW7x9Nv+QJWAqK8805xRV0t8VL5Z/VUZhZmrxFXihsW+ZKYj0AeO3CXE+R3NdUkZcSXg3A== X-Received: by 2002:a6b:e01a:: with SMTP id z26mr1732552iog.260.1569420739476; Wed, 25 Sep 2019 07:12:19 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id d20sm196878ilk.83.2019.09.25.07.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 07:12:19 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 25 Sep 2019 08:11:20 -0600 Message-Id: <20190925141147.191166-12-sjg@chromium.org> X-Mailer: git-send-email 2.23.0.444.g18eeb5a265-goog In-Reply-To: <20190925141147.191166-1-sjg@chromium.org> References: <20190925141147.191166-1-sjg@chromium.org> MIME-Version: 1.0 Subject: [U-Boot] [PATCH v2 11/38] spl: Add a function to determine the U-Boot phase X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" U-Boot is built in three phases: TPL, SPL and U-Boot proper. Sometimes it is necessary to use different init code depending on the phase. For example, TPL might do very basic CPU init, SPL might do a little more and U-Boot proper might bring the CPU up to full speed and enable all cores. Add a function which allows easy determination of the current phase being built. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v2: None include/spl.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/include/spl.h b/include/spl.h index 4bc35cb0e77..2869c9dc702 100644 --- a/include/spl.h +++ b/include/spl.h @@ -49,6 +49,66 @@ static inline bool u_boot_first_phase(void) return false; } +enum u_boot_phase { + PHASE_TPL, + PHASE_SPL, + PHASE_U_BOOT, +}; + +/** + * spl_phase() - Find out the phase of U-Boot + * + * This can be used to avoid #ifdef logic and use if() instead. + * + * For example, to include code only in TPL, you might do: + * + * #ifdef CONFIG_TPL_BUILD + * ... + * #endif + * + * but with this you can use: + * + * if (spl_phase() == PHASE_TPL) { + * ... + * } + * + * To include code only in SPL, you might do: + * + * #if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) + * ... + * #endif + * + * but with this you can use: + * + * if (spl_phase() == PHASE_SPL) { + * ... + * } + * + * To include code only in U-Boot proper, you might do: + * + * #ifndef CONFIG_SPL_BUILD + * ... + * #endif + * + * but with this you can use: + * + * if (spl_phase() == PHASE_U_BOOT) { + * ... + * } + * + * @return U-Boot phase + */ +static inline enum u_boot_phase spl_phase(void) +{ +#ifdef CONFIG_TPL_BUILD + return PHASE_TPL; +#elif CONFIG_SPL_BUILD + return PHASE_SPL; +#else + return PHASE_U_BOOT; +#endif +} + /* A string name for SPL or TPL */ #ifdef CONFIG_SPL_BUILD # ifdef CONFIG_TPL_BUILD