From eafd19bc607638c90f01a96b1da561a11311e0dd Mon Sep 17 00:00:00 2001 From: Jingyu Li Date: Wed, 25 Dec 2024 17:28:34 +0800 Subject: [PATCH] FirmwareManagerUiDxe: Add "Update CONF.INI" button - Add a button that allows users to select file from the media devices to update the conf.ini in Nor Flash. - Add SPIFMC1 base address. Each SPIFMC only connects on a Nor Flash without chip selection. firmware.bin is in Nor Flash 0, and conf.ini is in Nor Flash 1. Use SelectedFlashNumber to select to set up corresponding devices. Signed-off-by: Jingyu Li --- Platform/Sophgo/SG2044Pkg/SG2044.dsc | 3 +- .../FirmwareUpdate/FirmwareUpdate.c | 8 +- .../Sophgo/Drivers/FlashFvbDxe/FlashFvbDxe.c | 3 +- .../SpifmcDxe/SpiFlashMasterController.c | 9 +- .../SpifmcDxe/SpiFlashMasterController.h | 6 +- Silicon/Sophgo/Include/Spifmc.h | 3 +- .../FirmwareManagerUiDxe/FirmwareManager.c | 120 +++++++++++++----- .../FirmwareManagerFormGuid.h | 1 + .../FirmwareManagerStrings.uni | 7 +- .../FirmwareManagerVfr.vfr | 7 + 10 files changed, 126 insertions(+), 41 deletions(-) diff --git a/Platform/Sophgo/SG2044Pkg/SG2044.dsc b/Platform/Sophgo/SG2044Pkg/SG2044.dsc index aa7e40e30c8..86408e5ee9a 100644 --- a/Platform/Sophgo/SG2044Pkg/SG2044.dsc +++ b/Platform/Sophgo/SG2044Pkg/SG2044.dsc @@ -460,7 +460,8 @@ # Flash Offset: 32MB # !if $(FLASH_ENABLE) == TRUE - gSophgoTokenSpaceGuid.PcdSPIFMC1Base|0x7001000000 + gSophgoTokenSpaceGuid.PcdSPIFMC0Base|0x7001000000 + gSophgoTokenSpaceGuid.PcdSPIFMC1Base|0x7005000000 gSophgoTokenSpaceGuid.PcdSpifmcDmmrEnable|TRUE gSophgoTokenSpaceGuid.PcdFlashPartitionTableAddress|0x80000 !endif diff --git a/Silicon/Sophgo/Applications/FirmwareUpdate/FirmwareUpdate.c b/Silicon/Sophgo/Applications/FirmwareUpdate/FirmwareUpdate.c index 79daecfed39..0f288dda3df 100755 --- a/Silicon/Sophgo/Applications/FirmwareUpdate/FirmwareUpdate.c +++ b/Silicon/Sophgo/Applications/FirmwareUpdate/FirmwareUpdate.c @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -569,7 +568,8 @@ FirmwareUpdateEntry ( // Nor = SpiMasterProtocol->SetupDevice ( SpiMasterProtocol, - Nor + Nor, + 0 ); if (Nor == NULL) { @@ -636,6 +636,10 @@ FirmwareUpdateEntry ( FreePages (FirmwareData, EFI_SIZE_TO_PAGES (FirmwareSize)); } + if (Nor) { + SpiMasterProtocol->FreeDevice (Nor); + } + Attribute = EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK; gST->ConOut->SetAttribute (gST->ConOut, Attribute); diff --git a/Silicon/Sophgo/Drivers/FlashFvbDxe/FlashFvbDxe.c b/Silicon/Sophgo/Drivers/FlashFvbDxe/FlashFvbDxe.c index 292f4504a5e..f200b7a4460 100644 --- a/Silicon/Sophgo/Drivers/FlashFvbDxe/FlashFvbDxe.c +++ b/Silicon/Sophgo/Drivers/FlashFvbDxe/FlashFvbDxe.c @@ -1162,7 +1162,8 @@ FlashFvbConfigureFlashInstance ( // FlashInstance->Nor = FlashInstance->SpiMasterProtocol->SetupDevice ( FlashInstance->SpiMasterProtocol, - FlashInstance->Nor + FlashInstance->Nor, + 0 ); if (FlashInstance->Nor == NULL) { diff --git a/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.c b/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.c index 07121782b93..4b3e22be9eb 100644 --- a/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.c +++ b/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.c @@ -468,7 +468,8 @@ SPI_NOR * EFIAPI SpiMasterSetupSlave ( IN SOPHGO_SPI_MASTER_PROTOCOL *This, - IN SPI_NOR *Nor + IN SPI_NOR *Nor, + IN UINT8 SelectedFlashNumber ) { EFI_STATUS Status; @@ -485,7 +486,11 @@ SpiMasterSetupSlave ( } } - Nor->SpiBase = SPIFMC_BASE; + if (SelectedFlashNumber == 0) { + Nor->SpiBase = FixedPcdGet64 (PcdSPIFMC0Base); + } else if (SelectedFlashNumber == 1) { + Nor->SpiBase = FixedPcdGet64 (PcdSPIFMC1Base); + } Status = gDS->AddMemorySpace ( EfiGcdMemoryTypeMemoryMappedIo, diff --git a/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.h b/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.h index 7af3365c16b..5dd6b42151b 100644 --- a/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.h +++ b/Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.h @@ -27,9 +27,6 @@ // // SPIFMC registers // -// #define SPIFMC_BASE (FixedPcdGet64(PcdSPIFMC0Base)) -#define SPIFMC_BASE (FixedPcdGet64(PcdSPIFMC1Base)) - #define SPIFMC_CTRL 0x00 #define SPIFMC_CTRL_CPHA BIT12 #define SPIFMC_CTRL_CPOL BIT13 @@ -170,7 +167,8 @@ SPI_NOR * EFIAPI SpiMasterSetupSlave ( IN SOPHGO_SPI_MASTER_PROTOCOL *This, - IN SPI_NOR *Nor + IN SPI_NOR *Nor, + IN UINT8 SelectedFlashNumber ); EFI_STATUS diff --git a/Silicon/Sophgo/Include/Spifmc.h b/Silicon/Sophgo/Include/Spifmc.h index bcecea9ab1b..341b685db81 100644 --- a/Silicon/Sophgo/Include/Spifmc.h +++ b/Silicon/Sophgo/Include/Spifmc.h @@ -89,7 +89,8 @@ typedef SPI_NOR * (EFIAPI *SG_SPI_MASTER_PROTOCOL_SETUP_DEVICE) ( IN SOPHGO_SPI_MASTER_PROTOCOL *This, - IN SPI_NOR *Nor + IN SPI_NOR *Nor, + IN UINT8 SelectedFlashNumber ); typedef diff --git a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManager.c b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManager.c index 7aec7113a02..69f56eb0dab 100755 --- a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManager.c +++ b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManager.c @@ -242,11 +242,12 @@ FirmwareManagerRouteConfig ( /** Update firmware in spi nor flash. - @param[in] Nor Structure of nor flash. - @param[in] Address Address to update. - @param[in] Buffer A pointer to update firmware data. - @param[in] Size Size of update firmware to update. - @param[in] String Start info to print. + @param[in] Nor Structure of nor flash. + @param[in] Address Address to update. + @param[in] Buffer A pointer to update firmware data. + @param[in] Size Size of update firmware to update. + @param[in] String Start info to print. + @param[in] SkipVariable Whether skip variable range or not. @retval EFI_SUCCESS Success. Other Failed. @@ -257,7 +258,8 @@ UpdateFirmware ( IN UINTN Address, IN UINT8 *Buffer, IN UINTN Size, - IN CHAR16 *String + IN CHAR16 *String, + IN BOOLEAN SkipVariable ) { EFI_STATUS Status; @@ -285,7 +287,7 @@ UpdateFirmware ( WarningString = HiiGetString ( gFirmwareUpdateHandle, - STRING_TOKEN (STR_UPDATING_FIRMWARE_WARNING), + STRING_TOKEN (STR_UPDATING_WARNING), NULL ); @@ -316,9 +318,11 @@ UpdateFirmware ( // // Skip the Variable range // - if (((VariableBase / BlockSize) <= Index) - && (Index < ((VariableBase + VariableSize) / BlockSize))) { - continue; + if (SkipVariable) { + if (((VariableBase / BlockSize) <= Index) + && (Index < ((VariableBase + VariableSize) / BlockSize))) { + continue; + } } if (TempBuffer) { @@ -515,7 +519,7 @@ VOID ClearScreen ( **/ VOID PressKeytoReset ( - VOID + EFI_STRING_ID TokenToUpdate ) { CHAR16 Str1[64]; @@ -523,7 +527,7 @@ PressKeytoReset ( UINTN EventIndex; CHAR16 *UpdateSuccString; - UpdateSuccString = HiiGetString (gFirmwareUpdateHandle, STRING_TOKEN (STR_FIRMWARE_UPDATE_SUCC), NULL); + UpdateSuccString = HiiGetString (gFirmwareUpdateHandle, TokenToUpdate, NULL); CreatePopUp ( EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, NULL, @@ -591,16 +595,18 @@ NorFlashProbe ( } /** - Update firmware from file. + Update file. - @param[in] FilePath A pointer to update firmware data file path. + @param[in] FilePath A pointer to update firmware data file path. + @param[in] QuestionId A unique value which is sent to the original exporting driver + so that it can identify the type of data to expect. @retval FALSE Failed. **/ BOOLEAN -EFIAPI UpdateFromFile ( - IN EFI_DEVICE_PATH_PROTOCOL *FilePath + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + IN EFI_QUESTION_ID QuestionId ) { VOID *FileBuffer; @@ -608,7 +614,11 @@ UpdateFromFile ( UINT32 AuthStat; EFI_STATUS Status; UINT8 *FirmwareAddress; + UINT8 SelectedFlashNumber; CHAR16 *UpdatingFirmwareString; + BOOLEAN SkipVariable; + EFI_STRING_ID TokenToUpdate1; + EFI_STRING_ID TokenToUpdate2; // // Locate SPI Master protocol @@ -636,16 +646,29 @@ UpdateFromFile ( return FALSE; } + if (QuestionId == UPDATE_FIRMWARE_KEY) { + SelectedFlashNumber = 0; + TokenToUpdate1 = STRING_TOKEN (STR_UPDATING_FIRMWARE); + TokenToUpdate2 = STRING_TOKEN (STR_FIRMWARE_UPDATE_SUCC); + SkipVariable = TRUE; + } else if (QuestionId == UPDATE_INI_KEY) { + SelectedFlashNumber = 1; + TokenToUpdate1 = STRING_TOKEN (STR_UPDATING_INI); + TokenToUpdate2 = STRING_TOKEN (STR_INI_UPDATE_SUCC); + SkipVariable = FALSE; + } + // // Setup and probe Nor flash // Nor = SpiMasterProtocol->SetupDevice ( SpiMasterProtocol, - Nor + Nor, + SelectedFlashNumber ); if (Nor == NULL) { - Print (L" Nor Flash not found!\n"); + Print (L" Nor Flash %d not found!\n", SelectedFlashNumber); return FALSE; } @@ -657,22 +680,23 @@ UpdateFromFile ( FileBuffer = GetFileBufferByFilePath (FALSE, FilePath, &FileSize, &AuthStat); - if (!EFI_ERROR(Status)) { + if (!EFI_ERROR (Status)) { FirmwareAddress = FileBuffer; UpdatingFirmwareString = HiiGetString ( gFirmwareUpdateHandle, - STRING_TOKEN (STR_UPDATING_FIRMWARE), + TokenToUpdate1, NULL ); Status = UpdateFirmware ( - Nor, - 0, - FirmwareAddress, - FileSize, - UpdatingFirmwareString - ); - - PressKeytoReset (); + Nor, + 0, + FirmwareAddress, + FileSize, + UpdatingFirmwareString, + SkipVariable + ); + + PressKeytoReset (TokenToUpdate2); } FreePool (FileBuffer); @@ -680,6 +704,40 @@ UpdateFromFile ( return FALSE; } +/** + Update the firmware.bin base on the input file path info. + + @param FilePath Point to the file path. + + @retval TRUE Exit caller function. + @retval FALSE Not exit caller function. +**/ +BOOLEAN +EFIAPI +UpdateFirmwareFromFile ( + IN EFI_DEVICE_PATH_PROTOCOL *FilePath + ) +{ + return UpdateFromFile (FilePath, UPDATE_FIRMWARE_KEY); +} + +/** + Update the conf.ini base on the input file path info. + + @param FilePath Point to the file path. + + @retval TRUE Exit caller function. + @retval FALSE Not exit caller function. +**/ +BOOLEAN +EFIAPI +UpdateIniFromFile ( + IN EFI_DEVICE_PATH_PROTOCOL *FilePath + ) +{ + return UpdateFromFile (FilePath, UPDATE_INI_KEY); +} + /** This function processes the results of changes in configuration. @@ -713,7 +771,11 @@ FirmwareManagerCallback ( Status = EFI_SUCCESS; if (Action == EFI_BROWSER_ACTION_CHANGING) { if (QuestionId == UPDATE_FIRMWARE_KEY) { - Status = ChooseFile (NULL, NULL, UpdateFromFile, &File); + Status = ChooseFile (NULL, NULL, UpdateFirmwareFromFile, &File); + } + + if (QuestionId == UPDATE_INI_KEY) { + Status = ChooseFile (NULL, NULL, UpdateIniFromFile, &File); } } diff --git a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerFormGuid.h b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerFormGuid.h index 273090484ea..adf73000a47 100755 --- a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerFormGuid.h +++ b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerFormGuid.h @@ -14,5 +14,6 @@ #define FIRMWARE_MANAGER_VARIABLE L"FirmwareManagerSetup" #define FORM_FIRMWARE_MANAGER_ID 0x3000 #define UPDATE_FIRMWARE_KEY 0x3100 +#define UPDATE_INI_KEY 0x3200 #endif diff --git a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerStrings.uni b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerStrings.uni index 62dc8c06d13..a2fab3cd3b9 100755 --- a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerStrings.uni +++ b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerStrings.uni @@ -15,7 +15,12 @@ #string STR_UPDATE_FIRMWARE_TITLE #language en-US "Update Firmware" #string STR_UPDATE_FIRMWARE_HELP #language en-US "Select the file to update the firmware. Do not power off or reset the device during the update" +#string STR_UPDATING_WARNING #language en-US "Do not power off or reset the device during the update" #string STR_FIRMWARE_UPDATE_SUCC #language en-US "Firmware update success. Press Enter to reboot the system" #string STR_UPDATING_FIRMWARE #language en-US "Updating Firmware" -#string STR_UPDATING_FIRMWARE_WARNING #language en-US "Do not power off or reset the device during the update" + +#string STR_UPDATE_INI_TITLE #language en-US "Update CONF.INI" +#string STR_UPDATE_INI_HELP #language en-US "Select the file to update the conf.ini." +#string STR_UPDATING_INI #language en-US "Updating conf.ini" +#string STR_INI_UPDATE_SUCC #language en-US "conf.ini update success. Press Enter to reboot the system" diff --git a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerVfr.vfr b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerVfr.vfr index caca01a45ce..86bb14a3a4e 100755 --- a/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerVfr.vfr +++ b/Silicon/Sophgo/SG2044Pkg/Drivers/FirmwareManagerUiDxe/FirmwareManagerVfr.vfr @@ -15,11 +15,18 @@ formset form formid = FORM_FIRMWARE_MANAGER_ID, title = STRING_TOKEN (STR_FIRMWARE_MANAGER_TITLE); + goto FORM_FIRMWARE_MANAGER_ID, prompt = STRING_TOKEN (STR_UPDATE_FIRMWARE_TITLE), help = STRING_TOKEN (STR_UPDATE_FIRMWARE_HELP), flags = INTERACTIVE, key = UPDATE_FIRMWARE_KEY; + + goto FORM_FIRMWARE_MANAGER_ID, + prompt = STRING_TOKEN (STR_UPDATE_INI_TITLE), + help = STRING_TOKEN (STR_UPDATE_INI_HELP), + flags = INTERACTIVE, + key = UPDATE_INI_KEY; endform; endformset;