From 6d415de83fe084c08558895837d0eb90210420a9 Mon Sep 17 00:00:00 2001
From: Salman Nabi <salman.nabi@arm.com>
Date: Thu, 7 Mar 2024 14:08:03 +0000
Subject: [PATCH] refactor(bl32): flush before console switch state

Move console_switch_state(CONSOLE_FLAG_RUNTIME) to sp_min_main() so
that this becomes the last call before bl32/sp_min exits. This also
ensures that console_flush() is called before switching console state
to runtime.

This patch mimics the behavior of console_switch_state() call in BL31
per this patch
https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/26771/4.

Change-Id: I5b562d02706b19bb8b14154be97b6e9ef4e2fd3b
Signed-off-by: Salman Nabi <salman.nabi@arm.com>
---
 bl32/sp_min/sp_min_main.c                | 1 +
 plat/common/aarch32/plat_sp_min_common.c | 7 +------
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/bl32/sp_min/sp_min_main.c b/bl32/sp_min/sp_min_main.c
index a26910cb2..a85b35515 100644
--- a/bl32/sp_min/sp_min_main.c
+++ b/bl32/sp_min/sp_min_main.c
@@ -213,6 +213,7 @@ void sp_min_main(void)
 	sp_min_plat_runtime_setup();
 
 	console_flush();
+	console_switch_state(CONSOLE_FLAG_RUNTIME);
 }
 
 /******************************************************************************
diff --git a/plat/common/aarch32/plat_sp_min_common.c b/plat/common/aarch32/plat_sp_min_common.c
index 949358738..8e96b9684 100644
--- a/plat/common/aarch32/plat_sp_min_common.c
+++ b/plat/common/aarch32/plat_sp_min_common.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -17,9 +17,4 @@
 
 void sp_min_plat_runtime_setup(void)
 {
-	/*
-	 * Finish the use of console driver in SP_MIN so that any runtime logs
-	 * from SP_MIN will be suppressed.
-	 */
-	console_switch_state(CONSOLE_FLAG_RUNTIME);
 }