From 31726d38a7c3c31a3cde1c055f79e5dcd81dab0f Mon Sep 17 00:00:00 2001 From: HoshuChiu Date: Sat, 1 Apr 2023 18:47:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86qemu=E4=BD=BF?= =?UTF-8?q?=E7=94=A8VNC=E4=BD=9C=E4=B8=BA=E5=9B=BE=E5=83=8F=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 22 ++++++++++++++++++++-- tools/run-qemu.sh | 36 ++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 974a9ee87..ff93442b0 100644 --- a/Makefile +++ b/Makefile @@ -79,10 +79,16 @@ write_diskimage-uefi: bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .." # 不编译,直接启动QEMU qemu: - sh -c "cd tools && bash run-qemu.sh --bios=legacy && cd .." + sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=window && cd .." # 不编译,直接启动QEMU(UEFI) qemu-uefi: - sh -c "cd tools && bash run-qemu.sh --bios=uefi && cd .." + sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=window && cd .." +# 不编译,直接启动QEMU,使用VNC Display作为图像输出 +qemu-vnc: + sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=vnc && cd .." +# 不编译,直接启动QEMU(UEFI),使用VNC Display作为图像输出 +qemu-uefi-vnc: + sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=vnc && cd .." # 编译并写入磁盘镜像 build: @@ -107,6 +113,18 @@ run: $(MAKE) write_diskimage || exit 1 $(MAKE) qemu +# uefi方式启动,使用VNC Display作为图像输出 +run-uefi-vnc: + $(MAKE) all -j $(NPROCS) + $(MAKE) write_diskimage-uefi || exit 1 + $(MAKE) qemu-uefi-vnc + +# 编译并启动QEMU,使用VNC Display作为图像输出 +run-vnc: + $(MAKE) all -j $(NPROCS) + $(MAKE) write_diskimage || exit 1 + $(MAKE) qemu-vnc + # 在docker中编译,并启动QEMU run-docker: @echo "使用docker构建并运行" diff --git a/tools/run-qemu.sh b/tools/run-qemu.sh index e4b571d97..b54f370be 100644 --- a/tools/run-qemu.sh +++ b/tools/run-qemu.sh @@ -1,6 +1,6 @@ # 进行启动前检查 flag_can_run=1 -ARGS=`getopt -o p -l bios: -- "$@"` +ARGS=`getopt -o p -l bios:,display: -- "$@"` eval set -- "${ARGS}" echo "$@" allflags=$(qemu-system-x86_64 -cpu help | awk '/flags/ {y=1; getline}; y {print}' | tr ' ' '\n' | grep -Ev "^$" | sed -r 's|^|+|' | tr '\n' ',' | sed -r "s|,$||") @@ -36,22 +36,38 @@ QEMU_ARGUMENT="-d ${QEMU_DISK_IMAGE} -m ${QEMU_MEMORY} -smp ${QEMU_SMP} -boot or QEMU_ARGUMENT+="-s -S -cpu ${QEMU_CPU_FEATURES} -rtc ${QEMU_RTC_CLOCK} -serial ${QEMU_SERIAL} -drive ${QEMU_DRIVE} ${QEMU_DEVICES}" if [ $flag_can_run -eq 1 ]; then + while true;do case "$1" in --bios) - case "$2" in + case "$2" in uefi) #uefi启动新增ovmf.fd固件 - if [ ${ARCH} == x86_64 ] ;then - sudo ${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT} - elif [ ${ARCH} == i386 ] ;then - sudo ${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT} - fi + BIOS_TYPE=uefi ;; legacy) - sudo ${QEMU} ${QEMU_ARGUMENT} + BIOS_TYPE=lagacy ;; - esac + esac;shift 2;; + --display) + case "$2" in + vnc) + QEMU_ARGUMENT+=" -display vnc=:00";; + window) + ;; + esac;shift 2;; + *) break + esac + done + +if [ ${BIOS_TYPE} == uefi ] ;then + if [ ${ARCH} == x86_64 ] ;then + sudo ${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT} + elif [ ${ARCH} == i386 ] ;then + sudo ${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT} + fi +else + sudo ${QEMU} ${QEMU_ARGUMENT} +fi -esac else echo "不满足运行条件" fi From 76e6af9ef77f69fc840fb04b67f0b9f7f2b57055 Mon Sep 17 00:00:00 2001 From: longjin Date: Sun, 2 Apr 2023 07:54:44 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E8=AE=BE=E7=BD=AEvnc=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E4=B8=BA5900?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/run-qemu.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/run-qemu.sh b/tools/run-qemu.sh index b54f370be..7597bfca0 100644 --- a/tools/run-qemu.sh +++ b/tools/run-qemu.sh @@ -50,7 +50,8 @@ if [ $flag_can_run -eq 1 ]; then --display) case "$2" in vnc) - QEMU_ARGUMENT+=" -display vnc=:00";; + QEMU_ARGUMENT+=" -display vnc=:5900" + ;; window) ;; esac;shift 2;; From 6dc5ec8d779cfd4256e162c4841f6ff776e8a568 Mon Sep 17 00:00:00 2001 From: HoshuChiu Date: Sun, 16 Apr 2023 14:07:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIssue#220?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/apps/shell/cmd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index 72545c8a7..64cacb8d4 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -600,7 +600,7 @@ done:; * @param buf 输入缓冲区 * @param argc 返回值:参数数量 * @param argv 返回值:参数列表 - * @return int 主命令的编号 + * @return int 主命令的编号,小于零为无效命令 */ int parse_command(char *buf, int *argc, char ***argv) { @@ -609,6 +609,9 @@ int parse_command(char *buf, int *argc, char ***argv) // 去除命令前导的空格 while (index < INPUT_BUFFER_SIZE && buf[index] == ' ') ++index; + // 如果去除前导空格后第一项为0x00,则归为空命令 + if(!buf[index]) + return -1; // 计算参数数量 for (int i = index; i < (INPUT_BUFFER_SIZE - 1); ++i) @@ -619,7 +622,7 @@ int parse_command(char *buf, int *argc, char ***argv) if (buf[i] != ' ' && (buf[i + 1] == ' ' || buf[i + 1] == '\0')) ++(*argc); } - + // printf("\nargc=%d\n", *argc); // 为指向每个指令的指针分配空间 From e2a85b3d6f016deb264586c1183f290aed9f651b Mon Sep 17 00:00:00 2001 From: HoshuChiu Date: Sun, 16 Apr 2023 14:17:01 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E5=8F=B7=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E4=B8=BA5900?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/run-qemu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run-qemu.sh b/tools/run-qemu.sh index 5b40c6e91..7b5a0f63a 100644 --- a/tools/run-qemu.sh +++ b/tools/run-qemu.sh @@ -50,7 +50,7 @@ if [ $flag_can_run -eq 1 ]; then --display) case "$2" in vnc) - QEMU_ARGUMENT+=" -display vnc=:5900" + QEMU_ARGUMENT+=" -display vnc=:00" ;; window) ;;