Skip to content

Commit

Permalink
shell: device_service: refine level output
Browse files Browse the repository at this point in the history
Fix the order so that it reflects the actual initialization order,
rather than putting PRE_KERNEL initializations after APPLICATION.

Add SMP in the proper location.

Use the helper function to provide unique identifiers for "devices"
that don't have a device pointer (so don't have a name).

Signed-off-by: Peter Bigot <[email protected]>
  • Loading branch information
pabigot authored and nashif committed Feb 19, 2021
1 parent f0df72c commit 1fa3447
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions subsys/shell/modules/device_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,32 @@ static const struct device *levels[] = {
__device_end,
};

static const char *get_device_name(const struct device *dev,
char *buf,
size_t len)
{
const char *name = dev->name;

if ((name == NULL) || (name[0] == 0)) {
snprintf(buf, len, "[%p]", dev);
name = buf;
}

return name;
}

static bool device_get_config_level(const struct shell *shell, int level)
{
const struct device *dev;
bool devices = false;
char buf[20];

for (dev = levels[level]; dev < levels[level+1]; dev++) {
if (device_is_ready(dev)) {
devices = true;

shell_fprintf(shell, SHELL_NORMAL, "- %s\n", dev->name);
shell_fprintf(shell, SHELL_NORMAL, "- %s\n",
get_device_name(dev, buf, sizeof(buf)));
}
}
return devices;
Expand All @@ -55,45 +71,39 @@ static int cmd_device_levels(const struct shell *shell,
ARG_UNUSED(argv);
bool ret;

shell_fprintf(shell, SHELL_NORMAL, "POST_KERNEL:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_POST_KERNEL);
shell_fprintf(shell, SHELL_NORMAL, "PRE KERNEL 1:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_PRE_KERNEL_1);
if (ret == false) {
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
}

shell_fprintf(shell, SHELL_NORMAL, "APPLICATION:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_APPLICATION);
shell_fprintf(shell, SHELL_NORMAL, "PRE KERNEL 2:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_PRE_KERNEL_2);
if (ret == false) {
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
}

shell_fprintf(shell, SHELL_NORMAL, "PRE KERNEL 1:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_PRE_KERNEL_1);
shell_fprintf(shell, SHELL_NORMAL, "POST_KERNEL:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_POST_KERNEL);
if (ret == false) {
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
}

shell_fprintf(shell, SHELL_NORMAL, "PRE KERNEL 2:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_PRE_KERNEL_2);
shell_fprintf(shell, SHELL_NORMAL, "APPLICATION:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_APPLICATION);
if (ret == false) {
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
}

return 0;
}

static const char *get_device_name(const struct device *dev,
char *buf,
size_t len)
{
const char *name = dev->name;

if ((name == NULL) || (name[0] == 0)) {
snprintf(buf, len, "[%p]", dev);
name = buf;
#ifdef CONFIG_SMP
shell_fprintf(shell, SHELL_NORMAL, "SMP:\n");
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_SMP);
if (ret == false) {
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
}
#endif /* CONFIG_SMP */

return name;
return 0;
}

static int cmd_device_list(const struct shell *shell,
Expand Down

0 comments on commit 1fa3447

Please sign in to comment.