Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell: Fix shell init procedure when configured as inactive on startup #67400

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/zephyr/shell/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ struct shell_backend_ctx_flags {
uint32_t cmd_ctx :1; /*!< Shell is executing command */
uint32_t print_noinit :1; /*!< Print request from not initialized shell */
uint32_t sync_mode :1; /*!< Shell in synchronous mode */
uint32_t handle_log :1; /*!< Shell is handling logger backend */
};

BUILD_ASSERT((sizeof(struct shell_backend_ctx_flags) == sizeof(uint32_t)),
Expand Down Expand Up @@ -798,6 +799,9 @@ struct shell_ctx {
/** When bypass is set, all incoming data is passed to the callback. */
shell_bypass_cb_t bypass;

/*!< Logging level for a backend. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be:

Suggested change
/*!< Logging level for a backend. */
/** Logging level for a backend. */

Any chance you could follow up with a commit to fix this? given this is API, it's always nicer if documentation is accurate there. Thanks!

uint32_t log_level;

#if defined CONFIG_SHELL_GETOPT
/*!< getopt context for a shell backend. */
struct getopt_state getopt;
Expand Down
18 changes: 10 additions & 8 deletions subsys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,21 +1315,16 @@ void shell_thread(void *shell_handle, void *arg_log_backend,
void *arg_log_level)
{
struct shell *sh = shell_handle;
bool log_backend = (bool)arg_log_backend;
uint32_t log_level = POINTER_TO_UINT(arg_log_level);
int err;

z_flag_handle_log_set(sh, (bool)arg_log_backend);
sh->ctx->log_level = POINTER_TO_UINT(arg_log_level);

err = sh->iface->api->enable(sh->iface, false);
if (err != 0) {
return;
}

if (IS_ENABLED(CONFIG_SHELL_LOG_BACKEND) && log_backend
&& !IS_ENABLED(CONFIG_SHELL_START_OBSCURED)) {
z_shell_log_backend_enable(sh->log_backend, (void *)sh,
log_level);
}

if (IS_ENABLED(CONFIG_SHELL_AUTOSTART)) {
/* Enable shell and print prompt. */
err = shell_start(sh);
Expand Down Expand Up @@ -1430,6 +1425,11 @@ int shell_start(const struct shell *sh)
return -ENOTSUP;
}

if (IS_ENABLED(CONFIG_SHELL_LOG_BACKEND) && z_flag_handle_log_get(sh)
&& !z_flag_obscure_get(sh)) {
z_shell_log_backend_enable(sh->log_backend, (void *)sh, sh->ctx->log_level);
}

k_mutex_lock(&sh->ctx->wr_mtx, K_FOREVER);

if (IS_ENABLED(CONFIG_SHELL_VT100_COLORS)) {
Expand Down Expand Up @@ -1460,6 +1460,8 @@ int shell_stop(const struct shell *sh)

state_set(sh, SHELL_STATE_INITIALIZED);

z_shell_log_backend_disable(sh->log_backend);

return 0;
}

Expand Down
13 changes: 13 additions & 0 deletions subsys/shell/shell_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ static inline bool z_flag_sync_mode_set(const struct shell *sh, bool val)
return ret;
}

static inline bool z_flag_handle_log_get(const struct shell *sh)
{
return sh->ctx->ctx.flags.handle_log == 1;
}

static inline bool z_flag_handle_log_set(const struct shell *sh, bool val)
{
bool ret;

Z_SHELL_SET_FLAG_ATOMIC(sh, ctx, handle_log, val, ret);
return ret;
}

/* Function sends VT100 command to clear the screen from cursor position to
* end of the screen.
*/
Expand Down
Loading