Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Loongarch support #2955

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cee98db
pe: Add LoongArch definitions
opsiff Aug 25, 2024
c6bef1d
copy grub 2.04 elf.h to MOD
opsiff Aug 25, 2024
1b46769
elf: Add LoongArch definitions
opsiff Aug 25, 2024
fd9d0b6
loongarch: Add setjmp implementation
opsiff Aug 25, 2024
e2359cc
loongarch: Add early startup code
opsiff Aug 25, 2024
19c9513
copy grub 2.04 grub-core/kern/dl.c to MOD
opsiff Aug 25, 2024
a12fcf9
loongarch: Add support for ELF psABI v1.00 relocations
opsiff Aug 25, 2024
30b840d
loongarch: Add support for ELF psABI v2.00 relocations
opsiff Aug 25, 2024
c8be8c5
loongarch: Add auxiliary files
opsiff Aug 25, 2024
583bcc8
copy grub 2.04 Makefile.util.def to MOD
opsiff Aug 25, 2024
680df77
loongarch: Add to build system
opsiff Aug 25, 2024
26a4e6f
copy files need mod for loader: Drop argv[] argument in grub_initrd_l…
opsiff Aug 25, 2024
e45b2b4
loader: Drop argv[] argument in grub_initrd_load()
opsiff Aug 25, 2024
018b8e8
Ventoy Version loader/efi: Move ARM64 linux loader to common code
opsiff Aug 25, 2024
2808670
efi: Move MS-DOS stub out of generic PE header definition
opsiff Aug 25, 2024
e2e760c
mdraid1x_linux: Fix gcc10 error -Werror=array-bounds
opsiff Aug 25, 2024
846cbab
loader/linux: Remove magic number header field check
opsiff Aug 25, 2024
34e16ee
copy zfs.c zfs_lef.h
opsiff Aug 25, 2024
611baa9
zfs: Fix gcc10 error -Werror=zero-length-bounds
opsiff Aug 25, 2024
0878faf
copy files need mod efi: Fix use-after-free in halt/reboot path
opsiff Aug 25, 2024
1fc47c7
efi: Fix use-after-free in halt/reboot path
opsiff Aug 25, 2024
066a259
cache: fix no previous prototype for ‘grub_arch_sync_dma_caches’ in l…
opsiff Aug 25, 2024
c40640c
grub-core/ventoy: add some define and code for loongarch64
opsiff Aug 26, 2024
fd70b6d
Ventoy: install.sh: add support for loongarch64
opsiff Aug 26, 2024
e431499
Ventoy: add compiled binary
opsiff Aug 26, 2024
f14326c
Ventoy: dmsetup: add binary & build.txt
opsiff Aug 26, 2024
babf879
Ventoy: EDK2: adapt for loogarch in edk2-edk2-stable202408
opsiff Aug 26, 2024
59d4aaa
Ventoy: EDK2: add compiled binary
opsiff Aug 26, 2024
68e30ca
loongarch: adapt build lzma and lzo
opsiff Aug 26, 2024
279cb45
squashfs-tools-4.4/squashfs-tools: allow for using system libz
opsiff Aug 26, 2024
23ef449
unsquashfs: add loongarch binary
opsiff Aug 26, 2024
43143ba
Ventoy: FUSEISO: add support for loongarch64
opsiff Aug 26, 2024
c3ab1c6
Ventoy: busybox: add loongarch
opsiff Sep 2, 2024
66b1c78
Ventoy: vtoygpt: add binary
opsiff Sep 2, 2024
4f81cac
Ventoy: vtoytool: build for loongarch and musl
opsiff Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,166 changes: 1,166 additions & 0 deletions BUSYBOX/loongarch64_ash.config

Large diffs are not rendered by default.

1,166 changes: 1,166 additions & 0 deletions BUSYBOX/loongarch64_hexdump.config

Large diffs are not rendered by default.

1,166 changes: 1,166 additions & 0 deletions BUSYBOX/loongarch64_xzcat.config

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions DMSETUP/build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ build for 32bit, static linked with dietlibc
5. mips64el-linux-musl-strip dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetupm64e binary file

======================== Build for loongarch64 dmsetup =========================
1. extract device mapper source code
2. ./configure build_alias=loongarch64-unknown-linux-gnu --disable-nls --disable-selinux --disable-shared --enable-static_link CC='gcc -specs /usr/local/musl/lib/musl-gcc.specs'
3. make
4. strip --strip-all dmsetup/dmsetup.static
5. get dmsetup/dmsetup.static as the dmsetupla64 binary file



