-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mario Bălănică <[email protected]>
- Loading branch information
1 parent
d6e003b
commit 61fdb61
Showing
11 changed files
with
276 additions
and
13 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
edk2-rockchip/Silicon/Rockchip/Applications/MaskromReset/MaskromReset.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** @file | ||
* | ||
* Copyright (c) 2024, Mario Bălănică <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
**/ | ||
|
||
#include <Uefi.h> | ||
#include <Library/BaseMemoryLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <Library/MemoryAllocationLib.h> | ||
#include <Library/UefiApplicationEntryPoint.h> | ||
#include <Library/UefiLib.h> | ||
#include <Library/UefiRuntimeServicesTableLib.h> | ||
|
||
STATIC | ||
VOID | ||
EFIAPI | ||
RuntimeResetPlatformSpecific ( | ||
IN CONST GUID *ResetSubtype, | ||
IN CONST CHAR16 *ResetString | ||
) | ||
{ | ||
UINTN StringSize; | ||
UINTN ResetDataSize = 0; | ||
VOID *ResetData = NULL; | ||
|
||
if (ResetSubtype == NULL) { | ||
ASSERT (FALSE); | ||
goto Exit; | ||
} | ||
|
||
if (ResetString == NULL) { | ||
ResetString = L""; | ||
} | ||
|
||
StringSize = StrSize (ResetString); | ||
ResetDataSize = StringSize + sizeof (GUID); | ||
|
||
ResetData = AllocateZeroPool (ResetDataSize); | ||
if (ResetData == NULL) { | ||
ResetDataSize = 0; | ||
goto Exit; | ||
} | ||
|
||
CopyMem (ResetData, ResetString, StringSize); | ||
CopyGuid ((GUID *)((UINT8 *)ResetData + StringSize), ResetSubtype); | ||
|
||
Exit: | ||
gRT->ResetSystem (EfiResetPlatformSpecific, EFI_SUCCESS, ResetDataSize, ResetData); | ||
|
||
if (ResetData != NULL) { | ||
FreePool (ResetData); | ||
} | ||
} | ||
|
||
EFI_STATUS | ||
EFIAPI | ||
UefiMain ( | ||
IN EFI_HANDLE ImageHandle, | ||
IN EFI_SYSTEM_TABLE *SystemTable | ||
) | ||
{ | ||
RuntimeResetPlatformSpecific (&gRockchipResetTypeMaskromGuid, L"MASKROM"); | ||
|
||
return EFI_SUCCESS; | ||
} |
33 changes: 33 additions & 0 deletions
33
edk2-rockchip/Silicon/Rockchip/Applications/MaskromReset/MaskromReset.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#/** @file | ||
# | ||
# Copyright (c) 2024, Mario Bălănică <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
#**/ | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010005 | ||
BASE_NAME = MaskromReset | ||
FILE_GUID = 1f64e768-9f2c-4b39-a54a-f84a31ed6d6b | ||
MODULE_TYPE = UEFI_APPLICATION | ||
VERSION_STRING = 1.0 | ||
ENTRY_POINT = UefiMain | ||
|
||
[Sources] | ||
MaskromReset.c | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
Silicon/Rockchip/RockchipPkg.dec | ||
|
||
[LibraryClasses] | ||
BaseMemoryLib | ||
DebugLib | ||
MemoryAllocationLib | ||
UefiApplicationEntryPoint | ||
UefiLib | ||
UefiRuntimeServicesTableLib | ||
|
||
[Guids] | ||
gRockchipResetTypeMaskromGuid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/** @file | ||
Implementation for PlatformBootManagerLib library class interfaces. | ||
Copyright (c) 2023-2024, Mario Bălănică <[email protected]> | ||
Copyright (C) 2015-2016, Red Hat, Inc. | ||
Copyright (c) 2014 - 2021, ARM Ltd. All rights reserved.<BR> | ||
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR> | ||
|
@@ -39,6 +40,8 @@ | |
|
||
#include "PlatformBm.h" | ||
|
||
#define BOOT_PROMPT L"Setup (ESC/F2) Shell (F1) Reset to MaskROM (F4) Continue (Enter)" | ||
|
||
#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) } | ||
|
||
#pragma pack (1) | ||
|
@@ -789,6 +792,8 @@ PlatformRegisterOptionsAndKeys ( | |
EFI_INPUT_KEY Enter; | ||
EFI_INPUT_KEY F2; | ||
EFI_INPUT_KEY Esc; | ||
EFI_INPUT_KEY F1; | ||
EFI_INPUT_KEY F4; | ||
EFI_BOOT_MANAGER_LOAD_OPTION BootOption; | ||
|
||
GetPlatformOptions (); | ||
|
@@ -826,6 +831,22 @@ PlatformRegisterOptionsAndKeys ( | |
NULL | ||
); | ||
ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); | ||
|
||
// | ||
// Register UEFI Shell | ||
// | ||
F1.ScanCode = SCAN_F1; | ||
F1.UnicodeChar = CHAR_NULL; | ||
PlatformRegisterFvBootOption (&gUefiShellFileGuid, L"UEFI Shell", 0, &F1); | ||
|
||
// | ||
// Register Maskrom Reset | ||
// | ||
F4.ScanCode = SCAN_F4; | ||
F4.UnicodeChar = CHAR_NULL; | ||
PlatformRegisterFvBootOption (&gRockchipMaskromResetFileGuid, L"Reset to MaskROM", 0, &F4); | ||
|
||
RemoveStaleFvFileOptions (); | ||
} | ||
|
||
// | ||
|
@@ -1158,7 +1179,6 @@ PlatformBootManagerAfterConsole ( | |
UINTN FirmwareVerLength; | ||
UINTN PosX; | ||
UINTN PosY; | ||
EFI_INPUT_KEY Key; | ||
|
||
EfiEventGroupSignal (&gRockchipEventPlatformBmAfterConsoleGuid); | ||
|
||
|
@@ -1175,7 +1195,7 @@ PlatformBootManagerAfterConsole ( | |
PcdGetPtr (PcdFirmwareVersionString) | ||
); | ||
} | ||
Print (L"Press ESCAPE for boot options"); | ||
Print (BOOT_PROMPT); | ||
} else if (FirmwareVerLength > 0) { | ||
Status = gBS->HandleProtocol ( | ||
gST->ConsoleOutHandle, | ||
|
@@ -1213,15 +1233,6 @@ PlatformBootManagerAfterConsole ( | |
// feedback about what is going on. | ||
// | ||
HandleCapsules (); | ||
|
||
// | ||
// Register UEFI Shell | ||
// | ||
Key.ScanCode = SCAN_NULL; | ||
Key.UnicodeChar = L's'; | ||
PlatformRegisterFvBootOption (&gUefiShellFileGuid, L"UEFI Shell", 0, &Key); | ||
|
||
RemoveStaleFvFileOptions (); | ||
} | ||
|
||
/** | ||
|
@@ -1249,7 +1260,7 @@ PlatformBootManagerWaitCallback ( | |
Status = BootLogoUpdateProgress ( | ||
White.Pixel, | ||
Black.Pixel, | ||
L"Press ESCAPE for boot options", | ||
BOOT_PROMPT, | ||
White.Pixel, | ||
(Timeout - TimeoutRemain) * 100 / Timeout, | ||
0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/ResetPlatformDxe/ResetPlatformDxe.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** @file | ||
* | ||
* Copyright (c) 2024, Mario Bălănică <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
* | ||
**/ | ||
|
||
#include <Library/BaseMemoryLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <Library/IoLib.h> | ||
#include <Library/ResetUtilityLib.h> | ||
#include <Library/UefiBootServicesTableLib.h> | ||
#include <Protocol/PlatformSpecificResetHandler.h> | ||
|
||
#define ROCKCHIP_BOOT_MODE_REG 0xFD588080 // PMU0_GRF_OS_REG8 | ||
|
||
#define BOOT_BROM_DOWNLOAD 0xEF08A53C | ||
|
||
#define PMU1GRF_SOC_CON1 0xfd58a004 | ||
|
||
STATIC | ||
VOID | ||
EFIAPI | ||
ResetNotifyHandler ( | ||
IN EFI_RESET_TYPE ResetType, | ||
IN EFI_STATUS ResetStatus, | ||
IN UINTN DataSize, | ||
IN VOID *ResetData OPTIONAL | ||
) | ||
{ | ||
GUID *ResetSubtype; | ||
BOOLEAN SoftReset; | ||
|
||
if ((ResetType != EfiResetPlatformSpecific) || | ||
(DataSize == 0) || | ||
(ResetData == NULL)) | ||
{ | ||
return; | ||
} | ||
|
||
ResetSubtype = GetResetPlatformSpecificGuid (DataSize, ResetData); | ||
|
||
SoftReset = TRUE; | ||
|
||
if (CompareGuid (ResetSubtype, &gRockchipResetTypeMaskromGuid)) { | ||
MmioWrite32 (ROCKCHIP_BOOT_MODE_REG, BOOT_BROM_DOWNLOAD); | ||
} else { | ||
SoftReset = FALSE; | ||
} | ||
|
||
// | ||
// It has been observed that the boot mode register does not persist | ||
// across reset after BL31 sets reset_width to 0xFFFF. | ||
// Setting it back to 0 causes a softer reset, which solves the issue. | ||
// | ||
if (SoftReset) { | ||
MmioWrite32 (PMU1GRF_SOC_CON1, 0xFFFF0000); | ||
} | ||
} | ||
|
||
EFI_STATUS | ||
EFIAPI | ||
ResetPlatformDxeInitialize ( | ||
IN EFI_HANDLE ImageHandle, | ||
IN EFI_SYSTEM_TABLE *SystemTable | ||
) | ||
{ | ||
EFI_STATUS Status; | ||
|
||
EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL *ResetNotify; | ||
|
||
Status = gBS->LocateProtocol ( | ||
&gEdkiiPlatformSpecificResetHandlerProtocolGuid, | ||
NULL, | ||
(VOID **)&ResetNotify | ||
); | ||
ASSERT_EFI_ERROR (Status); | ||
if (!EFI_ERROR (Status)) { | ||
Status = ResetNotify->RegisterResetNotify ( | ||
ResetNotify, | ||
ResetNotifyHandler | ||
); | ||
ASSERT_EFI_ERROR (Status); | ||
} | ||
|
||
return Status; | ||
} |
42 changes: 42 additions & 0 deletions
42
edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/ResetPlatformDxe/ResetPlatformDxe.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#/** @file | ||
# | ||
# Copyright (c) 2024, Mario Bălănică <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
#**/ | ||
|
||
[Defines] | ||
INF_VERSION = 0x0001001A | ||
BASE_NAME = ResetPlatformDxe | ||
FILE_GUID = 8c01f5b0-1da5-471b-97fd-f60f77e09de6 | ||
MODULE_TYPE = DXE_DRIVER | ||
VERSION_STRING = 1.0 | ||
ENTRY_POINT = ResetPlatformDxeInitialize | ||
|
||
[Sources] | ||
ResetPlatformDxe.c | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
MdeModulePkg/MdeModulePkg.dec | ||
Silicon/Rockchip/RockchipPkg.dec | ||
|
||
[LibraryClasses] | ||
BaseMemoryLib | ||
DebugLib | ||
IoLib | ||
ResetUtilityLib | ||
UefiBootServicesTableLib | ||
UefiDriverEntryPoint | ||
|
||
[Guids] | ||
gRockchipResetTypeMaskromGuid | ||
|
||
[Protocols] | ||
gEdkiiPlatformSpecificResetHandlerProtocolGuid | ||
|
||
[Pcd] | ||
|
||
[Depex] | ||
gEdkiiPlatformSpecificResetHandlerProtocolGuid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# | ||
# Copyright (c) 2014-2018, Linaro Limited. All rights reserved. | ||
# Copyright (c) 2021-2022, Rockchip Limited. All rights reserved. | ||
# Copyright (c) 2023, Mario Bălănică <[email protected]> | ||
# Copyright (c) 2023-2024, Mario Bălănică <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
|
@@ -110,6 +110,11 @@ READ_LOCK_STATUS = TRUE | |
# | ||
INF Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.inf | ||
|
||
# | ||
# Custom reset handler | ||
# | ||
INF Silicon/Rockchip/RK3588/Drivers/ResetPlatformDxe/ResetPlatformDxe.inf | ||
|
||
# | ||
# PCI Support | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters