diff --git a/subsys/shell/modules/device_service.c b/subsys/shell/modules/device_service.c index 5334c7359c6..3db6a0c7018 100644 --- a/subsys/shell/modules/device_service.c +++ b/subsys/shell/modules/device_service.c @@ -8,9 +8,9 @@ #include #include #include -#include #include +extern const struct device __device_start[]; extern const struct device __device_PRE_KERNEL_1_start[]; extern const struct device __device_PRE_KERNEL_2_start[]; extern const struct device __device_POST_KERNEL_start[]; @@ -82,62 +82,33 @@ static int cmd_device_levels(const struct shell *shell, 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; - } - - return name; -} - static int cmd_device_list(const struct shell *shell, size_t argc, char **argv) { - const struct device *devlist; - size_t devcnt = z_device_get_all_static(&devlist); - const struct device *devlist_end = devlist + devcnt; const struct device *dev; ARG_UNUSED(argc); ARG_UNUSED(argv); shell_fprintf(shell, SHELL_NORMAL, "devices:\n"); - for (dev = devlist; dev < devlist_end; dev++) { - char buf[20]; - const char *name = get_device_name(dev, buf, sizeof(buf)); - const char *state = "READY"; - size_t nhdls = 0; - const device_handle_t *hdls = - device_get_requires_handles(dev, &nhdls); - - shell_fprintf(shell, SHELL_NORMAL, "- %s", name); + for (dev = __device_start; dev != __device_end; dev++) { if (!device_is_ready(dev)) { - state = "DISABLED"; - } else { + continue; + } + + shell_fprintf(shell, SHELL_NORMAL, "- %s", dev->name); + #ifdef CONFIG_PM_DEVICE - uint32_t st = DEVICE_PM_ACTIVE_STATE; - int err = device_get_power_state(dev, &st); + uint32_t state = DEVICE_PM_ACTIVE_STATE; + int err; - if (!err) { - state = device_pm_state_str(st); - } + err = device_get_power_state(dev, &state); + if (!err) { + shell_fprintf(shell, SHELL_NORMAL, " (%s)", + device_pm_state_str(state)); + } #endif /* CONFIG_PM_DEVICE */ - } - - shell_fprintf(shell, SHELL_NORMAL, " (%s)\n", state); - for (size_t di = 0; di < nhdls; ++di) { - device_handle_t dh = hdls[di]; - const struct device *rdp = device_from_handle(dh); - - shell_fprintf(shell, SHELL_NORMAL, " requires: %s\n", - get_device_name(rdp, buf, sizeof(buf))); - } + shell_fprintf(shell, SHELL_NORMAL, "\n"); } return 0;