From nobody Sat Nov 2 08:26:16 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; dkim=fail spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1492163746500917.3480502975424; Fri, 14 Apr 2017 02:55:46 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E2E712194EB5C; Fri, 14 Apr 2017 02:55:43 -0700 (PDT) Received: from mail-pg0-x230.google.com (mail-pg0-x230.google.com [IPv6:2607:f8b0:400e:c05::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F179B21A04830 for ; Fri, 14 Apr 2017 02:55:42 -0700 (PDT) Received: by mail-pg0-x230.google.com with SMTP id x125so42082455pgb.0 for ; Fri, 14 Apr 2017 02:55:42 -0700 (PDT) Received: from localhost.localdomain ([45.56.159.122]) by smtp.gmail.com with ESMTPSA id v8sm2500020pfd.108.2017.04.14.02.55.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Apr 2017 02:55:41 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=3ME2CAgUqpBNdY4UdOIN6MW56Ib3tgy7SWbQJ+kAgR0=; b=Bwpc4iKer7BWtKhBxVXMiKQAnfQ9P++IDyanPUCrQbu5Woka/l1z8eCxTbPjgamdB2 PmTxbQQYQpux9vMWbEpgYD95izQ4N9HnUgeBl/1giofzaR5rvh0YL3E/JFTbWFzvO0VR c7ALC3toEeOcJJtKjxHmY8ZFtR8+IJyoiRINQ= 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; bh=3ME2CAgUqpBNdY4UdOIN6MW56Ib3tgy7SWbQJ+kAgR0=; b=Z8pOhPtlJaw3Lfup6piF1HGx+Oxd5NOXbGMh0ByS/5p+e8LwzvGwvMMoIU234N9CIv UIQkdlY/zThyfwBy0J5UNWEpaoUrDTrfDtnS3xAi6Whu7SSrMBS/BYUc3QxysE5BExpW 966M4UyuWkMlFPU4zGntKDa4BOCih+kcAEIYSW0RPJMJahCLk4cd8iNYAkVVmraiV9k5 mhEbxxak+tvFeVETKHwTH4Iaq4AXdDYbuDIfmowNDKX6OaQj9zuTQlrr1iRySAK7bYMS nxx9T4xFKg6b0cOYLWHBHR25O5uQy6xRLQP9gKTR2qaaGuqBc7IYusjQBEz2X3NYeAVr RISA== X-Gm-Message-State: AN3rC/7zSFdFiD+F5Re3/fZMh8HNNUE5PTwCADTQXdJEMLcEWXcgXyjR AjWfp9nvbbH/F9BW X-Received: by 10.99.97.75 with SMTP id v72mr174522pgb.76.1492163742410; Fri, 14 Apr 2017 02:55:42 -0700 (PDT) From: Haojian Zhuang To: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, edk2-devel@lists.01.org Date: Fri, 14 Apr 2017 17:55:32 +0800 Message-Id: <1492163732-3264-1-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [PATCH] EmbeddedPkg/AndroidFastbootApp: support sparse image X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haojian Zhuang MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Support sparse image that is reformatted from large raw image and splitted into a few smaller images. The sparse image follows the rule of Android Sparse Image format. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Haojian Zhuang --- .../AndroidFastboot/AndroidFastbootApp.c | 127 +++++++++++++++++= ++-- .../Include/Protocol/AndroidFastbootPlatform.h | 23 ++++ 2 files changed, 142 insertions(+), 8 deletions(-) diff --git a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c b= /EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c index 61abc67..4883a77 100644 --- a/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c +++ b/EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.c @@ -25,7 +25,34 @@ #include #include =20 -#define ANDROID_FASTBOOT_VERSION "0.4" +#define ANDROID_FASTBOOT_VERSION "0.5" + +#define SPARSE_HEADER_MAGIC 0xED26FF3A +#define CHUNK_TYPE_RAW 0xCAC1 +#define CHUNK_TYPE_FILL 0xCAC2 +#define CHUNK_TYPE_DONT_CARE 0xCAC3 +#define CHUNK_TYPE_CRC32 0xCAC4 + +#define FILL_BUF_SIZE 1024 + +typedef struct _SPARSE_HEADER { + UINT32 Magic; + UINT16 MajorVersion; + UINT16 MinorVersion; + UINT16 FileHeaderSize; + UINT16 ChunkHeaderSize; + UINT32 BlockSize; + UINT32 TotalBlocks; + UINT32 TotalChunks; + UINT32 ImageChecksum; +} SPARSE_HEADER; + +typedef struct _CHUNK_HEADER { + UINT16 ChunkType; + UINT16 Reserved1; + UINT32 ChunkSize; + UINT32 TotalSize; +} CHUNK_HEADER; =20 /* * UEFI Application using the FASTBOOT_TRANSPORT_PROTOCOL and @@ -139,13 +166,83 @@ HandleDownload ( } =20 STATIC +EFI_STATUS +FlashSparseImage ( + IN CHAR8 *PartitionName, + IN SPARSE_HEADER *SparseHeader + ) +{ + EFI_STATUS Status; + UINTN Chunk, Offset =3D 0, Index; + VOID *Image; + CHUNK_HEADER *ChunkHeader; + UINT32 FillBuf[FILL_BUF_SIZE]; + CHAR16 OutputString[FASTBOOT_STRING_MAX_LENGTH]; + + Image =3D (VOID *)SparseHeader; + Image +=3D SparseHeader->FileHeaderSize; + for (Chunk =3D 0; Chunk < SparseHeader->TotalChunks; Chunk++) { + ChunkHeader =3D (CHUNK_HEADER *)Image; + DEBUG ((DEBUG_INFO, "Chunk #%d - Type: 0x%x Size: %d TotalSize: %d Off= set %d\n", + (Chunk+1), ChunkHeader->ChunkType, ChunkHeader->ChunkSize, + ChunkHeader->TotalSize, Offset)); + Image +=3D sizeof (CHUNK_HEADER); + switch (ChunkHeader->ChunkType) { + case CHUNK_TYPE_RAW: + Status =3D mPlatform->FlashPartitionEx ( + PartitionName, + Offset, + ChunkHeader->ChunkSize * SparseHeader->BlockSi= ze, + Image + ); + if (EFI_ERROR (Status)) { + return Status; + } + Image +=3D ChunkHeader->ChunkSize * SparseHeader->BlockSize; + Offset +=3D ChunkHeader->ChunkSize * SparseHeader->BlockSize; + break; + case CHUNK_TYPE_FILL: + SetMem32 (FillBuf, FILL_BUF_SIZE * sizeof (UINT32), *(UINT32 *)Image= ); + Image +=3D sizeof (UINT32); + for (Index =3D 0; Index < ChunkHeader->ChunkSize; Index++) { + Status =3D mPlatform->FlashPartitionEx ( + PartitionName, + Offset, + SparseHeader->BlockSize, + FillBuf + ); + if (EFI_ERROR (Status)) { + return Status; + } + Offset +=3D SparseHeader->BlockSize; + } + break; + case CHUNK_TYPE_DONT_CARE: + Offset +=3D ChunkHeader->ChunkSize * SparseHeader->BlockSize; + break; + default: + UnicodeSPrint ( + OutputString, + sizeof (OutputString), + L"Unsupported Chunk Type:0x%x\n", + ChunkHeader->ChunkType + ); + mTextOut->OutputString (mTextOut, OutputString); + break; + } + } + return Status; +} + +STATIC VOID HandleFlash ( IN CHAR8 *PartitionName ) { - EFI_STATUS Status; - CHAR16 OutputString[FASTBOOT_STRING_MAX_LENGTH]; + EFI_STATUS Status; + CHAR16 OutputString[FASTBOOT_STRING_MAX_LENGTH]; + SPARSE_HEADER *SparseHeader; =20 // Build output string UnicodeSPrint (OutputString, sizeof (OutputString), L"Flashing partition= %a\r\n", PartitionName); @@ -157,11 +254,25 @@ HandleFlash ( return; } =20 - Status =3D mPlatform->FlashPartition ( - PartitionName, - mNumDataBytes, - mDataBuffer - ); + SparseHeader =3D (SPARSE_HEADER *)mDataBuffer; + if (SparseHeader->Magic =3D=3D SPARSE_HEADER_MAGIC) { + DEBUG ((DEBUG_INFO, "Sparse Magic: 0x%x Major: %d Minor: %d fhs: %d ch= s: %d bs: %d tbs: %d tcs: %d checksum: %d \n", + SparseHeader->Magic, SparseHeader->MajorVersion, SparseHea= der->MinorVersion, SparseHeader->FileHeaderSize, + SparseHeader->ChunkHeaderSize, SparseHeader->BlockSize, Sp= arseHeader->TotalBlocks, + SparseHeader->TotalChunks, SparseHeader->ImageChecksum)); + if (SparseHeader->MajorVersion !=3D 1) { + DEBUG ((DEBUG_ERROR, "Sparse image version %d.%d not supported.\n", + SparseHeader->MajorVersion, SparseHeader->MinorVersion= )); + return; + } + Status =3D FlashSparseImage (PartitionName, SparseHeader); + } else { + Status =3D mPlatform->FlashPartition ( + PartitionName, + mNumDataBytes, + mDataBuffer + ); + } if (Status =3D=3D EFI_NOT_FOUND) { SEND_LITERAL ("FAILNo such partition."); mTextOut->OutputString (mTextOut, L"No such partition.\r\n"); diff --git a/EmbeddedPkg/Include/Protocol/AndroidFastbootPlatform.h b/Embed= dedPkg/Include/Protocol/AndroidFastbootPlatform.h index a9b4aac..2cb51eb 100644 --- a/EmbeddedPkg/Include/Protocol/AndroidFastbootPlatform.h +++ b/EmbeddedPkg/Include/Protocol/AndroidFastbootPlatform.h @@ -133,6 +133,28 @@ EFI_STATUS IN CHAR8 *Command ); =20 +/* + Flash the partition named (according to a platform-specific scheme) + PartitionName, with partition offset and the image pointed to by Buffer, + whose size is BufferSize. + + @param[in] PartitionName Null-terminated name of partition to write. + @param[in] Offset Offset of partition. + @param[in] BufferSize Size of Buffer in byets. + @param[in] Buffer Data to write to partition. + + @retval EFI_NOT_FOUND No such partition. + @retval EFI_DEVICE_ERROR Flashing failed. +*/ +typedef +EFI_STATUS +(*FASTBOOT_PLATFORM_FLASH_EX) ( + IN CHAR8 *PartitionName, + IN UINTN Offset, + IN UINTN BufferSize, + IN VOID *Buffer + ); + typedef struct _FASTBOOT_PLATFORM_PROTOCOL { FASTBOOT_PLATFORM_INIT Init; FASTBOOT_PLATFORM_UN_INIT UnInit; @@ -140,6 +162,7 @@ typedef struct _FASTBOOT_PLATFORM_PROTOCOL { FASTBOOT_PLATFORM_ERASE ErasePartition; FASTBOOT_PLATFORM_GETVAR GetVar; FASTBOOT_PLATFORM_OEM_COMMAND DoOemCommand; + FASTBOOT_PLATFORM_FLASH_EX FlashPartitionEx; } FASTBOOT_PLATFORM_PROTOCOL; =20 #endif --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel