From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=IGF7iFKI; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.222.193, mailfrom: mw@semihalf.com) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by groups.io with SMTP; Thu, 02 May 2019 07:32:00 -0700 Received: by mail-qk1-f193.google.com with SMTP id d5so1533652qko.12 for ; Thu, 02 May 2019 07:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=DQW9ST1LLNfefAQ4avkDt+BOvLmaPpkxmdG5wFXZBU8=; b=IGF7iFKISn0oPFkHCTqo15nJcX+PxCSV8eTKAkJnJ/50K2ib018VZn7bYvIzJIXpuz BR2httANYHxyxIe2z540zMt7HHHb0/l3uvuATSAaNnnfmB8pl9dABmi4tP2kDpsw3BSw CSPtWAE/b19VyFSKkHYUUfB5GAgwbMjNqmjVEhp6YbO4lmOAm5TlEKSVJMs48YBuWfPQ RTu/bMKuyzyrqUFqhCXrCUqzo+68tZ2nXPIpmYloKHLG3C9Lplu3zFNAdrJ4GCFUAWBi QoY8M6JXeDiVHduyDcHS0DGZut7xQkK0vSjT0jSZ1AZuYopOyorcx5MZc5P8kPfe3LZg DmEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=DQW9ST1LLNfefAQ4avkDt+BOvLmaPpkxmdG5wFXZBU8=; b=PsAbwwy8OMn8G5jhc2spZTfbLq4bGlabqiNUTX3IEycWOGkwqvVTZALSpbFJVJFR0g Qe0f0C/OLsnCDAnojHpCAHN25wveOnZwHawy7ngUZnIDmu62GMWfHnXgRv5wmIJx4kcy q1ouByvMHSxEXqDFAi5gMDo3Cbw1k6fs5qrh2zEq3w/VBMhwiGvuhBswi+2ZTa3iHsXh 1ZASzyUot04ulpo8iW0w1ZFrg+E+IJWYCGE0lIk0kbNfbpOWRlnlz6hIzJFDcccrhlLH TXY/YwcuAfLN/FHoU7VSbSwX/CsyOtxCD/HnvDPPiApaK5J13JnEF1k7bp4748SsoLW4 AxWg== X-Gm-Message-State: APjAAAUMtQ7k2Jo6f89dmyHzVsgYWpiv7FpJk9ho1jHd7SFKulxLiRDB zrwnAW3I8fFzmPc2NCPScBiNurx7EIn0o12I405FTw== X-Google-Smtp-Source: APXvYqxCHiDVjIZBHo+1j3ZZXmGbH8geHGV2z7bztisyuh8GXjUQM4jf1e9DT3/HtlWUeJYiGtBDbjHWe0wdkUGi4o0= X-Received: by 2002:a05:620a:13a7:: with SMTP id m7mr3278727qki.247.1556807519014; Thu, 02 May 2019 07:31:59 -0700 (PDT) MIME-Version: 1.0 References: <1556796685-3359-1-git-send-email-mw@semihalf.com> In-Reply-To: From: "Marcin Wojtas" Date: Thu, 2 May 2019 16:31:48 +0200 Message-ID: Subject: Re: [PATCH] Marvell/Applications: FirmwareUpdate: Enable burning image on SD/MMC To: Ard Biesheuvel Cc: edk2-devel-groups-io , Leif Lindholm , =?UTF-8?B?SmFuIETEhWJyb8Wb?= , Grzegorz Jaszczyk , Jici Gao , Tomasz Michalec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Ard, czw., 2 maj 2019 o 14:58 Ard Biesheuvel napisa= =C5=82(a): > > On Thu, 2 May 2019 at 13:31, Marcin Wojtas wrote: > > > > 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 possibl= e > > 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(0x0) > > 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 > > Pushed as cee103d37d6b..4795747fe477 > Wow, thanks - I didn't expect it to happen that fast :) If so, I'm submitting the last 3 small patches I have on my stack. PCIE most likely tomorrow. Afterwards SMBIOS and we'd be functionally ahead of any other branch for this SoC :) Best regard, Marcin > > --- > > 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/= Silicon/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 > > > > +[Pcd] > > + gMarvellTokenSpaceGuid.PcdSpiFlashCs > > + gMarvellTokenSpaceGuid.PcdSpiFlashMode > > + > > [Protocols] > > - gMarvellSpiFlashProtocolGuid > > - gMarvellSpiMasterProtocolGuid > > + gEfiBlockIoProtocolGuid > > + gEfiDevicePathFromTextProtocolGuid > > + gEfiDevicePathProtocolGuid > > + gMarvellSpiFlashProtocolGuid > > + gMarvellSpiMasterProtocolGuid > > > > [Guids] > > gShellFUpdateHiiGuid > > diff --git a/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.c b/Si= licon/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 = DAMAGE. > > #include > > #include > > #include > > +#include > > #include > > +#include > > #include > > #include > > #include > > @@ -46,22 +48,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUC= H DAMAGE. > > #include > > #include > > > > +#include > > +#include > > +#include > > #include > > #include > > > > #define CMD_NAME_STRING L"fupdate" > > > > +#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 > > > > -STATIC MARVELL_SPI_FLASH_PROTOCOL *SpiFlashProtocol; > > -STATIC MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol; > > +STATIC EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProto= col; > > +STATIC MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol; > > +STATIC MARVELL_SPI_FLASH_PROTOCOL *SpiFlashProtocol; > > +STATIC EFI_BLOCK_IO_PROTOCOL *BlkIo; > > > > STATIC CONST CHAR16 gShellFUpdateFileName[] =3D L"ShellCommands"; > > STATIC EFI_HANDLE gShellFUpdateHiiHandle =3D NULL; > > > > 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} > > }; > > > > typedef struct { // Bytes > > @@ -86,6 +103,14 @@ typedef struct { // Bytes > > UINT32 Reserved3; // 60-63 > > } MV_FIRMWARE_IMAGE_HEADER; > > > > +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; > > } > > > > +/** > > + 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; > > > > // 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); > > } > > > > + // Allocate aligned buffer in case of updating firmware in a BlockDe= vice > > + if (Alignment > 0) { > > + AlignedFileSize =3D *FileSize + (Alignment - (*FileSize % Alignmen= t)); > > + } 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; > > + } > > > > Status =3D FileHandleRead (*FileHandle, (UINTN *)FileSize, Buffer); > > if (EFI_ERROR (Status)) { > > @@ -196,6 +385,233 @@ PrepareFirmwareImage ( > > } > > > > *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_S= TRING); > > + 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_STRI= NG); > > + 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 comma= nd. > > + Picked, depending on the device = type. > > + @param[in/out] *Alignment File buffer alignment value. > > + @param[in/out] *Offset First logical block to be update= d. > > + > > +**/ > > +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_PAR= AM)) { > > + // > > + // SD/MMC is selected using device path string. > > + // > > + Status =3D gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGui= d, > > + 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->ConvertTextToDeviceP= ath (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_ST= RING); > > + 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= _STRING); > > + 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_STRIN= G); > > + return Status; > > + } > > + *FlashCommand =3D ProgramBlockDevice; > > + *Alignment =3D BlkIo->Media->BlockSize; > > > > 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 \"fupd= ate 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.bi= n\n" > > + " fupdate fs2:flash-image.bin\n" > > + " * Update firmware in device with handle 5F from file flash-= image.bin\n" > > + " fupdate flash-image.bin 5F\n" > > + " * Update firmware in device with selected path from file fl= ash.bin\n" > > + " fupdate flash.bin -p VenHw(0D51905B-B77E-452A-A2C0-ECA0= CC8D514A,000078F20000000000)/SD(0x0)\n" > > + " * List supported devices\n" > > + " fupdate list\n" > > ); > > } > > > > @@ -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; > > > > // Parse command line > > Status =3D ShellInitialize (); > > @@ -283,14 +692,29 @@ ShellCommandRunFUpdate ( > > return SHELL_ABORTED; > > } > > > > - if (ShellCommandLineGetFlag (CheckPackage, L"help")) { > > - FUpdateUsage(); > > + if (ShellCommandLineGetFlag (CheckPackage, SHELL_HELP_PARAM)) { > > + FUpdateUsage (); > > return EFI_SUCCESS; > > } > > > > + if (ShellCommandLineGetFlag (CheckPackage, SHELL_LIST_PARAM)) { > > + ListSupportedDevices (); > > + return EFI_SUCCESS; > > + } > > + > > + // Select device to flash > > + Status =3D SelectDevice (CheckPackage, &FlashCommand, &Alignment, &O= ffset); > > + if (EFI_ERROR (Status)) { > > + return SHELL_ABORTED; > > + } > > + > > // Prepare local file to be burned into flash > > - Status =3D PrepareFirmwareImage (CheckPackage, &FileHandle, &FileBuf= fer, &FileSize); > > - if (EFI_ERROR(Status)) { > > + Status =3D PrepareFirmwareImage (CheckPackage, > > + &FileHandle, > > + &FileBuffer, > > + &FileSize, > > + Alignment); > > + if (EFI_ERROR (Status)) { > > return SHELL_ABORTED; > > } > > > > @@ -300,38 +724,22 @@ ShellCommandRunFUpdate ( > > goto HeaderError; > > } > > > > - // 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; > > } > > > > - Status =3D SpiFlashProbe (Slave); > > - if (EFI_ERROR(Status)) { > > - Print (L"%s: Error while performing SPI flash probe\n", CMD_NAME_S= TRING); > > - goto FlashProbeError; > > - } > > - > > - // Update firmware image in flash at offset 0x0 > > - Status =3D SpiFlashProtocol->Update (Slave, 0, FileSize, (UINT8 *)Fi= leBuffer); > > - > > - // Release resources > > - SpiMasterProtocol->FreeDevice(Slave); > > FreePool (FileBuffer); > > ShellCloseFile (&FileHandle); > > > > - if (EFI_ERROR(Status)) { > > - Print (L"%s: Error while performing flash update\n", CMD_NAME_STRI= NG); > > - return SHELL_ABORTED; > > - } > > - > > - Print (L"%s: Update %d bytes at offset 0x0 succeeded!\n", CMD_NAME_S= TRING, FileSize); > > + Print (L"%s: Update %d bytes at offset 0x%x succeeded!\n", > > + CMD_NAME_STRING, > > + FileSize, > > + Offset * Alignment); > > > > return EFI_SUCCESS; > > > > -FlashProbeError: > > - SpiMasterProtocol->FreeDevice(Slave); > > HeaderError: > > FreePool (FileBuffer); > > ShellCloseFile (&FileHandle); > > diff --git a/Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.uni b/= Silicon/Marvell/Applications/FirmwareUpdate/FUpdate.uni > > index 146f624737d96e2cd354857dbb63390ebe2f347e..3ea892aa2a982827ad235c5= 05270acbca21ea27b 100644 > > GIT binary patch > > delta 1093 > > zcmah|(P|Sx6g@$uNPXDuTB`)<=3Du@MnS*4*0zNBf3VttT^MNE-2v2I|EF`G2{ > z@FxU|U!V{Ehai3S*(cAP$>^GjGVIKqnRDmfd(Pc2ONT2TJ_kjEM<}C@9jLXAC)h_9 > > zZLT}=3DDaZwMaDVfdCISiA?FTH@~?VS > > zm%e&GVC(@`i > zEzIWP%e`n}L-TLY!)H0|Kj!PoK| > z(fPcTo3_o&zm;0XJWC_is;nrJO?eYUv;Mw`i_^?(w;AUdhpTj%KDjEnb6O~~j$c*9 > > zF|La2;+4e=3DEx%KI<*TaPw>rB@_84tME|l?o+9`L+iPyc4F8Q99A3-4R=3D9=3Du9OE7X= W > > zxFDy)q+nzm-uZo2(OUmx$g!>38h*bt > zJ#=3DgmxBBlGM?2N_mXyNcjP|su{5U-S`mYfueNPOQ$)}5?f0Dri%k?ex&JtqkQpHu=3D > > zpjE{h|D!dma%|9A;mI}BXw|sZi74~D&Rxv8j_c0%CV@4!dpsGdyx63J-{;p7Ds1g_ > > m8~7y=3DC8eW6I~E;m3pUZQ&;(bkkG- > > > > delta 54 > > zcmV-60LlO6G{z{f!Vr_v7#NfG5Ly9HlTi^ > MlkN}*v+5Xp0aXzc(f|Me > > > > -- > > 2.7.4 > >