From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Fri, 30 Apr 2021 15:31:20 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1lcTEm-0004y2-Ku for lore@lore.pengutronix.de; Fri, 30 Apr 2021 15:31:20 +0200 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lcTEk-0006p0-T9 for lore@pengutronix.de; Fri, 30 Apr 2021 15:31:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=P9tPPWsQCTjB5IFOwxvzXpvgUu8zOP0EwebsTe0eajs=; b=aSY/dXOvdTvB2EWEL+1m5eDDI P8FvvEDeQHBj6DeZHMBKHW3Y1evjaNnus0hOxvDBuwmMBmOFiUtpQDTBm5RR8jAH3XiJTJbxWd5nT GWY1MBDv1vuJgOGddzmKSaTtZ0RXmKCmc7i+XWE6tLOSdakEF60F0FxMY+mB56nxImH1clfnNzwJL xDofr8Lfoq7P2CoFE6NW+Sa445V9F1ZzW189SHvEuzgKvV/wsGCWdVjISZBWfiTWFw7yqY+xnMi1G 0X8BdVzCOzDqM5HjwBzpotln3qNphL04Su8X5MARX4Uv2/fyeTy2tvgjbGSfLMoa1mPmNMCWGKl/T FHyh6VXAw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lcTDp-007ubP-Sw; Fri, 30 Apr 2021 13:30:23 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lcTDW-007uYS-8I for barebox@desiato.infradead.org; Fri, 30 Apr 2021 13:30:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=1LVwQEvbLMdTVVQIchsX8Mly1t7eiSmxihbNb6TFKhs=; b=V8fEWRuHBhLN0Xp3RyyDkqCAgm w/vvJQF2kA2k5Hr88G+2HOys7KMXYzduN092VbUV5puRkE0+IPU5o/8AMjgkr500663WQbWis/2fR MAW9VsONAkNwUz7+V+d+57wIXlDJt0L6fbQspR9Vhq5Ia02dKcfictg9xti+rUCbND1gYffRwaBb+ Uy9fWE943JkBItYTaS52qCdjMq9ch1m3BGs8yGDriMX24H3cg+qL7mhbgmkQPf19XdcpJgppzI5Za iOnWvzlv4y4cJ09Xfa8MQD5D4ep2J78gkGJ0Y5JScNZvUet7uPg9UBtcanl0YDjXljLDtZthqZiYr iSsQpZJQ==; Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lcTDS-001PHO-B6 for barebox@lists.infradead.org; Fri, 30 Apr 2021 13:30:01 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lcTDN-00069m-IN; Fri, 30 Apr 2021 15:29:53 +0200 Received: from afa by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lcTDN-0003qV-0K; Fri, 30 Apr 2021 15:29:53 +0200 From: Ahmad Fatoum To: barebox@lists.infradead.org Cc: Ahmad Fatoum Date: Fri, 30 Apr 2021 15:29:35 +0200 Message-Id: <20210430132949.14617-2-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210430132949.14617-1-a.fatoum@pengutronix.de> References: <20210430132949.14617-1-a.fatoum@pengutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210430_062958_436786_45CE563C X-CRM114-Status: GOOD ( 15.76 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" X-SA-Exim-Connect-IP: 2001:8b0:10b:1:d65d:64ff:fe57:4e05 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.ext.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-3.4 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH v2 01/15] show_progress: add system wide progress stage notifier X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.ext.pengutronix.de) Use case is e.g. board code that wants to register a client to light status LEDs to indicate system state when no serial output is available. This functionality doesn't increase code size due to linker GC when CONFIG_PROGRESS_NOTIFIER is disabled. There is a generic progress notifier provided that just logs the status. This could be shared with the booted kernel via pstore or the log as a whole written to a system setup USB drive. Signed-off-by: Ahmad Fatoum --- include/progress.h | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 6 ++++++ lib/show_progress.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/include/progress.h b/include/progress.h index 50b15fb12b4c..7230bd3a9bd5 100644 --- a/include/progress.h +++ b/include/progress.h @@ -3,6 +3,8 @@ #define __PROGRSS_H #include +#include +#include /* Initialize a progress bar. If max > 0 a one line progress * bar is printed where 'max' corresponds to 100%. If max == 0 @@ -15,4 +17,45 @@ void init_progression_bar(loff_t max); */ void show_progress(loff_t now); +extern struct notifier_head progress_notifier; + +enum progress_stage { + PROGRESS_UNSPECIFIED = 0, + PROGRESS_UPDATING, + PROGRESS_UPDATE_SUCCESS, + PROGRESS_UPDATE_FAIL, +}; + +/* + * Notifier list for code which wants to be called at progress + * This could use by board code to e.g. flash a LED during updates + */ +extern struct notifier_head progress_notifier_list; + +/* generic client that just logs the state */ +extern struct notifier_block progress_log_client; + +static inline int progress_register_client(struct notifier_block *nb) +{ + if (!IS_ENABLED(CONFIG_PROGRESS_NOTIFIER)) + return -ENOSYS; + return notifier_chain_register(&progress_notifier_list, nb); +} + +static inline int progress_unregister_client(struct notifier_block *nb) +{ + if (!IS_ENABLED(CONFIG_PROGRESS_NOTIFIER)) + return -ENOSYS; + return notifier_chain_unregister(&progress_notifier_list, nb); +} + +static inline int progress_notifier_call_chain(enum progress_stage stage, const char *prefix) +{ + if (!IS_ENABLED(CONFIG_PROGRESS_NOTIFIER)) + return -ENOSYS; + + /* clients should not modify the prefix */ + return notifier_call_chain(&progress_notifier_list, stage, (char *)(prefix ?: "")); +} + #endif /* __PROGRSS_H */ diff --git a/lib/Kconfig b/lib/Kconfig index e5831ecdb9a7..922710e106b3 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -154,6 +154,12 @@ source "lib/logo/Kconfig" source "lib/bootstrap/Kconfig" +config PROGRESS_NOTIFIER + bool + help + This is selected by boards that register a notifier to visualize + progress, like blinking a LED during an update. + config PRINTF_UUID bool diff --git a/lib/show_progress.c b/lib/show_progress.c index 1be06ea7806e..1b624bcb9af8 100644 --- a/lib/show_progress.c +++ b/lib/show_progress.c @@ -57,3 +57,31 @@ void init_progression_bar(loff_t max) else printf("\t"); } + +NOTIFIER_HEAD(progress_notifier_list); + +static int progress_logger(struct notifier_block *r, unsigned long stage, void *_prefix) +{ + const char *prefix = _prefix; + + switch ((enum progress_stage)stage) { + case PROGRESS_UPDATING: + pr_info("%sSoftware update in progress\n", prefix); + break; + case PROGRESS_UPDATE_SUCCESS: + pr_info("%sSoftware update finished successfully\n", prefix); + break; + case PROGRESS_UPDATE_FAIL: + pr_info("%sSoftware update failed\n", prefix); + break; + case PROGRESS_UNSPECIFIED: + /* default state. This should not be reached */ + break; + } + + return 0; +} + +struct notifier_block progress_log_client = { + .notifier_call = progress_logger +}; -- 2.29.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox