Mercurial > hg > Gears > UEFIloader
changeset 1:cbcaeba32076
add shellscript
author | nana |
---|---|
date | Tue, 11 Apr 2023 11:50:25 +0900 |
parents | f434d6ab8db1 |
children | 4cca1b408702 |
files | README.md bootloader.c gnu-efi-3.0.12/apps/bootloader.c run-aauefi.sh run-uefi.sh start_singularity.sh xv6-uefi.def |
diffstat | 7 files changed, 110 insertions(+), 87 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Tue Apr 11 11:50:25 2023 +0900 @@ -0,0 +1,13 @@ +# +``` +cd /mnt/ssd1/user/one/src/xv6-UEFI +singularity shell --shell /bin/zsh -f -B /mnt/ssd1/user/one/src/xv6-UEFI:/xv6-UEFI xv6-uefi.sif + ++xv6-uefi.sif+root sh run-uefi.sh +``` + +make apps in gnu +``` +cd gnu-efi-3.0.12 +make -k CROSS_COMPILE=arm-linux-gnueabihf- CFLAGS="-fno-stack-protector -Werror=implicit-fallthrough=0" apps +```
--- a/bootloader.c Tue Apr 11 11:12:12 2023 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -#include<efi.h> -#include<efilib.h> - - -EFI_STATUS -efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) -{ - - // UINTN UartBase = 0x09000000; - // UINTN UartClk = 24000000; - //CHAR8 buffer[256]; - //UINTN bufferSize; - - EFI_DEVICE_PATH *Path; - EFI_LOADED_IMAGE *LoadedImageParent; - EFI_LOADED_IMAGE *LoadedImage; - EFI_HANDLE Image; - CHAR16 *Options = L"root=/dev/sda2 rootfstype=btrfs rw quiet splash"; - EFI_STATUS Status=EFI_SUCCESS; - - InitializeLib(ImageHandle, SystemTable); - Print(L"Hello, EFI!\n"); - -// Status = InitializeUart(UartBase, UartClk); -// if (EFI_ERROR(Status)) { -// Print(L"Error initializing UART device: %r\n", Status); -// return Status; -// } -// Print(L"Hello, UART1!\n"); - - // Read kernel image from UART -// bufferSize = sizeof(buffer); -// Status = ReadUart(UartBase, &bufferSize, buffer); -// if (EFI_ERROR(Status)) { -// Print(L"Error reading kernel image from UART: %r\n", Status); -// return Status; -// } - -// Print(L"Hello, UART2!\n"); - -// Status = uefi_call_wrapper(BS->OpenProtocol, 6, ImageHandle, &LoadedImageProtocol,(void**)&LoadedImageParent, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); -// if (EFI_ERROR(Status)) { -// Print(L"Could not get LoadedImageProtocol handler %r\n", Status); -// return Status; -// } - - // Check the validity of the received data -// if (!validate_image(buffer, bufferSize)) { -// Print(L"Invalid kernel image received\n"); -// return EFI_INVALID_PARAMETER; -// } - - - Print(L"Hello,2!\n"); - Path = FileDevicePath(LoadedImageParent->DeviceHandle, L"\\kernel.elf"); - if (Path == NULL) { - Print(L"Could not get device path."); - return EFI_INVALID_PARAMETER; - } - Print(L"Hello,3!\n"); - Status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, ImageHandle, Path, NULL, 0, &Image); - if (EFI_ERROR(Status)) { - Print(L"Could not load %r", Status); - FreePool(Path); - return Status; - } - Print(L"Hello,4!\n"); - Status = uefi_call_wrapper(BS->OpenProtocol, 6, Image, &LoadedImageProtocol, (void**)&LoadedImage, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (EFI_ERROR(Status)) { - Print(L"Could not get LoadedImageProtocol handler %r\n", Status); - uefi_call_wrapper(BS->UnloadImage, 1, Image); - FreePool(Path); - return Status; - } - Print(L"Hello,5!\n"); - LoadedImage->LoadOptions = Options; - LoadedImage->LoadOptionsSize = (StrLen(LoadedImage->LoadOptions)+1) * sizeof(CHAR16); - - Print(L"Hello,6!\n"); - Status = uefi_call_wrapper(BS->StartImage, 3, Image, NULL, NULL); - uefi_call_wrapper(BS->UnloadImage, 1, Image); - FreePool(Path); - Print(L"Hello,7!\n"); - - return EFI_SUCCESS; -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnu-efi-3.0.12/apps/bootloader.c Tue Apr 11 11:50:25 2023 +0900 @@ -0,0 +1,55 @@ +#include<efi.h> +#include<efilib.h> + + +EFI_STATUS +efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) +{ + EFI_DEVICE_PATH *Path; + EFI_LOADED_IMAGE *LoadedImageParent; + EFI_LOADED_IMAGE *LoadedImage; + EFI_HANDLE Image; + CHAR16 *Options = L"root=/dev/sda2 rootfstype=btrfs rw quiet splash"; + EFI_STATUS Status=EFI_SUCCESS; + + InitializeLib(ImageHandle, SystemTable); + Print(L"Hello, EFI!\n"); + + Status = uefi_call_wrapper(BS->OpenProtocol, 6, ImageHandle, &LoadedImageProtocol,(void**)&LoadedImageParent, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR(Status)) { + Print(L"Could not get LoadedImageProtocol handler %r\n", Status); + return Status; + } + Print(L"Hello,2!\n"); + Path = FileDevicePath(LoadedImageParent->DeviceHandle, L"\\OS"); + if (Path == NULL) { + Print(L"Could not get device path."); + return EFI_INVALID_PARAMETER; + } + Print(L"Hello,3!\n"); + Status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, ImageHandle, Path, NULL, 0, &Image); + if (EFI_ERROR(Status)) { + Print(L"Could not load %r", Status); + FreePool(Path); + return Status; + } + Print(L"Hello,4!\n"); + Status = uefi_call_wrapper(BS->OpenProtocol, 6, Image, &LoadedImageProtocol, (void**)&LoadedImage, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR(Status)) { + Print(L"Could not get LoadedImageProtocol handler %r\n", Status); + uefi_call_wrapper(BS->UnloadImage, 1, Image); + FreePool(Path); + return Status; + } + Print(L"Hello,5!\n"); + LoadedImage->LoadOptions = Options; + LoadedImage->LoadOptionsSize = (StrLen(LoadedImage->LoadOptions)+1) * sizeof(CHAR16); + + Print(L"Hello,6!\n"); + Status = uefi_call_wrapper(BS->StartImage, 3, Image, NULL, NULL); + uefi_call_wrapper(BS->UnloadImage, 1, Image); + FreePool(Path); + Print(L"Hello,7!\n"); + + return EFI_SUCCESS; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run-aauefi.sh Tue Apr 11 11:50:25 2023 +0900 @@ -0,0 +1,6 @@ + qemu-system-aarch64 -m 128 \ + -M virt \ + -bios ./QEMU_EFI_DBG.fd \ + -drive format=raw,file=fat:rw:gnu-efi-3.0.12/arm/apps \ + -net none \ + -nographic
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run-uefi.sh Tue Apr 11 11:50:25 2023 +0900 @@ -0,0 +1,6 @@ + qemu-system-arm -m 128 \ + -M virt \ + -bios ./QEMU_EFI_DBG.fd \ + -drive format=raw,file=fat:rw:gnu-efi-3.0.12/arm/apps \ + -net none \ + -nographic
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/start_singularity.sh Tue Apr 11 11:50:25 2023 +0900 @@ -0,0 +1,1 @@ +singularity shell --shell /bin/zsh -f -B /mnt/ssd1/user/one/src/xv6-UEFI:/xv6-UEFI xv6-uefi.sif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xv6-uefi.def Tue Apr 11 11:50:25 2023 +0900 @@ -0,0 +1,29 @@ +BootStrap: docker +From: ubuntu:22.04 + +%post + apt-get update + apt-get upgrade -y + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y \ + qemu-utils \ + qemu-efi-aarch64 \ + qemu-system-arm \ + build-essential \ + uuid-dev \ + git \ + tzdata \ + mercurial \ + python3-pip \ + iasl \ + nasm \ + zsh \ + vim \ + wget + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y \ + crossbuild-essential-armhf + cd /usr/local/src + git clone --recursive https://github.com/tianocore/edk2 + wget "https://sourceforge.net/projects/gnu-efi/files/gnu-efi-3.0.12.tar.bz2/download" + tar xf download