From patchwork Mon Aug 20 10:31:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 144565 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3797156ljj; Mon, 20 Aug 2018 03:32:02 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxiU8JBjvBIqXhrPjj+n85xIPGVO2XOCdRu+kSM82rXyQQnf5nUsRHuZP5KjJQ1hZBcFFbE X-Received: by 2002:a63:aa44:: with SMTP id x4-v6mr43070780pgo.120.1534761122030; Mon, 20 Aug 2018 03:32:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534761122; cv=none; d=google.com; s=arc-20160816; b=ctvm1enM5CIs7LD2cEyETMB1Tcxko0VOCieWGOu0tKns7WzaPotUfSeW7Z8I9fR+T6 70iIY9eiAn4Nn217Z69fVuSdzwgw9I0W82CqIQF4CkD1592BrRqcGg7Bmn48r2qN3wFG /2wFgb5gVGjcjgiWqURMNGcU6+SDnpQZnZmDq87we3sWchM6HaNhaPhQQsEqtRxKWlL5 y2fNSfYXVXMowXI364O70Nf8MVOLnnNJMWAyhCZ7ja1SNdc0gLF7kxIzdl12kGTqJL0y qeHoJXPkeovdoeJIJtmSiGXuBcwNaeHuwXv6ev9RtTcWpIiMG/e5yETn2K0OM8dsrZYQ WJhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=ZlIUriNBA0Mq1E48rlAXelUi7SAbw44a1SS5Wby1WsU=; b=bJLd2MxfWabilwh1j6KCY5GaT5+kApZB3sTE4m/EyOkJCxWYdW3dSuKmJaFMjY6+MM XbA60sA4oOmTSjk4U1kmFgPxbPWcUg5V+3/nkE6jpr9cP4otE4riJmd770hTeqFFiZG0 4Uw8N7KhUNdnLLsMFOgQpeujnlMzoDliCogjisL5He3P1w/lt8lhDG9CMJhhMGc6CKUc o6yEZkQH/SZ8oCEpQWlJGh66c50UHp0TTYkQTQvNrPXMXLF4AbhN1DoH0nVIfqMGhQL5 I7mPTE8FoLZkTWwssOqYCtz2QJWBOMx2ldnhgBnGLV5mNahLTfKkYN4vMp6gZA6FW3ld EhVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N6reDEqR; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id z1-v6si9698181plo.222.2018.08.20.03.32.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 03:32:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N6reDEqR; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9E88E210F6255; Mon, 20 Aug 2018 03:32:01 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::52e; helo=mail-pg1-x52e.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (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 D19AF210D83CD for ; Mon, 20 Aug 2018 03:32:00 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id r1-v6so6558194pgp.11 for ; Mon, 20 Aug 2018 03:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XmaZchu2QgVwFQLLo7SieX1Ebfmp6GFHMnRB2Qh6eRM=; b=N6reDEqRkf2upgo4icwsel3ZWo6LrYYyVZcoRQt37jXCxkMfzL1OSN49a8NYRghUYw 3guvSruTaoS/rh0Jv7OcyBBV9sjNUAZY8aWaxpmYYjsWQstO8Uz6AkJyeM32E8Tp3Jpj 7fuq8CbtjcCxMrsVrZx4Dzz4Tbd2cM92pPsUs= 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; bh=XmaZchu2QgVwFQLLo7SieX1Ebfmp6GFHMnRB2Qh6eRM=; b=GULPjdOF0PRrpp3cDFjHE/hoWIKCHNm7pN+sl5/vSSBmDbb6mXrRl1Dfjt5A38GId0 DzccqK934VcD5OmY7TR3Tg8WW66RWyYjUBOETvaBA3IQ9E2zbmc25AdBVuprWw4OKC4y U4qPQtsTeZ1kf9s+JSMZ27VlYk/nYFF8dshpZhEg2J4JBpyqMjPMEIMqr0p8r3Y5Fb0N qTMevdSefIbuUo6S2z6teM2FEZSPkdN8VEC+8MjYRAdc1234idzlt0l/YxxS1gbqpRcv cmk8vATMieYeWonYIKdSJ4c/l57u+0DChBn2sPuX1zoncnjz8Ra2Dme7O7hZkGUXjIcg 9gUw== X-Gm-Message-State: AOUpUlEdvN26O+TJEeeBKC0ZReZV95KfktElS290YgS4YExl+ytx07tY aG2BX78qFMILA80oGrpm8RMRuHLYt8NRPA== X-Received: by 2002:a62:3a5b:: with SMTP id h88-v6mr47699436pfa.61.1534761118879; Mon, 20 Aug 2018 03:31:58 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.180]) by smtp.gmail.com with ESMTPSA id s195-v6sm24217163pgs.76.2018.08.20.03.31.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Aug 2018 03:31:57 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Mon, 20 Aug 2018 18:31:46 +0800 Message-Id: <1534761109-27037-2-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> References: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk-platforms v1 1/4] Platform/Hisilicon: add UsbSerialNumberLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Add UsbSerialNumberLib. The Library could generate USB Serial Number that is used in USB device driver. And it could load/save the USB Serial Number into storage device. Cc: Leif Lindholm Cc: Ard Biesheuvel Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Haojian Zhuang --- Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.dec | 32 ++ Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.inf | 45 +++ Platform/Hisilicon/Library/UsbSerialNumberLib/Include/Library/UsbSerialNumberLib.h | 59 ++++ Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.c | 341 ++++++++++++++++++++ 4 files changed, 477 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.dec b/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.dec new file mode 100644 index 000000000000..4b8b2e047ed9 --- /dev/null +++ b/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.dec @@ -0,0 +1,32 @@ +# +# Copyright (c) 2018, Linaro Limited. All rights reserved. +# +# This program and the accompanying materials are licensed and made available +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +[Defines] + DEC_SPECIFICATION = 0x00010019 + PACKAGE_NAME = UsbSerialNumberPkg + PACKAGE_GUID = dcd67420-4220-4b01-a8ba-1fa97fda1678 + PACKAGE_VERSION = 0.1 + +################################################################################ +# +# Include Section - list of Include Paths that are provided by this package. +# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +################################################################################ +[Includes.common] + Include # Root include for the package + +[Guids.common] + gUsbSerialNumberTokenSpaceGuid = { 0x0572f26b, 0x1a88, 0x49c2, { 0xb6, 0x98, 0x4d, 0xe0, 0xd0, 0x2a, 0xfe, 0x09 } } diff --git a/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.inf b/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.inf new file mode 100644 index 000000000000..70ea086d324e --- /dev/null +++ b/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.inf @@ -0,0 +1,45 @@ +#/** @file +# +# Copyright (c) 2018, Linaro. All rights reserved. +# +# This program and the accompanying materials are licensed and made available +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = UsbSerialNumberLib + FILE_GUID = 88709c56-2a76-4a13-8bcf-427970b7e32a + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = UsbSerialNumberLib + +# +# The following information is for reference only and not required by the build tools. +# + VALID_ARCHITECTURES = ARM AARCH64 + +[Sources] + UsbSerialNumberLib.c + +[LibraryClasses] + ArmGenericTimerCounterLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiLib + +[Protocols] + gEfiBlockIoProtocolGuid + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.dec diff --git a/Platform/Hisilicon/Library/UsbSerialNumberLib/Include/Library/UsbSerialNumberLib.h b/Platform/Hisilicon/Library/UsbSerialNumberLib/Include/Library/UsbSerialNumberLib.h new file mode 100644 index 000000000000..d3307153ff11 --- /dev/null +++ b/Platform/Hisilicon/Library/UsbSerialNumberLib/Include/Library/UsbSerialNumberLib.h @@ -0,0 +1,59 @@ +/** @file + + Copyright (c) 2017, Linaro. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __USB_SERIAL_NUMBER_LIB_H__ +#define __USB_SERIAL_NUMBER_LIB_H__ + +#include + +#define SERIAL_NUMBER_SIZE 17 + +typedef struct { + UINT64 Magic; + UINT64 Data; + CHAR16 UnicodeSN[SERIAL_NUMBER_SIZE]; +} RANDOM_SERIAL_NUMBER; + +EFI_STATUS +GenerateUsbSNBySeed ( + IN UINT32 Seed, + OUT RANDOM_SERIAL_NUMBER *RandomSN + ); + +EFI_STATUS +GenerateUsbSN ( + OUT CHAR16 *UnicodeSN + ); + +EFI_STATUS +AssignUsbSN ( + IN CHAR8 *AsciiCmd, + OUT CHAR16 *UnicodeSN + ); + +EFI_STATUS +LoadSNFromBlock ( + IN EFI_HANDLE FlashHandle, + IN EFI_LBA Lba, + OUT CHAR16 *UnicodeSN + ); + +EFI_STATUS +StoreSNToBlock ( + IN EFI_HANDLE FlashHandle, + IN EFI_LBA Lba, + IN CHAR16 *UnicodeSN + ); + +#endif /* __USB_SERIAL_NUMBER_LIB_H__ */ diff --git a/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.c b/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.c new file mode 100644 index 000000000000..98552f5f72fc --- /dev/null +++ b/Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.c @@ -0,0 +1,341 @@ +/** @file + + Copyright (c) 2018, Linaro. All rights reserved. + + This program and the accompanying materials are licensed and made available + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define SERIAL_NUMBER_LEN 16 +#define SERIAL_NUMBER_SIZE 17 + +#define RANDOM_MAX 0x7FFFFFFFFFFFFFFF +#define RANDOM_MAGIC 0x9A4DBEAF + +STATIC +EFI_STATUS +GenerateRandomData ( + IN UINT32 Seed, + OUT UINT64 *RandomData + ) +{ + INT64 Quotient, Remainder, Tmp; + + if (RandomData == NULL) { + return EFI_INVALID_PARAMETER; + } + Quotient = (INT64) Seed / 127773; + Remainder = (INT64) Seed % 127773; + Tmp = (16807 * Remainder) - (2836 * Quotient); + if (Tmp < 0) { + Tmp += RANDOM_MAX; + } + Tmp = Tmp % ((UINT64)RANDOM_MAX + 1); + *RandomData = (UINT64)Tmp; + return EFI_SUCCESS; +} + +EFI_STATUS +GenerateUsbSNBySeed ( + IN UINT32 Seed, + OUT RANDOM_SERIAL_NUMBER *RandomSN + ) +{ + EFI_STATUS Status; + UINT64 Tmp; + + if (RandomSN == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (RandomSN, sizeof (RANDOM_SERIAL_NUMBER)); + Status = GenerateRandomData (Seed, &Tmp); + if (EFI_ERROR (Status)) { + return Status; + } + RandomSN->Data = (Tmp << 32) | Seed; + UnicodeSPrint ( + RandomSN->UnicodeSN, + SERIAL_NUMBER_SIZE * sizeof (CHAR16), + L"%lx", + RandomSN->Data + ); + RandomSN->Magic = RANDOM_MAGIC; + return EFI_SUCCESS; +} + +EFI_STATUS +GenerateUsbSN ( + OUT CHAR16 *UnicodeSN + ) +{ + EFI_STATUS Status; + UINT64 Tmp; + UINT32 Seed; + RANDOM_SERIAL_NUMBER RandomSN; + + if (UnicodeSN == NULL) { + return EFI_INVALID_PARAMETER; + } + ZeroMem (&RandomSN, sizeof (RANDOM_SERIAL_NUMBER)); + Seed = ArmGenericTimerGetSystemCount (); + Status = GenerateRandomData (Seed, &Tmp); + if (EFI_ERROR (Status)) { + return Status; + } + RandomSN.Data = (Tmp << 32) | Seed; + UnicodeSPrint ( + RandomSN.UnicodeSN, + SERIAL_NUMBER_SIZE * sizeof (CHAR16), + L"%lx", + RandomSN.Data + ); + StrCpyS (UnicodeSN, SERIAL_NUMBER_SIZE * sizeof (CHAR16), RandomSN.UnicodeSN); + return EFI_SUCCESS; +} + +EFI_STATUS +AssignUsbSN ( + IN CHAR8 *AsciiCmd, + OUT CHAR16 *UnicodeSN + ) +{ + CHAR8 Data; + UINTN Index; + RANDOM_SERIAL_NUMBER RandomSN; + + if ((AsciiCmd == NULL) || (UnicodeSN == NULL)) { + return EFI_INVALID_PARAMETER; + } + for (Index = 0; Index < SERIAL_NUMBER_LEN; Index++) { + Data = *(AsciiCmd + Index); + if (((Data >= '0') && (Data <= '9')) || + ((Data >= 'A') && (Data <= 'F'))) { + continue; + } + // + // Always use with upper case + // + if ((Data >= 'a') && (Data <= 'f')) { + *(AsciiCmd + Index) = Data - 'a' + 'A'; + continue; + } + if (Data == '\0') { + break; + } + return EFI_INVALID_PARAMETER; + } + ZeroMem (&RandomSN, sizeof (RANDOM_SERIAL_NUMBER)); + AsciiStrToUnicodeStr (AsciiCmd, RandomSN.UnicodeSN); + StrCpyS (UnicodeSN, SERIAL_NUMBER_SIZE * sizeof (CHAR16), RandomSN.UnicodeSN); + return EFI_SUCCESS; +} + +EFI_STATUS +LoadSNFromBlock ( + IN EFI_HANDLE FlashHandle, + IN EFI_LBA Lba, + OUT CHAR16 *UnicodeSN + ) +{ + EFI_STATUS Status; + EFI_BLOCK_IO_PROTOCOL *BlockIoProtocol; + VOID *DataPtr; + BOOLEAN Found = FALSE; + UINT32 Seed; + RANDOM_SERIAL_NUMBER *RandomSN; + UINTN NumPages; + CHAR16 UnicodeStr[SERIAL_NUMBER_SIZE]; + + if (UnicodeSN == NULL) { + return EFI_INVALID_PARAMETER; + } + Status = gBS->OpenProtocol ( + FlashHandle, + &gEfiBlockIoProtocolGuid, + (VOID **) &BlockIoProtocol, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_WARN, + "Warning: Couldn't open block device (status: %r)\n", + Status + )); + return EFI_DEVICE_ERROR; + } + + NumPages = EFI_SIZE_TO_PAGES (BlockIoProtocol->Media->BlockSize); + DataPtr = AllocatePages (NumPages); + if (DataPtr == NULL) { + return EFI_BUFFER_TOO_SMALL; + } + Status = BlockIoProtocol->ReadBlocks ( + BlockIoProtocol, + BlockIoProtocol->Media->MediaId, + Lba, + BlockIoProtocol->Media->BlockSize, + DataPtr + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "Warning: Failed on reading blocks\n")); + goto Exit; + } + + Seed = ArmGenericTimerGetSystemCount (); + RandomSN = (RANDOM_SERIAL_NUMBER *)DataPtr; + if (RandomSN->Magic == RANDOM_MAGIC) { + Found = TRUE; + // + // Verify the unicode string. + // + ZeroMem (UnicodeStr, SERIAL_NUMBER_SIZE * sizeof (CHAR16)); + UnicodeSPrint ( + UnicodeStr, + SERIAL_NUMBER_SIZE * sizeof (CHAR16), + L"%lx", + RandomSN->Data + ); + if (StrLen (RandomSN->UnicodeSN) != StrLen (UnicodeStr)) { + Found = FALSE; + } + if (StrnCmp (RandomSN->UnicodeSN, UnicodeStr, StrLen (UnicodeStr)) != 0) { + Found = FALSE; + } + } + if (Found == FALSE) { + Status = GenerateUsbSNBySeed (Seed, RandomSN); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "Warning: Failed to generate serial number\n")); + goto Exit; + } + // + // Update SN to block device + // + Status = BlockIoProtocol->WriteBlocks ( + BlockIoProtocol, + BlockIoProtocol->Media->MediaId, + Lba, + BlockIoProtocol->Media->BlockSize, + DataPtr + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "Warning: Failed on writing blocks\n")); + goto Exit; + } + } + CopyMem ( + UnicodeSN, + RandomSN->UnicodeSN, + SERIAL_NUMBER_SIZE * sizeof (CHAR16) + ); +Exit: + FreePages (DataPtr, NumPages); + return Status; +} + +EFI_STATUS +StoreSNToBlock ( + IN EFI_HANDLE FlashHandle, + IN EFI_LBA Lba, + IN CHAR16 *UnicodeSN + ) +{ + EFI_STATUS Status; + EFI_BLOCK_IO_PROTOCOL *BlockIoProtocol; + VOID *DataPtr; + UINTN NumPages; + RANDOM_SERIAL_NUMBER *RandomSN; + CHAR16 UnicodeStr[SERIAL_NUMBER_SIZE]; + + if (UnicodeSN == NULL) { + return EFI_INVALID_PARAMETER; + } + Status = gBS->OpenProtocol ( + FlashHandle, + &gEfiBlockIoProtocolGuid, + (VOID **) &BlockIoProtocol, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_WARN, + "Warning: Couldn't open block device (status: %r)\n", + Status + )); + return EFI_DEVICE_ERROR; + } + NumPages = EFI_SIZE_TO_PAGES (BlockIoProtocol->Media->BlockSize); + DataPtr = AllocatePages (NumPages); + if (DataPtr == NULL) { + return EFI_BUFFER_TOO_SMALL; + } + ZeroMem (DataPtr, BlockIoProtocol->Media->BlockSize); + RandomSN = (RANDOM_SERIAL_NUMBER *)DataPtr; + RandomSN->Magic = RANDOM_MAGIC; + StrnCpyS ( + RandomSN->UnicodeSN, + SERIAL_NUMBER_SIZE * sizeof (CHAR16), + UnicodeSN, + StrSize (UnicodeSN) + ); + RandomSN->Data = StrHexToUint64 (RandomSN->UnicodeSN); + + // + // Verify the unicode string. + // + ZeroMem (UnicodeStr, SERIAL_NUMBER_SIZE * sizeof (CHAR16)); + UnicodeSPrint ( + UnicodeStr, + SERIAL_NUMBER_SIZE * sizeof (CHAR16), + L"%lx", + RandomSN->Data + ); + if (StrLen (RandomSN->UnicodeSN) != StrLen (UnicodeStr)) { + Status = EFI_INVALID_PARAMETER; + goto Exit; + } + if (StrnCmp (RandomSN->UnicodeSN, UnicodeStr, StrLen (UnicodeStr)) != 0) { + Status = EFI_INVALID_PARAMETER; + goto Exit; + } + + Status = BlockIoProtocol->WriteBlocks ( + BlockIoProtocol, + BlockIoProtocol->Media->MediaId, + Lba, + BlockIoProtocol->Media->BlockSize, + DataPtr + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "Warning: Failed on writing blocks\n")); + goto Exit; + } +Exit: + FreePages (DataPtr, NumPages); + return Status; +} From patchwork Mon Aug 20 10:31:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 144566 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3797221ljj; Mon, 20 Aug 2018 03:32:05 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyQ2kJKkbQm2cIXsp8QrsoQbtj7z+nn+2Cdmd96dob68bJx+uAR4IeEPttXQwxC4EGIiYk6 X-Received: by 2002:ac8:44d2:: with SMTP id b18-v6mr41895866qto.167.1534761125309; Mon, 20 Aug 2018 03:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534761125; cv=none; d=google.com; s=arc-20160816; b=0Fy6HGh6gvVnprcvc2xQVRBqH4QRn0xsc3PETsFshPS80TOXfhYPMTjL/UCHpjq/C9 qbGkaQDNxdID+eGP7RSjBIzzAKRg514dvYrt3IubOuJxag9P5KrJ9AxIyEESH40qDCw2 qxyesFa9DTkoZVZvHt9Vh5PrrJJbsTLkc3r7Rhc3zAKdJPxGctK8dZp+IthR/hCHA3ad YWB1yxqU2RWcb4nTy11zAb708dbeMppm9yxtApbE2gXDS9WpvmZAxYF/KhPU9n8ZOD/9 bkrB02nuWvx1ImDDecvwjG9MTD+xd2NzLKHfyrQnikVmNK6tcu4hSj/Uv4lHkI9iF1RB rBuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=RWuBwjcD6kNGO1mkQy+Jas4Cy/LWECya+WvLI5lgNgQ=; b=yoAZBhu8WtYtLJwH7a4i0+G35RaGofpTXihRmLugy3UWjvJynb4ZYnDre0IsqSB8sx 5kkwSnI5hPWtx7D9aRoyJASFiLxzBjGeNc0NtO4Vp5MkHP+03gbyftBx3oQTnz2gjd+8 qK8jYDzUwcGt4rj2vqD9exBiC3Hx/q/znsMHMb9DdG711yu8kXPmI2FGSleLVIlyGGvd 2+EtFAKG22ZSmxboOWhJCKJRpNLAtoUC3E+7yIJE9Fz0thvJkQgBt2gozL9f/+ykcDWe brHNs1v6vv24pJwla/d/2gvB2gB9gzNcptlZCCSfneAuCf5OSNOpZPKlPT0/U1AsDJzj OSlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=W5ZRMAeF; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id i65-v6si1806697qtd.255.2018.08.20.03.32.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 03:32:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=W5ZRMAeF; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C8729210F625D; Mon, 20 Aug 2018 03:32:03 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c01::243; helo=mail-pl0-x243.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl0-x243.google.com (mail-pl0-x243.google.com [IPv6:2607:f8b0:400e:c01::243]) (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 D14A0210F625B for ; Mon, 20 Aug 2018 03:32:02 -0700 (PDT) Received: by mail-pl0-x243.google.com with SMTP id s17-v6so6903290plp.7 for ; Mon, 20 Aug 2018 03:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vSXPUIxf6BvwBFsHpdLeIxGWs9YV5m3T0OpcIjHskLU=; b=W5ZRMAeFvyiLjeb07r9zB7m+MywgnPXvaj0IuGo1G1CYYp85O5CYHJOcFrSqWSEJej qDOUfDGHIOQRtFfiqwxNicEZKoBCAemM3D/HBj7s8xRP63oN4PwsaqNRkkU+1IOM3gMl k3MfVzTclcoqTPVom2pahekx1sABKhBh1TV00= 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; bh=vSXPUIxf6BvwBFsHpdLeIxGWs9YV5m3T0OpcIjHskLU=; b=Y9iXJNZdpsRJJJnDGZN/UTEslXFbBMBKdUKGyLxn1vAXZSIaqRd4kdWdrCbrsMqP4+ IFxKUDSHEwwtbB2zaa5kXc64pV3B62J43UpYoQuhYMNXjHiT+7Sr1N2a/yfadziJbtrg qPBZnOUkWZ1iPMxlboqcrw1Fit7QBghdr7HffKarZB/vim9NDfX6d+OxCr2pRZsSlTad drl9dS3ZK0Kbk03+n3CPqmIWGHf+YpL88XkJVFhA3pOKI+NNjTUmZFHCNmR+ZeXY44Bb oLvvrEoxsiIfAbSRbJKr7XAdSzlm/9nSGPGhmKJAftpHflFwoCimr+JBAr8RPyNGOLlq RtGw== X-Gm-Message-State: AOUpUlEGnzplVusGGiYpIIJZQz+zYfCOnrZs64oLjFacBehxaT6Rroh3 B3FwKLfe7OpoA02TaVYMjdgBS/tuxwx5qQ== X-Received: by 2002:a17:902:d211:: with SMTP id t17-v6mr10108376ply.258.1534761122110; Mon, 20 Aug 2018 03:32:02 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.180]) by smtp.gmail.com with ESMTPSA id s195-v6sm24217163pgs.76.2018.08.20.03.31.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Aug 2018 03:32:01 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Mon, 20 Aug 2018 18:31:47 +0800 Message-Id: <1534761109-27037-3-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> References: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk-platforms v1 2/4] Platform/HiKey960: add platform usb driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Register the callbacks of Designware USB 3.0 driver on HiKey960 platform. Cc: Leif Lindholm Cc: Ard Biesheuvel Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Haojian Zhuang --- Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.inf | 52 +++ Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.c | 382 ++++++++++++++++++++ 2 files changed, 434 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.inf b/Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.inf new file mode 100644 index 000000000000..121a76da57a2 --- /dev/null +++ b/Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.inf @@ -0,0 +1,52 @@ +#/** @file +# +# Copyright (c) 2018, Linaro. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = HiKey960UsbDxe + FILE_GUID = 9998be97-6fb6-40f6-a98d-d797dc7b9d32 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = HiKey960UsbEntryPoint + +[Sources.common] + HiKey960UsbDxe.c + +[LibraryClasses] + DebugLib + IoLib + TimerLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UsbSerialNumberLib + +[Protocols] + gDwUsbProtocolGuid + gEfiBlockIoProtocolGuid + gEfiDriverBindingProtocolGuid + +[Packages] + EmbeddedPkg/Drivers/DwUsb3Dxe/DwUsb3Dxe.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Platform/Hisilicon/HiKey960/HiKey960.dec + Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.dec + Silicon/Hisilicon/Hi3660/Hi3660.dec + +[Pcd] + gHiKey960TokenSpaceGuid.PcdAndroidFastbootNvmDevicePath + +[Depex] + TRUE diff --git a/Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.c b/Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.c new file mode 100644 index 000000000000..d8b7997b7382 --- /dev/null +++ b/Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.c @@ -0,0 +1,382 @@ +/** @file +* +* Copyright (c) 2018, Linaro. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define USB_EYE_PARAM 0x01c466e3 +#define USB_PHY_TX_VBOOST_LVL 5 + +#define DWC3_PHY_RX_OVRD_IN_HI 0x1006 +#define DWC3_PHY_RX_SCOPE_VDCC 0x1026 + +#define RX_SCOPE_LFPS_EN (1 << 0) + +#define TX_VBOOST_LVL_MASK 7 +#define TX_VBOOST_LVL(x) ((x) & TX_VBOOST_LVL_MASK) + +#define SERIAL_NUMBER_LBA 20 + +STATIC EFI_HANDLE mFlashHandle; + +UINTN +HiKey960GetUsbMode ( + IN VOID + ) +{ + return USB_DEVICE_MODE; +} + +VOID +HiKey960UsbPhyCrWaitAck ( + VOID + ) +{ + INT32 Timeout = 1000; + UINT32 Data; + + while (TRUE) { + Data = MmioRead32 (USB3OTG_PHY_CR_STS); + if ((Data & USB3OTG_PHY_CR_ACK) == USB3OTG_PHY_CR_ACK) { + return; + } + MicroSecondDelay (50); + if (Timeout-- <= 0) { + DEBUG ((DEBUG_ERROR, "Wait PHY_CR_ACK timeout!\n")); + return; + } + } +} + +VOID +HiKey960UsbPhyCrSetAddr ( + IN UINT32 Addr + ) +{ + // + // set addr + // + MmioWrite32 ( + USB3OTG_PHY_CR_CTRL, + USB3OTG_PHY_CR_DATA_IN (Addr) + ); + MicroSecondDelay (100); + // + // cap addr + // + MmioOr32 (USB3OTG_PHY_CR_CTRL, USB3OTG_PHY_CR_CAP_ADDR); + HiKey960UsbPhyCrWaitAck (); + MmioWrite32 (USB3OTG_PHY_CR_CTRL, 0); +} + +UINT16 +HiKey960UsbPhyCrRead ( + IN UINT32 Addr + ) +{ + INT32 Timeout = 1000; + UINT32 Data; + + HiKey960UsbPhyCrSetAddr (Addr); + MmioWrite32 (USB3OTG_PHY_CR_CTRL, USB3OTG_PHY_CR_READ); + MicroSecondDelay (100); + + while (TRUE) { + Data = MmioRead32 (USB3OTG_PHY_CR_STS); + if ((Data & USB3OTG_PHY_CR_ACK) == USB3OTG_PHY_CR_ACK) { + DEBUG (( + DEBUG_INFO, + "Addr 0x%x, Data Out:0x%x\n", + Addr, + USB3OTG_PHY_CR_DATA_OUT(Data) + )); + break; + } + MicroSecondDelay (50); + if (Timeout-- <= 0) { + DEBUG ((DEBUG_ERROR, "Wait PHY_CR_ACK timeout!\n")); + break; + } + } + MmioWrite32 (USB3OTG_PHY_CR_CTRL, 0); + return (UINT16)USB3OTG_PHY_CR_DATA_OUT(Data); +} + +VOID +HiKey960UsbPhyCrWrite ( + IN UINT32 Addr, + IN UINT32 Value + ) +{ + UINT32 Data; + + HiKey960UsbPhyCrSetAddr (Addr); + Data = USB3OTG_PHY_CR_DATA_IN(Value); + MmioWrite32 (USB3OTG_PHY_CR_CTRL, Data); + + Data = MmioRead32 (USB3OTG_PHY_CR_CTRL); + Data |= USB3OTG_PHY_CR_CAP_DATA; + MmioWrite32 (USB3OTG_PHY_CR_CTRL, Data); + HiKey960UsbPhyCrWaitAck (); + + MmioWrite32 (USB3OTG_PHY_CR_CTRL, 0); + MmioWrite32 (USB3OTG_PHY_CR_CTRL, USB3OTG_PHY_CR_WRITE); + HiKey960UsbPhyCrWaitAck (); +} + +VOID +HiKey960UsbSetEyeDiagramParam ( + VOID + ) +{ + UINT32 Data; + + /* set eye diagram for usb 2.0 */ + MmioWrite32 (USB3OTG_CTRL4, USB_EYE_PARAM); + /* set eye diagram for usb 3.0 */ + HiKey960UsbPhyCrRead (DWC3_PHY_RX_OVRD_IN_HI); + HiKey960UsbPhyCrWrite (DWC3_PHY_RX_OVRD_IN_HI, BIT11 | BIT9 | BIT8 |BIT7); + HiKey960UsbPhyCrRead (DWC3_PHY_RX_OVRD_IN_HI); + + /* enable RX_SCOPE_LFPS_EN for usb 3.0 */ + Data = HiKey960UsbPhyCrRead (DWC3_PHY_RX_SCOPE_VDCC); + Data |= RX_SCOPE_LFPS_EN; + HiKey960UsbPhyCrWrite (DWC3_PHY_RX_SCOPE_VDCC, Data); + HiKey960UsbPhyCrRead (DWC3_PHY_RX_SCOPE_VDCC); + + Data = MmioRead32 (USB3OTG_CTRL6); + Data &= ~TX_VBOOST_LVL_MASK; + Data = TX_VBOOST_LVL (USB_PHY_TX_VBOOST_LVL); + MmioWrite32 (USB3OTG_CTRL6, Data); + DEBUG (( + DEBUG_INFO, + "set ss phy tx vboost lvl 0x%x\n", + MmioRead32 (USB3OTG_CTRL6) + )); +} + +STATIC +VOID +HiKey960UsbReset ( + VOID + ) +{ + MmioWrite32 (CRG_PERRSTEN4, PERRSTEN4_USB3OTG); + MmioWrite32 (CRG_PERRSTEN4, PERRSTEN4_USB3OTGPHY_POR); + MmioWrite32 ( + CRG_PERRSTEN4, + PERRSTEN4_USB3OTG_MUX | PERRSTEN4_USB3OTG_AHBIF | PERRSTEN4_USB3OTG_32K + ); + MmioWrite32 ( + CRG_PERDIS4, + PEREN4_GT_ACLK_USB3OTG | PEREN4_GT_CLK_USB3OTG_REF + ); + + MmioAnd32 (PCTRL_CTRL24, ~PCTRL_CTRL24_USB3PHY_3MUX1_SEL); + // + // disable + // + MmioWrite32 (PCTRL_CTRL3, (PCTRL_CTRL3_USB_TXCO_EN << 16) | 0); + MicroSecondDelay (10000); +} + +STATIC +VOID +HiKey960UsbRelease ( + VOID + ) +{ + /* enable USB REFCLK ISO */ + MmioWrite32 (CRG_ISODIS, PERISOEN_USB_REFCLK_ISO_EN); + /* enable USB_TXCO_EN */ + MmioWrite32 (PCTRL_CTRL3, (PCTRL_CTRL3_USB_TXCO_EN << 16) | PCTRL_CTRL3_USB_TXCO_EN); + + MmioAnd32 (PCTRL_CTRL24, ~PCTRL_CTRL24_USB3PHY_3MUX1_SEL); + + MmioWrite32 ( + CRG_PEREN4, + PEREN4_GT_ACLK_USB3OTG | PEREN4_GT_CLK_USB3OTG_REF + ); + MmioWrite32 ( + CRG_PERRSTDIS4, + PERRSTEN4_USB3OTG_MUX | PERRSTEN4_USB3OTG_AHBIF | PERRSTEN4_USB3OTG_32K + ); + + MmioWrite32 (CRG_PERRSTEN4, PERRSTEN4_USB3OTG | PERRSTEN4_USB3OTGPHY_POR); + + /* enable PHY REF CLK */ + MmioOr32 (USB3OTG_CTRL0, USB3OTG_CTRL0_SC_USB3PHY_ABB_GT_EN); + + MmioOr32 (USB3OTG_CTRL7, USB3OTG_CTRL7_REF_SSP_EN); + + /* exit from IDDQ mode */ + MmioAnd32 ( + USB3OTG_CTRL2, + ~(USB3OTG_CTRL2_TEST_POWERDOWN_SSP | USB3OTG_CTRL2_TEST_POWERDOWN_HSP) + ); + MicroSecondDelay (100000); + + MmioWrite32 (CRG_PERRSTDIS4, PERRSTEN4_USB3OTGPHY_POR); + MmioWrite32 (CRG_PERRSTDIS4, PERRSTEN4_USB3OTG); + MicroSecondDelay (10000); + MmioOr32 (USB3OTG_CTRL3, USB3OTG_CTRL3_VBUSVLDEXT | USB3OTG_CTRL3_VBUSVLDEXTSEL); + MicroSecondDelay (100000); + + HiKey960UsbSetEyeDiagramParam (); +} + +EFI_STATUS +HiKey960UsbPhyInit ( + IN UINT8 Mode + ) +{ + HiKey960UsbReset (); + MicroSecondDelay (10000); + HiKey960UsbRelease (); + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +HiKey960UsbGetLang ( + OUT CHAR16 *Lang, + OUT UINT8 *Length + ) +{ + if ((Lang == NULL) || (Length == NULL)) { + return EFI_INVALID_PARAMETER; + } + Lang[0] = 0x409; + *Length = sizeof (CHAR16); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +HiKey960UsbGetManuFacturer ( + OUT CHAR16 *ManuFacturer, + OUT UINT8 *Length + ) +{ + UINTN VariableSize; + CHAR16 DataUnicode[MANU_FACTURER_STRING_LENGTH]; + + if ((ManuFacturer == NULL) || (Length == NULL)) { + return EFI_INVALID_PARAMETER; + } + VariableSize = MANU_FACTURER_STRING_LENGTH * sizeof (CHAR16); + ZeroMem (DataUnicode, MANU_FACTURER_STRING_LENGTH * sizeof(CHAR16)); + StrCpy (DataUnicode, L"96Boards"); + CopyMem (ManuFacturer, DataUnicode, VariableSize); + *Length = VariableSize; + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +HiKey960UsbGetProduct ( + OUT CHAR16 *Product, + OUT UINT8 *Length + ) +{ + UINTN VariableSize; + CHAR16 DataUnicode[PRODUCT_STRING_LENGTH]; + + if ((Product == NULL) || (Length == NULL)) { + return EFI_INVALID_PARAMETER; + } + VariableSize = PRODUCT_STRING_LENGTH * sizeof (CHAR16); + ZeroMem (DataUnicode, PRODUCT_STRING_LENGTH * sizeof(CHAR16)); + StrCpy (DataUnicode, L"HiKey960"); + CopyMem (Product, DataUnicode, VariableSize); + *Length = VariableSize; + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +HiKey960UsbGetSerialNo ( + OUT CHAR16 *SerialNo, + OUT UINT8 *Length + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *FlashDevicePath; + + if (mFlashHandle == 0) { + FlashDevicePath = ConvertTextToDevicePath ( + (CHAR16*)FixedPcdGetPtr (PcdAndroidFastbootNvmDevicePath) + ); + Status = gBS->LocateDevicePath ( + &gEfiBlockIoProtocolGuid, + &FlashDevicePath, + &mFlashHandle + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Warning: Couldn't locate Android NVM device (status: %r)\n", + Status + )); + // + // Failing to locate partitions should not prevent to do other + // Android FastBoot actions + // + return EFI_SUCCESS; + } + } + + if ((SerialNo == NULL) || (Length == NULL)) { + return EFI_INVALID_PARAMETER; + } + Status = LoadSNFromBlock (mFlashHandle, SERIAL_NUMBER_LBA, SerialNo); + *Length = StrSize (SerialNo); + return Status; +} + +DW_USB_PROTOCOL mDwUsbDevice = { + HiKey960UsbGetLang, + HiKey960UsbGetManuFacturer, + HiKey960UsbGetProduct, + HiKey960UsbGetSerialNo, + HiKey960UsbPhyInit +}; + +EFI_STATUS +EFIAPI +HiKey960UsbEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gBS->InstallProtocolInterface ( + &ImageHandle, + &gDwUsbProtocolGuid, + EFI_NATIVE_INTERFACE, + &mDwUsbDevice + ); +} From patchwork Mon Aug 20 10:31:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 144567 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3797275ljj; Mon, 20 Aug 2018 03:32:08 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxMACkP18o+AdsHl28R1Co3Nzkmsg50yT389Z8BYiP/X6Ibe2xmEX9fsqgj8annGPtGkHWY X-Received: by 2002:a17:902:a507:: with SMTP id s7-v6mr8936064plq.303.1534761128598; Mon, 20 Aug 2018 03:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534761128; cv=none; d=google.com; s=arc-20160816; b=F1YSGWy7bMQjweYNrB91hyJ7Js/ULtopwiuqePv6U0CxzH6TGGAJzxxGxB9uw8Jk8x BAR2NzZn48cMRdI6b+g+i7e/V/RYqrEVx/BLmaJsmfoTfkSBc1zex6v5gXfYlSePoJZo sZTTF0qp+sN97ybeiICyJo6XXlO67JTx10K4wPLhXgatJkIQDV28wXwYljeBs6tFB0yr gDFh/r5F8kT+CFoFBOQtbD0LgPmvuccenBpc9c3uvF/Y1WvHfNtwtyZ6dYOqhKvqYYhz UIslSFinc2NQdXpJSjzpppT7ryOF1zyHWUbuPyDdwI7HTl38Zb970ow4YCYJmiJygTXz Sh+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=VhYABRYLIRVVw1sjbu73KtMouCluFt/9olbwQr2oU5k=; b=03e3M6o3/+ro1Wehvfcg9ECE4wPspXl+nZ3tUkmkzWvnHquQkuQt1rAqQl8GdyMb6i LNvAKTNtpDd/sgVtPFFavW5aOennKGI28cUqGUikxwRquGG1r0XmXN4K8CMzbPXC9qcS r9ygGLmTXO13mlfFIHZnBuy3IvenGPXJpCSdudm/cJ50G7csjOkbxm9Z+/vKxeBobRlN GB0WNH0zylQrxQGW4qtykYD/aGh2x1RAwlNvg4dLP1zWaueC5rf4gSfeIE4KgsQOUhL9 QW1aWzxvDFs6hwPBvLe/ohWIjN5uEM6whC7z2PHCGFJItnC/34R9ANOSzmsaDonwVEEG Rtiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PKXg7Xc0; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id d17-v6si10503797plj.448.2018.08.20.03.32.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 03:32:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PKXg7Xc0; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 00CC2210F6700; Mon, 20 Aug 2018 03:32:08 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::544; helo=mail-pg1-x544.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 3CFE2210F4BDA for ; Mon, 20 Aug 2018 03:32:06 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id r1-v6so6558305pgp.11 for ; Mon, 20 Aug 2018 03:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uU9QjchKnZFI7T5r26aEyPPYMlVpJ4BkfsOvmwjX04A=; b=PKXg7Xc0plXhOi6r3mX6Ruv8TapGTR6lSKodYw+Ad8REsc1MtSf+pbIcojE60nQ6wU rozet1f0lu0g1FJ0GTf6l7+CXWgGsxjOBwySvWN/sNHMsLE5gST5YZsdeQYfOoDGFtpn gpey/VlGW32ZXgtVTJ9yoHD0XrT0J4XklR5tc= 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; bh=uU9QjchKnZFI7T5r26aEyPPYMlVpJ4BkfsOvmwjX04A=; b=W4m2OAhHZtzhtmMYHFVD2zXdCjwVQTlLx3cShGdRbAsdr2HMQygq1U0TZj0N5PnoHG oAFcqiEVLIzZ7T7TJsHQEBk/58vuVSo2ZJ7zm6zMmmIr4O52nXFk2nudKy6ppkIpZXO3 6o+8NcE7zqM+qmyFhZobKoLd6YaZU1I5q2MxMeUNYKFpXi4/whVIoYh96oQwIKqPoCEO x0DpfDVywVYnNtDJlr52JQkBkNvwXgR3xBBaeSKo1K037wV8UGbUq5x7kZlolwDB5Aan RrwEa4/JEwHKXlYm0lXQjRr+K4akWZ7m5Dj7gOSpHbrKL1KOjgwXS8rrZSo1yYeMzxvF Or5A== X-Gm-Message-State: AOUpUlF9WSMww7vBhJ1UDXK1lo0ojKlcag1f+Rv8CoH4JYIZg5PqUZdb B4SAaZnZKt9lWYWK2vM7/BPw1t56ID7Njw== X-Received: by 2002:a63:e457:: with SMTP id i23-v6mr42929537pgk.127.1534761125301; Mon, 20 Aug 2018 03:32:05 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.180]) by smtp.gmail.com with ESMTPSA id s195-v6sm24217163pgs.76.2018.08.20.03.32.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Aug 2018 03:32:04 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Mon, 20 Aug 2018 18:31:48 +0800 Message-Id: <1534761109-27037-4-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> References: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk-platforms v1 3/4] Platform/HiKey960: add fastboot platform driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Implement the Android Fastboot protocol in HiKey960 platform. Cc: Leif Lindholm Cc: Ard Biesheuvel Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Haojian Zhuang --- Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.inf | 63 ++ Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c | 758 ++++++++++++++++++++ 2 files changed, 821 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.inf b/Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.inf new file mode 100644 index 000000000000..1771d41828d4 --- /dev/null +++ b/Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.inf @@ -0,0 +1,63 @@ +#/** @file +# +# Copyright (c) 2014, ARM Ltd. All rights reserved.
+# Copyright (c) 2018, Linaro. All rights reserved. +# +# This program and the accompanying materials are licensed and made available +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = HiKey960FastbootDxe + FILE_GUID = 80f046c6-d5ba-4916-a656-2e2b28d32304 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = HiKey960FastbootPlatformEntryPoint + +[Sources.common] + HiKey960FastbootDxe.c + +[LibraryClasses] + BaseLib + BaseMemoryLib + CacheMaintenanceLib + DebugLib + DevicePathLib + IoLib + MemoryAllocationLib + PcdLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + UefiDriverEntryPoint + UsbSerialNumberLib + TimerLib + +[Protocols] + gAndroidFastbootPlatformProtocolGuid + gEfiBlockIoProtocolGuid + gEfiDevicePathToTextProtocolGuid + gEfiDiskIoProtocolGuid + gEfiEraseBlockProtocolGuid + gEfiSimpleTextOutProtocolGuid + +[Packages] + ArmPlatformPkg/ArmPlatformPkg.dec + ArmPkg/ArmPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Platform/Hisilicon/HiKey960/HiKey960.dec + Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.dec + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor + gHiKey960TokenSpaceGuid.PcdAndroidFastbootNvmDevicePath + gHiKey960TokenSpaceGuid.PcdArmFastbootFlashLimit + gHiKey960TokenSpaceGuid.PcdXloaderDevicePath diff --git a/Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c b/Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c new file mode 100644 index 000000000000..5e99a9f93ca4 --- /dev/null +++ b/Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c @@ -0,0 +1,758 @@ +/** @file + + Copyright (c) 2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2018, Linaro. All rights reserved. + + This program and the accompanying materials are licensed and made available + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +/* + Implementation of the Android Fastboot Platform protocol, to be used by the + Fastboot UEFI application, for Hisilicon HiKey960 platform. +*/ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARTITION_NAME_MAX_LENGTH (72/2) + +#define SERIAL_NUMBER_LBA 20 + +#define RANDOM_MAX 0x7FFFFFFFFFFFFFFF +#define RANDOM_MAGIC 0x9A4DBEAF + +#define ADB_REBOOT_ADDRESS 0x32100000 +#define ADB_REBOOT_BOOTLOADER 0x77665500 + +#define UFS_BLOCK_SIZE 4096 + +typedef struct _FASTBOOT_PARTITION_LIST { + LIST_ENTRY Link; + CHAR16 PartitionName[PARTITION_NAME_MAX_LENGTH]; + EFI_LBA StartingLBA; + EFI_LBA EndingLBA; +} FASTBOOT_PARTITION_LIST; + +STATIC LIST_ENTRY mPartitionListHead; +STATIC EFI_HANDLE mFlashHandle; +STATIC EFI_BLOCK_IO_PROTOCOL *mFlashBlockIo; +STATIC EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *mTextOut; + +/* + Helper to free the partition list +*/ +STATIC +VOID +FreePartitionList ( + VOID + ) +{ + FASTBOOT_PARTITION_LIST *Entry; + FASTBOOT_PARTITION_LIST *NextEntry; + + Entry = (FASTBOOT_PARTITION_LIST *) GetFirstNode (&mPartitionListHead); + while (!IsNull (&mPartitionListHead, &Entry->Link)) { + NextEntry = (FASTBOOT_PARTITION_LIST *) GetNextNode ( + &mPartitionListHead, + &Entry->Link + ); + RemoveEntryList (&Entry->Link); + FreePool (Entry); + + Entry = NextEntry; + } +} + +/* + Read the PartitionName fields from the GPT partition entries, putting them + into an allocated array that should later be freed. +*/ +STATIC +EFI_STATUS +ReadPartitionEntries ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + OUT EFI_PARTITION_ENTRY **PartitionEntries, + OUT UINTN *PartitionNumbers + ) +{ + UINT32 MediaId; + EFI_PARTITION_TABLE_HEADER *GptHeader; + EFI_PARTITION_ENTRY *Entry; + EFI_STATUS Status; + VOID *Buffer; + UINTN PageCount; + UINTN BlockSize; + UINTN Count, EndLBA; + + if ((PartitionEntries == NULL) || (PartitionNumbers == NULL)) { + return EFI_INVALID_PARAMETER; + } + MediaId = BlockIo->Media->MediaId; + BlockSize = BlockIo->Media->BlockSize; + + // + // Read size of Partition entry and number of entries from GPT header + // + + PageCount = EFI_SIZE_TO_PAGES (6 * BlockSize); + Buffer = AllocatePages (PageCount); + if (Buffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = BlockIo->ReadBlocks ( + BlockIo, + MediaId, + 0, + PageCount * EFI_PAGE_SIZE, + Buffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + GptHeader = (EFI_PARTITION_TABLE_HEADER *)(Buffer + BlockSize); + + // + // Check there is a GPT on the media + // + if (GptHeader->Header.Signature != EFI_PTAB_HEADER_ID || + GptHeader->MyLBA != 1) { + DEBUG ((DEBUG_ERROR, + "Fastboot platform: No GPT on flash. " + "Fastboot on Versatile Express does not support MBR.\n" + )); + return EFI_DEVICE_ERROR; + } + + Entry = (EFI_PARTITION_ENTRY *)(Buffer + (2 * BlockSize)); + EndLBA = GptHeader->FirstUsableLBA - 1; + Count = 0; + while (1) { + if ((Entry->StartingLBA > EndLBA) && + (Entry->EndingLBA <= GptHeader->LastUsableLBA)) { + Count++; + EndLBA = Entry->EndingLBA; + Entry++; + } else { + break; + } + } + if (Count == 0) { + return EFI_INVALID_PARAMETER; + } + if (Count > GptHeader->NumberOfPartitionEntries) { + Count = GptHeader->NumberOfPartitionEntries; + } + + *PartitionEntries = (EFI_PARTITION_ENTRY *)((UINTN)Buffer + (2 * BlockSize)); + *PartitionNumbers = Count; + return EFI_SUCCESS; +} + +EFI_STATUS +LoadPtable ( + VOID + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *FlashDevicePath; + EFI_DEVICE_PATH_PROTOCOL *FlashDevicePathDup; + UINTN PartitionNumbers = 0; + UINTN LoopIndex; + EFI_PARTITION_ENTRY *PartitionEntries = NULL; + FASTBOOT_PARTITION_LIST *Entry; + + InitializeListHead (&mPartitionListHead); + + Status = gBS->LocateProtocol ( + &gEfiSimpleTextOutProtocolGuid, + NULL, + (VOID **) &mTextOut + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "Fastboot platform: Couldn't open Text Output Protocol: %r\n", Status + )); + return Status; + } + + // + // Get EFI_HANDLES for all the partitions on the block devices pointed to by + // PcdFastbootFlashDevicePath, also saving their GPT partition labels. + // There's no way to find all of a device's children, so we get every handle + // in the system supporting EFI_BLOCK_IO_PROTOCOL and then filter out ones + // that don't represent partitions on the flash device. + // + FlashDevicePath = ConvertTextToDevicePath ( + (CHAR16*)FixedPcdGetPtr (PcdAndroidFastbootNvmDevicePath) + ); + + // + // Create another device path pointer because LocateDevicePath will modify it. + // + FlashDevicePathDup = FlashDevicePath; + Status = gBS->LocateDevicePath ( + &gEfiBlockIoProtocolGuid, + &FlashDevicePathDup, + &mFlashHandle + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Warning: Couldn't locate Android NVM device (status: %r)\n", + Status + )); + // + // Failing to locate partitions should not prevent to do other Android + // FastBoot actions. + // + return EFI_SUCCESS; + } + + + Status = gBS->OpenProtocol ( + mFlashHandle, + &gEfiBlockIoProtocolGuid, + (VOID **) &mFlashBlockIo, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Fastboot platform: Couldn't open Android NVM device (status: %r)\n", + Status + )); + return EFI_DEVICE_ERROR; + } + + // + // Read the GPT partition entry array into memory so we can get the + // partition names. + // + Status = ReadPartitionEntries ( + mFlashBlockIo, + &PartitionEntries, + &PartitionNumbers + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Warning: Failed to read partitions from Android NVM device (status: %r)\n", + Status + )); + // + // Failing to locate partitions should not prevent to do other Android + // FastBoot actions. + // + return EFI_SUCCESS; + } + for (LoopIndex = 0; LoopIndex < PartitionNumbers; LoopIndex++) { + // + // Create entry + // + Entry = AllocatePool (sizeof (FASTBOOT_PARTITION_LIST)); + if (Entry == NULL) { + Status = EFI_OUT_OF_RESOURCES; + FreePartitionList (); + goto Exit; + } + StrnCpy ( + Entry->PartitionName, + PartitionEntries[LoopIndex].PartitionName, + PARTITION_NAME_MAX_LENGTH + ); + Entry->StartingLBA = PartitionEntries[LoopIndex].StartingLBA; + Entry->EndingLBA = PartitionEntries[LoopIndex].EndingLBA; + InsertTailList (&mPartitionListHead, &Entry->Link); + } +Exit: + FreePages ( + (VOID *)((UINTN)PartitionEntries - (2 * mFlashBlockIo->Media->BlockSize)), + EFI_SIZE_TO_PAGES (6 * mFlashBlockIo->Media->BlockSize) + ); + return Status; +} + +/* + Initialise: Open the Android NVM device and find the partitions on it. Save + them in a list along with the "PartitionName" fields for their GPT entries. + We will use these partition names as the key in + HiKey960FastbootPlatformFlashPartition. +*/ +EFI_STATUS +HiKey960FastbootPlatformInit ( + VOID + ) +{ + EFI_STATUS Status; + + Status = LoadPtable (); + if (EFI_ERROR (Status)) { + return Status; + } + return Status; +} + +VOID +HiKey960FastbootPlatformUnInit ( + VOID + ) +{ + FreePartitionList (); +} + +EFI_STATUS +HiKey960FlashPtable ( + IN UINTN Size, + IN VOID *Image + ) +{ + EFI_STATUS Status; + Status = mFlashBlockIo->WriteBlocks ( + mFlashBlockIo, + mFlashBlockIo->Media->MediaId, + 0, + Size, + Image + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to write (status:%r)\n", Status)); + return Status; + } + FreePartitionList (); + Status = LoadPtable (); + return Status; +} + +EFI_STATUS +HiKey960ErasePtable ( + VOID + ) +{ + EFI_STATUS Status; + + { + VOID *DataPtr; + UINTN Lba; + + DataPtr = AllocatePages (1); + ZeroMem (DataPtr, EFI_PAGE_SIZE); + for (Lba = 0; Lba < 6; Lba++) { + Status = mFlashBlockIo->WriteBlocks ( + mFlashBlockIo, + mFlashBlockIo->Media->MediaId, + Lba, + EFI_PAGE_SIZE, + DataPtr + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + } +Exit: + FreePages (DataPtr, 1); + } + FreePartitionList (); + return Status; +} + +EFI_STATUS +HiKey960FlashXloader ( + IN UINTN Size, + IN VOID *Image + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_HANDLE Handle; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + EFI_DISK_IO_PROTOCOL *DiskIo; + + DevicePath = ConvertTextToDevicePath ( + (CHAR16*)FixedPcdGetPtr (PcdXloaderDevicePath) + ); + + Status = gBS->LocateDevicePath ( + &gEfiBlockIoProtocolGuid, + &DevicePath, + &Handle + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Warning: Couldn't locate xloader device (status: %r)\n", + Status + )); + return Status; + } + + Status = gBS->OpenProtocol ( + Handle, + &gEfiBlockIoProtocolGuid, + (VOID **) &BlockIo, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Fastboot platform: Couldn't open xloader device (status: %r)\n", + Status + )); + return EFI_DEVICE_ERROR; + } + Status = gBS->OpenProtocol ( + Handle, + &gEfiDiskIoProtocolGuid, + (VOID **) &DiskIo, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = DiskIo->WriteDisk ( + DiskIo, + BlockIo->Media->MediaId, + 0, + Size, + Image + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to write (status:%r)\n", Status)); + return Status; + } + return Status; +} + +EFI_STATUS +HiKey960FastbootPlatformFlashPartition ( + IN CHAR8 *PartitionName, + IN UINTN Size, + IN VOID *Image + ) +{ + EFI_STATUS Status; + UINTN PartitionSize; + FASTBOOT_PARTITION_LIST *Entry; + CHAR16 PartitionNameUnicode[60]; + BOOLEAN PartitionFound; + EFI_DISK_IO_PROTOCOL *DiskIo; + UINTN BlockSize; + + // + // Support the pseudo partition name, such as "ptable". + // + if (AsciiStrCmp (PartitionName, "ptable") == 0) { + return HiKey960FlashPtable (Size, Image); + } else if (AsciiStrCmp (PartitionName, "xloader") == 0) { + return HiKey960FlashXloader (Size, Image); + } + + AsciiStrToUnicodeStr (PartitionName, PartitionNameUnicode); + PartitionFound = FALSE; + Entry = (FASTBOOT_PARTITION_LIST *) GetFirstNode (&(mPartitionListHead)); + while (!IsNull (&mPartitionListHead, &Entry->Link)) { + // + // Search the partition list for the partition named by PartitionName + // + if (StrCmp (Entry->PartitionName, PartitionNameUnicode) == 0) { + PartitionFound = TRUE; + break; + } + + Entry = (FASTBOOT_PARTITION_LIST *) GetNextNode ( + &mPartitionListHead, + &(Entry)->Link + ); + } + if (!PartitionFound) { + return EFI_NOT_FOUND; + } + + // + // Check image will fit on device + // + BlockSize = mFlashBlockIo->Media->BlockSize; + PartitionSize = (Entry->EndingLBA - Entry->StartingLBA + 1) * BlockSize; + if (PartitionSize < Size) { + DEBUG ((DEBUG_ERROR, "Partition not big enough.\n")); + DEBUG (( + DEBUG_ERROR, + "Partition Size:\t%ld\nImage Size:\t%ld\n", + PartitionSize, + Size + )); + return EFI_VOLUME_FULL; + } + + Status = gBS->OpenProtocol ( + mFlashHandle, + &gEfiDiskIoProtocolGuid, + (VOID **) &DiskIo, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + ASSERT_EFI_ERROR (Status); + + Status = DiskIo->WriteDisk ( + DiskIo, + mFlashBlockIo->Media->MediaId, + Entry->StartingLBA * BlockSize, + Size, + Image + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to write %d bytes into 0x%x, Status:%r\n", + Size, + Entry->StartingLBA * BlockSize, + Status + )); + return Status; + } + + mFlashBlockIo->FlushBlocks(mFlashBlockIo); + MicroSecondDelay (50000); + + return Status; +} + +EFI_STATUS +HiKey960FastbootPlatformErasePartition ( + IN CHAR8 *PartitionName + ) +{ + EFI_STATUS Status; + EFI_ERASE_BLOCK_PROTOCOL *EraseBlockProtocol; + UINTN Size; + BOOLEAN PartitionFound; + CHAR16 PartitionNameUnicode[60]; + FASTBOOT_PARTITION_LIST *Entry; + + AsciiStrToUnicodeStr (PartitionName, PartitionNameUnicode); + + // + // Support the pseudo partition name, such as "ptable". + // + if (AsciiStrCmp (PartitionName, "ptable") == 0) { + return HiKey960ErasePtable (); + } + + PartitionFound = FALSE; + Entry = (FASTBOOT_PARTITION_LIST *) GetFirstNode (&mPartitionListHead); + while (!IsNull (&mPartitionListHead, &Entry->Link)) { + // + // Search the partition list for the partition named by PartitionName + // + if (StrCmp (Entry->PartitionName, PartitionNameUnicode) == 0) { + PartitionFound = TRUE; + break; + } + Entry = (FASTBOOT_PARTITION_LIST *) GetNextNode (&mPartitionListHead, &Entry->Link); + } + if (!PartitionFound) { + return EFI_NOT_FOUND; + } + + Status = gBS->OpenProtocol ( + mFlashHandle, + &gEfiEraseBlockProtocolGuid, + (VOID **) &EraseBlockProtocol, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } + Size = (Entry->EndingLBA - Entry->StartingLBA + 1) * mFlashBlockIo->Media->BlockSize; + Status = EraseBlockProtocol->EraseBlocks ( + EraseBlockProtocol, + mFlashBlockIo->Media->MediaId, + Entry->StartingLBA, + NULL, + Size + ); + return Status; +} + +EFI_STATUS +HiKey960FastbootPlatformGetVar ( + IN CHAR8 *Name, + OUT CHAR8 *Value + ) +{ + EFI_STATUS Status = EFI_SUCCESS; + UINT64 PartitionSize; + FASTBOOT_PARTITION_LIST *Entry; + CHAR16 PartitionNameUnicode[60]; + BOOLEAN PartitionFound; + CHAR16 UnicodeSN[SERIAL_NUMBER_SIZE]; + + if (!AsciiStrCmp (Name, "max-download-size")) { + AsciiStrCpy (Value, FixedPcdGetPtr (PcdArmFastbootFlashLimit)); + } else if (!AsciiStrCmp (Name, "product")) { + AsciiStrCpy (Value, FixedPcdGetPtr (PcdFirmwareVendor)); + } else if (!AsciiStrCmp (Name, "serialno")) { + Status = LoadSNFromBlock (mFlashHandle, SERIAL_NUMBER_LBA, UnicodeSN); + UnicodeStrToAsciiStr (UnicodeSN, Value); + } else if ( !AsciiStrnCmp (Name, "partition-size", 14)) { + AsciiStrToUnicodeStr ((Name + 15), PartitionNameUnicode); + PartitionFound = FALSE; + Entry = (FASTBOOT_PARTITION_LIST *) GetFirstNode (&(mPartitionListHead)); + while (!IsNull (&mPartitionListHead, &Entry->Link)) { + // + // Search the partition list for the partition named by PartitionName + // + if (StrCmp (Entry->PartitionName, PartitionNameUnicode) == 0) { + PartitionFound = TRUE; + break; + } + + Entry = (FASTBOOT_PARTITION_LIST *) GetNextNode ( + &mPartitionListHead, + &(Entry)->Link + ); + } + if (!PartitionFound) { + *Value = '\0'; + return EFI_NOT_FOUND; + } + + PartitionSize = (Entry->EndingLBA - Entry->StartingLBA + 1) * + mFlashBlockIo->Media->BlockSize; + DEBUG (( + DEBUG_ERROR, + "Fastboot platform: check for partition-size:%a 0X%llx\n", + Name, + PartitionSize + )); + AsciiSPrint (Value, 12, "0x%llx", PartitionSize); + } else if ( !AsciiStrnCmp (Name, "partition-type", 14)) { + DEBUG (( + DEBUG_ERROR, + "Fastboot platform: check for partition-type:%a\n", + (Name + 15) + )); + if ( !AsciiStrnCmp ( (Name + 15) , "system", 6) || \ + !AsciiStrnCmp ( (Name + 15) , "userdata", 8) || \ + !AsciiStrnCmp ( (Name + 15) , "cache", 5)) { + AsciiStrCpy (Value, "ext4"); + } else { + AsciiStrCpy (Value, "raw"); + } + } else if ( !AsciiStrCmp (Name, "erase-block-size")) { + AsciiSPrint (Value, 12, "0x%llx", UFS_BLOCK_SIZE); + } else if ( !AsciiStrCmp (Name, "logical-block-size")) { + AsciiSPrint (Value, 12, "0x%llx", UFS_BLOCK_SIZE); + } else { + *Value = '\0'; + } + return Status; +} + +EFI_STATUS +HiKey960FastbootPlatformOemCommand ( + IN CHAR8 *Command + ) +{ + EFI_STATUS Status; + CHAR16 UnicodeSN[SERIAL_NUMBER_SIZE]; + UINTN Size; + + Size = AsciiStrLen ("serialno"); + if (AsciiStrCmp (Command, "Demonstrate") == 0) { + DEBUG ((DEBUG_ERROR, "ARM OEM Fastboot command 'Demonstrate' received.\n")); + return EFI_SUCCESS; + } else if (AsciiStrnCmp (Command, "serialno", Size) == 0) { + while (*(Command + Size) == ' ') { + Size++; + } + if (AsciiStrnCmp (Command + Size, "set", AsciiStrLen ("set")) == 0) { + Size += AsciiStrLen ("set"); + while (*(Command + Size) == ' ') { + Size++; + } + Status = AssignUsbSN (Command + Size, UnicodeSN); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to set USB Serial Number.\n")); + return Status; + } + } else { + Status = GenerateUsbSN (UnicodeSN); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to generate USB Serial Number.\n")); + return Status; + } + } + Status = StoreSNToBlock (mFlashHandle, SERIAL_NUMBER_LBA, UnicodeSN); + return Status; + } else if (AsciiStrCmp (Command, "reboot-bootloader") == 0) { + MmioWrite32 (ADB_REBOOT_ADDRESS, ADB_REBOOT_BOOTLOADER); + WriteBackInvalidateDataCacheRange ((VOID *)ADB_REBOOT_ADDRESS, 4); + return EFI_SUCCESS; + } else { + DEBUG ((DEBUG_ERROR, + "HiKey960: Unrecognised Fastboot OEM command: %a\n", + Command + )); + return EFI_NOT_FOUND; + } +} + +FASTBOOT_PLATFORM_PROTOCOL mPlatformProtocol = { + HiKey960FastbootPlatformInit, + HiKey960FastbootPlatformUnInit, + HiKey960FastbootPlatformFlashPartition, + HiKey960FastbootPlatformErasePartition, + HiKey960FastbootPlatformGetVar, + HiKey960FastbootPlatformOemCommand, +}; + +EFI_STATUS +EFIAPI +HiKey960FastbootPlatformEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gBS->InstallProtocolInterface ( + &ImageHandle, + &gAndroidFastbootPlatformProtocolGuid, + EFI_NATIVE_INTERFACE, + &mPlatformProtocol + ); +} From patchwork Mon Aug 20 10:31:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 144568 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3797375ljj; Mon, 20 Aug 2018 03:32:13 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxIQ0fP5SXTFXgbb10WtEMI18BMbDrh0vhJfoaD2Evnr0QX8CEUkV0LmbjFyg0dI58oSMOb X-Received: by 2002:a62:ce05:: with SMTP id y5-v6mr47511825pfg.95.1534761132981; Mon, 20 Aug 2018 03:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534761132; cv=none; d=google.com; s=arc-20160816; b=j869k9Oaj0w9M4OaE64MKf+f7dy8EW+OhfvwOjoyg0ZtJs5Qw5dhbgn87McpSxPHCG 3aOEmXe24RrIcNUj9VrSyzcmjnKA7fbpCLdRSYZzNLwO6Db/VUIldyvemSID+kw0kgPM LWzVmyJRCz3WS2zlxJ1QzzGSNx6SkEV1xahSLpk5JxQ0VV8v2ucbAvjiAuKa+uD/ZgNU wpARf1j8qVgOPlniLWLRoMTY4ms+drvrk5x9jduvPAnZq9L27E+BNWjIHwy6TD4p9nD3 M5iUj96jId77G/PiNfXkXZ2z7VYMHRw4bc13dpmD82oJcCco7CpeuuisZlbdFkUMjh7D C5FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=ZDXLdiqz9lygGsCPgXf3eJDIfNJukQHBxaIZgb14+N8=; b=CptqdOhixs57bOmtFaZIbnzIj6f50gDs5CrIEgwy9ekk1YtkgNIosYlRENYW2y/+V6 FsXEHC39KXZHlf12Dh/yjwx7YHZU7LlRL4rtHxFgyAvw6YuoHIGkU7lbTSG5fLuMlJ1Q UnMhq7QjcC+JvOrSkOkkDdZOPG03UXqKEHJgwllmzoSzwZQRtStB7RI/YjkN1TTqbdes jCBjuckbvJ3GD+PRaDOc1iXCYuDvpzofUHHZazJKfOhpeEDE4YWcmLGZ9FKS2L6ziQKE vOiZ9DUk8lL6VjQlR1E+X2gPYKrY/7Q5kJ+eVdt7Kjmv2tRXssyDgb364O7LfAHJVPi1 avJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FofU153r; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id l7-v6si9113982pgm.677.2018.08.20.03.32.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 03:32:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FofU153r; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2C975210F6706; Mon, 20 Aug 2018 03:32:10 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 035E3210F4BDA for ; Mon, 20 Aug 2018 03:32:09 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id u24-v6so6537932pfn.13 for ; Mon, 20 Aug 2018 03:32:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xMbcXKoIFQzZxLJqi0x4i/ZhI8vQumjg0fFMsTobHN0=; b=FofU153rAyUU4YeJfkbktP2uMJVuXpPluo9aZxsQDAgJa4KR8YqcyPazmgGQlE/lNL R3kZ8RxgZkFeQ5ehheSXbyvQjsVgmTEgVnlpiBoIqBcpTOz62aH1cK4/dLjtPfP2xNzk H2PPXjHhM9Kir4Q6GvBILCcLFujzXp9ykC78c= 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; bh=xMbcXKoIFQzZxLJqi0x4i/ZhI8vQumjg0fFMsTobHN0=; b=bnn1sO3BIx5+55HfNhbnG4Jchcm1gBPVrE/+55mW8FKTlJFE/laVsQ2ASyCT21UNOL JcjSbFXKMjYb4B79BVg77oe41ps1KuvQcVKMaFBDKX1u8itWToT5wubHuYyvw4pE8Ex1 UWb/OdoVM2WWkI17EE9gP3cLEbdd+LaLKveBS5YiVt8CtFEWREEfk3/LB1i82jiyge+g a4wXXx+YHD88HAMNdCy2en/4L9hB5w6PUXi8sP1VUReYEFv8j0XqubTGjK3Q6lio0L2k MalMzwI7ZRNAfjN9qK6pDKY7Oigi6N5pi8Q+Ng/ZZbnfYB8ISvV5oJCGxhJLVj9x5639 jPTA== X-Gm-Message-State: AOUpUlE965pOomkexCFqoZTyUObTi//0eRA5U+L7iaa49Vn3Mv4/17nY PlN5Mmjl0NlhdyxoMvlmsr+UVy7rjYKxIQ== X-Received: by 2002:a62:2c95:: with SMTP id s143-v6mr47532623pfs.3.1534761128449; Mon, 20 Aug 2018 03:32:08 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.180]) by smtp.gmail.com with ESMTPSA id s195-v6sm24217163pgs.76.2018.08.20.03.32.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Aug 2018 03:32:07 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Mon, 20 Aug 2018 18:31:49 +0800 Message-Id: <1534761109-27037-5-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> References: <1534761109-27037-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk-platforms v1 4/4] Platform/HiKey960: enable usb device driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Enable Designware USB 3.0 device driver on HiKey960 platform. Android Fastboot application is based on the USB driver. Cc: Leif Lindholm Cc: Ard Biesheuvel Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Haojian Zhuang --- Platform/Hisilicon/HiKey960/HiKey960.dec | 3 +++ Platform/Hisilicon/HiKey960/HiKey960.dsc | 13 +++++++++++++ Platform/Hisilicon/HiKey960/HiKey960.fdf | 3 +++ 3 files changed, 19 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Hisilicon/HiKey960/HiKey960.dec b/Platform/Hisilicon/HiKey960/HiKey960.dec index aa5a0caf52e5..c925ae6c5eb5 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960.dec +++ b/Platform/Hisilicon/HiKey960/HiKey960.dec @@ -33,3 +33,6 @@ [PcdsFixedAtBuild.common] gHiKey960TokenSpaceGuid.PcdAndroidBootFile|{ 0x36, 0x8b, 0x73, 0x3a, 0xc5, 0xb9, 0x63, 0x47, 0xab, 0xbd, 0x6c, 0xbd, 0x4b, 0x25, 0xf9, 0xff }|VOID*|0x00000002 gHiKey960TokenSpaceGuid.PcdAndroidFastbootFile|{ 0x2a, 0x50, 0x88, 0x95, 0x70, 0x53, 0xe3, 0x11, 0x86, 0x31, 0xd7, 0xc5, 0x95, 0x13, 0x64, 0xc8 }|VOID*|0x00000003 gHiKey960TokenSpaceGuid.PcdSdBootDevicePath|L""|VOID*|0x00000004 + gHiKey960TokenSpaceGuid.PcdAndroidFastbootNvmDevicePath|L""|VOID*|0x00000005 + gHiKey960TokenSpaceGuid.PcdArmFastbootFlashLimit|L""|VOID*|0x00000006 + gHiKey960TokenSpaceGuid.PcdXloaderDevicePath|L""|VOID*|0x00000007 diff --git a/Platform/Hisilicon/HiKey960/HiKey960.dsc b/Platform/Hisilicon/HiKey960/HiKey960.dsc index 1ce306da5b50..2b65254ba255 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960.dsc +++ b/Platform/Hisilicon/HiKey960/HiKey960.dsc @@ -52,6 +52,8 @@ [LibraryClasses.common] # USB Requirements UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf + UsbSerialNumberLib|Platform/Hisilicon/Library/UsbSerialNumberLib/UsbSerialNumberLib.inf + # Network Libraries UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf @@ -59,6 +61,8 @@ [LibraryClasses.common] IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf + DmaLib|EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf + [LibraryClasses.common.SEC] PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf @@ -82,6 +86,7 @@ [PcdsFeatureFlag.common] [PcdsFixedAtBuild.common] gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor|"hikey960" gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"Alpha" # System Memory (3GB) @@ -123,6 +128,11 @@ [PcdsFixedAtBuild.common] gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|1000 # + # DW USB3 controller + # + gDwUsb3DxeTokenSpaceGuid.PcdDwUsb3DxeBaseAddress|0xFF100000 + + # # # Fastboot # @@ -216,6 +226,9 @@ [Components.common] # # USB Peripheral Support # + Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.inf + EmbeddedPkg/Drivers/DwUsb3Dxe/DwUsb3Dxe.inf + Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.inf EmbeddedPkg/Drivers/AndroidFastbootTransportUsbDxe/FastbootTransportUsbDxe.inf # diff --git a/Platform/Hisilicon/HiKey960/HiKey960.fdf b/Platform/Hisilicon/HiKey960/HiKey960.fdf index d4fe4c46b818..8addf49d1647 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960.fdf +++ b/Platform/Hisilicon/HiKey960/HiKey960.fdf @@ -151,6 +151,9 @@ [FV.FvMain] # # USB Peripheral Support # + INF Platform/Hisilicon/HiKey960/HiKey960UsbDxe/HiKey960UsbDxe.inf + INF EmbeddedPkg/Drivers/DwUsb3Dxe/DwUsb3Dxe.inf + INF Platform/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.inf INF EmbeddedPkg/Drivers/AndroidFastbootTransportUsbDxe/FastbootTransportUsbDxe.inf #