]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBoot.c
ArmPlatformPkg/ArmVExpressFastBootDxe: eliminate deprecated string functions
[mirror_edk2.git] / ArmPlatformPkg / ArmVExpressPkg / ArmVExpressFastBootDxe / ArmVExpressFastBoot.c
index 4962666cf16f1367aef89ffd4f2297670e4f2ba6..a01bf3c671ad4ba8a0a8cf9187beb8ccd803f984 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
 \r
   Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
+  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -135,11 +136,13 @@ ReadPartitionEntries (
 \r
 \r
 /*\r
-  Initialise: Open the Android NVM device and find the partitions on it. Save them in\r
-  a list along with the "PartitionName" fields for their GPT entries.\r
-  We will use these partition names as the key in\r
-  ArmFastbootPlatformFlashPartition.\r
+  Do any initialisation that needs to be done in order to be able to respond to\r
+  commands.\r
+\r
+  @retval EFI_SUCCESS   Initialised successfully.\r
+  @retval !EFI_SUCCESS  Error in initialisation.\r
 */\r
+STATIC\r
 EFI_STATUS\r
 ArmFastbootPlatformInit (\r
   VOID\r
@@ -164,6 +167,7 @@ ArmFastbootPlatformInit (
   //\r
   // Get EFI_HANDLES for all the partitions on the block devices pointed to by\r
   // PcdFastbootFlashDevicePath, also saving their GPT partition labels.\r
+  // We will use these labels as the key in ArmFastbootPlatformFlashPartition.\r
   // There's no way to find all of a device's children, so we get every handle\r
   // in the system supporting EFI_BLOCK_IO_PROTOCOL and then filter out ones\r
   // that don't represent partitions on the flash device.\r
@@ -200,9 +204,9 @@ ArmFastbootPlatformInit (
   // Read the GPT partition entry array into memory so we can get the partition names\r
   Status = ReadPartitionEntries (FlashBlockIo, &PartitionEntries);\r
   if (EFI_ERROR (Status)) {\r
-       DEBUG ((EFI_D_ERROR, "Warning: Failed to read partitions from Android NVM device (status: %r)\n", Status));\r
-       // Failing to locate partitions should not prevent to do other Android FastBoot actions\r
-       return EFI_SUCCESS;\r
+    DEBUG ((EFI_D_ERROR, "Warning: Failed to read partitions from Android NVM device (status: %r)\n", Status));\r
+    // Failing to locate partitions should not prevent to do other Android FastBoot actions\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   // Get every Block IO protocol instance installed in the system\r
@@ -269,7 +273,7 @@ ArmFastbootPlatformInit (
 \r
       // Copy handle and partition name\r
       Entry->PartitionHandle = AllHandles[LoopIndex];\r
-      StrnCpy (\r
+      CopyMem (\r
         Entry->PartitionName,\r
         PartitionEntries[PartitionNode->PartitionNumber - 1].PartitionName, // Partition numbers start from 1.\r
         PARTITION_NAME_MAX_LENGTH\r
@@ -296,6 +300,11 @@ Exit:
 \r
 }\r
 \r
+/*\r
+  To be called when Fastboot is finished and we aren't rebooting or booting an\r
+  image. Undo initialisation, free resrouces.\r
+*/\r
+STATIC\r
 VOID\r
 ArmFastbootPlatformUnInit (\r
   VOID\r
@@ -304,6 +313,18 @@ ArmFastbootPlatformUnInit (
   FreePartitionList ();\r
 }\r
 \r
+/*\r
+  Flash the partition named (according to a platform-specific scheme)\r
+  PartitionName, with the image pointed to by Buffer, whose size is BufferSize.\r
+\r
+  @param[in] PartitionName  Null-terminated name of partition to write.\r
+  @param[in] BufferSize     Size of Buffer in byets.\r
+  @param[in] Buffer         Data to write to partition.\r
+\r
+  @retval EFI_NOT_FOUND     No such partition.\r
+  @retval EFI_DEVICE_ERROR  Flashing failed.\r
+*/\r
+STATIC\r
 EFI_STATUS\r
 ArmFastbootPlatformFlashPartition (\r
   IN CHAR8  *PartitionName,\r
@@ -320,7 +341,8 @@ ArmFastbootPlatformFlashPartition (
   CHAR16                   PartitionNameUnicode[60];\r
   BOOLEAN                  PartitionFound;\r
 \r
-  AsciiStrToUnicodeStr (PartitionName, PartitionNameUnicode);\r
+  AsciiStrToUnicodeStrS (PartitionName, PartitionNameUnicode,\r
+    ARRAY_SIZE (PartitionNameUnicode));\r
 \r
   PartitionFound = FALSE;\r
   Entry = (FASTBOOT_PARTITION_LIST *) GetFirstNode (&(mPartitionListHead));\r
@@ -381,6 +403,15 @@ ArmFastbootPlatformFlashPartition (
   return Status;\r
 }\r
 \r
+/*\r
+  Erase the partition named PartitionName.\r
+\r
+  @param[in] PartitionName  Null-terminated name of partition to erase.\r
+\r
+  @retval EFI_NOT_FOUND     No such partition.\r
+  @retval EFI_DEVICE_ERROR  Erasing failed.\r
+*/\r
+STATIC\r
 EFI_STATUS\r
 ArmFastbootPlatformErasePartition (\r
   IN CHAR8 *Partition\r
@@ -389,6 +420,25 @@ ArmFastbootPlatformErasePartition (
   return EFI_SUCCESS;\r
 }\r
 \r
+/*\r
+  If the variable referred to by Name exists, copy it (as a null-terminated\r
+  string) into Value. If it doesn't exist, put the Empty string in Value.\r
+\r
+  Variable names and values may not be larger than 60 bytes, excluding the\r
+  terminal null character. This is a limitation of the Fastboot protocol.\r
+\r
+  The Fastboot application will handle platform-nonspecific variables\r
+  (Currently "version" is the only one of these.)\r
+\r
+  @param[in]  Name   Null-terminated name of Fastboot variable to retrieve.\r
+  @param[out] Value  Caller-allocated buffer for null-terminated value of\r
+                     variable.\r
+\r
+  @retval EFI_SUCCESS       The variable was retrieved, or it doesn't exist.\r
+  @retval EFI_DEVICE_ERROR  There was an error looking up the variable. This\r
+                            does _not_ include the variable not existing.\r
+*/\r
+STATIC\r
 EFI_STATUS\r
 ArmFastbootPlatformGetVar (\r
   IN  CHAR8   *Name,\r
@@ -396,13 +446,33 @@ ArmFastbootPlatformGetVar (
   )\r
 {\r
   if (AsciiStrCmp (Name, "product")) {\r
-    AsciiStrCpy (Value, FixedPcdGetPtr (PcdFirmwareVendor));\r
+    AsciiStrCpyS (Value, 61, FixedPcdGetPtr (PcdFirmwareVendor));\r
   } else {\r
     *Value = '\0';\r
   }\r
   return EFI_SUCCESS;\r
 }\r
 \r
+/*\r
+  React to an OEM-specific command.\r
+\r
+  Future versions of this function might want to allow the platform to do some\r
+  extra communication with the host. A way to do this would be to add a function\r
+  to the FASTBOOT_TRANSPORT_PROTOCOL that allows the implementation of\r
+  DoOemCommand to replace the ReceiveEvent with its own, and to restore the old\r
+  one when it's finished.\r
+\r
+  However at the moment although the specification allows it, the AOSP fastboot\r
+  host application doesn't handle receiving any data from the client, and it\r
+  doesn't support a data phase for OEM commands.\r
+\r
+  @param[in] Command    Null-terminated command string.\r
+\r
+  @retval EFI_SUCCESS       The command executed successfully.\r
+  @retval EFI_NOT_FOUND     The command wasn't recognised.\r
+  @retval EFI_DEVICE_ERROR  There was an error executing the command.\r
+*/\r
+STATIC\r
 EFI_STATUS\r
 ArmFastbootPlatformOemCommand (\r
   IN  CHAR8   *Command\r
@@ -410,7 +480,7 @@ ArmFastbootPlatformOemCommand (
 {\r
   CHAR16 CommandUnicode[65];\r
 \r
-  AsciiStrToUnicodeStr (Command, CommandUnicode);\r
+  AsciiStrToUnicodeStrS (Command, CommandUnicode, ARRAY_SIZE (CommandUnicode));\r
 \r
   if (AsciiStrCmp (Command, "Demonstrate") == 0) {\r
     DEBUG ((EFI_D_ERROR, "ARM OEM Fastboot command 'Demonstrate' received.\n"));\r
@@ -424,7 +494,7 @@ ArmFastbootPlatformOemCommand (
   }\r
 }\r
 \r
-FASTBOOT_PLATFORM_PROTOCOL mPlatformProtocol = {\r
+STATIC FASTBOOT_PLATFORM_PROTOCOL mPlatformProtocol = {\r
   ArmFastbootPlatformInit,\r
   ArmFastbootPlatformUnInit,\r
   ArmFastbootPlatformFlashPartition,\r