Skip to content

Commit

Permalink
Add LoongArch64 support
Browse files Browse the repository at this point in the history
* Requires the toolchain from https://github.com/loongson/build-tools/releases/.
* Closes #43.
* Also remove ARM32 VS2022 builds since support for ARM32 has been dropped in latest VS2022.
* Also update compiler options and libraries to build with current EDK2.
  • Loading branch information
MarsDoge authored and pbatard committed Nov 29, 2024
1 parent 4087873 commit da4be21
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 26 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/linux_gcc_edk2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ env:
GCC5_ARM_PREFIX: arm-linux-gnueabi-
GCC5_AARCH64_PREFIX: aarch64-linux-gnu-
GCC5_RISCV64_PREFIX: riscv64-linux-gnu-
GCC5_LOONGARCH64_PREFIX: loongarch64-unknown-linux-gnu-

jobs:
build:
runs-on: ubuntu-24.04

strategy:
matrix:
arch: [X64, IA32, AARCH64, ARM, RISCV64]
arch: [X64, IA32, AARCH64, ARM, RISCV64, LOONGARCH64]
include:
- arch: X64
short: x64
Expand All @@ -54,15 +55,23 @@ jobs:
- arch: RISCV64
short: riscv64
pkgs: gcc-riscv64-linux-gnu python3-setuptools uuid-dev
- arch: LOONGARCH64
short: loongarch64
pkgs: gcc-multilib python3-setuptools uuid-dev

steps:
- name: Install toolchain
run: |
sudo apt-get update
sudo apt-get install ${{ matrix.pkgs }}
if [[ "${{ matrix.arch }}" == "LOONGARCH64" ]]; then
curl -L -O https://github.com/loongson/build-tools/releases/download/2024.11.01/x86_64-cross-tools-loongarch64-binutils_2.43.1-gcc_14.2.0-glibc_2.40.tar.xz
tar -xJf x86_64-cross-tools-loongarch64-binutils_2.43.1-gcc_14.2.0-glibc_2.40.tar.xz
echo "$PWD/cross-tools/bin" >> "$GITHUB_PATH"
fi
- name: Fix missing Risc-V header
if: matrix.arch == 'riscv64'
if: matrix.arch == 'RISCV64'
run: sudo ln -s /usr/riscv64-linux-gnu/include/gnu/stubs-lp64d.h /usr/riscv64-linux-gnu/include/gnu/stubs-lp64.h

- name: Set up EDK2
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/linux_gcc_gnu-efi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

strategy:
matrix:
arch: [x64, ia32, aa64, arm, riscv64]
arch: [x64, ia32, aa64, arm, riscv64, loongarch64]
include:
- arch: x64
pkg: gcc-mingw-w64-x86-64
Expand All @@ -47,6 +47,9 @@ jobs:
- arch: riscv64
pkg: gcc-riscv64-linux-gnu
tuple: riscv64-linux-gnu-
- arch: loongarch64
pkg: gcc-multilib
tuple: loongarch64-unknown-linux-gnu-

steps:
- name: Checkout repository and submodules
Expand All @@ -59,6 +62,11 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install ${{ matrix.pkg }}
if [[ "${{ matrix.arch }}" == "loongarch64" ]]; then
curl -L -O https://github.com/loongson/build-tools/releases/download/2024.11.01/x86_64-cross-tools-loongarch64-binutils_2.43.1-gcc_14.2.0-glibc_2.40.tar.xz
tar -xJf x86_64-cross-tools-loongarch64-binutils_2.43.1-gcc_14.2.0-glibc_2.40.tar.xz
echo "$PWD/cross-tools/bin" >> "$GITHUB_PATH"
fi
- name: Patch GRUB
run: |
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/windows_msvc_edk2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

strategy:
matrix:
arch: [X64, IA32, AARCH64, ARM]
arch: [X64, IA32, AARCH64]
include:
- arch: X64
short: x64
Expand All @@ -46,9 +46,6 @@ jobs:
- arch: AARCH64
short: aa64
msvc: amd64_arm64
- arch: ARM
short: arm
msvc: amd64_arm

steps:
- name: Set up environment variables
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_msvc_gnu-efi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

strategy:
matrix:
arch: [x64, ia32, aa64, arm]
arch: [x64, ia32, aa64]

steps:
- name: Checkout repository and submodules
Expand Down
10 changes: 5 additions & 5 deletions EfiFsPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
PLATFORM_GUID = 700d6096-1578-409e-a6c7-9acdf9f565b3
PLATFORM_VERSION = 1.3
DSC_SPECIFICATION = 0x00010005
SUPPORTED_ARCHITECTURES = IA32|X64|EBC|ARM|AARCH64|RISCV64
SUPPORTED_ARCHITECTURES = IA32|X64|EBC|ARM|AARCH64|RISCV64|LOONGARCH64
OUTPUT_DIRECTORY = Build/EfiFs
BUILD_TARGETS = DEBUG|RELEASE|NOOPT
SKUID_IDENTIFIER = DEFAULT
Expand All @@ -21,6 +21,7 @@
MSFT:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
RVCT:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
*_*_*_CC_FLAGS = -DDISABLE_NEW_DEPRECATED_INTERFACES
MSFT:*_*_AARCH64_CC_FLAGS = /GS-

!include MdePkg/MdeLibs.dsc.inc

Expand All @@ -44,9 +45,8 @@
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf

[LibraryClasses.ARM, LibraryClasses.AARCH64, LibraryClasses.RISCV64]
NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
[LibraryClasses.ARM, LibraryClasses.AARCH64, LibraryClasses.RISCV64, LibraryClasses.LOONGARCH64,]
NULL|MdePkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