Expand Down
Binary file added DMSETUP/dmsetupla64
Binary file not shown.
4 changes: 3 additions & 1 deletion EDK2/buildedk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ sh ./build.sh ia32 || exit 1
echo '======== build EDK2 for arm64-efi ==============='
sh ./build.sh aa64 || exit 1

echo '======== build EDK2 for loongarch64-efi ========='
sh ./build.sh la64 || exit 1

echo '======== build EDK2 for x86_64-efi ==============='
sh ./build.sh || exit 1

44 changes: 44 additions & 0 deletions EDK2/buildloongarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

EDKARCH=LOONGARCH64
postfix=la64


cd edk2-edk2-stable202408

rm -rf ./Conf/.cache
rm -f ./Conf/.AutoGenIdFile.txt

VTEFI_PATH=Build/MdeModule/RELEASE_GCC/$EDKARCH/MdeModulePkg/Application/Ventoy/Ventoy/OUTPUT/Ventoy.efi
DST_PATH=../../INSTALL/ventoy/ventoy_${postfix}.efi

VTEFI_PATH2=Build/MdeModule/RELEASE_GCC/$EDKARCH/MdeModulePkg/Application/VtoyUtil/VtoyUtil/OUTPUT/VtoyUtil.efi
DST_PATH2=../../INSTALL/ventoy/vtoyutil_${postfix}.efi

VTEFI_PATH3=Build/MdeModule/RELEASE_GCC/$EDKARCH/MdeModulePkg/Application/VDiskChain/VDiskChain/OUTPUT/VDiskChain.efi
DST_PATH3=../../VDiskChain/Tool/vdiskchain_${postfix}.efi


rm -f $VTEFI_PATH
rm -f $DST_PATH
rm -f $VTEFI_PATH2
rm -f $DST_PATH2
rm -f $VTEFI_PATH3
[ -d ../../VDiskChain ] && rm -f $DST_PATH3

unset WORKSPACE
source ./edksetup.sh

build -p MdeModulePkg/MdeModulePkg.dsc -a $EDKARCH -b RELEASE -t GCC

