From 22c2c17915ba3f18d958bbf2c2f2c7facf2194cf Mon Sep 17 00:00:00 2001 From: Álvaro Fernández Rojas Date: Tue, 25 Apr 2017 00:39:13 +0200 Subject: cmd: cpu: fix NULL cpu feature prints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 740d5d3 added two new features but only one feature name, which results in NULL prints when device_id feature is selected. Before: HG556a # cpu detail -1: cpu@0 BCM6358A1 ID = 0, freq = 300 MHz: L1 cache, MMU, NULL Device ID 0x2a010 -1: cpu@1 BCM6358A1 ID = 1, freq = 300 MHz: L1 cache, MMU, NULL Device ID 0x2a010 After: HG556a # cpu detail -1: cpu@0 BCM6358A1 ID = 0, freq = 300 MHz: L1 cache, MMU, Device ID Device ID 0x2a010 -1: cpu@1 BCM6358A1 ID = 1, freq = 300 MHz: L1 cache, MMU, Device ID Device ID 0x2a010 Signed-off-by: Álvaro Fernández Rojas Reviewed-by: Simon Glass Reviewed-by: Tom Rini --- cmd/cpu.c | 1 + 1 file changed, 1 insertion(+) (limited to 'cmd') diff --git a/cmd/cpu.c b/cmd/cpu.c index bc4dc5c529b..adfd54a5799 100644 --- a/cmd/cpu.c +++ b/cmd/cpu.c @@ -15,6 +15,7 @@ static const char *cpu_feature_name[CPU_FEAT_COUNT] = { "L1 cache", "MMU", "Microcode", + "Device ID", }; static int print_cpu_list(bool detail) -- cgit v1.3.1 From 320eca5cf77ebab347adab4f9bbdb5417b2da81d Mon Sep 17 00:00:00 2001 From: Álvaro Fernández Rojas Date: Tue, 25 Apr 2017 00:39:17 +0200 Subject: cmd: cpu: refactor to ensure devices are probed and improve code style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use uclass_first_device and uclass_next_device in order to avoid exceptions for drivers that aren't probed when cpu ops are requested. Improve code style and fix indentations. Fix incorrect line break when cpu info is not available. Remove unneeded brackets. Signed-off-by: Álvaro Fernández Rojas Reviewed-by: Simon Glass --- cmd/cpu.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'cmd') diff --git a/cmd/cpu.c b/cmd/cpu.c index adfd54a5799..6213c720cbf 100644 --- a/cmd/cpu.c +++ b/cmd/cpu.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2015 Google, Inc * Written by Simon Glass + * Copyright (c) 2017 Álvaro Fernández Rojas * * SPDX-License-Identifier: GPL-2.0+ */ @@ -21,20 +22,15 @@ static const char *cpu_feature_name[CPU_FEAT_COUNT] = { static int print_cpu_list(bool detail) { struct udevice *dev; - struct uclass *uc; char buf[100]; - int ret; - ret = uclass_get(UCLASS_CPU, &uc); - if (ret) { - printf("Cannot find CPU uclass\n"); - return ret; - } - uclass_foreach_dev(dev, uc) { + for (uclass_first_device(UCLASS_CPU, &dev); + dev; + uclass_next_device(&dev)) { struct cpu_platdata *plat = dev_get_parent_platdata(dev); struct cpu_info info; - bool first; - int i; + bool first = true; + int ret, i; ret = cpu_get_desc(dev, buf, sizeof(buf)); printf("%3d: %-10s %s\n", dev->seq, dev->name, @@ -45,13 +41,12 @@ static int print_cpu_list(bool detail) if (ret) { printf("\t(no detail available"); if (ret != -ENOSYS) - printf(": err=%d\n", ret); + printf(": err=%d", ret); printf(")\n"); continue; } printf("\tID = %d, freq = ", plat->cpu_id); print_freq(info.cpu_freq, ""); - first = true; for (i = 0; i < CPU_FEAT_COUNT; i++) { if (info.features & (1 << i)) { printf("%s%s", first ? ": " : ", ", @@ -60,10 +55,9 @@ static int print_cpu_list(bool detail) } } printf("\n"); - if (info.features & (1 << CPU_FEAT_UCODE)) { + if (info.features & (1 << CPU_FEAT_UCODE)) printf("\tMicrocode version %#x\n", plat->ucode_version); - } if (info.features & (1 << CPU_FEAT_DEVICE_ID)) printf("\tDevice ID %#lx\n", plat->device_id); } @@ -71,7 +65,8 @@ static int print_cpu_list(bool detail) return 0; } -static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) { if (print_cpu_list(false)) return CMD_RET_FAILURE; @@ -97,7 +92,7 @@ static cmd_tbl_t cmd_cpu_sub[] = { * Process a cpu sub-command */ static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) + char * const argv[]) { cmd_tbl_t *c = NULL; @@ -106,7 +101,8 @@ static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc, argv++; if (argc) - c = find_cmd_tbl(argv[0], cmd_cpu_sub, ARRAY_SIZE(cmd_cpu_sub)); + c = find_cmd_tbl(argv[0], cmd_cpu_sub, + ARRAY_SIZE(cmd_cpu_sub)); if (c) return c->cmd(cmdtp, flag, argc, argv); -- cgit v1.3.1