#!/bin/bash MAIN_FILE="MemtestEfi" OBJECT_FILES=(AutoGen.obj OUTPUT/main.o OUTPUT/test.o OUTPUT/smp.o OUTPUT/config.o OUTPUT/screen_buffer.o OUTPUT/lib.o OUTPUT/init.o OUTPUT/controller.o OUTPUT/pci.o OUTPUT/spd.o OUTPUT/dmi.o OUTPUT/reloc.o OUTPUT/patn.o OUTPUT/linuxbios.o OUTPUT/error.o OUTPUT/vmem.o OUTPUT/cpuid.o OUTPUT/memsize.o OUTPUT/random.o OUTPUT/$MAIN_FILE.obj) STATIC_LIBRARY_FILES=(OUTPUT/$MAIN_FILE.lib libs/BaseLib.lib libs/BaseMemoryLib.lib libs/BasePcdLibNull.lib libs/BaseDebugPrintErrorLevelLib.lib libs/BasePrintLib.lib libs/UefiDebugLibStdErr.lib libs/UefiBootServicesTableLib.lib libs/UefiMemoryAllocationLib.lib libs/UefiRuntimeServicesTableLib.lib libs/UefiDevicePathLib.lib libs/UefiApplicationEntryPoint.lib libs/UefiLib.lib) INCLUDE_FILES=(main cpuid test smp config screen_buffer lib init controller pci spd dmi reloc patn linuxbios error vmem memsize random) ADDITIONAL_HEADER=(defs.h linuxbios_tables.h stdin.h io.h stdint.h stddef.h serial.h msr.h jedec_id.h elf.h) rm -f OUTPUT/* echo "######################## Create *.o files" for elem in ${ADDITIONAL_HEADER[@]} do cp memtest86+/${elem} OUTPUT/ done for elem in ${INCLUDE_FILES[@]} do cp memtest86+/${elem}.* OUTPUT/ done for elem in ${INCLUDE_FILES[@]} do gcc -c \ -IInclude \ -g \ -fno-stack-protector \ -fno-common \ -fshort-wchar \ -fno-builtin \ -fno-strict-aliasing \ -Wall \ -Wno-array-bounds \ -ffunction-sections \ -fdata-sections \ -include Include/AutoGen.h \ -m64 \ -maccumulate-outgoing-args \ -mno-red-zone \ -Wno-address \ -mcmodel=small \ -fpie \ -fno-asynchronous-unwind-tables \ -Wno-address \ -flto \ -DUSING_LTO \ -Os \ -D DISABLE_NEW_DEPRECATED_INTERFACES \ "-DEFIAPI=__attribute__((ms_abi))" \ -o OUTPUT/${elem}.o \ OUTPUT/${elem}.c if [ $? -ne 0 ]; then exit 1; fi done # -Werror \ if [ $? -ne 0 ]; then exit 1; fi echo "####################### Create obj file\n" #-S #-fverbose-asm # -m32 \ #gcc -E -traditional memtest86+/head.S -o memtest86+/head.s #as --64 -o memtest86+/head.o memtest86+/head.s #gcc -E -traditional memtest86+/bootsect.S -o memtest86+/bootsect.s #as -o memtest86+/bootsect.o memtest86+/bootsect.s #gcc -E -traditional memtest86+/setup.S -o memtest86+/setup.s #as -o memtest86+/setup.o memtest86+/setup.s gcc -MMD -MF OUTPUT/$MAIN_FILE.obj.deps \ -g \ -fshort-wchar \ -fno-builtin \ -fno-strict-aliasing \ -Wall \ -Wno-array-bounds \ -ffunction-sections \ -fdata-sections \ -include Include/AutoGen.h \ -fno-common \ -DSTRING_ARRAY_NAME=${MAIN_FILE}Strings \ -m64 \ -fno-stack-protector \ "-DEFIAPI=__attribute__((ms_abi))" \ -maccumulate-outgoing-args \ -mno-red-zone \ -Wno-address \ -mcmodel=small \ -fpie \ -fno-asynchronous-unwind-tables \ -Wno-address \ -flto \ -DUSING_LTO \ -Os \ -D DISABLE_NEW_DEPRECATED_INTERFACES \ -c \ -o OUTPUT/$MAIN_FILE.obj \ -I . \ -IInclude \ -IOUTPUT \ $MAIN_FILE.c if [ $? -ne 0 ]; then exit 1; fi echo "####################### Create $MAIN_FILE.lib" echo ${OBJECT_FILES[@]} gcc-ar crv OUTPUT/$MAIN_FILE.lib "${OBJECT_FILES[@]}" if [ $? -ne 0 ]; then exit 1; fi echo "####################### Create $MAIN_FILE.dll" echo ${STATIC_LIBRARY_FILES[@]} gcc -o OUTPUT/$MAIN_FILE.dll \ -nostdlib \ -Wl,-n,-q,--gc-sections \ -Wl,--entry,_ModuleEntryPoint \ -Wl,-Map,OUTPUT/$MAIN_FILE.map,--whole-archive \ -Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie \ -Wl,--start-group,@static_library_files.lst,--end-group \ -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 \ -Wl,--script=Include/GccBase.lds \ -z common-page-size=0x40 \ -u _ModuleEntryPoint \ -flto \ -Os \ -g \ -fshort-wchar \ -fno-builtin \ -fno-strict-aliasing \ -Wall \ -Werror \ -Wno-array-bounds \ -ffunction-sections \ -fdata-sections \ -fno-common \ -DSTRING_ARRAY_NAME=${MAIN_FILE}Strings \ -m64 \ -fno-stack-protector \ "-DEFIAPI=__attribute__((ms_abi))" \ -maccumulate-outgoing-args \ -mno-red-zone \ -Wno-address \ -mcmodel=small \ -fpie \ -fno-asynchronous-unwind-tables \ -Wno-address \ -flto \ -DUSING_LTO \ -Os \ -D DISABLE_NEW_DEPRECATED_INTERFACES \ -include AutoGen.h \ -I OUTPUT/ \ -I Library/ \ -Wno-error if [ $? -ne 0 ]; then exit 1; fi echo "####################### Objcopy strip unneeded" objcopy --strip-unneeded -R .eh_frame -v OUTPUT/$MAIN_FILE.dll OUTPUT/$MAIN_FILE.dll if [ $? -ne 0 ]; then exit 1; fi echo "####################### Run GenFW" ./Include/GenFw -e UEFI_APPLICATION -o OUTPUT/start_$MAIN_FILE.efi OUTPUT/$MAIN_FILE.dll cp -v OUTPUT/start_$MAIN_FILE.efi ../test_code/hda-contents/