if [ -e $VTEFI_PATH ] && [ -e $VTEFI_PATH2 ] && [ -e $VTEFI_PATH3 ]; then
echo -e '\n\n====================== SUCCESS ========================\n\n'
cp -a $VTEFI_PATH $DST_PATH
cp -a $VTEFI_PATH2 $DST_PATH2
[ -d ../../VDiskChain ] && cp -a $VTEFI_PATH3 $DST_PATH3
cd ..
else
echo -e '\n\n====================== FAILED ========================\n\n'
cd ..
fi

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ CONST CHAR16 *gEfiBootFileName[] =
L"\\EFI\\BOOT\\BOOTaa64.EFI",
L"\\EFI\\BOOT\\bootaa64.efi",
L"\\efi\\boot\\bootaa64.efi",
#elif defined (MDE_CPU_LOONGARCH64)
L"\\EFI\\BOOT\\GRUBLOONGARCH64.EFI",
L"\\EFI\\BOOT\\BOOTLOONGARCH64.EFI",
L"\\EFI\\BOOT\\bootloongarch64.efi",
L"\\efi\\boot\\bootloongarch64.efi",
#endif

};
Expand Down Expand Up @@ -109,10 +114,15 @@ STATIC EFI_STATUS EFIAPI vdisk_load_image
)
{
EFI_STATUS Status = EFI_SUCCESS;
CHAR16 TmpBuf[256] = {0};
CHAR16 TmpBuf[256];
UINT8 i;
FILEPATH_DEVICE_PATH *pFilePath = NULL;
EFI_DEVICE_PATH_PROTOCOL *pImgPath = NULL;

for (i = 0; i < 256; i++)
{
TmpBuf[i] = 0;
}
pFilePath = (FILEPATH_DEVICE_PATH *)TmpBuf;
pFilePath->Header.Type = MEDIA_DEVICE_PATH;
pFilePath->Header.SubType = MEDIA_FILEPATH_DP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define VENTOY_UEFI_DESC L"ARM UEFI"
#elif defined (MDE_CPU_AARCH64)
#define VENTOY_UEFI_DESC L"ARM64 UEFI"
#elif defined (MDE_CPU_LOONGARCH64)
#define VENTOY_UEFI_DESC L"LOONGARCH64 UEFI"
#else
#error Unknown Processor Type
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ EFI_STATUS EFIAPI vdisk_block_io_write
EFI_STATUS EFIAPI vdisk_fill_device_path(VOID)
{
UINTN NameLen = 0;
UINT8 TmpBuf[128] = {0};
UINT8 TmpBuf[128];
UINT8 i;
VENDOR_DEVICE_PATH *venPath = NULL;

for (i = 0; i < 128; i++)
{
TmpBuf[i] = 0;
}
venPath = (VENDOR_DEVICE_PATH *)TmpBuf;
NameLen = StrSize(VDISK_BLOCK_DEVICE_PATH_NAME);
venPath->Header.Type = HARDWARE_DEVICE_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ CONST CHAR16 *gEfiBootFileName[] =
L"\\EFI\\BOOT\\BOOTaa64.EFI",
L"\\EFI\\BOOT\\bootaa64.efi",
L"\\efi\\boot\\bootaa64.efi",
#elif defined (MDE_CPU_LOONGARCH64)
L"\\EFI\\BOOT\\GRUBLOONGARCH64.EFI",
L"\\EFI\\BOOT\\BOOTLOONGARCH64.EFI",
L"\\EFI\\BOOT\\bootloongarch64.efi",
L"\\efi\\boot\\bootloongarch64.efi",
#endif

};
Expand Down Expand Up @@ -503,10 +508,15 @@ STATIC EFI_STATUS EFIAPI ventoy_load_image
)
{
EFI_STATUS Status = EFI_SUCCESS;
CHAR16 TmpBuf[256] = {0};
CHAR16 TmpBuf[256];
UINT8 i;
FILEPATH_DEVICE_PATH *pFilePath = NULL;
EFI_DEVICE_PATH_PROTOCOL *pImgPath = NULL;

for (i = 0; i < 256; i++)
{
TmpBuf[i] = 0;
}
pFilePath = (FILEPATH_DEVICE_PATH *)TmpBuf;
pFilePath->Header.Type = MEDIA_DEVICE_PATH;
pFilePath->Header.SubType = MEDIA_FILEPATH_DP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ typedef struct ventoy_virt_chunk
#define VENTOY_UEFI_DESC L"ARM64 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_aa64.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_aa64.efi"
#elif defined (MDE_CPU_LOONGARCH64)
#define VENTOY_UEFI_DESC L"LOONGARCH64 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_la64.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_la64.efi"
#else
#error Unknown Processor Type
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,12 @@ STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector
UINT32 i = 0;
UINTN secLeft = 0;
UINTN secRead = 0;
UINT64 ReadStart = 0;
UINT64 ReadEnd = 0;
UINT8 *pCurBuf = (UINT8 *)Buffer;
ventoy_img_chunk *pchunk = g_chunk;
EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo;

debug("write iso sector %lu count %u", Sector, Count);

ReadStart = Sector * 2048;
ReadEnd = (Sector + Count) * 2048;

for (i = 0; Count > 0 && i < g_img_chunk_num; i++, pchunk++)
{
if (Sector >= pchunk->img_start_sector && Sector <= pchunk->img_end_sector)
Expand Down Expand Up @@ -603,7 +598,6 @@ EFI_STATUS EFIAPI ventoy_block_io_write
)
{
UINT32 secNum = 0;
UINT64 offset = 0;

(VOID)This;
(VOID)MediaId;
Expand All @@ -614,7 +608,6 @@ EFI_STATUS EFIAPI ventoy_block_io_write
}

secNum = BufferSize / 2048;
offset = Lba * 2048;

return ventoy_write_iso_sector(Lba, secNum, Buffer);
}
Expand Down Expand Up @@ -673,13 +666,18 @@ EFI_STATUS EFIAPI ventoy_fill_device_path(VOID)
{
UINTN CurVtoyDpId = 0;
UINTN NameLen = 0;
UINT8 TmpBuf[128] = {0};
UINT8 TmpBuf[128];
UINT8 i;
VENDOR_DEVICE_PATH *venPath = NULL;
CHAR16 VtoyDpName[32];

CurVtoyDpId = ventoy_get_current_device_path_id();
UnicodeSPrintAsciiFormat(VtoyDpName, sizeof(VtoyDpName), "ventoy_%03lu", CurVtoyDpId);

for (i = 0; i < 128; i++)
{
TmpBuf[i] = 0;
}
venPath = (VENDOR_DEVICE_PATH *)TmpBuf;
NameLen = StrSize(VtoyDpName);
venPath->Header.Type = HARDWARE_DEVICE_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
PLATFORM_VERSION = 0.98
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/MdeModule
SUPPORTED_ARCHITECTURES = IA32|X64|EBC|ARM|AARCH64
SUPPORTED_ARCHITECTURES = IA32|X64|EBC|ARM|AARCH64|LOONGARCH64
BUILD_TARGETS = DEBUG|RELEASE|NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand Down
Loading