Skip to content

Commit

Permalink
FirmwareManagerUiDxe: Add "Update CONF.INI" button
Browse files Browse the repository at this point in the history
 - 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 <[email protected]>
  • Loading branch information
jingyu-li98 committed Dec 25, 2024
1 parent a2feadc commit eafd19b
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Platform/Sophgo/SG2044Pkg/SG2044.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions Silicon/Sophgo/Applications/FirmwareUpdate/FirmwareUpdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <Protocol/DevicePath.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/NonDiscoverableDevice.h>

#include <Include/Spifmc.h>
#include <Include/SpiNorFlash.h>
Expand Down Expand Up @@ -569,7 +568,8 @@ FirmwareUpdateEntry (
//
Nor = SpiMasterProtocol->SetupDevice (
SpiMasterProtocol,
Nor
Nor,
0
);

if (Nor == NULL) {
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion Silicon/Sophgo/Drivers/FlashFvbDxe/FlashFvbDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,8 @@ FlashFvbConfigureFlashInstance (
//
FlashInstance->Nor = FlashInstance->SpiMasterProtocol->SetupDevice (
FlashInstance->SpiMasterProtocol,
FlashInstance->Nor
FlashInstance->Nor,
0
);

if (FlashInstance->Nor == NULL) {
Expand Down
9 changes: 7 additions & 2 deletions Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions Silicon/Sophgo/Drivers/SpifmcDxe/SpiFlashMasterController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Silicon/Sophgo/Include/Spifmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -285,7 +287,7 @@ UpdateFirmware (

WarningString = HiiGetString (
gFirmwareUpdateHandle,
STRING_TOKEN (STR_UPDATING_FIRMWARE_WARNING),
STRING_TOKEN (STR_UPDATING_WARNING),
NULL
);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -515,15 +519,15 @@ VOID ClearScreen (
**/
VOID
PressKeytoReset (
VOID
EFI_STRING_ID TokenToUpdate
)
{
CHAR16 Str1[64];
EFI_INPUT_KEY InputKey;
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,
Expand Down Expand Up @@ -591,24 +595,30 @@ 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;
UINTN FileSize;
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
Expand Down Expand Up @@ -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;
}

Expand All @@ -657,29 +680,64 @@ 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);

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.
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit eafd19b

Please sign in to comment.