[LibraryClasses.IA32, LibraryClasses.X64]
!if $(TOOLCHAIN) == "VS2019"
Expand Down Expand Up @@ -98,4 +98,4 @@
EfiFsPkg/EfiFsPkg/UfsBe.inf
EfiFsPkg/EfiFsPkg/Ufs2.inf
EfiFsPkg/EfiFsPkg/Xfs.inf
EfiFsPkg/EfiFsPkg/Zfs.inf
EfiFsPkg/EfiFsPkg/Zfs.inf
13 changes: 13 additions & 0 deletions Make.common
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ else
else ifeq ($(shell uname -m),riscv64)
ARCH = riscv64
CROSS_COMPILE =
else ifeq ($(shell uname -m),loongarch64)
ARCH = loongarch64
CROSS_COMPILE =
else
ARCH = ia32
endif
Expand Down Expand Up @@ -86,6 +89,16 @@ else ifeq ($(ARCH),riscv64)
CFLAGS = -fpic -fshort-wchar -Wno-pointer-to-int-cast
LDFLAGS = -Wl,--defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)
CRT0_LIBS = -lgnuefi
else ifeq ($(ARCH),loongarch64)
GNUEFI_ARCH = loongarch64
GCC_ARCH = loongarch64-unknown
CPU_ARCH = loongarch64
CRT0_ARCH = loongarch64
CROSS_COMPILE = $(GCC_ARCH)-linux-gnu-
EP_PREFIX =
CFLAGS = -fpic -fshort-wchar -Wno-pointer-to-int-cast
LDFLAGS = -Wl,--defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)
CRT0_LIBS = -lgnuefi
endif

TOPDIR := $(dir $(lastword $(MAKEFILE_LIST)))
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ For additional info as well as precompiled drivers, see https://efi.akeo.ie

* Run `make` in the top directory. If needed you can also issue something like
`make ARCH=<arch> CROSS_COMPILE=<tuple>` where `<arch>` is one of `ia32`,
`x64`, `arm`, `aa64` or `riscv64` (the __official__ UEFI abbreviations for an
arch, as used in `/efi/boot/boot[ARCH].efi`) and `<tuple>` is the one for your
cross-compiler, such as `arm-linux-gnueabi-` or `aarch64-linux-gnu-`.
`x64`, `arm`, `aa64`, `riscv64` or `loongarch64` (the __official__ UEFI
abbreviations for an arch, as used in `/efi/boot/boot[ARCH].efi`) and `<tuple>`
is the one for your cross-compiler, such as `arm-linux-gnueabi-` or
`aarch64-linux-gnu-`.
e.g. `make ARCH=aa64 CROSS_COMPILE=aarch64-linux-gnu-`

### EDK2
Expand All @@ -54,7 +55,7 @@ For additional info as well as precompiled drivers, see https://efi.akeo.ie
by invoking:
* (Windows) `set_grub_cpu.cmd <arch>`
* (Linux) `./set_grub_cpu.sh <arch>`
Where `<arch>` is one of `ia32`, `x64`, `arm`, `aarch64` or `riscv64`.
Where `<arch>` is one of `ia32`, `x64`, `arm`, `aarch64`, `riscv64` or `loongarch64`.
Note that you __MUST__ invoke the `set_grub_cpu` script __every time you
switch target__.
* After having invoked `edksetup.bat` (Windows) or `edksetup.sh` (Linux) run
Expand Down
2 changes: 2 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define GRUB_TARGET_CPU "arm64"
#elif defined (_M_RISCV64) || (defined (__riscv) && (__riscv_xlen == 64))
#define GRUB_TARGET_CPU "riscv64"
#elif defined (_M_LOONGARCH64) || defined (__loongarch64)
#define GRUB_TARGET_CPU "loongarch64"
#else
#error Usupported architecture
#endif
Expand Down
17 changes: 9 additions & 8 deletions set_grub_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
grub_include=`dirname $(readlink -f $0)`/grub/include/grub
shopt -s nocasematch
case "$1" in
"x64") arch=x86_64;;
"x86") arch=i386;;
"ia32") arch=i386;;
"arm") arch=arm;;
"arm64") arch=arm64;;
"aa64") arch=arm64;;
"aarch64") arch=arm64;;
"riscv64") arch=riscv64;;
"x64") arch=x86_64;;
"x86") arch=i386;;
"ia32") arch=i386;;
"arm") arch=arm;;
"arm64") arch=arm64;;
"aa64") arch=arm64;;
"aarch64") arch=arm64;;
"riscv64") arch=riscv64;;
"loongarch64") arch=loongarch64;;
*) echo "Unsupported arch"; exit 1;;
esac
rm -f $grub_include/cpu
Expand Down
2 changes: 1 addition & 1 deletion src/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#endif

/* Sort out the platform specifics */
#if defined(_M_ARM64) || defined(__aarch64__) || defined (_M_X64) || defined(__x86_64__) || defined(_M_RISCV64) || (defined (__riscv) && (__riscv_xlen == 64))
#if defined(_M_ARM64) || defined(__aarch64__) || defined (_M_X64) || defined(__x86_64__) || defined(_M_RISCV64) || (defined (__riscv) && (__riscv_xlen == 64)) || defined (_M_LOONGARCH64) || defined (__loongarch64)
#define PERCENT_P L"%llx"
#else
#define PERCENT_P L"%x"
Expand Down

0 comments on commit da4be21

Please sign in to comment.