diff mbox series

[3/8] sunxi: board: Simplify Pine A64 DT selection logic

Message ID 20200903050716.48488-4-samuel@sholland.org
State Changes Requested
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series PinePhone automatic device tree selection | expand

Commit Message

Samuel Holland Sept. 3, 2020, 5:07 a.m. UTC
Instead of using an entirely separate matching algorithm, simply update
the name of the DT we want to match. Enabling this logic does not depend
on the FIT config name, only on the initial guess of the board name.

Importantly, the initial guess must be "sun50i-a64-pine64-plus", because
otherwise the logic would trigger when "sun50i-a64-pine64-lts" was
written to the SPL header.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 board/sunxi/board.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Andre Przywara Sept. 22, 2020, 12:40 a.m. UTC | #1
On 03/09/2020 06:07, Samuel Holland wrote:
> Instead of using an entirely separate matching algorithm, simply update
> the name of the DT we want to match. Enabling this logic does not depend
> on the FIT config name, only on the initial guess of the board name.

Yeah, clever solution. The original code was indeed quite confusing,
partly because it tried to desperately save on code size. Turns out your
solution is much smaller now ;-)

> Importantly, the initial guess must be "sun50i-a64-pine64-plus", because
> otherwise the logic would trigger when "sun50i-a64-pine64-lts" was
> written to the SPL header.

Ah, good catch.

> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

One nit below, with that:

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

> ---
>  board/sunxi/board.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index 5c9b811f27a..fb0d5bf4743 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -914,14 +914,10 @@ int board_fit_config_name_match(const char *name)
>  		return 0;
>  	}
>  #ifdef CONFIG_PINE64_DT_SELECTION
> -/* Differentiate the two Pine64 board DTs by their DRAM size. */
> -	if (strstr(name, "-pine64") && strstr(best_dt_name, "-pine64")) {
> -		if ((gd->ram_size > 512 * 1024 * 1024))
> -			return !strstr(name, "plus");
> -		else
> -			return !!strstr(name, "plus");
> -	} else {
> -		return strcmp(name, best_dt_name);
> +	else if (strstr(best_dt_name, "-pine64-plus")) {

I think you don't need this "else" here, as the "if" part returns
already. Makes this even easier to read.

Cheers,
Andre.

> +		/* Differentiate the Pine A64 boards by their DRAM size. */
> +		if ((gd->ram_size == 512 * 1024 * 1024))
> +			best_dt_name = "sun50i-a64-pine64";
>  	}
>  #endif
>  	return strcmp(name, best_dt_name);
>
diff mbox series

Patch

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 5c9b811f27a..fb0d5bf4743 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -914,14 +914,10 @@  int board_fit_config_name_match(const char *name)
 		return 0;
 	}
 #ifdef CONFIG_PINE64_DT_SELECTION
-/* Differentiate the two Pine64 board DTs by their DRAM size. */
-	if (strstr(name, "-pine64") && strstr(best_dt_name, "-pine64")) {
-		if ((gd->ram_size > 512 * 1024 * 1024))
-			return !strstr(name, "plus");
-		else
-			return !!strstr(name, "plus");
-	} else {
-		return strcmp(name, best_dt_name);
+	else if (strstr(best_dt_name, "-pine64-plus")) {
+		/* Differentiate the Pine A64 boards by their DRAM size. */
+		if ((gd->ram_size == 512 * 1024 * 1024))
+			best_dt_name = "sun50i-a64-pine64";
 	}
 #endif
 	return strcmp(name, best_dt_name);