From 516ad87e824e8cf6dba01c7c04f096767768b865 Mon Sep 17 00:00:00 2001 From: yaya Date: Mon, 14 Dec 2020 10:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BB=BF.=20=E4=B8=80=E6=AC=A1=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=AE=8C=E6=88=9032=E4=BD=8D=E3=80=8164=E4=BD=8D?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 5 +-- ChangeLog_UEFI.txt | 3 ++ build | 90 ++++++++++------------------------------- grub4dos_version | 2 +- stage2/Makefile.in-i386 | 12 +++--- stage2/builtins.c | 17 ++++++-- stage2/common.c | 2 + stage2/stage2.c | 2 + 8 files changed, 50 insertions(+), 83 deletions(-) diff --git a/.travis.yml b/.travis.yml index c3e6b7c0..8a146cc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,6 @@ before_script: script: - ./build - - ./build i386 after_success: - eval $SUCCESS @@ -48,9 +47,7 @@ branches: deploy: provider: releases api_key: $GITHUB_TOKEN - file: - - grub4dos-$(cat grub4dos_version)-x64-$(date -u +%Y-%m-%d).7z - - grub4dos-$(cat grub4dos_version)-ia32-$(date -u +%Y-%m-%d).7z + file: grub4dos-$(cat grub4dos_version)-$(date -u +%Y-%m-%d).7z skip_cleanup: true overwrite: true on: diff --git a/ChangeLog_UEFI.txt b/ChangeLog_UEFI.txt index 038bbcbc..5896a398 100644 --- a/ChangeLog_UEFI.txt +++ b/ChangeLog_UEFI.txt @@ -1,4 +1,7 @@ 更新说明: +2020-12-14 (yaya) + 一次编译完成32位、64位版本。 + 2020-12-10 (yaya) 使用 "./build i386" 编译 BOOTIA32.EFI 。 可以使用参数 "--top" 将镜像强制加载到 4Gb 以上内存。 diff --git a/build b/build index 10fc145f..d6e92696 100755 --- a/build +++ b/build @@ -8,16 +8,6 @@ # ./build #此时在根目录 /home/dev/grub4efi -#使用“./build i386”编译BOOTIA32.EFI -#使用“./build”或者"make"编译BOOTX64.EFI -if [ "$1" = "i386" ]; then - I386=1 - ARCH="ia32" -else - I386=0 - ARCH="x64" -fi - #源目录 SOURCE_DIR=`pwd` #版本 @@ -25,7 +15,7 @@ VER=`cat grub4dos_version` #日期 DATE=`date -u +%Y-%m-%d` #发布日期 -RELEASE=grub4dos-${VER}-${ARCH}-${DATE} +RELEASE=grub4dos-${VER}-${DATE} #定义复制文件集 #COPY_FILES="COPYING README_GRUB4DOS*.txt ChangeLog_*.txt \ # config.sys default menu.lst grub.pif config.h\ @@ -81,13 +71,6 @@ fi #转到 GRUB4DOS_TEMP 目录 cd ${GRUB4DOS_TEMP} || exit $? -#编译切换 -if [ $I386 = 1 ]; then - mv stage2/Makefile.in stage2/Makefile.in-64 - mv stage2/Makefile.in-i386 stage2/Makefile.in - echo 1 -fi - #生成 Get_Source_of_This_Build.txt 文件 if [ "$Get_source" ]; then echo -n -e "Get the source code of this build in this way:\r\n\r\n${Get_source}" > Get_Source_of_This_Build.txt @@ -98,11 +81,10 @@ if [ "$Get_source" ]; then echo -n -e "and now you may do a \"make\" to compile.\r\n\r\n" >> Get_Source_of_This_Build.txt fi -############################################# -# Build english version 生成英文版本 -############################################# +#********************************************** +# 编译 BOOTX64.EFI +#********************************************** #配置 -#./configure --enable-preset-menu=preset_menu.lst || exit $? ./configure || exit $? #清洁 make clean @@ -142,24 +124,6 @@ make || exit $? # fi #fi -############################################# -# Build chinese version 建立中文版 -############################################# -#如果补丁 -p1 < patch-chinese.diff,编译 -#patch -p1 < patch-chinese.diff || exit $? -#make || exit $? - -#建立 grub4dos-${VER}/chinese 目录 -#mkdir grub4dos-${VER}/chinese || exit $? -#复制 README_GRUB4DOS_CN.txt 及 stage2/grldr 到 grub4dos-${VER}/chinese -#cp README_GRUB4DOS_CN.txt stage2/grldr grub4dos-${VER}/chinese || exit $? - -############################################# -# Create ZIP ball or TAR ball 创建 ZIP 或 TAR -############################################# -#转到 $SOURCE_DIR -#cd $SOURCE_DIR - #如果存在 ipxe,则转到 ipxe/src 目录,编译并推送...,然后返回 $SOURCE_DIR 目录 #if [ -d ipxe ] ; then # cd ipxe/src @@ -173,55 +137,43 @@ make || exit $? cp stage2/pre_stage2.exec $GRUB4DOS_TEMP/kernel.img cp $SOURCE_DIR/moddep.lst $GRUB4DOS_TEMP/moddep.lst platform=`uname -m` -if ! [ $I386 = 1 ]; then if [ $platform = 'x86_64' ] then $SOURCE_DIR/grub-mkimage64 -d $GRUB4DOS_TEMP -p /GRUB2 -o BOOTX64.EFI -O x86_64-efi else $SOURCE_DIR/grub-mkimage -d $GRUB4DOS_TEMP -p /GRUB2 -o BOOTX64.EFI -O x86_64-efi fi -else -echo 3 + +#********************************************** +# 编译 BOOTIA32.EFI +#********************************************** +#编译切换 +mv stage2/Makefile.in stage2/Makefile.in-64 +mv stage2/Makefile.in-i386 stage2/Makefile.in +#配置 +./configure || exit $? +#清洁 +make clean +#编译 +make || exit $? +cp stage2/pre_stage2.exec $GRUB4DOS_TEMP/kernel.img if [ $platform = 'x86_64' ] then $SOURCE_DIR/grub-mkimage64 -d $GRUB4DOS_TEMP -p /GRUB2 -o BOOTIA32.EFI -O i386-efi else $SOURCE_DIR/grub-mkimage -d $GRUB4DOS_TEMP -p /GRUB2 -o BOOTIA32.EFI -O i386-efi fi -fi + #转到源目录 cd $SOURCE_DIR -#$SOURCE_DIR/grub-mkimage -d $SOURCE_DIR -p /GRUB2 -o BOOTX64.EFI -O x86_64-efi #此时在 /tmp/grub4dos-temp/ #cd / #此时在 /home/ 的上一级目录,但不是 /g4d_dev/ -#产生 grub4dos-0.4.6a-xxxx-xx-xx.7z 文件 -#rm -f ${RELEASE}.zip ${RELEASE}.rar ${RELEASE}.tar.gz || exit $? -#if ! 7z a ${RELEASE}.7z ${GRUB4DOS_TEMP}/grub4dos-${VER} ; then -# echo 7z failed. Continue with zip or tar... -# if ! zip -r -q ${RELEASE}.zip ${GRUB4DOS_TEMP}/grub4dos-${VER} ; then -# tar -czf ${RELEASE}.tar.gz ${GRUB4DOS_TEMP}/grub4dos-${VER} -# fi -#fi - rm -f ${RELEASE}.zip ${RELEASE}.rar ${RELEASE}.tar.gz || exit $? -if ! [ $I386 = 1 ]; then -if ! 7z a ${RELEASE}.7z ${GRUB4DOS_TEMP}/BOOTX64.EFI $SOURCE_DIR/ChangeLog_UEFI.txt $SOURCE_DIR/menu.lst \ - ${GRUB4DOS_TEMP}/Get_Source_of_This_Build.txt ${GRUB4DOS_TEMP}/grub4dos_${CURR_REVISION}.diff; then +if ! 7z a ${RELEASE}.7z ${GRUB4DOS_TEMP}/BOOTX64.EFI ${GRUB4DOS_TEMP}/BOOTIA32.EFI $SOURCE_DIR/ChangeLog_UEFI.txt \ + $SOURCE_DIR/menu.lst ${GRUB4DOS_TEMP}/Get_Source_of_This_Build.txt ${GRUB4DOS_TEMP}/grub4dos_${CURR_REVISION}.diff; then echo 7z failed. Continue with zip or tar... fi -else -if ! 7z a ${RELEASE}.7z ${GRUB4DOS_TEMP}/BOOTIA32.EFI $SOURCE_DIR/ChangeLog_UEFI.txt $SOURCE_DIR/menu.lst \ - ${GRUB4DOS_TEMP}/Get_Source_of_This_Build.txt ${GRUB4DOS_TEMP}/grub4dos_${CURR_REVISION}.diff; then - echo 7z failed. Continue with zip or tar... -fi -fi -#删除*.zip *.7z *~ -#rm -rf *.zip *.7z *~ || exit $? -#产生 grub4dos_for_UEFI-0.4.6a-xxxx-xx-xx.7z 文件 -#if ! 7z a ${RELEASE}.7z $SOURCE_DIR/BOOTX64.EFI $SOURCE_DIR/ChangeLog_UEFI.txt; then -# echo 7z failed. Continue with zip or tar... -#fi # Do not remove grub4dos-temp as we can check and re-use it later. 不要删除grub4dos temp,因为我们可以稍后检查并重新使用它。 diff --git a/grub4dos_version b/grub4dos_version index 64e14d25..44456ad3 100644 --- a/grub4dos_version +++ b/grub4dos_version @@ -1 +1 @@ -0.4.6a_for_UEFI +for_UEFI diff --git a/stage2/Makefile.in-i386 b/stage2/Makefile.in-i386 index 902a46f1..cfcfc930 100644 --- a/stage2/Makefile.in-i386 +++ b/stage2/Makefile.in-i386 @@ -68,9 +68,9 @@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m32 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c +install_sh_DATA = $(install_sh) -c -m32 -m 644 +install_sh_PROGRAM = $(install_sh) -c -m32 +install_sh_SCRIPT = $(install_sh) -c -m32 INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : @@ -645,14 +645,14 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pxeloader.Po@am__quote@ .S.o: -@am__fastdepCCAS_TRUE@ $(AM_V_CPPAS)$(CPPASCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCCAS_TRUE@ $(AM_V_CPPAS)$(CPPASCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -m32 -o $@ $< @am__fastdepCCAS_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCCAS_FALSE@ $(AM_V_CPPAS)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCCAS_FALSE@ DEPDIR=$(DEPDIR) $(CCASDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCCAS_FALSE@ $(AM_V_CPPAS@am__nodep@)$(CPPASCOMPILE) -c -o $@ $< +@am__fastdepCCAS_FALSE@ $(AM_V_CPPAS@am__nodep@)$(CPPASCOMPILE) -c -m32 -o $@ $< .S.obj: -@am__fastdepCCAS_TRUE@ $(AM_V_CPPAS)$(CPPASCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCCAS_TRUE@ $(AM_V_CPPAS)$(CPPASCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -m32 -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCCAS_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCCAS_FALSE@ $(AM_V_CPPAS)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCCAS_FALSE@ DEPDIR=$(DEPDIR) $(CCASDEPMODE) $(depcomp) @AMDEPBACKSLASH@ diff --git a/stage2/builtins.c b/stage2/builtins.c index 223237eb..77bb8874 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -782,12 +782,14 @@ map_to_svbus (grub_efi_physical_address_t address) if (drive_map_slot_empty (disk_drive_map[i])) //判断驱动器映像插槽是否为空 为空,返回1 break; + //滤除软盘 + if (disk_drive_map[i].from_drive < 0x80) + continue; + //复制映射插槽 grub_memmove ((char *)((char *)(grub_size_t)address + i*24), (char *)&disk_drive_map[i], 24); *(char*)((char *)(grub_size_t)address + i*24 + 2) = 0xfe; //from最大磁头号 if (disk_drive_map[i].from_drive >= 0xa0) *(char*)((char *)(grub_size_t)address + i*24 + 5) = 0x20; //from驱动器是cdrom - else - *(char*)((char *)(grub_size_t)address + i*24 + 5) = 0; } //复制碎片插槽 @@ -1081,6 +1083,9 @@ chainloader_func (char *arg, int flags) d = get_device_by_drive (current_drive); file_path = grub_efi_file_device_path (d->device_path, filename); + if (debug > 1) + grub_efi_print_device_path (file_path); //打印设备路径 + status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, boot_image, filemax, &image_handle); //调用(装载镜像,0,镜像句柄,文件路径,引导镜像,尺寸,镜像句柄地址) @@ -6793,7 +6798,13 @@ struct drive_map_slot } } } - +/* +通过g4e或者grub2作为一个UEFI引导器,加载镜像到内存盘,并且做好了与svbus驱动的对接,然后启动windows,进入桌面。 +当内存类型为GRUB_EFI_RUNTIME_SERVICES_DATA时,有的系统可以成功启动,而有的windows系统报错误0xc0000225和0xc0000017. +“c0000225”或“c0000017”错误发生在您试图在运行Windows 7或Windows Server 2008 R2的启用了UEFI的计算机上启动Windows PE RAM磁盘映像时. +看微软的意思是“内存状态不同步,一个内存管理器使用的一些内存仍然被另一个内存管理器标记为可用. +改用内存类型GRUB_EFI_RESERVED_MEMORY_TYPE,完美解决. +*/ status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES, // GRUB_EFI_RUNTIME_SERVICES_DATA, GRUB_EFI_RESERVED_MEMORY_TYPE, //保留内存类型 0 diff --git a/stage2/common.c b/stage2/common.c index 6c03e777..d2cdda04 100644 --- a/stage2/common.c +++ b/stage2/common.c @@ -1540,6 +1540,8 @@ copy_grub4dos_self_address (void) GRUB_EFI_RUNTIME_SERVICES_DATA, 1, &grub4dos_self_address); //(分配页,分配类型=指定地址,存储类型=运行时数据,页数=1,返回分配地址) if (status) return; + //清除残留 + grub_memset ((void *)(grub_size_t)grub4dos_self_address, 0, 0x1000); //复制特定字符串 grub_memmove ((void *)(grub_size_t)(grub4dos_self_address + 0xe0), " $INT13SFGRUB4DOS", 19); //复制bootx64.efi自身地址 diff --git a/stage2/stage2.c b/stage2/stage2.c index 3739997b..c6c11009 100644 --- a/stage2/stage2.c +++ b/stage2/stage2.c @@ -1771,6 +1771,8 @@ cmain (void) if (*config_file) { is_opened = (configfile_opened || grub_open (config_file)); + if (! is_opened) + goto done_config_file; menu_mem = grub_zalloc (filemax + 0x40c00); //分配内存, 并清零 title_boot = (unsigned short *)menu_mem; titles = (char * *)(menu_mem + 1024);