From nobody Sun May 19 10:57:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+39915+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39915+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1556796702; cv=none; d=zoho.com; s=zohoarc; b=SyLEgfxZ0UBTh0OWnuHZyQiDLQOoo0gTRF97edsXHzwHVenpIKn/5KRBAc8+maVuYaw1lepbw0qmADDlfPC4Tvh3YmJE1X9Dl2qlHLQZkRGHQis4iWmkgZPTWe27ZvtA6xao88pQPqAXX5TNj2fHm4wJpw5gYzZYsTLcXXAa6lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556796702; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=pDBRurXsUOjW5GYDGYIp5U+MzDu0dsgWmYRDPmitS9Y=; b=Igf/tZaWFHWh/DEvwjduUSzrsT4hLsIP/hXTBObyhzXp2bpvnMDoi1Hdkbz/hsk6FcCOIGKYrVzFyChuFM7RC23y8U6xBnvsYtyFNqudSldZYD/e4Pra9PErvFMAJhsd91o/Zr3CRQf0LhI1/HEL2+2KvkiOjN32MGBV076aGVE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39915+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1556796702535986.2839479123764; Thu, 2 May 2019 04:31:42 -0700 (PDT) Return-Path: X-Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by groups.io with SMTP; Thu, 02 May 2019 04:31:41 -0700 X-Received: by mail-lj1-f194.google.com with SMTP id y8so1626033ljd.3 for ; Thu, 02 May 2019 04:31:40 -0700 (PDT) X-Gm-Message-State: APjAAAXH+Vw4fJNgEjuF4FI9PcBjPaxVbFvZUN/DIF6L1wL5vCSWGpOR yYx5hONODCASusxXzasTcLjftZVf+hF+HQ== X-Google-Smtp-Source: APXvYqyR65MGi9adFogtNkSYA3RyiBO4PkrZUSK3Zv/0ySYIajj7MMz3DWxoa2DAR4jH3lN8czaDcg== X-Received: by 2002:a2e:7a03:: with SMTP id v3mr1776945ljc.142.1556796698844; Thu, 02 May 2019 04:31:38 -0700 (PDT) X-Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id d22sm9321072lfm.57.2019.05.02.04.31.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 May 2019 04:31:38 -0700 (PDT) From: "Marcin Wojtas" To: devel@edk2.groups.io Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, mw@semihalf.com, jsd@semihalf.com, jaz@semihalf.com, Jici.Gao@arm.com, Tomasz Michalec Subject: [edk2-devel] [PATCH] Marvell/Applications: FirmwareUpdate: Enable burning image on SD/MMC Date: Thu, 2 May 2019 13:31:25 +0200 Message-Id: <1556796685-3359-1-git-send-email-mw@semihalf.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mw@semihalf.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1556796702; bh=JCAugfA3VvbdcHBoqcYKF1PjJ2drP5f5pnio8FnhkBY=; h=Cc:Date:From:Reply-To:Subject:To; b=TK1K5voUUqvLkdxIM9ltNI9EqG3TUAH/gsEdDcHmwFO9d9rEvgLg78Y7YMi9s5QkPk2 TcKKguEMaOjGUWQ3xKY9LK2t/S1ft+qhLSEBhV8SHuXe3+QYy5uisoav4TwF8dUkYutim gOuQbLW5HdYnvLaGREad1ha9+31zbC21Sj0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Tomasz Michalec Extend fupdate shell application to be able to flash firmware on SD/MMC. Device on which firmware will be updated is selected via third argument of command. The SPI is still used as default. Command uses BlockIo protocol to communicate with SD/MMC. It is possible to list all valid devices and specify selection via handle number or device path string. Example output (detailed usage can be found in updated command's 'help'): Shell> fupdate list Handle Path spi spi 8F VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,00006EF00000000000)/SD(0= x0) 93 VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,000078F20000000000)/eMMC= (0x0)/Ctrl(0x0) 94 VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,000078F20000000000)/eMMC= (0x0)/Ctrl(0x1) 95 VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,000078F20000000000)/eMMC= (0x0)/Ctrl(0x2) The code was restructured, to dynamically assign appropriate firmware update routine, depending on the user choice (SPI vs BlockDevice). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas Reviewed-by: Ard Biesheuvel --- Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.inf | 13 +- Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.c | 542 ++++++++++++= +++++--- Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.uni | Bin 5190 -> 6758= bytes 3 files changed, 485 insertions(+), 70 deletions(-) diff --git a/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.inf b/Sili= con/Marvell/Applications/FirmwareUpdate/FUpdate.inf index 69ee0f8..46847fc 100644 --- a/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.inf +++ b/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.inf @@ -55,6 +55,7 @@ BaseMemoryLib DebugLib FileHandleLib + HandleParsingLib HiiLib MemoryAllocationLib PcdLib @@ -62,12 +63,18 @@ ShellLib UefiBootServicesTableLib UefiLib - UefiLib UefiRuntimeServicesTableLib =20 +[Pcd] + gMarvellTokenSpaceGuid.PcdSpiFlashCs + gMarvellTokenSpaceGuid.PcdSpiFlashMode + [Protocols] - gMarvellSpiFlashProtocolGuid - gMarvellSpiMasterProtocolGuid + gEfiBlockIoProtocolGuid + gEfiDevicePathFromTextProtocolGuid + gEfiDevicePathProtocolGuid + gMarvellSpiFlashProtocolGuid + gMarvellSpiMasterProtocolGuid =20 [Guids] gShellFUpdateHiiGuid diff --git a/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.c b/Silico= n/Marvell/Applications/FirmwareUpdate/FUpdate.c index 22a9b8f..3a496f0 100644 --- a/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.c +++ b/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.c @@ -36,7 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMA= GE. #include #include #include +#include #include +#include #include #include #include @@ -46,22 +48,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DA= MAGE. #include #include =20 +#include +#include +#include #include #include =20 #define CMD_NAME_STRING L"fupdate" =20 +#define SHELL_USE_DEVICE_PATH_PARAM L"-p" +#define SHELL_DEVICE_NAME_PARAM L"DeviceName" +#define SHELL_FILE_NAME_PARAM L"LocalFileName" +#define SHELL_HELP_PARAM L"help" +#define SHELL_LIST_PARAM L"list" + #define MAIN_HDR_MAGIC 0xB105B002 =20 -STATIC MARVELL_SPI_FLASH_PROTOCOL *SpiFlashProtocol; -STATIC MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol; +STATIC EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol; +STATIC MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol; +STATIC MARVELL_SPI_FLASH_PROTOCOL *SpiFlashProtocol; +STATIC EFI_BLOCK_IO_PROTOCOL *BlkIo; =20 STATIC CONST CHAR16 gShellFUpdateFileName[] =3D L"ShellCommands"; STATIC EFI_HANDLE gShellFUpdateHiiHandle =3D NULL; =20 STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { - {L"help", TypeFlag}, - {NULL , TypeMax} + {SHELL_HELP_PARAM, TypeFlag}, + {SHELL_LIST_PARAM, TypeFlag}, + {SHELL_USE_DEVICE_PATH_PARAM, TypeFlag}, + {SHELL_FILE_NAME_PARAM, TypePosition}, + {SHELL_DEVICE_NAME_PARAM, TypePosition}, + {NULL , TypeMax} }; =20 typedef struct { // Bytes @@ -86,6 +103,14 @@ typedef struct { // Bytes UINT32 Reserved3; // 60-63 } MV_FIRMWARE_IMAGE_HEADER; =20 +typedef +EFI_STATUS +(EFIAPI *FLASH_COMMAND) ( + UINT64 FileSize, + UINTN *FileBuffer, + EFI_LBA Offset +); + STATIC EFI_STATUS SpiFlashProbe ( @@ -109,6 +134,156 @@ SpiFlashProbe ( return EFI_SUCCESS; } =20 +/** + Verify if selected device is valid for the firmware update. + + @param[in] Handle Handle of verified device + @param[in] Offset [OPTIONAL] Additional parameter + required for BlkIo->WriteBlocks, + filled depending on detected device + type. + +**/ +STATIC +EFI_STATUS +IsDeviceSupported ( + IN EFI_HANDLE Handle, + OUT EFI_LBA *Offset OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + + // + // Skip handles that do not have device path protocol + // + Status =3D gBS->OpenProtocol (Handle, + &gEfiDevicePathProtocolGuid, + (VOID**)&DevicePath, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + // + // Skip handles that are not block devices + // + Status =3D gBS->OpenProtocol (Handle, + &gEfiBlockIoProtocolGuid, + NULL, + NULL, + NULL, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + while (!IsDevicePathEnd (DevicePath)) { + if (DevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) { + // + // Search for SD/MMC devices. + // + if (DevicePath->SubType =3D=3D MSG_SD_DP) { + // + // Only flashing in the beginning of SD card makes sense. + // + DevicePath =3D NextDevicePathNode (DevicePath); + if (!IsDevicePathEnd (DevicePath)) { + return EFI_UNSUPPORTED; + } + if (Offset !=3D NULL) { + *Offset =3D 1; + } + return EFI_SUCCESS; + } + if (DevicePath->SubType =3D=3D MSG_EMMC_DP) { + // + // Filter out entire MMC device (ctrl(0x0)) + // and boot partitions (ctrl(0x1)/ctrl(0x2)) as valid for + // the firmware update. + // + DevicePath =3D NextDevicePathNode (DevicePath); + if (IsDevicePathEnd (DevicePath)) { + return EFI_UNSUPPORTED; + } + DevicePath =3D NextDevicePathNode (DevicePath); + if (!IsDevicePathEnd (DevicePath)) { + return EFI_UNSUPPORTED; + } + if (Offset !=3D NULL) { + *Offset =3D 0; + } + return EFI_SUCCESS; + } + } + DevicePath =3D NextDevicePathNode (DevicePath); + } + + return EFI_UNSUPPORTED; +} + +/** + Print information about single device supporting the firmware update. + + @param[in] Handle Handle of verified device + +**/ +STATIC +EFI_STATUS +PrintSupportedDevice ( + IN EFI_HANDLE Handle + ) +{ + CHAR16 *Name; + + gEfiShellProtocol->GetDeviceName (Handle, + EFI_DEVICE_NAME_USE_DEVICE_PATH, + NULL, + &Name); + if (Name !=3D NULL) { + ShellPrintEx (-1, + -1, + L"%H%02x%N %s\n", + ConvertHandleToHandleIndex (Handle), + Name); + } + + return EFI_SUCCESS; +} + +/** + Print information about all devices supporting the firmware update. + +**/ +STATIC +EFI_STATUS +ListSupportedDevices ( + ) +{ + UINTN LoopVar; + EFI_HANDLE Handle; + EFI_STATUS Status; + + ShellPrintEx (-1, -1, L"%BHandle Path%N\n"); + ShellPrintEx (-1, -1, L"%Hspi%N spi\n"); + + for (LoopVar =3D 1; ; LoopVar++) { + Handle =3D ConvertHandleIndexToHandle (LoopVar); + if (Handle =3D=3D NULL) { + break; + } + + Status =3D IsDeviceSupported (Handle, NULL); + if (!EFI_ERROR (Status)) { + PrintSupportedDevice (Handle); + } + } + + return EFI_SUCCESS; +} + STATIC EFI_STATUS CheckImageHeader ( @@ -149,13 +324,15 @@ PrepareFirmwareImage ( IN LIST_ENTRY *CheckPackage, IN OUT SHELL_FILE_HANDLE *FileHandle, IN OUT UINTN **FileBuffer, - IN OUT UINT64 *FileSize + IN OUT UINT64 *FileSize, + IN UINT64 Alignment ) { CONST CHAR16 *FileStr; EFI_STATUS Status; UINT64 OpenMode; UINTN *Buffer; + UINTN AlignedFileSize; =20 // Parse string from commandline FileStr =3D ShellCommandLineGetRawValue (CheckPackage, 1); @@ -184,8 +361,20 @@ PrepareFirmwareImage ( Print (L"%s: Cannot get Image file size\n", CMD_NAME_STRING); } =20 + // Allocate aligned buffer in case of updating firmware in a BlockDevice + if (Alignment > 0) { + AlignedFileSize =3D *FileSize + (Alignment - (*FileSize % Alignment)); + } else { + AlignedFileSize =3D *FileSize; + } + // Read Image header into buffer - Buffer =3D AllocateZeroPool (*FileSize); + Buffer =3D AllocateZeroPool (AlignedFileSize); + if (Buffer =3D=3D NULL) { + Print (L"%s: Fail to allocate buffer\n", CMD_NAME_STRING); + ShellCloseFile (FileHandle); + return EFI_OUT_OF_RESOURCES; + } =20 Status =3D FileHandleRead (*FileHandle, (UINTN *)FileSize, Buffer); if (EFI_ERROR (Status)) { @@ -196,6 +385,233 @@ PrepareFirmwareImage ( } =20 *FileBuffer =3D Buffer; + *FileSize =3D AlignedFileSize; + + return EFI_SUCCESS; +} + +/** + Update firmware image in the block device. + + @param[in] FileSize Size of the file to be flashed + @param[in] *FileBuffer Pointer to the file in memory + @param[in] Offset First logical block to be updated. + +**/ +STATIC +EFI_STATUS +EFIAPI +ProgramBlockDevice ( + IN UINT64 FileSize, + IN UINTN *FileBuffer, + IN EFI_LBA Offset + ) +{ + EFI_STATUS Status; + + Print (L"Updating image in BlockDevice\n"); + + Status =3D BlkIo->WriteBlocks (BlkIo, + BlkIo->Media->MediaId, + Offset, + FileSize, + FileBuffer); + if (EFI_ERROR (Status)) { + Print (L"%s: Cannot write to device (Status: %r)\n", + CMD_NAME_STRING, + Status); + return Status; + } + + Status =3D BlkIo->FlushBlocks (BlkIo); + if (EFI_ERROR (Status)) { + Print (L"%s: Cannot flush to device (Status: %r)\n", + CMD_NAME_STRING, + Status); + return Status; + } + + return EFI_SUCCESS; +} + + +/** + Update firmware image in the SPI flash. + + @param[in] FileSize Size of the file to be flashed + @param[in] *FileBuffer Pointer to the file in memory + @param[in] Offset First logical block to be updated. + Irrelevant for SPI. + +**/ +STATIC +EFI_STATUS +EFIAPI +ProgramSpiFlash ( + IN UINT64 FileSize, + IN UINTN *FileBuffer, + IN EFI_LBA Offset + ) +{ + SPI_DEVICE *SpiFlash; + EFI_STATUS Status; + + // Locate SPI protocols + Status =3D gBS->LocateProtocol (&gMarvellSpiFlashProtocolGuid, + NULL, + (VOID **)&SpiFlashProtocol); + if (EFI_ERROR (Status)) { + Print (L"%s: Cannot locate SpiFlash protocol\n", CMD_NAME_STRING); + return Status; + } + + Status =3D gBS->LocateProtocol (&gMarvellSpiMasterProtocolGuid, + NULL, + (VOID **)&SpiMasterProtocol); + if (EFI_ERROR (Status)) { + Print (L"%s: Cannot locate SpiMaster protocol\n", CMD_NAME_STRING); + return Status; + } + + // Setup and probe SPI flash + SpiFlash =3D NULL; + SpiFlash =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, + SpiFlash, + PcdGet32 (PcdSpiFlashCs), + PcdGet32 (PcdSpiFlashMode)); + if (SpiFlash =3D=3D NULL) { + Print(L"%s: Cannot allocate SPI device!\n", CMD_NAME_STRING); + return EFI_ABORTED; + } + + Status =3D SpiFlashProbe (SpiFlash); + if (EFI_ERROR (Status)) { + Print (L"%s: Error while performing SPI flash probe\n", CMD_NAME_STRIN= G); + goto FlashProbeError; + } + + // Update firmware image in flash at offset 0x0 + Status =3D SpiFlashProtocol->Update (SpiFlash, + 0x0, + FileSize, + (UINT8 *)FileBuffer); + if (EFI_ERROR (Status)) { + Print (L"%s: Error while performing flash update\n", CMD_NAME_STRING); + goto FlashProbeError; + } + + // Release resources + SpiMasterProtocol->FreeDevice (SpiFlash); + + return EFI_SUCCESS; + +FlashProbeError: + SpiMasterProtocol->FreeDevice (SpiFlash); + + return Status; +} + +/** + Parse commandline parameters and pick device for the firmware update. + + @param[in] *CheckPackage Shell command argument list. + @param[in/out] *FlashCommand Pointer to firmware update command. + Picked, depending on the device type. + @param[in/out] *Alignment File buffer alignment value. + @param[in/out] *Offset First logical block to be updated. + +**/ +STATIC +EFI_STATUS +EFIAPI +SelectDevice ( + IN LIST_ENTRY *CheckPackage, + IN OUT FLASH_COMMAND *FlashCommand, + IN OUT UINT64 *Alignment, + IN OUT EFI_LBA *Offset + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + CONST CHAR16 *DeviceName; + EFI_HANDLE Handle; + UINTN HandleIndex; + EFI_STATUS Status; + + // + // SPI flash + // + DeviceName =3D ShellCommandLineGetRawValue (CheckPackage, 2); + if (DeviceName =3D=3D NULL || StrnCmp(DeviceName, L"spi", 4) =3D=3D 0) { + *FlashCommand =3D ProgramSpiFlash; + *Alignment =3D 0; + *Offset =3D 0; + return EFI_SUCCESS; + } + + if (ShellCommandLineGetFlag (CheckPackage, SHELL_USE_DEVICE_PATH_PARAM))= { + // + // SD/MMC is selected using device path string. + // + Status =3D gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, + NULL, + (VOID **)&EfiDevicePathFromTextProtocol); + if (EFI_ERROR (Status)) { + Print (L"%s: cannot locate EfiDevicePathFromText protocol\n", + CMD_NAME_STRING); + return EFI_INVALID_PARAMETER; + } + + DevicePath =3D EfiDevicePathFromTextProtocol->ConvertTextToDevicePath = (DeviceName); + if (DevicePath =3D=3D NULL) { + Print (L"%s: cannot locate EfiDevicePathFromText protocol\n", + CMD_NAME_STRING); + return EFI_INVALID_PARAMETER; + } + + Status =3D gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, + &DevicePath, + &Handle); + if (EFI_ERROR (Status)) { + Print (L"%s: cannot locate selected block device\n", CMD_NAME_STRING= ); + return Status; + } + } else { + // + // SD/MMC device is selected using handle number. + // + HandleIndex =3D ShellHexStrToUintn (DeviceName); + if (HandleIndex =3D=3D (UINTN)(-1)) { + Print (L"%s: handle to device have to be hex number\n", CMD_NAME_STR= ING); + return EFI_INVALID_PARAMETER; + } + + Handle =3D ConvertHandleIndexToHandle (HandleIndex); + if (Handle =3D=3D NULL) { + Print (L"%s: %x is not correct device handle\n", + CMD_NAME_STRING, + HandleIndex); + return EFI_INVALID_PARAMETER; + } + } + + Status =3D IsDeviceSupported (Handle, Offset); + if (EFI_ERROR (Status)) { + Print (L"%s: device not supported\n", CMD_NAME_STRING); + return EFI_INVALID_PARAMETER; + } + + Status =3D gBS->OpenProtocol (Handle, + &gEfiBlockIoProtocolGuid, + (VOID**)&BlkIo, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR (Status)) { + Print (L"%s: Cannot open device BlokIo protocol\n", CMD_NAME_STRING); + return Status; + } + *FlashCommand =3D ProgramBlockDevice; + *Alignment =3D BlkIo->Media->BlockSize; =20 return EFI_SUCCESS; } @@ -222,11 +638,23 @@ FUpdateUsage ( ) { Print (L"\nFirmware update command\n" - "fupdate \n\n" + "fupdate [-p] [Device]\n\n" "LocalFilePath - path to local firmware image file\n" - "Example:\n" - "Update firmware from file fs2:flash-image.bin\n" - " fupdate fs2:flash-image.bin\n" + "-p - When flag is selected Device is interpreted\n" + " as device path, not device handle.\n" + "Device - Select device which will be flashed.\n" + " Supported devices can be listed using \"fupdate = list\"\n" + " command. Device is represented by its handle.\n" + " The default value is spi.\n" + "EXAMPLES:\n" + " * Update firmware in SPI flash from file fs2:flash-image.bin\n" + " fupdate fs2:flash-image.bin\n" + " * Update firmware in device with handle 5F from file flash-imag= e.bin\n" + " fupdate flash-image.bin 5F\n" + " * Update firmware in device with selected path from file flash.= bin\n" + " fupdate flash.bin -p VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D= 514A,000078F20000000000)/SD(0x0)\n" + " * List supported devices\n" + " fupdate list\n" ); } =20 @@ -238,36 +666,17 @@ ShellCommandRunFUpdate ( IN EFI_SYSTEM_TABLE *SystemTable ) { - IN SHELL_FILE_HANDLE FileHandle; - SPI_DEVICE *Slave =3D NULL; - UINT64 FileSize; - UINTN *FileBuffer =3D NULL; - CHAR16 *ProblemParam; - LIST_ENTRY *CheckPackage; - EFI_STATUS Status; - - // Locate SPI protocols - Status =3D gBS->LocateProtocol ( - &gMarvellSpiFlashProtocolGuid, - NULL, - (VOID **)&SpiFlashProtocol - ); - - if (EFI_ERROR(Status)) { - Print (L"%s: Cannot locate SpiFlash protocol\n", CMD_NAME_STRING); - return SHELL_ABORTED; - } - - Status =3D gBS->LocateProtocol ( - &gMarvellSpiMasterProtocolGuid, - NULL, - (VOID **)&SpiMasterProtocol - ); - - if (EFI_ERROR(Status)) { - Print (L"%s: Cannot locate SpiMaster protocol\n", CMD_NAME_STRING); - return SHELL_ABORTED; - } + SHELL_FILE_HANDLE FileHandle; + FLASH_COMMAND FlashCommand; + LIST_ENTRY *CheckPackage; + EFI_LBA Offset; + UINT64 Alignment; + UINT64 FileSize; + UINTN *FileBuffer; + CHAR16 *ProblemParam; + EFI_STATUS Status; + + FileBuffer =3D NULL; =20 // Parse command line Status =3D ShellInitialize (); @@ -283,14 +692,29 @@ ShellCommandRunFUpdate ( return SHELL_ABORTED; } =20 - if (ShellCommandLineGetFlag (CheckPackage, L"help")) { - FUpdateUsage(); + if (ShellCommandLineGetFlag (CheckPackage, SHELL_HELP_PARAM)) { + FUpdateUsage (); return EFI_SUCCESS; } =20 + if (ShellCommandLineGetFlag (CheckPackage, SHELL_LIST_PARAM)) { + ListSupportedDevices (); + return EFI_SUCCESS; + } + + // Select device to flash + Status =3D SelectDevice (CheckPackage, &FlashCommand, &Alignment, &Offse= t); + if (EFI_ERROR (Status)) { + return SHELL_ABORTED; + } + // Prepare local file to be burned into flash - Status =3D PrepareFirmwareImage (CheckPackage, &FileHandle, &FileBuffer,= &FileSize); - if (EFI_ERROR(Status)) { + Status =3D PrepareFirmwareImage (CheckPackage, + &FileHandle, + &FileBuffer, + &FileSize, + Alignment); + if (EFI_ERROR (Status)) { return SHELL_ABORTED; } =20 @@ -300,38 +724,22 @@ ShellCommandRunFUpdate ( goto HeaderError; } =20 - // Setup and probe SPI flash - Slave =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Slave, 0, 0= ); - if (Slave =3D=3D NULL) { - Print(L"%s: Cannot allocate SPI device!\n", CMD_NAME_STRING); + // Update firmware image + Status =3D FlashCommand (FileSize, FileBuffer, Offset); + if (EFI_ERROR (Status)) { goto HeaderError; } =20 - Status =3D SpiFlashProbe (Slave); - if (EFI_ERROR(Status)) { - Print (L"%s: Error while performing SPI flash probe\n", CMD_NAME_STRIN= G); - goto FlashProbeError; - } - - // Update firmware image in flash at offset 0x0 - Status =3D SpiFlashProtocol->Update (Slave, 0, FileSize, (UINT8 *)FileBu= ffer); - - // Release resources - SpiMasterProtocol->FreeDevice(Slave); FreePool (FileBuffer); ShellCloseFile (&FileHandle); =20 - if (EFI_ERROR(Status)) { - Print (L"%s: Error while performing flash update\n", CMD_NAME_STRING); - return SHELL_ABORTED; - } - - Print (L"%s: Update %d bytes at offset 0x0 succeeded!\n", CMD_NAME_STRIN= G, FileSize); + Print (L"%s: Update %d bytes at offset 0x%x succeeded!\n", + CMD_NAME_STRING, + FileSize, + Offset * Alignment); =20 return EFI_SUCCESS; =20 -FlashProbeError: - SpiMasterProtocol->FreeDevice(Slave); HeaderError: FreePool (FileBuffer); ShellCloseFile (&FileHandle); diff --git a/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.uni b/Sili= con/Marvell/Applications/FirmwareUpdate/FUpdate.uni index 146f624737d96e2cd354857dbb63390ebe2f347e..3ea892aa2a982827ad235c50527= 0acbca21ea27b 100644 GIT binary patch delta 1093 zcmah|(P|Sx6g@$uNPXDuTB`)<=3Du@MnS*4*0zNBf3VttT^MNE-2v2I|EF`G2{^GjGVIKqnRDmfd(Pc2ONT2TJ_kjEM<}C@9jLXAC)h_9 zZLT}=3DDaZwMaDVfdCISiA?FTH@~?VS zm%e&GVC(@`irB@_84tME|l?o+9`L+iPyc4F8Q99A3-4R=3D9=3Du9OE7XW zxFDy)q+nzm-uZo2(OUmx$g!>38h*bt~E;m3pUZQ&;(bkkG- delta 54 zcmV-60LlO6G{z{f!Vr_v7#NfG5Ly9HlTi^