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=m306Ll+a; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.167.67, mailfrom: pdk@semihalf.com) Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by groups.io with SMTP; Mon, 09 Sep 2019 08:53:03 -0700 Received: by mail-lf1-f67.google.com with SMTP id z21so10940005lfe.1 for ; Mon, 09 Sep 2019 08:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g0vcZyw9wE2jz5RF7Mniga/UPgTLGPF5juE6WQO62P0=; b=m306Ll+aSiNWqdACzyNix575c2HpwOnByUykBD4Vcvr0OO4Gm41LFeHhiGeq9YSnU3 Mk4/vCS/1hKsvbcHoHMDeXoMRmYtLd/ZyiHlkWTeKCLevHCYCX6KD1gjbXnTJn2OmPsv V0F1eoLjZghMOtBfzUAXhL4/RP9IPsYp2FkLusVZCrVlExZyUjJdPtT6lUjzk/V86NXq caQodydKR9+wd78RI2czufJRgtiE+9UuyKWhEO9lyLu4sU8SomBlH8ZZITqsXAWvWP2H hRNEDamjE5DIQP1EmkG3gnz8/ye9zKyNIlR6WnJ0rJfHI8n8LOuE0jNRu8yBCGeUKHRB rLPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g0vcZyw9wE2jz5RF7Mniga/UPgTLGPF5juE6WQO62P0=; b=AbqZKW+65wzE52IYNcjcOXr87bz3Oj+Y7W1upJOp2nrMwjXulpSpbAN2XqlLDjHwAq jkA8U0+om6A7Dw99+yU8iD9LyK2+40uOwdnkTQGrY+rRC+X2B2zql8qPZdNgEKvFRpLq ZDgulseTDy9G3qrbSZV84fEAeOHq5CTrEiGLu2bWy1chjgUk0AEQ9yFMtFhplKzssvHl Ld2/9C3iaeRXrKfgpr9mOWIgJI7z7tZ0eSAfQstIJjS2Ym61cBREnzDbEOxIgp4eYsVr hYwfsM5niomq6aOaggmVn5hFbZw9atfzVfgI0QSdpHjFf+K+6Dwpsi8zCZSi5r27p83n LDwg== X-Gm-Message-State: APjAAAVZEBYTZpwSDLRD59evxFGAmjzL7kWDKxhTteSvuS2iD+e7CLLY HJ4NQ3R+E33m3PiiY1hbhZoTmPzPY0ikNQ== X-Google-Smtp-Source: APXvYqysINUjp9Uve/FHsNLFKr/e1kewOUziFf00v/a5h0hpHpgbsDvUpRrSbpbycewYQvkyH/5y6Q== X-Received: by 2002:ac2:4835:: with SMTP id 21mr16717795lft.121.1568044381273; Mon, 09 Sep 2019 08:53:01 -0700 (PDT) Return-Path: Received: from pdkmachine.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id d8sm3221238ljj.59.2019.09.09.08.53.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Sep 2019 08:53:00 -0700 (PDT) From: Patryk Duda To: devel@edk2.groups.io Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, mw@semihalf.com, jsd@semihalf.com, Patryk Duda Subject: [edk2-platforms: PATCH 2/2] Marvell/Drivers: MvSpiFlashDxe: Implement progress bar Date: Mon, 9 Sep 2019 17:52:12 +0200 Message-Id: <20190909155212.30338-3-pdk@semihalf.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190909155212.30338-1-pdk@semihalf.com> References: <20190909155212.30338-1-pdk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch implements TFTP-like progress bar in MvSpiFlashUpdateWithProgress. This is necessary because CapsuleRuntimeDxe uses DxeRuntimeCapsuleLib which uses CapsuleProcessLibNull implementation of capsule process. Signed-off-by: Patryk Duda --- Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf | 1 + Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h | 1 + Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c | 57 ++++++++++++++++---- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf index c6e93b82a1..088e9592e2 100644 --- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf +++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf @@ -23,6 +23,7 @@ DebugLib MemoryAllocationLib NorFlashInfoLib + PrintLib TimerLib UefiBootServicesTableLib UefiDriverEntryPoint diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h index 21877ba2a6..d51892c439 100755 --- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h +++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include +#include #include #include #include diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c index db12adb764..91e195b97c 100755 --- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c +++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c @@ -6,6 +6,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent *******************************************************************************/ #include "MvSpiFlashDxe.h" +// Frame for the progression slider +STATIC CONST CHAR16 mProgressFrame[] = L"[ ]"; + +// Number of steps in the progression slider +#define PROGRESS_SLIDER_STEPS ((sizeof (mProgressFrame) / sizeof (CHAR16)) - 3) + +// Size in number of characters plus one (final zero) of the message to +// indicate the progress of update. The format is "[(progress slider: +// 40 characters)] (nb of KBytes written so far: 7 characters) Kb". There +// are thus the number of characters in mProgressFrame[] plus 11 characters +// (2 // spaces, "Kb" and seven characters for the number of KBytes). +#define PROGRESS_MESSAGE_SIZE ((sizeof (mProgressFrame) / sizeof (CHAR16)) + 12) + +// String to delete progress message to be able to update it : +// (PROGRESS_MESSAGE_SIZE-1) '\b' +STATIC CONST CHAR16 mProgressDelete[] = L"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" + "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" + "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"; + STATIC EFI_EVENT mMvSpiFlashVirtualAddrChangeEvent; MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol; SPI_FLASH_INSTANCE *mSpiFlashInstance; @@ -380,12 +399,15 @@ MvSpiFlashUpdateWithProgress ( IN UINTN EndPercentage ) { + CHAR16 ProgressBar[PROGRESS_MESSAGE_SIZE]; + UINTN ProgressIndex; EFI_STATUS Status; UINTN SectorSize; UINTN SectorNum; UINTN ToUpdate; - UINTN Index; UINT8 *TmpBuf; + UINTN Index; + UINTN Step; SectorSize = Slave->Info->SectorSize; SectorNum = (ByteCount / SectorSize) + 1; @@ -397,12 +419,9 @@ MvSpiFlashUpdateWithProgress ( return EFI_OUT_OF_RESOURCES; } - for (Index = 0; Index < SectorNum; Index++) { - if (Progress != NULL) { - Progress (StartPercentage + - ((Index * (EndPercentage - StartPercentage)) / SectorNum)); - } + Print(L"%s 0 Kb", mProgressFrame); + for (Index = 0; Index < SectorNum; Index++) { // In the last chunk update only an actual number of remaining bytes. if (Index + 1 == SectorNum) { ToUpdate = ByteCount % SectorSize; @@ -418,12 +437,32 @@ MvSpiFlashUpdateWithProgress ( DEBUG ((DEBUG_ERROR, "%a: Error while updating\n", __FUNCTION__)); return Status; } + + ProgressBar[0] = L'\0'; + Step = ((Index * SectorSize + ToUpdate) * PROGRESS_SLIDER_STEPS) / ByteCount; + + Print (L"%s", mProgressDelete); + + Status = StrCpyS (ProgressBar, PROGRESS_MESSAGE_SIZE, mProgressFrame); + if (EFI_ERROR(Status)) { + return Status; + } + for (ProgressIndex = 1; ProgressIndex < Step; ProgressIndex++) { + ProgressBar[ProgressIndex] = L'='; + } + ProgressBar[Step] = L'>'; + UnicodeSPrint ( + ProgressBar + (sizeof (mProgressFrame) / sizeof (CHAR16)) - 1, + sizeof (ProgressBar) - sizeof (mProgressFrame), + L" %7d Kb", + (Index * SectorSize + ToUpdate) / 1024 + ); + + Print(L"%s", ProgressBar); } FreePool (TmpBuf); - if (Progress != NULL) { - Progress (EndPercentage); - } + Print (L"\n"); return EFI_SUCCESS; } -- 2.21.0