提交 41c7689d 编写于 作者: G Guangyao Ma 提交者: YOUR_NAME

feat: introduce mksh toybox to rootfs

Change-Id: I0a6e6f2962ca6904c858898eb93a5b2f93e85b69
上级 34f35524
......@@ -27,7 +27,10 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include ../.config
LITEOSTOPDIR = $(shell pwd)/../
include $(LITEOSTOPDIR)/.config
include ./config.mk
include ./module.mk
HIDE := @
......
......@@ -55,6 +55,6 @@ COMMON_INCLUDE := -I $(LITEOSTHIRDPARTY)/bounds_checking_function/include
# alias variable config
HIDE := @
MAKE := make
RM := -rm -rf
CP := -cp -rf
MV := -mv
RM := rm -rf
CP := cp -rf
MV := mv -f
......@@ -49,7 +49,7 @@
int main(int argc, char * const *argv)
{
int ret;
const char *shellPath = "/bin/shell";
const char *shellPath = "/bin/mksh";
#ifdef LOSCFG_QUICK_START
const char *samplePath = "/dev/shm/sample_quickstart";
......@@ -74,6 +74,11 @@ int main(int argc, char * const *argv)
if (ret < 0) {
printf("Failed to fork for shell\n");
} else if (ret == 0) {
ret = tcsetpgrp(STDIN_FILENO, getpgrp());
if (ret != 0) {
printf("tcsetpgrp failed, pgrpid %d, errno %d\n", getpgrp(), errno);
exit(0);
}
(void)execve(shellPath, NULL, NULL);
exit(0);
}
......
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MKSH := mksh
MKSH_DIR := $(shell pwd)/
LITEOSTOPDIR = $(MKSH_DIR)/../../
include $(MKSH_DIR)/../config.mk
APPS_OUT := $(OUT)/bin
BUILD_DIR := $(MKSH_DIR)/build
BUILD_LOG := $(MKSH_DIR)/build.log
TARGET_OS := OpenHarmony
LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4
LOCAL_CFLAGS += --target=arm-liteos --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
LOCAL_CFLAGS += -DMKSH_DISABLE_TTY_WARNING -DMKSH_SMALL=1 -DMKSH_ASSUME_UTF8=1 -DMKSH_SMALL_BUT_FAST=0 -DMKSH_S_NOVI=1 -DHAVE_CAN_FSTACKPROTECTORSTRONG=1
LOCAL_CFLAGS += -DMKSH_LESS_CMDLINE_EDITING -DMKSH_LESS_BUILDINS -DMKSH_NO_INITCOMS -DADAPT_FOR_LITEOS_A
all:$(MKSH)
$(MKSH):
ifneq ($(wildcard $(BUILD_DIR)),)
$(HIDE)echo "not clean, rebuilding now"
$(HIDE)chmod +x $(BUILD_DIR)/Rebuild.sh
$(HIDE)cd $(BUILD_DIR) && ./Rebuild.sh > $(BUILD_LOG) 2>&1
else
$(HIDE)mkdir $(BUILD_DIR)
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(MKSH)/. $(BUILD_DIR)
$(HIDE)chmod +x $(BUILD_DIR)/Build.sh
$(HIDE)cd $(BUILD_DIR) && CC=$(CC) TARGET_OS=$(TARGET_OS) CFLAGS="$(LOCAL_CFLAGS)" LDFLAGS="$(LDFLAGS)" ./Build.sh -r > $(BUILD_LOG) 2>&1
endif
$(HIDE)$(CP) -rf $(BUILD_DIR)/$(MKSH) .
$(HIDE)$(STRIP) $(MKSH)
$(HIDE)mkdir -p $(APPS_OUT)
$(HIDE)$(CP) $(MKSH) $(APPS_OUT)
clean:
$(HIDE)$(RM) $(MKSH) $(BUILD_DIR) $(BUILD_LOG)
.PHONY: all $(MKSH) clean
......@@ -29,7 +29,7 @@
APP_SUBDIRS :=
##compile modules config##
##build modules config##
ifeq ($(LOSCFG_SHELL), y)
APP_SUBDIRS += shell
......@@ -42,3 +42,9 @@ endif
ifeq ($(LOSCFG_NET_LWIP_SACK_TFTP), y)
APP_SUBDIRS += tftp
endif
#only enable for qemu now
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
APP_SUBDIRS += mksh
APP_SUBDIRS += toybox
endif
......@@ -345,6 +345,11 @@ static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len
exit(1);
}
ret = tcsetpgrp(STDIN_FILENO, getpgrp());
if (ret != 0) {
printf("tcsetpgrp failed, pgrpid %d, errno %d\n", getpgrp(), errno);
}
ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL);
if (ret == -1) {
perror("execve");
......
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TOYBOX:= toybox
TOYBOX_DIR := $(shell pwd)
LITEOSTOPDIR = $(TOYBOX_DIR)/../../
include $(TOYBOX_DIR)/../config.mk
APPS_OUT := $(OUT)/bin
BUILD_DIR := $(TOYBOX_DIR)/build
BUILD_LOG := $(TOYBOX_DIR)/build.log
OUTNAME := $(TOYBOX)
$(TOYBOX):
ifneq ($(wildcard $(BUILD_DIR)),)
$(HIDE)echo "not clean, rebuilding now";
else
$(HIDE)mkdir $(BUILD_DIR)
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(TOYBOX)/. $(BUILD_DIR)
endif
$(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=arm-liteos \
--sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/" CC="$(CC)" OUTNAME=$(OUTNAME) \
make -C $(BUILD_DIR) toybox -j> $(BUILD_LOG) 2>&1
$(HIDE)$(CP) $(BUILD_DIR)/$(TOYBOX) .
$(HIDE)$(STRIP) $(TOYBOX)
$(HIDE)mkdir -p $(APPS_OUT)
$(HIDE)$(CP) $(TOYBOX) $(APPS_OUT)
clean:
$(HIDE)$(RM) $(TOYBOX) $(BUILD_DIR) $(BUILD_LOG)
.PHONY: all $(TOYBOX) clean
......@@ -111,14 +111,7 @@ INT32 ConsoleTcGetAttr(INT32 fd, struct termios *termios)
struct file *filep = NULL;
CONSOLE_CB *consoleCB = NULL;
if ((fd >= STDIN_FILENO) && (fd <= STDERR_FILENO)) {
fd = ConsoleUpdateFd();
if (fd < STDIN_FILENO) {
return -EBADF;
}
}
int ret = fs_getfilep(fd, &filep);
INT32 ret = fs_getfilep(fd, &filep);
if (ret < 0) {
return -EPERM;
}
......@@ -128,7 +121,7 @@ INT32 ConsoleTcGetAttr(INT32 fd, struct termios *termios)
return -EFAULT;
}
termios->c_lflag = consoleCB->consoleTermios.c_lflag;
(VOID)memcpy_s(termios, sizeof(struct termios), &consoleCB->consoleTermios, sizeof(struct termios));
return LOS_OK;
}
......@@ -138,14 +131,8 @@ INT32 ConsoleTcSetAttr(INT32 fd, INT32 actions, const struct termios *termios)
CONSOLE_CB *consoleCB = NULL;
(VOID)actions;
if ((fd >= STDIN_FILENO) && (fd <= STDERR_FILENO)) {
fd = ConsoleUpdateFd();
if (fd < STDIN_FILENO) {
return -EBADF;
}
}
int ret = fs_getfilep(fd, &filep);
INT32 ret = fs_getfilep(fd, &filep);
if (ret < 0) {
return -EPERM;
}
......@@ -154,7 +141,8 @@ INT32 ConsoleTcSetAttr(INT32 fd, INT32 actions, const struct termios *termios)
if (consoleCB == NULL) {
return -EFAULT;
}
consoleCB->consoleTermios.c_lflag = termios->c_lflag;
(VOID)memcpy_s(&consoleCB->consoleTermios, sizeof(struct termios), termios, sizeof(struct termios));
return LOS_OK;
}
......@@ -183,14 +171,13 @@ BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB)
STATIC INT32 ConsoleCtrlCaptureLine(CONSOLE_CB *consoleCB)
{
struct termios *consoleTermios = NULL;
struct termios consoleTermios;
UINT32 intSave;
LOS_SpinLockSave(&g_consoleSpin, &intSave);
consoleTermios = &consoleCB->consoleTermios;
(VOID)ConsoleTcGetAttr(consoleCB->fd, consoleTermios);
consoleTermios->c_lflag |= ICANON | ECHO;
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, consoleTermios);
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
consoleTermios.c_lflag |= ICANON | ECHO;
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
return LOS_OK;
......@@ -198,14 +185,13 @@ STATIC INT32 ConsoleCtrlCaptureLine(CONSOLE_CB *consoleCB)
STATIC INT32 ConsoleCtrlCaptureChar(CONSOLE_CB *consoleCB)
{
struct termios *consoleTermios = NULL;
struct termios consoleTermios;
UINT32 intSave;
LOS_SpinLockSave(&g_consoleSpin, &intSave);
consoleTermios = &consoleCB->consoleTermios;
(VOID)ConsoleTcGetAttr(consoleCB->fd, consoleTermios);
consoleTermios->c_lflag &= ~(ICANON | ECHO);
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, consoleTermios);
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
consoleTermios.c_lflag &= ~(ICANON | ECHO);
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
return LOS_OK;
......@@ -451,6 +437,20 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
}
}
VOID KillPgrp()
{
INT32 consoleId = -1;
LosProcessCB *process = OsCurrProcessGet();
if ((process->consoleID > CONSOLE_NUM -1 ) || (process->consoleID < 0)) {
return;
}
consoleId = process->consoleID;
CONSOLE_CB *consoleCB = g_console[consoleId];
(VOID)OsKillLock(consoleCB->pgrpId, SIGINT);
}
STATIC INT32 UserFilepRead(CONSOLE_CB *consoleCB, struct file *filep, const struct file_operations_vfs *fops,
CHAR *buffer, size_t bufLen)
{
......@@ -829,6 +829,75 @@ ERROUT:
return VFS_ERROR;
}
STATIC INT32 ConsoleSetSW(CONSOLE_CB *consoleCB, unsigned long arg)
{
struct termios kerTermios;
UINT32 intSave;
if (LOS_ArchCopyFromUser(&kerTermios, (struct termios *)arg, sizeof(struct termios)) != 0) {
return -EFAULT;
}
LOS_SpinLockSave(&g_consoleSpin, &intSave);
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &kerTermios);
LOS_SpinUnlockRestore(&g_consoleSpin, intSave);
return LOS_OK;
}
#define DEFAULT_WINDOW_SIZE_COL 80
#define DEFAULT_WINDOW_SIZE_ROW 24
STATIC INT32 ConsoleGetWinSize(unsigned long arg)
{
struct winsize kws = {
.ws_col = DEFAULT_WINDOW_SIZE_COL,
.ws_row = DEFAULT_WINDOW_SIZE_ROW
};
if(LOS_ArchCopyToUser((VOID *)arg, &kws, sizeof(struct winsize)) != 0) {
return -EFAULT;
} else {
return LOS_OK;
}
}
STATIC INT32 ConsoleGetTermios(unsigned long arg)
{
struct file *filep = NULL;
CONSOLE_CB *consoleCB = NULL;
INT32 ret = fs_getfilep(0, &filep);
if (ret < 0) {
return -EPERM;
}
consoleCB = (CONSOLE_CB *)filep->f_priv;
if (consoleCB == NULL) {
return -EFAULT;
}
if(LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) {
return -EFAULT;
} else {
return LOS_OK;
}
}
INT32 ConsoleSetPgrp(CONSOLE_CB *consoleCB, unsigned long arg)
{
if (LOS_ArchCopyFromUser(&consoleCB->pgrpId, (INT32 *)(UINTPTR)arg, sizeof(INT32)) != 0) {
return -EFAULT;
}
return LOS_OK;
}
INT32 ConsoleGetPgrp(CONSOLE_CB *consoleCB, unsigned long arg)
{
if (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->pgrpId, sizeof(INT32)) != 0) {
return -EFAULT;
}
return LOS_OK;
}
STATIC INT32 ConsoleIoctl(struct file *filep, INT32 cmd, unsigned long arg)
{
INT32 ret;
......@@ -869,6 +938,21 @@ STATIC INT32 ConsoleIoctl(struct file *filep, INT32 cmd, unsigned long arg)
case CONSOLE_CONTROL_REG_USERTASK:
ret = ConsoleTaskReg(consoleCB->consoleID, arg);
break;
case TIOCGWINSZ:
ret = ConsoleGetWinSize(arg);
break;
case TCSETSW:
ret = ConsoleSetSW(consoleCB, arg);
break;
case TCGETS:
ret = ConsoleGetTermios(arg);
break;
case TIOCGPGRP:
ret = ConsoleGetPgrp(consoleCB, arg);
break;
case TIOCSPGRP:
ret = ConsoleSetPgrp(consoleCB, arg);
break;
default:
if ((cmd == UART_CFG_ATTR || cmd == UART_CFG_PRIVATE)
&& !LOS_IsUserAddress(arg)) {
......@@ -940,6 +1024,7 @@ STATIC VOID OsConsoleTermiosInit(CONSOLE_CB *consoleCB, const CHAR *deviceName)
/* set console to have a buffer for user */
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
consoleTermios.c_lflag |= ICANON | ECHO;
consoleTermios.c_cc[VINTR] = 3; /* /003 for ^C */
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
}
#ifdef LOSCFG_NET_TELNET
......@@ -950,6 +1035,7 @@ STATIC VOID OsConsoleTermiosInit(CONSOLE_CB *consoleCB, const CHAR *deviceName)
/* set console to have a buffer for user */
(VOID)ConsoleTcGetAttr(consoleCB->fd, &consoleTermios);
consoleTermios.c_lflag |= ICANON | ECHO;
consoleTermios.c_cc[VINTR] = 3; /* /003 for ^C */
(VOID)ConsoleTcSetAttr(consoleCB->fd, 0, &consoleTermios);
}
#endif
......@@ -1157,6 +1243,7 @@ STATIC CONSOLE_CB *OsConsoleCBInit(UINT32 consoleID)
(VOID)memset_s(consoleCB, sizeof(CONSOLE_CB), 0, sizeof(CONSOLE_CB));
consoleCB->consoleID = consoleID;
consoleCB->pgrpId = -1;
consoleCB->shellEntryId = SHELL_ENTRYID_INVALID; /* initialize shellEntryId to an invalid value */
consoleCB->name = LOS_MemAlloc((VOID *)m_aucSysMem0, CONSOLE_NAMELEN);
if (consoleCB->name == NULL) {
......
......@@ -80,7 +80,6 @@ typedef struct {
UINT32 consoleID;
UINT32 consoleType;
UINT32 consoleSem;
UINT32 shellEntryId;
UINT32 consoleMask;
struct Vnode *devVnode;
CHAR *name;
......@@ -88,7 +87,9 @@ typedef struct {
UINT32 refCount;
BOOL isNonBlock;
#ifdef LOSCFG_SHELL
UINT32 shellEntryId;
VOID *shellHandle;
INT32 pgrpId;
#endif
UINT32 sendTaskID;
CirBufSendCB *cirBufSendCB;
......@@ -123,6 +124,7 @@ extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, cons
extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID);
extern VOID OsWakeConsoleSendTask(VOID);
#endif
extern VOID KillPgrp(VOID);
/* console ioctl */
#define CONSOLE_IOC_MAGIC 'c'
......
......@@ -30,13 +30,13 @@
*/
#include "los_magickey.h"
#include "console.h"
#include "los_task_pri.h"
#ifdef LOSCFG_ENABLE_MAGICKEY
#define MAGIC_KEY_NUM 5
STATIC VOID OsMagicHelp(VOID);
STATIC VOID OsMagicTaskShow(VOID);
STATIC VOID OsMagicPanic(VOID);
......@@ -66,6 +66,12 @@ STATIC MagicKeyOp g_magicHelpOp = {
.magicKey = 0x1a /* ctrl + z */
};
STATIC MagicKeyOp g_magicKillPgrp = {
.opHandler = KillPgrp,
.helpMsg = "Show all magic op key(ctrl+c) ",
.magicKey = 0x03 /* ctrl + c */
};
/*
* NOTICE:Suggest don't use
* ctrl+h/backspace=0x8,
......@@ -81,7 +87,7 @@ STATIC MagicKeyOp *g_magicOpTable[MAGIC_KEY_NUM] = {
&g_magicPanicOp, /* ctrl + p */
&g_magicTaskShowOp, /* ctrl + t */
&g_magicHelpOp, /* ctrl + z */
NULL /* rserved */
&g_magicKillPgrp /* ctrl + c */
};
STATIC VOID OsMagicHelp(VOID)
......@@ -131,7 +137,11 @@ INT32 CheckMagicKey(CHAR key)
PRINTK("Magic key off\n");
}
return 1;
} else if (key == 0x03){ /* ctrl + c */
KillPgrp();
return 0;
}
if (magicKeySwitch != 0) {
for (i = 0; g_magicOpTable[i] != NULL; ++i) {
if (key == g_magicOpTable[i]->magicKey) {
......
......@@ -3,7 +3,7 @@ LOSCFG_BOARD_CONFIG_PATH="device/qemu/arm_virt/liteos_a/config/board"
# LOSCFG_HRTIMER_ENABLE is not set
# LOSCFG_KERNEL_CPPSUPPORT is not set
# LOSCFG_FS_FAT is not set
# LOSCFG_ENABLE_MAGICKEY is not set
LOSCFG_ENABLE_MAGICKEY=y
LOSCFG_DEBUG_VERSION=y
# LOSCFG_SHELL_LK is not set
LOSCFG_USER_INIT_DEBUG=y
......
......@@ -109,9 +109,11 @@ endif
ifeq ($(OUTDIR),)
OUT = $(LITEOSTOPDIR)/out/$(LITEOS_PLATFORM)
LITEOS_TARGET_DIR = $(OUT)
KERNEL_COMPILE_ONLY = y
else
OUT = $(OUTDIR)
LITEOS_TARGET_DIR = $(OUT)/../../../
KERNEL_COMPILE_ONLY = n
endif
BUILD = $(OUT)/obj
MK_PATH = $(LITEOSTOPDIR)/tools/build/mk
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册