mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2025-01-21 20:51:31 +01:00
Merge branch 'master' of https://github.com/CloverHackyColor/CloverBootloader
This commit is contained in:
commit
b71e22c298
@ -2575,7 +2575,7 @@ RELEASE_XCODE8_*_MTOC_FLAGS = -align 0x20
|
||||
##################
|
||||
# X64 definitions
|
||||
##################
|
||||
DEBUG_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x260,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
|
||||
DEBUG_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x260,-object_path_lto,$(DEST_DIR_DEBUG)/$(BASE_NAME).o,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
|
||||
DEBUGMACOS_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x800,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
|
||||
RELEASE_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x260,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
|
||||
RELEASEMACOS_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAGE_ENTRY_POINT),-e,_$(IMAGE_ENTRY_POINT),-preload,-segalign,0x20,-pie,-all_load,-dead_strip,-seg1addr,0x800,-map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
|
||||
|
158
Qemu/gdb_x8_launch
Executable file
158
Qemu/gdb_x8_launch
Executable file
@ -0,0 +1,158 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_ABS_FILENAME=`LC_ALL=en_US.ISO8859-1 perl -e 'use Cwd "abs_path";print abs_path(shift)' "${BASH_SOURCE[0]}"`
|
||||
SCRIPT_DIR=`dirname "$SCRIPT_ABS_FILENAME"`
|
||||
|
||||
# we can't cd "$SCRIPT_DIR" because the 1st arg maybe a relative path to the current dir (and NOT relative to the SCRIPT_DIR)
|
||||
|
||||
OSTYPE=`uname -s`
|
||||
#echo $OSTYPE
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
if [ -f "${1%.*}".debug ]
|
||||
then
|
||||
clover_debug_file="${1%.*}".debug
|
||||
echo Using debug file "$clover_debug_file"
|
||||
else
|
||||
if [ -f "${1%.*}".dll.dSYM ]
|
||||
then
|
||||
clover_debug_file="${1%.*}".dll.dSYM
|
||||
echo Using debug file "$clover_debug_file"
|
||||
else
|
||||
echo "Usage: $SCRIPT_ABS_FILENAME [Clover debug file]"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
clover_debug_file="${1%.*}".dll.dSYM
|
||||
fi
|
||||
|
||||
clover_debug_file="${1%.*}".dll.dSYM
|
||||
clover_efi_file="${1%.*}".efi
|
||||
|
||||
#if ! [ -f "$clover_debug_file" ]
|
||||
#then
|
||||
# echo Debug file "$clover_debug_file" doesn\'t exist
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
#clover_efi_file="${clover_debug_file%.*}".efi
|
||||
#if ! [ -f "$clover_efi_file" ]
|
||||
#then
|
||||
# echo Efi file "$clover_efi_file" doesn\'t exist
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
echo clover_debug_file="$clover_debug_file"
|
||||
echo clover_efi_file="$clover_efi_file"
|
||||
|
||||
#qemu_path="$SCRIPT_DIR"/qemu_portable-v4.2.0/qemu-system-x86_64
|
||||
qemu_path="$SCRIPT_DIR"/qemu_portable-v5.2.0/qemu-system-x86_64
|
||||
#set -x
|
||||
|
||||
if [ "$OSTYPE" = "Darwin" ]
|
||||
then
|
||||
if ! [ -f "$qemu_path" ]
|
||||
then
|
||||
echo "You must restore the folder \'"$(dirname "$qemu_path")"\'"
|
||||
exit 1
|
||||
fi
|
||||
if ! [ -f "$SCRIPT_DIR"/disk_image_gpt.img ]
|
||||
then
|
||||
unzip -o "$SCRIPT_DIR"/disk_image_gpt.img.zip -d "$SCRIPT_DIR"
|
||||
rm -rf "$SCRIPT_DIR"/__MACOSX
|
||||
fi
|
||||
|
||||
if pgrep qemu
|
||||
then
|
||||
killall qemu-system-x86_64
|
||||
fi
|
||||
> "$SCRIPT_DIR"/serial0_qemu_out.log # empty file without erasing it. Useful for editor for refreshing and reloading.
|
||||
|
||||
hdiutil attach "$SCRIPT_DIR"/disk_image_gpt.img || exit 1
|
||||
|
||||
shopt -s nocasematch
|
||||
|
||||
if [[ "$(basename "$clover_debug_file")" =~ "CloverX64"* ]]
|
||||
then
|
||||
echo ditto "${clover_efi_file}" /Volumes/QEMU_EFI/EFI/CLOVER/CLOVERX64.efi
|
||||
ditto "${clover_efi_file}" /Volumes/QEMU_EFI/EFI/CLOVER/CLOVERX64.efi || exit 1
|
||||
|
||||
#no need to replace BootX64.efi, it's not used in legacy boot
|
||||
else
|
||||
: # TODO : if it's a module, has to be copied in Drivers
|
||||
fi
|
||||
|
||||
shopt -u nocasematch
|
||||
|
||||
diskutil eject /Volumes/QEMU_EFI || exit 1
|
||||
|
||||
sleep 1 # not 100% sure it's needed
|
||||
set -m
|
||||
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
bios_file=("$(dirname "$qemu_path")"/bios*)
|
||||
|
||||
"$qemu_path" \
|
||||
-L "$(dirname "$qemu_path")" \
|
||||
-m 2048 \
|
||||
-cpu Penryn \
|
||||
-bios "$bios_file" \
|
||||
-machine q35 \
|
||||
-device ahci,id=ahi \
|
||||
-drive format=raw,id=hda,file=./disk_image_gpt.img \
|
||||
-usb \
|
||||
-device usb-mouse,bus=usb-bus.0,port=2 \
|
||||
-device usb-kbd,bus=usb-bus.0,port=1 \
|
||||
-serial file:./serial0_qemu_out.log \
|
||||
-gdb tcp::9000 &
|
||||
[[ $? == 0 ]] || exit 1
|
||||
|
||||
set +m
|
||||
|
||||
count=1
|
||||
timeout=60
|
||||
image_base_str="CloverX64 : Image base = "
|
||||
|
||||
getImageBase() {
|
||||
[ -f ./serial0_qemu_out.log ] || return 1
|
||||
grep "$image_base_str" ./serial0_qemu_out.log
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
while [ $count -le $timeout ] && ! getImageBase
|
||||
do
|
||||
sleep 1
|
||||
count=$((count+1))
|
||||
done
|
||||
|
||||
if [ $count -ge $timeout ]
|
||||
then
|
||||
echo Cannot find "\"Clover : Image base = \"" in ./serial0_qemu_out.log after $timeout seconds
|
||||
exit 1
|
||||
fi
|
||||
|
||||
adr="$(grep "$image_base_str" ./serial0_qemu_out.log | awk '{printf "0x%x",$NF}')"
|
||||
echo adr="$adr"
|
||||
|
||||
GDB=gdb
|
||||
if [ -f ../../../toolchain.gdb/gdb ]
|
||||
then
|
||||
GDB=../../../toolchain.gdb/gdb
|
||||
fi
|
||||
|
||||
"$GDB" --eval-command="file "$clover_debug_file" -o $adr" \
|
||||
--eval-command="target remote localhost:9000" \
|
||||
--eval-command="rwatch *0" \
|
||||
--eval-command="br panic_" \
|
||||
--eval-command="continue"
|
||||
|
||||
|
||||
exit 0
|
||||
|
||||
|
||||
|
||||
fi
|
||||
|
@ -29,9 +29,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#endif
|
||||
|
||||
#if PATCH_DEBUG
|
||||
#define DBG(...) printf(__VA_ARGS__);
|
||||
#define DBG(...) printf(__VA_ARGS__);
|
||||
#else
|
||||
#define DBG(...)
|
||||
#define DBG(...)
|
||||
#endif
|
||||
|
||||
////
|
||||
@ -87,28 +87,28 @@ void CorrectMemoryMap(IN UINT32 memMap,
|
||||
IN UINT32 memDescriptorSize,
|
||||
IN OUT UINT32 *memMapSize)
|
||||
{
|
||||
EfiMemoryRange* memDescriptor;
|
||||
UINT64 Bytes;
|
||||
UINT32 Index;
|
||||
EfiMemoryRange* memDescriptor;
|
||||
UINT64 Bytes;
|
||||
UINT32 Index;
|
||||
CHAR16 tmp[80];
|
||||
EFI_INPUT_KEY Key;
|
||||
// UINTN ind;
|
||||
//
|
||||
//step 1. Check for last empty descriptors
|
||||
//
|
||||
//
|
||||
//step 1. Check for last empty descriptors
|
||||
//
|
||||
// PauseForKey(L"Check for last empty descriptors");
|
||||
// gST->ConOut->OutputString (gST->ConOut, L"Check for last empty descriptors\n\r");
|
||||
// gBS->Stall(2000000);
|
||||
memDescriptor = (EfiMemoryRange *)(UINTN)(memMap + *memMapSize - memDescriptorSize);
|
||||
while ((memDescriptor->NumberOfPages == 0) || (memDescriptor->NumberOfPages > (1<<25)))
|
||||
{
|
||||
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor - memDescriptorSize);
|
||||
*memMapSize -= memDescriptorSize;
|
||||
}
|
||||
//
|
||||
//step 2. Add last desc about MEM4GB
|
||||
//
|
||||
/* if (gTotalMemory > MEM4GB) {
|
||||
memDescriptor = (EfiMemoryRange *)(UINTN)(memMap + *memMapSize - memDescriptorSize);
|
||||
while ((memDescriptor->NumberOfPages == 0) || (memDescriptor->NumberOfPages > (1<<25)))
|
||||
{
|
||||
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor - memDescriptorSize);
|
||||
*memMapSize -= memDescriptorSize;
|
||||
}
|
||||
//
|
||||
//step 2. Add last desc about MEM4GB
|
||||
//
|
||||
/* if (gTotalMemory > MEM4GB) {
|
||||
//next descriptor
|
||||
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor + memDescriptorSize);
|
||||
memDescriptor->Type = EfiConventionalMemory;
|
||||
@ -118,7 +118,7 @@ void CorrectMemoryMap(IN UINT32 memMap,
|
||||
memDescriptor->Attribute = 0;
|
||||
*memMapSize += memDescriptorSize;
|
||||
}
|
||||
*/
|
||||
*/
|
||||
memDescriptor = (EfiMemoryRange *)(UINTN)memMap;
|
||||
for (Index = 0; Index < *memMapSize / memDescriptorSize; Index ++) {
|
||||
//
|
||||
@ -177,17 +177,17 @@ void CorrectMemoryMap(IN UINT32 memMap,
|
||||
*memMapSize += memDescriptorSize;
|
||||
|
||||
|
||||
if(MEM_DEB) {
|
||||
if(MEM_DEB) {
|
||||
gST->ConOut->OutputString (gST->ConOut, L"press any key to dump MemoryMap\r\n");
|
||||
// gBS->Stall(2000000);
|
||||
WaitForSingleEvent (gST->ConIn->WaitForKey, 0);
|
||||
|
||||
gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
||||
|
||||
// PauseForKey(L"press any key to dump MemoryMap");
|
||||
memDescriptor = (EfiMemoryRange *)(UINTN)memMap;
|
||||
for (Index = 0; Index < *memMapSize / memDescriptorSize; Index ++) {
|
||||
Bytes = LShiftU64 (memDescriptor->NumberOfPages, 12);
|
||||
|
||||
// PauseForKey(L"press any key to dump MemoryMap");
|
||||
memDescriptor = (EfiMemoryRange *)(UINTN)memMap;
|
||||
for (Index = 0; Index < *memMapSize / memDescriptorSize; Index ++) {
|
||||
Bytes = LShiftU64 (memDescriptor->NumberOfPages, 12);
|
||||
snwprintf(tmp, 160, "%lX-%lX pages %lX type %lX attr %hhX \r\n\r\t",
|
||||
memDescriptor->PhysicalStart,
|
||||
memDescriptor->PhysicalStart + Bytes - 1,
|
||||
@ -198,9 +198,9 @@ void CorrectMemoryMap(IN UINT32 memMap,
|
||||
gST->ConOut->OutputString (gST->ConOut, tmp);
|
||||
// gBS->Stall(2000000);
|
||||
|
||||
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor + memDescriptorSize);
|
||||
if (Index % 20 == 19) {
|
||||
gST->ConOut->OutputString (gST->ConOut, L"press any key\r\n");
|
||||
memDescriptor = (EfiMemoryRange *)((UINTN)memDescriptor + memDescriptorSize);
|
||||
if (Index % 20 == 19) {
|
||||
gST->ConOut->OutputString (gST->ConOut, L"press any key\r\n");
|
||||
WaitForSingleEvent (gST->ConIn->WaitForKey, 0);
|
||||
// gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
||||
/* if (ReadAllKeyStrokes()) { // remove buffered key strokes
|
||||
@ -212,10 +212,10 @@ void CorrectMemoryMap(IN UINT32 memMap,
|
||||
ReadAllKeyStrokes(); // empty the buffer to protect the menu
|
||||
WaitForCR();
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -257,26 +257,26 @@ OnExitBootServices(IN EFI_EVENT Event, IN void *Context)
|
||||
*/
|
||||
|
||||
gST->ConOut->OutputString (gST->ConOut, L"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
|
||||
//
|
||||
// Patch kernel and kexts if needed
|
||||
//
|
||||
//
|
||||
// Patch kernel and kexts if needed
|
||||
//
|
||||
// Jief : OpenCore is doing the kernel patching for all versions.
|
||||
// LOADER_ENTRY *Entry = ((REFIT_ABSTRACT_MENU_ENTRY*)Context)->getLOADER_ENTRY();
|
||||
// if ( Entry && Entry->OSVersion.startWith("10") ) {
|
||||
// if ( Entry && Entry->OSVersion.startWith("10") ) {
|
||||
// Entry->KernelAndKextsPatcherStart();
|
||||
// }
|
||||
|
||||
|
||||
#if 0 //it will be as a sample of possible patches in future
|
||||
// gBS->Stall(2000000);
|
||||
//PauseForKey(L"press any key to MemoryFix");
|
||||
if (gSettings.MemoryFix) {
|
||||
BootArgs1* bootArgs1v;
|
||||
BootArgs2* bootArgs2v;
|
||||
UINT8* ptr=(UINT8*)(UINTN)0x100000;
|
||||
// DTEntry efiPlatform;
|
||||
// CHAR8* dtreeRoot;
|
||||
UINTN archMode = sizeof(UINTN) * 8;
|
||||
UINTN Version = 0;
|
||||
//PauseForKey(L"press any key to MemoryFix");
|
||||
if (gSettings.MemoryFix) {
|
||||
BootArgs1* bootArgs1v;
|
||||
BootArgs2* bootArgs2v;
|
||||
UINT8* ptr=(UINT8*)(UINTN)0x100000;
|
||||
// DTEntry efiPlatform;
|
||||
// CHAR8* dtreeRoot;
|
||||
UINTN archMode = sizeof(UINTN) * 8;
|
||||
UINTN Version = 0;
|
||||
|
||||
while(true)
|
||||
{
|
||||
@ -318,7 +318,7 @@ OnExitBootServices(IN EFI_EVENT Event, IN void *Context)
|
||||
// DBG("bootArgs not found!\n");
|
||||
gST->ConOut->OutputString (gST->ConOut, L"bootArgs not found!");
|
||||
gBS->Stall(5000000);
|
||||
// return;
|
||||
// return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -334,12 +334,12 @@ OnExitBootServices(IN EFI_EVENT Event, IN void *Context)
|
||||
&bootArgs1v->MemoryMapSize);
|
||||
// bootArgs1v->efiSystemTable = (UINT32)(UINTN)gST;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (gSettings.Devices.USB.USBFixOwnership) {
|
||||
if (gSettings.Devices.USB.USBFixOwnership) {
|
||||
FixOwnership();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -381,44 +381,44 @@ OnSimpleFileSystem (
|
||||
IN void *Context
|
||||
)
|
||||
{
|
||||
EFI_TPL OldTpl;
|
||||
|
||||
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
|
||||
gEvent = 1;
|
||||
// ReinitRefitLib();
|
||||
//ScanVolumes();
|
||||
//enter GUI
|
||||
// DrawMenuText(L"OnSimpleFileSystem", 0, 0, UGAHeight-40, 1);
|
||||
// MsgLog("OnSimpleFileSystem occured\n");
|
||||
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
|
||||
EFI_TPL OldTpl;
|
||||
|
||||
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
|
||||
gEvent = 1;
|
||||
// ReinitRefitLib();
|
||||
//ScanVolumes();
|
||||
//enter GUI
|
||||
// DrawMenuText(L"OnSimpleFileSystem", 0, 0, UGAHeight-40, 1);
|
||||
// MsgLog("OnSimpleFileSystem occured\n");
|
||||
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
GuiEventsInitialize ()
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_EVENT Event;
|
||||
void* RegSimpleFileSystem = NULL;
|
||||
|
||||
gEvent = 0;
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_NOTIFY_SIGNAL,
|
||||
TPL_NOTIFY,
|
||||
OnSimpleFileSystem,
|
||||
NULL,
|
||||
&Event);
|
||||
if(!EFI_ERROR(Status))
|
||||
{
|
||||
Status = gBS->RegisterProtocolNotify (
|
||||
&gEfiSimpleFileSystemProtocolGuid,
|
||||
Event,
|
||||
&RegSimpleFileSystem);
|
||||
}
|
||||
|
||||
|
||||
return Status;
|
||||
EFI_STATUS Status;
|
||||
EFI_EVENT Event;
|
||||
void* RegSimpleFileSystem = NULL;
|
||||
|
||||
gEvent = 0;
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_NOTIFY_SIGNAL,
|
||||
TPL_NOTIFY,
|
||||
OnSimpleFileSystem,
|
||||
NULL,
|
||||
&Event);
|
||||
if(!EFI_ERROR(Status))
|
||||
{
|
||||
Status = gBS->RegisterProtocolNotify (
|
||||
&gEfiSimpleFileSystemProtocolGuid,
|
||||
Event,
|
||||
&RegSimpleFileSystem);
|
||||
}
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
//EFI_STATUS
|
||||
@ -517,141 +517,141 @@ WaitFor2EventWithTsc (
|
||||
EFI_STATUS
|
||||
EventsInitialize (IN LOADER_ENTRY *Entry)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
void* Registration = NULL;
|
||||
|
||||
//
|
||||
// Register the event to reclaim variable for OS usage.
|
||||
//
|
||||
//EfiCreateEventReadyToBoot(&OnReadyToBootEvent);
|
||||
/* EfiCreateEventReadyToBootEx (
|
||||
TPL_NOTIFY,
|
||||
OnReadyToBoot,
|
||||
NULL,
|
||||
&OnReadyToBootEvent
|
||||
); */
|
||||
|
||||
//
|
||||
// Register notify for exit boot services
|
||||
//
|
||||
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES,
|
||||
TPL_CALLBACK,
|
||||
OnExitBootServices,
|
||||
Entry,
|
||||
&ExitBootServiceEvent);
|
||||
EFI_STATUS Status;
|
||||
void* Registration = NULL;
|
||||
|
||||
if(!EFI_ERROR(Status))
|
||||
{
|
||||
/*Status = */gBS->RegisterProtocolNotify (
|
||||
//
|
||||
// Register the event to reclaim variable for OS usage.
|
||||
//
|
||||
//EfiCreateEventReadyToBoot(&OnReadyToBootEvent);
|
||||
/* EfiCreateEventReadyToBootEx (
|
||||
TPL_NOTIFY,
|
||||
OnReadyToBoot,
|
||||
NULL,
|
||||
&OnReadyToBootEvent
|
||||
); */
|
||||
|
||||
//
|
||||
// Register notify for exit boot services
|
||||
//
|
||||
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES,
|
||||
TPL_CALLBACK,
|
||||
OnExitBootServices,
|
||||
Entry,
|
||||
&ExitBootServiceEvent);
|
||||
|
||||
if(!EFI_ERROR(Status))
|
||||
{
|
||||
/*Status = */gBS->RegisterProtocolNotify (
|
||||
&gEfiStatusCodeRuntimeProtocolGuid,
|
||||
ExitBootServiceEvent,
|
||||
&Registration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Register the event to convert the pointer for runtime.
|
||||
//
|
||||
//
|
||||
// Register the event to convert the pointer for runtime.
|
||||
//
|
||||
/*
|
||||
gBS->CreateEventEx (
|
||||
EVT_NOTIFY_SIGNAL,
|
||||
TPL_NOTIFY,
|
||||
VirtualAddressChangeEvent,
|
||||
NULL,
|
||||
&gEfiEventVirtualAddressChangeGuid,
|
||||
&mVirtualAddressChangeEvent
|
||||
);
|
||||
gBS->CreateEventEx (
|
||||
EVT_NOTIFY_SIGNAL,
|
||||
TPL_NOTIFY,
|
||||
VirtualAddressChangeEvent,
|
||||
NULL,
|
||||
&gEfiEventVirtualAddressChangeGuid,
|
||||
&mVirtualAddressChangeEvent
|
||||
);
|
||||
*/
|
||||
// and what if EFI_ERROR?
|
||||
return Status;
|
||||
// and what if EFI_ERROR?
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS EjectVolume(IN REFIT_VOLUME *Volume)
|
||||
{
|
||||
EFI_SCSI_IO_PROTOCOL *ScsiIo = NULL;
|
||||
EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
|
||||
// UINT64 Lun = 0;
|
||||
// UINT8 *Target;
|
||||
// UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
|
||||
EFI_STATUS Status; // = EFI_UNSUPPORTED;
|
||||
UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];
|
||||
USB_MASS_DEVICE *UsbMass = NULL;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlkIo = NULL;
|
||||
EFI_BLOCK_IO_MEDIA *Media;
|
||||
UINT32 Timeout;
|
||||
UINT32 CmdResult;
|
||||
EFI_SCSI_IO_PROTOCOL *ScsiIo = NULL;
|
||||
EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
|
||||
// UINT64 Lun = 0;
|
||||
// UINT8 *Target;
|
||||
// UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];
|
||||
EFI_STATUS Status; // = EFI_UNSUPPORTED;
|
||||
UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];
|
||||
USB_MASS_DEVICE *UsbMass = NULL;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlkIo = NULL;
|
||||
EFI_BLOCK_IO_MEDIA *Media;
|
||||
UINT32 Timeout;
|
||||
UINT32 CmdResult;
|
||||
|
||||
//
|
||||
// Initialize SCSI REQUEST_PACKET and 6-byte Cdb
|
||||
//
|
||||
ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
|
||||
ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
|
||||
|
||||
Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiScsiIoProtocolGuid, (void **) &ScsiIo);
|
||||
if (ScsiIo) {
|
||||
// Target = &TargetArray[0];
|
||||
// ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
|
||||
|
||||
|
||||
Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT;
|
||||
// Cdb[1] = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
|
||||
// Cdb[1] |= 0x01;
|
||||
Cdb[1] = 0x01;
|
||||
Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC;
|
||||
CommandPacket.Timeout = EFI_TIMER_PERIOD_SECONDS (3);
|
||||
CommandPacket.Cdb = Cdb;
|
||||
CommandPacket.CdbLength = (UINT8) sizeof (Cdb);
|
||||
//
|
||||
// Initialize SCSI REQUEST_PACKET and 6-byte Cdb
|
||||
//
|
||||
ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));
|
||||
ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);
|
||||
|
||||
Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiScsiIoProtocolGuid, (void **) &ScsiIo);
|
||||
if (ScsiIo) {
|
||||
// Target = &TargetArray[0];
|
||||
// ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);
|
||||
|
||||
Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
|
||||
} else {
|
||||
Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiBlockIoProtocolGuid, (void **) &BlkIo);
|
||||
if (BlkIo) {
|
||||
UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlkIo);
|
||||
if (!UsbMass) {
|
||||
MsgLog("no UsbMass\n");
|
||||
Status = EFI_NOT_FOUND;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
Media = &UsbMass->BlockIoMedia;
|
||||
if (!Media) {
|
||||
MsgLog("no BlockIoMedia\n");
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// If it is a removable media, such as CD-Rom or Usb-Floppy,
|
||||
// need to detect the media before each read/write. While some of
|
||||
// Usb-Flash is marked as removable media.
|
||||
//
|
||||
//TODO - DetectMedia will appear automatically. Do nothing?
|
||||
if (!Media->RemovableMedia) {
|
||||
//Status = UsbBootDetectMedia (UsbMass);
|
||||
// if (EFI_ERROR(Status)) {
|
||||
Status = EFI_UNSUPPORTED;
|
||||
|
||||
Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT;
|
||||
// Cdb[1] = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
|
||||
// Cdb[1] |= 0x01;
|
||||
Cdb[1] = 0x01;
|
||||
Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC;
|
||||
CommandPacket.Timeout = EFI_TIMER_PERIOD_SECONDS (3);
|
||||
CommandPacket.Cdb = Cdb;
|
||||
CommandPacket.CdbLength = (UINT8) sizeof (Cdb);
|
||||
|
||||
Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);
|
||||
} else {
|
||||
Status = gBS->HandleProtocol(Volume->DeviceHandle, &gEfiBlockIoProtocolGuid, (void **) &BlkIo);
|
||||
if (BlkIo) {
|
||||
UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlkIo);
|
||||
if (!UsbMass) {
|
||||
MsgLog("no UsbMass\n");
|
||||
Status = EFI_NOT_FOUND;
|
||||
goto ON_EXIT;
|
||||
// }
|
||||
}
|
||||
|
||||
if (!(Media->MediaPresent)) {
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
//TODO - remember previous state
|
||||
/* if (MediaId != Media->MediaId) {
|
||||
}
|
||||
Media = &UsbMass->BlockIoMedia;
|
||||
if (!Media) {
|
||||
MsgLog("no BlockIoMedia\n");
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// If it is a removable media, such as CD-Rom or Usb-Floppy,
|
||||
// need to detect the media before each read/write. While some of
|
||||
// Usb-Flash is marked as removable media.
|
||||
//
|
||||
//TODO - DetectMedia will appear automatically. Do nothing?
|
||||
if (!Media->RemovableMedia) {
|
||||
//Status = UsbBootDetectMedia (UsbMass);
|
||||
// if (EFI_ERROR(Status)) {
|
||||
Status = EFI_UNSUPPORTED;
|
||||
goto ON_EXIT;
|
||||
// }
|
||||
}
|
||||
|
||||
if (!(Media->MediaPresent)) {
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
//TODO - remember previous state
|
||||
/* if (MediaId != Media->MediaId) {
|
||||
Status = EFI_MEDIA_CHANGED;
|
||||
goto ON_EXIT;
|
||||
}*/
|
||||
|
||||
Timeout = USB_BOOT_GENERAL_CMD_TIMEOUT;
|
||||
Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT;
|
||||
// Cdb[1] = (UINT8) (USB_BOOT_LUN(UsbMass->Lun) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
|
||||
// Cdb[1] |= 0x01;
|
||||
|
||||
Timeout = USB_BOOT_GENERAL_CMD_TIMEOUT;
|
||||
Cdb[0] = EFI_SCSI_OP_START_STOP_UNIT;
|
||||
// Cdb[1] = (UINT8) (USB_BOOT_LUN(UsbMass->Lun) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);
|
||||
// Cdb[1] |= 0x01;
|
||||
Cdb[1] = 0x01;
|
||||
Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC; //eject command.
|
||||
// Status = EFI_UNSUPPORTED;
|
||||
Status = UsbMass->Transport->ExecCommand (
|
||||
Cdb[4] = ATA_CMD_SUBOP_EJECT_DISC; //eject command.
|
||||
// Status = EFI_UNSUPPORTED;
|
||||
Status = UsbMass->Transport->ExecCommand (
|
||||
UsbMass->Context,
|
||||
&Cdb,
|
||||
sizeof(Cdb),
|
||||
@ -662,10 +662,10 @@ EFI_STATUS EjectVolume(IN REFIT_VOLUME *Volume)
|
||||
&CmdResult
|
||||
);
|
||||
|
||||
//ON_EXIT:
|
||||
// gBS->RestoreTPL (OldTpl);
|
||||
}
|
||||
}
|
||||
//ON_EXIT:
|
||||
// gBS->RestoreTPL (OldTpl);
|
||||
}
|
||||
}
|
||||
ON_EXIT:
|
||||
return Status;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user