git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15378 27425a3e-05d8-49a3-a47f-9c15f0e5edd8

This commit is contained in:
Giovanni Di Sirio 2022-01-20 06:20:57 +00:00
parent 916876b01f
commit e446956b6a
2 changed files with 19 additions and 7 deletions

View File

@ -25,7 +25,7 @@
#define SHELL_MAX_ARGUMENTS 20
#define SHELL_PROMPT_STR "> "
#define SHELL_NEWLINE_STR "\r\n"
#define SHELL_WELCOME_STR "ChibiOS/SB shell"
#define SHELL_WELCOME_STR "ChibiOS/SB Mini Shell"
static const char *prompt;
@ -160,7 +160,7 @@ static void cmd_exit(int argc, char *argv[]) {
return;
}
sbExit(msg);
_exit(msg);
}
static void cmd_path(int argc, char *argv[]) {
@ -181,7 +181,8 @@ static void cmd_path(int argc, char *argv[]) {
}
static bool shell_execute(int argc, char *argv[]) {
int i;
extern int runelf(const char *fname, int argc, char *argv[], char *envp[]);
int i, ret;
static const struct {
const char *name;
@ -202,6 +203,12 @@ static bool shell_execute(int argc, char *argv[]) {
i++;
}
/* Trying to execute from file.*/
ret = runelf(argv[0], argc - 1, argv + 1, environ);
if (ret != -1) {
return false;
}
return true;
}
@ -236,7 +243,7 @@ int main(int argc, char *argv[], char *envp[]) {
/* Reading input line.*/
if (shell_getline(line, SHELL_MAX_LINE_LENGTH)) {
shell_write(SHELL_NEWLINE_STR);
shell_write("logout");
shell_write("logout" SHELL_NEWLINE_STR);
break;
}

View File

@ -23,6 +23,8 @@
extern int __callelf(sb_header_t *sbhp, int argc, char *argv[], char *envp[]);
extern int __returnelf(void);
static char buf[1024];
int runelf(const char *fname, int argc, char *argv[], char *envp[]) {
uint8_t *buf, *bufend;
sb_header_t *sbhp;
@ -35,13 +37,15 @@ int runelf(const char *fname, int argc, char *argv[], char *envp[]) {
/* Aligning the start address.*/
buf = (uint8_t *)((((uint32_t)buf - 1U) | 3U) + 1U);
if (buf >= bufend) {
return ENOMEM;
errno = ENOMEM;
return -1;
}
/* Loading the specified file.*/
ret = sbLoadElf(fname, buf, (size_t)(bufend - buf));
if (CH_RET_IS_ERROR(ret)) {
return CH_DECODE_ERROR(ret);
errno = CH_DECODE_ERROR(ret);
return -1;
}
/* Pointer to the executable header.*/
@ -51,7 +55,8 @@ int runelf(const char *fname, int argc, char *argv[], char *envp[]) {
if ((sbhp->hdr_magic1 != SB_HDR_MAGIC1) ||
(sbhp->hdr_magic2 != SB_HDR_MAGIC2) ||
(sbhp->hdr_size != sizeof (sb_header_t))) {
return ENOEXEC;
errno = ENOEXEC;
return -1;
}
/* Setting up the exit vector for the loaded elf file.*/