Skip to contentSkip to conversation

cmd: ufetch improvements

PATCH Applied J. Neuschäfer 2 participants 6 messages Dec 11, 2024 – Jan 22, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover cmd: ufetch improvements

Following the recent addition of the "ufetch" command, this patchset improves it in a few ways.

---
Changes in v2:
- Address comments and add R-b tags from Caleb
- Link to v1: https://lore.kernel.org/r/[email protected]

---
J. Neuschäfer (3):
cmd: ufetch: Fix type mismatch on 32-bit
cmd: Allow building ufetch without CONFIG_BLK
cmd: ufetch: Show CPU architecture under "CPU"

 cmd/Kconfig  |  1 -
 cmd/ufetch.c | 17 +++++++++++------
 2 files changed, 11 insertions(+), 7 deletions(-)

---
base-commit: a7efabf75cc7a31bc0c9dc8a1509a788ade238bc
change-id: 20241203-ufetch-326e771b26ad

Best regards,

Signature · 1 line
J. Neuschäfer <[email protected]>
#1 lore raw

PATCH v2 1/3 cmd: ufetch: Fix type mismatch on 32-bit

On 32-bit architectures, LAST_LINE (_LAST_LINE - 1UL) is 64 bits long, but size_t (from ARRAY_SIZE(...)) is 32 bits. This results in a warning because the max() macro expects the same type on both sides:

cmd/ufetch.c: In function ‘do_ufetch’:
include/linux/kernel.h:179:24: warning: comparison of distinct pointer types lacks a cast [-Wcompare-distinct-pointer-types]
179 | (void) (&_max1 == &_max2); \
| ^~
cmd/ufetch.c:92:25: note: in expansion of macro ‘max’
92 | int num_lines = max(LAST_LINE + 1, ARRAY_SIZE(logo_lines));
| ^~~

Fix this by casting LAST_LINE to size_t.

---

v2:
- Add Caleb's R-b

---
 cmd/ufetch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/ufetch.c +1 -1
index 0b825d7e8c75f3b18933d3e3f77e5f40f2c7b658..5f3ef847b268dc384271fc6774720e5fd2337157 100644
@@ -89,7 +89,7 @@ enum output_lines {
 static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int argc,
 		     char *const argv[])
 {
-	int num_lines = max(LAST_LINE + 1, ARRAY_SIZE(logo_lines));
+	int num_lines = max((size_t)LAST_LINE + 1, ARRAY_SIZE(logo_lines));
 	const char *model, *compatible;
 	char *ipaddr;
 	int n_cmds, n_cpus = 0, ret, compatlen;
Signature · 1 line
2.45.2
#2 lore raw

PATCH v2 2/3 cmd: Allow building ufetch without CONFIG_BLK

In reply to J. Neuschäfer

The ufetch command is still quite useful on systems without block device support; remove the CONFIG_BLK dependency and make sure the code compiles/works with and without CONFIG_BLK.

---

v2:
- Add parentheses to avoid having declarations after the "default" label.
- Add Caleb's R-b

---
 cmd/Kconfig  |  1 -
 cmd/ufetch.c | 13 +++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)
cmd/Kconfig +0 -1
index 4936a70f3ef16ddb093ceafa12d011ca1b89e95c..547fd2a91f7883e2ae5982897ec93c4483d67852 100644
@@ -178,7 +178,6 @@ config CMD_CPU
 
 config CMD_UFETCH
 	bool "U-Boot fetch"
-	depends on BLK
 	help
 	  Fetch utility for U-Boot (akin to neofetch). Prints information
 	  about U-Boot and the board it is running on in a pleasing format.
cmd/ufetch.c +9 -4
index 5f3ef847b268dc384271fc6774720e5fd2337157..83cec0f6d5c875f150f7b948392a29803bdbc201 100644
@@ -92,11 +92,9 @@ static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int argc,
 	int num_lines = max((size_t)LAST_LINE + 1, ARRAY_SIZE(logo_lines));
 	const char *model, *compatible;
 	char *ipaddr;
-	int n_cmds, n_cpus = 0, ret, compatlen;
+	int n_cmds, n_cpus = 0, compatlen;
 	size_t size;
 	ofnode np;
-	struct udevice *dev;
-	struct blk_desc *desc;
 	bool skip_ascii = false;
 
 	if (argc > 1 && strcmp(argv[1], "-n") == 0) {
@@ -199,7 +197,12 @@ static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int argc,
 			print_size(size, "\n");
 			break;
 		case STORAGE:
-		default:
+		default: {
+#ifdef CONFIG_BLK
+			struct udevice *dev;
+			struct blk_desc *desc;
+			int ret;
+
 			ret = uclass_find_device_by_seq(UCLASS_BLK, line - STORAGE, &dev);
 			if (!ret && dev) {
 				desc = dev_get_uclass_plat(dev);
@@ -213,8 +216,10 @@ static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int argc,
 			} else if (ret == -ENODEV && (skip_ascii || line > ARRAY_SIZE(logo_lines))) {
 				break;
 			}
+#endif
 			printf("\n");
 		}
+		}
 	}
 
 	printf(RESET "\n\n");
Signature · 1 line
2.45.2
#3 lore raw

PATCH v2 3/3 cmd: ufetch: Show CPU architecture under "CPU"

In reply to J. Neuschäfer

When looking at ufetch output it isn't immediately obvious which CPU architecture the presented board has. This patch therefore adds the CPU architecture string (for example "powerpc") to the "CPU:" line. The new format is:

CPU: powerpc (1 cores, 1 in use)

---

v2:
- Reformat the CPU message for readability

---
 cmd/ufetch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/ufetch.c +1 -1
index 83cec0f6d5c875f150f7b948392a29803bdbc201..ed5a856c7abbe08949b81e0b2f634edd8b390be5 100644
@@ -188,7 +188,7 @@ static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int argc,
 				if (ofnode_name_eq(np, "cpu"))
 					n_cpus++;
 			}
-			printf("CPU:" RESET " %d (1 in use)\n", n_cpus);
+			printf("CPU: " RESET CONFIG_SYS_ARCH " (%d cores, 1 in use)\n", n_cpus);
 			break;
 		case MEMORY:
 			for (int j = 0; j < CONFIG_NR_DRAM_BANKS && gd->bd->bi_dram[j].size; j++)
Signature · 1 line
2.45.2
Reviewed-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] cmd: ufetch: Show CPU architecture under "CPU"

Quoted 10 lines · On 11/12/2024 23:25, J. Neuschäfer via B4 Relay wrote:

From: "J. Neuschäfer" <[email protected]>

When looking at ufetch output it isn't immediately obvious which CPU architecture the presented board has. This patch therefore adds the CPU architecture string (for example "powerpc") to the "CPU:" line. The new format is:

CPU: powerpc (1 cores, 1 in use)

Thanks for re-spinning this!

Quoted 22 lines

---

v2:
- Reformat the CPU message for readability

---
 cmd/ufetch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/ufetch.c +1 -1
index 83cec0f6d5c875f150f7b948392a29803bdbc201..ed5a856c7abbe08949b81e0b2f634edd8b390be5 100644
@@ -188,7 +188,7 @@ static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int argc,
 				if (ofnode_name_eq(np, "cpu"))
 					n_cpus++;
 			}
-			printf("CPU:" RESET " %d (1 in use)\n", n_cpus);
+			printf("CPU: " RESET CONFIG_SYS_ARCH " (%d cores, 1 in use)\n", n_cpus);
 			break;
 		case MEMORY:
 			for (int j = 0; j < CONFIG_NR_DRAM_BANKS && gd->bd->bi_dram[j].size; j++)
Signature · 1 line
// Caleb (they/them)
#5 lore raw
In reply to J. Neuschäfer
Quoted 4 lines · J. Neuschäfer

Following the recent addition of the "ufetch" command, this patchset improves it in a few ways.

Applied, thanks!

[1/3] cmd: ufetch: Fix type mismatch on 32-bit

      https://source.denx.de/u-boot/custodians/u-boot-snapdragon/-/commit/e288366364c3
[2/3] cmd: Allow building ufetch without CONFIG_BLK
      https://source.denx.de/u-boot/custodians/u-boot-snapdragon/-/commit/c38d5bad3507
[3/3] cmd: ufetch: Show CPU architecture under "CPU"
      https://source.denx.de/u-boot/custodians/u-boot-snapdragon/-/commit/3db33a6fd690

Best regards,

Signature · 1 line
// Caleb (they/them)