hikey: Add UEFI sources for reference

UEFI needs to be built outside Android build system.
Please follow the instructions in README.

The sources correspond to:
https://github.com/96boards/edk2/commit/14eae0c12e71fd33c4c0fc51e4475e8db02566cf
https://github.com/96boards/arm-trusted-firmware/commit/e9b4909dcd75fc4ae7041cfb83d28ab9adb7afdf
https://github.com/96boards/l-loader/commit/6b784ad5c4ab00e2b1c6f53cd5f74054e5d00a78
https://git.linaro.org/uefi/uefi-tools.git/commit/abe618f8ab72034fff1ce46c9c006a2c6bd40a7e

Change-Id: Ieeefdb63e673e0c8e64e0a1f02c7bddc63b2c7fb
Signed-off-by: Vishal Bhoj <vishal.bhoj@linaro.org>
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf
new file mode 100644
index 0000000..76a0d0a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf
@@ -0,0 +1,51 @@
+## @file

+#

+#  ACPI table data and ASL sources required to boot the platform.

+#

+#  Copyright (c) 2014, ARM Ltd. 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                    = 0x00010005

+  BASE_NAME                      = JunoAcpiTables

+  FILE_GUID                      = a1dd808e-1e95-4399-abc0-653c82e8530c

+  MODULE_TYPE                    = USER_DEFINED

+  VERSION_STRING                 = 1.0

+

+[Sources]

+  Dsdt.asl

+  Facs.aslc

+  Fadt.aslc

+  Gtdt.aslc

+  Madt.aslc

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec

+  ArmPlatformPkg/ArmJunoPkg/ArmJuno.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

+  gArmTokenSpaceGuid.PcdGicDistributorBase

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase

+

+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum

+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum

+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum

+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum

+

+  gArmTokenSpaceGuid.PcdGenericWatchdogControlBase

+  gArmTokenSpaceGuid.PcdGenericWatchdogRefreshBase

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Dsdt.asl b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Dsdt.asl
new file mode 100644
index 0000000..7a56f00
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Dsdt.asl
@@ -0,0 +1,184 @@
+/** @file

+  Differentiated System Description Table Fields (DSDT)

+

+  Copyright (c) 2014-2015, ARM Ltd. All rights reserved.<BR>

+    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 "ArmPlatform.h"

+

+DefinitionBlock("DsdtTable.aml", "DSDT", 1, "ARMLTD", "ARM-JUNO", EFI_ACPI_ARM_OEM_REVISION) {

+  Scope(_SB) {

+    //

+    // A57x2-A53x4 Processor declaration

+    //

+    Device(CPU0) { // A53-0: Cluster 1, Cpu 0

+      Name(_HID, "ACPI0007")

+      Name(_UID, 0)

+    }

+    Device(CPU1) { // A53-1: Cluster 1, Cpu 1

+      Name(_HID, "ACPI0007")

+      Name(_UID, 1)

+    }

+    Device(CPU2) { // A53-2: Cluster 1, Cpu 2

+      Name(_HID, "ACPI0007")

+      Name(_UID, 2)

+    }

+    Device(CPU3) { // A53-3: Cluster 1, Cpu 3

+      Name(_HID, "ACPI0007")

+      Name(_UID, 3)

+    }

+    Device(CPU4) { // A57-0: Cluster 0, Cpu 0

+      Name(_HID, "ACPI0007")

+      Name(_UID, 4)

+    }

+    Device(CPU5) { // A57-1: Cluster 0, Cpu 1

+      Name(_HID, "ACPI0007")

+      Name(_UID, 5)

+    }

+

+    //

+    // Keyboard and Mouse

+    //

+    Device(KMI0) {

+      Name(_HID, "ARMH0501")

+      Name(_CID, "PL050_KBD")

+      Name(_CRS, ResourceTemplate() {

+              Memory32Fixed(ReadWrite, 0x1C060008, 0x4)

+              Memory32Fixed(ReadWrite, 0x1C060000, 0x4)

+              Memory32Fixed(ReadOnly, 0x1C060004, 0x4)

+              Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 197 }

+      })

+    }

+

+    //

+    // LAN9118 Ethernet

+    //

+    Device(ETH0) {

+      Name(_HID, "ARMH9118")

+      Name(_UID, Zero)

+      Name(_CRS, ResourceTemplate() {

+              Memory32Fixed(ReadWrite, 0x1A000000, 0x1000)

+              Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 192 }

+      })

+    }

+

+    // UART PL011

+    Device(COM0) {

+      Name(_HID, "ARMH0011")

+      Name(_CID, "PL011")

+      Name(_UID, Zero)

+      Name(_CRS, ResourceTemplate() {

+        Memory32Fixed(ReadWrite, 0x7FF80000, 0x1000)

+        Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 115 }

+      })

+    }

+

+    //

+    // USB Host Controller

+    //

+    Device(USB0){

+        Name(_HID, "ARMH0D20")

+        Name(_CID, "PNP0D20")

+        Name(_UID, 2)

+

+        Method(_CRS, 0x0, Serialized){

+            Name(RBUF, ResourceTemplate(){

+                Memory32Fixed(ReadWrite, 0x7FFC0000, 0x000000B0)

+                Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) {149}  // INT ID=149 GIC IRQ ID=117 for Juno SoC USB EHCI Controller

+            })

+            Return(RBUF)

+        }

+

+        //

+        // Root Hub

+        //

+        Device(RHUB){

+            Name(_ADR, 0x00000000)  // Address of Root Hub should be 0 as per ACPI 5.0 spec

+

+            //

+            // Ports connected to Root Hub

+            //

+            Device(HUB1){

+                Name(_ADR, 0x00000001)

+                Name(_UPC, Package(){

+                    0x00,       // Port is NOT connectable

+                    0xFF,       // Don't care

+                    0x00000000, // Reserved 0 must be zero

+                    0x00000000  // Reserved 1 must be zero

+                })

+

+                Device(PRT1){

+                    Name(_ADR, 0x00000001)

+                    Name(_UPC, Package(){

+                        0xFF,        // Port is connectable

+                        0x00,        // Port connector is A

+                        0x00000000,

+                        0x00000000

+                    })

+                    Name(_PLD, Package(){

+                        Buffer(0x10){

+                            0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+                            0x31, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

+                        }

+                    })

+                } // USB0_RHUB_HUB1_PRT1

+                Device(PRT2){

+                    Name(_ADR, 0x00000002)

+                    Name(_UPC, Package(){

+                        0xFF,        // Port is connectable

+                        0x00,        // Port connector is A

+                        0x00000000,

+                        0x00000000

+                    })

+                    Name(_PLD, Package(){

+                        Buffer(0x10){

+                            0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+                            0x31, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

+                        }

+                    })

+                } // USB0_RHUB_HUB1_PRT2

+

+                Device(PRT3){

+                    Name(_ADR, 0x00000003)

+                    Name(_UPC, Package(){

+                        0xFF,        // Port is connectable

+                        0x00,        // Port connector is A

+                        0x00000000,

+                        0x00000000

+                    })

+                    Name(_PLD, Package(){

+                        Buffer(0x10){

+                            0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+                            0x31, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

+                        }

+                    })

+                } // USB0_RHUB_HUB1_PRT3

+

+                Device(PRT4){

+                    Name(_ADR, 0x00000004)

+                    Name(_UPC, Package(){

+                        0xFF,        // Port is connectable

+                        0x00,        // Port connector is A

+                        0x00000000,

+                        0x00000000

+                    })

+                    Name(_PLD, Package(){

+                        Buffer(0x10){

+                            0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+                            0x31, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

+                        }

+                    })

+                } // USB0_RHUB_HUB1_PRT4

+            } // USB0_RHUB_HUB1

+        } // USB0_RHUB

+    } // USB0

+  } // Scope(_SB)

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Facs.aslc b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Facs.aslc
new file mode 100644
index 0000000..9743ddb
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Facs.aslc
@@ -0,0 +1,68 @@
+/** @file

+*  Firmware ACPI Control Structure (FACS)

+*

+*  Copyright (c) 2012 - 2014, ARM 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.

+*

+**/

+

+#include <IndustryStandard/Acpi.h>

+

+EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE Facs = {

+  EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE, // UINT32  Signature

+  sizeof (EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE),  // UINT32  Length

+  0xA152,                                                 // UINT32  HardwareSignature

+  0,                                                      // UINT32  FirmwareWakingVector

+  0,                                                      // UINT32  GlobalLock

+  0,                                                      // UINT32  Flags

+  0,                                                      // UINT64  XFirmwareWakingVector

+  EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION,   // UINT8   Version;

+    { EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved0[0]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved0[1]

+      EFI_ACPI_RESERVED_BYTE },                           // UINT8   Reserved0[2]

+  0,                                                      // UINT32  OspmFlags  "Platform firmware must

+                                                          //                    initialize this field to zero."

+    { EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[0]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[1]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[2]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[3]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[4]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[5]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[6]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[7]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[8]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[9]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[10]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[11]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[12]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[13]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[14]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[15]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[16]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[17]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[18]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[19]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[20]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[21]

+      EFI_ACPI_RESERVED_BYTE,                             // UINT8   Reserved1[22]

+      EFI_ACPI_RESERVED_BYTE },                           // UINT8   Reserved1[23]

+};

+

+VOID*

+ReferenceAcpiTable (

+  VOID

+  )

+{

+  //

+  // Reference the table being generated to prevent the optimizer from removing the

+  // data structure from the executable

+  //

+  return (VOID*)&Facs;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Fadt.aslc b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Fadt.aslc
new file mode 100644
index 0000000..ef6d786
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Fadt.aslc
@@ -0,0 +1,105 @@
+/** @file

+*  Fixed ACPI Description Table (FADT)

+*

+*  Copyright (c) 2012 - 2014, ARM 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.

+*

+**/

+

+#include "ArmPlatform.h"

+#include <Library/AcpiLib.h>

+#include <IndustryStandard/Acpi.h>

+

+#ifdef ARM_JUNO_ACPI_5_0

+EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE Fadt = {

+  ARM_ACPI_HEADER (

+    EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,

+    EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE,

+    EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION

+  ),

+#else

+EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE Fadt = {

+  ARM_ACPI_HEADER (

+    EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,

+    EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE,

+    EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE_REVISION

+  ),

+#endif

+  0,                                                                        // UINT32     FirmwareCtrl

+  0,                                                                        // UINT32     Dsdt

+  EFI_ACPI_RESERVED_BYTE,                                                   // UINT8      Reserved0

+  EFI_ACPI_5_0_PM_PROFILE_UNSPECIFIED,                                      // UINT8      PreferredPmProfile

+  0,                                                                        // UINT16     SciInt

+  0,                                                                        // UINT32     SmiCmd

+  0,                                                                        // UINT8      AcpiEnable

+  0,                                                                        // UINT8      AcpiDisable

+  0,                                                                        // UINT8      S4BiosReq

+  0,                                                                        // UINT8      PstateCnt

+  0,                                                                        // UINT32     Pm1aEvtBlk

+  0,                                                                        // UINT32     Pm1bEvtBlk

+  0,                                                                        // UINT32     Pm1aCntBlk

+  0,                                                                        // UINT32     Pm1bCntBlk

+  0,                                                                        // UINT32     Pm2CntBlk

+  0,                                                                        // UINT32     PmTmrBlk

+  0,                                                                        // UINT32     Gpe0Blk

+  0,                                                                        // UINT32     Gpe1Blk

+  0,                                                                        // UINT8      Pm1EvtLen

+  0,                                                                        // UINT8      Pm1CntLen

+  0,                                                                        // UINT8      Pm2CntLen

+  0,                                                                        // UINT8      PmTmrLen

+  0,                                                                        // UINT8      Gpe0BlkLen

+  0,                                                                        // UINT8      Gpe1BlkLen

+  0,                                                                        // UINT8      Gpe1Base

+  0,                                                                        // UINT8      CstCnt

+  0,                                                                        // UINT16     PLvl2Lat

+  0,                                                                        // UINT16     PLvl3Lat

+  0,                                                                        // UINT16     FlushSize

+  0,                                                                        // UINT16     FlushStride

+  0,                                                                        // UINT8      DutyOffset

+  0,                                                                        // UINT8      DutyWidth

+  0,                                                                        // UINT8      DayAlrm

+  0,                                                                        // UINT8      MonAlrm

+  0,                                                                        // UINT8      Century

+  0,                                                                        // UINT16     IaPcBootArch

+  0,                                                                        // UINT8      Reserved1

+  EFI_ACPI_5_0_HW_REDUCED_ACPI | EFI_ACPI_5_0_LOW_POWER_S0_IDLE_CAPABLE,    // UINT32     Flags

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  ResetReg

+  0,                                                                        // UINT8      ResetValue

+#if ARM_JUNO_ACPI_5_0

+  {EFI_ACPI_RESERVED_BYTE,EFI_ACPI_RESERVED_BYTE,EFI_ACPI_RESERVED_BYTE},   // UINT8      Reserved2[3]

+#else

+  EFI_ACPI_5_1_ARM_PSCI_COMPLIANT,                                          // UINT16     ArmBootArchFlags

+  EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE_MINOR_REVISION,                 // UINT8      MinorRevision

+#endif

+  0,                                                                        // UINT64     XFirmwareCtrl

+  0,                                                                        // UINT64     XDsdt

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XPm1aEvtBlk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XPm1bEvtBlk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XPm1aCntBlk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XPm1bCntBlk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XPm2CntBlk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XPmTmrBlk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XGpe0Blk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  XGpe1Blk

+  NULL_GAS,                                                                 // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  SleepControlReg

+  NULL_GAS                                                                  // EFI_ACPI_5_0_GENERIC_ADDRESS_STRUCTURE  SleepStatusReg

+};

+

+VOID*

+ReferenceAcpiTable (

+  VOID

+  )

+{

+  //

+  // Reference the table being generated to prevent the optimizer from removing the

+  // data structure from the executable

+  //

+  return (VOID*)&Fadt;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Gtdt.aslc b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Gtdt.aslc
new file mode 100644
index 0000000..49d6e8e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Gtdt.aslc
@@ -0,0 +1,109 @@
+/** @file

+*  Generic Timer Description Table (GTDT)

+*

+*  Copyright (c) 2012 - 2014, ARM 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.

+*

+**/

+

+#include "ArmPlatform.h"

+#include <Library/AcpiLib.h>

+#include <Library/PcdLib.h>

+#include <IndustryStandard/Acpi.h>

+

+#define GTDT_GLOBAL_FLAGS_MAPPED      EFI_ACPI_5_0_GTDT_GLOBAL_FLAG_MEMORY_MAPPED_BLOCK_PRESENT

+#define GTDT_GLOBAL_FLAGS_NOT_MAPPED  0

+#define GTDT_GLOBAL_FLAGS_EDGE        EFI_ACPI_5_0_GTDT_GLOBAL_FLAG_INTERRUPT_MODE

+#define GTDT_GLOBAL_FLAGS_LEVEL       0

+

+// Note: We could have a build flag that switches between memory mapped/non-memory mapped timer

+#ifdef SYSTEM_TIMER_BASE_ADDRESS

+  #define GTDT_GLOBAL_FLAGS             (GTDT_GLOBAL_FLAGS_MAPPED | GTDT_GLOBAL_FLAGS_LEVEL)

+#else

+  #define GTDT_GLOBAL_FLAGS             (GTDT_GLOBAL_FLAGS_NOT_MAPPED | GTDT_GLOBAL_FLAGS_LEVEL)

+  #define SYSTEM_TIMER_BASE_ADDRESS     0xFFFFFFFFFFFFFFFF
+#endif

+

+#define GTDT_TIMER_EDGE_TRIGGERED   EFI_ACPI_5_0_GTDT_TIMER_FLAG_TIMER_INTERRUPT_MODE
+#define GTDT_TIMER_LEVEL_TRIGGERED  0 
+#define GTDT_TIMER_ACTIVE_LOW       EFI_ACPI_5_0_GTDT_TIMER_FLAG_TIMER_INTERRUPT_POLARITY
+#define GTDT_TIMER_ACTIVE_HIGH      0
+

+#define GTDT_GTIMER_FLAGS           (GTDT_TIMER_ACTIVE_LOW | GTDT_TIMER_LEVEL_TRIGGERED)

+

+#ifdef ARM_JUNO_ACPI_5_0

+  EFI_ACPI_5_0_GENERIC_TIMER_DESCRIPTION_TABLE Gtdt = {

+    ARM_ACPI_HEADER(

+      EFI_ACPI_5_0_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,

+      EFI_ACPI_5_0_GENERIC_TIMER_DESCRIPTION_TABLE,

+      EFI_ACPI_5_0_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION

+    ),

+    SYSTEM_TIMER_BASE_ADDRESS,                    // UINT64  PhysicalAddress

+    GTDT_GLOBAL_FLAGS,                            // UINT32  GlobalFlags

+    FixedPcdGet32 (PcdArmArchTimerSecIntrNum),    // UINT32  SecurePL1TimerGSIV

+    GTDT_GTIMER_FLAGS,                            // UINT32  SecurePL1TimerFlags

+    FixedPcdGet32 (PcdArmArchTimerIntrNum),       // UINT32  NonSecurePL1TimerGSIV

+    GTDT_GTIMER_FLAGS,                            // UINT32  NonSecurePL1TimerFlags

+    FixedPcdGet32 (PcdArmArchTimerVirtIntrNum),   // UINT32  VirtualTimerGSIV

+    GTDT_GTIMER_FLAGS,                            // UINT32  VirtualTimerFlags

+    FixedPcdGet32 (PcdArmArchTimerHypIntrNum),    // UINT32  NonSecurePL2TimerGSIV

+    GTDT_GTIMER_FLAGS                             // UINT32  NonSecurePL2TimerFlags

+  };

+#else

+  #pragma pack (1)

+

+  typedef struct {

+    EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE          Gtdt;

+    EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE     Watchdogs[JUNO_WATCHDOG_COUNT];

+  } EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLES;

+

+  #pragma pack ()

+

+  EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLES Gtdt = {

+    {

+      ARM_ACPI_HEADER(

+        EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,

+        EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE,

+        EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION

+      ),

+      SYSTEM_TIMER_BASE_ADDRESS,                    // UINT64  PhysicalAddress

+      0,                                            // UINT32  Reserved

+      FixedPcdGet32 (PcdArmArchTimerSecIntrNum),    // UINT32  SecurePL1TimerGSIV

+      GTDT_GTIMER_FLAGS,                            // UINT32  SecurePL1TimerFlags

+      FixedPcdGet32 (PcdArmArchTimerIntrNum),       // UINT32  NonSecurePL1TimerGSIV

+      GTDT_GTIMER_FLAGS,                            // UINT32  NonSecurePL1TimerFlags

+      FixedPcdGet32 (PcdArmArchTimerVirtIntrNum),   // UINT32  VirtualTimerGSIV

+      GTDT_GTIMER_FLAGS,                            // UINT32  VirtualTimerFlags

+      FixedPcdGet32 (PcdArmArchTimerHypIntrNum),    // UINT32  NonSecurePL2TimerGSIV

+      GTDT_GTIMER_FLAGS,                            // UINT32  NonSecurePL2TimerFlags

+      0xFFFFFFFFFFFFFFFF,                           // UINT64  CntReadBasePhysicalAddress

+      JUNO_WATCHDOG_COUNT,                          // UINT32  PlatformTimerCount

+      sizeof (EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE) // UINT32 PlatfromTimerOffset

+    },

+    {

+      EFI_ACPI_5_1_SBSA_GENERIC_WATCHDOG_STRUCTURE_INIT(

+          FixedPcdGet32 (PcdGenericWatchdogRefreshBase), FixedPcdGet32 (PcdGenericWatchdogControlBase), 93, 0),

+      EFI_ACPI_5_1_SBSA_GENERIC_WATCHDOG_STRUCTURE_INIT(

+          FixedPcdGet32 (PcdGenericWatchdogRefreshBase), FixedPcdGet32 (PcdGenericWatchdogControlBase), 94, EFI_ACPI_5_1_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_SECURE_TIMER)

+    }

+  };

+#endif

+

+VOID*

+ReferenceAcpiTable (

+  VOID

+  )

+{

+  //

+  // Reference the table being generated to prevent the optimizer from removing the

+  // data structure from the exeutable

+  //

+  return (VOID*)&Gtdt;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Madt.aslc b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Madt.aslc
new file mode 100644
index 0000000..76236a1
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/AcpiTables/Madt.aslc
@@ -0,0 +1,134 @@
+/** @file

+*  Multiple APIC Description Table (MADT)

+*

+*  Copyright (c) 2012 - 2015, ARM 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.

+*

+**/

+

+#include "ArmPlatform.h"

+#include <Library/AcpiLib.h>

+#include <Library/ArmLib.h>

+#include <Library/PcdLib.h>

+#include <IndustryStandard/Acpi.h>

+

+//

+// Multiple APIC Description Table

+//

+#ifdef ARM_JUNO_ACPI_5_0

+  #pragma pack (1)

+

+  typedef struct {

+    EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER   Header;

+    EFI_ACPI_5_0_GIC_STRUCTURE                            GicInterfaces[FixedPcdGet32 (PcdCoreCount)];

+    EFI_ACPI_5_0_GIC_DISTRIBUTOR_STRUCTURE                GicDistributor;

+  } EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE;

+

+  #pragma pack ()

+

+  EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE Madt = {

+    {

+      ARM_ACPI_HEADER (

+        EFI_ACPI_1_0_APIC_SIGNATURE,

+        EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE,

+        EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION

+      ),

+      //

+      // MADT specific fields

+      //

+      0, // LocalApicAddress

+      0, // Flags

+    },

+    {

+      // Format: EFI_ACPI_5_0_GIC_STRUCTURE_INIT(GicId, AcpiCpuId, Flags, PmuIrq, GicBase)

+      // Note: The GIC Structure of the primary CPU must be the first entry (see note in 5.2.12.14 GIC Structure of

+      //       ACPI v5.0).

+      //       On Juno we can change the primary CPU changing the SCC register. It is not currently supported in the

+      //       Trusted Firmware. When supported, we will need to code to dynamically change the ordering.

+      //       For now we leave CPU2 (A53-0) at the first position.

+      //       The cores from a same cluster are kept together. It is not an ACPI requirement but in case the OSPM uses

+      //       the ACPI ARM Parking protocol, it might want to wake up the cores in the order of this table.

+      EFI_ACPI_5_0_GIC_STRUCTURE_INIT(2, 0, EFI_ACPI_5_0_GIC_ENABLED, 50, FixedPcdGet32 (PcdGicInterruptInterfaceBase)), // A53-0

+      EFI_ACPI_5_0_GIC_STRUCTURE_INIT(3, 1, EFI_ACPI_5_0_GIC_ENABLED, 54, FixedPcdGet32 (PcdGicInterruptInterfaceBase)), // A53-1

+      EFI_ACPI_5_0_GIC_STRUCTURE_INIT(4, 2, EFI_ACPI_5_0_GIC_ENABLED, 58, FixedPcdGet32 (PcdGicInterruptInterfaceBase)), // A53-2

+      EFI_ACPI_5_0_GIC_STRUCTURE_INIT(5, 3, EFI_ACPI_5_0_GIC_ENABLED, 62, FixedPcdGet32 (PcdGicInterruptInterfaceBase)), // A53-3

+      EFI_ACPI_5_0_GIC_STRUCTURE_INIT(0, 4, EFI_ACPI_5_0_GIC_ENABLED, 34, FixedPcdGet32 (PcdGicInterruptInterfaceBase)), // A57-0

+      EFI_ACPI_5_0_GIC_STRUCTURE_INIT(1, 5, EFI_ACPI_5_0_GIC_ENABLED, 38, FixedPcdGet32 (PcdGicInterruptInterfaceBase))  // A57-1

+    },

+    EFI_ACPI_5_0_GIC_DISTRIBUTOR_INIT(0, FixedPcdGet32 (PcdGicDistributorBase), 0)

+  };

+#else

+  #pragma pack (1)

+

+  typedef struct {

+    EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER   Header;

+    EFI_ACPI_5_1_GIC_STRUCTURE                            GicInterfaces[FixedPcdGet32 (PcdCoreCount)];

+    EFI_ACPI_5_0_GIC_DISTRIBUTOR_STRUCTURE                GicDistributor;

+  } EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE;

+

+  #pragma pack ()

+

+  EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE Madt = {

+    {

+      ARM_ACPI_HEADER (

+        EFI_ACPI_1_0_APIC_SIGNATURE,

+        EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE,

+        EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION

+      ),

+      //

+      // MADT specific fields

+      //

+      0, // LocalApicAddress

+      0, // Flags

+    },

+    {

+      // Format: EFI_ACPI_5_1_GICC_STRUCTURE_INIT(GicId, AcpiCpuUid, Flags, PmuIrq, GicBase, GicVBase, GicHBase,

+      //                                          GsivId, GicRBase, Mpidr)

+      // Note: The GIC Structure of the primary CPU must be the first entry (see note in 5.2.12.14 GICC Structure of

+      //       ACPI v5.1).

+      //       On Juno we can change the primary CPU changing the SCC register. It is not currently supported in the

+      //       Trusted Firmware. When supported, we will need to code to dynamically change the ordering.

+      //       For now we leave CPU2 (A53-0) at the first position.

+      //       The cores from a same cluster are kept together. It is not an ACPI requirement but in case the OSPM uses

+      //       the ACPI ARM Parking protocol, it might want to wake up the cores in the order of this table.

+      EFI_ACPI_5_1_GICC_STRUCTURE_INIT( // A53-0

+          2, 0, GET_MPID(1, 0), EFI_ACPI_5_0_GIC_ENABLED, 50, FixedPcdGet32 (PcdGicInterruptInterfaceBase),

+          0x2C06F000, 0x2C04F000, 25, 0 /* GicRBase */),

+      EFI_ACPI_5_1_GICC_STRUCTURE_INIT( // A53-1

+          3, 1, GET_MPID(1, 1),  EFI_ACPI_5_0_GIC_ENABLED, 54, FixedPcdGet32 (PcdGicInterruptInterfaceBase),

+          0x2C06F000, 0x2C04F000, 25, 0 /* GicRBase */),

+      EFI_ACPI_5_1_GICC_STRUCTURE_INIT( // A53-2

+          4, 2, GET_MPID(1, 2),  EFI_ACPI_5_0_GIC_ENABLED, 58, FixedPcdGet32 (PcdGicInterruptInterfaceBase),

+          0x2C06F000, 0x2C04F000, 25, 0 /* GicRBase */),

+      EFI_ACPI_5_1_GICC_STRUCTURE_INIT( // A53-3

+          5, 3, GET_MPID(1, 3),  EFI_ACPI_5_0_GIC_ENABLED, 62, FixedPcdGet32 (PcdGicInterruptInterfaceBase),

+          0x2C06F000, 0x2C04F000, 25, 0 /* GicRBase */),

+      EFI_ACPI_5_1_GICC_STRUCTURE_INIT( // A57-0

+          0, 4, GET_MPID(0, 0),  EFI_ACPI_5_0_GIC_ENABLED, 34, FixedPcdGet32 (PcdGicInterruptInterfaceBase),

+          0x2C06F000, 0x2C04F000, 25, 0 /* GicRBase */),

+      EFI_ACPI_5_1_GICC_STRUCTURE_INIT( // A57-1

+          1, 5, GET_MPID(0, 1),  EFI_ACPI_5_0_GIC_ENABLED, 38, FixedPcdGet32 (PcdGicInterruptInterfaceBase),

+          0x2C06F000, 0x2C04F000, 25, 0 /* GicRBase */),

+    },

+    EFI_ACPI_5_0_GIC_DISTRIBUTOR_INIT(0, FixedPcdGet32 (PcdGicDistributorBase), 0)

+  };

+#endif

+

+VOID*

+ReferenceAcpiTable (

+  VOID

+  )

+{

+  //

+  // Reference the table being generated to prevent the optimizer from removing the

+  // data structure from the executable

+  //

+  return (VOID*)&Madt;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.dec b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.dec
new file mode 100644
index 0000000..051ffbb
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.dec
@@ -0,0 +1,36 @@
+#

+#  Copyright (c) 2013-2014, ARM 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              = 0x00010005

+  PACKAGE_NAME                   = ArmJunoPkg

+  PACKAGE_GUID                   = a1147a20-3144-4f8d-8295-b48311c8e4a4

+  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]

+  gArmJunoTokenSpaceGuid    =  { 0xa1147a20, 0x3144, 0x4f8d, { 0x82, 0x95, 0xb4, 0x83, 0x11, 0xc8, 0xe4, 0xa4 } }

+

+[PcdsFixedAtBuild.common]

+  gArmJunoTokenSpaceGuid.PcdSynopsysUsbOhciBaseAddress|0x7FFB0000|UINT32|0x00000004

+  gArmJunoTokenSpaceGuid.PcdSynopsysUsbEhciBaseAddress|0x7FFC0000|UINT32|0x00000005

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.dsc
new file mode 100644
index 0000000..b61831a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.dsc
@@ -0,0 +1,246 @@
+#

+#  Copyright (c) 2013-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmJuno

+  PLATFORM_GUID                  = ca0722fd-7d3d-45ea-948c-d62b2199807d

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmJuno

+  SUPPORTED_ARCHITECTURES        = AARCH64|ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmJunoPkg/ArmJuno.fdf

+

+# On RTSM, most peripherals are VExpress Motherboard peripherals

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmPlatformLib|ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoLib.inf

+  ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmJunoPkg/Library/NorFlashJunoLib/NorFlashJunoLib.inf

+  EfiResetSystemLib|ArmPkg/Library/ArmPsciResetSystemLib/ArmPsciResetSystemLib.inf

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+

+  # USB Requirements

+  UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf

+

+[LibraryClasses.ARM]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+

+[LibraryClasses.AARCH64]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+

+[LibraryClasses.common.SEC]

+  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf

+  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf

+  LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf

+  HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf

+  PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf

+  MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf

+

+[BuildOptions]

+  *_*_*_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmJunoPkg/Include

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Juno"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmJuno"

+

+  #

+  # NV Storage PCDs. Use base of 0x08000000 for NOR0

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0BFC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0BFD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0BFE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+

+  # System Memory (2GB - 16MB of Trusted DRAM at the top of the 32bit address space)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x7F000000

+

+  # Juno Dual-Cluster profile

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|6

+  gArmPlatformTokenSpaceGuid.PcdClusterCount|2

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x7FF80000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200

+  gArmPlatformTokenSpaceGuid.PL011UartInteger|4

+  gArmPlatformTokenSpaceGuid.PL011UartFractional|0

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x1C170000

+

+  # LAN9118 Ethernet Driver

+  gEmbeddedTokenSpaceGuid.PcdLan9118DxeBaseAddress|0x18000000

+  gEmbeddedTokenSpaceGuid.PcdLan9118DefaultMacAddress|0x1215161822242628

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C010000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C02F000

+

+  # List of Device Paths that support BootMonFs

+  gArmPlatformTokenSpaceGuid.PcdBootMonFsSupportedDevicePaths|L"VenHw(E7223039-5836-41E1-B542-D7EC736C5E59)"

+

+  #

+  # ARM OS Loader

+  #

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux from NOR Flash"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(E7223039-5836-41E1-B542-D7EC736C5E59)/Image"

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(E7223039-5836-41E1-B542-D7EC736C5E59)/juno.dtb"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"console=ttyAMA0,115200 earlyprintk=pl011,0x7ff80000 root=/dev/sda1 rootwait verbose debug"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi();VenHw(CE660500-824D-11E0-AC72-0002A5D5C51B)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM Architectural Timer Frequency

+  #

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|50000000

+  gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|1000

+

+[PcdsPatchableInModule]

+  # Console Resolution (Full HD)

+  gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|1920

+  gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|1080

+

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+  #

+  # PEI Phase modules

+  #

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+

+  #

+  # ACPI Support

+  #

+  MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf

+  ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  # Networking stack

+  EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.inf

+

+  #

+  # Usb Support

+  #

+  MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf

+  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf

+  MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf

+  MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf

+  MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf

+

+  #

+  # Juno platform driver

+  #

+  ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.fdf
new file mode 100644
index 0000000..e0aa56f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/ArmJuno.fdf
@@ -0,0 +1,336 @@
+#

+#  Copyright (c) 2013-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.BL33_AP_UEFI]

+BaseAddress   = 0xE0000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+Size          = 0x000F0000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0xF0

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x000F0000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+

+  #

+  # ACPI Support

+  #

+  INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf

+  INF RuleOverride=ACPITABLE ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf

+

+  # NOR Flash driver

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+

+  # Versatile Express FileSystem

+  INF ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  # FV FileSystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+  #

+  # Usb Support

+  #

+  INF MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf

+  INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf

+  INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf

+  INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf

+  INF MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf

+

+  #

+  # Networking stack

+  #

+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

+  INF EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.inf

+

+  #

+  # UEFI applications

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Juno platform driver

+  #

+  INF ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+#

+# These SEC rules are used for ArmPlatformPkg/PrePi module.

+# ArmPlatformPkg/PrePi is declared as a SEC module to make GenFv patch the

+# UEFI Firmware to jump to ArmPlatformPkg/PrePi entrypoint

+#

+[Rule.ARM.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.AARCH64.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 4K                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+# A shim specific rule is required to ensure the alignment is 4K.

+# Otherwise BaseTools pick up the AArch32 alignment (ie: 32)

+[Rule.ARM.SEC.SHIM]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 4K                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.USER_DEFINED.ACPITABLE]

+  FILE FREEFORM = $(NAMED_GUID) {

+    RAW ACPI               |.acpi

+    RAW ASL                |.aml

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
new file mode 100644
index 0000000..0542a20
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
@@ -0,0 +1,91 @@
+/** @file

+*

+*  Copyright (c) 2013-2015, ARM 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.

+*

+**/

+

+#include "ArmJunoDxeInternal.h"

+#include <Library/ArmShellCmdLib.h>

+#include <Library/AcpiLib.h>

+

+// This GUID must match the FILE_GUID in ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf

+STATIC CONST EFI_GUID mJunoAcpiTableFile = { 0xa1dd808e, 0x1e95, 0x4399, { 0xab, 0xc0, 0x65, 0x3c, 0x82, 0xe8, 0x53, 0x0c } };

+

+EFI_STATUS

+EFIAPI

+ArmJunoEntryPoint (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS           Status;

+  EFI_PHYSICAL_ADDRESS HypBase;

+

+  Status = PciEmulationEntryPoint ();

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  //

+  // If a hypervisor has been declared then we need to make sure its region is protected at runtime

+  //

+  // Note: This code is only a workaround for our dummy hypervisor (ArmPkg/Extra/AArch64ToAArch32Shim/)

+  //       that does not set up (yet) the stage 2 translation table to hide its own memory to EL1.

+  //

+  if (FixedPcdGet32 (PcdHypFvSize) != 0) {

+    // Ensure the hypervisor region is strictly contained into a EFI_PAGE_SIZE-aligned region.

+    // The memory must be a multiple of EFI_PAGE_SIZE to ensure we do not reserve more memory than the hypervisor itself.

+    // A UEFI Runtime region size granularity cannot be smaller than EFI_PAGE_SIZE. If the hypervisor size is not rounded

+    // to this size then there is a risk some non-runtime memory could be visible to the OS view.

+    if (((FixedPcdGet32 (PcdHypFvSize) & EFI_PAGE_MASK) == 0) && ((FixedPcdGet32 (PcdHypFvBaseAddress) & EFI_PAGE_MASK) == 0)) {

+      // The memory needs to be declared because the DXE core marked it as reserved and removed it from the memory space

+      // as it contains the Firmware.

+      Status = gDS->AddMemorySpace (

+          EfiGcdMemoryTypeSystemMemory,

+          FixedPcdGet32 (PcdHypFvBaseAddress), FixedPcdGet32 (PcdHypFvSize),

+          EFI_MEMORY_WB | EFI_MEMORY_RUNTIME

+          );

+      if (!EFI_ERROR (Status)) {

+        // We allocate the memory to ensure it is marked as runtime memory

+        HypBase = FixedPcdGet32 (PcdHypFvBaseAddress);

+        Status = gBS->AllocatePages (AllocateAddress, EfiRuntimeServicesCode,

+                                     EFI_SIZE_TO_PAGES (FixedPcdGet32 (PcdHypFvSize)), &HypBase);

+      }

+    } else {

+      // The hypervisor must be contained into a EFI_PAGE_SIZE-aligned region and its size must also be aligned

+      // on a EFI_PAGE_SIZE boundary (ie: 4KB).

+      Status = EFI_UNSUPPORTED;

+      ASSERT_EFI_ERROR (Status);

+    }

+

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  }

+

+  // Install dynamic Shell command to run baremetal binaries.

+  Status = ShellDynCmdRunAxfInstall (ImageHandle);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "ArmJunoDxe: Failed to install ShellDynCmdRunAxf\n"));

+  }

+

+  // Try to install the ACPI Tables

+  Status = LocateAndInstallAcpiFromFv (&mJunoAcpiTableFile);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Try to install the Flat Device Tree (FDT). This function actually installs the

+  // UEFI Driver Binding Protocol.

+  Status = JunoFdtInstall (ImageHandle);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.inf
new file mode 100644
index 0000000..fd77a5d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.inf
@@ -0,0 +1,78 @@
+#

+#  Copyright (c) 2013-2014, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmJunoDxe

+  FILE_GUID                      = 1484ebe8-2681-45f1-a2e5-12ecad893b62

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  ENTRY_POINT                    = ArmJunoEntryPoint

+

+[Sources.common]

+  ArmJunoDxe.c

+  InstallFdt.c

+  PciEmulation.c

+  PciRootBridgeIo.c

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmJunoPkg/ArmJuno.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+

+[LibraryClasses]

+  AcpiLib

+  ArmShellCmdRunAxfLib

+  BaseMemoryLib

+  BdsLib

+  DebugLib

+  DmaLib

+  DxeServicesTableLib

+  FdtLib

+  IoLib

+  PcdLib

+  PrintLib

+  SerialPortLib

+  UefiBootServicesTableLib

+  UefiRuntimeServicesTableLib

+  UefiLib

+  UefiDriverEntryPoint

+

+[Guids]

+  gArmGlobalVariableGuid

+  gEfiEndOfDxeEventGroupGuid

+  gEfiFileInfoGuid

+  gFdtTableGuid

+  gArmPlatformUpdateFdtEventGuid

+

+[Protocols]

+  gEfiBlockIoProtocolGuid

+  gEfiDevicePathFromTextProtocolGuid

+  gEfiPciIoProtocolGuid

+  gEfiSimpleFileSystemProtocolGuid

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdHypFvBaseAddress

+  gArmTokenSpaceGuid.PcdHypFvSize

+

+  gArmJunoTokenSpaceGuid.PcdSynopsysUsbEhciBaseAddress

+  gArmJunoTokenSpaceGuid.PcdSynopsysUsbOhciBaseAddress

+

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxeInternal.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxeInternal.h
new file mode 100644
index 0000000..5ebb516
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxeInternal.h
@@ -0,0 +1,36 @@
+/** @file

+*

+*  Copyright (c) 2013-2014, ARM 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.

+*

+**/

+

+#ifndef __ARM_JUNO_DXE_INTERNAL_H__

+#define __ARM_JUNO_DXE_INTERNAL_H__

+

+#include <Uefi.h>

+

+#include <Library/DebugLib.h>

+#include <Library/DxeServicesTableLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#include <IndustryStandard/Acpi.h>

+

+EFI_STATUS

+PciEmulationEntryPoint (

+  VOID

+  );

+

+EFI_STATUS

+JunoFdtInstall (

+  IN EFI_HANDLE                            ImageHandle

+  );

+

+#endif // __ARM_JUNO_DXE_INTERNAL_H__

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/InstallFdt.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/InstallFdt.c
new file mode 100644
index 0000000..337a4f0
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/InstallFdt.c
@@ -0,0 +1,444 @@
+/** @file

+*

+*  Copyright (c) 2014-2015, ARM 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.

+*

+**/

+

+#include "ArmJunoDxeInternal.h"

+

+#include <Protocol/BlockIo.h>

+#include <Protocol/DevicePathFromText.h>

+#include <Protocol/DriverBinding.h>

+#include <Protocol/SimpleFileSystem.h>

+

+#include <Library/BaseMemoryLib.h>

+#include <Library/BdsLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PrintLib.h>

+#include <Library/SerialPortLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+

+#include <Guid/ArmGlobalVariableHob.h>

+#include <Guid/ArmPlatformEvents.h>

+#include <Guid/EventGroup.h>

+#include <Guid/Fdt.h>

+#include <Guid/FileInfo.h>

+

+#include <libfdt.h>

+

+#define FDT_DEFAULT_FILENAME  L"juno"

+

+#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))

+

+// Hardware Vendor Device Path node for the Juno NOR Flash. We use the Juno NOR Flash if the user

+// has not specified another filesystem location into the UEFI Variable 'Fdt'.

+// The Juno NOR Flash has its own filesystem format (supported by ArmPlatformPkg/FileSystem/BootMonFs).

+STATIC CONST struct {

+  VENDOR_DEVICE_PATH NorGuid;

+  EFI_DEVICE_PATH    End;

+} mJunoNorFlashDevicePath = {

+  {

+    { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, { sizeof (VENDOR_DEVICE_PATH), 0 } },

+    {0xE7223039, 0x5836, 0x41E1, { 0xB5, 0x42, 0xD7, 0xEC, 0x73, 0x6C, 0x5E, 0x59} }

+  },

+  { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 } }

+};

+

+STATIC EFI_DEVICE_PATH* mFdtFileSystemDevicePath = NULL;

+STATIC CHAR16* mFdtFileName = NULL;

+

+STATIC BOOLEAN mFdtTableInstalled = FALSE;

+

+/**

+  See definition EFI_DRIVER_BINDING_PROTOCOL.Supported()

+**/

+EFI_STATUS

+EFIAPI

+JunoFdtSupported (

+  IN        EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,

+  IN        EFI_HANDLE                   ControllerHandle,

+  IN        EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath OPTIONAL

+  )

+{

+  EFI_STATUS                Status;

+  EFI_DEVICE_PATH_PROTOCOL *DevicePath;

+

+  //

+  // Check if the Handle support the Simple File System Protocol

+  //

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiSimpleFileSystemProtocolGuid,

+                  NULL,

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL

+                  );

+

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Check if a DevicePath is attached to the handle

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiDevicePathProtocolGuid,

+                  (VOID **)&DevicePath,

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_BY_DRIVER

+                  );

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Check if the Device Path is the one from the NOR Flash

+  if (CompareMem (mFdtFileSystemDevicePath, DevicePath, GetDevicePathSize (mFdtFileSystemDevicePath)) != 0) {

+    return EFI_NOT_FOUND;

+  }

+

+  gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, gImageHandle, ControllerHandle);

+  return Status;

+}

+

+/**

+  This function is used to print messages back to the user.

+

+  We use the Serial terminal for these messages as the gST->ConOut might not be initialized at this stage.

+

+  @param Message    Message to display to the user

+**/

+STATIC

+VOID

+PrintMessage (

+  IN CHAR8* Message,

+  ...

+  )

+{

+  UINTN   CharCount;

+  CHAR8   Buffer[100];

+  VA_LIST Marker;

+

+  VA_START (Marker, Message);

+  CharCount = AsciiVSPrint (Buffer, sizeof (Buffer), Message, Marker);

+  VA_END (Marker);

+

+  SerialPortWrite ((UINT8*)Buffer, CharCount);

+}

+

+/**

+  See definition EFI_DRIVER_BINDING_PROTOCOL.Start ()

+**/

+EFI_STATUS

+EFIAPI

+JunoFdtStart (

+  IN        EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,

+  IN        EFI_HANDLE                   ControllerHandle,

+  IN        EFI_DEVICE_PATH_PROTOCOL    *DevicePath OPTIONAL

+  )

+{

+  EFI_STATUS                       Status;

+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *BootMonFs;

+  EFI_FILE_PROTOCOL               *Fs;

+  EFI_FILE_PROTOCOL               *File;

+  UINTN                            Size;

+  EFI_PHYSICAL_ADDRESS             FdtBlob;

+  EFI_FILE_INFO                   *FileInfo;

+

+  if (mFdtTableInstalled) {

+    return EFI_ALREADY_STARTED;

+  }

+

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiSimpleFileSystemProtocolGuid,

+                  (VOID**)&BootMonFs,

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_BY_DRIVER

+                  );

+

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Try to Open the volume and get root directory

+  Status = BootMonFs->OpenVolume (BootMonFs, &Fs);

+  if (EFI_ERROR (Status)) {

+    PrintMessage ("Warning: Fail to open file system that should contain FDT file.\n");

+    goto CLOSE_PROTOCOL;

+  }

+

+  File = NULL;

+  Status = Fs->Open (Fs, &File, mFdtFileName, EFI_FILE_MODE_READ, 0);

+  if (EFI_ERROR (Status)) {

+    PrintMessage ("Warning: Fail to load FDT file '%s'.\n", mFdtFileName);

+    goto CLOSE_PROTOCOL;

+  }

+

+  Size = 0;

+  File->GetInfo (File, &gEfiFileInfoGuid, &Size, NULL);

+  FileInfo = AllocatePool (Size);

+  Status = File->GetInfo (File, &gEfiFileInfoGuid, &Size, FileInfo);

+  if (EFI_ERROR (Status)) {

+    goto CLOSE_FILE;

+  }

+

+  // Get the file size

+  Size = FileInfo->FileSize;

+  FreePool (FileInfo);

+

+  // The FDT blob is attached to the Configuration Table. It is better to load it as Runtime Service Data

+  // to prevent the kernel to overwrite its data

+  Status = gBS->AllocatePages (AllocateAnyPages, EfiRuntimeServicesData, EFI_SIZE_TO_PAGES (Size), &FdtBlob);

+  if (!EFI_ERROR (Status)) {

+    Status = File->Read (File, &Size, (VOID*)(UINTN)(FdtBlob));

+    if (EFI_ERROR (Status)) {

+      gBS->FreePages (FdtBlob, EFI_SIZE_TO_PAGES (Size));

+    } else {

+      // Check the FDT header is valid. We only make this check in DEBUG mode in case the FDT header change on

+      // production device and this ASSERT() becomes not valid.

+      ASSERT (fdt_check_header ((VOID*)(UINTN)(FdtBlob)) == 0);

+

+      // Ensure the Size of the Device Tree is smaller than the size of the read file

+      ASSERT ((UINTN)fdt_totalsize ((VOID*)(UINTN)FdtBlob) <= Size);

+

+      // Install the FDT into the Configuration Table

+      Status = gBS->InstallConfigurationTable (&gFdtTableGuid, (VOID*)(UINTN)(FdtBlob));

+      if (!EFI_ERROR (Status)) {

+        mFdtTableInstalled = TRUE;

+      }

+    }

+  }

+

+CLOSE_FILE:

+  File->Close (File);

+

+CLOSE_PROTOCOL:

+  // We do not need the FileSystem protocol

+  gBS->CloseProtocol (

+         ControllerHandle,

+         &gEfiSimpleFileSystemProtocolGuid,

+         gImageHandle,

+         ControllerHandle);

+

+  return Status;

+}

+

+/**

+  See definition EFI_DRIVER_BINDING_PROTOCOL.Stop()

+**/

+EFI_STATUS

+EFIAPI

+JunoFdtStop (

+  IN        EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,

+  IN        EFI_HANDLE                   ControllerHandle,

+  IN        UINTN                        NumberOfChildren,

+  IN        EFI_HANDLE                  *ChildHandleBuffer OPTIONAL

+  )

+{

+  UINTN      Index;

+  VOID*      FdtBlob;

+  UINTN      FdtSize;

+

+  // Look for FDT Table

+  for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {

+    // Check for correct GUID type

+    if (CompareGuid (&gFdtTableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {

+      FdtBlob = gST->ConfigurationTable[Index].VendorTable;

+      FdtSize = (UINTN)fdt_totalsize (FdtBlob);

+

+      // Uninstall the FDT Configuration Table

+      gBS->InstallConfigurationTable (&gFdtTableGuid, NULL);

+

+      // Free the memory

+      gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)FdtBlob, EFI_SIZE_TO_PAGES (FdtSize));

+

+      return EFI_SUCCESS;

+    }

+  }

+

+  return EFI_NOT_FOUND;

+}

+

+//

+// Driver Binding Protocol for Juno FDT support

+//

+EFI_DRIVER_BINDING_PROTOCOL mJunoFdtBinding = {

+  JunoFdtSupported,

+  JunoFdtStart,

+  JunoFdtStop,

+  0xa,

+  NULL,

+  NULL

+};

+

+/**

+  Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.

+

+  This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.

+

+  @param  Event        Event whose notification function is being invoked.

+  @param  Context      Pointer to the notification function's context.

+

+**/

+STATIC

+VOID

+EFIAPI

+LoadFdtOnEvent (

+  EFI_EVENT                               Event,

+  VOID                                    *Context

+  )

+{

+  EFI_DEVICE_PATH *DevicePathNode;

+  EFI_HANDLE       Handle;

+  EFI_STATUS       Status;

+  UINTN            VariableSize;

+  CHAR16*          FdtDevicePathStr;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;

+  EFI_EVENT        ArmPlatformUpdateFdtEvent;

+

+  //

+  // Read the 'FDT' UEFI Variable to know where we should we read the blob from.

+  // The 'Fdt' variable contains either the full device path or only the filename of the FDT.

+  // If 'Fdt' only contains the filename then we assume its location is on the NOR Flash.

+  //

+  VariableSize     = 0;

+  Status = gRT->GetVariable (L"Fdt", &gArmGlobalVariableGuid, NULL, &VariableSize, mFdtFileSystemDevicePath);

+  if (Status == EFI_BUFFER_TOO_SMALL) {

+    // Get the environment variable value

+    mFdtFileSystemDevicePath = AllocatePool (VariableSize);

+    if (mFdtFileSystemDevicePath != NULL) {

+      Status = gRT->GetVariable (L"Fdt", &gArmGlobalVariableGuid, NULL, &VariableSize, mFdtFileSystemDevicePath);

+      if (EFI_ERROR (Status)) {

+        FreePool (mFdtFileSystemDevicePath);

+        ASSERT_EFI_ERROR (Status);

+        return;

+      }

+    } else {

+      ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);

+      return;

+    }

+  } else if (Status == EFI_NOT_FOUND) {

+    // If the 'Fdt' variable does not exist then we get the FDT location from the PCD

+    FdtDevicePathStr = (CHAR16*)PcdGetPtr (PcdFdtDevicePath);

+

+    Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+    if (EFI_ERROR (Status)) {

+      ASSERT_EFI_ERROR (Status);

+      return;

+    }

+

+    // Conversion of the Device Path string into EFI Device Path

+    mFdtFileSystemDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (FdtDevicePathStr);

+  }

+

+  if (mFdtFileSystemDevicePath != NULL) {

+    // Look for the FDT filename that should be contained into the FilePath device path node

+    DevicePathNode = mFdtFileSystemDevicePath;

+    while (!IsDevicePathEnd (DevicePathNode)) {

+      if (IS_DEVICE_PATH_NODE (DevicePathNode, MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP)) {

+        // Extract the name from the File Path Node. The name of the Filename is the size of the

+        // device path node minus the size of the device path node header.

+        mFdtFileName = AllocateCopyPool (

+            DevicePathNodeLength (DevicePathNode) - sizeof(EFI_DEVICE_PATH_PROTOCOL),

+            ((FILEPATH_DEVICE_PATH*)DevicePathNode)->PathName);

+        if (mFdtFileName == NULL) {

+          ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);

+          return;

+        }

+

+        // We remove the FilePath device path node from the FileSystem Device Path

+        // because it will never match a device path installed by the FileSystem driver

+        SetDevicePathEndNode (DevicePathNode);

+        break;

+      }

+      DevicePathNode = NextDevicePathNode (DevicePathNode);

+    }

+

+    // The UEFI Variable might just contain the FDT filename. In this case we assume the FileSystem is

+    // the NOR Flash based one (ie: BootMonFs).

+    // If it was only containing the FilePath device node then the previous condition should have

+    // replaced it by the End Device Path Node.

+    if (IsDevicePathEndType (mFdtFileSystemDevicePath)) {

+      mFdtFileSystemDevicePath = (EFI_DEVICE_PATH*)&mJunoNorFlashDevicePath;

+    }

+  } else {

+    // Fallback on the NOR Flash filesystem

+    mFdtFileSystemDevicePath = (EFI_DEVICE_PATH*)&mJunoNorFlashDevicePath;

+  }

+

+  // If the FDT FileName has been provided during the FileSystem identification

+  if (mFdtFileName == NULL) {

+    mFdtFileName = AllocateCopyPool (StrSize (FDT_DEFAULT_FILENAME), FDT_DEFAULT_FILENAME);

+    if (mFdtFileName == NULL) {

+      ASSERT_EFI_ERROR (Status);

+      return;

+    }

+  }

+

+  // Context is not NULL when this function is called for a gEfiEndOfDxeEventGroupGuid event

+  if (Context) {

+    // Install the Binding protocol to verify when the FileSystem that contains the FDT has been installed

+    Status = gBS->InstallMultipleProtocolInterfaces (

+                    &gImageHandle,

+                    &gEfiDriverBindingProtocolGuid, &mJunoFdtBinding,

+                    NULL

+                    );

+    if (EFI_ERROR (Status)) {

+      ASSERT_EFI_ERROR (Status);

+      return;

+    }

+

+    // Register the event triggered when the 'Fdt' variable is updated.

+    Status = gBS->CreateEventEx (

+                    EVT_NOTIFY_SIGNAL,

+                    TPL_CALLBACK,

+                    LoadFdtOnEvent,

+                    NULL,

+                    &gArmPlatformUpdateFdtEventGuid,

+                    &ArmPlatformUpdateFdtEvent

+                    );

+    ASSERT_EFI_ERROR (Status);

+  }

+

+  //

+  // Force to connect the FileSystem that contains the FDT

+  //

+  BdsConnectDevicePath (mFdtFileSystemDevicePath, &Handle, NULL);

+}

+

+STATIC CONST BOOLEAN mIsEndOfDxeEvent = TRUE;

+

+EFI_STATUS

+JunoFdtInstall (

+  IN EFI_HANDLE                            ImageHandle

+  )

+{

+  EFI_STATUS Status;

+  EFI_EVENT  EndOfDxeEvent;

+

+  // Register the event handling function to set the End Of DXE flag.

+  // We wait until the end of the DXE phase to load the FDT to make sure

+  // all the required drivers (NOR Flash, UEFI Variable, BootMonFs) are dispatched

+  Status = gBS->CreateEventEx (

+                  EVT_NOTIFY_SIGNAL,

+                  TPL_CALLBACK,

+                  LoadFdtOnEvent,

+                  &mIsEndOfDxeEvent,

+                  &gEfiEndOfDxeEventGroupGuid,

+                  &EndOfDxeEvent

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciEmulation.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciEmulation.c
new file mode 100644
index 0000000..9fdb09b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciEmulation.c
@@ -0,0 +1,596 @@
+/** @file

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.<BR>

+

+  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 "PciEmulation.h"

+

+#define HOST_CONTROLLER_OPERATION_REG_SIZE  0x44

+

+typedef struct {

+  ACPI_HID_DEVICE_PATH      AcpiDevicePath;

+  PCI_DEVICE_PATH           PciDevicePath;

+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;

+} EFI_PCI_IO_DEVICE_PATH;

+

+typedef struct {

+  UINT32                  Signature;

+  EFI_PCI_IO_DEVICE_PATH  DevicePath;

+  EFI_PCI_IO_PROTOCOL     PciIoProtocol;

+  PCI_TYPE00              *ConfigSpace;

+  PCI_ROOT_BRIDGE         RootBridge;

+  UINTN                   Segment;

+} EFI_PCI_IO_PRIVATE_DATA;

+

+#define EFI_PCI_IO_PRIVATE_DATA_SIGNATURE     SIGNATURE_32('p', 'c', 'i', 'o')

+#define EFI_PCI_IO_PRIVATE_DATA_FROM_THIS(a)  CR (a, EFI_PCI_IO_PRIVATE_DATA, PciIoProtocol, EFI_PCI_IO_PRIVATE_DATA_SIGNATURE)

+

+EFI_PCI_IO_DEVICE_PATH PciIoDevicePathTemplate =

+{

+  {

+    { ACPI_DEVICE_PATH, ACPI_DP, { sizeof (ACPI_HID_DEVICE_PATH), 0 } },

+    EISA_PNP_ID(0x0A03),  // HID

+    0                     // UID

+  },

+  {

+    { HARDWARE_DEVICE_PATH, HW_PCI_DP, { sizeof (PCI_DEVICE_PATH), 0 } },

+    0,

+    0

+  },

+  { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0} }

+};

+

+STATIC

+VOID

+ConfigureUSBHost (

+  VOID

+  )

+{

+}

+

+

+EFI_STATUS

+PciIoPollMem (

+  IN EFI_PCI_IO_PROTOCOL           *This,

+  IN  EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN  UINT8                        BarIndex,

+  IN  UINT64                       Offset,

+  IN  UINT64                       Mask,

+  IN  UINT64                       Value,

+  IN  UINT64                       Delay,

+  OUT UINT64                       *Result

+  )

+{

+  ASSERT (FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+EFI_STATUS

+PciIoPollIo (

+  IN EFI_PCI_IO_PROTOCOL           *This,

+  IN  EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN  UINT8                        BarIndex,

+  IN  UINT64                       Offset,

+  IN  UINT64                       Mask,

+  IN  UINT64                       Value,

+  IN  UINT64                       Delay,

+  OUT UINT64                       *Result

+  )

+{

+  ASSERT (FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+EFI_STATUS

+PciIoMemRead (

+  IN EFI_PCI_IO_PROTOCOL              *This,

+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN     UINT8                        BarIndex,

+  IN     UINT64                       Offset,

+  IN     UINTN                        Count,

+  IN OUT VOID                         *Buffer

+  )

+{

+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS (This);

+

+  return PciRootBridgeIoMemRead (&Private->RootBridge.Io,

+                                (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,

+                                Private->ConfigSpace->Device.Bar[BarIndex] + Offset, //Fix me ConfigSpace

+                                Count,

+                                Buffer

+                                );

+}

+

+EFI_STATUS

+PciIoMemWrite (

+  IN EFI_PCI_IO_PROTOCOL              *This,

+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN     UINT8                        BarIndex,

+  IN     UINT64                       Offset,

+  IN     UINTN                        Count,

+  IN OUT VOID                         *Buffer

+  )

+{

+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS (This);

+

+  return PciRootBridgeIoMemWrite (&Private->RootBridge.Io,

+                                 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,

+                                 Private->ConfigSpace->Device.Bar[BarIndex] + Offset,  //Fix me ConfigSpace

+                                 Count,

+                                 Buffer

+                                 );

+}

+

+EFI_STATUS

+PciIoIoRead (

+  IN EFI_PCI_IO_PROTOCOL              *This,

+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN     UINT8                        BarIndex,

+  IN     UINT64                       Offset,

+  IN     UINTN                        Count,

+  IN OUT VOID                         *Buffer

+  )

+{

+  ASSERT (FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+EFI_STATUS

+PciIoIoWrite (

+  IN EFI_PCI_IO_PROTOCOL              *This,

+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN     UINT8                        BarIndex,

+  IN     UINT64                       Offset,

+  IN     UINTN                        Count,

+  IN OUT VOID                         *Buffer

+  )

+{

+  ASSERT (FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Enable a PCI driver to read PCI controller registers in PCI configuration space.

+

+  @param[in]      This    A pointer to the EFI_PCI_IO_PROTOCOL instance.

+  @param[in]      Width   Signifies the width of the memory operations.

+  @param[in]      Offset  The offset within the PCI configuration space for

+                          the PCI controller.

+  @param[in]      Count   The number of PCI configuration operations to

+                          perform. Bytes moved is Width size * Count,

+                          starting at Offset.

+

+  @param[in out]  Buffer  The destination buffer to store the results.

+

+  @retval  EFI_SUCCESS            The data was read from the PCI controller.

+  @retval  EFI_INVALID_PARAMETER  "Width" is invalid.

+  @retval  EFI_INVALID_PARAMETER  "Buffer" is NULL.

+

+**/

+EFI_STATUS

+PciIoPciRead (

+  IN     EFI_PCI_IO_PROTOCOL       *This,

+  IN     EFI_PCI_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT32                     Offset,

+  IN     UINTN                      Count,

+  IN OUT VOID                      *Buffer

+  )

+{

+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS (This);

+  EFI_STATUS Status;

+

+  if ((Width < 0) || (Width >= EfiPciIoWidthMaximum) || (Buffer == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Status = PciRootBridgeIoMemRW (

+             (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH)Width,

+             Count,

+             TRUE,

+             (PTR)(UINTN)Buffer,

+             TRUE,

+             (PTR)(UINTN)(((UINT8 *)Private->ConfigSpace) + Offset)  //Fix me ConfigSpace

+             );

+

+  return Status;

+}

+

+/**

+  Enable a PCI driver to write PCI controller registers in PCI configuration space.

+

+  @param[in]      This    A pointer to the EFI_PCI_IO_PROTOCOL instance.

+  @param[in]      Width   Signifies the width of the memory operations.

+  @param[in]      Offset  The offset within the PCI configuration space for

+                          the PCI controller.

+  @param[in]      Count   The number of PCI configuration operations to

+                          perform. Bytes moved is Width size * Count,

+                          starting at Offset.

+

+  @param[in out]  Buffer  The source buffer to write data from.

+

+  @retval  EFI_SUCCESS            The data was read from the PCI controller.

+  @retval  EFI_INVALID_PARAMETER  "Width" is invalid.

+  @retval  EFI_INVALID_PARAMETER  "Buffer" is NULL.

+

+**/

+EFI_STATUS

+PciIoPciWrite (

+  IN EFI_PCI_IO_PROTOCOL              *This,

+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN     UINT32                       Offset,

+  IN     UINTN                        Count,

+  IN OUT VOID                         *Buffer

+  )

+{

+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS (This);

+

+  if ((Width < 0) || (Width >= EfiPciIoWidthMaximum) || (Buffer == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  return PciRootBridgeIoMemRW ((EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,

+                               Count,

+                               TRUE,

+                               (PTR)(UINTN)(((UINT8 *)Private->ConfigSpace) + Offset),  //Fix me ConfigSpace

+                               TRUE,

+                               (PTR)(UINTN)Buffer

+                               );

+}

+

+EFI_STATUS

+PciIoCopyMem (

+  IN EFI_PCI_IO_PROTOCOL              *This,

+  IN     EFI_PCI_IO_PROTOCOL_WIDTH    Width,

+  IN     UINT8                        DestBarIndex,

+  IN     UINT64                       DestOffset,

+  IN     UINT8                        SrcBarIndex,

+  IN     UINT64                       SrcOffset,

+  IN     UINTN                        Count

+  )

+{

+  ASSERT (FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+EFI_STATUS

+PciIoMap (

+  IN EFI_PCI_IO_PROTOCOL                *This,

+  IN     EFI_PCI_IO_PROTOCOL_OPERATION  Operation,

+  IN     VOID                           *HostAddress,

+  IN OUT UINTN                          *NumberOfBytes,

+  OUT    EFI_PHYSICAL_ADDRESS           *DeviceAddress,

+  OUT    VOID                           **Mapping

+  )

+{

+  DMA_MAP_OPERATION   DmaOperation;

+

+  if (Operation == EfiPciIoOperationBusMasterRead) {

+    DmaOperation = MapOperationBusMasterRead;

+  } else if (Operation == EfiPciIoOperationBusMasterWrite) {

+    DmaOperation = MapOperationBusMasterWrite;

+  } else if (Operation == EfiPciIoOperationBusMasterCommonBuffer) {

+    DmaOperation = MapOperationBusMasterCommonBuffer;

+  } else {

+    return EFI_INVALID_PARAMETER;

+  }

+  return DmaMap (DmaOperation, HostAddress, NumberOfBytes, DeviceAddress, Mapping);

+}

+

+EFI_STATUS

+PciIoUnmap (

+  IN EFI_PCI_IO_PROTOCOL           *This,

+  IN  VOID                         *Mapping

+  )

+{

+  return DmaUnmap (Mapping);

+}

+

+/**

+  Allocate pages that are suitable for an EfiPciIoOperationBusMasterCommonBuffer

+  mapping.

+

+  @param[in]   This         A pointer to the EFI_PCI_IO_PROTOCOL instance.

+  @param[in]   Type         This parameter is not used and must be ignored.

+  @param[in]   MemoryType   The type of memory to allocate, EfiBootServicesData or

+                            EfiRuntimeServicesData.

+  @param[in]   Pages        The number of pages to allocate.

+  @param[out]  HostAddress  A pointer to store the base system memory address of

+                            the allocated range.

+  @param[in]   Attributes   The requested bit mask of attributes for the allocated

+                            range. Only the attributes,

+                            EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE and

+                            EFI_PCI_ATTRIBUTE_MEMORY_CACHED may be used with this

+                            function. If any other bits are set, then EFI_UNSUPPORTED

+                            is returned. This function ignores this bit mask.

+

+  @retval  EFI_SUCCESS            The requested memory pages were allocated.

+  @retval  EFI_INVALID_PARAMETER  HostAddress is NULL.

+  @retval  EFI_INVALID_PARAMETER  MemoryType is invalid.

+  @retval  EFI_UNSUPPORTED        Attributes is unsupported.

+  @retval  EFI_OUT_OF_RESOURCES   The memory pages could not be allocated.

+

+**/

+EFI_STATUS

+PciIoAllocateBuffer (

+  IN EFI_PCI_IO_PROTOCOL  *This,

+  IN  EFI_ALLOCATE_TYPE   Type,

+  IN  EFI_MEMORY_TYPE     MemoryType,

+  IN  UINTN               Pages,

+  OUT VOID                **HostAddress,

+  IN  UINT64              Attributes

+  )

+{

+  if (Attributes &

+      (~(EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE |

+         EFI_PCI_ATTRIBUTE_MEMORY_CACHED         ))) {

+    return EFI_UNSUPPORTED;

+  }

+

+  return DmaAllocateBuffer (MemoryType, Pages, HostAddress);

+}

+

+

+EFI_STATUS

+PciIoFreeBuffer (

+  IN EFI_PCI_IO_PROTOCOL           *This,

+  IN  UINTN                        Pages,

+  IN  VOID                         *HostAddress

+  )

+{

+  return DmaFreeBuffer (Pages, HostAddress);

+}

+

+

+EFI_STATUS

+PciIoFlush (

+  IN EFI_PCI_IO_PROTOCOL  *This

+  )

+{

+  return EFI_SUCCESS;

+}

+

+/**

+  Retrieves this PCI controller's current PCI bus number, device number, and function number.

+

+  @param[in]   This            A pointer to the EFI_PCI_IO_PROTOCOL instance.

+  @param[out]  SegmentNumber   The PCI controller's current PCI segment number.

+  @param[out]  BusNumber       The PCI controller's current PCI bus number.

+  @param[out]  DeviceNumber    The PCI controller's current PCI device number.

+  @param[out]  FunctionNumber  The PCI controller’s current PCI function number.

+

+  @retval  EFI_SUCCESS            The PCI controller location was returned.

+  @retval  EFI_INVALID_PARAMETER  At least one out of the four output parameters is

+                                  a NULL pointer.

+**/

+EFI_STATUS

+PciIoGetLocation (

+  IN   EFI_PCI_IO_PROTOCOL  *This,

+  OUT  UINTN                *SegmentNumber,

+  OUT  UINTN                *BusNumber,

+  OUT  UINTN                *DeviceNumber,

+  OUT  UINTN                *FunctionNumber

+  )

+{

+  EFI_PCI_IO_PRIVATE_DATA *Private = EFI_PCI_IO_PRIVATE_DATA_FROM_THIS (This);

+

+  if ((SegmentNumber == NULL) || (BusNumber      == NULL) ||

+      (DeviceNumber  == NULL) || (FunctionNumber == NULL)    ) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *SegmentNumber  = Private->Segment;

+  *BusNumber      = 0xff;

+  *DeviceNumber   = 0;

+  *FunctionNumber = 0;

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Performs an operation on the attributes that this PCI controller supports.

+

+  The operations include getting the set of supported attributes, retrieving

+  the current attributes, setting the current attributes, enabling attributes,

+  and disabling attributes.

+

+  @param[in]   This        A pointer to the EFI_PCI_IO_PROTOCOL instance.

+  @param[in]   Operation   The operation to perform on the attributes for this

+                           PCI controller.

+  @param[in]   Attributes  The mask of attributes that are used for Set,

+                           Enable and Disable operations.

+  @param[out]  Result      A pointer to the result mask of attributes that are

+                           returned for the Get and Supported operations. This

+                           is an optional parameter that may be NULL for the

+                           Set, Enable, and Disable operations.

+

+  @retval  EFI_SUCCESS            The operation on the PCI controller's

+                                  attributes was completed. If the operation

+                                  was Get or Supported, then the attribute mask

+                                  is returned in Result.

+  @retval  EFI_INVALID_PARAMETER  Operation is greater than or equal to

+                                  EfiPciIoAttributeOperationMaximum.

+  @retval  EFI_INVALID_PARAMETER  Operation is Get and Result is NULL.

+  @retval  EFI_INVALID_PARAMETER  Operation is Supported and Result is NULL.

+

+**/

+EFI_STATUS

+PciIoAttributes (

+  IN EFI_PCI_IO_PROTOCOL                       *This,

+  IN  EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION  Operation,

+  IN  UINT64                                   Attributes,

+  OUT UINT64                                   *Result OPTIONAL

+  )

+{

+  switch (Operation) {

+  case EfiPciIoAttributeOperationGet:

+  case EfiPciIoAttributeOperationSupported:

+    if (Result == NULL) {

+      return EFI_INVALID_PARAMETER;

+    }

+    //

+    // We are not a real PCI device so just say things we kind of do

+    //

+    *Result = EFI_PCI_DEVICE_ENABLE;

+    break;

+

+  case EfiPciIoAttributeOperationSet:

+  case EfiPciIoAttributeOperationEnable:

+  case EfiPciIoAttributeOperationDisable:

+    if (Attributes & (~EFI_PCI_DEVICE_ENABLE)) {

+      return EFI_UNSUPPORTED;

+    }

+    // Since we are not a real PCI device no enable/set or disable operations exist.

+    return EFI_SUCCESS;

+

+  default:

+    return EFI_INVALID_PARAMETER;

+  };

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+PciIoGetBarAttributes (

+  IN EFI_PCI_IO_PROTOCOL             *This,

+  IN  UINT8                          BarIndex,

+  OUT UINT64                         *Supports, OPTIONAL

+  OUT VOID                           **Resources OPTIONAL

+  )

+{

+  ASSERT (FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+EFI_STATUS

+PciIoSetBarAttributes (

+  IN EFI_PCI_IO_PROTOCOL              *This,

+  IN     UINT64                       Attributes,

+  IN     UINT8                        BarIndex,

+  IN OUT UINT64                       *Offset,

+  IN OUT UINT64                       *Length

+  )

+{

+  ASSERT (FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+EFI_PCI_IO_PROTOCOL PciIoTemplate =

+{

+  PciIoPollMem,

+  PciIoPollIo,

+  { PciIoMemRead, PciIoMemWrite },

+  { PciIoIoRead,  PciIoIoWrite },

+  { PciIoPciRead, PciIoPciWrite },

+  PciIoCopyMem,

+  PciIoMap,

+  PciIoUnmap,

+  PciIoAllocateBuffer,

+  PciIoFreeBuffer,

+  PciIoFlush,

+  PciIoGetLocation,

+  PciIoAttributes,

+  PciIoGetBarAttributes,

+  PciIoSetBarAttributes,

+  0,

+  0

+};

+

+EFI_STATUS

+PciInstallDevice (

+  IN UINTN            DeviceId,

+  IN PHYSICAL_ADDRESS MemoryStart,

+  IN UINT64           MemorySize,

+  IN UINTN            ClassCode1,

+  IN UINTN            ClassCode2,

+  IN UINTN            ClassCode3

+  )

+{

+  EFI_STATUS              Status;

+  EFI_HANDLE              Handle;

+  EFI_PCI_IO_PRIVATE_DATA *Private;

+

+  // Configure USB host

+  ConfigureUSBHost ();

+

+  // Create a private structure

+  Private = AllocatePool (sizeof (EFI_PCI_IO_PRIVATE_DATA));

+  if (Private == NULL) {

+    Status = EFI_OUT_OF_RESOURCES;

+    return Status;

+  }

+

+  Private->Signature              = EFI_PCI_IO_PRIVATE_DATA_SIGNATURE;  // Fill in signature

+  Private->RootBridge.Signature   = PCI_ROOT_BRIDGE_SIGNATURE;          // Fake Root Bridge structure needs a signature too

+  Private->RootBridge.MemoryStart = MemoryStart; // Get the USB capability register base

+  Private->Segment                = 0;                                  // Default to segment zero

+

+  // Calculate the total size of the USB controller (OHCI + EHCI).

+  Private->RootBridge.MemorySize = MemorySize; //CapabilityLength + (HOST_CONTROLLER_OPERATION_REG_SIZE + ((4 * PhysicalPorts) - 1));

+

+  // Create fake PCI config space: OHCI + EHCI

+  Private->ConfigSpace = AllocateZeroPool (sizeof (PCI_TYPE00));

+  if (Private->ConfigSpace == NULL) {

+    Status = EFI_OUT_OF_RESOURCES;

+    FreePool (Private);

+    return Status;

+  }

+

+  //

+  // Configure PCI config space: OHCI + EHCI

+  //

+  Private->ConfigSpace->Hdr.VendorId = 0xFFFF; // Invalid vendor Id as it is not an actual device.

+  Private->ConfigSpace->Hdr.DeviceId = 0x0000; // Not relevant as the vendor id is not valid.

+  Private->ConfigSpace->Hdr.ClassCode[0] = ClassCode1;

+  Private->ConfigSpace->Hdr.ClassCode[1] = ClassCode2;

+  Private->ConfigSpace->Hdr.ClassCode[2] = ClassCode3;

+  Private->ConfigSpace->Device.Bar[0] = MemoryStart;

+

+  Handle = NULL;

+

+  // Unique device path.

+  CopyMem (&Private->DevicePath, &PciIoDevicePathTemplate, sizeof (PciIoDevicePathTemplate));

+  Private->DevicePath.AcpiDevicePath.UID = 0;

+  Private->DevicePath.PciDevicePath.Device = DeviceId;

+

+  // Copy protocol structure

+  CopyMem (&Private->PciIoProtocol, &PciIoTemplate, sizeof (PciIoTemplate));

+

+  Status = gBS->InstallMultipleProtocolInterfaces (&Handle,

+                                                  &gEfiPciIoProtocolGuid,       &Private->PciIoProtocol,

+                                                  &gEfiDevicePathProtocolGuid,  &Private->DevicePath,

+                                                  NULL);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "PciEmulationEntryPoint InstallMultipleProtocolInterfaces () failed.\n"));

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+PciEmulationEntryPoint (

+  VOID

+  )

+{

+  EFI_STATUS              Status;

+

+  Status = PciInstallDevice (0, FixedPcdGet32 (PcdSynopsysUsbOhciBaseAddress), SIZE_64KB, PCI_IF_OHCI, PCI_CLASS_SERIAL_USB, PCI_CLASS_SERIAL);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "PciEmulation: failed to install OHCI device.\n"));

+  }

+

+  Status = PciInstallDevice (1, FixedPcdGet32 (PcdSynopsysUsbEhciBaseAddress), SIZE_64KB, PCI_IF_EHCI, PCI_CLASS_SERIAL_USB, PCI_CLASS_SERIAL);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "PciEmulation: failed to install EHCI device.\n"));

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciEmulation.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciEmulation.h
new file mode 100644
index 0000000..de2855d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciEmulation.h
@@ -0,0 +1,284 @@
+/** @file

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.<BR>

+

+  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 _PCI_ROOT_BRIDGE_H_

+#define _PCI_ROOT_BRIDGE_H_

+

+#include <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DxeServicesTableLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PciLib.h>

+#include <Library/UefiLib.h>

+#include <Library/DmaLib.h>

+

+#include <Protocol/EmbeddedExternalDevice.h>

+#include <Protocol/DevicePath.h>

+#include <Protocol/PciIo.h>

+#include <Protocol/PciRootBridgeIo.h>

+#include <Protocol/PciHostBridgeResourceAllocation.h>

+

+#include <IndustryStandard/Pci23.h>

+

+#include "ArmJunoDxeInternal.h"

+

+#define EFI_RESOURCE_NONEXISTENT  0xFFFFFFFFFFFFFFFFULL

+#define EFI_RESOURCE_LESS         0xFFFFFFFFFFFFFFFEULL

+#define EFI_RESOURCE_SATISFIED    0x0000000000000000ULL

+

+

+typedef struct {

+  ACPI_HID_DEVICE_PATH      AcpiDevicePath;

+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;

+} EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;

+

+

+#define ACPI_CONFIG_IO    0

+#define ACPI_CONFIG_MMIO  1

+#define ACPI_CONFIG_BUS   2

+

+typedef struct {

+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR Desc[3];

+  EFI_ACPI_END_TAG_DESCRIPTOR       EndDesc;

+} ACPI_CONFIG_INFO;

+

+

+#define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('P', 'c', 'i', 'F')

+

+typedef struct {

+  UINT32                                            Signature;

+  EFI_HANDLE                                        Handle;

+  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL                   Io;

+  EFI_PCI_ROOT_BRIDGE_DEVICE_PATH                   DevicePath;

+

+  UINT8   StartBus;

+  UINT8   EndBus;

+  UINT16  Type;

+  UINT32  MemoryStart;

+  UINT32  MemorySize;

+  UINTN   IoOffset;

+  UINT32  IoStart;

+  UINT32  IoSize;

+  UINT64  PciAttributes;

+

+  ACPI_CONFIG_INFO  *Config;

+

+} PCI_ROOT_BRIDGE;

+

+

+#define INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(a) CR (a, PCI_ROOT_BRIDGE, Io, PCI_ROOT_BRIDGE_SIGNATURE)

+

+

+typedef union {

+  UINT8   volatile  *Buffer;

+  UINT8   volatile  *Ui8;

+  UINT16  volatile  *Ui16;

+  UINT32  volatile  *Ui32;

+  UINT64  volatile  *Ui64;

+  UINTN   volatile  Ui;

+} PTR;

+

+

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoPollMem (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN  UINT64                                 Address,

+  IN  UINT64                                 Mask,

+  IN  UINT64                                 Value,

+  IN  UINT64                                 Delay,

+  OUT UINT64                                 *Result

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoPollIo (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN  UINT64                                 Address,

+  IN  UINT64                                 Mask,

+  IN  UINT64                                 Value,

+  IN  UINT64                                 Delay,

+  OUT UINT64                                 *Result

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoMemRead (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoMemWrite (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoIoRead (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 UserAddress,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *UserBuffer

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoIoWrite (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 UserAddress,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *UserBuffer

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoCopyMem (

+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN UINT64                                 DestAddress,

+  IN UINT64                                 SrcAddress,

+  IN UINTN                                  Count

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoPciRead (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoPciWrite (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoMap (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL            *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION  Operation,

+  IN     VOID                                       *HostAddress,

+  IN OUT UINTN                                      *NumberOfBytes,

+  OUT    EFI_PHYSICAL_ADDRESS                       *DeviceAddress,

+  OUT    VOID                                       **Mapping

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoUnmap (

+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *This,

+  IN VOID                             *Mapping

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoAllocateBuffer (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *This,

+  IN  EFI_ALLOCATE_TYPE                Type,

+  IN  EFI_MEMORY_TYPE                  MemoryType,

+  IN  UINTN                            Pages,

+  OUT VOID                             **HostAddress,

+  IN  UINT64                           Attributes

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoFreeBuffer (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *This,

+  IN  UINTN                            Pages,

+  OUT VOID                             *HostAddress

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoFlush (

+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *This

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoGetAttributes (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *This,

+  OUT UINT64                           *Supported,

+  OUT UINT64                           *Attributes

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoSetAttributes (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *This,

+  IN     UINT64                           Attributes,

+  IN OUT UINT64                           *ResourceBase,

+  IN OUT UINT64                           *ResourceLength

+  );

+

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoConfiguration (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *This,

+  OUT VOID                             **Resources

+  );

+

+//

+// Private Function Prototypes

+//

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoMemRW (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN  UINTN                                  Count,

+  IN  BOOLEAN                                InStrideFlag,

+  IN  PTR                                    In,

+  IN  BOOLEAN                                OutStrideFlag,

+  OUT PTR                                    Out

+  );

+

+BOOLEAN

+PciIoMemAddressValid (

+  IN EFI_PCI_IO_PROTOCOL  *This,

+  IN UINT64               Address

+  );

+

+EFI_STATUS

+EmulatePciIoForEhci (

+  INTN    MvPciIfMaxIf

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciRootBridgeIo.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciRootBridgeIo.c
new file mode 100644
index 0000000..f1eacef
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/PciRootBridgeIo.c
@@ -0,0 +1,299 @@
+/** @file

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+

+  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 "PciEmulation.h"

+

+BOOLEAN

+PciRootBridgeMemAddressValid (

+  IN PCI_ROOT_BRIDGE  *Private,

+  IN UINT64           Address

+  )

+{

+  if ((Address >= Private->MemoryStart) && (Address < (Private->MemoryStart + Private->MemorySize))) {

+    return TRUE;

+  }

+

+  return FALSE;

+}

+

+

+EFI_STATUS

+PciRootBridgeIoMemRW (

+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN  UINTN                                  Count,

+  IN  BOOLEAN                                InStrideFlag,

+  IN  PTR                                    In,

+  IN  BOOLEAN                                OutStrideFlag,

+  OUT PTR                                    Out

+  )

+{

+  UINTN  Stride;

+  UINTN  InStride;

+  UINTN  OutStride;

+

+  Width     = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (Width & 0x03);

+  Stride    = (UINTN)1 << Width;

+  InStride  = InStrideFlag  ? Stride : 0;

+  OutStride = OutStrideFlag ? Stride : 0;

+

+  //

+  // Loop for each iteration and move the data

+  //

+  switch (Width) {

+  case EfiPciWidthUint8:

+    for (;Count > 0; Count--, In.Buffer += InStride, Out.Buffer += OutStride) {

+      *In.Ui8 = *Out.Ui8;

+    }

+    break;

+  case EfiPciWidthUint16:

+    for (;Count > 0; Count--, In.Buffer += InStride, Out.Buffer += OutStride) {

+      *In.Ui16 = *Out.Ui16;

+    }

+    break;

+  case EfiPciWidthUint32:

+    for (;Count > 0; Count--, In.Buffer += InStride, Out.Buffer += OutStride) {

+      *In.Ui32 = *Out.Ui32;

+    }

+    break;

+  default:

+    return EFI_INVALID_PARAMETER;

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+PciRootBridgeIoPciRW (

+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN BOOLEAN                                Write,

+  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN UINT64                                 UserAddress,

+  IN UINTN                                  Count,

+  IN OUT VOID                               *UserBuffer

+  )

+{

+  return EFI_SUCCESS;

+}

+

+/**

+  Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.

+

+  @param  This                  A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.

+  @param  Width                 Signifies the width of the memory operations.

+  @param  Address               The base address of the memory operations.

+  @param  Count                 The number of memory operations to perform.

+  @param  Buffer                For read operations, the destination buffer to store the results. For write

+                                operations, the source buffer to write data from.

+

+  @retval EFI_SUCCESS           The data was read from or written to the PCI root bridge.

+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.

+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.

+

+**/

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoMemRead (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  )

+{

+  PCI_ROOT_BRIDGE   *Private;

+  UINTN             AlignMask;

+  PTR               In;

+  PTR               Out;

+

+  if ( Buffer == NULL ) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Private = INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This);

+

+  if (!PciRootBridgeMemAddressValid (Private, Address)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  AlignMask = (1 << (Width & 0x03)) - 1;

+  if (Address & AlignMask) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  In.Buffer  = Buffer;

+  Out.Buffer = (VOID *)(UINTN) Address;

+

+  switch (Width) {

+  case EfiPciWidthUint8:

+  case EfiPciWidthUint16:

+  case EfiPciWidthUint32:

+  case EfiPciWidthUint64:

+    return PciRootBridgeIoMemRW (Width, Count, TRUE, In, TRUE, Out);

+

+  case EfiPciWidthFifoUint8:

+  case EfiPciWidthFifoUint16:

+  case EfiPciWidthFifoUint32:

+  case EfiPciWidthFifoUint64:

+    return PciRootBridgeIoMemRW (Width, Count, TRUE, In, FALSE, Out);

+

+  case EfiPciWidthFillUint8:

+  case EfiPciWidthFillUint16:

+  case EfiPciWidthFillUint32:

+  case EfiPciWidthFillUint64:

+    return PciRootBridgeIoMemRW (Width, Count, FALSE, In, TRUE, Out);

+

+  default:

+    break;

+  }

+

+  return EFI_INVALID_PARAMETER;

+}

+

+/**

+  Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.

+

+  @param  This                  A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.

+  @param  Width                 Signifies the width of the memory operations.

+  @param  Address               The base address of the memory operations.

+  @param  Count                 The number of memory operations to perform.

+  @param  Buffer                For read operations, the destination buffer to store the results. For write

+                                operations, the source buffer to write data from.

+

+  @retval EFI_SUCCESS           The data was read from or written to the PCI root bridge.

+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.

+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.

+

+**/

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoMemWrite (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  )

+{

+  PCI_ROOT_BRIDGE *Private;

+  UINTN  AlignMask;

+  PTR    In;

+  PTR    Out;

+

+  if ( Buffer == NULL ) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Private = INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This);

+

+  if (!PciRootBridgeMemAddressValid (Private, Address)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  AlignMask = (1 << (Width & 0x03)) - 1;

+  if (Address & AlignMask) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  In.Buffer  = (VOID *)(UINTN) Address;

+  Out.Buffer = Buffer;

+

+  switch (Width) {

+  case EfiPciWidthUint8:

+  case EfiPciWidthUint16:

+  case EfiPciWidthUint32:

+  case EfiPciWidthUint64:

+    return PciRootBridgeIoMemRW (Width, Count, TRUE, In, TRUE, Out);

+

+  case EfiPciWidthFifoUint8:

+  case EfiPciWidthFifoUint16:

+  case EfiPciWidthFifoUint32:

+  case EfiPciWidthFifoUint64:

+    return PciRootBridgeIoMemRW (Width, Count, FALSE, In, TRUE, Out);

+

+  case EfiPciWidthFillUint8:

+  case EfiPciWidthFillUint16:

+  case EfiPciWidthFillUint32:

+  case EfiPciWidthFillUint64:

+    return PciRootBridgeIoMemRW (Width, Count, TRUE, In, FALSE, Out);

+

+  default:

+    break;

+  }

+

+  return EFI_INVALID_PARAMETER;

+}

+

+/**

+  Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.

+

+  @param  This                  A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.

+  @param  Width                 Signifies the width of the memory operations.

+  @param  Address               The base address of the memory operations.

+  @param  Count                 The number of memory operations to perform.

+  @param  Buffer                For read operations, the destination buffer to store the results. For write

+                                operations, the source buffer to write data from.

+

+  @retval EFI_SUCCESS           The data was read from or written to the PCI root bridge.

+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.

+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.

+

+**/

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoPciRead (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  )

+{

+  if (Buffer == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  return PciRootBridgeIoPciRW (This, FALSE, Width, Address, Count, Buffer);

+}

+

+/**

+  Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.

+

+  @param  This                  A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.

+  @param  Width                 Signifies the width of the memory operations.

+  @param  Address               The base address of the memory operations.

+  @param  Count                 The number of memory operations to perform.

+  @param  Buffer                For read operations, the destination buffer to store the results. For write

+                                operations, the source buffer to write data from.

+

+  @retval EFI_SUCCESS           The data was read from or written to the PCI root bridge.

+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.

+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.

+

+**/

+EFI_STATUS

+EFIAPI

+PciRootBridgeIoPciWrite (

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,

+  IN     EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,

+  IN     UINT64                                 Address,

+  IN     UINTN                                  Count,

+  IN OUT VOID                                   *Buffer

+  )

+{

+  if (Buffer == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  return PciRootBridgeIoPciRW (This, TRUE, Width, Address, Count, Buffer);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Include/ArmPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Include/ArmPlatform.h
new file mode 100644
index 0000000..badd7a6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Include/ArmPlatform.h
@@ -0,0 +1,83 @@
+/** @file

+*

+*  Copyright (c) 2013-2014, ARM 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.

+*

+**/

+

+#ifndef __ARM_JUNO_H__

+#define __ARM_JUNO_H__

+

+#include <VExpressMotherBoard.h>

+

+/***********************************************************************************

+// Platform Memory Map

+************************************************************************************/

+

+// Motherboard Peripheral and On-chip peripheral

+#define ARM_VE_BOARD_PERIPH_BASE              0x1C010000

+

+// NOR Flash 0

+#define ARM_VE_SMB_NOR0_BASE                  0x08000000

+#define ARM_VE_SMB_NOR0_SZ                    SIZE_64MB

+

+// Off-Chip peripherals (USB, Ethernet, VRAM)

+#define ARM_VE_SMB_PERIPH_BASE                0x18000000

+#define ARM_VE_SMB_PERIPH_SZ                  (SIZE_64MB + SIZE_2MB)

+

+// On-Chip non-secure ROM

+#define ARM_JUNO_NON_SECURE_ROM_BASE          0x1F000000

+#define ARM_JUNO_NON_SECURE_ROM_SZ            SIZE_16MB

+

+// On-Chip Peripherals

+#define ARM_JUNO_PERIPHERALS_BASE             0x20000000

+#define ARM_JUNO_PERIPHERALS_SZ               0x0E000000

+

+// On-Chip non-secure SRAM

+#define ARM_JUNO_NON_SECURE_SRAM_BASE         0x2E000000

+#define ARM_JUNO_NON_SECURE_SRAM_SZ           SIZE_16MB

+

+// SOC peripherals (HDLCD, UART, I2C, I2S, USB, SMC-PL354, etc)

+#define ARM_JUNO_SOC_PERIPHERALS_BASE         0x7FF50000

+#define ARM_JUNO_SOC_PERIPHERALS_SZ           (SIZE_64KB * 9)

+

+// 6GB of DRAM from the 64bit address space

+#define ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE     0x0880000000

+#define ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ       (SIZE_2GB + SIZE_4GB)

+

+//

+// ACPI table information used to initialize tables.

+//

+#define EFI_ACPI_ARM_OEM_ID           'A','R','M','L','T','D'   // OEMID 6 bytes long

+#define EFI_ACPI_ARM_OEM_TABLE_ID     SIGNATURE_64('A','R','M','-','J','U','N','O') // OEM table id 8 bytes long

+#define EFI_ACPI_ARM_OEM_REVISION     0x20140727

+#define EFI_ACPI_ARM_CREATOR_ID       SIGNATURE_32('A','R','M',' ')

+#define EFI_ACPI_ARM_CREATOR_REVISION 0x00000099

+

+// A macro to initialise the common header part of EFI ACPI tables as defined by

+// EFI_ACPI_DESCRIPTION_HEADER structure.

+#define ARM_ACPI_HEADER(Signature, Type, Revision) {              \

+    Signature,                      /* UINT32  Signature */       \

+    sizeof (Type),                  /* UINT32  Length */          \

+    Revision,                       /* UINT8   Revision */        \

+    0,                              /* UINT8   Checksum */        \

+    { EFI_ACPI_ARM_OEM_ID },        /* UINT8   OemId[6] */        \

+    EFI_ACPI_ARM_OEM_TABLE_ID,      /* UINT64  OemTableId */      \

+    EFI_ACPI_ARM_OEM_REVISION,      /* UINT32  OemRevision */     \

+    EFI_ACPI_ARM_CREATOR_ID,        /* UINT32  CreatorId */       \

+    EFI_ACPI_ARM_CREATOR_REVISION   /* UINT32  CreatorRevision */ \

+  }

+

+#define JUNO_WATCHDOG_COUNT  2

+

+// Define if the exported ACPI Tables are based on ACPI 5.0 spec or latest

+//#define ARM_JUNO_ACPI_5_0

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/AArch64/ArmJunoHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/AArch64/ArmJunoHelper.S
new file mode 100644
index 0000000..73b249c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/AArch64/ArmJunoHelper.S
@@ -0,0 +1,75 @@
+/** @file

+*

+*  Copyright (c) 2013-2014, ARM 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.

+*

+**/

+

+#include <AsmMacroIoLibV8.h>

+#include <Library/ArmLib.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+

+

+PrimaryCoreMpid:  .word    0x0

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+// With this function: CorePos = (ClusterId * 2) + CoreId

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   x1, x0, #ARM_CORE_MASK

+  and   x0, x0, #ARM_CLUSTER_MASK

+  add   x0, x1, x0, LSR #7

+  ret

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  ldr   x0, =PrimaryCoreMpid

+  ldrh  w0, [x0]

+  ret

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, x1)

+  ldrh  w1, [x1]

+  and   x0, x0, x1

+

+  ldr   x1, =PrimaryCoreMpid

+  ldrh  w1, [x1]

+

+  cmp   w0, w1

+  mov   x0, #1

+  mov   x1, #0

+  csel  x0, x0, x1, eq

+  ret

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  // The trusted firmware passes the primary CPU MPID through x0 register.

+  // Save it in a variable.

+  ldr  x1, =PrimaryCoreMpid

+  str  w0, [x1]

+  ret

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/Arm/ArmJunoHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/Arm/ArmJunoHelper.S
new file mode 100644
index 0000000..2efb545
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/Arm/ArmJunoHelper.S
@@ -0,0 +1,105 @@
+/** @file

+*

+*  Copyright (c) 2013-2014, ARM 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.

+*

+**/

+

+#include <AsmMacroIoLibV8.h>

+#include <Library/ArmLib.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+

+

+PrimaryCoreMpid:  .word    0x0

+

+//

+// Return the core position from the value of its MpId register

+//

+// This function returns the core position from the position 0 in the processor.

+// This function might be called from assembler before any stack is set.

+//

+// @return   Return the core position

+//

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+// With this function: CorePos = (ClusterId * 2) + CoreId

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+

+//

+// Return the MpId of the primary core

+//

+// This function returns the MpId of the primary core.

+// This function might be called from assembler before any stack is set.

+//

+// @return   Return the MpId of the primary core

+//

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  ldr   r0, =PrimaryCoreMpid

+  ldr   r0, [r0]

+  bx    lr

+

+//

+// Return a non-zero value if the callee is the primary core

+//

+// This function returns a non-zero value if the callee is the primary core.

+// The primary core is the core responsible to initialize the hardware and run UEFI.

+// This function might be called from assembler before any stack is set.

+//

+//  @return   Return a non-zero value if the callee is the primary core.

+//

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+

+  ldr   r1, =PrimaryCoreMpid

+  ldr   r1, [r1]

+

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+

+//

+// First platform specific function to be called in the PEI phase

+//

+// This function is actually the first function called by the PrePi

+// or PrePeiCore modules. It allows to retrieve arguments passed to

+// the UEFI firmware through the CPU registers.

+//

+ASM_PFX(ArmPlatformPeiBootAction):

+  // The trusted firmware passes the primary CPU MPID through r0 register.

+  // Save it in a variable.

+  ldr  r1, =PrimaryCoreMpid

+  str  r0, [r1]

+  bx   lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJuno.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJuno.c
new file mode 100644
index 0000000..3be26d3
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJuno.c
@@ -0,0 +1,163 @@
+/** @file

+*

+*  Copyright (c) 2013-2014, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+#include <ArmPlatform.h>

+

+ARM_CORE_INFO mJunoInfoTable[] = {

+  {

+    // Cluster 0, Core 0

+    0x0, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 1

+    0x0, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 0

+    0x1, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 1

+    0x1, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 2

+    0x1, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 3

+    0x1, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  }

+};

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+  @return   Return the current Boot Mode of the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  return BOOT_WITH_FULL_CONFIGURATION;

+}

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+}

+

+EFI_STATUS

+PrePeiCoreGetMpCoreInfo (

+  OUT UINTN                   *CoreCount,

+  OUT ARM_CORE_INFO           **ArmCoreTable

+  )

+{

+  // Only support one cluster

+  *CoreCount    = sizeof(mJunoInfoTable) / sizeof(ARM_CORE_INFO);

+  *ArmCoreTable = mJunoInfoTable;

+  return EFI_SUCCESS;

+}

+

+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore

+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;

+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };

+

+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &mArmMpCoreInfoPpiGuid,

+    &mMpCoreInfoPpi

+  }

+};

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  *PpiListSize = sizeof(gPlatformPpiTable);

+  *PpiList = gPlatformPpiTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoLib.inf
new file mode 100644
index 0000000..b677e9d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoLib.inf
@@ -0,0 +1,54 @@
+#

+#  Copyright (c) 2013-2014, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmJunoLib

+  FILE_GUID                      = 87c525cd-e1a2-469e-994c-c28cd0c7bd0d

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmJunoPkg/ArmJuno.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  HobLib

+  MemoryAllocationLib

+  SerialPortLib

+

+[Sources.common]

+  ArmJuno.c

+  ArmJunoMem.c

+

+[Sources.AARCH64]

+  AArch64/ArmJunoHelper.S

+

+[Sources.ARM]

+  Arm/ArmJunoHelper.S     | GCC

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoMem.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoMem.c
new file mode 100644
index 0000000..bc725df
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoMem.c
@@ -0,0 +1,144 @@
+/** @file

+*

+*  Copyright (c) 2013-2014, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <ArmPlatform.h>

+

+// The total number of descriptors, including the final "end-of-table" descriptor.

+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 12

+

+// DDR attributes

+#define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK

+#define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;

+  UINTN                         Index = 0;

+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;

+  EFI_RESOURCE_ATTRIBUTE_TYPE   ResourceAttributes;

+

+  ASSERT (VirtualMemoryMap != NULL);

+

+  //

+  // Declared the additional 6GB of memory

+  //

+  ResourceAttributes =

+      EFI_RESOURCE_ATTRIBUTE_PRESENT |

+      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |

+      EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_TESTED;

+

+  BuildResourceDescriptorHob (

+    EFI_RESOURCE_SYSTEM_MEMORY,

+    ResourceAttributes,

+    ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE,

+    ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ);

+

+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));

+  if (VirtualMemoryTable == NULL) {

+      return;

+  }

+

+  if (FeaturePcdGet(PcdCacheEnable) == TRUE) {

+      CacheAttributes = DDR_ATTRIBUTES_CACHED;

+  } else {

+      CacheAttributes = DDR_ATTRIBUTES_UNCACHED;

+  }

+

+  // SMB CS0 - NOR0 Flash

+  VirtualMemoryTable[Index].PhysicalBase    = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].Length          = SIZE_256KB * 255;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+  // Environment Variables region

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SMB_NOR0_BASE + (SIZE_256KB * 255);

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_NOR0_BASE + (SIZE_256KB * 255);

+  VirtualMemoryTable[Index].Length          = SIZE_64KB * 4;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS2 & CS3 - Off-chip (motherboard) peripherals

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_SMB_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // Juno OnChip non-secure ROM

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_JUNO_NON_SECURE_ROM_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_JUNO_NON_SECURE_ROM_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_JUNO_NON_SECURE_ROM_SZ;

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+

+  // Juno OnChip peripherals

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_JUNO_PERIPHERALS_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_JUNO_PERIPHERALS_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_JUNO_PERIPHERALS_SZ;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // Juno OnChip non-secure SRAM

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_JUNO_NON_SECURE_SRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_JUNO_NON_SECURE_SRAM_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_JUNO_NON_SECURE_SRAM_SZ;

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+

+  // Juno SOC peripherals

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_JUNO_SOC_PERIPHERALS_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_JUNO_SOC_PERIPHERALS_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_JUNO_SOC_PERIPHERALS_SZ;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // DDR - 2GB

+  VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdSystemMemoryBase);

+  VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdSystemMemoryBase);

+  VirtualMemoryTable[Index].Length          = PcdGet64 (PcdSystemMemorySize);

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+

+  // DDR - 6GB

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ;

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+

+  // End of Table

+  VirtualMemoryTable[++Index].PhysicalBase  = 0;

+  VirtualMemoryTable[Index].VirtualBase     = 0;

+  VirtualMemoryTable[Index].Length          = 0;

+  VirtualMemoryTable[Index].Attributes      = (ARM_MEMORY_REGION_ATTRIBUTES)0;

+

+  ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);

+

+  *VirtualMemoryMap = VirtualMemoryTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/NorFlashJunoLib/NorFlashJuno.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/NorFlashJunoLib/NorFlashJuno.c
new file mode 100644
index 0000000..b31b963
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/NorFlashJunoLib/NorFlashJuno.c
@@ -0,0 +1,68 @@
+/** @file

+

+ Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+

+ 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 <PiDxe.h>

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/NorFlashPlatformLib.h>

+#include <ArmPlatform.h>

+

+NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {

+  {

+    ARM_VE_SMB_NOR0_BASE,

+    ARM_VE_SMB_NOR0_BASE,

+    SIZE_256KB * 255,

+    SIZE_256KB,

+    {0xE7223039, 0x5836, 0x41E1, { 0xB5, 0x42, 0xD7, 0xEC, 0x73, 0x6C, 0x5E, 0x59} }

+  },

+  {

+    ARM_VE_SMB_NOR0_BASE,

+    ARM_VE_SMB_NOR0_BASE + SIZE_256KB * 255,

+    SIZE_64KB * 4,

+    SIZE_64KB,

+    {0x02118005, 0x9DA7, 0x443A, { 0x92, 0xD5, 0x78, 0x1F, 0x02, 0x2A, 0xED, 0xBB } }

+  },

+};

+

+EFI_STATUS

+NorFlashPlatformInitialization (

+  VOID

+  )

+{

+  // Everything seems ok so far, so now we need to disable the platform-specific

+  // flash write protection for Versatile Express

+  if ((MmioRead32 (ARM_VE_SYS_FLASH) & 0x1) == 0) {

+    // Writing to NOR FLASH is disabled, so enable it

+    MmioWrite32 (ARM_VE_SYS_FLASH, 1);

+    DEBUG((DEBUG_BLKIO, "NorFlashPlatformInitialization: informational - Had to enable HSYS_FLASH flag.\n" ));

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+NorFlashPlatformGetDevices (

+  OUT NOR_FLASH_DESCRIPTION   **NorFlashDevices,

+  OUT UINT32                  *Count

+  )

+{

+  if ((NorFlashDevices == NULL) || (Count == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *NorFlashDevices = mNorFlashDevices;

+  *Count = sizeof (mNorFlashDevices) / sizeof (NOR_FLASH_DESCRIPTION);

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/NorFlashJunoLib/NorFlashJunoLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/NorFlashJunoLib/NorFlashJunoLib.inf
new file mode 100644
index 0000000..6b13635
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Library/NorFlashJunoLib/NorFlashJunoLib.inf
@@ -0,0 +1,32 @@
+#/** @file

+#

+#  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = NorFlashJunoLib

+  FILE_GUID                      = 3eb6cbc4-ce95-11e2-b1bd-00241d0c1ba8

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = NorFlashPlatformLib

+

+[Sources.common]

+  NorFlashJuno.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  IoLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Makefile b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Makefile
new file mode 100644
index 0000000..71828f3
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmJunoPkg/Makefile
@@ -0,0 +1,89 @@
+#
+#  Copyright (c) 2013-2014, ARM 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.
+#
+
+# Define the following variables to specify an alternative toolchain to the one located in your PATH:
+# - RVCT_TOOLS_PATH: for RVCT and RVCTLINUX toolchains
+# - ARMGCC_TOOLS_PATH: for ARMGCC toolchain
+# - ARMLINUXGCC_TOOLS_PATH: for ARMLINUXGCC
+
+EDK2_TOOLCHAIN ?= GCC49
+GCC49_AARCH64_PREFIX ?= aarch64-none-elf-
+EDK2_ARCH ?= AARCH64
+EDK2_BUILD ?= DEBUG
+EDK2_DSC = ArmPlatformPkg/ArmJunoPkg/ArmJuno.dsc
+DEST_BIN_ROOT ?=
+
+ifeq ($(EDK2_DSC),"")
+  $(error The Makefile macro 'EDK2_DSC' must be defined with an EDK2 DSC file.)
+endif
+
+ifeq ("$(OS)","Windows_NT")
+export WORKSPACE?=$(PWD)
+export EDK_TOOLS_PATH ?= $(WORKSPACE)\BaseTools
+else
+export WORKSPACE?=$(PWD)
+endif
+
+# Define the destination of the Firmware Image Package (FIP) if not defined
+ifndef JUNO_FIP
+  ifdef DEST_BIN_ROOT
+    JUNO_FIP=$(DEST_BIN_ROOT)/fip.bin
+  else
+    JUNO_FIP=fip.bin
+  endif
+endif
+
+SHELL := /bin/bash
+SILENT ?= @
+ECHO ?= echo
+MAKE ?= make -i -k
+RM ?= rm -f
+CP ?= cp
+
+.PHONY: all clean
+
+EDK2_CONF = Conf/BuildEnv.sh Conf/build_rule.txt Conf/target.txt Conf/tools_def.txt
+
+all: $(EDK2_CONF)
+ifeq ("$(OS)","Windows_NT")
+	build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS)
+else
+	. ./edksetup.sh; GCC49_AARCH64_PREFIX=$(GCC49_AARCH64_PREFIX) build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS)
+endif
+ifeq ("$(OS)","Windows_NT")
+	$(SILENT)$(ECHO) "Warning: The UEFI Firmware must be added to the Firmware Image Package (FIP)."
+else
+	$(SILENT)which fip_create ; \
+	if [ $$? -ne 0 ]; then \
+		$(ECHO) "Warning: 'fip_create' tool is not in the PATH. The UEFI binary will not be added in the Firmware Image Package (FIP)."; \
+	else \
+		fip_create --bl33 $(WORKSPACE)/Build/ArmJuno/$(EDK2_BUILD)_$(EDK2_TOOLCHAIN)/FV/BL33_AP_UEFI.fd --dump $(JUNO_FIP); \
+	fi
+endif
+
+$(EDK2_CONF):
+ifeq ("$(OS)","Windows_NT")
+	copy $(EDK_TOOLS_PATH)\Conf\build_rule.template Conf\build_rule.txt
+	copy $(EDK_TOOLS_PATH)\Conf\FrameworkDatabase.template Conf\FrameworkDatabase.txt
+	copy $(EDK_TOOLS_PATH)\Conf\target.template Conf\target.txt
+	copy $(EDK_TOOLS_PATH)\Conf\tools_def.template Conf\tools_def.txt
+else
+	. ./edksetup.sh; $(MAKE) -C BaseTools
+endif
+
+clean:
+ifeq ("$(OS)","Windows_NT")
+	build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS) cleanall
+else
+	. ./edksetup.sh; build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS) cleanall; \
+	rm -Rf $(EDK2_CONF) Conf/.cache
+endif
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc
new file mode 100644
index 0000000..66a9797
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc
@@ -0,0 +1,369 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmPlatform

+  PLATFORM_GUID                  = 4fe82b83-9315-4ff3-8cc0-ab77ca93cb7f

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/$(PLATFORM_NAME)

+  SUPPORTED_ARCHITECTURES        = ARM|AARCH64

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmPlatformPkg-2ndstage.fdf

+

+[LibraryClasses.common]

+  ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf

+

+!if $(TARGET) == RELEASE

+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+!else

+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+#  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf

+!endif

+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf

+

+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf

+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf

+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf

+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf

+

+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf

+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf

+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf

+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf

+

+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf

+

+  #

+  # Assume everything is fixed at build

+  #

+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+

+  # 1/123 faster than Stm or Vstm version

+  #BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf

+  BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf

+

+  # ARM Architectural Libraries

+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf

+  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf

+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf

+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf

+  ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf

+  ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf

+  ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf

+

+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf

+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf

+  EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf

+  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf

+

+  # Networking Requirements for ArmPlatformPkg/Bds

+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf

+

+  # EBL Related Libraries

+  EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf

+  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf

+  EblAddExternalCommandLib|EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf

+  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf

+

+  #

+  # Uncomment (and comment out the next line) For RealView Debugger. The Standard IO window

+  # in the debugger will show load and unload commands for symbols. You can cut and paste this

+  # into the command window to load symbols. We should be able to use a script to do this, but

+  # the version of RVD I have does not support scripts accessing system memory.

+  #

+  #PeCoffExtraActionLib|ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf

+  PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf

+  #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf

+

+  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf

+  DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf

+

+  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf

+

+  # BDS Libraries

+  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf

+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf

+

+[LibraryClasses.ARM]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf

+

+[LibraryClasses.AARCH64]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf

+

+[LibraryClasses.common.SEC]

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+

+  ArmPlatformSecExtraActionLib|ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf

+  DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf

+

+  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf

+  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf

+  LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf

+  HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf

+  PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf

+  MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf

+

+[LibraryClasses.common.DXE_CORE]

+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf

+  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf

+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf

+

+[LibraryClasses.common.DXE_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf

+

+[LibraryClasses.common.UEFI_APPLICATION]

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+

+[LibraryClasses.common.UEFI_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+

+[LibraryClasses.common.DXE_RUNTIME_DRIVER]

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf

+

+[LibraryClasses.ARM, LibraryClasses.AARCH64]

+  #

+  # It is not possible to prevent the ARM compiler for generic intrinsic functions.

+  # This library provides the instrinsic functions generate by a given compiler.

+  # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.

+  #

+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

+

+  # Add support for GCC stack protector

+  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf

+

+[BuildOptions]

+  XCODE:*_*_ARM_PLATFORM_FLAGS == -arch armv7

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -march=armv7-a

+

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A8

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE

+

+  #

+  # Control what commands are supported from the UI

+  # Turn these on and off to add features or save size

+  #

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE

+

+  # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress

+  gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE

+

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Platform"

+

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmPlatform"

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000

+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF

+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1

+  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0

+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320

+

+  # DEBUG_ASSERT_ENABLED       0x01

+  # DEBUG_PRINT_ENABLED        0x02

+  # DEBUG_CODE_ENABLED         0x04

+  # CLEAR_MEMORY_ENABLED       0x08

+  # ASSERT_BREAKPOINT_ENABLED  0x10

+  # ASSERT_DEADLOOP_ENABLED    0x20

+!if $(TARGET) == RELEASE

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x21

+!else

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f

+!endif

+

+  #  DEBUG_INIT      0x00000001  // Initialization

+  #  DEBUG_WARN      0x00000002  // Warnings

+  #  DEBUG_LOAD      0x00000004  // Load events

+  #  DEBUG_FS        0x00000008  // EFI File system

+  #  DEBUG_POOL      0x00000010  // Alloc & Free's

+  #  DEBUG_PAGE      0x00000020  // Alloc & Free's

+  #  DEBUG_INFO      0x00000040  // Verbose

+  #  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers

+  #  DEBUG_VARIABLE  0x00000100  // Variable

+  #  DEBUG_BM        0x00000400  // Boot Manager

+  #  DEBUG_BLKIO     0x00001000  // BlkIo Driver

+  #  DEBUG_NET       0x00004000  // SNI Driver

+  #  DEBUG_UNDI      0x00010000  // UNDI Driver

+  #  DEBUG_LOADFILE  0x00020000  // UNDI Driver

+  #  DEBUG_EVENT     0x00080000  // Event messages

+  #  DEBUG_ERROR     0x80000000  // Error

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F

+

+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07

+

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000

+

+  #

+  # Optional feature to help prevent EFI memory map fragments

+  # Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob

+  # Values are in EFI Pages (4K). DXE Core will make sure that

+  # at least this much of each type of memory can be allocated

+  # from a single memory range. This way you only end up with

+  # maximum of two fragements for each type in the memory map

+  # (the memory used, and the free memory that was prereserved

+  # but not used).

+  #

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|50

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|20

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|20000

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000000000000

+

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # PEI Phase modules

+  #

+  ArmPlatformPkg/PrePi/PeiUniCore.inf

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

+  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  # Simple TextIn/TextOut for UEFI Terminal

+  EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf

+

+  #

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Application

+  #

+  EmbeddedPkg/Ebl/Ebl.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.fdf
new file mode 100644
index 0000000..aa86610
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.fdf
@@ -0,0 +1,260 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.ArmPlatform_EFI]

+BaseAddress   = 0xEC200000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x200

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00200000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

+  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  # Simple TextIn/TextOut for UEFI Terminal

+  INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf

+

+  #

+  # Semi-hosting filesystem (Required the Hardware Debugger to be connected)

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF EmbeddedPkg/Ebl/Ebl.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/PrePi/PeiUniCore.inf

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.ARM.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+# The AArch64 Vector Table requires a 2K alignment that is not supported by the FDF specification.

+# It is the reason 4K is used instead of 2K for the module alignment.

+[Rule.AARCH64.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 4K                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.dec b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.dec
new file mode 100644
index 0000000..e1653c7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.dec
@@ -0,0 +1,167 @@
+#/** @file

+#

+#  Copyright (c) 2011-2015, ARM 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              = 0x00010005

+  PACKAGE_NAME                   = ArmPlatformPkg

+  PACKAGE_GUID                   = 3308e0a0-1d94-11e0-915c-0002a5d5c51b

+  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]

+  gArmPlatformTokenSpaceGuid   = { 0x9c0aaed4, 0x74c5, 0x4043, { 0xb4, 0x17, 0xa3, 0x22, 0x38, 0x14, 0xce, 0x76 } }

+  #

+  # Following Guid must match FILE_GUID in MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  #

+  gVariableRuntimeDxeFileGuid = { 0xcbd2e4d5, 0x7068, 0x4ff5, { 0xb4, 0x62, 0x98, 0x22, 0xb4, 0xad, 0x8d, 0x60 } }

+

+  ## Include/Guid/ArmGlobalVariableHob.h

+  gArmGlobalVariableGuid      = { 0xc3253c90, 0xa24f, 0x4599, { 0xa6, 0x64, 0x1f, 0x88, 0x13, 0x77, 0x8f, 0xc9} }

+

+  gArmBootMonFsFileInfoGuid   = { 0x41e26b9c, 0xada6, 0x45b3, { 0x80, 0x8e, 0x23, 0x57, 0xa3, 0x5b, 0x60, 0xd6 } }

+

+  ## Include/Guid/ArmPlatformEvents.h

+  gArmPlatformUpdateFdtEventGuid = { 0xaffe115b, 0x8589, 0x456d, { 0xba, 0xb5, 0x8f, 0x2e, 0xda, 0x53, 0xae, 0xb7 } }

+

+[Ppis]

+  ## Include/Ppi/ArmGlobalVariable.h

+  gArmGlobalVariablePpiGuid = { 0xab1c1816, 0xd542, 0x4e6f, {0x9b, 0x1e, 0x8e, 0xcd, 0x92, 0x53, 0xe2, 0xe7} }

+

+[PcdsFeatureFlag.common]

+  # Set this PCD to TRUE to map NORFlash at 0x0. FALSE means the DRAM is mapped at 0x0.

+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping|FALSE|BOOLEAN|0x00000012

+

+  gArmPlatformTokenSpaceGuid.PcdStandalone|TRUE|BOOLEAN|0x00000001

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|FALSE|BOOLEAN|0x00000002

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|FALSE|BOOLEAN|0x00000004

+

+  gArmPlatformTokenSpaceGuid.PcdNorFlashCheckBlockLocked|FALSE|BOOLEAN|0x0000003C

+

+  # Disable the GOP controller on ExitBootServices(). By default the value is FALSE,

+  # we assume the OS will handle the FrameBuffer from the UEFI GOP information.

+  gArmPlatformTokenSpaceGuid.PcdGopDisableOnExitBootServices|FALSE|BOOLEAN|0x0000003D

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|1|UINT32|0x00000039

+  gArmPlatformTokenSpaceGuid.PcdClusterCount|1|UINT32|0x00000038

+

+  # Stack for CPU Cores in Secure Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0|UINT32|0x00000005

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x10000|UINT32|0x00000036

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecSecondaryStackSize|0x1000|UINT32|0x00000006

+

+  # Stack for CPU Cores in Non Secure Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0|UINT64|0x00000009

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x10000|UINT32|0x00000037

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize|0x1000|UINT32|0x0000000A

+

+  # Size of the region used by UEFI in permanent memory (Reserved 128MB by default)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x08000000|UINT32|0x00000015

+

+  # Size to reserve in the primary core stack for PEI Global Variables

+  #  = sizeof(UINTN) /* PcdPeiServicePtr or HobListPtr */

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize|0x4|UINT32|0x00000016

+  # PeiServicePtr and HobListPtr shares the same location in the PEI Global Variable list

+  # PeiServicePtr is only valid with PEI Core and HobListPtr only when the PEI Core is skipped.

+  gArmPlatformTokenSpaceGuid.PcdPeiServicePtrGlobalOffset|0x0|UINT32|0x00000017

+  gArmPlatformTokenSpaceGuid.PcdHobListPtrGlobalOffset|0x0|UINT32|0x00000018

+

+  # Size to reserve in the primary core stack for SEC Global Variables

+  gArmPlatformTokenSpaceGuid.PcdSecGlobalVariableSize|0x0|UINT32|0x00000031

+

+  # Boot Monitor FileSystem

+  gArmPlatformTokenSpaceGuid.PcdBootMonFsSupportedDevicePaths|L""|VOID*|0x0000003A

+

+  #

+  # ARM Primecells

+  #

+

+  ## SP804 DualTimer

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerFrequencyInMHz|1|UINT32|0x0000001D

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum|0|UINT32|0x0000001E

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase|0|UINT32|0x0000002A

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase|0|UINT32|0x0000002B

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase|0|UINT32|0x0000002C

+

+  ## SP805 Watchdog

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x0|UINT32|0x00000023

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz|32000|UINT32|0x00000021

+

+  ## PL011 UART

+  gArmPlatformTokenSpaceGuid.PL011UartClkInHz|24000000|UINT32|0x0000001F

+  gArmPlatformTokenSpaceGuid.PL011UartInteger|0|UINT32|0x00000020

+  gArmPlatformTokenSpaceGuid.PL011UartFractional|0|UINT32|0x0000002D

+

+  ## PL061 GPIO

+  gArmPlatformTokenSpaceGuid.PcdPL061GpioBase|0x0|UINT32|0x00000025

+

+  ## PL111 Lcd & HdLcd

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x0|UINT32|0x00000026

+  gArmPlatformTokenSpaceGuid.PcdArmHdLcdBase|0x0|UINT32|0x00000027

+

+  ## PL180 MCI

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x00000000|UINT32|0x00000028

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x00000000|UINT32|0x00000029

+

+  #

+  # BDS - Boot Manager

+  #

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Platform"|VOID*|0x00000019

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Default Boot Device"|VOID*|0x0000000C

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L""|VOID*|0x0000000D

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootInitrdPath|L""|VOID*|0x0000000E

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|L""|VOID*|0x000000F

+  gArmPlatformTokenSpaceGuid.PcdArmFastbootFlashLimit|L""|VOID*|0x0000003E

+  # PcdDefaultBootType define the type of the binary pointed by PcdDefaultBootDevicePath:

+  #  - 0 = an EFI application

+  #  - 1 = a Linux kernel with ATAG support

+  #  - 2 = a Linux kernel with FDT support

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|0|UINT32|0x00000010

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L""|VOID*|0x00000011

+

+  ## Timeout value for displaying progressing bar in before boot OS.

+  #  According to UEFI 2.0 spec, the default TimeOut should be 0xffff.

+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut|0xffff|UINT16|0x0000001A

+

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L""|VOID*|0x0000001B

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L""|VOID*|0x0000001C

+

+[PcdsFixedAtBuild.common,PcdsDynamic.common]

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x0|UINT32|0x00000024

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcPpmAccuracy|300000000|UINT32|0x00000022

+

+[PcdsFixedAtBuild.ARM]

+  # Stack for CPU Cores in Secure Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0|UINT32|0x00000007

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize|0x1000|UINT32|0x00000008

+

+[PcdsFixedAtBuild.AARCH64]

+  # The Secure World is only running in EL3. Only one set of stacks is needed for AArch64.

+  # The Secure stacks are described by PcdCPUCoresSecStackBase, PcdCPUCoreSecPrimaryStackSize

+  # and PcdCPUCoreSecSecondaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0|UINT32|0x00000007

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize|0x0|UINT32|0x00000008

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.dsc
new file mode 100644
index 0000000..81402da
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.dsc
@@ -0,0 +1,433 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmPlatform

+  PLATFORM_GUID                  = 4fe82b83-9315-4ff3-8cc0-ab77ca93cb7f

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/$(PLATFORM_NAME)

+  SUPPORTED_ARCHITECTURES        = ARM|AARCH64

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmPlatformPkg.fdf

+

+[LibraryClasses.common]

+  ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf

+

+!if $(TARGET) == RELEASE

+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+!else

+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+#  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf

+!endif

+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf

+

+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf

+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf

+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf

+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf

+

+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf

+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf

+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf

+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf

+

+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf

+

+  #

+  # Assume everything is fixed at build

+  #

+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+

+  # 1/123 faster than Stm or Vstm version

+  #BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf

+  BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf

+

+  # ARM Architectural Libraries

+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf

+  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf

+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf

+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf

+  ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf

+  ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf

+

+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf

+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf

+  EfiResetSystemLib|EmbeddedPkg/Library/TemplateResetSystemLib/TemplateResetSystemLib.inf

+  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf

+

+  # Networking Requirements for ArmPlatformPkg/Bds

+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf

+

+  # EBL Related Libraries

+  EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf

+  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf

+  EblAddExternalCommandLib|EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf

+  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf

+

+  #

+  # Uncomment (and comment out the next line) For RealView Debugger. The Standard IO window

+  # in the debugger will show load and unload commands for symbols. You can cut and paste this

+  # into the command window to load symbols. We should be able to use a script to do this, but

+  # the version of RVD I have does not support scripts accessing system memory.

+  #

+  #PeCoffExtraActionLib|ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf

+  PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf

+  #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf

+

+  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf

+  DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf

+

+  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf

+

+  # BDS Libraries

+  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf

+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf

+

+[LibraryClasses.ARM]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf

+

+[LibraryClasses.AARCH64]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf

+  ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmPlatformSecLib|ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.inf

+  ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullSec.inf

+  ArmTrustedMonitorLib|ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf

+

+  ArmPlatformSecExtraActionLib|ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf

+

+  DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf

+

+[LibraryClasses.ARM.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+

+[LibraryClasses.AARCH64.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf

+

+[LibraryClasses.common.PEI_CORE]

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+

+[LibraryClasses.common.PEIM]

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+  PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf

+

+[LibraryClasses.common.DXE_CORE]

+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf

+  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf

+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf

+

+[LibraryClasses.common.DXE_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf

+

+[LibraryClasses.common.UEFI_APPLICATION]

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+

+[LibraryClasses.common.UEFI_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+

+[LibraryClasses.common.DXE_RUNTIME_DRIVER]

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf

+

+[LibraryClasses.ARM, LibraryClasses.AARCH64]

+  #

+  # It is not possible to prevent the ARM compiler for generic intrinsic functions.

+  # This library provides the instrinsic functions generate by a given compiler.

+  # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.

+  #

+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

+

+  # Add support for GCC stack protector

+  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf

+

+[BuildOptions]

+  XCODE:*_*_ARM_PLATFORM_FLAGS == -arch armv7

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -march=armv7-a

+

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A8

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE

+

+  #

+  # Control what commands are supported from the UI

+  # Turn these on and off to add features or save size

+  #

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE

+

+  # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress

+  gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE

+

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Platform"

+

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmPlatform"

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000

+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF

+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1

+  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0

+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320

+

+  # DEBUG_ASSERT_ENABLED       0x01

+  # DEBUG_PRINT_ENABLED        0x02

+  # DEBUG_CODE_ENABLED         0x04

+  # CLEAR_MEMORY_ENABLED       0x08

+  # ASSERT_BREAKPOINT_ENABLED  0x10

+  # ASSERT_DEADLOOP_ENABLED    0x20

+!if $(TARGET) == RELEASE

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x21

+!else

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f

+!endif

+

+  #  DEBUG_INIT      0x00000001  // Initialization

+  #  DEBUG_WARN      0x00000002  // Warnings

+  #  DEBUG_LOAD      0x00000004  // Load events

+  #  DEBUG_FS        0x00000008  // EFI File system

+  #  DEBUG_POOL      0x00000010  // Alloc & Free's

+  #  DEBUG_PAGE      0x00000020  // Alloc & Free's

+  #  DEBUG_INFO      0x00000040  // Verbose

+  #  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers

+  #  DEBUG_VARIABLE  0x00000100  // Variable

+  #  DEBUG_BM        0x00000400  // Boot Manager

+  #  DEBUG_BLKIO     0x00001000  // BlkIo Driver

+  #  DEBUG_NET       0x00004000  // SNI Driver

+  #  DEBUG_UNDI      0x00010000  // UNDI Driver

+  #  DEBUG_LOADFILE  0x00020000  // UNDI Driver

+  #  DEBUG_EVENT     0x00080000  // Event messages

+  #  DEBUG_ERROR     0x80000000  // Error

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F

+

+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07

+

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000

+

+  #

+  # Optional feature to help prevent EFI memory map fragments

+  # Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob

+  # Values are in EFI Pages (4K). DXE Core will make sure that

+  # at least this much of each type of memory can be allocated

+  # from a single memory range. This way you only end up with

+  # maximum of two fragements for each type in the memory map

+  # (the memory used, and the free memory that was prereserved

+  # but not used).

+  #

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|50

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|20

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|20000

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000000000000

+

+  # Stacks for MPCores in Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0

+  # Stacks for MPCores in Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0

+  # Stacks for MPCores in Normal World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0

+

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

+  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  # Simple TextIn/TextOut for UEFI Terminal

+  EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Application

+  #

+  EmbeddedPkg/Ebl/Ebl.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.fdf
new file mode 100644
index 0000000..65f49bf
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmPlatformPkg.fdf
@@ -0,0 +1,317 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.Sec_ArmPlatform_EFI]

+BaseAddress   = 0xEC000000|gArmTokenSpaceGuid.PcdSecureFdBaseAddress  #The base address of the Secure FLASH Device.

+Size          = 0x00020000|gArmTokenSpaceGuid.PcdSecureFdSize         #The size in bytes of the Secure FLASH Device

+ErasePolarity = 1

+BlockSize     = 0x00002000

+NumBlocks     = 0x10

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00020000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+

+[FD.ArmPlatform_EFI]

+BaseAddress   = 0xEC200000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x200

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00200000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

+  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  # Simple TextIn/TextOut for UEFI Terminal

+  INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf

+

+  #

+  # Semi-hosting filesystem (Required the Hardware Debugger to be connected)

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF EmbeddedPkg/Ebl/Ebl.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.ARM.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+# The AArch64 Vector Table requires a 2K alignment that is not supported by the FDF specification.

+# It is the reason 4K is used instead of 2K for the module alignment.

+[Rule.AARCH64.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 4K                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-A8.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-A8.dsc
new file mode 100644
index 0000000..036e389
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-A8.dsc
@@ -0,0 +1,235 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmRealViewEbPkg

+  PLATFORM_GUID                  = F4C1AD3E-9D3E-4F61-8791-B3BB1C43D04C

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmRealViewEb-RTSM-A8

+  SUPPORTED_ARCHITECTURES        = ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-UniCore.fdf

+

+!include ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA8Lib/ArmCortexA8Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLibSec.inf

+

+[BuildOptions]

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A8 -I$(WORKSPACE)/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a8 -I$(WORKSPACE)/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform

+

+  XCODE:*_*_ARM_PLATFORM_FLAGS == -arch armv7 -I$(WORKSPACE)/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform

+

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+!ifdef EDK2_SKIP_PEICORE

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+  # Install Debugger Exception Handlers.

+  gArmTokenSpaceGuid.PcdDebuggerExceptionSupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM RealView Emulation Board"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmRealViewEb-A8"

+

+  #

+  # NV Storage PCDs. Use base of 0x43F00000 for NOR0

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x43F00000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00020000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x43F20000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00020000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x43F40000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00020000

+

+  # Stack for CPU Cores in Secure Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x4B000000

+  # Stack for CPU Cores in Secure Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0x4A000000

+  # Stack for CPU Cores in Non Secure Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x48000000

+

+  # System Memory (256MB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x70000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x10000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  #

+  # ARM PrimeCells

+  #

+

+  ## SP804 Timer

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|1000000

+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000        # expressed in 100ns units, 100,000 x 100 ns = 10,000,000 ns = 10 ms

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum|36

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase|0x10011000

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase|0x10011020

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase|0x10012020

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x10017000

+

+  ## PL111 Lcd

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x10020000

+

+  #

+  # ARM PL011 - Serial Terminal

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x10009000

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x10041000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x10040000

+

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef EDK2_SKIP_PEICORE

+  ArmPlatformPkg/PrePi/PeiUniCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-A9x2.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-A9x2.dsc
new file mode 100644
index 0000000..a7aec05
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-A9x2.dsc
@@ -0,0 +1,235 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmRealViewEb-RTSM-A9x2

+  PLATFORM_GUID                  = f6c2f4a0-2027-11e0-a2a1-0002a5d5c51b

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmRealViewEb-RTSM-A9x2

+  SUPPORTED_ARCHITECTURES        = ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-MPCore.fdf

+

+!include ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLibSec.inf

+

+[BuildOptions]

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A9 -I$(WORKSPACE)/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a9 -I$(WORKSPACE)/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform

+

+  XCODE:*_*_ARM_PLATFORM_FLAGS == -arch armv7 -I$(WORKSPACE)/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform

+

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+!ifdef EDK2_SKIP_PEICORE

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM RealView Emulation Board"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmRealViewEb-A9x2"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|2

+

+  #

+  # NV Storage PCDs. Use base of 0x43F00000 for NOR0

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x43F00000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00020000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x43F20000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00020000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x43F40000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00020000

+

+  # Stacks for MPCores in Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x4B000000

+  # Stacks for MPCores in Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0x4A000000

+  # Stacks for MPCores in Normal World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x48000000

+

+  # System Memory (256MB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x70000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x10000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  #

+  # ARM PrimeCells

+  #

+

+  ## SP804 Timer

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|1000000

+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000        # expressed in 100ns units, 100,000 x 100 ns = 10,000,000 ns = 10 ms

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum|33

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase|0x10011000

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase|0x10011020

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase|0x10012020

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x10017000

+

+  ## PL111 Lcd

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x10020000

+

+  #

+  # ARM PL011 - Serial Terminal

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x10009000

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x1F001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x1F000100

+

+  #

+  # ARM L2x0 PCDs

+  #

+  gArmTokenSpaceGuid.PcdL2x0ControllerBase|0x1F002000

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef EDK2_SKIP_PEICORE

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-MPCore.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-MPCore.fdf
new file mode 100644
index 0000000..8382d27
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-MPCore.fdf
@@ -0,0 +1,316 @@
+# FLASH layout file for ARM RealView EB.

+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+

+[FD.ArmRealViewEb_EFI]

+BaseAddress   = 0x40000000|gArmTokenSpaceGuid.PcdFdBaseAddress

+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize

+ErasePolarity = 1

+BlockSize     = 0x00010000

+NumBlocks     = 0x20

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00050000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+0x00050000|0x00150000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-UniCore.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-UniCore.fdf
new file mode 100644
index 0000000..d5b4eb6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb-RTSM-UniCore.fdf
@@ -0,0 +1,317 @@
+# FLASH layout file for ARM RealView EB.

+#

+# Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>

+# Copyright (c) 2011 - 2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+

+[FD.ArmRealViewEb_EFI]

+BaseAddress   = 0x40000000|gArmTokenSpaceGuid.PcdFdBaseAddress

+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize

+ErasePolarity = 1

+BlockSize     = 0x00010000

+NumBlocks     = 0x20

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00050000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+0x00050000|0x00150000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiUniCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                  $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                             $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional         $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                          $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional          $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                      $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                          $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc
new file mode 100644
index 0000000..2a6a5b7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc
@@ -0,0 +1,318 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+#

+

+[LibraryClasses.common]

+!if $(TARGET) == RELEASE

+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+!else

+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+#  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf

+!endif

+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf

+

+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf

+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf

+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf

+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf

+

+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf

+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf

+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf

+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf

+

+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf

+

+  #

+  # Assume everything is fixed at build

+  #

+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+

+  # 1/123 faster than Stm or Vstm version

+  #BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf

+  BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf

+

+  # ARM Architectural Libraries

+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf

+  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf

+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf

+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf

+  ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf

+  ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf

+  ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf

+

+  # RealView Emulation Board Specific Libraries

+  PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf

+  EfiResetSystemLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/ResetSystemLib/ResetSystemLib.inf

+  RealTimeClockLib|ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

+  SerialPortLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf

+  SerialPortExtLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.inf

+  TimerLib|ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf

+  # ARM PL011 UART Driver

+  PL011UartLib|ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEbLib.inf

+  LcdPlatformLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEbLib.inf

+  ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf

+

+  # Networking Requirements for ArmPlatformPkg/Bds

+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf

+

+  # EBL Related Libraries

+  EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf

+  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf

+  EblAddExternalCommandLib|EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf

+  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf

+

+  #

+  # Uncomment (and comment out the next line) For RealView Debugger. The Standard IO window

+  # in the debugger will show load and unload commands for symbols. You can cut and paste this

+  # into the command window to load symbols. We should be able to use a script to do this, but

+  # the version of RVD I have does not support scripts accessing system memory.

+  #

+  #PeCoffExtraActionLib|ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf

+  PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf

+  #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf

+

+  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf

+  DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf

+  #DebugAgentTimerLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf

+

+  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf

+

+  GdbSerialLib|ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.inf

+

+  # BDS Libraries

+  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf

+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmPlatformSecExtraActionLib|ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf

+  ArmTrustedMonitorLib|ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf

+

+  DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf

+  # Uncomment to turn on GDB stub in SEC.

+  #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf

+

+!ifdef $(EDK2_SKIP_PEICORE)

+  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf

+  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf

+  LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf

+  HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf

+  PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf

+  MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf

+!endif

+

+[LibraryClasses.common.PEI_CORE]

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+

+[LibraryClasses.common.PEIM]

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+

+[LibraryClasses.common.DXE_CORE]

+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf

+  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf

+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf

+

+[LibraryClasses.common.DXE_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf

+

+[LibraryClasses.common.UEFI_APPLICATION]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+

+[LibraryClasses.common.UEFI_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+

+[LibraryClasses.common.DXE_RUNTIME_DRIVER]

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf

+

+[LibraryClasses.ARM]

+  #

+  # It is not possible to prevent the ARM compiler for generic intrinsic functions.

+  # This library provides the instrinsic functions generate by a given compiler.

+  # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.

+  #

+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

+

+  # Add support for GCC stack protector

+  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf

+

+[BuildOptions]

+  RVCT:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG

+

+  GCC:RELEASE_*_*_CC_FLAGS    = -DMDEPKG_NDEBUG

+

+  XCODE:RELEASE_*_*_CC_FLAGS     = -DMDEPKG_NDEBUG

+

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE

+

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE

+

+  # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress

+  gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE

+

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000

+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF

+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1

+  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0

+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320

+

+  # DEBUG_ASSERT_ENABLED       0x01

+  # DEBUG_PRINT_ENABLED        0x02

+  # DEBUG_CODE_ENABLED         0x04

+  # CLEAR_MEMORY_ENABLED       0x08

+  # ASSERT_BREAKPOINT_ENABLED  0x10

+  # ASSERT_DEADLOOP_ENABLED    0x20

+!if $(TARGET) == RELEASE

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x21

+!else

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f

+!endif

+

+  #  DEBUG_INIT      0x00000001  // Initialization

+  #  DEBUG_WARN      0x00000002  // Warnings

+  #  DEBUG_LOAD      0x00000004  // Load events

+  #  DEBUG_FS        0x00000008  // EFI File system

+  #  DEBUG_POOL      0x00000010  // Alloc & Free's

+  #  DEBUG_PAGE      0x00000020  // Alloc & Free's

+  #  DEBUG_INFO      0x00000040  // Verbose

+  #  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers

+  #  DEBUG_VARIABLE  0x00000100  // Variable

+  #  DEBUG_BM        0x00000400  // Boot Manager

+  #  DEBUG_BLKIO     0x00001000  // BlkIo Driver

+  #  DEBUG_NET       0x00004000  // SNI Driver

+  #  DEBUG_UNDI      0x00010000  // UNDI Driver

+  #  DEBUG_LOADFILE  0x00020000  // UNDI Driver

+  #  DEBUG_EVENT     0x00080000  // Event messages

+  #  DEBUG_ERROR     0x80000000  // Error

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F

+

+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07

+

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000

+

+  #

+  # Optional feature to help prevent EFI memory map fragments

+  # Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob

+  # Values are in EFI Pages (4K). DXE Core will make sure that

+  # at least this much of each type of memory can be allocated

+  # from a single memory range. This way you only end up with

+  # maximum of two fragements for each type in the memory map

+  # (the memory used, and the free memory that was prereserved

+  # but not used).

+  #

+  gArmTokenSpaceGuid.PcdCpuVectorBaseAddress|0x00000000

+

+  ## PL180 MMC/SD card controller

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x10000048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x10005000

+

+  #

+  # ARM OS Loader

+  #

+  gArmTokenSpaceGuid.PcdArmMachineType|827

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"SemiHosting"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/zImage-RTSM"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|1

+

+  # Use the Serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi()"

+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut|10

+

+[Components.common]

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dec b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dec
new file mode 100644
index 0000000..5015532
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dec
@@ -0,0 +1,39 @@
+#/** @file

+# Arm RealView EB package.

+#

+# Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>

+# Copyright (c) 2011 - 2012, Arm Ltd. All rights reserved.<BR>

+#

+#    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              = 0x00010005

+  PACKAGE_NAME                   = ArmRealViewEbPkg

+  PACKAGE_GUID                   = 44577A0D-361A-45B2-B33D-BB9EE60D5A4F

+  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]

+  gArmRealViewEbPkgTokenSpaceGuid    =  { 0x44577A0D, 0x361A, 0x45B2, { 0xb3, 0x3d, 0xbb, 0x9e, 0xe6, 0x0d, 0x5a, 0x4f} }

+

+[PcdsFixedAtBuild.common]

+  gArmRealViewEbPkgTokenSpaceGuid.PcdGdbUartBase|0|UINT32|0x00000001

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/EBLoadSecSyms.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/EBLoadSecSyms.inc
new file mode 100644
index 0000000..8783036
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/EBLoadSecSyms.inc
@@ -0,0 +1,16 @@
+// returns the base address of the SEC FV in flash on the EB board

+// change this address for where your platform's SEC FV is located

+// (or make it more intelligent to search for it)

+define /r FindFv()

+{

+  return 0x40000000;

+}

+.

+

+include /s 'ZZZZZZ/EfiFuncs.inc'

+error=continue

+unload ,all

+error=abort

+LoadPeiSec()

+include C:\loadfiles.inc

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/EfiFuncs.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/EfiFuncs.inc
new file mode 100644
index 0000000..82a3288
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/EfiFuncs.inc
@@ -0,0 +1,463 @@
+error=abort

+

+// NOTE: THIS MAY NEED TO BE ADJUSTED

+// change to reflect the total amount of ram in your system

+define /r GetMaxMem()

+{

+  return 0x10000000; // 256 MB

+}

+.

+

+define /r GetWord(Addr)

+{

+  unsigned long data;

+

+  if( (Addr & 0x2) == 0 )

+  {

+    data = dword(Addr);

+    data = data & 0xffff;

+    //$printf "getword data is %x\n", data$;

+    return data;

+  }

+  else

+  {

+    data = dword(Addr & 0xfffffffc);

+    //data = data >> 16;

+    data = data / 0x10000;

+    //$printf "getword data is %x (1)\n", data$;

+    return data;

+  }

+}

+.

+

+define /r ProcessPE32(imgstart)

+unsigned long imgstart;

+{

+  unsigned long filehdrstart;

+  unsigned long debugdirentryrva;

+	unsigned long debugtype;

+  unsigned long debugrva;

+	unsigned long dwarfsig;

+  unsigned long baseofcode;

+  unsigned long baseofdata;

+  unsigned long elfbase;

+  char *elfpath;

+

+	$printf "PE32 image found at %x",imgstart$;

+

+	//$printf "PE file hdr offset %x",dword(imgstart+0x3C)$;

+

+  // offset from dos hdr to PE file hdr

+  filehdrstart = imgstart + dword(imgstart+0x3C);

+

+  // offset to debug dir in PE hdrs

+	//$printf "debug dir is at %x",(filehdrstart+0xA8)$;

+	debugdirentryrva = dword(filehdrstart + 0xA8);

+  if(debugdirentryrva == 0)

+	{

+		$printf "no debug dir for image at %x",imgstart$;

+	  return;

+	}

+

+	//$printf "debug dir entry rva is %x",debugdirentryrva$;

+

+	debugtype = dword(imgstart + debugdirentryrva + 0xc);

+  if( (debugtype != 0xdf) && (debugtype != 0x2) )

+	{

+		$printf "debug type is not dwarf for image at %x",imgstart$;

+		$printf "debug type is %x",debugtype$;

+		return;

+	}

+

+	debugrva = dword(imgstart + debugdirentryrva + 0x14);

+	dwarfsig = dword(imgstart + debugrva);

+	if(dwarfsig != 0x66727764)

+	{

+		$printf "dwarf debug signature not found for image at %x",imgstart$;

+	  return;

+	}

+

+  elfpath = (char *)(imgstart + debugrva + 0xc);

+

+  baseofcode = imgstart + dword(filehdrstart + 0x28);

+  baseofdata = imgstart + dword(filehdrstart + 0x2c);

+

+  if( (baseofcode < baseofdata) && (baseofcode != 0) )

+  {

+		elfbase = baseofcode;

+  }

+  else

+  {

+    elfbase = baseofdata;

+  }

+

+	$printf "found path %s",elfpath$;

+	$fprintf 50, "load /ni /np /a %s &0x%x\n",elfpath,elfbase$;

+}

+.

+

+define /r ProcessTE(imgstart)

+unsigned long imgstart;

+{

+  unsigned long strippedsize;

+	unsigned long debugdirentryrva;

+	unsigned long debugtype;

+  unsigned long debugrva;

+	unsigned long dwarfsig;

+  unsigned long elfbase;

+  char *elfpath;

+

+	$printf "TE image found at %x",imgstart$;

+

+  // determine pe header bytes removed to account for in rva references

+  //strippedsize = word(imgstart + 0x6);

+  //strippedsize = (dword(imgstart + 0x4) & 0xffff0000) >> 16;

+  strippedsize = (dword(imgstart + 0x4) & 0xffff0000) / 0x10000;

+  strippedsize = strippedsize - 0x28;

+

+	debugdirentryrva = dword(imgstart + 0x20);

+  if(debugdirentryrva == 0)

+	{

+		$printf "no debug dir for image at %x",imgstart$;

+	  return;

+	}

+  debugdirentryrva = debugdirentryrva - strippedsize;

+

+	//$printf "debug dir entry rva is %x",debugdirentryrva$;

+

+	debugtype = dword(imgstart + debugdirentryrva + 0xc);

+  if( (debugtype != 0xdf) && (debugtype != 0x2) )

+	{

+		$printf "debug type is not dwarf for image at %x",imgstart$;

+		$printf "debug type is %x",debugtype$;

+		return;

+	}

+

+	debugrva = dword(imgstart + debugdirentryrva + 0x14);

+  debugrva = debugrva - strippedsize;

+	dwarfsig = dword(imgstart + debugrva);

+	if( (dwarfsig != 0x66727764) && (dwarfsig != 0x3031424e) )

+	{

+		$printf "dwarf debug signature not found for image at %x",imgstart$;

+		$printf "found %x", dwarfsig$;

+	  return;

+	}

+

+	if( dwarfsig == 0x66727764 )

+	{

+		elfpath = (char *)(imgstart + debugrva + 0xc);

+    $printf "looking for elf path at 0x%x", elfpath$;

+  }

+  else

+  {

+    elfpath = (char *)(imgstart + debugrva + 0x10);

+    $printf "looking for elf path at 0x%x", elfpath$;

+  }

+

+  // elf base is baseofcode (we hope that for TE images it's not baseofdata)

+  elfbase = imgstart + dword(imgstart + 0xc) - strippedsize;

+

+	$printf "found path %s",elfpath$;

+	$fprintf 50, "load /ni /np /a %s &0x%x\n",elfpath,elfbase$;

+}

+.

+

+define /r ProcessFvSection(secstart)

+unsigned long secstart;

+{

+  unsigned long sectionsize;

+  unsigned char sectiontype;

+

+	sectionsize = dword(secstart);

+  //sectiontype = (sectionsize & 0xff000000) >> 24;

+  sectiontype = (sectionsize & 0xff000000) / 0x1000000;

+  sectionsize = sectionsize & 0x00ffffff;

+

+	$printf "fv section at %x size %x type %x",secstart,sectionsize,sectiontype$;

+

+	if(sectiontype == 0x10) // PE32

+  {

+		ProcessPE32(secstart+0x4);

+	}

+	else if(sectiontype == 0x12) // TE

+	{

+		ProcessTE(secstart+0x4);

+ 	}

+}

+.

+

+define /r ProcessFfsFile(ffsfilestart)

+unsigned long ffsfilestart;

+{

+  unsigned long ffsfilesize;

+  unsigned long ffsfiletype;

+  unsigned long secoffset;

+  unsigned long secsize;

+

+  //ffsfiletype = byte(ffsfilestart + 0x12);

+  ffsfilesize = dword(ffsfilestart + 0x14);

+  //ffsfiletype = (ffsfilesize & 0xff000000) >> 24;

+  ffsfiletype = (ffsfilesize & 0xff000000) / 0x1000000;

+  ffsfilesize = ffsfilesize & 0x00ffffff;

+

+  if(ffsfiletype == 0xff) return;

+

+	$printf "ffs file at %x size %x type %x",ffsfilestart,ffsfilesize,ffsfiletype$;

+

+  secoffset = ffsfilestart + 0x18;

+

+  // loop through sections in file

+  while(secoffset < (ffsfilestart + ffsfilesize))

+	{

+		// process fv section and increment section offset by size

+    secsize = dword(secoffset) & 0x00ffffff;

+    ProcessFvSection(secoffset);

+		secoffset = secoffset + secsize;

+

+	  // align to next 4 byte boundary

+    if( (secoffset & 0x3) != 0 )

+		{

+			secoffset = secoffset + (0x4 - (secoffset & 0x3));

+		}

+	} // end section loop

+}

+.

+

+define /r LoadPeiSec()

+{

+  unsigned long fvbase;

+  unsigned long fvlen;

+  unsigned long fvsig;

+	unsigned long ffsoffset;

+  unsigned long ffsfilesize;

+

+  fvbase = FindFv();

+	$printf "fvbase %x",fvbase$;

+

+  // get fv signature field

+  fvsig = dword(fvbase + 0x28);

+  if(fvsig != 0x4856465F)

+  {

+		$printf "FV does not have proper signature, exiting"$;

+    return 0;

+  }

+

+	$printf "FV signature found"$;

+

+  $fopen 50, 'C:\loadfiles.inc'$;

+

+  fvlen = dword(fvbase + 0x20);

+

+  // first ffs file is after fv header, use headerlength field

+  //ffsoffset = (dword(fvbase + 0x30) & 0xffff0000) >> 16;

+  ffsoffset = (dword(fvbase + 0x30) & 0xffff0000) / 0x10000;

+  ffsoffset = fvbase + GetWord(fvbase + 0x30);

+

+  // loop through ffs files

+  while(ffsoffset < (fvbase+fvlen))

+	{

+		// process ffs file and increment by ffs file size field

+ 		ProcessFfsFile(ffsoffset);

+ 		ffsfilesize = (dword(ffsoffset + 0x14) & 0x00ffffff);

+ 		if(ffsfilesize == 0)

+ 		{

+ 		  break;

+ 		}

+		ffsoffset = ffsoffset + ffsfilesize;

+

+

+		// align to next 8 byte boundary

+    if( (ffsoffset & 0x7) != 0 )

+		{

+			ffsoffset = ffsoffset + (0x8 - (ffsoffset & 0x7));

+		}

+

+  } // end fv ffs loop

+

+	$vclose 50$;

+

+}

+.

+

+define /r FindSystemTable(TopOfRam)

+unsigned long TopOfRam;

+{

+  unsigned long offset;

+

+  $printf "FindSystemTable"$;

+  $printf "top of mem is %x",TopOfRam$;

+

+  offset = TopOfRam;

+

+  // align to highest 4MB boundary

+  offset = offset & 0xFFC00000;

+

+  // start at top and look on 4MB boundaries for system table ptr structure

+  while(offset > 0)

+  {

+    //$printf "checking %x",offset$;

+    //$printf "value is %x",dword(offset)$;

+

+    // low signature match

+    if(dword(offset) == 0x20494249)

+    {

+      // high signature match

+      if(dword(offset+4) == 0x54535953)

+      {

+        // less than 4GB?

+        if(dword(offset+0x0c) == 0)

+        {

+          // less than top of ram?

+          if(dword(offset+8) < TopOfRam)

+          {

+            return(dword(offset+8));

+          }

+        }

+      }

+

+    }

+

+    if(offset < 0x400000) break;

+    offset = offset - 0x400000;

+  }

+

+  return 0;

+}

+.

+

+define /r ProcessImage(ImageBase)

+unsigned long ImageBase;

+{

+  $printf "ProcessImage %x", ImageBase$;

+}

+.

+

+define /r FindDebugInfo(SystemTable)

+unsigned long SystemTable;

+{

+  unsigned long   CfgTableEntries;

+  unsigned long   ConfigTable;

+  unsigned long   i;

+  unsigned long   offset;

+  unsigned long   dbghdr;

+  unsigned long   dbgentries;

+  unsigned long   dbgptr;

+  unsigned long   dbginfo;

+  unsigned long   loadedimg;

+

+  $printf "FindDebugInfo"$;

+

+  dbgentries = 0;

+  CfgTableEntries = dword(SystemTable + 0x40);

+  ConfigTable = dword(SystemTable + 0x44);

+

+  $printf "config table is at %x (%d entries)", ConfigTable, CfgTableEntries$;

+

+  // now search for debug info entry with guid 49152E77-1ADA-4764-B7A2-7AFEFED95E8B

+  //	0x49152E77	0x47641ADA	0xFE7AA2B7	0x8B5ED9FE

+  for(i=0; i<CfgTableEntries; i++)

+  {

+    offset = ConfigTable + (i*0x14);

+    if(dword(offset) == 0x49152E77)

+    {

+      if(dword(offset+4) == 0x47641ADA)

+      {

+        if(dword(offset+8) == 0xFE7AA2B7)

+        {

+          if(dword(offset+0xc) == 0x8B5ED9FE)

+          {

+            dbghdr = dword(offset+0x10);

+            dbgentries = dword(dbghdr + 4);

+            dbgptr = dword(dbghdr + 8);

+          }

+        }

+      }

+    }

+  }

+

+  if(dbgentries == 0)

+  {

+    $printf "no debug entries found"$;

+    return;

+  }

+

+  $printf "debug table at %x (%d entries)", dbgptr, dbgentries$;

+

+  for(i=0; i<dbgentries; i++)

+  {

+    dbginfo = dword(dbgptr + (i*4));

+    if(dbginfo != 0)

+    {

+      if(dword(dbginfo) == 1) // normal debug info type

+      {

+        loadedimg = dword(dbginfo + 4);

+        ProcessPE32(dword(loadedimg + 0x20));

+      }

+    }

+  }

+}

+.

+

+define /r LoadDxe()

+{

+  unsigned long     maxmem;

+  unsigned long     systbl;

+

+  $printf "LoadDxe"$;

+

+  $fopen 50, 'C:\loadfiles.inc'$;

+

+  maxmem = GetMaxMem();

+  systbl = FindSystemTable(maxmem);

+  if(systbl != 0)

+  {

+    $printf "found system table at %x",systbl$;

+    FindDebugInfo(systbl);

+  }

+

+  $vclose 50$;

+}

+.

+

+define /r LoadRuntimeDxe()

+

+{

+  unsigned long   maxmem;

+  unsigned long   SystemTable;

+  unsigned long   CfgTableEntries;

+  unsigned long   ConfigTable;

+  unsigned long   i;

+  unsigned long   offset;

+  unsigned long   numentries;

+  unsigned long   RuntimeDebugInfo;

+  unsigned long   DebugInfoOffset;

+  unsigned long   imgbase;

+

+  $printf "LoadRuntimeDxe"$;

+

+  $fopen 50, 'C:\loadfiles.inc'$;

+

+  RuntimeDebugInfo = 0x80000010;

+

+  if(RuntimeDebugInfo != 0)

+  {

+    numentries = dword(RuntimeDebugInfo);

+

+    $printf "runtime debug info is at %x (%d entries)", RuntimeDebugInfo, numentries$;

+

+    DebugInfoOffset = RuntimeDebugInfo + 0x4;

+    for(i=0; i<numentries; i++)

+    {

+      imgbase = dword(DebugInfoOffset);

+      if(imgbase != 0)

+      {

+        $printf "found image at %x",imgbase$;

+        ProcessPE32(imgbase);

+      }

+      DebugInfoOffset = DebugInfoOffset + 0x4;

+    }

+  }

+

+  $vclose 50$;

+}

+.

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_boot_from_ram.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_boot_from_ram.inc
new file mode 100644
index 0000000..a4e9674
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_boot_from_ram.inc
@@ -0,0 +1,21 @@
+//

+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+//

+//  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.

+//

+error = continue

+unload

+error = abort

+

+setreg @CP15_CONTROL = 0x0005107E

+setreg @pc=0x80008208

+setreg @cpsr=0x000000D3

+dis/D

+readfile,raw,nowarn "ZZZZZZ/FV/BEAGLEBOARD_EFI.fd"=0x80008000

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_convert_symbols.sh b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_convert_symbols.sh
new file mode 100644
index 0000000..67fdfe1
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_convert_symbols.sh
@@ -0,0 +1,23 @@
+#!/bin/sh

+#

+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+#  

+#  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.

+#

+

+

+IN=`/usr/bin/cygpath -u $1`

+OUT=`/usr/bin/cygpath -u $2`

+

+/usr/bin/sed -e "s/\/cygdrive\/\(.\)/load\/a\/ni\/np \"\1:/g" \

+             -e 's:\\:/:g' \

+             -e "s/^/load\/a\/ni\/np \"/g" \

+             -e "s/dll /dll\" \&/g" \

+              $IN | /usr/bin/sort.exe --key=3 --output=$OUT

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_hw_setup.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_hw_setup.inc
new file mode 100644
index 0000000..dbce4df
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_hw_setup.inc
@@ -0,0 +1,67 @@
+//

+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+//

+//  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.

+//

+

+error = continue

+unload

+error = abort

+

+setreg @CP15_CONTROL = 0x0005107E

+setreg @cpsr=0x000000D3

+

+; General clock settings.

+setmem /32 0x48307270=0x00000080

+setmem /32 0x48306D40=0x00000003

+setmem /32 0x48005140=0x03020A50

+

+;Clock configuration

+setmem /32 0x48004A40=0x0000030A

+setmem /32 0x48004C40=0x00000015

+

+;DPLL3 (Core) settings

+setmem /32 0x48004D00=0x00370037

+setmem /32 0x48004D30=0x00000000

+setmem /32 0x48004D40=0x094C0C00

+

+;DPLL4 (Peripheral) settings

+setmem /32 0x48004D00=0x00370037

+setmem /32 0x48004D30=0x00000000

+setmem /32 0x48004D44=0x0001B00C

+setmem /32 0x48004D48=0x00000009

+

+;DPLL1 (MPU) settings

+setmem /32 0x48004904=0x00000037

+setmem /32 0x48004934=0x00000000

+setmem /32 0x48004940=0x0011F40C

+setmem /32 0x48004944=0x00000001

+setmem /32 0x48004948=0x00000000

+

+;RAM setup.

+setmem /16 0x6D000010=0x0000

+setmem /16 0x6D000040=0x0001

+setmem /16 0x6D000044=0x0100

+setmem /16 0x6D000048=0x0000

+setmem /32 0x6D000060=0x0000000A

+setmem /32 0x6D000070=0x00000081

+setmem /16 0x6D000040=0x0003

+setmem /32 0x6D000080=0x02D04011

+setmem /16 0x6D000084=0x0032

+setmem /16 0x6D00008C=0x0000

+setmem /32 0x6D00009C=0xBA9DC4C6

+setmem /32 0x6D0000A0=0x00012522

+setmem /32 0x6D0000A4=0x0004E201

+setmem /16 0x6D000040=0x0003

+setmem /32 0x6D0000B0=0x02D04011

+setmem /16 0x6D0000B4=0x0032

+setmem /16 0x6D0000BC=0x0000

+setmem /32 0x6D0000C4=0xBA9DC4C6

+setmem /32 0x6D0000C8=0x00012522

+setmem /32 0x6D0000D4=0x0004E201

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_load_symbols.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_load_symbols.inc
new file mode 100644
index 0000000..33e3eac
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_load_symbols.inc
@@ -0,0 +1,23 @@
+//

+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+//

+//  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 'ZZZZZZ/rvi_symbols_macros.inc'

+

+macro write_symbols_file("ZZZZZZ/rvi_symbols.tmp", 0x00000000, 0x10000000)

+

+host "bash -o igncr ZZZZZZ/rvi_convert_symbols.sh ZZZZZZ/rvi_symbols.tmp ZZZZZZ/rvi_symbols.inc"

+include 'ZZZZZZ/rvi_symbols.inc'

+load /NI /NP 'ZZZZZZ/rvi_dummy.axf' ;.constdata

+unload rvi_dummy.axf

+delfile rvi_dummy.axf

+

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_symbols_macros.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_symbols_macros.inc
new file mode 100644
index 0000000..0fc2c64
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_symbols_macros.inc
@@ -0,0 +1,194 @@
+//

+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+//

+//  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.

+//

+

+define /R int compare_guid(guid1, guid2)

+    unsigned char *guid1;

+    unsigned char *guid2;

+{

+    return strncmp(guid1, guid2, 16);

+}

+.

+

+define /R unsigned char * find_system_table(mem_start, mem_size)

+    unsigned char *mem_start;

+    unsigned long mem_size;

+{

+    unsigned char *mem_ptr;

+

+    mem_ptr = mem_start + mem_size;

+

+    do

+    {

+        mem_ptr -= 0x400000; // 4 MB

+

+        if (strncmp(mem_ptr, "IBI SYST", 8) == 0)

+        {

+            return *(unsigned long *)(mem_ptr + 8); // EfiSystemTableBase

+        }

+

+    } while (mem_ptr > mem_start);

+

+    return 0;

+}

+.

+

+define /R unsigned char * find_debug_info_table_header(system_table)

+    unsigned char *system_table;

+{

+    unsigned long configuration_table_entries;

+    unsigned char *configuration_table;

+    unsigned long index;

+    unsigned char debug_table_guid[16];

+

+    // Fill in the debug table's guid

+    debug_table_guid[ 0] = 0x77;

+    debug_table_guid[ 1] = 0x2E;

+    debug_table_guid[ 2] = 0x15;

+    debug_table_guid[ 3] = 0x49;

+    debug_table_guid[ 4] = 0xDA;

+    debug_table_guid[ 5] = 0x1A;

+    debug_table_guid[ 6] = 0x64;

+    debug_table_guid[ 7] = 0x47;

+    debug_table_guid[ 8] = 0xB7;

+    debug_table_guid[ 9] = 0xA2;

+    debug_table_guid[10] = 0x7A;

+    debug_table_guid[11] = 0xFE;

+    debug_table_guid[12] = 0xFE;

+    debug_table_guid[13] = 0xD9;

+    debug_table_guid[14] = 0x5E;

+    debug_table_guid[15] = 0x8B;

+

+    configuration_table_entries = *(unsigned long *)(system_table + 64);

+    configuration_table         = *(unsigned long *)(system_table + 68);

+

+    for (index = 0; index < configuration_table_entries; index++)

+    {

+        if (compare_guid(configuration_table, debug_table_guid) == 0)

+        {

+            return *(unsigned long *)(configuration_table + 16);

+        }

+

+        configuration_table += 20;

+    }

+

+    return 0;

+}

+.

+

+define /R int valid_pe_header(header)

+        unsigned char *header;

+{

+    if ((header[0x00] == 'M') &&

+        (header[0x01] == 'Z') &&

+        (header[0x80] == 'P') &&

+        (header[0x81] == 'E'))

+    {

+        return 1;

+    }

+

+    return 0;

+}

+.

+

+define /R unsigned long pe_headersize(header)

+        unsigned char *header;

+{

+    unsigned long *size;

+

+    size = header + 0x00AC;

+

+    return *size;

+}

+.

+

+define /R unsigned char *pe_filename(header)

+        unsigned char *header;

+{

+    unsigned long *debugOffset;

+    unsigned char *stringOffset;

+

+    if (valid_pe_header(header))

+    {

+        debugOffset  = header + 0x0128;

+        stringOffset = header + *debugOffset + 0x002C;

+

+        return stringOffset;

+    }

+

+    return 0;

+}

+.

+

+define /R int char_is_valid(c)

+        unsigned char c;

+{

+    if (c >= 32 && c < 127)

+    	return 1;

+

+    return 0;

+}

+.

+

+define /R write_symbols_file(filename, mem_start, mem_size)

+    unsigned char *filename;

+    unsigned char *mem_start;

+    unsigned long mem_size;

+{

+    unsigned char *system_table;

+    unsigned char *debug_info_table_header;

+    unsigned char *debug_info_table;

+    unsigned long debug_info_table_size;

+    unsigned long index;

+    unsigned char *debug_image_info;

+    unsigned char *loaded_image_protocol;

+    unsigned char *image_base;

+    unsigned char *debug_filename;

+    unsigned long header_size;

+    int           status;

+

+    system_table = find_system_table(mem_start, mem_size);

+    if (system_table == 0)

+    {

+        return;

+    }

+

+    status = fopen(88, filename, "w");

+

+    debug_info_table_header = find_debug_info_table_header(system_table);

+

+    debug_info_table      = *(unsigned long *)(debug_info_table_header + 8);

+    debug_info_table_size = *(unsigned long *)(debug_info_table_header + 4);

+

+    for (index = 0; index < (debug_info_table_size * 4); index += 4)

+    {

+        debug_image_info = *(unsigned long *)(debug_info_table + index);

+

+        if (debug_image_info == 0)

+        {

+            break;

+        }

+

+        loaded_image_protocol = *(unsigned long *)(debug_image_info + 4);

+

+        image_base = *(unsigned long *)(loaded_image_protocol + 32);

+

+        debug_filename = pe_filename(image_base);

+        header_size    = pe_headersize(image_base);

+

+        $fprintf 88, "%s 0x%08x\n", debug_filename, image_base + header_size$;

+    }

+

+

+    fclose(88);

+}

+.

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_unload_symbols.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_unload_symbols.inc
new file mode 100644
index 0000000..b00a132
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts/rvi_unload_symbols.inc
@@ -0,0 +1,118 @@
+//

+// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+//

+//  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.

+//

+

+error = continue

+

+unload

+

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+delfile 1

+

+error = abort

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/FvbDxe/FvbDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/FvbDxe/FvbDxe.c
new file mode 100644
index 0000000..3fbbec7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/FvbDxe/FvbDxe.c
@@ -0,0 +1,417 @@
+/*++

+RealView EB FVB DXE Driver

+

+Copyright (c) 2010, Apple Inc. All rights reserved.<BR>

+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 <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiLib.h>

+#include <Library/PcdLib.h>

+

+#include <Protocol/FirmwareVolumeBlock.h>

+

+

+

+/**

+  The GetAttributes() function retrieves the attributes and

+  current settings of the block.

+

+  @param This       Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+  @param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the

+                    attributes and current settings are

+                    returned. Type EFI_FVB_ATTRIBUTES_2 is defined

+                    in EFI_FIRMWARE_VOLUME_HEADER.

+

+  @retval EFI_SUCCESS The firmware volume attributes were

+                      returned.

+

+**/

+

+EFI_STATUS

+EFIAPI

+FvbGetAttributes (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  OUT       EFI_FVB_ATTRIBUTES_2                *Attributes

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  The SetAttributes() function sets configurable firmware volume

+  attributes and returns the new settings of the firmware volume.

+

+

+  @param This         Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+  @param Attributes   On input, Attributes is a pointer to

+                      EFI_FVB_ATTRIBUTES_2 that contains the

+                      desired firmware volume settings. On

+                      successful return, it contains the new

+                      settings of the firmware volume. Type

+                      EFI_FVB_ATTRIBUTES_2 is defined in

+                      EFI_FIRMWARE_VOLUME_HEADER.

+

+  @retval EFI_SUCCESS           The firmware volume attributes were returned.

+

+  @retval EFI_INVALID_PARAMETER The attributes requested are in

+                                conflict with the capabilities

+                                as declared in the firmware

+                                volume header.

+

+**/

+EFI_STATUS

+EFIAPI

+FvbSetAttributes (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  IN OUT    EFI_FVB_ATTRIBUTES_2                *Attributes

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  The GetPhysicalAddress() function retrieves the base address of

+  a memory-mapped firmware volume. This function should be called

+  only for memory-mapped firmware volumes.

+

+  @param This     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+  @param Address  Pointer to a caller-allocated

+                  EFI_PHYSICAL_ADDRESS that, on successful

+                  return from GetPhysicalAddress(), contains the

+                  base address of the firmware volume.

+

+  @retval EFI_SUCCESS       The firmware volume base address was returned.

+

+  @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.

+

+**/

+EFI_STATUS

+EFIAPI

+FvbGetPhysicalAddress (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  OUT       EFI_PHYSICAL_ADDRESS                *Address

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  The GetBlockSize() function retrieves the size of the requested

+  block. It also returns the number of additional blocks with

+  the identical size. The GetBlockSize() function is used to

+  retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).

+

+

+  @param This           Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+  @param Lba            Indicates the block for which to return the size.

+

+  @param BlockSize      Pointer to a caller-allocated UINTN in which

+                        the size of the block is returned.

+

+  @param NumberOfBlocks Pointer to a caller-allocated UINTN in

+                        which the number of consecutive blocks,

+                        starting with Lba, is returned. All

+                        blocks in this range have a size of

+                        BlockSize.

+

+

+  @retval EFI_SUCCESS             The firmware volume base address was returned.

+

+  @retval EFI_INVALID_PARAMETER   The requested LBA is out of range.

+

+**/

+EFI_STATUS

+EFIAPI

+FvbGetBlockSize (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  IN        EFI_LBA                             Lba,

+  OUT       UINTN                               *BlockSize,

+  OUT       UINTN                               *NumberOfBlocks

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+

+

+/**

+  Reads the specified number of bytes into a buffer from the specified block.

+

+  The Read() function reads the requested number of bytes from the

+  requested block and stores them in the provided buffer.

+  Implementations should be mindful that the firmware volume

+  might be in the ReadDisabled state. If it is in this state,

+  the Read() function must return the status code

+  EFI_ACCESS_DENIED without modifying the contents of the

+  buffer. The Read() function must also prevent spanning block

+  boundaries. If a read is requested that would span a block

+  boundary, the read must read up to the boundary but not

+  beyond. The output parameter NumBytes must be set to correctly

+  indicate the number of bytes actually read. The caller must be

+  aware that a read may be partially completed.

+

+  @param This     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+  @param Lba      The starting logical block index

+                  from which to read.

+

+  @param Offset   Offset into the block at which to begin reading.

+

+  @param NumBytes Pointer to a UINTN. At entry, *NumBytes

+                  contains the total size of the buffer. At

+                  exit, *NumBytes contains the total number of

+                  bytes read.

+

+  @param Buffer   Pointer to a caller-allocated buffer that will

+                  be used to hold the data that is read.

+

+  @retval EFI_SUCCESS         The firmware volume was read successfully,

+                              and contents are in Buffer.

+

+  @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA

+                              boundary. On output, NumBytes

+                              contains the total number of bytes

+                              returned in Buffer.

+

+  @retval EFI_ACCESS_DENIED   The firmware volume is in the

+                              ReadDisabled state.

+

+  @retval EFI_DEVICE_ERROR    The block device is not

+                              functioning correctly and could

+                              not be read.

+

+**/

+EFI_STATUS

+EFIAPI

+FvbRead (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  IN        EFI_LBA                             Lba,

+  IN        UINTN                               Offset,

+  IN OUT    UINTN                               *NumBytes,

+  IN OUT    UINT8                               *Buffer

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  Writes the specified number of bytes from the input buffer to the block.

+

+  The Write() function writes the specified number of bytes from

+  the provided buffer to the specified block and offset. If the

+  firmware volume is sticky write, the caller must ensure that

+  all the bits of the specified range to write are in the

+  EFI_FVB_ERASE_POLARITY state before calling the Write()

+  function, or else the result will be unpredictable. This

+  unpredictability arises because, for a sticky-write firmware

+  volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY

+  state but cannot flip it back again.  Before calling the

+  Write() function,  it is recommended for the caller to first call

+  the EraseBlocks() function to erase the specified block to

+  write. A block erase cycle will transition bits from the

+  (NOT)EFI_FVB_ERASE_POLARITY state back to the

+  EFI_FVB_ERASE_POLARITY state. Implementations should be

+  mindful that the firmware volume might be in the WriteDisabled

+  state. If it is in this state, the Write() function must

+  return the status code EFI_ACCESS_DENIED without modifying the

+  contents of the firmware volume. The Write() function must

+  also prevent spanning block boundaries. If a write is

+  requested that spans a block boundary, the write must store up

+  to the boundary but not beyond. The output parameter NumBytes

+  must be set to correctly indicate the number of bytes actually

+  written. The caller must be aware that a write may be

+  partially completed. All writes, partial or otherwise, must be

+  fully flushed to the hardware before the Write() service

+  returns.

+

+  @param This     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+  @param Lba      The starting logical block index to write to.

+

+  @param Offset   Offset into the block at which to begin writing.

+

+  @param NumBytes The pointer to a UINTN. At entry, *NumBytes

+                  contains the total size of the buffer. At

+                  exit, *NumBytes contains the total number of

+                  bytes actually written.

+

+  @param Buffer   The pointer to a caller-allocated buffer that

+                  contains the source for the write.

+

+  @retval EFI_SUCCESS         The firmware volume was written successfully.

+

+  @retval EFI_BAD_BUFFER_SIZE The write was attempted across an

+                              LBA boundary. On output, NumBytes

+                              contains the total number of bytes

+                              actually written.

+

+  @retval EFI_ACCESS_DENIED   The firmware volume is in the

+                              WriteDisabled state.

+

+  @retval EFI_DEVICE_ERROR    The block device is malfunctioning

+                              and could not be written.

+

+

+**/

+EFI_STATUS

+EFIAPI

+FvbWrite (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  IN        EFI_LBA                             Lba,

+  IN        UINTN                               Offset,

+  IN OUT    UINTN                               *NumBytes,

+  IN        UINT8                               *Buffer

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  Erases and initializes a firmware volume block.

+

+  The EraseBlocks() function erases one or more blocks as denoted

+  by the variable argument list. The entire parameter list of

+  blocks must be verified before erasing any blocks. If a block is

+  requested that does not exist within the associated firmware

+  volume (it has a larger index than the last block of the

+  firmware volume), the EraseBlocks() function must return the

+  status code EFI_INVALID_PARAMETER without modifying the contents

+  of the firmware volume. Implementations should be mindful that

+  the firmware volume might be in the WriteDisabled state. If it

+  is in this state, the EraseBlocks() function must return the

+  status code EFI_ACCESS_DENIED without modifying the contents of

+  the firmware volume. All calls to EraseBlocks() must be fully

+  flushed to the hardware before the EraseBlocks() service

+  returns.

+

+  @param This   Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL

+                instance.

+

+  @param ...    The variable argument list is a list of tuples.

+                Each tuple describes a range of LBAs to erase

+                and consists of the following:

+                - An EFI_LBA that indicates the starting LBA

+                - A UINTN that indicates the number of blocks to

+                  erase.

+

+                The list is terminated with an

+                EFI_LBA_LIST_TERMINATOR. For example, the

+                following indicates that two ranges of blocks

+                (5-7 and 10-11) are to be erased: EraseBlocks

+                (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);

+

+  @retval EFI_SUCCESS The erase request successfully

+                      completed.

+

+  @retval EFI_ACCESS_DENIED   The firmware volume is in the

+                              WriteDisabled state.

+  @retval EFI_DEVICE_ERROR  The block device is not functioning

+                            correctly and could not be written.

+                            The firmware device may have been

+                            partially erased.

+  @retval EFI_INVALID_PARAMETER One or more of the LBAs listed

+                                in the variable argument list do

+                                not exist in the firmware volume.

+

+**/

+EFI_STATUS

+EFIAPI

+FvbEraseBlocks (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  ...

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+

+//

+// Making this global saves a few bytes in image size

+//

+EFI_HANDLE  gFvbHandle = NULL;

+

+

+///

+/// The Firmware Volume Block Protocol is the low-level interface

+/// to a firmware volume. File-level access to a firmware volume

+/// should not be done using the Firmware Volume Block Protocol.

+/// Normal access to a firmware volume must use the Firmware

+/// Volume Protocol. Typically, only the file system driver that

+/// produces the Firmware Volume Protocol will bind to the

+/// Firmware Volume Block Protocol.

+///

+EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL gFvbProtocol = {

+  FvbGetAttributes,

+  FvbSetAttributes,

+  FvbGetPhysicalAddress,

+  FvbGetBlockSize,

+  FvbRead,

+  FvbWrite,

+  FvbEraseBlocks,

+  ///

+  /// The handle of the parent firmware volume.

+  ///

+  NULL

+};

+

+//     NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) FixedPcdGet32 (PcdFlashNvStorageVariableBase);

+

+

+/**

+  Initialize the state information for the CPU Architectural Protocol

+

+  @param  ImageHandle   of the loaded driver

+  @param  SystemTable   Pointer to the System Table

+

+  @retval EFI_SUCCESS           Protocol registered

+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure

+  @retval EFI_DEVICE_ERROR      Hardware problems

+

+**/

+EFI_STATUS

+EFIAPI

+FvbDxeInitialize (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+

+

+  Status = gBS->InstallMultipleProtocolInterfaces (

+                  &gFvbHandle,

+                  &gEfiFirmwareVolumeBlockProtocolGuid,   &gFvbProtocol,

+                  NULL

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  // SetVertAddressEvent ()

+

+  // GCD Map NAND as RT

+

+  return Status;

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/FvbDxe/FvbDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/FvbDxe/FvbDxe.inf
new file mode 100644
index 0000000..9eb3b90
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/FvbDxe/FvbDxe.inf
@@ -0,0 +1,53 @@
+#/** @file

+#

+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = FvbDxe

+  FILE_GUID                      = 43ECE281-D9E2-4DD0-B304-E6A5689256F4

+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = FvbDxeInitialize

+

+

+[Sources.common]

+  FvbDxe.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  UefiLib

+  UefiBootServicesTableLib

+  DebugLib

+  PrintLib

+  UefiDriverEntryPoint

+  IoLib

+

+[Guids]

+

+

+[Protocols]

+  gEfiFirmwareVolumeBlockProtocolGuid

+

+[FixedPcd.common]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase

+

+[depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform/ArmPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform/ArmPlatform.h
new file mode 100644
index 0000000..5b8f5e2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Include/Platform/ArmPlatform.h
@@ -0,0 +1,122 @@
+/** @file

+*  Header defining RealView EB constants (Base addresses, sizes, flags)

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef __ARM_EB_H__

+#define __ARM_EB_H__

+

+/*******************************************

+// Platform Memory Map

+*******************************************/

+

+// Can be NOR, DOC, DRAM, SRAM

+#define ARM_EB_REMAP_BASE                     0x00000000

+#define ARM_EB_REMAP_SZ                       0x04000000

+

+// Motherboard Peripheral and On-chip peripheral

+#define ARM_EB_SMB_MB_ON_CHIP_PERIPH_BASE     0x10000000

+#define ARM_EB_SMB_MB_ON_CHIP_PERIPH_SZ       0x10000000

+#define ARM_EB_BOARD_PERIPH_BASE              0x10000000

+//#define ARM_EB_CHIP_PERIPH_BASE             0x10020000

+

+// SMC

+#define ARM_EB_SMC_BASE                       0x40000000

+#define ARM_EB_SMC_SZ                         0x20000000

+

+// NOR Flash 1

+#define ARM_EB_SMB_NOR_BASE                   0x40000000

+#define ARM_EB_SMB_NOR_SZ                     0x04000000 /* 64 MB */

+// DOC Flash

+#define ARM_EB_SMB_DOC_BASE                   0x44000000

+#define ARM_EB_SMB_DOC_SZ                     0x04000000 /* 64 MB */

+// SRAM

+#define ARM_EB_SMB_SRAM_BASE                  0x48000000

+#define ARM_EB_SMB_SRAM_SZ                    0x02000000 /* 32 MB */

+// USB, Ethernet, VRAM

+#define ARM_EB_SMB_PERIPH_BASE                0x4E000000

+//#define ARM_EB_SMB_PERIPH_VRAM              0x4C000000

+#define ARM_EB_SMB_PERIPH_SZ                  0x02000000 /* 32 MB */

+

+// Logic Tile

+#define ARM_EB_LOGIC_TILE_BASE                0xC0000000

+#define ARM_EB_LOGIC_TILE_SZ                  0x40000000

+

+/*******************************************

+// Motherboard peripherals

+*******************************************/

+

+// Define MotherBoard SYS flags offsets (from ARM_EB_BOARD_PERIPH_BASE)

+#define ARM_EB_SYS_ID_REG                     (ARM_EB_BOARD_PERIPH_BASE + 0x00000)

+#define ARM_EB_SYS_OSC4_REG                   (ARM_EB_BOARD_PERIPH_BASE + 0x0001C)

+#define ARM_EB_SYS_LOCK_REG                   (ARM_EB_BOARD_PERIPH_BASE + 0x00020)

+#define ARM_EB_SYS_100HZ_REG                  (ARM_EB_BOARD_PERIPH_BASE + 0x00024)

+#define ARM_EB_SYS_FLAGS_REG                  (ARM_EB_BOARD_PERIPH_BASE + 0x00030)

+#define ARM_EB_SYS_FLAGS_SET_REG              (ARM_EB_BOARD_PERIPH_BASE + 0x00030)

+#define ARM_EB_SYS_FLAGS_CLR_REG              (ARM_EB_BOARD_PERIPH_BASE + 0x00034)

+#define ARM_EB_SYS_FLAGS_NV_REG               (ARM_EB_BOARD_PERIPH_BASE + 0x00038)

+#define ARM_EB_SYS_FLAGS_NV_SET_REG           (ARM_EB_BOARD_PERIPH_BASE + 0x00038)

+#define ARM_EB_SYS_FLAGS_NV_CLR_REG           (ARM_EB_BOARD_PERIPH_BASE + 0x0003C)

+#define ARM_EB_SYS_RESETCTL_REG               (ARM_EB_BOARD_PERIPH_BASE + 0x00040)

+#define ARM_EB_SYS_CLCD_REG                   (ARM_EB_BOARD_PERIPH_BASE + 0x00050)

+#define ARM_EB_SYS_PROCID0_REG                (ARM_EB_BOARD_PERIPH_BASE + 0x00084)

+#define ARM_EB_SYS_PROCID1_REG                (ARM_EB_BOARD_PERIPH_BASE + 0x00088)

+

+// SP810 Controller

+#define SP810_CTRL_BASE                       (ARM_EB_BOARD_PERIPH_BASE + 0x01000)

+

+// SYSTRCL Register

+#define ARM_EB_SYSCTRL                        0x10001000

+

+// Dynamic Memory Controller Base

+#define ARM_EB_DMC_BASE                       0x10018000

+

+// Static Memory Controller Base

+#define ARM_EB_SMC_CTRL_BASE                  0x10080000

+

+//Note: Moving the framebuffer into the 0x70000000-0x80000000 region does not seem to work

+#define PL111_CLCD_VRAM_BASE                  0x00100000

+

+/*// System Configuration Controller register Base addresses

+//#define ARM_EB_SYS_CFG_CTRL_BASE                0x100E2000

+#define ARM_EB_SYS_CFGRW0_REG                   0x100E2000

+#define ARM_EB_SYS_CFGRW1_REG                   0x100E2004

+#define ARM_EB_SYS_CFGRW2_REG                   0x100E2008

+

+#define ARM_EB_CFGRW1_REMAP_NOR0                0

+#define ARM_EB_CFGRW1_REMAP_NOR1                (1 << 28)

+#define ARM_EB_CFGRW1_REMAP_EXT_AXI             (1 << 29)

+#define ARM_EB_CFGRW1_REMAP_DRAM                (1 << 30)

+

+// PL301 Fast AXI Base Address

+#define ARM_EB_FAXI_BASE                        0x100E9000

+

+// L2x0 Cache Controller Base Address

+//#define ARM_EB_L2x0_CTLR_BASE                   0x1E00A000*/

+

+#define ARM_EB_SYS_PROC_ID_MASK                  (UINT32)(0xFFU << 24)

+#define ARM_EB_SYS_PROC_ID_CORTEX_A8             (UINT32)(0x0EU << 24)

+#define ARM_EB_SYS_PROC_ID_CORTEX_A9             (UINT32)(0x0CU << 24)

+

+/*******************************************

+// System Configuration Control

+*******************************************/

+

+// Sites where the peripheral is fitted

+#define ARM_EB_UNSUPPORTED                        ~0

+

+#define VIRTUAL_SYS_CFG(site,func)                     (((site) << 24) | (func))

+

+#define SYS_CFG_RTC                               VIRTUAL_SYS_CFG(ARM_EB_UNSUPPORTED,1)

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/InterruptDxe/InterruptDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/InterruptDxe/InterruptDxe.c
new file mode 100644
index 0000000..0e70e44
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/InterruptDxe/InterruptDxe.c
@@ -0,0 +1,484 @@
+/*++

+

+Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR>

+Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>

+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.

+

+Module Name:

+

+  Gic.c

+

+Abstract:

+

+  Driver implementing the GIC interrupt controller protocol

+

+--*/

+

+#include <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+

+#include <Protocol/Cpu.h>

+#include <Protocol/HardwareInterrupt.h>

+

+

+//

+// EB board definitions

+//

+#define EB_GIC1_CPU_INTF_BASE   0x10040000

+#define EB_GIC1_DIST_BASE       0x10041000

+#define EB_GIC2_CPU_INTF_BASE   0x10050000

+#define EB_GIC2_DIST_BASE       0x10051000

+#define EB_GIC3_CPU_INTF_BASE   0x10060000

+#define EB_GIC3_DIST_BASE       0x10061000

+#define EB_GIC4_CPU_INTF_BASE   0x10070000

+#define EB_GIC5_DIST_BASE       0x10071000

+

+// number of interrupts sources supported by each GIC on the EB

+#define EB_NUM_GIC_INTERRUPTS   96

+

+// number of 32-bit registers needed to represent those interrupts as a bit

+// (used for enable set, enable clear, pending set, pending clear, and active regs)

+#define EB_NUM_GIC_REG_PER_INT_BITS   (EB_NUM_GIC_INTERRUPTS / 32)

+

+// number of 32-bit registers needed to represent those interrupts as two bits

+// (used for configuration reg)

+#define EB_NUM_GIC_REG_PER_INT_CFG    (EB_NUM_GIC_INTERRUPTS / 16)

+

+// number of 32-bit registers needed to represent interrupts as 8-bit priority field

+// (used for priority regs)

+#define EB_NUM_GIC_REG_PER_INT_BYTES  (EB_NUM_GIC_INTERRUPTS / 4)

+

+#define GIC_DEFAULT_PRIORITY  0x80

+

+//

+// GIC definitions

+//

+

+// Distributor

+#define GIC_ICDDCR          0x000 // Distributor Control Register

+#define GIC_ICDICTR         0x004 // Interrupt Controller Type Register

+#define GIC_ICDIIDR         0x008 // Implementer Identification Register

+

+// each reg base below repeats for EB_NUM_GIC_REG_PER_INT_BITS (see GIC spec)

+#define GIC_ICDISR          0x080 // Interrupt Security Registers

+#define GIC_ICDISER         0x100 // Interrupt Set-Enable Registers

+#define GIC_ICDICER         0x180 // Interrupt Clear-Enable Registers

+#define GIC_ICDSPR          0x200 // Interrupt Set-Pending Registers

+#define GIC_ICDCPR          0x280 // Interrupt Clear-Pending Registers

+#define GIC_ICDABR          0x300 // Active Bit Registers

+

+// each reg base below repeats for EB_NUM_GIC_REG_PER_INT_BYTES

+#define GIC_ICDIPR          0x400 // Interrupt Priority Registers

+

+// each reg base below repeats for EB_NUM_GIC_INTERRUPTS

+#define GIC_ICDIPTR         0x800 // Interrupt Processor Target Registers

+#define GIC_ICDICFR         0xC00 // Interrupt Configuration Registers

+

+// just one of these

+#define GIC_ICDSGIR         0xF00 // Software Generated Interrupt Register

+

+

+// Cpu interface

+#define GIC_ICCICR          0x00  // CPU Interface Controler Register

+#define GIC_ICCPMR          0x04  // Interrupt Priority Mask Register

+#define GIC_ICCBPR          0x08  // Binary Point Register

+#define GIC_ICCIAR          0x0C  // Interrupt Acknowledge Register

+#define GIC_ICCEIOR         0x10  // End Of Interrupt Register

+#define GIC_ICCRPR          0x14  // Running Priority Register

+#define GIC_ICCPIR          0x18  // Highest Pending Interrupt Register

+#define GIC_ICCABPR         0x1C  // Aliased Binary Point Register

+#define GIC_ICCIDR          0xFC  // Identification Register

+

+extern EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol;

+

+//

+// Notifications

+//

+VOID      *CpuProtocolNotificationToken = NULL;

+EFI_EVENT CpuProtocolNotificationEvent  = (EFI_EVENT)NULL;

+EFI_EVENT EfiExitBootServicesEvent      = (EFI_EVENT)NULL;

+

+

+HARDWARE_INTERRUPT_HANDLER  gRegisteredInterruptHandlers[EB_NUM_GIC_INTERRUPTS];

+

+/**

+  Register Handler for the specified interrupt source.

+

+  @param This     Instance pointer for this protocol

+  @param Source   Hardware source of the interrupt

+  @param Handler  Callback for interrupt. NULL to unregister

+

+  @retval EFI_SUCCESS Source was updated to support Handler.

+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.

+

+**/

+EFI_STATUS

+EFIAPI

+RegisterInterruptSource (

+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,

+  IN HARDWARE_INTERRUPT_SOURCE          Source,

+  IN HARDWARE_INTERRUPT_HANDLER         Handler

+  )

+{

+  if (Source > EB_NUM_GIC_INTERRUPTS) {

+    ASSERT(FALSE);

+    return EFI_UNSUPPORTED;

+  }

+

+  if ((Handler == NULL) && (gRegisteredInterruptHandlers[Source] == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if ((Handler != NULL) && (gRegisteredInterruptHandlers[Source] != NULL)) {

+    return EFI_ALREADY_STARTED;

+  }

+

+  gRegisteredInterruptHandlers[Source] = Handler;

+  return This->EnableInterruptSource(This, Source);

+}

+

+

+/**

+  Enable interrupt source Source.

+

+  @param This     Instance pointer for this protocol

+  @param Source   Hardware source of the interrupt

+

+  @retval EFI_SUCCESS       Source interrupt enabled.

+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.

+

+**/

+EFI_STATUS

+EFIAPI

+EnableInterruptSource (

+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,

+  IN HARDWARE_INTERRUPT_SOURCE          Source

+  )

+{

+  UINT32    RegOffset;

+  UINTN     RegShift;

+

+  if (Source > EB_NUM_GIC_INTERRUPTS) {

+    ASSERT(FALSE);

+    return EFI_UNSUPPORTED;

+  }

+

+  // calculate enable register offset and bit position

+  RegOffset = Source / 32;

+  RegShift = Source % 32;

+

+  // write set-enable register

+  MmioWrite32 (EB_GIC1_DIST_BASE+GIC_ICDISER+(4*RegOffset), 1 << RegShift);

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Disable interrupt source Source.

+

+  @param This     Instance pointer for this protocol

+  @param Source   Hardware source of the interrupt

+

+  @retval EFI_SUCCESS       Source interrupt disabled.

+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.

+

+**/

+EFI_STATUS

+EFIAPI

+DisableInterruptSource (

+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,

+  IN HARDWARE_INTERRUPT_SOURCE          Source

+  )

+{

+  UINT32    RegOffset;

+  UINTN     RegShift;

+

+  if (Source > EB_NUM_GIC_INTERRUPTS) {

+    ASSERT(FALSE);

+    return EFI_UNSUPPORTED;

+  }

+

+  // calculate enable register offset and bit position

+  RegOffset = Source / 32;

+  RegShift = Source % 32;

+

+  // write set-enable register

+  MmioWrite32 (EB_GIC1_DIST_BASE+GIC_ICDICER+(4*RegOffset), 1 << RegShift);

+

+  return EFI_SUCCESS;

+}

+

+

+

+/**

+  Return current state of interrupt source Source.

+

+  @param This     Instance pointer for this protocol

+  @param Source   Hardware source of the interrupt

+  @param InterruptState  TRUE: source enabled, FALSE: source disabled.

+

+  @retval EFI_SUCCESS       InterruptState is valid

+  @retval EFI_DEVICE_ERROR  InterruptState is not valid

+

+**/

+EFI_STATUS

+EFIAPI

+GetInterruptSourceState (

+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,

+  IN HARDWARE_INTERRUPT_SOURCE          Source,

+  IN BOOLEAN                            *InterruptState

+  )

+{

+  UINT32    RegOffset;

+  UINTN     RegShift;

+

+  if (Source > EB_NUM_GIC_INTERRUPTS) {

+    ASSERT(FALSE);

+    return EFI_UNSUPPORTED;

+  }

+

+  // calculate enable register offset and bit position

+  RegOffset = Source / 32;

+  RegShift = Source % 32;

+

+  if ((MmioRead32 (EB_GIC1_DIST_BASE+GIC_ICDISER+(4*RegOffset)) & (1<<RegShift)) == 0) {

+    *InterruptState = FALSE;

+  } else {

+    *InterruptState = TRUE;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Signal to the hardware that the End Of Intrrupt state

+  has been reached.

+

+  @param This     Instance pointer for this protocol

+  @param Source   Hardware source of the interrupt

+

+  @retval EFI_SUCCESS       Source interrupt EOI'ed.

+  @retval EFI_DEVICE_ERROR  Hardware could not be programmed.

+

+**/

+EFI_STATUS

+EFIAPI

+EndOfInterrupt (

+  IN EFI_HARDWARE_INTERRUPT_PROTOCOL    *This,

+  IN HARDWARE_INTERRUPT_SOURCE          Source

+  )

+{

+  if (Source > EB_NUM_GIC_INTERRUPTS) {

+    ASSERT(FALSE);

+    return EFI_UNSUPPORTED;

+  }

+

+  MmioWrite32 (EB_GIC1_CPU_INTF_BASE+GIC_ICCEIOR, Source);

+  return EFI_SUCCESS;

+}

+

+

+/**

+  EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.

+

+  @param  InterruptType    Defines the type of interrupt or exception that

+                           occurred on the processor.This parameter is processor architecture specific.

+  @param  SystemContext    A pointer to the processor context when

+                           the interrupt occurred on the processor.

+

+  @return None

+

+**/

+VOID

+EFIAPI

+IrqInterruptHandler (

+  IN EFI_EXCEPTION_TYPE           InterruptType,

+  IN EFI_SYSTEM_CONTEXT           SystemContext

+  )

+{

+  UINT32                      GicInterrupt;

+  HARDWARE_INTERRUPT_HANDLER  InterruptHandler;

+

+  GicInterrupt = MmioRead32 (EB_GIC1_CPU_INTF_BASE + GIC_ICCIAR);

+  if (GicInterrupt >= EB_NUM_GIC_INTERRUPTS) {

+    MmioWrite32 (EB_GIC1_CPU_INTF_BASE+GIC_ICCEIOR, GicInterrupt);

+  }

+

+  InterruptHandler = gRegisteredInterruptHandlers[GicInterrupt];

+  if (InterruptHandler != NULL) {

+    // Call the registered interrupt handler.

+    InterruptHandler (GicInterrupt, SystemContext);

+  } else {

+    DEBUG ((EFI_D_ERROR, "Spurious GIC interrupt: %x\n", GicInterrupt));

+  }

+

+  EndOfInterrupt (&gHardwareInterruptProtocol, GicInterrupt);

+}

+

+

+//

+// Making this global saves a few bytes in image size

+//

+EFI_HANDLE  gHardwareInterruptHandle = NULL;

+

+//

+// The protocol instance produced by this driver

+//

+EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol = {

+  RegisterInterruptSource,

+  EnableInterruptSource,

+  DisableInterruptSource,

+  GetInterruptSourceState,

+  EndOfInterrupt

+};

+

+

+/**

+  Shutdown our hardware

+

+  DXE Core will disable interrupts and turn off the timer and disable interrupts

+  after all the event handlers have run.

+

+  @param[in]  Event   The Event that is being processed

+  @param[in]  Context Event Context

+**/

+VOID

+EFIAPI

+ExitBootServicesEvent (

+  IN EFI_EVENT  Event,

+  IN VOID       *Context

+  )

+{

+  UINTN    i;

+

+  for (i = 0; i < EB_NUM_GIC_INTERRUPTS; i++) {

+    DisableInterruptSource (&gHardwareInterruptProtocol, i);

+  }

+}

+

+

+//

+// Notification routines

+//

+VOID

+CpuProtocolInstalledNotification (

+  IN EFI_EVENT   Event,

+  IN VOID        *Context

+  )

+{

+  EFI_STATUS              Status;

+  EFI_CPU_ARCH_PROTOCOL   *Cpu;

+

+  //

+  // Get the cpu protocol that this driver requires.

+  //

+  Status = gBS->LocateProtocol(&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);

+  ASSERT_EFI_ERROR(Status);

+

+  //

+  // Unregister the default exception handler.

+  //

+  Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, NULL);

+  ASSERT_EFI_ERROR(Status);

+

+  //

+  // Register to receive interrupts

+  //

+  Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, IrqInterruptHandler);

+  ASSERT_EFI_ERROR(Status);

+}

+

+/**

+  Initialize the state information for the CPU Architectural Protocol

+

+  @param  ImageHandle   of the loaded driver

+  @param  SystemTable   Pointer to the System Table

+

+  @retval EFI_SUCCESS           Protocol registered

+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure

+  @retval EFI_DEVICE_ERROR      Hardware problems

+

+**/

+EFI_STATUS

+InterruptDxeInitialize (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+  UINTN      i;

+  UINT32      RegOffset;

+  UINTN       RegShift;

+

+

+  // Make sure the Interrupt Controller Protocol is not already installed in the system.

+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gHardwareInterruptProtocolGuid);

+

+  for (i = 0; i < EB_NUM_GIC_INTERRUPTS; i++) {

+    DisableInterruptSource (&gHardwareInterruptProtocol, i);

+

+    // Set Priority

+    RegOffset = i / 4;

+    RegShift = (i % 4) * 8;

+    MmioAndThenOr32 (

+      EB_GIC1_DIST_BASE+GIC_ICDIPR+(4*RegOffset),

+      ~(0xff << RegShift),

+      GIC_DEFAULT_PRIORITY << RegShift

+      );

+  }

+

+  // configure interrupts for cpu 0

+  for (i = 0; i < EB_NUM_GIC_REG_PER_INT_BYTES; i++) {

+    MmioWrite32 (EB_GIC1_DIST_BASE + GIC_ICDIPTR + (i*4), 0x01010101);

+  }

+

+  // set binary point reg to 0x7 (no preemption)

+  MmioWrite32 (EB_GIC1_CPU_INTF_BASE + GIC_ICCBPR, 0x7);

+

+  // set priority mask reg to 0xff to allow all priorities through

+  MmioWrite32 (EB_GIC1_CPU_INTF_BASE + GIC_ICCPMR, 0xff);

+

+  // enable gic cpu interface

+  MmioWrite32 (EB_GIC1_CPU_INTF_BASE + GIC_ICCICR, 0x1);

+

+  // enable gic distributor

+  MmioWrite32 (EB_GIC1_DIST_BASE + GIC_ICCICR, 0x1);

+

+

+  ZeroMem (&gRegisteredInterruptHandlers, sizeof (gRegisteredInterruptHandlers));

+

+  Status = gBS->InstallMultipleProtocolInterfaces (

+                  &gHardwareInterruptHandle,

+                  &gHardwareInterruptProtocolGuid,   &gHardwareInterruptProtocol,

+                  NULL

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  // Set up to be notified when the Cpu protocol is installed.

+  Status = gBS->CreateEvent (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, CpuProtocolInstalledNotification, NULL, &CpuProtocolNotificationEvent);

+  ASSERT_EFI_ERROR (Status);

+

+  Status = gBS->RegisterProtocolNotify (&gEfiCpuArchProtocolGuid, CpuProtocolNotificationEvent, (VOID *)&CpuProtocolNotificationToken);

+  ASSERT_EFI_ERROR (Status);

+

+  // Register for an ExitBootServicesEvent

+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/InterruptDxe/InterruptDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/InterruptDxe/InterruptDxe.inf
new file mode 100644
index 0000000..97739ea
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/InterruptDxe/InterruptDxe.inf
@@ -0,0 +1,53 @@
+#/** @file

+#

+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = GicInterruptDxe

+  FILE_GUID                      = A7496828-946E-43BF-97D6-AA0272001899

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = InterruptDxeInitialize

+

+

+[Sources.common]

+  InterruptDxe.c

+

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  UefiLib

+  UefiBootServicesTableLib

+  DebugLib

+  PrintLib

+  UefiDriverEntryPoint

+  IoLib

+

+[Guids]

+

+

+[Protocols]

+  gHardwareInterruptProtocolGuid

+  gEfiCpuArchProtocolGuid

+

+[FixedPcd.common]

+  gEmbeddedTokenSpaceGuid.PcdInterruptBaseAddress

+

+[depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEb.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEb.c
new file mode 100644
index 0000000..9ffcbee
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEb.c
@@ -0,0 +1,146 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Drivers/PL341Dmc.h>

+#include <Drivers/SP804Timer.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+#include <ArmPlatform.h>

+

+ARM_CORE_INFO mRealViewEbMpCoreInfoTable[] = {

+  {

+    // Cluster 0, Core 0

+    0x0, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 1

+    0x0, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_EB_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  }

+};

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  return BOOT_WITH_FULL_CONFIGURATION;

+}

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // Disable memory remapping and return to normal mapping

+  MmioOr32 (ARM_EB_SYSCTRL, BIT8); //EB_SP810_CTRL_BASE

+

+  // Configure periodic timer (TIMER0) for 1MHz operation

+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);

+  // Configure 1MHz clock

+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);

+  // configure SP810 to use 1MHz clock and disable

+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);

+  // Configure SP810 to use 1MHz clock and disable

+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+  // We do not need to initialize the System Memory on RTSM

+}

+

+EFI_STATUS

+PrePeiCoreGetMpCoreInfo (

+  OUT UINTN                   *CoreCount,

+  OUT ARM_CORE_INFO           **ArmCoreTable

+  )

+{

+  if ((MmioRead32 (ARM_EB_SYS_PROCID0_REG) & ARM_EB_SYS_PROC_ID_MASK) == ARM_EB_SYS_PROC_ID_CORTEX_A9) {

+    *CoreCount    = sizeof(mRealViewEbMpCoreInfoTable) / sizeof(ARM_CORE_INFO);

+    *ArmCoreTable = mRealViewEbMpCoreInfoTable;

+    return EFI_SUCCESS;

+  } else {

+    return EFI_UNSUPPORTED;

+  }

+}

+

+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore

+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;

+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };

+

+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &mArmMpCoreInfoPpiGuid,

+    &mMpCoreInfoPpi

+  }

+};

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  *PpiListSize = sizeof(gPlatformPpiTable);

+  *PpiList = gPlatformPpiTable;

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbHelper.S
new file mode 100644
index 0000000..2978753
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbHelper.S
@@ -0,0 +1,53 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  bx    lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbHelper.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbHelper.asm
new file mode 100644
index 0000000..99a2ed4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbHelper.asm
@@ -0,0 +1,59 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformPeiBootAction

+  EXPORT  ArmPlatformGetCorePosition

+  EXPORT  ArmPlatformIsPrimaryCore

+

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCore

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCoreMask

+

+  AREA    ArmRealViewEbHelper, CODE, READONLY

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ArmPlatformGetCorePosition FUNCTION

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ArmPlatformIsPrimaryCore FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+  ENDFUNC

+

+ArmPlatformPeiBootAction FUNCTION

+  bx    lr

+  ENDFUNC

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLib.inf
new file mode 100644
index 0000000..fa08876
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLib.inf
@@ -0,0 +1,50 @@
+#/* @file

+#  Copyright (c) 2011-2013, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmRealViewEbLib

+  FILE_GUID                      = 736343a0-1d96-11e0-aaaa-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  MemoryAllocationLib

+

+[Sources.common]

+  ArmRealViewEbHelper.asm  | RVCT

+  ArmRealViewEbHelper.S    | GCC

+  ArmRealViewEb.c

+  ArmRealViewEbMem.c

+  ArmRealViewEbHelper.asm | RVCT

+  ArmRealViewEbHelper.S   | GCC

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLibSec.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLibSec.inf
new file mode 100644
index 0000000..bc73400
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbLibSec.inf
@@ -0,0 +1,46 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmRealViewEbLibSec

+  FILE_GUID                      = 5d1013ae-57b8-4a37-87d8-f5bf70e49059

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+

+[Sources.common]

+  ArmRealViewEb.c

+  ArmRealViewEbHelper.asm | RVCT

+  ArmRealViewEbHelper.S   | GCC

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbMem.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbMem.c
new file mode 100644
index 0000000..40055b2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbMem.c
@@ -0,0 +1,116 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/IoLib.h>

+

+#include <ArmPlatform.h>

+

+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          6

+

+// DDR attributes

+#define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK

+#define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  UINT32                        CacheAttributes;

+  UINTN                         Index = 0;

+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;

+

+  ASSERT(VirtualMemoryMap != NULL);

+

+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages (EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));

+  if (VirtualMemoryTable == NULL) {

+      return;

+  }

+

+  if (FeaturePcdGet(PcdCacheEnable) == TRUE) {

+    CacheAttributes = DDR_ATTRIBUTES_CACHED;

+  } else {

+    CacheAttributes = DDR_ATTRIBUTES_UNCACHED;

+  }

+

+  // ReMap (Either NOR Flash or DRAM)

+  VirtualMemoryTable[Index].PhysicalBase = ARM_EB_REMAP_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_EB_REMAP_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_EB_REMAP_SZ;

+  VirtualMemoryTable[Index].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;

+

+  // DDR

+  VirtualMemoryTable[++Index].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);

+  VirtualMemoryTable[Index].VirtualBase  = PcdGet64 (PcdSystemMemoryBase);

+  VirtualMemoryTable[Index].Length       = PcdGet64 (PcdSystemMemorySize);

+  VirtualMemoryTable[Index].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;

+

+  // SMC CS7

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_MB_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_EB_SMB_MB_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_EB_SMB_MB_ON_CHIP_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS0-CS1 - NOR Flash 1 & 2

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_NOR_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_EB_SMB_NOR_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_EB_SMB_NOR_SZ + ARM_EB_SMB_DOC_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS2 - SRAM

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_EB_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_EB_SMB_SRAM_SZ;

+  VirtualMemoryTable[Index].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;

+

+  // SMB CS3-CS6 - Motherboard Peripherals

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_EB_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_EB_SMB_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // If a Logic Tile is connected to The ARM Versatile Express Motherboard

+  if (MmioRead32(ARM_EB_SYS_PROCID1_REG) != 0) {

+      VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_LOGIC_TILE_BASE;

+      VirtualMemoryTable[Index].VirtualBase  = ARM_EB_LOGIC_TILE_BASE;

+      VirtualMemoryTable[Index].Length       = ARM_EB_LOGIC_TILE_SZ;

+      VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+      ASSERT((Index + 1) == (MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS + 1));

+  } else {

+    ASSERT((Index + 1) == MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);

+  }

+

+  // End of Table

+  VirtualMemoryTable[++Index].PhysicalBase = 0;

+  VirtualMemoryTable[Index].VirtualBase  = 0;

+  VirtualMemoryTable[Index].Length       = 0;

+  VirtualMemoryTable[Index].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)0;

+

+  *VirtualMemoryMap = VirtualMemoryTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbBoot.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbBoot.S
new file mode 100644
index 0000000..ba87650
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbBoot.S
@@ -0,0 +1,54 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmPlatformSecLib.h>

+#include <ArmPlatform.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformSecBootAction)

+GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit)

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ASM_PFX(ArmPlatformSecBootAction):

+  LoadConstantToReg (ARM_EB_SYS_FLAGS_NV_REG, r0)

+  ldr   r0, [r0]

+  cmp   r0, #0

+  bxeq  lr

+  bxne  r0

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ASM_PFX(ArmPlatformSecBootMemoryInit):

+  // The SMC does not need to be initialized for RTSM

+  bx    lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbBoot.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbBoot.asm
new file mode 100644
index 0000000..e8bc0cd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbBoot.asm
@@ -0,0 +1,58 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmPlatformSecLib.h>

+#include <ArmPlatform.h>

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformSecBootAction

+  EXPORT  ArmPlatformSecBootMemoryInit

+

+  PRESERVE8

+  AREA    ArmRealviewEbBootMode, CODE, READONLY

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ArmPlatformSecBootAction

+  LoadConstantToReg (ARM_EB_SYS_FLAGS_NV_REG, r0)

+  ldr   r0, [r0]

+  cmp   r0, #0

+  bxeq  lr

+  bxne  r0

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ArmPlatformSecBootMemoryInit

+  // The SMC does not need to be initialized for RTSM

+  bx    lr

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSec.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSec.c
new file mode 100644
index 0000000..e09e33a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSec.c
@@ -0,0 +1,78 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/ArmPlatformSecLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Drivers/PL341Dmc.h>

+#include <Drivers/SP804Timer.h>

+

+#include <ArmPlatform.h>

+

+/**

+  Initialize the Secure peripherals and memory regions

+

+  If Trustzone is supported by your platform then this function makes the required initialization

+  of the secure peripherals and memory regions.

+

+**/

+VOID

+ArmPlatformSecTrustzoneInit (

+  IN  UINTN                     MpId

+  )

+{

+  ASSERT(FALSE);

+}

+

+/**

+  Initialize controllers that must setup at the early stage

+

+  Some peripherals must be initialized in Secure World.

+  For example, some L2x0 requires to be initialized in Secure World

+

+**/

+RETURN_STATUS

+ArmPlatformSecInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  // If it is not the primary core then there is nothing to do

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // Do nothing yet

+  return RETURN_SUCCESS;

+}

+

+/**

+  Call before jumping to Normal World

+

+  This function allows the firmware platform to do extra actions before

+  jumping to the Normal World

+

+**/

+VOID

+ArmPlatformSecExtraAction (

+  IN  UINTN         MpId,

+  OUT UINTN*        JumpAddress

+  )

+{

+  *JumpAddress = (UINTN)PcdGet64 (PcdFvBaseAddress);

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSecLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSecLib.inf
new file mode 100644
index 0000000..11466ac
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbSecLibRTSM/ArmRealViewEbSecLib.inf
@@ -0,0 +1,41 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmRealViewEbSecLib

+  FILE_GUID                      = 6e02ebe0-1d96-11e0-b9cb-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSecLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  ArmPlatformLib

+

+[Sources.common]

+  ArmRealViewEbSec.c

+  ArmRealViewEbBoot.asm     | RVCT

+  ArmRealViewEbBoot.S       | GCC

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.c
new file mode 100644
index 0000000..1dd3153
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.c
@@ -0,0 +1,77 @@
+/** @file

+  Template for ArmEb DebugAgentLib.

+

+  For ARM we reserve FIQ for the Debug Agent Timer. We don't care about

+  laytency as we only really need the timer to run a few times a second

+  (how fast can some one type a ctrl-c?), but it works much better if

+  the interrupt we are using to break into the debugger is not being

+  used, and masked, by the system.

+

+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+

+  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 <Base.h>

+

+#include <Library/DebugAgentTimerLib.h>

+

+

+

+/**

+  Setup all the hardware needed for the debug agents timer.

+

+  This function is used to set up debug enviroment.

+

+**/

+VOID

+EFIAPI

+DebugAgentTimerIntialize (

+  VOID

+  )

+{

+  // Map Timer to FIQ

+}

+

+

+/**

+  Set the period for the debug agent timer. Zero means disable the timer.

+

+  @param[in] TimerPeriodMilliseconds    Frequency of the debug agent timer.

+

+**/

+VOID

+EFIAPI

+DebugAgentTimerSetPeriod (

+  IN  UINT32  TimerPeriodMilliseconds

+  )

+{

+  if (TimerPeriodMilliseconds == 0) {

+    // Disable timer and Disable FIQ

+    return;

+  }

+

+  // Set timer period and unmask FIQ

+}

+

+

+/**

+  Perform End Of Interrupt for the debug agent timer. This is called in the

+  interrupt handler after the interrupt has been processed.

+

+**/

+VOID

+EFIAPI

+DebugAgentTimerEndOfInterrupt (

+  VOID

+  )

+{

+  // EOI Timer interrupt for FIQ

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf
new file mode 100644
index 0000000..38642fd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf
@@ -0,0 +1,38 @@
+#/** @file

+# Component description file for Base PCI Cf8 Library.

+#

+# PCI CF8 Library that uses I/O ports 0xCF8 and 0xCFC to perform PCI Configuration cycles.

+#  Layers on top of an I/O Library instance.

+# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmEbDebugAgentTimerLib

+  FILE_GUID                      = 80949BBB-68EE-4a4c-B434-D5DB5A232F0C

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = DebugAgentTimerLib|SEC BASE DXE_CORE

+

+

+[Sources.common]

+  DebugAgentTimerLib.c

+

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dec

+

+[LibraryClasses]

+  IoLib

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c
new file mode 100644
index 0000000..6d2892f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.c
@@ -0,0 +1,118 @@
+/** @file

+  Basic serial IO abstaction for GDB

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+

+  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 <Uefi.h>

+#include <Library/GdbSerialLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+#include <Drivers/PL011Uart.h>

+

+RETURN_STATUS

+EFIAPI

+GdbSerialLibConstructor (

+  VOID

+  )

+{

+  return GdbSerialInit (115200, 0, 8, 1);

+}

+

+RETURN_STATUS

+EFIAPI

+GdbSerialInit (

+  IN UINT64     BaudRate,

+  IN UINT8      Parity,

+  IN UINT8      DataBits,

+  IN UINT8      StopBits

+  )

+{

+  if ((Parity != 0) || (DataBits != 8) || (StopBits != 1)) {

+    return RETURN_UNSUPPORTED;

+  }

+

+  if (BaudRate != 115200) {

+    // Could add support for different Baud rates....

+    return RETURN_UNSUPPORTED;

+  }

+

+  UINT32  Base = PcdGet32 (PcdGdbUartBase);

+

+  // initialize baud rate generator to 115200 based on EB clock REFCLK24MHZ

+  MmioWrite32 (Base + UARTIBRD, UART_115200_IDIV);

+  MmioWrite32 (Base + UARTFBRD, UART_115200_FDIV);

+

+  // no parity, 1 stop, no fifo, 8 data bits

+  MmioWrite32 (Base + UARTLCR_H, 0x60);

+

+  // clear any pending errors

+  MmioWrite32 (Base + UARTECR, 0);

+

+  // enable tx, rx, and uart overall

+  MmioWrite32 (Base + UARTCR, 0x301);

+

+  return RETURN_SUCCESS;

+}

+

+BOOLEAN

+EFIAPI

+GdbIsCharAvailable (

+  VOID

+  )

+{

+  UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;

+

+  if ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0) {

+    return TRUE;

+  } else {

+    return FALSE;

+  }

+}

+

+CHAR8

+EFIAPI

+GdbGetChar (

+  VOID

+  )

+{

+  UINT32  FR = PcdGet32 (PcdGdbUartBase) + UARTFR;

+  UINT32  DR = PcdGet32 (PcdGdbUartBase) + UARTDR;

+

+  while ((MmioRead32 (FR) & UART_RX_EMPTY_FLAG_MASK) == 0);

+  return MmioRead8 (DR);

+}

+

+VOID

+EFIAPI

+GdbPutChar (

+  IN  CHAR8   Char

+  )

+{

+  UINT32 FR = PcdGet32 (PcdGdbUartBase) + UARTFR;

+  UINT32 DR = PcdGet32 (PcdGdbUartBase) + UARTDR;

+

+  while ((MmioRead32 (FR) & UART_TX_EMPTY_FLAG_MASK) != 0);

+  MmioWrite8 (DR, Char);

+  return;

+}

+

+VOID

+GdbPutString (

+  IN CHAR8  *String

+  )

+{

+  while (*String != '\0') {

+    GdbPutChar (*String);

+    String++;

+  }

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.inf
new file mode 100644
index 0000000..38448ce
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/GdbSerialLib/GdbSerialLib.inf
@@ -0,0 +1,39 @@
+#/** @file

+#

+#  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = GdbSerialLib

+  FILE_GUID                      = E8EA1309-2F14-428f-ABE3-7016CE4B4305

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = GdbSerialLib

+

+  CONSTRUCTOR                    = GdbSerialLibConstructor

+

+

+[Sources.common]

+  GdbSerialLib.c

+

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  IoLib

+

+[FixedPcd]

+  gArmRealViewEbPkgTokenSpaceGuid.PcdGdbUartBase

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEb.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEb.c
new file mode 100644
index 0000000..33524c0
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEb.c
@@ -0,0 +1,54 @@
+/** @file

+

+ Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+

+ 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 <PiDxe.h>

+#include <Library/NorFlashPlatformLib.h>

+#include <ArmPlatform.h>

+

+#define NOR_FLASH_DEVICE_COUNT                     1

+

+// RTSM

+NOR_FLASH_DESCRIPTION mNorFlashDevices[NOR_FLASH_DEVICE_COUNT] = {

+  { // UEFI

+    ARM_EB_SMB_NOR_BASE,

+    ARM_EB_SMB_NOR_BASE,

+    SIZE_128KB * 512,

+    SIZE_128KB,

+    {0xE7223039, 0x5836, 0x41E1, { 0xB5, 0x42, 0xD7, 0xEC, 0x73, 0x6C, 0x5E, 0x59 } }

+  }

+};

+

+EFI_STATUS

+NorFlashPlatformInitialization (

+  VOID

+  )

+{

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+NorFlashPlatformGetDevices (

+  OUT NOR_FLASH_DESCRIPTION   **NorFlashDevices,

+  OUT UINT32                  *Count

+  )

+{

+  if ((NorFlashDevices == NULL) || (Count == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *NorFlashDevices = mNorFlashDevices;

+  *Count = NOR_FLASH_DEVICE_COUNT;

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEbLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEbLib.inf
new file mode 100644
index 0000000..5f8c5c6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/NorFlashArmRealViewEbLib/NorFlashArmRealViewEbLib.inf
@@ -0,0 +1,35 @@
+#/** @file

+#

+#  Component description file for NorFlashArmRealViewEbLib module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = NorFlashArmRealViewEbLib

+  FILE_GUID                      = a3a49a60-7597-11e0-b07c-0002a5d5c51b

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = NorFlashPlatformLib

+

+[Sources.common]

+  NorFlashArmRealViewEb.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  IoLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEb.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEb.c
new file mode 100644
index 0000000..8b1a49b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEb.c
@@ -0,0 +1,232 @@
+/** @file

+

+  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>

+  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 <PiDxe.h>

+

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/LcdPlatformLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#include <Protocol/EdidDiscovered.h>

+#include <Protocol/EdidActive.h>

+

+#include <Drivers/PL111Lcd.h>

+

+#include <ArmPlatform.h>

+

+typedef struct {

+  UINT32                     Mode;

+  UINT32                     HorizontalResolution;

+  UINT32                     VerticalResolution;

+  LCD_BPP                    Bpp;

+  UINT32                     ClcdClk;

+

+  UINT32                     HSync;

+  UINT32                     HBackPorch;

+  UINT32                     HFrontPorch;

+  UINT32                     VSync;

+  UINT32                     VBackPorch;

+  UINT32                     VFrontPorch;

+} CLCD_RESOLUTION;

+

+

+CLCD_RESOLUTION mResolutions[] = {

+  { // Mode 0 : VGA : 640 x 480 x 24 bpp

+      VGA, VGA_H_RES_PIXELS, VGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, 0x2C77,

+      VGA_H_SYNC, VGA_H_BACK_PORCH, VGA_H_FRONT_PORCH,

+      VGA_V_SYNC, VGA_V_BACK_PORCH, VGA_V_FRONT_PORCH

+  },

+  { // Mode 1 : SVGA : 800 x 600 x 24 bpp

+      SVGA, SVGA_H_RES_PIXELS, SVGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, 0x2CAC,

+      SVGA_H_SYNC, SVGA_H_BACK_PORCH, SVGA_H_FRONT_PORCH,

+      SVGA_V_SYNC, SVGA_V_BACK_PORCH, SVGA_V_FRONT_PORCH

+  }

+};

+

+EFI_EDID_DISCOVERED_PROTOCOL  mEdidDiscovered = {

+  0,

+  NULL

+};

+

+EFI_EDID_ACTIVE_PROTOCOL      mEdidActive = {

+  0,

+  NULL

+};

+

+EFI_STATUS

+LcdPlatformInitializeDisplay (

+  IN EFI_HANDLE   Handle

+  )

+{

+  EFI_STATUS  Status;

+

+  MmioWrite32(ARM_EB_SYS_CLCD_REG, 1);

+

+  // Install the EDID Protocols

+  Status = gBS->InstallMultipleProtocolInterfaces(

+    &Handle,

+    &gEfiEdidDiscoveredProtocolGuid,  &mEdidDiscovered,

+    &gEfiEdidActiveProtocolGuid,      &mEdidActive,

+    NULL

+  );

+

+  return Status;

+}

+

+EFI_STATUS

+LcdPlatformGetVram (

+  OUT EFI_PHYSICAL_ADDRESS*  VramBaseAddress,

+  OUT UINTN*                 VramSize

+  )

+{

+  *VramBaseAddress = PL111_CLCD_VRAM_BASE;

+  *VramSize = SIZE_8MB; //FIXME: Can this size change ?

+  return EFI_SUCCESS;

+}

+

+UINT32

+LcdPlatformGetMaxMode (

+  VOID

+  )

+{

+  return (sizeof(mResolutions) / sizeof(CLCD_RESOLUTION));

+}

+

+EFI_STATUS

+LcdPlatformSetMode (

+  IN UINT32                         ModeNumber

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  MmioWrite32(ARM_EB_SYS_LOCK_REG,0x0000A05F);

+  MmioWrite32(ARM_EB_SYS_OSC4_REG,mResolutions[ModeNumber].ClcdClk);

+  MmioWrite32(ARM_EB_SYS_LOCK_REG,0x0);

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdPlatformQueryMode (

+  IN  UINT32                                ModeNumber,

+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info

+  )

+{

+  EFI_STATUS    Status;

+

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Status = EFI_UNSUPPORTED;

+

+  Info->Version = 0;

+  Info->HorizontalResolution = mResolutions[ModeNumber].HorizontalResolution;

+  Info->VerticalResolution = mResolutions[ModeNumber].VerticalResolution;

+  Info->PixelsPerScanLine = mResolutions[ModeNumber].HorizontalResolution;

+

+  switch (mResolutions[ModeNumber].Bpp) {

+    case LCD_BITS_PER_PIXEL_24:

+      Info->PixelFormat                   = PixelRedGreenBlueReserved8BitPerColor;

+      Info->PixelInformation.RedMask      = LCD_24BPP_RED_MASK;

+      Info->PixelInformation.GreenMask    = LCD_24BPP_GREEN_MASK;

+      Info->PixelInformation.BlueMask     = LCD_24BPP_BLUE_MASK;

+      Info->PixelInformation.ReservedMask = LCD_24BPP_RESERVED_MASK;

+      Status = EFI_SUCCESS;

+      break;

+

+    case LCD_BITS_PER_PIXEL_16_555:

+      Info->PixelFormat                   = PixelBitMask;

+      Info->PixelInformation.RedMask      = LCD_16BPP_555_RED_MASK;

+      Info->PixelInformation.GreenMask    = LCD_16BPP_555_GREEN_MASK;

+      Info->PixelInformation.BlueMask     = LCD_16BPP_555_BLUE_MASK;

+      Info->PixelInformation.ReservedMask = LCD_16BPP_555_RESERVED_MASK;

+      Status = EFI_SUCCESS;

+      break;

+

+    case LCD_BITS_PER_PIXEL_16_565:

+      Info->PixelFormat                   = PixelBitMask;

+      Info->PixelInformation.RedMask      = LCD_16BPP_565_RED_MASK;

+      Info->PixelInformation.GreenMask    = LCD_16BPP_565_GREEN_MASK;

+      Info->PixelInformation.BlueMask     = LCD_16BPP_565_BLUE_MASK;

+      Info->PixelInformation.ReservedMask = LCD_16BPP_565_RESERVED_MASK;

+      Status = EFI_SUCCESS;

+      break;

+

+    case LCD_BITS_PER_PIXEL_12_444:

+      Info->PixelFormat                   = PixelBitMask;

+      Info->PixelInformation.RedMask      = LCD_12BPP_444_RED_MASK;

+      Info->PixelInformation.GreenMask    = LCD_12BPP_444_GREEN_MASK;

+      Info->PixelInformation.BlueMask     = LCD_12BPP_444_BLUE_MASK;

+      Info->PixelInformation.ReservedMask = LCD_12BPP_444_RESERVED_MASK;

+      Status = EFI_SUCCESS;

+      break;

+

+    case LCD_BITS_PER_PIXEL_8:

+    case LCD_BITS_PER_PIXEL_4:

+    case LCD_BITS_PER_PIXEL_2:

+    case LCD_BITS_PER_PIXEL_1:

+    default:

+      // These are not supported

+      break;

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+LcdPlatformGetTimings (

+  IN  UINT32                              ModeNumber,

+  OUT UINT32*                             HRes,

+  OUT UINT32*                             HSync,

+  OUT UINT32*                             HBackPorch,

+  OUT UINT32*                             HFrontPorch,

+  OUT UINT32*                             VRes,

+  OUT UINT32*                             VSync,

+  OUT UINT32*                             VBackPorch,

+  OUT UINT32*                             VFrontPorch

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *HRes           = mResolutions[ModeNumber].HorizontalResolution;

+  *HSync          = mResolutions[ModeNumber].HSync;

+  *HBackPorch     = mResolutions[ModeNumber].HBackPorch;

+  *HFrontPorch    = mResolutions[ModeNumber].HFrontPorch;

+  *VRes           = mResolutions[ModeNumber].VerticalResolution;

+  *VSync          = mResolutions[ModeNumber].VSync;

+  *VBackPorch     = mResolutions[ModeNumber].VBackPorch;

+  *VFrontPorch    = mResolutions[ModeNumber].VFrontPorch;

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdPlatformGetBpp (

+  IN  UINT32                              ModeNumber,

+  OUT LCD_BPP  *                          Bpp

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *Bpp = mResolutions[ModeNumber].Bpp;

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEbLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEbLib.inf
new file mode 100644
index 0000000..b94936b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEbLib.inf
@@ -0,0 +1,65 @@
+#/** @file

+#

+#  Component description file for ArmRealViewGraphicsDxe module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = PL111LcdArmRealViewEbLib

+  FILE_GUID                      = 51396ee0-4973-11e0-868a-0002a5d5c51b

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PL111LcdPlatformLib

+

+[Sources.common]

+  PL111LcdArmRealViewEb.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  IoLib

+

+[Guids]

+

+[Protocols]

+  gEfiEdidDiscoveredProtocolGuid                # Produced

+  gEfiEdidActiveProtocolGuid                    # Produced

+

+[FixedPcd.common]

+

+  #

+  # The following modes are supported by PL111

+  #

+  #    0 :  640 x 480 x 24 bpp

+  #    1 :  800 x 600 x 24 bpp

+  #    2 : 1024 x 768 x 24 bpp

+  #    3 :  640 x 480 x 16 bpp (565 RGB Mode)

+  #    4 :  800 x 600 x 16 bpp (565 RGB Mode)

+  #    5 : 1024 x 768 x 16 bpp (565 RGB Mode)

+  #    6 :  640 x 480 x 15 bpp (555 RGB Mode)

+  #    7 :  800 x 600 x 15 bpp (555 RGB Mode)

+  #    8 : 1024 x 768 x 15 bpp (555 RGB Mode)

+  #    9 : 1024 x 768 x 15 bpp (555 RGB Mode) - Linux driver settings

+  #   10 :  640 x 480 x 12 bpp (444 RGB Mode)

+  #   11 :  800 x 600 x 12 bpp (444 RGB Mode)

+  #   12 : 1024 x 768 x 12 bpp (444 RGB Mode)

+  #

+

+[Pcd.common]

+

+[Depex]

+ # gEfiCpuArchProtocolGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ResetSystemLib/ResetSystemLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ResetSystemLib/ResetSystemLib.c
new file mode 100644
index 0000000..1bcc481
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ResetSystemLib/ResetSystemLib.c
@@ -0,0 +1,87 @@
+/** @file

+  Template library implementation to support ResetSystem Runtime call.

+

+  Fill in the templates with what ever makes you system reset.

+

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+

+  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 <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/PcdLib.h>

+#include <Library/DebugLib.h>

+#include <Library/EfiResetSystemLib.h>

+#include <Drivers/PL011Uart.h>

+

+/**

+  Resets the entire platform.

+

+  @param  ResetType             The type of reset to perform.

+  @param  ResetStatus           The status code for the reset.

+  @param  DataSize              The size, in bytes, of WatchdogData.

+  @param  ResetData             For a ResetType of EfiResetCold, EfiResetWarm, or

+                                EfiResetShutdown the data buffer starts with a Null-terminated

+                                Unicode string, optionally followed by additional binary data.

+

+**/

+EFI_STATUS

+EFIAPI

+LibResetSystem (

+  IN EFI_RESET_TYPE   ResetType,

+  IN EFI_STATUS       ResetStatus,

+  IN UINTN            DataSize,

+  IN CHAR16           *ResetData OPTIONAL

+  )

+{

+  if (ResetData != NULL) {

+    DEBUG ((EFI_D_ERROR, "%s", ResetData));

+  }

+

+  switch (ResetType) {

+  case EfiResetWarm:

+    // Map a warm reset into a cold reset

+  case EfiResetCold:

+  case EfiResetShutdown:

+  default:

+    CpuDeadLoop ();

+    break;

+  }

+

+  // If the reset didn't work, return an error.

+  ASSERT (FALSE);

+  return EFI_DEVICE_ERROR;

+}

+

+

+

+/**

+  Initialize any infrastructure required for LibResetSystem () to function.

+

+  @param  ImageHandle   The firmware allocated handle for the EFI image.

+  @param  SystemTable   A pointer to the EFI System Table.

+

+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.

+

+**/

+EFI_STATUS

+EFIAPI

+LibInitializeResetSystem (

+  IN EFI_HANDLE        ImageHandle,

+  IN EFI_SYSTEM_TABLE  *SystemTable

+  )

+{

+  return EFI_SUCCESS;

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ResetSystemLib/ResetSystemLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ResetSystemLib/ResetSystemLib.inf
new file mode 100644
index 0000000..18a1203
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/Library/ResetSystemLib/ResetSystemLib.inf
@@ -0,0 +1,35 @@
+#/** @file

+# Reset System lib to make it easy to port new platforms

+#

+# Copyright (c) 2008, Apple Inc. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmEbResetSystemLib

+  FILE_GUID                      = CEFFA65C-B568-453e-9E11-B81AE683D035

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = EfiResetSystemLib

+

+

+[Sources.common]

+  ResetSystemLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  BaseLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/b.bat b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/b.bat
new file mode 100644
index 0000000..28aab38
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/b.bat
@@ -0,0 +1,43 @@
+@REM Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+@REM This program and the accompanying materials

+@REM are licensed and made available under the terms and conditions of the BSD License

+@REM which accompanies this distribution.  The full text of the license may be found at

+@REM http://opensource.org/licenses/bsd-license.php

+@REM

+@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

+@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

+@REM

+

+@REM Example usage of this script. default is a DEBUG build

+@REM b

+@REM b clean

+@REM b release 

+@REM b release clean

+@REM b -v -y build.log

+

+ECHO OFF

+@REM Setup Build environment. Sets WORKSPACE and puts build in path

+CALL ..\edksetup.bat

+

+@REM Set for tools chain. Currently RVCT31

+SET TARGET_TOOLS=RVCT31

+SET TARGET=DEBUG

+

+@if /I "%1"=="RELEASE" (

+  @REM If 1st argument is release set TARGET to RELEASE and shift arguments to remove it 

+  SET TARGET=RELEASE

+  shift /1

+)

+

+SET BUILD_ROOT=%WORKSPACE%\Build\ArmRealViewEb\%TARGET%_%TARGET_TOOLS%

+

+@REM Build the ARM RealView EB firmware and creat an FD (FLASH Device) Image.

+CALL build -p ArmRealViewEbPkg\ArmRealViewEbPkg.dsc -a ARM -t RVCT31 -b %TARGET% %1 %2 %3 %4 %5 %6 %7 %8

+@if ERRORLEVEL 1 goto Exit

+

+@if /I "%1"=="CLEAN" goto Clean

+

+:Exit

+EXIT /B

+

+:Clean

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ba.bat b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ba.bat
new file mode 100644
index 0000000..6ec1cbe
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/ba.bat
@@ -0,0 +1,56 @@
+@REM Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+@REM This program and the accompanying materials

+@REM are licensed and made available under the terms and conditions of the BSD License

+@REM which accompanies this distribution.  The full text of the license may be found at

+@REM http://opensource.org/licenses/bsd-license.php

+@REM

+@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

+@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

+@REM

+

+@REM Example usage of this script. default is a DEBUG build

+@REM b

+@REM b clean

+@REM b release 

+@REM b release clean

+@REM b -v -y build.log

+

+ECHO OFF

+@REM Setup Build environment. Sets WORKSPACE and puts build in path

+CALL ..\edksetup.bat

+

+@REM Set for tools chain. Currently ARMGCC

+SET TARGET_TOOLS=ARMGCC

+SET TARGET=DEBUG

+

+

+@if /I "%1"=="RELEASE" (

+

+  @REM If 1st argument is release set TARGET to RELEASE and shift arguments to remove it 

+

+  SET TARGET=RELEASE

+

+  shift /1

+

+)

+

+

+SET BUILD_ROOT=%WORKSPACE%\Build\ArmRealViewEb\%TARGET%_%TARGET_TOOLS%

+

+@REM Build the ARM RealView EB firmware and creat an FD (FLASH Device) Image.

+CALL build -p ArmRealViewEbPkg\ArmRealViewEbPkg.dsc -a ARM -t %TARGET_TOOLS% -b %TARGET% %1 %2 %3 %4 %5 %6 %7 %8

+@if ERRORLEVEL 1 goto Exit

+

+@if /I "%1"=="CLEAN" goto Clean

+

+

+ECHO Patching ..\Debugger_scripts ...

+SET DEBUGGER_SCRIPT=Debugger_scripts

+@for /f %%a IN ('dir /b %DEBUGGER_SCRIPT%\*.inc %DEBUGGER_SCRIPT%\*.cmm') do (

+  @CALL replace %DEBUGGER_SCRIPT%\%%a %BUILD_ROOT%\%%a ZZZZZZ %BUILD_ROOT% WWWWWW  %WORKSPACE%

+)

+

+:Exit

+EXIT /B

+

+:Clean

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/build.sh b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/build.sh
new file mode 100644
index 0000000..89b176e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmRealViewEbPkg/build.sh
@@ -0,0 +1,118 @@
+#!/bin/bash
+# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+# 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.
+#
+
+set -e
+shopt -s nocasematch
+
+function process_debug_scripts {
+  if [[ -d $1 ]]; then
+    for filename in `ls $1`
+    do
+      sed -e "s@ZZZZZZ@$BUILD_ROOT@g" -e "s@WWWWWW@$WORKSPACE@g" \
+            "$1/$filename" \
+            > "$BUILD_ROOT/$filename"
+
+      #For ARMCYGWIN, we have to change /cygdrive/c to c:
+      if [[ $TARGET_TOOLS == RVCT31CYGWIN ]]
+      then
+        mv "$BUILD_ROOT/$filename" "$BUILD_ROOT/$filename"_temp
+        sed -e "s@/cygdrive/\(.\)@\1:@g" \
+              "$BUILD_ROOT/$filename"_temp \
+              > "$BUILD_ROOT/$filename"
+        rm -f "$BUILD_ROOT/$filename"_temp
+      fi
+    done
+  fi
+}
+
+
+#
+# Setup workspace if it is not set
+#
+if [ -z "$WORKSPACE" ]
+then
+  echo Initializing workspace
+  cd ..
+  export EDK_TOOLS_PATH=`pwd`/BaseTools
+  source edksetup.sh BaseTools
+else
+  echo Building from: $WORKSPACE
+fi
+
+#
+# Pick a default tool type for a given OS
+#
+case `uname` in
+  CYGWIN*) 
+      TARGET_TOOLS=RVCT31CYGWIN 
+      ;;
+  Linux*)  
+      # Not tested
+      TARGET_TOOLS=ARMGCC 
+      ;;
+  Darwin*) 
+      Major=$(uname -r | cut -f 1 -d '.')
+      if [[ $Major == 9 ]]
+      then
+        # Not supported by this open source project
+        TARGET_TOOLS=XCODE31
+      else 
+        TARGET_TOOLS=XCODE32
+      fi  
+      ;;
+esac
+
+TARGET=DEBUG
+for arg in "$@"
+do
+  if [[ $arg == RELEASE ]]; 
+  then
+    TARGET=RELEASE
+  fi
+done
+
+BUILD_ROOT=$WORKSPACE/Build/ArmRealViewEb/"$TARGET"_"$TARGET_TOOLS"
+
+if  [[ ! -e $EDK_TOOLS_PATH/Source/C/bin ]];
+then
+  # build the tools if they don't yet exist
+  echo Building tools: $EDK_TOOLS_PATH
+  make -C $EDK_TOOLS_PATH
+else
+  echo using prebuilt tools
+fi
+
+#
+# Build the edk2 ArmEb code
+#
+if [[ $TARGET == RELEASE ]]; then
+  build -p $WORKSPACE/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dsc -a ARM -t $TARGET_TOOLS -b $TARGET -D DEBUG_TARGET=RELEASE $2 $3 $4 $5 $6 $7 $8
+else
+  build -p $WORKSPACE/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEbPkg.dsc -a ARM -t $TARGET_TOOLS -b $TARGET $1 $2 $3 $4 $5 $6 $7 $8
+fi
+
+
+for arg in "$@"
+do
+  if [[ $arg == clean ]]; then
+    # no need to post process if we are doing a clean
+    exit
+  elif [[ $arg == cleanall ]]; then
+    make -C $EDK_TOOLS_PATH clean
+    exit
+    
+  fi
+done
+
+
+echo Creating debugger scripts
+process_debug_scripts $WORKSPACE/ArmPlatformPkg/ArmRealViewEbPkg/Debugger_scripts
+
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.dsc
new file mode 100644
index 0000000..521f4ed
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.dsc
@@ -0,0 +1,289 @@
+#

+#  Copyright (c) 2012-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpressPkg-CTA15-A7

+  PLATFORM_GUID                  = 0b511920-978d-4b34-acc0-3d9f8e6f9d81

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-CTA15-A7

+  SUPPORTED_ARCHITECTURES        = ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.fdf

+  DEFINE EDK2_SKIP_PEICORE=1

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/ArmVExpressLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+

+  #DebugAgentTimerLib|ArmPlatformPkg/ArmVExpressPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf

+

+  # ARM General Interrupt Driver in Secure and Non-secure

+  ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf

+

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpressLib.inf

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+  ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf

+

+[BuildOptions]

+!ifdef ARM_BIGLITTLE_TC2

+  *_*_ARM_ARCHCC_FLAGS  = -DARM_BIGLITTLE_TC2=1

+  *_*_ARM_PP_FLAGS  = -DARM_BIGLITTLE_TC2=1

+!endif

+

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA15-A7

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA15-A7

+

+  XCODE:*_*_ARM_PLATFORM_FLAGS = -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA15-A7

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Versatile Express"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmVExpress-CTA15-A7"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|5

+

+  #

+  # NV Storage PCDs. Use base of 0x0C000000 for NOR1

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FFC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FFD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FFE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # Stacks for MPCores in Secure World

+  # SRAM (CS1) is only available between 0x14000000 and 0x14001000 on the model

+  # ZBT SRAM is available between 0x2E000000 and 0x2E010000 on the model

+!ifdef ARM_BIGLITTLE_TC2

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x17000000

+!else

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x2E000000

+!endif

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x8000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecSecondaryStackSize|0x1000

+  # Share Monitor stacks with Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize|0

+

+  # System Memory (1GB) - An additional 1GB will be added if UEFI is running on a 2GB Test Chip

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x40000000

+

+!ifdef ARM_BIGLITTLE_TC2

+  # TC2 Dual-Cluster profile

+  gArmPlatformTokenSpaceGuid.PcdClusterCount|2

+

+  # Core Ids and Gic values

+  # A15_0 = 0x000, GicCoreId = 0

+  # A15_1 = 0x001, GicCoreId = 1

+  #  A7_0 = 0x100, GicCoreId = 2

+  #  A7_1 = 0x101, GicCoreId = 3

+  #  A7_2 = 0x102, GicCoreId = 4

+  gArmTokenSpaceGuid.PcdArmPrimaryCore|0x100

+!endif

+

+  #

+  # SEC Phase Global Variables :

+  # - 0x00-0x04: Debugger Exception Handler Pointer address

+  # - 0x04-0x08: Normal Exception Handler Pointer

+  # - 0x0C-0x10: MpSafe Serial Console SpinLock

+  # - 0x10-0x20: KfScb 8 Bakery Locks of 2Bytes each

+  # - 0x20-0x30: CCI 8 Bakery Locks of 2Bytes each

+  # - 0x30-0x48: ARM SMC Events (8 cores * 3 max_event * sizeof(UINT8))

+  gArmPlatformTokenSpaceGuid.PcdSecGlobalVariableSize|0x48

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## SP805 Watchdog - Motherboard Watchdog

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x1C0F0000

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x1C090000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x1C170000

+

+!ifdef ARM_BIGLITTLE_TC2

+  ## PL111 Lcd & HdLcd

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x1C1F0000

+  gArmPlatformTokenSpaceGuid.PcdArmHdLcdBase|0x2B000000

+  gArmVExpressTokenSpaceGuid.PcdHdLcdVideoModeOscId|5

+!endif

+

+  #

+  # PL180 MMC/SD card controller

+  #

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x1C010048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x1C050000

+

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C002000

+

+  # ISP1761 USB OTG Controller

+  gEmbeddedTokenSpaceGuid.PcdIsp1761BaseAddress|0x1B000000

+

+  # Ethernet (SMSC LAN9118)

+  gEmbeddedTokenSpaceGuid.PcdLan9118DxeBaseAddress|0x1A000000

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmTokenSpaceGuid.PcdArmMachineType|2272

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux from NorFlash"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(1F15DA3C-37FF-4070-B471-BB4AF12A724A)/MemoryMapped(0x0,0xE000000,0xE800000)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"console=ttyAMA0,38400 earlyprintk debug verbose"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(1F15DA3C-37FF-4070-B471-BB4AF12A724A)/MemoryMapped(0x0,0x0E800000,0x0E803000)"

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  # PL111 - CLCD

+  #gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  # HDLCD

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(CE660500-824D-11E0-AC72-0002A5D5C51B)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM Architectural Timer Frequency

+  #

+!ifdef ARM_BIGLITTLE_TC2

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|24000000

+!else

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|10000000

+!endif

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+  #

+  # PEI Phase modules

+  #

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/ArmVExpressLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  #ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcdGraphicsOutputDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Platform

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.inf

+

+  #

+  # Filesystems

+  #

+!ifndef ARM_BIGLITTLE_TC2

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+!endif

+

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  # SMSC LAN 9118

+  EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.fdf
new file mode 100644
index 0000000..323be8a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.fdf
@@ -0,0 +1,307 @@
+#

+#  Copyright (c) 2012-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.ARM_VEXPRESS_CTA15A7_EFI]

+BaseAddress   = 0xB0000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in remapped DRAM.

+Size          = 0x000B8000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+BlockSize     = 0x00001000

+NumBlocks     = 0xB8

+

+0x00000000|0x000B8000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  #INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcdGraphicsOutputDxe.inf

+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Platform

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Filesystems

+  #

+!ifndef $(ARM_BIGLITTLE_TC2)

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+!endif

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  # Versatile Express FileSystem

+  INF ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf

+

+  #

+  # USB support

+  #

+  INF EmbeddedPkg/Drivers/Isp1761UsbDxe/Isp1761UsbDxe.inf

+

+  #

+  # Android Fastboot

+  #

+  INF EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf

+  INF EmbeddedPkg/Drivers/AndroidFastbootTransportUsbDxe/FastbootTransportUsbDxe.inf

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBootDxe.inf

+

+  # ACPI Support

+  INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf

+

+  #

+  # Networking stack

+  #

+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

+  INF EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.inf

+

+  #

+  # UEFI application

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvBaseAddress      = 0xB0000000

+FvForceRebase      = TRUE

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc
new file mode 100644
index 0000000..8377479
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc
@@ -0,0 +1,314 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpressPkg-CTA9x4

+  PLATFORM_GUID                  = eb2bd5ff-2379-4a06-9c12-db905cdee9ea

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  SUPPORTED_ARCHITECTURES        = ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.fdf

+

+  # Reflashing the NOR Flash is a slow process. To ease the development on ARM Versatile Express Cortex-A9x4,

+  # the UEFI firmware can be built to be started from DRAM (instead of NOR Flash).

+  # The engineer only needs to copy the new binary in DRAM with the hardware debugger and execute from there.

+!ifndef EDK2_ARMVE_STANDALONE

+  DEFINE EDK2_ARMVE_STANDALONE=1

+!endif

+!if $(EDK2_ARMVE_STANDALONE) == 1

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-CTA9x4-Standalone

+!else

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-CTA9x4

+!endif

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLib.inf

+  ArmTrustZoneLib|ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.inf

+

+  # ARM PL310 L2 Cache Driver

+  L2X0CacheLib|ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2CacheSec.inf

+  # ARM PL354 SMC Driver

+  PL35xSmcLib|ArmPlatformPkg/Drivers/PL35xSmc/PL35xSmc.inf

+  # ARM PL341 DMC Driver

+  PL341DmcLib|ArmPlatformPkg/Drivers/PL34xDmc/PL341Dmc.inf

+  # ARM PL301 Axi Driver

+  PL301AxiLib|ArmPlatformPkg/Drivers/PL301Axi/PL301Axi.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/ArmVExpressSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLibSec.inf

+

+  # Uncomment to turn on GDB stub in SEC.

+  #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf

+

+[BuildOptions]

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A9 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA9x4

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a9 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA9x4

+

+  XCODE:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a9 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA9x4

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+!if $(EDK2_ARMVE_STANDALONE) == 1

+  gArmPlatformTokenSpaceGuid.PcdStandalone|TRUE

+!else

+  gArmPlatformTokenSpaceGuid.PcdStandalone|FALSE

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+!ifdef EDK2_SKIP_PEICORE

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Versatile Express"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmVExpress"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|4

+

+  #

+  # NV Storage PCDs. Use base of 0x43FC0000 for NOR0 or 0x47FC0000 for NOR1 on Versatile Express

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x47FC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x47FD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x47FE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # Stacks for MPCores in Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x49E00000

+  # Stacks for MPCores in Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0x49D00000

+  # Stacks for MPCores in Normal World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x48000000

+

+  # System Memory (1GB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x60000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x40000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## SP804 Timer

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|1000000

+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000        # expressed in 100ns units, 100,000 x 100 ns = 10,000,000 ns = 10 ms

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum|34

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase|0x10011000

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase|0x10011020

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase|0x10012020

+

+  ## SP805 Watchdog - Motherboard Watchdog

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x1000F000

+  ## SP805 Watchdog - CoreTile Watchdog

+  #gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x100E5000

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x10009000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x10017000

+

+  ## PL111 Lcd

+  # PL111 CoreTile or Tuscan Standalone controller

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x10020000

+  # PL111 Versatile Express Motherboard controller

+  #gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x1001F000

+

+  ## PL180 MMC/SD card controller

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x10000048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x10005000

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x1e001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x1e000100

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmTokenSpaceGuid.PcdArmMachineType|2272

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"NorFlash"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(1F15DA3C-37FF-4070-B471-BB4AF12A724A)/MemoryMapped(0x0,0x46000000,0x46400000)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|1

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM L2x0 PCDs

+  #

+  gArmTokenSpaceGuid.PcdL2x0ControllerBase|0x1E00A000

+

+  # ISP1761 USB OTG Controller

+  gEmbeddedTokenSpaceGuid.PcdIsp1761BaseAddress|0x4f000000

+

+  # LAN9118 Ethernet Driver PCDs

+  gEmbeddedTokenSpaceGuid.PcdLan9118DxeBaseAddress|0x4E000000

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef EDK2_SKIP_PEICORE

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Platform

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.inf

+

+  #

+  # Filesystems

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  # SMSC LAN 9118

+  EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.fdf
new file mode 100644
index 0000000..d3d6ba1
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.fdf
@@ -0,0 +1,386 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.Sec_ArmVExpress_EFI]

+BaseAddress   = 0x44000000|gArmTokenSpaceGuid.PcdSecureFdBaseAddress  #The base address of the Secure FLASH Device.

+Size          = 0x00080000|gArmTokenSpaceGuid.PcdSecureFdSize         #The size in bytes of the Secure FLASH Device

+ErasePolarity = 1

+BlockSize     = 0x00001000

+NumBlocks     = 0x80

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00080000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+

+[FD.ArmVExpress_EFI]

+!if $(EDK2_ARMVE_STANDALONE) == 1

+BaseAddress   = 0x45000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+!else

+BaseAddress   = 0x80000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in remapped DRAM.

+!endif

+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x200

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00200000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Platform

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.inf

+

+!if $(EDK2_ARMVE_STANDALONE) != 1

+  #

+  # Semi-hosting filesystem (Required the Hardware Debugger to be connected)

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+!endif

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  # Versatile Express FileSystem

+  INF ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # USB support

+  #

+  INF EmbeddedPkg/Drivers/Isp1761UsbDxe/Isp1761UsbDxe.inf

+

+  #

+  # Android Fastboot

+  #

+  INF EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf

+  INF EmbeddedPkg/Drivers/AndroidFastbootTransportUsbDxe/FastbootTransportUsbDxe.inf

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBootDxe.inf

+

+  #

+  # Networking stack

+  #

+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

+  INF EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.dsc
new file mode 100644
index 0000000..39bff88
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.dsc
@@ -0,0 +1,310 @@
+#

+#  Copyright (c) 2011-2015, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpress-FVP-AArch64

+  PLATFORM_GUID                  = 0de70077-9b3b-43bf-ba38-0ea37d77141b

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-FVP-AArch64

+  SUPPORTED_ARCHITECTURES        = AARCH64

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.fdf

+

+!ifndef ARM_FVP_RUN_NORFLASH

+  DEFINE EDK2_SKIP_PEICORE=1

+!endif

+

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+!ifndef ARM_FOUNDATION_FVP

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf

+!endif

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+

+  # Virtio Support

+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf

+

+[BuildOptions]

+  GCC:*_*_AARCH64_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+  # Force the UEFI GIC driver to use GICv2 legacy mode. To use

+  # GICv3 without GICv2 legacy in UEFI, the ARM Trusted Firmware needs

+  # to configure the Non-Secure interrupts in the GIC Redistributors

+  # which is not supported at the moment.

+  gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Fixed Virtual Platform"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ARM-FVP"

+

+!ifndef ARM_FOUNDATION_FVP

+  # Up to 8 cores on Base models. This works fine if model happens to have less.

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|8

+  gArmPlatformTokenSpaceGuid.PcdClusterCount|2

+!else

+  # Up to 4 cores on Foundation models. This works fine if model happens to have less.

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|4

+!endif

+

+  #

+  # NV Storage PCDs. Use base of 0x0C000000 for NOR1

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FFC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FFD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FFE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # FVP models can have 2 clusters with 4 cpus each

+  # Stacks for MPCores in Secure World

+  # Trusted SRAM (DRAM on Foundation model)

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x04000000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x1000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecSecondaryStackSize|0x800

+

+  # Stacks for MPCores in Normal World

+  # Non-Trusted SRAM

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x2E000000

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize|0x1000

+

+  # System Memory (2GB - 16MB of Trusted DRAM at the top of the 32bit address space)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x7F000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  ## Trustzone enable (to make the transition from EL3 to NS EL2 in ArmPlatformPkg/Sec)

+  gArmTokenSpaceGuid.PcdTrustzoneSupport|TRUE

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## SP805 Watchdog - Motherboard Watchdog at 24MHz

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x1C0F0000

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz|24000000

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x1c090000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x1C170000

+

+!ifndef ARM_FOUNDATION_FVP

+  ## PL111 Versatile Express Motherboard controller

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x1C1F0000

+

+  ## PL180 MMC/SD card controller

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x1C010048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x1C050000

+!endif

+

+  #

+  # ARM General Interrupt Controller

+  #

+!ifdef ARM_FVP_LEGACY_GICV2_LOCATION

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C002000

+!else

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2f000000

+  gArmTokenSpaceGuid.PcdGicRedistributorsBase|0x2f100000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C000000

+!endif

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux from SemiHosting"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/Image"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootInitrdPath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/filesystem.cpio.gz"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"console=ttyAMA0 earlyprintk=pl011,0x1c090000 debug user_debug=31 loglevel=9"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/fdt.dtb"

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM Architectural Timer Frequency

+  #

+  # Set tick frequency value to 100Mhz

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef EDK2_SKIP_PEICORE

+  # UEFI is placed in RAM by bootloader

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  # UEFI lives in FLASH and copies itself to RAM

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+!ifndef ARM_FOUNDATION_FVP

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+!endif

+  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+!ifndef ARM_FOUNDATION_FVP

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+!endif

+

+  #

+  # Platform Driver

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.fdf
new file mode 100644
index 0000000..80acb95
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.fdf
@@ -0,0 +1,343 @@
+#

+#  Copyright (c) 2011 - 2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.FVP_AARCH64_EFI_SEC]

+BaseAddress   = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in SecureROM.

+Size          = 0x04000000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the device (64MiB).

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x4000

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00080000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+[FD.FVP_AARCH64_EFI]

+!ifdef ARM_FVP_RUN_NORFLASH

+BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in Flash0.

+!else

+BaseAddress   = 0x88000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # UEFI in DRAM + 128MB.

+!endif

+Size          = 0x04000000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the device (64MiB).

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x4000

+

+0x00000000|0x00280000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvBaseAddress      = 0x0  # Secure ROM

+FvForceRebase      = TRUE

+FvAlignment        = 16

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 16        # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+!ifndef ARM_FOUNDATION_FVP

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+!endif

+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+!ifndef ARM_FOUNDATION_FVP

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+!endif

+

+  #

+  # Platform Driver

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 16

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE Align = 4K                  $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE Align = 8                 $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE Align = 8              $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)"     Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.dsc
new file mode 100644
index 0000000..78f4077
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.dsc
@@ -0,0 +1,287 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpressPkg-RTSM-A15

+  PLATFORM_GUID                  = 1665b5b1-529d-4ba1-bd51-c3c9b29a2274

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-RTSM-A15

+  SUPPORTED_ARCHITECTURES        = ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.fdf

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf

+

+  #DebugAgentTimerLib|ArmPlatformPkg/ArmVExpressPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+

+  # Virtio Support

+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf

+

+[BuildOptions]

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+  XCODE:*_*_ARM_PLATFORM_FLAGS = -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+!ifdef EDK2_SKIP_PEICORE

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Versatile Express"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmVExpress-RTSM"

+

+  #

+  # NV Storage PCDs. Use base of 0x0C000000 for NOR1

+  #

+!if $(EDK2_ARMVE_SUPPORT_QEMU) == 1

+  # QEMU only models a single flash block size, so use larger blocks

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FF00000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00040000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FF40000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00040000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FF80000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00040000

+!else

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FFC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FFD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FFE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+!endif

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # Stacks for MPCores in Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x2E009000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x1000

+

+  # Stacks for MPCores in Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0x2E008000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize|0x100

+

+  # Stacks for MPCores in Normal World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x2E000000

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000

+

+  # System Memory (1GB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x40000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## SP805 Watchdog - Motherboard Watchdog

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x1C0F0000

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x1c090000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x1C170000

+

+  ## PL111 Versatile Express Motherboard controller

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x1C1F0000

+

+  ## PL180 MMC/SD card controller

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x1C010048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x1C050000

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C002000

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmTokenSpaceGuid.PcdArmMachineType|2272

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"SemiHosting"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/zImage"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/rtsm_ve-cortex_a15x1.dtb"

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM Architectural Timer Frequency

+  #

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000

+

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef EDK2_SKIP_PEICORE

+  ArmPlatformPkg/PrePi/PeiUniCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform Driver

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.fdf
new file mode 100644
index 0000000..547f8cf
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15.fdf
@@ -0,0 +1,344 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.RTSM_VE_Cortex-A15_EFI]

+BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+Size          = 0x00300000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x300

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00080000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+0x00080000|0x00280000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Networking stack

+  #

+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  # Versatile Express FileSystem

+  INF ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform  Driver

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiUniCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.dsc
new file mode 100644
index 0000000..2a81c85
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.dsc
@@ -0,0 +1,289 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpressPkg-RTSM-A15_MPCore

+  PLATFORM_GUID                  = 3a91a0f8-3af4-409d-a71d-a199dc134357

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-RTSM-A15_MPCore

+  SUPPORTED_ARCHITECTURES        = ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.fdf

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf

+

+  #DebugAgentTimerLib|ArmPlatformPkg/ArmVExpressPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+

+  # Virtio Support

+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf

+

+[BuildOptions]

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+  XCODE:*_*_ARM_PLATFORM_FLAGS = -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+!ifdef EDK2_SKIP_PEICORE

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Versatile Express"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmVExpress-RTSM"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|2

+

+  #

+  # NV Storage PCDs. Use base of 0x0C000000 for NOR1

+  #

+!if $(EDK2_ARMVE_SUPPORT_QEMU) == 1

+  # QEMU only models a single flash block size, so use larger blocks

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FF00000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00040000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FF40000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00040000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FF80000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00040000

+!else

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FFC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FFD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FFE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+!endif

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # Stacks for MPCores in Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x2E009000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x1000

+

+  # Stacks for MPCores in Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0x2E008000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize|0x100

+

+  # Stacks for MPCores in Normal World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x2E000000

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000

+

+  # System Memory (1GB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x40000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## SP805 Watchdog - Motherboard Watchdog

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x1C0F0000

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x1c090000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x1C170000

+

+  ## PL111 Versatile Express Motherboard controller

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x1C1F0000

+

+  ## PL180 MMC/SD card controller

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x1C010048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x1C050000

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C002000

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmTokenSpaceGuid.PcdArmMachineType|2272

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"SemiHosting"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/zImage"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/rtsm_ve-cortex_a15x4.dtb"

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM Architectural Timer Frequency

+  #

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000

+

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef EDK2_SKIP_PEICORE

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform Driver

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.fdf
new file mode 100644
index 0000000..b2be83b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A15_MPCore.fdf
@@ -0,0 +1,344 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.RTSM_VE_Cortex-A15_MPCore_EFI]

+BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+Size          = 0x00300000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x300

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00080000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+0x00080000|0x00280000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Networking stack

+  #

+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  # Versatile Express FileSystem

+  INF ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform  Driver

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A9x4.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A9x4.dsc
new file mode 100644
index 0000000..0923a1e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A9x4.dsc
@@ -0,0 +1,289 @@
+#

+#  Copyright (c) 2011-2014, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpressPkg-RTSM-A9x4

+  PLATFORM_GUID                  = e46039e0-5bb3-11e0-a9d6-0002a5d5c51b

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-RTSM-A9x4

+  SUPPORTED_ARCHITECTURES        = ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A9x4.fdf

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA9Lib/ArmCortexA9Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf

+

+  #DebugAgentTimerLib|ArmPlatformPkg/ArmVExpressPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.inf

+

+

+  # Virtio Support

+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf

+

+  # Uncomment to turn on GDB stub in SEC.

+  #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf

+

+[BuildOptions]

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A9 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a9 -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+  XCODE:*_*_ARM_PLATFORM_FLAGS == -march=armv7-a -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+

+!ifdef EDK2_SKIP_PEICORE

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Versatile Express"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmVExpress-RTSM"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|4

+

+  #

+  # NV Storage PCDs. Use base of 0x0C000000 for NOR1

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FFC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FFD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FFE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # Stacks for MPCores in Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x2E009000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x1000

+

+  # Stacks for MPCores in Monitor Mode

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase|0x2E008000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize|0x100

+

+  # Stacks for MPCores in Normal World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x2E000000

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000

+

+  # System Memory (1GB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x40000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## SP804 Timer

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|1000000

+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod|100000        # expressed in 100ns units, 100,000 x 100 ns = 10,000,000 ns = 10 ms

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum|34

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase|0x1c110000

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase|0x1c110020

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase|0x1c120020

+

+  ## SP805 Watchdog - Motherboard Watchdog

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x1C0F0000

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x1c090000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x1C170000

+

+  ## PL111 Versatile Express Motherboard controller

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x1C1F0000

+

+  ## PL180 MMC/SD card controller

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x1C010048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x1C050000

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C000100

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmTokenSpaceGuid.PcdArmMachineType|2272

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"SemiHosting"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/zImage"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/rtsm_ve-cortex_a9x4.dtb"

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM L2x0 PCDs

+  #

+  gArmTokenSpaceGuid.PcdL2x0ControllerBase|0x1E00A000

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef EDK2_SKIP_PEICORE

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform Driver

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A9x4.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A9x4.fdf
new file mode 100644
index 0000000..a46d341
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-A9x4.fdf
@@ -0,0 +1,330 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.RTSM_VE_Cortex-A9_EFI]

+BaseAddress   = 0x08000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+Size          = 0x00300000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x300

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00080000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+0x00080000|0x00280000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 8         # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Versatile Express FileSystem

+  #

+  INF ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform  Driver

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 8

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE    Align = 32                $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE                           $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE                        $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)" Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4-foundation.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4-foundation.dsc
new file mode 100644
index 0000000..725ce20
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4-foundation.dsc
@@ -0,0 +1,244 @@
+#

+#  Copyright (c) 2011-2013, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpressPkg-RTSM-AEMv8Ax4-foundation

+  PLATFORM_GUID                  = 2a9d4992-0730-11e2-9829-1c6f650265cc

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-RTSM-AEMv8Ax4-foundation

+  SUPPORTED_ARCHITECTURES        = AARCH64

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4-foundation.fdf

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLib.inf

+

+  # Virtio Support

+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+

+  # Foundation model does not have an RTC. Use the NULL version.

+  RealTimeClockLib|EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressFoundationSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLibSec.inf

+

+[BuildOptions]

+  GCC:*_*_AARCH64_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+

+!ifdef $(EDK2_SKIP_PEICORE)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Foundation Model"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmFoundation"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|4

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # Stacks for MPCores in Secure World (No SRAM on foundation model, put in RAM at 64MB)

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0xA4008000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x1000

+

+  # Stacks for MPCores in Normal World (No SRAM on foundation model, put in RAM at 64MB)

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0xA4000000

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000

+

+  # System Memory (2GB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x80000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  ## Trustzone enable (to make the transition from EL3 to EL2 in ArmPlatformPkg/Sec)

+  gArmTokenSpaceGuid.PcdTrustzoneSupport|TRUE

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x1c090000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C002000

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux from SemiHosting"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/Image"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/vda2 rw console=ttyAMA0 earlyprintk=pl011,0x1c090000 maxcpus=4 debug user_debug=31 loglevel=9"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/foundation-v8.dtb"

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM Architectural Timer Frequency

+  #

+  # Set model tick to 100Mhz. This depends a lot on workstation performance.

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef $(EDK2_SKIP_PEICORE)

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Platform Driver

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4-foundation.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4-foundation.fdf
new file mode 100644
index 0000000..b971d4e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4-foundation.fdf
@@ -0,0 +1,316 @@
+#

+#  Copyright (c) 2011 - 2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.RTSM_VE_Foundationv8_EFI]

+BaseAddress   = 0xA0000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in RAM (Foundation model has no NOR Flash).

+Size          = 0x00300000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x300

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00080000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+0x00080000|0x00280000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvAlignment        = 16

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 16        # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Platform Driver

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 16

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE Align = 4K                  $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE Align = 8                 $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE Align = 8              $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)"     Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.dsc
new file mode 100644
index 0000000..b2ffd37
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.dsc
@@ -0,0 +1,281 @@
+#

+#  Copyright (c) 2011-2013, ARM 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVExpressPkg-RTSM-AEMv8Ax4

+  PLATFORM_GUID                  = f7003abd-8809-4096-ac3d-a6a99ff52478

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVExpress-RTSM-AEMv8Ax4

+  SUPPORTED_ARCHITECTURES        = AARCH64

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.fdf

+

+!include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

+

+[LibraryClasses.common]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+

+  # VirtIo Support

+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf

+  ArmPlatformSecLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf

+  ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf

+

+[BuildOptions]

+  GCC:*_*_AARCH64_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include -I$(WORKSPACE)/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM

+

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+!ifdef $(EDK2_SKIP_PEICORE)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec|TRUE

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|TRUE

+!endif

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE

+

+  # UEFI firmware is responsible to park the secondary cores on this platform.

+  # This PCD ensures the secondary cores are parked into the AArch64 Linux parking protocol.

+  gArmTokenSpaceGuid.PcdArmLinuxSpinTable|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Versatile Express"

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"ArmVExpress-RTSM"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|8

+

+  #

+  # NV Storage PCDs. Use base of 0x0C000000 for NOR1

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0FFC0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0FFD0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00010000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0FFE0000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00010000

+

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+

+  # FVP models can have 2 clusters with 4 cpus each

+  # Stacks for MPCores in Secure World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase|0x2E009000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize|0x1000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecSecondaryStackSize|0x800

+

+  # Stacks for MPCores in Normal World

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x2E000000

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize|0x800

+

+  # System Memory (2GB)

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x80000000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  ## Trustzone enable (to make the transition from EL3 to EL2 in ArmPlatformPkg/Sec)

+  gArmTokenSpaceGuid.PcdTrustzoneSupport|TRUE

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## SP805 Watchdog - Motherboard Watchdog at 24MHz

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x1C0F0000

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz|24000000

+

+  ## PL011 - Serial Terminal

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x1c090000

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x1C170000

+

+  ## PL111 Versatile Express Motherboard controller

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase|0x1C1F0000

+

+  ## PL180 MMC/SD card controller

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress|0x1C010048

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress|0x1C050000

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x2C001000

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x2C002000

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux from SemiHosting"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/Image"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/mmcblk0p2 console=ttyAMA0 earlyprintk=pl011,0x1c090000 debug user_debug=31 loglevel=9"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|2

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L"VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/rtsm_ve-aemv8a.dtb"

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(407B4008-BF5B-11DF-9547-CF16E0D72085)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+

+  #

+  # ARM Architectural Timer Frequency

+  #

+  # Set model tick to 100Mhz. This depends a lot on workstation performance.

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|100000000

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+

+  #

+  # SEC

+  #

+  ArmPlatformPkg/Sec/Sec.inf {

+    <LibraryClasses>

+      # Use the implementation which set the Secure bits

+      ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

+  }

+

+  #

+  # PEI Phase modules

+  #

+!ifdef $(EDK2_SKIP_PEICORE)

+  ArmPlatformPkg/PrePi/PeiMPCore.inf {

+    <LibraryClasses>

+      ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+      ArmPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf

+  }

+!else

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  }

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  Nt32Pkg/BootModePei/BootModePei.inf

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+!endif

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform Driver

+  #

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  ArmPlatformPkg/Bds/Bds.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.fdf
new file mode 100644
index 0000000..48074c8
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-RTSM-AEMv8Ax4.fdf
@@ -0,0 +1,327 @@
+#

+#  Copyright (c) 2011 - 2014, ARM 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.RTSM_VE_AEMv8_EFI]

+BaseAddress   = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # The base address of the Firmware in NOR Flash.

+Size          = 0x00300000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x300

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+0x00000000|0x00080000

+gArmTokenSpaceGuid.PcdSecureFvBaseAddress|gArmTokenSpaceGuid.PcdSecureFvSize

+FV = FVMAIN_SEC

+

+0x00080000|0x00280000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FVMAIN_SEC]

+FvBaseAddress      = 0x0

+FvForceRebase      = TRUE

+FvAlignment        = 16

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF ArmPlatformPkg/Sec/Sec.inf

+

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 16        # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  INF ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf

+  INF ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf

+

+  #

+  # Semi-hosting filesystem

+  #

+  INF ArmPkg/Filesystem/SemihostFs/SemihostFs.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Multimedia Card Interface

+  #

+  INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

+  INF ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf

+

+  #

+  # Platform Driver

+  #

+  INF ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf

+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+  INF ArmPlatformPkg/Bds/Bds.inf

+

+  # FV Filesystem

+  INF MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 16

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+!if $(EDK2_SKIP_PEICORE) == 1

+  INF ArmPlatformPkg/PrePi/PeiMPCore.inf

+!else

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+!endif

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE Align = 4K                  $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE Align = 8                 $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE Align = 8              $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)"     Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc
new file mode 100644
index 0000000..ddc796d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc
@@ -0,0 +1,411 @@
+#

+#  Copyright (c) 2011-2015, ARM 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.

+#

+#

+

+[LibraryClasses.common]

+!if $(TARGET) == RELEASE

+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+!else

+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+#  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf

+!endif

+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf

+

+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf

+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf

+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf

+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf

+

+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf

+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf

+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf

+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf

+

+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf

+

+  #

+  # Assume everything is fixed at build

+  #

+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+

+  # 1/123 faster than Stm or Vstm version

+  #BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf

+  BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf

+

+  # Networking Requirements

+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf

+  DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf

+  UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf

+  IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf

+

+  # ARM Architectural Libraries

+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf

+  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf

+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf

+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf

+  ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf

+  ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf

+  ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf

+  ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf

+

+  # Versatile Express Specific Libraries

+  PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf

+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf

+  NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf

+  EfiResetSystemLib|ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.inf

+  # ARM PL111 Lcd Driver

+  LcdPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf

+  # ARM PL031 RTC Driver

+  RealTimeClockLib|ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

+  # ARM PL354 SMC Driver

+  PL35xSmcLib|ArmPlatformPkg/Drivers/PL35xSmc/PL35xSmc.inf

+  # ARM PL011 UART Driver

+  PL011UartLib|ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf

+  SerialPortLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf

+  SerialPortExtLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.inf

+  # ARM SP804 Dual Timer Driver

+  TimerLib|ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf

+

+  # EBL Related Libraries

+  EblCmdLib|ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf

+  EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf

+  EblAddExternalCommandLib|EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.inf

+  EblNetworkLib|EmbeddedPkg/Library/EblNetworkLib/EblNetworkLib.inf

+

+  #

+  # Uncomment (and comment out the next line) For RealView Debugger. The Standard IO window

+  # in the debugger will show load and unload commands for symbols. You can cut and paste this

+  # into the command window to load symbols. We should be able to use a script to do this, but

+  # the version of RVD I have does not support scripts accessing system memory.

+  #

+  #PeCoffExtraActionLib|ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf

+  PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf

+  #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf

+

+  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf

+  DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf

+

+  SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf

+

+  # BDS Libraries

+  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf

+

+  AcpiLib|EmbeddedPkg/Library/AcpiLib/AcpiLib.inf

+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf

+

+  # RunAxf support via Dynamic Shell Command protocol

+  # It uses the Shell libraries.

+  ArmShellCmdRunAxfLib|ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.inf

+  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf

+  FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf

+  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf

+

+[LibraryClasses.common.SEC]

+  ArmPlatformSecExtraActionLib|ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf

+

+  DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf

+

+!ifdef $(EDK2_SKIP_PEICORE)

+  PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf

+  ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf

+  LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf

+  HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf

+  PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf

+!endif

+

+  # Trustzone Support

+  ArmTrustedMonitorLib|ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf

+

+[LibraryClasses.common.PEI_CORE]

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+

+[LibraryClasses.common.PEIM]

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+

+[LibraryClasses.common.DXE_CORE]

+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf

+  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf

+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf

+

+[LibraryClasses.common.DXE_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf

+

+[LibraryClasses.common.UEFI_APPLICATION]

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+

+[LibraryClasses.common.UEFI_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+

+[LibraryClasses.common.DXE_RUNTIME_DRIVER]

+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf

+

+[LibraryClasses.ARM, LibraryClasses.AARCH64]

+  #

+  # It is not possible to prevent the ARM compiler for generic intrinsic functions.

+  # This library provides the instrinsic functions generate by a given compiler.

+  # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.

+  #

+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

+

+  # Add support for GCC stack protector

+  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf

+

+

+[BuildOptions]

+  RVCT:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG

+

+  GCC:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE

+

+  #

+  # Control what commands are supported from the UI

+  # Turn these on and off to add features or save size

+  #

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE

+

+  # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress

+  gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE

+

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Versatile Express"

+!ifdef $(FIRMWARE_VER)

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"$(FIRMWARE_VER)"

+!endif

+

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"VExpress"

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000

+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF

+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1

+  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0

+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320

+

+  # DEBUG_ASSERT_ENABLED       0x01

+  # DEBUG_PRINT_ENABLED        0x02

+  # DEBUG_CODE_ENABLED         0x04

+  # CLEAR_MEMORY_ENABLED       0x08

+  # ASSERT_BREAKPOINT_ENABLED  0x10

+  # ASSERT_DEADLOOP_ENABLED    0x20

+!if $(TARGET) == RELEASE

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x21

+!else

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f

+!endif

+

+  #  DEBUG_INIT      0x00000001  // Initialization

+  #  DEBUG_WARN      0x00000002  // Warnings

+  #  DEBUG_LOAD      0x00000004  // Load events

+  #  DEBUG_FS        0x00000008  // EFI File system

+  #  DEBUG_POOL      0x00000010  // Alloc & Free's

+  #  DEBUG_PAGE      0x00000020  // Alloc & Free's

+  #  DEBUG_INFO      0x00000040  // Verbose

+  #  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers

+  #  DEBUG_VARIABLE  0x00000100  // Variable

+  #  DEBUG_BM        0x00000400  // Boot Manager

+  #  DEBUG_BLKIO     0x00001000  // BlkIo Driver

+  #  DEBUG_NET       0x00004000  // SNI Driver

+  #  DEBUG_UNDI      0x00010000  // UNDI Driver

+  #  DEBUG_LOADFILE  0x00020000  // UNDI Driver

+  #  DEBUG_EVENT     0x00080000  // Event messages

+  #  DEBUG_GCD       0x00100000  // Global Coherency Database changes

+  #  DEBUG_CACHE     0x00200000  // Memory range cachability changes

+  #  DEBUG_ERROR     0x80000000  // Error

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F

+

+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07

+

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000

+

+  #

+  # Optional feature to help prevent EFI memory map fragments

+  # Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob

+  # Values are in EFI Pages (4K). DXE Core will make sure that

+  # at least this much of each type of memory can be allocated

+  # from a single memory range. This way you only end up with

+  # maximum of two fragements for each type in the memory map

+  # (the memory used, and the free memory that was prereserved

+  # but not used).

+  #

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|80

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|65

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|20000

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0

+

+  # Device path of block device on which Android Fastboot should flash

+  # partitions. We just use the SD card on VExpress.

+  gArmVExpressTokenSpaceGuid.PcdAndroidFastbootNvmDevicePath|L"VenHw(09831032-6FA3-4484-AF4F-0A000A8D3A82)"

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000000000000

+

+  #

+  # ARM PrimeCell

+  #

+

+  #

+  # FileSystem

+  #

+

+  # List of Device Paths that support BootMonFs

+  gArmPlatformTokenSpaceGuid.PcdBootMonFsSupportedDevicePaths|L"VenHw(E7223039-5836-41E1-B542-D7EC736C5E59);VenHw(1F15DA3C-37FF-4070-B471-BB4AF12A724A)"

+

+  #

+  # ARM OS Loader

+  #

+  # Versatile Express machine type (ARM VERSATILE EXPRESS = 2272) required for ARM Linux:

+  gArmTokenSpaceGuid.PcdArmMachineType|2272

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux from NorFlash"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(E7223039-5836-41E1-B542-D7EC736C5E59)/MemoryMapped(0x0,0xED000000,0xED400000)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|1

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi();VenHw(CE660500-824D-11E0-AC72-0002A5D5C51B)"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenPcAnsi()"

+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut|10

+

+  # RunAxf support via Dynamic Shell Command protocol

+  # We want to use the Shell Libraries but don't want it to initialise

+  # automatically. We initialise the libraries when the command is called by the

+  # Shell.

+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE

+

+[Components.common]

+  # Versatile Express FileSystem

+  ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf

+

+  #

+  # Networking stack

+  #

+  MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

+

+  # ISP1761 USB OTG Controller

+  EmbeddedPkg/Drivers/Isp1761UsbDxe/Isp1761UsbDxe.inf

+

+  #

+  # Android Fastboot

+  #

+  EmbeddedPkg/Application/AndroidFastboot/AndroidFastbootApp.inf

+  EmbeddedPkg/Drivers/AndroidFastbootTransportUsbDxe/FastbootTransportUsbDxe.inf

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBootDxe.inf

+

+  # FV Filesystem

+  MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemDxe.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c
new file mode 100644
index 0000000..64e4158
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.c
@@ -0,0 +1,82 @@
+/** @file

+

+  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>

+

+  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 <Library/UefiLib.h>

+#include <Library/VirtioMmioDeviceLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/ArmShellCmdLib.h>

+

+#define ARM_FVP_BASE_VIRTIO_BLOCK_BASE    0x1c130000

+

+#pragma pack(1)

+typedef struct {

+  VENDOR_DEVICE_PATH                  Vendor;

+  EFI_DEVICE_PATH_PROTOCOL            End;

+} VIRTIO_BLK_DEVICE_PATH;

+#pragma pack()

+

+VIRTIO_BLK_DEVICE_PATH mVirtioBlockDevicePath =

+{

+  {

+    {

+      HARDWARE_DEVICE_PATH,

+      HW_VENDOR_DP,

+      {

+        (UINT8)( sizeof(VENDOR_DEVICE_PATH) ),

+        (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8)

+      }

+    },

+    EFI_CALLER_ID_GUID,

+  },

+  {

+    END_DEVICE_PATH_TYPE,

+    END_ENTIRE_DEVICE_PATH_SUBTYPE,

+    {

+      sizeof (EFI_DEVICE_PATH_PROTOCOL),

+      0

+    }

+  }

+};

+

+EFI_STATUS

+EFIAPI

+ArmFvpInitialise (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS              Status;

+

+  Status = gBS->InstallProtocolInterface (&ImageHandle,

+                 &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,

+                 &mVirtioBlockDevicePath);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Declare the Virtio BlockIo device

+  Status = VirtioMmioInstallDevice (ARM_FVP_BASE_VIRTIO_BLOCK_BASE, ImageHandle);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "ArmFvpDxe: Failed to install Virtio block device\n"));

+  }

+

+  // Install dynamic Shell command to run baremetal binaries.

+  Status = ShellDynCmdRunAxfInstall (ImageHandle);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "ArmFvpDxe: Failed to install ShellDynCmdRunAxf\n"));

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf
new file mode 100644
index 0000000..7112144
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmFvpDxe.inf
@@ -0,0 +1,36 @@
+#/** @file

+#

+#  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010006

+  BASE_NAME                      = ArmFvpDxe

+  FILE_GUID                      = 405b2307-6839-4d52-aeb9-bece64252800

+  MODULE_TYPE                    = UEFI_DRIVER

+  VERSION_STRING                 = 1.0

+  ENTRY_POINT                    = ArmFvpInitialise

+

+[Sources.common]

+  ArmFvpDxe.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  OvmfPkg/OvmfPkg.dec

+

+[LibraryClasses]

+  ArmShellCmdRunAxfLib

+  UefiDriverEntryPoint

+  UefiBootServicesTableLib

+  VirtioMmioDeviceLib

+  BaseMemoryLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.c
new file mode 100644
index 0000000..7ed5c61
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.c
@@ -0,0 +1,35 @@
+/** @file

+

+  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>

+

+  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 <Library/UefiLib.h>

+#include <Library/DebugLib.h>

+#include <Library/ArmShellCmdLib.h>

+

+EFI_STATUS

+EFIAPI

+ArmHwInitialise (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+

+  // Install dynamic Shell command to run baremetal binaries.

+  Status = ShellDynCmdRunAxfInstall (ImageHandle);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "ArmHwDxe: Failed to install ShellDynCmdRunAxf\n"));

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.inf
new file mode 100644
index 0000000..3bcdbd0
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressDxe/ArmHwDxe.inf
@@ -0,0 +1,32 @@
+#/** @file

+#

+#  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010006

+  BASE_NAME                      = ArmFvpDxe

+  FILE_GUID                      = fe61bb5f-1b67-4c24-b346-73db42e873e5

+  MODULE_TYPE                    = UEFI_DRIVER

+  VERSION_STRING                 = 1.0

+  ENTRY_POINT                    = ArmHwInitialise

+

+[Sources.common]

+  ArmHwDxe.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmShellCmdRunAxfLib

+  UefiDriverEntryPoint

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBoot.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBoot.c
new file mode 100644
index 0000000..8888dcd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBoot.c
@@ -0,0 +1,503 @@
+/** @file

+

+  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+

+  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 ARM Versatile Express platforms.

+*/

+

+#include <Protocol/AndroidFastbootPlatform.h>

+#include <Protocol/BlockIo.h>

+#include <Protocol/DiskIo.h>

+

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DebugLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#define FLASH_DEVICE_PATH_SIZE(DevPath) ( GetDevicePathSize (DevPath) - \

+                                            sizeof (EFI_DEVICE_PATH_PROTOCOL))

+

+#define PARTITION_NAME_MAX_LENGTH 72/2

+

+#define IS_ALPHA(Char) (((Char) <= L'z' && (Char) >= L'a') || \

+                        ((Char) <= L'Z' && (Char) >= L'Z'))

+

+typedef struct _FASTBOOT_PARTITION_LIST {

+  LIST_ENTRY  Link;

+  CHAR16      PartitionName[PARTITION_NAME_MAX_LENGTH];

+  EFI_HANDLE  PartitionHandle;

+} FASTBOOT_PARTITION_LIST;

+

+STATIC LIST_ENTRY mPartitionListHead;

+

+/*

+  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

+  )

+{

+  UINTN                       EntrySize;

+  UINTN                       NumEntries;

+  UINTN                       BufferSize;

+  UINT32                      MediaId;

+  EFI_PARTITION_TABLE_HEADER *GptHeader;

+  EFI_STATUS                  Status;

+

+  MediaId = BlockIo->Media->MediaId;

+

+  //

+  // Read size of Partition entry and number of entries from GPT header

+  //

+

+  GptHeader = AllocatePool (BlockIo->Media->BlockSize);

+  if (GptHeader == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  Status = BlockIo->ReadBlocks (BlockIo, MediaId, 1, BlockIo->Media->BlockSize, (VOID *) GptHeader);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Check there is a GPT on the media

+  if (GptHeader->Header.Signature != EFI_PTAB_HEADER_ID ||

+      GptHeader->MyLBA != 1) {

+    DEBUG ((EFI_D_ERROR,

+      "Fastboot platform: No GPT on flash. "

+      "Fastboot on Versatile Express does not support MBR.\n"

+      ));

+    return EFI_DEVICE_ERROR;

+  }

+

+  EntrySize = GptHeader->SizeOfPartitionEntry;

+  NumEntries = GptHeader->NumberOfPartitionEntries;

+

+  FreePool (GptHeader);

+

+  ASSERT (EntrySize != 0);

+  ASSERT (NumEntries != 0);

+

+  BufferSize = ALIGN_VALUE (EntrySize * NumEntries, BlockIo->Media->BlockSize);

+  *PartitionEntries = AllocatePool (BufferSize);

+  if (PartitionEntries == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  Status = BlockIo->ReadBlocks (BlockIo, MediaId, 2, BufferSize, (VOID *) *PartitionEntries);

+  if (EFI_ERROR (Status)) {

+    FreePool (PartitionEntries);

+    return Status;

+  }

+

+  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

+  ArmFastbootPlatformFlashPartition.

+*/

+EFI_STATUS

+ArmFastbootPlatformInit (

+  VOID

+  )

+{

+  EFI_STATUS                          Status;

+  EFI_DEVICE_PATH_PROTOCOL           *FlashDevicePath;

+  EFI_DEVICE_PATH_PROTOCOL           *FlashDevicePathDup;

+  EFI_DEVICE_PATH_PROTOCOL           *DevicePath;

+  EFI_DEVICE_PATH_PROTOCOL           *NextNode;

+  HARDDRIVE_DEVICE_PATH              *PartitionNode;

+  UINTN                               NumHandles;

+  EFI_HANDLE                         *AllHandles;

+  UINTN                               LoopIndex;

+  EFI_HANDLE                          FlashHandle;

+  EFI_BLOCK_IO_PROTOCOL              *FlashBlockIo;

+  EFI_PARTITION_ENTRY                *PartitionEntries;

+  FASTBOOT_PARTITION_LIST            *Entry;

+

+  InitializeListHead (&mPartitionListHead);

+

+  //

+  // 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));

+

+  //

+  // Open the Disk IO protocol on the flash device - this will be used to read

+  // partition names out of the GPT entries

+  //

+  // Create another device path pointer because LocateDevicePath will modify it.

+  FlashDevicePathDup = FlashDevicePath;

+  Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &FlashDevicePathDup, &FlashHandle);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_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 (

+                  FlashHandle,

+                  &gEfiBlockIoProtocolGuid,

+                  (VOID **) &FlashBlockIo,

+                  gImageHandle,

+                  NULL,

+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL

+                  );

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_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 (FlashBlockIo, &PartitionEntries);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_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;

+  }

+

+  // Get every Block IO protocol instance installed in the system

+  Status = gBS->LocateHandleBuffer (

+                  ByProtocol,

+                  &gEfiBlockIoProtocolGuid,

+                  NULL,

+                  &NumHandles,

+                  &AllHandles

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  // Filter out handles that aren't children of the flash device

+  for (LoopIndex = 0; LoopIndex < NumHandles; LoopIndex++) {

+    // Get the device path for the handle

+    Status = gBS->OpenProtocol (

+                    AllHandles[LoopIndex],

+                    &gEfiDevicePathProtocolGuid,

+                    (VOID **) &DevicePath,

+                    gImageHandle,

+                    NULL,

+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL

+                    );

+    ASSERT_EFI_ERROR (Status);

+

+    // Check if it is a sub-device of the flash device

+    if (!CompareMem (DevicePath, FlashDevicePath, FLASH_DEVICE_PATH_SIZE (FlashDevicePath))) {

+      // Device path starts with path of flash device. Check it isn't the flash

+      // device itself.

+      NextNode = NextDevicePathNode (DevicePath);

+      if (IsDevicePathEndType (NextNode)) {

+        continue;

+      }

+

+      // Assert that this device path node represents a partition.

+      ASSERT (NextNode->Type == MEDIA_DEVICE_PATH &&

+              NextNode->SubType == MEDIA_HARDDRIVE_DP);

+

+      PartitionNode = (HARDDRIVE_DEVICE_PATH *) NextNode;

+

+      // Assert that the partition type is GPT. ReadPartitionEntries checks for

+      // presence of a GPT, so we should never find MBR partitions.

+      // ("MBRType" is a misnomer - this field is actually called "Partition

+      //  Format")

+      ASSERT (PartitionNode->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER);

+

+      // The firmware may install a handle for "partition 0", representing the

+      // whole device. Ignore it.

+      if (PartitionNode->PartitionNumber == 0) {

+        continue;

+      }

+

+      //

+      // Add the partition handle to the list

+      //

+

+      // Create entry

+      Entry = AllocatePool (sizeof (FASTBOOT_PARTITION_LIST));

+      if (Entry == NULL) {

+        Status = EFI_OUT_OF_RESOURCES;

+        FreePartitionList ();

+        goto Exit;

+      }

+

+      // Copy handle and partition name

+      Entry->PartitionHandle = AllHandles[LoopIndex];

+      StrnCpy (

+        Entry->PartitionName,

+        PartitionEntries[PartitionNode->PartitionNumber - 1].PartitionName, // Partition numbers start from 1.

+        PARTITION_NAME_MAX_LENGTH

+        );

+      InsertTailList (&mPartitionListHead, &Entry->Link);

+

+      // Print a debug message if the partition label is empty or looks like

+      // garbage.

+      if (!IS_ALPHA (Entry->PartitionName[0])) {

+        DEBUG ((EFI_D_ERROR,

+          "Warning: Partition %d doesn't seem to have a GPT partition label. "

+          "You won't be able to flash it with Fastboot.\n",

+          PartitionNode->PartitionNumber

+          ));

+      }

+    }

+  }

+

+Exit:

+  FreePool (PartitionEntries);

+  FreePool (FlashDevicePath);

+  FreePool (AllHandles);

+  return Status;

+

+}

+

+VOID

+ArmFastbootPlatformUnInit (

+  VOID

+  )

+{

+  FreePartitionList ();

+}

+

+EFI_STATUS

+ArmFastbootPlatformFlashPartition (

+  IN CHAR8  *PartitionName,

+  IN UINTN   Size,

+  IN VOID   *Image

+  )

+{

+  EFI_STATUS               Status;

+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;

+  EFI_DISK_IO_PROTOCOL    *DiskIo;

+  UINT32                   MediaId;

+  UINTN                    PartitionSize;

+  FASTBOOT_PARTITION_LIST *Entry;

+  CHAR16                   PartitionNameUnicode[60];

+  BOOLEAN                  PartitionFound;

+  SPARSE_HEADER           *SparseHeader;

+  CHUNK_HEADER            *ChunkHeader;

+  UINTN                    Offset = 0;

+  UINT32                   Chunk;

+

+

+  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;

+  }

+

+  Status = gBS->OpenProtocol (

+                  Entry->PartitionHandle,

+                  &gEfiBlockIoProtocolGuid,

+                  (VOID **) &BlockIo,

+                  gImageHandle,

+                  NULL,

+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL

+                  );

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "Fastboot platform: couldn't open Block IO for flash: %r\n", Status));

+    return EFI_NOT_FOUND;

+  }

+

+  SparseHeader=(SPARSE_HEADER *)Image;

+

+  if (SparseHeader->Magic == SPARSE_HEADER_MAGIC) {

+    DEBUG ((EFI_D_INFO, "Sparse Magic: 0x%x Major: %d Minor: %d fhs: %d chs: %d bs: %d tbs: %d tcs: %d checksum: %d \n",

+                SparseHeader->Magic, SparseHeader->MajorVersion, SparseHeader->MinorVersion,  SparseHeader->FileHeaderSize,

+                SparseHeader->ChunkHeaderSize, SparseHeader->BlockSize, SparseHeader->TotalBlocks,

+                SparseHeader->TotalChunks, SparseHeader->ImageChecksum));

+    if (SparseHeader->MajorVersion != 1) {

+        DEBUG ((EFI_D_ERROR, "Sparse image version %d.%d not supported.\n",

+                    SparseHeader->MajorVersion, SparseHeader->MinorVersion));

+        return EFI_INVALID_PARAMETER;

+    }

+

+    Size = SparseHeader->BlockSize * SparseHeader->TotalBlocks;

+  }

+

+  // Check image will fit on device

+  PartitionSize = (BlockIo->Media->LastBlock + 1) * BlockIo->Media->BlockSize;

+  if (PartitionSize < Size) {

+    DEBUG ((EFI_D_ERROR, "Partition not big enough.\n"));

+    DEBUG ((EFI_D_ERROR, "Partition Size:\t%d\nImage Size:\t%d\n", PartitionSize, Size));

+

+    return EFI_VOLUME_FULL;

+  }

+

+  MediaId = BlockIo->Media->MediaId;

+

+  Status = gBS->OpenProtocol (

+                  Entry->PartitionHandle,

+                  &gEfiDiskIoProtocolGuid,

+                  (VOID **) &DiskIo,

+                  gImageHandle,

+                  NULL,

+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  if (SparseHeader->Magic == SPARSE_HEADER_MAGIC) {

+    Image += SparseHeader->FileHeaderSize;

+    for (Chunk = 0; Chunk < SparseHeader->TotalChunks; Chunk++) {

+      UINTN WriteSize;

+      ChunkHeader = (CHUNK_HEADER *)Image;

+      DEBUG ((EFI_D_INFO, "Chunk #%d - Type: 0x%x Size: %d TotalSize: %d Offset %d\n",

+                  (Chunk+1), ChunkHeader->ChunkType, ChunkHeader->ChunkSize,

+                  ChunkHeader->TotalSize, Offset));

+      Image += sizeof(CHUNK_HEADER);

+      WriteSize=(SparseHeader->BlockSize) * ChunkHeader->ChunkSize;

+      switch (ChunkHeader->ChunkType) {

+        case CHUNK_TYPE_RAW:

+          DEBUG ((EFI_D_INFO, "Writing %d at Offset %d\n", WriteSize, Offset));

+          Status = DiskIo->WriteDisk (DiskIo, MediaId, Offset, WriteSize, Image);

+          if (EFI_ERROR (Status)) {

+            return Status;

+          }

+          Image+=WriteSize;

+          break;

+        case CHUNK_TYPE_DONT_CARE:

+          break;

+        case CHUNK_TYPE_CRC32:

+          break;

+        default:

+          DEBUG ((EFI_D_ERROR, "Unknown Chunk Type: 0x%x"));

+          return EFI_PROTOCOL_ERROR;

+      }

+      Offset += WriteSize;

+    }

+  } else {

+    Status = DiskIo->WriteDisk (DiskIo, MediaId, 0, Size, Image);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  }

+

+  BlockIo->FlushBlocks(BlockIo);

+

+  return Status;

+}

+

+EFI_STATUS

+ArmFastbootPlatformErasePartition (

+  IN CHAR8 *Partition

+  )

+{

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+ArmFastbootPlatformGetVar (

+  IN  CHAR8   *Name,

+  OUT CHAR8   *Value

+  )

+{

+  if (!AsciiStrCmp (Name, "max-download-size")) {

+    AsciiStrCpy (Value, FixedPcdGetPtr (PcdArmFastbootFlashLimit));

+  } else if (AsciiStrCmp (Name, "product")) {

+    AsciiStrCpy (Value, FixedPcdGetPtr (PcdFirmwareVendor));

+  } else {

+    *Value = '\0';

+  }

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+ArmFastbootPlatformOemCommand (

+  IN  CHAR8   *Command

+  )

+{

+  CHAR16 CommandUnicode[65];

+

+  AsciiStrToUnicodeStr (Command, CommandUnicode);

+

+  if (AsciiStrCmp (Command, "Demonstrate") == 0) {

+    DEBUG ((EFI_D_ERROR, "ARM OEM Fastboot command 'Demonstrate' received.\n"));

+    return EFI_SUCCESS;

+  } else {

+    DEBUG ((EFI_D_ERROR,

+      "VExpress: Unrecognised Fastboot OEM command: %s\n",

+      CommandUnicode

+      ));

+    return EFI_NOT_FOUND;

+  }

+}

+

+FASTBOOT_PLATFORM_PROTOCOL mPlatformProtocol = {

+  ArmFastbootPlatformInit,

+  ArmFastbootPlatformUnInit,

+  ArmFastbootPlatformFlashPartition,

+  ArmFastbootPlatformErasePartition,

+  ArmFastbootPlatformGetVar,

+  ArmFastbootPlatformOemCommand

+};

+

+EFI_STATUS

+EFIAPI

+ArmAndroidFastbootPlatformEntryPoint (

+  IN EFI_HANDLE                            ImageHandle,

+  IN EFI_SYSTEM_TABLE                      *SystemTable

+  )

+{

+  return gBS->InstallProtocolInterface (

+                &ImageHandle,

+                &gAndroidFastbootPlatformProtocolGuid,

+                EFI_NATIVE_INTERFACE,

+                &mPlatformProtocol

+                );

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBootDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBootDxe.inf
new file mode 100644
index 0000000..f5bae8a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressFastBootDxe/ArmVExpressFastBootDxe.inf
@@ -0,0 +1,55 @@
+#/** @file

+#

+#  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmVExpressFastBootDxe

+  FILE_GUID                      = 4004e454-89a0-11e3-89aa-97ef9d942abc

+  MODULE_TYPE                    = UEFI_DRIVER

+  VERSION_STRING                 = 1.0

+  ENTRY_POINT                    = ArmAndroidFastbootPlatformEntryPoint

+

+[Sources.common]

+  ArmVExpressFastBoot.c

+

+[LibraryClasses]

+  BaseLib

+  BaseMemoryLib

+  DebugLib

+  DevicePathLib

+  MemoryAllocationLib

+  PcdLib

+  UefiBootServicesTableLib

+  UefiDriverEntryPoint

+

+[Protocols]

+  gAndroidFastbootPlatformProtocolGuid

+  gEfiBlockIoProtocolGuid

+  gEfiDiskIoProtocolGuid

+

+[Packages]

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec

+  ArmPkg/ArmPkg.dec

+

+[Guids]

+  gArmGlobalVariableGuid

+

+[Pcd]

+  gArmVExpressTokenSpaceGuid.PcdAndroidFastbootNvmDevicePath

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor

+  gArmPlatformTokenSpaceGuid.PcdArmFastbootFlashLimit

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
new file mode 100644
index 0000000..f54733a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
@@ -0,0 +1,57 @@
+#/** @file

+# Arm Versatile Express package.

+#

+#  Copyright (c) 2012, ARM 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              = 0x00010005

+  PACKAGE_NAME                   = ArmVExpressPkg

+  PACKAGE_GUID                   = 9c0aaed4-74c5-4043-b417-a3223814ce76

+  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]

+  gArmVExpressTokenSpaceGuid    =  { 0x9c0aaed4, 0x74c5, 0x4043, { 0xb4, 0x17, 0xa3, 0x22, 0x38, 0x14, 0xce, 0x76 } }

+  #

+  # Following Guid must match FILE_GUID in MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  #

+  gVariableRuntimeDxeFileGuid = { 0xcbd2e4d5, 0x7068, 0x4ff5, { 0xb4, 0x62, 0x98, 0x22, 0xb4, 0xad, 0x8d, 0x60 } }

+

+[PcdsFeatureFlag.common]

+

+[PcdsFixedAtBuild.common]

+  #

+  # MaxMode must be one number higher than the actual max mode,

+  # i.e. for actual maximum mode 2, set the value to 3.

+  #

+  # For a list of mode numbers look in LcdArmVExpress.c

+  #

+  gArmVExpressTokenSpaceGuid.PcdPL111LcdMaxMode|3|UINT32|0x00000003

+  gArmVExpressTokenSpaceGuid.PcdPL111LcdVideoModeOscId|1|UINT32|0x00000004

+  gArmVExpressTokenSpaceGuid.PcdHdLcdVideoModeOscId|0|UINT32|0x00000009

+

+  #

+  # Device path of block device on which Fastboot will flash partitions

+  #

+  gArmVExpressTokenSpaceGuid.PcdAndroidFastbootNvmDevicePath|""|VOID*|0x00000001

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA15-A7/ArmPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA15-A7/ArmPlatform.h
new file mode 100644
index 0000000..b52f89a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA15-A7/ArmPlatform.h
@@ -0,0 +1,154 @@
+/** @file

+*  Header defining Versatile Express constants (Base addresses, sizes, flags)

+*

+*  Copyright (c) 2012, ARM 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.

+*

+**/

+

+#ifndef __ARM_VEXPRESS_CTA15A7_H__

+#define __ARM_VEXPRESS_CTA15A7_H__

+

+#include <VExpressMotherBoard.h>

+

+/***********************************************************************************

+// Platform Memory Map

+************************************************************************************/

+

+// Motherboard Peripheral and On-chip peripheral

+#define ARM_VE_BOARD_PERIPH_BASE              0x1C010000

+

+#ifdef ARM_BIGLITTLE_TC2

+

+// Secure NOR Flash

+#define ARM_VE_SEC_NOR0_BASE                  0x00000000

+#define ARM_VE_SEC_NOR0_SZ                    SIZE_64MB

+

+// Secure RAM

+#define ARM_VE_SEC_RAM0_BASE                  0x04000000

+#define ARM_VE_SEC_RAM0_SZ                    SIZE_64MB

+

+#endif

+

+// NOR Flash 0

+#define ARM_VE_SMB_NOR0_BASE                  0x08000000

+#define ARM_VE_SMB_NOR0_SZ                    SIZE_64MB

+// NOR Flash 1

+#define ARM_VE_SMB_NOR1_BASE                  0x0C000000

+#define ARM_VE_SMB_NOR1_SZ                    SIZE_64MB

+

+// SRAM

+#define ARM_VE_SMB_SRAM_BASE                  0x14000000

+#define ARM_VE_SMB_SRAM_SZ                    SIZE_32MB

+

+// USB, Ethernet, VRAM

+#ifdef ARM_BIGLITTLE_TC2

+#define ARM_VE_SMB_PERIPH_BASE                0x18000000

+#define ARM_VE_SMB_PERIPH_SZ                  (SIZE_64MB + SIZE_32MB + SIZE_16MB)

+#else

+#define ARM_VE_SMB_PERIPH_BASE                0x1C000000

+#define ARM_VE_SMB_PERIPH_SZ                  (SIZE_64MB + SIZE_16MB)

+#endif

+#define PL111_CLCD_VRAM_MOTHERBOARD_BASE      ARM_VE_SMB_PERIPH_BASE

+

+// On-Chip non-secure ROM

+#ifdef ARM_BIGLITTLE_TC2

+#define ARM_VE_TC2_NON_SECURE_ROM_BASE        0x1F000000

+#define ARM_VE_TC2_NON_SECURE_ROM_SZ          SIZE_16MB

+#endif

+

+// On-Chip Peripherals

+#define ARM_VE_ONCHIP_PERIPH_BASE             0x20000000

+#define ARM_VE_ONCHIP_PERIPH_SZ               0x10000000

+

+// On-Chip non-secure SRAM

+#ifdef ARM_BIGLITTLE_TC2

+#define ARM_VE_TC2_NON_SECURE_SRAM_BASE       0x2E000000

+#define ARM_VE_TC2_NON_SECURE_SRAM_SZ         SIZE_64KB

+#endif

+

+// Allocate a section for the VRAM (Video RAM)

+// If 0 then allow random memory allocation

+#define LCD_VRAM_CORE_TILE_BASE               0

+

+// Define SEC phase sync point

+#define ARM_SEC_EVENT_BOOT_IMAGE_TABLE_IS_AVAILABLE   (ARM_SEC_EVENT_MAX + 1)

+

+/***********************************************************************************

+   Core Tile memory-mapped Peripherals

+************************************************************************************/

+

+// PL354 Static Memory Controller Base

+#ifdef ARM_BIGLITTLE_TC2

+#define ARM_VE_SMC_CTRL_BASE                    0x7FFD0000

+#else

+#define ARM_VE_SMC_CTRL_BASE                    (ARM_VE_BOARD_PERIPH_BASE + 0xE1000)

+#endif

+

+#define ARM_CTA15A7_SCC_BASE                    0x7FFF0000

+#define ARM_CTA15A7_SCC_CFGREG48                (ARM_CTA15A7_SCC_BASE + 0x700)

+

+#define ARM_CTA15A7_SCC_SYSINFO                 ARM_CTA15A7_SCC_CFGREG48

+

+#define ARM_CTA15A7_SCC_SYSINFO_CLUSTER_A7_NUM_CPU(val)         (((val) >> 20) & 0xF)

+#define ARM_CTA15A7_SCC_SYSINFO_CLUSTER_A15_NUM_CPU(val)        (((val) >> 16) & 0xF)

+#define ARM_CTA15A7_SCC_SYSINFO_ACTIVE_CLUSTER_A15              (1 << 0)

+#define ARM_CTA15A7_SCC_SYSINFO_ACTIVE_CLUSTER_A7               (1 << 1)

+#define ARM_CTA15A7_SCC_SYSINFO_UEFI_RESTORE_DEFAULT_NORFLASH   (1 << 4)

+

+#define ARM_CTA15A7_SPC_BASE                    0x7FFF0B00

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK           (ARM_CTA15A7_SPC_BASE + 0x24)

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT         (ARM_CTA15A7_SPC_BASE + 0x3C)

+#define ARM_CTA15A7_SPC_A15_BX_ADDR0            (ARM_CTA15A7_SPC_BASE + 0x68)

+#define ARM_CTA15A7_SPC_A15_BX_ADDR1            (ARM_CTA15A7_SPC_BASE + 0x6C)

+#define ARM_CTA15A7_SPC_A15_BX_ADDR2            (ARM_CTA15A7_SPC_BASE + 0x70)

+#define ARM_CTA15A7_SPC_A15_BX_ADDR3            (ARM_CTA15A7_SPC_BASE + 0x74)

+#define ARM_CTA15A7_SPC_A7_BX_ADDR0             (ARM_CTA15A7_SPC_BASE + 0x78)

+#define ARM_CTA15A7_SPC_A7_BX_ADDR1             (ARM_CTA15A7_SPC_BASE + 0x7C)

+#define ARM_CTA15A7_SPC_A7_BX_ADDR2             (ARM_CTA15A7_SPC_BASE + 0x80)

+#define ARM_CTA15A7_SPC_A7_BX_ADDR3             (ARM_CTA15A7_SPC_BASE + 0x84)

+

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_IRQ_A15_MASK_0  (1 << 0)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_IRQ_A15_MASK_1  (1 << 1)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_FIQ_A15_MASK_0  (1 << 2)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_FIQ_A15_MASK_1  (1 << 3)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_IRQ_A7_MASK_0   (1 << 4)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_IRQ_A7_MASK_1   (1 << 5)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_IRQ_A7_MASK_2   (1 << 6)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_FIQ_A7_MASK_0   (1 << 7)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_FIQ_A7_MASK_1   (1 << 8)

+#define ARM_CTA15A7_SPC_WAKE_INT_MASK_FIQ_A7_MASK_2   (1 << 9)

+

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT_A15_0   (1 << 0)

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT_A15_1   (1 << 1)

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT_A15_L2  (1 << 2)

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT_A7_0    (1 << 3)

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT_A7_1    (1 << 4)

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT_A7_2    (1 << 5)

+#define ARM_CTA15A7_SPC_STANDBYWFI_STAT_A7_L2   (1 << 6)

+

+

+/***********************************************************************************

+// Memory-mapped peripherals

+************************************************************************************/

+

+/*// SP810 Controller

+#undef SP810_CTRL_BASE

+#define SP810_CTRL_BASE                         0x1C020000

+

+// PL111 Colour LCD Controller

+#define PL111_CLCD_SITE                         ARM_VE_MOTHERBOARD_SITE

+#define PL111_CLCD_MOTHERBOARD_VIDEO_MODE_OSC_ID  1

+#define PL111_CLCD_CORE_TILE_VIDEO_MODE_OSC_ID  1

+

+// VRAM offset for the PL111 Colour LCD Controller on the motherboard

+#define VRAM_MOTHERBOARD_BASE                     (ARM_VE_SMB_PERIPH_BASE   + 0x00000)*/

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA9x4/ArmPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA9x4/ArmPlatform.h
new file mode 100644
index 0000000..b692b16
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/CTA9x4/ArmPlatform.h
@@ -0,0 +1,121 @@
+/** @file

+*  Header defining Versatile Express constants (Base addresses, sizes, flags)

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef __ARM_VEXPRESS_H__

+#define __ARM_VEXPRESS_H__

+

+#include <Base.h>

+#include <VExpressMotherBoard.h>

+

+/***********************************************************************************

+// Platform Memory Map

+************************************************************************************/

+

+// Can be NOR0, NOR1, DRAM

+#define ARM_VE_REMAP_BASE                       0x00000000

+#define ARM_VE_REMAP_SZ                         SIZE_64MB

+

+// Motherboard Peripheral and On-chip peripheral

+#define ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE       0x10000000

+#define ARM_VE_SMB_MB_ON_CHIP_PERIPH_SZ         SIZE_256MB

+#define ARM_VE_BOARD_PERIPH_BASE                0x10000000

+#define ARM_VE_CHIP_PERIPH_BASE                 0x10020000

+

+// SMC

+#define ARM_VE_SMC_BASE                         0x40000000

+#define ARM_VE_SMC_SZ                           0x1C000000

+

+// NOR Flash 1

+#define ARM_VE_SMB_NOR0_BASE                    0x40000000

+#define ARM_VE_SMB_NOR0_SZ                      SIZE_64MB

+// NOR Flash 2

+#define ARM_VE_SMB_NOR1_BASE                    0x44000000

+#define ARM_VE_SMB_NOR1_SZ                      SIZE_64MB

+// SRAM

+#define ARM_VE_SMB_SRAM_BASE                    0x48000000

+#define ARM_VE_SMB_SRAM_SZ                      SIZE_32MB

+// USB, Ethernet, VRAM

+#define ARM_VE_SMB_PERIPH_BASE                  0x4C000000

+#define PL111_CLCD_VRAM_MOTHERBOARD_BASE        ARM_VE_SMB_PERIPH_BASE

+#define ARM_VE_SMB_PERIPH_SZ                    SIZE_64MB

+

+// DRAM

+#define ARM_VE_DRAM_BASE                        PcdGet64 (PcdSystemMemoryBase)

+#define ARM_VE_DRAM_SZ                          PcdGet64 (PcdSystemMemorySize)

+// Inside the DRAM we allocate a section for the VRAM (Video RAM)

+#define LCD_VRAM_CORE_TILE_BASE                     0x64000000

+

+// External AXI between daughterboards (Logic Tile)

+#define ARM_VE_EXT_AXI_BASE                     0xE0000000

+#define ARM_VE_EXT_AXI_SZ                       0x20000000  /* 512 MB */

+

+

+/***********************************************************************************

+   Core Tile memory-mapped Peripherals

+************************************************************************************/

+

+// PL111 Colour LCD Controller - core tile

+#define PL111_CLCD_CORE_TILE_BASE               (ARM_VE_BOARD_PERIPH_BASE + 0x20000)

+#define PL111_CLCD_SITE                         ARM_VE_DAUGHTERBOARD_1_SITE

+

+// PL341 Dynamic Memory Controller Base

+#define ARM_VE_DMC_BASE                         (ARM_VE_BOARD_PERIPH_BASE + 0xE0000)

+

+// PL354 Static Memory Controller Base

+#define ARM_VE_SMC_CTRL_BASE                    (ARM_VE_BOARD_PERIPH_BASE + 0xE1000)

+

+// System Configuration Controller register Base addresses

+#define ARM_VE_SYS_CFG_CTRL_BASE                (ARM_VE_BOARD_PERIPH_BASE + 0xE2000)

+#define ARM_VE_SCC_BASE                         ARM_VE_SYS_CFG_CTRL_BASE

+#define ARM_VE_SYS_CFGRW0_REG                   (ARM_VE_BOARD_PERIPH_BASE + 0xE2000)

+#define ARM_VE_SYS_CFGRW1_REG                   (ARM_VE_BOARD_PERIPH_BASE + 0xE2004)

+#define ARM_VE_SYS_CFGRW2_REG                   (ARM_VE_BOARD_PERIPH_BASE + 0xE2008)

+

+// SP805 Watchdog on Cortex A9 core tile

+#define SP805_WDOG_CORE_TILE_BASE               (ARM_VE_BOARD_PERIPH_BASE + 0xE5000)

+

+// BP147 TZPC Base Address

+#define ARM_VE_TZPC_BASE                        (ARM_VE_BOARD_PERIPH_BASE + 0xE6000)

+

+// PL301 Fast AXI Base Address

+#define ARM_VE_FAXI_BASE                        (ARM_VE_BOARD_PERIPH_BASE + 0xE9000)

+

+// TZASC Trust Zone Address Space Controller Base Address

+#define ARM_VE_TZASC_BASE                       (ARM_VE_BOARD_PERIPH_BASE + 0xEC000)

+

+// PL310 L2x0 Cache Controller Base Address

+//#define ARM_VE_L2x0_CTLR_BASE                 0x1E00A000

+

+/***********************************************************************************

+   Peripherals' misc settings

+************************************************************************************/

+

+#define ARM_VE_CFGRW1_TZASC_EN_BIT_MASK         0x2000

+#define ARM_VE_CFGRW1_REMAP_NOR0                0

+#define ARM_VE_CFGRW1_REMAP_NOR1                (1 << 28)

+#define ARM_VE_CFGRW1_REMAP_EXT_AXI             (1 << 29)

+#define ARM_VE_CFGRW1_REMAP_DRAM                (1 << 30)

+

+// TZASC - Other settings

+#define ARM_VE_DECPROT_BIT_TZPC                 (1 << 6)

+#define ARM_VE_DECPROT_BIT_DMC_TZASC            (1 << 11)

+#define ARM_VE_DECPROT_BIT_NMC_TZASC            (1 << 12)

+#define ARM_VE_DECPROT_BIT_SMC_TZASC            (1 << 13)

+#define ARM_VE_DECPROT_BIT_EXT_MAST_TZ          (1)

+#define ARM_VE_DECPROT_BIT_DMC_TZASC_LOCK       (1 << 3)

+#define ARM_VE_DECPROT_BIT_NMC_TZASC_LOCK       (1 << 4)

+#define ARM_VE_DECPROT_BIT_SMC_TZASC_LOCK       (1 << 5)

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM/ArmPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM/ArmPlatform.h
new file mode 100644
index 0000000..06414e6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/Platform/RTSM/ArmPlatform.h
@@ -0,0 +1,80 @@
+/** @file

+*  Header defining Versatile Express constants (Base addresses, sizes, flags)

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef __ARM_VEXPRESS_H__

+#define __ARM_VEXPRESS_H__

+

+#include <VExpressMotherBoard.h>

+

+/***********************************************************************************

+// Platform Memory Map

+************************************************************************************/

+

+// Can be NOR0, NOR1, DRAM

+#define ARM_VE_REMAP_BASE                       0x00000000

+#define ARM_VE_REMAP_SZ                         SIZE_64MB

+

+// Motherboard Peripheral and On-chip peripheral

+#define ARM_VE_BOARD_PERIPH_BASE                0x1C010000

+

+// NOR Flash 1

+// There is typo in the reference manual for the Base address of NOR Flash 1

+#define ARM_VE_SMB_NOR0_BASE                    0x08000000

+#define ARM_VE_SMB_NOR0_SZ                      SIZE_64MB

+// NOR Flash 2

+#define ARM_VE_SMB_NOR1_BASE                    0x0C000000

+#define ARM_VE_SMB_NOR1_SZ                      SIZE_64MB

+// SRAM

+#define ARM_VE_SMB_SRAM_BASE                    0x2E000000

+#define ARM_VE_SMB_SRAM_SZ                      SIZE_64KB

+// USB, Ethernet, VRAM

+#define ARM_VE_SMB_PERIPH_BASE                  0x18000000

+#define PL111_CLCD_VRAM_MOTHERBOARD_BASE        ARM_VE_SMB_PERIPH_BASE

+#define ARM_VE_SMB_PERIPH_SZ                    SIZE_64MB

+

+// DRAM

+#define ARM_VE_DRAM_BASE                        PcdGet64 (PcdSystemMemoryBase)

+#define ARM_VE_DRAM_SZ                          PcdGet64 (PcdSystemMemorySize)

+

+// This can be any value since we only support motherboard PL111

+#define LCD_VRAM_CORE_TILE_BASE                 0x00000000

+

+// On-chip peripherals (Snoop Control Unit etc...)

+#define ARM_VE_ON_CHIP_PERIPH_BASE              0x2C000000

+// Note: The TRM says not all the peripherals are implemented

+#define ARM_VE_ON_CHIP_PERIPH_SZ                SIZE_256MB

+

+

+// External AXI between daughterboards (Logic Tile)

+#define ARM_VE_EXT_AXI_BASE                     0x2E010000 // Not modelled

+#define ARM_VE_EXT_AXI_SZ                       0x20000000  /* 512 MB */

+

+/***********************************************************************************

+// Memory-mapped peripherals

+************************************************************************************/

+

+// SP810 Controller

+#undef SP810_CTRL_BASE

+#define SP810_CTRL_BASE                         0x1C020000

+

+// PL111 Colour LCD Controller

+#define PL111_CLCD_SITE                         ARM_VE_MOTHERBOARD_SITE

+#define PL111_CLCD_MOTHERBOARD_VIDEO_MODE_OSC_ID  1

+#define PL111_CLCD_CORE_TILE_VIDEO_MODE_OSC_ID  1

+

+// VRAM offset for the PL111 Colour LCD Controller on the motherboard

+#define VRAM_MOTHERBOARD_BASE                     (ARM_VE_SMB_PERIPH_BASE   + 0x00000)

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/VExpressMotherBoard.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/VExpressMotherBoard.h
new file mode 100644
index 0000000..dd16b93
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Include/VExpressMotherBoard.h
@@ -0,0 +1,131 @@
+/** @file

+*  Header defining Versatile Express constants (Base addresses, sizes, flags)

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#ifndef __VEXPRESSMOTHERBOARD_H_

+#define __VEXPRESSMOTHERBOARD_H_

+

+#include <ArmPlatform.h>

+

+/***********************************************************************************

+// Motherboard memory-mapped peripherals

+************************************************************************************/

+

+// Define MotherBoard SYS flags offsets (from ARM_VE_BOARD_PERIPH_BASE)

+#define ARM_VE_SYS_ID_REG                         (ARM_VE_BOARD_PERIPH_BASE + 0x00000)

+#define ARM_VE_SYS_SW_REG                         (ARM_VE_BOARD_PERIPH_BASE + 0x00004)

+#define ARM_VE_SYS_LED_REG                        (ARM_VE_BOARD_PERIPH_BASE + 0x00008)

+#define ARM_VE_SYS_FLAGS_REG                      (ARM_VE_BOARD_PERIPH_BASE + 0x00030)

+#define ARM_VE_SYS_FLAGS_SET_REG                  (ARM_VE_BOARD_PERIPH_BASE + 0x00030)

+#define ARM_VE_SYS_FLAGS_CLR_REG                  (ARM_VE_BOARD_PERIPH_BASE + 0x00034)

+#define ARM_VE_SYS_FLAGS_NV_REG                   (ARM_VE_BOARD_PERIPH_BASE + 0x00038)

+#define ARM_VE_SYS_FLAGS_NV_SET_REG               (ARM_VE_BOARD_PERIPH_BASE + 0x00038)

+#define ARM_VE_SYS_FLAGS_NV_CLR_REG               (ARM_VE_BOARD_PERIPH_BASE + 0x0003C)

+#define ARM_VE_SYS_FLASH                          (ARM_VE_BOARD_PERIPH_BASE + 0x0004C)

+#define ARM_VE_SYS_CFGSWR_REG                     (ARM_VE_BOARD_PERIPH_BASE + 0x00058)

+#define ARM_VE_SYS_MISC                           (ARM_VE_BOARD_PERIPH_BASE + 0x00060)

+#define ARM_VE_SYS_PROCID0_REG                    (ARM_VE_BOARD_PERIPH_BASE + 0x00084)

+#define ARM_VE_SYS_PROCID1_REG                    (ARM_VE_BOARD_PERIPH_BASE + 0x00088)

+#define ARM_VE_SYS_CFGDATA_REG                    (ARM_VE_BOARD_PERIPH_BASE + 0x000A0)

+#define ARM_VE_SYS_CFGCTRL_REG                    (ARM_VE_BOARD_PERIPH_BASE + 0x000A4)

+#define ARM_VE_SYS_CFGSTAT_REG                    (ARM_VE_BOARD_PERIPH_BASE + 0x000A8)

+

+// SP810 Controller

+#ifndef SP810_CTRL_BASE

+#define SP810_CTRL_BASE                           (ARM_VE_BOARD_PERIPH_BASE + 0x01000)

+#endif

+

+// PL111 Colour LCD Controller - motherboard

+#define PL111_CLCD_MOTHERBOARD_BASE               (ARM_VE_BOARD_PERIPH_BASE + 0x1F000)

+#define PL111_CLCD_MOTHERBOARD_VIDEO_MODE_OSC_ID  1

+

+// VRAM offset for the PL111 Colour LCD Controller on the motherboard

+#define VRAM_MOTHERBOARD_BASE                     (ARM_VE_SMB_PERIPH_BASE   + 0x00000)

+

+#define ARM_VE_SYS_PROC_ID_HBI                    0xFFF

+#define ARM_VE_SYS_PROC_ID_MASK                   (UINT32)(0xFFU << 24)

+#define ARM_VE_SYS_PROC_ID_UNSUPPORTED            (UINT32)(0xFFU << 24)

+#define ARM_VE_SYS_PROC_ID_CORTEX_A9              (UINT32)(0x0CU << 24)

+#define ARM_VE_SYS_PROC_ID_CORTEX_A5              (UINT32)(0x12U << 24)

+#define ARM_VE_SYS_PROC_ID_CORTEX_A15             (UINT32)(0x14U << 24)

+#define ARM_VE_SYS_PROC_ID_CORTEX_A7              (UINT32)(0x18U << 24)

+#define ARM_VE_SYS_PROC_ID_CORTEX_A12             (UINT32)(0x1CU << 24)

+

+// Boot Master Select:

+// 0 = Site 1 boot master

+// 1 = Site 2 boot master

+#define ARM_VE_SYS_MISC_MASTERSITE                (1 << 14)

+//

+// Sites where the peripheral is fitted

+//

+#define ARM_VE_UNSUPPORTED                        ~0

+#define ARM_VE_MOTHERBOARD_SITE                   0

+#define ARM_VE_DAUGHTERBOARD_1_SITE               1

+#define ARM_VE_DAUGHTERBOARD_2_SITE               2

+

+#define VIRTUAL_SYS_CFG(site,func)                (((site) << 24) | (func))

+

+//

+// System Configuration Control Functions

+//

+#define SYS_CFG_OSC                               1

+#define SYS_CFG_VOLT                              2

+#define SYS_CFG_AMP                               3

+#define SYS_CFG_TEMP                              4

+#define SYS_CFG_RESET                             5

+#define SYS_CFG_SCC                               6

+#define SYS_CFG_MUXFPGA                           7

+#define SYS_CFG_SHUTDOWN                          8

+#define SYS_CFG_REBOOT                            9

+#define SYS_CFG_DVIMODE                           11

+#define SYS_CFG_POWER                             12

+// Oscillator for Site 1

+#define SYS_CFG_OSC_SITE1                         VIRTUAL_SYS_CFG(ARM_VE_DAUGHTERBOARD_1_SITE,SYS_CFG_OSC)

+// Oscillator for Site 2

+#define SYS_CFG_OSC_SITE2                         VIRTUAL_SYS_CFG(ARM_VE_DAUGHTERBOARD_2_SITE,SYS_CFG_OSC)

+// Can not access the battery backed-up hardware clock on the Versatile Express motherboard

+#define SYS_CFG_RTC                               VIRTUAL_SYS_CFG(ARM_VE_UNSUPPORTED,1)

+

+//

+// System ID

+//

+// All RTSM VE models have the same System ID : 0x225F500

+//

+// FVP models have a different System ID.

+// Default Base model System ID : 0x00201100

+// [31:28] Rev     - Board revision:          0x0     = Rev A

+// [27:16] HBI     - HBI board number in BCD: 0x020   = v8 Base Platform

+// [15:12] Variant - Build variant of board:  0x1     = Variant B. (GIC 64k map)

+// [11:8]  Plat    - Platform type:           0x1     = Model

+// [7:0]   FPGA    - FPGA build, BCD coded:   0x00

+//

+//HBI = 010 = Foundation Model

+//HBI = 020 = Base Platform

+//

+// And specifically, the GIC register banks start at the following

+// addresses:

+//              Variant = 0             Variant = 1

+//GICD          0x2c001000              0x2f000000

+//GICC          0x2c002000              0x2c000000

+//GICH          0x2c004000              0x2c010000

+//GICV          0x2c006000              0x2c020000

+

+// The default SYS_IDs. These can be changed when starting the model.

+#define ARM_RTSM_SYS_ID                (0x225F500)

+#define ARM_FVP_BASE_SYS_ID            (0x00201100)

+#define ARM_FVP_FOUNDATION_SYS_ID      (0x00101100)

+

+#define ARM_FVP_SYS_ID_VARIANT_MASK    (UINT32)(0xFUL << 12)

+

+#endif /* VEXPRESSMOTHERBOARD_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/ArmVExpressLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/ArmVExpressLib.inf
new file mode 100644
index 0000000..10ae6c7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/ArmVExpressLib.inf
@@ -0,0 +1,50 @@
+#/* @file

+#

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = CTA15A7ArmVExpressLib

+  FILE_GUID                      = b98a6cb7-d472-4128-ad62-a7347f85ce13

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  MemoryAllocationLib

+  SerialPortLib

+

+[Sources.common]

+  CTA15-A7.c

+  CTA15-A7Mem.c

+  CTA15-A7Helper.asm | RVCT

+  CTA15-A7Helper.S   | GCC

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

+

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+  gArmTokenSpaceGuid.PcdFvBaseAddress

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7.c
new file mode 100644
index 0000000..8b3287b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7.c
@@ -0,0 +1,197 @@
+/** @file

+*

+*  Copyright (c) 2012, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+#include <ArmPlatform.h>

+

+ARM_CORE_INFO mVersatileExpressCTA15A7InfoTable[] = {

+  {

+    // Cluster 0, Core 0

+    0x0, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR0,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR0,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR0,

+    (UINT64)0

+  },

+  {

+    // Cluster 0, Core 1

+    0x0, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR1,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR1,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR1,

+    (UINT64)0

+  },

+#ifndef ARM_BIGLITTLE_TC2

+  {

+    // Cluster 0, Core 2

+    0x0, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR2,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR2,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR2,

+    (UINT64)0

+  },

+  {

+    // Cluster 0, Core 3

+    0x0, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR3,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR3,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A15_BX_ADDR3,

+    (UINT64)0

+  },

+#endif

+  {

+    // Cluster 1, Core 0

+    0x1, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR0,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR0,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR0,

+    (UINT64)0

+  },

+  {

+    // Cluster 1, Core 1

+    0x1, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR1,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR1,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR1,

+    (UINT64)0

+  },

+  {

+    // Cluster 1, Core 2

+    0x1, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR2,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR2,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR2,

+    (UINT64)0

+  }

+#ifndef ARM_BIGLITTLE_TC2

+  ,{

+    // Cluster 1, Core 3

+    0x1, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR3,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR3,

+    (EFI_PHYSICAL_ADDRESS)ARM_CTA15A7_SPC_A7_BX_ADDR3,

+    (UINT64)0

+  }

+#endif

+};

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+  @return   Return the current Boot Mode of the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  if (MmioRead32(ARM_CTA15A7_SCC_SYSINFO) & ARM_CTA15A7_SCC_SYSINFO_UEFI_RESTORE_DEFAULT_NORFLASH) {

+    return BOOT_WITH_DEFAULT_SETTINGS;

+  } else {

+    return BOOT_WITH_FULL_CONFIGURATION;

+  }

+}

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // Nothing to do here

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+}

+

+EFI_STATUS

+PrePeiCoreGetMpCoreInfo (

+  OUT UINTN                   *CoreCount,

+  OUT ARM_CORE_INFO           **ArmCoreTable

+  )

+{

+  // Only support one cluster

+  *CoreCount    = sizeof(mVersatileExpressCTA15A7InfoTable) / sizeof(ARM_CORE_INFO);

+  *ArmCoreTable = mVersatileExpressCTA15A7InfoTable;

+  return EFI_SUCCESS;

+}

+

+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore

+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;

+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };

+

+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &mArmMpCoreInfoPpiGuid,

+    &mMpCoreInfoPpi

+  }

+};

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  *PpiListSize = sizeof(gPlatformPpiTable);

+  *PpiList = gPlatformPpiTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Helper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Helper.S
new file mode 100644
index 0000000..20bfe52
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Helper.S
@@ -0,0 +1,89 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+#include <ArmPlatform.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  bx    lr

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  // Extract cpu_id and cluster_id from ARM_SCC_CFGREG48

+  // with cpu_id[0:3] and cluster_id[4:7]

+  LoadConstantToReg (ARM_CTA15A7_SCC_CFGREG48, r1)

+  ldr   r1, [r1]

+  lsr   r1, #24

+

+  // Shift the SCC value to get the cluster ID at the offset #8

+  lsl   r2, r1, #4

+  and   r2, r2, #0xF00

+

+  // Keep only the cpu ID from the original SCC

+  and   r1, r1, #0x0F

+  // Add the Cluster ID to the Cpu ID

+  orr   r1, r1, r2

+

+  // Keep the Cluster ID and Core ID from the MPID

+  LoadConstantToReg (ARM_CLUSTER_MASK | ARM_CORE_MASK, r2)

+  and   r0, r0, r2

+

+  // Compare mpid and boot cpu from ARM_SCC_CFGREG48

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  // Extract cpu_id and cluster_id from ARM_SCC_CFGREG48

+  // with cpu_id[0:3] and cluster_id[4:7]

+  LoadConstantToReg (ARM_CTA15A7_SCC_CFGREG48, r0)

+  ldr   r0, [r0]

+  lsr   r0, #24

+

+  // Shift the SCC value to get the cluster ID at the offset #8

+  lsl   r1, r0, #4

+  and   r1, r1, #0xF00

+

+  // Keep only the cpu ID from the original SCC

+  and   r0, r0, #0x0F

+  // Add the Cluster ID to the Cpu ID

+  orr   r0, r0, r1

+  bx    lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Helper.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Helper.asm
new file mode 100644
index 0000000..f377cf2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Helper.asm
@@ -0,0 +1,97 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+#include <ArmPlatform.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformPeiBootAction

+  EXPORT  ArmPlatformGetCorePosition

+  EXPORT  ArmPlatformIsPrimaryCore

+  EXPORT  ArmPlatformGetPrimaryCoreMpId

+

+  PRESERVE8

+  AREA    CTA15A7Helper, CODE, READONLY

+

+ArmPlatformPeiBootAction FUNCTION

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ArmPlatformGetCorePosition FUNCTION

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ArmPlatformIsPrimaryCore FUNCTION

+  // Extract cpu_id and cluster_id from ARM_SCC_CFGREG48

+  // with cpu_id[0:3] and cluster_id[4:7]

+  LoadConstantToReg (ARM_CTA15A7_SCC_CFGREG48, r1)

+  ldr   r1, [r1]

+  lsr   r1, #24

+

+  // Shift the SCC value to get the cluster ID at the offset #8

+  lsl   r2, r1, #4

+  and   r2, r2, #0xF00

+

+  // Keep only the cpu ID from the original SCC

+  and   r1, r1, #0x0F

+  // Add the Cluster ID to the Cpu ID

+  orr   r1, r1, r2

+

+  // Keep the Cluster ID and Core ID from the MPID

+  LoadConstantToReg (ARM_CLUSTER_MASK :OR: ARM_CORE_MASK, r2)

+  and   r0, r0, r2

+

+  // Compare mpid and boot cpu from ARM_SCC_CFGREG48

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ArmPlatformGetPrimaryCoreMpId FUNCTION

+  // Extract cpu_id and cluster_id from ARM_SCC_CFGREG48

+  // with cpu_id[0:3] and cluster_id[4:7]

+  LoadConstantToReg (ARM_CTA15A7_SCC_CFGREG48, r0)

+  ldr   r0, [r0]

+  lsr   r0, #24

+

+  // Shift the SCC value to get the cluster ID at the offset #8

+  lsl   r1, r0, #4

+  and   r1, r1, #0xF00

+

+  // Keep only the cpu ID from the original SCC

+  and   r0, r0, #0x0F

+  // Add the Cluster ID to the Cpu ID

+  orr   r0, r0, r1

+  bx    lr

+  ENDFUNC

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Mem.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Mem.c
new file mode 100644
index 0000000..4403cba
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15-A7/CTA15-A7Mem.c
@@ -0,0 +1,182 @@
+/** @file

+*

+*  Copyright (c) 2012, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PcdLib.h>

+

+#include <ArmPlatform.h>

+

+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 14

+

+// DDR attributes

+#define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK

+#define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;

+  UINTN                         Index = 0;

+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;

+

+  ASSERT (VirtualMemoryMap != NULL);

+

+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));

+  if (VirtualMemoryTable == NULL) {

+    return;

+  }

+

+  if (FeaturePcdGet(PcdCacheEnable) == TRUE) {

+    CacheAttributes = DDR_ATTRIBUTES_CACHED;

+  } else {

+    CacheAttributes = DDR_ATTRIBUTES_UNCACHED;

+  }

+

+#ifdef ARM_BIGLITTLE_TC2

+  // Secure NOR0 Flash

+  VirtualMemoryTable[Index].PhysicalBase    = ARM_VE_SEC_NOR0_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SEC_NOR0_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_SEC_NOR0_SZ;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+  // Secure RAM

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SEC_RAM0_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SEC_RAM0_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_SEC_RAM0_SZ;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+#endif

+

+  // SMB CS0 - NOR0 Flash

+  VirtualMemoryTable[Index].PhysicalBase    = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].Length          = SIZE_256KB * 255;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+  // Environment Variables region

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SMB_NOR0_BASE + (SIZE_256KB * 255);

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_NOR0_BASE + (SIZE_256KB * 255);

+  VirtualMemoryTable[Index].Length          = SIZE_64KB * 4;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS1 or CS4 - NOR1 Flash

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SMB_NOR1_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_NOR1_BASE;

+  VirtualMemoryTable[Index].Length          = SIZE_256KB * 255;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+  // Environment Variables region

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SMB_NOR1_BASE + (SIZE_256KB * 255);

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_NOR1_BASE + (SIZE_256KB * 255);

+  VirtualMemoryTable[Index].Length          = SIZE_64KB * 4;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS3 or CS1 - PSRAM

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_SMB_SRAM_SZ;

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+

+  // Motherboard peripherals

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_SMB_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+#ifdef ARM_BIGLITTLE_TC2

+  // Non-secure ROM

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_TC2_NON_SECURE_ROM_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_TC2_NON_SECURE_ROM_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_TC2_NON_SECURE_ROM_SZ;

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+#endif

+

+  // OnChip peripherals

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_ONCHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_ONCHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_ONCHIP_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SCC Region

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_CTA15A7_SCC_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_CTA15A7_SCC_BASE;

+  VirtualMemoryTable[Index].Length          = SIZE_64KB;

+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+#ifdef ARM_BIGLITTLE_TC2

+  // TC2 OnChip non-secure SRAM

+  VirtualMemoryTable[++Index].PhysicalBase  = ARM_VE_TC2_NON_SECURE_SRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase     = ARM_VE_TC2_NON_SECURE_SRAM_BASE;

+  VirtualMemoryTable[Index].Length          = ARM_VE_TC2_NON_SECURE_SRAM_SZ;

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+#endif

+

+#ifndef ARM_BIGLITTLE_TC2

+  // Workaround for SRAM bug in RTSM

+  if (PcdGet64 (PcdSystemMemoryBase) != 0x80000000) {

+    VirtualMemoryTable[++Index].PhysicalBase  = 0x80000000;

+    VirtualMemoryTable[Index].VirtualBase     = 0x80000000;

+    VirtualMemoryTable[Index].Length          = PcdGet64 (PcdSystemMemoryBase) - 0x80000000;

+    VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+  }

+#endif

+

+  // DDR

+  VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdSystemMemoryBase);

+  VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdSystemMemoryBase);

+  VirtualMemoryTable[Index].Length          = PcdGet64 (PcdSystemMemorySize);

+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+

+  // Detect if it is a 1GB or 2GB Test Chip

+  //   [16:19]: 0=1GB TC2, 1=2GB TC2

+  if (MmioRead32(ARM_VE_SYS_PROCID0_REG) & (0xF << 16)) {

+    DEBUG((EFI_D_ERROR,"Info: 2GB Test Chip 2 detected.\n"));

+    BuildResourceDescriptorHob (

+        EFI_RESOURCE_SYSTEM_MEMORY,

+        EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |

+          EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |

+          EFI_RESOURCE_ATTRIBUTE_TESTED,

+        PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize),

+        SIZE_1GB

+    );

+

+    // Map the additional 1GB into the MMU

+    VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize);

+    VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize);

+    VirtualMemoryTable[Index].Length          = SIZE_1GB;

+    VirtualMemoryTable[Index].Attributes      = CacheAttributes;

+  }

+

+  // End of Table

+  VirtualMemoryTable[++Index].PhysicalBase  = 0;

+  VirtualMemoryTable[Index].VirtualBase     = 0;

+  VirtualMemoryTable[Index].Length          = 0;

+  VirtualMemoryTable[Index].Attributes      = (ARM_MEMORY_REGION_ATTRIBUTES)0;

+

+  ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);

+

+  *VirtualMemoryMap = VirtualMemoryTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLib.inf
new file mode 100644
index 0000000..d3c84de
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLib.inf
@@ -0,0 +1,54 @@
+#/* @file

+#  Copyright (c) 2011-2013, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = CTA9x4ArmVExpressLib

+  FILE_GUID                      = b16c63a0-f417-11df-b3af-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  ArmTrustZoneLib

+  MemoryAllocationLib

+  PL341DmcLib

+  PL301AxiLib

+

+[Sources.common]

+  CTA9x4Helper.asm    | RVCT

+  CTA9x4Helper.S      | GCC

+  CTA9x4.c

+  CTA9x4Mem.c

+  CTA9x4Helper.S   | GCC

+  CTA9x4Helper.asm | RVCT

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLibSec.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLibSec.inf
new file mode 100644
index 0000000..20fc0b7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/ArmVExpressLibSec.inf
@@ -0,0 +1,51 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = CTA9x4ArmVExpressLibSec

+  FILE_GUID                      = 8d25ef2c-2015-416e-b8aa-2369fecd4bda

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  ArmTrustZoneLib

+  PL341DmcLib

+  PL301AxiLib

+  SerialPortLib

+

+[Sources.common]

+  CTA9x4.c

+  CTA9x4Helper.S   | GCC

+  CTA9x4Helper.asm | RVCT

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c
new file mode 100644
index 0000000..0af1389
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c
@@ -0,0 +1,200 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Drivers/PL341Dmc.h>

+#include <Drivers/PL301Axi.h>

+#include <Drivers/SP804Timer.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+#include <ArmPlatform.h>

+

+ARM_CORE_INFO mVersatileExpressMpCoreInfoCTA9x4[] = {

+  {

+    // Cluster 0, Core 0

+    0x0, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 1

+    0x0, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 2

+    0x0, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 3

+    0x0, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  }

+};

+

+// DDR2 timings

+PL341_DMC_CONFIG DDRTimings = {

+  .MaxChip   = 1,

+  .IsUserCfg = TRUE,

+  .User0Cfg = 0x7C924924,

+  .User2Cfg = (TC_UIOLHXC_VALUE << TC_UIOLHNC_SHIFT) | (TC_UIOLHXC_VALUE << TC_UIOLHPC_SHIFT) | (0x1 << TC_UIOHOCT_SHIFT) | (0x1 << TC_UIOHSTOP_SHIFT),

+  .HasQos    = TRUE,

+  .RefreshPeriod  = 0x3D0,

+  .CasLatency  = 0x8,

+  .WriteLatency  = 0x3,

+  .t_mrd    = 0x2,

+  .t_ras    = 0xA,

+  .t_rc   = 0xE,

+  .t_rcd    = 0x104,

+  .t_rfc    = 0x2f32,

+  .t_rp   = 0x14,

+  .t_rrd    = 0x2,

+  .t_wr   = 0x4,

+  .t_wtr    = 0x2,

+  .t_xp   = 0x2,

+  .t_xsr    = 0xC8,

+  .t_esr    = 0x14,

+  .MemoryCfg   = DMC_MEMORY_CONFIG_ACTIVE_CHIP_1 | DMC_MEMORY_CONFIG_BURST_4 |

+                        DMC_MEMORY_CONFIG_ROW_ADDRESS_15 | DMC_MEMORY_CONFIG_COLUMN_ADDRESS_10,

+  .MemoryCfg2  = DMC_MEMORY_CFG2_DQM_INIT | DMC_MEMORY_CFG2_CKE_INIT |

+            DMC_MEMORY_CFG2_BANK_BITS_3 | DMC_MEMORY_CFG2_MEM_WIDTH_32,

+  .MemoryCfg3  = 0x00000001,

+  .ChipCfg0    = 0x00010000,

+  .t_faw    = 0x00000A0D,

+  .ModeReg = DDR2_MR_BURST_LENGTH_4 | DDR2_MR_CAS_LATENCY_4 | DDR2_MR_WR_CYCLES_4,

+  .ExtModeReg = DDR_EMR_RTT_50R | (DDR_EMR_ODS_VAL << DDR_EMR_ODS_MASK),

+};

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+  @return   Return the current Boot Mode of the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  if (MmioRead32(ARM_VE_SYS_FLAGS_NV_REG) == 0) {

+    return BOOT_WITH_FULL_CONFIGURATION;

+  } else {

+    return BOOT_ON_S2_RESUME;

+  }

+}

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // Configure periodic timer (TIMER0) for 1MHz operation

+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);

+  // Configure 1MHz clock

+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);

+  // configure SP810 to use 1MHz clock and disable

+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);

+  // Configure SP810 to use 1MHz clock and disable

+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+  PL341DmcInit (ARM_VE_DMC_BASE, &DDRTimings);

+  PL301AxiInit (ARM_VE_FAXI_BASE);

+}

+

+EFI_STATUS

+PrePeiCoreGetMpCoreInfo (

+  OUT UINTN                   *CoreCount,

+  OUT ARM_CORE_INFO           **ArmCoreTable

+  )

+{

+  *CoreCount    = sizeof(mVersatileExpressMpCoreInfoCTA9x4) / sizeof(ARM_CORE_INFO);

+  *ArmCoreTable = mVersatileExpressMpCoreInfoCTA9x4;

+

+  return EFI_SUCCESS;

+}

+

+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore

+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;

+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };

+

+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &mArmMpCoreInfoPpiGuid,

+    &mMpCoreInfoPpi

+  }

+};

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  *PpiListSize = sizeof(gPlatformPpiTable);

+  *PpiList = gPlatformPpiTable;

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Helper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Helper.S
new file mode 100644
index 0000000..c4aee74
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Helper.S
@@ -0,0 +1,63 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+#

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr   r0, [r0]

+  bx    lr

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   r0, r0, #ARM_CORE_MASK

+  bx    lr

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  bx    lr

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Helper.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Helper.asm
new file mode 100644
index 0000000..aa48ed7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Helper.asm
@@ -0,0 +1,70 @@
+//

+//  Copyright (c) 2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformPeiBootAction

+  EXPORT  ArmPlatformIsPrimaryCore

+  EXPORT  ArmPlatformGetPrimaryCoreMpId

+  EXPORT  ArmPlatformGetCorePosition

+

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCore

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCoreMask

+

+  AREA CTA9x4Helper, CODE, READONLY

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ArmPlatformGetPrimaryCoreMpId FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr     r0, [r0]

+  bx      lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ArmPlatformIsPrimaryCore FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ArmPlatformGetCorePosition FUNCTION

+  and   r0, r0, #ARM_CORE_MASK

+  bx    lr

+  ENDFUNC

+

+ArmPlatformPeiBootAction FUNCTION

+  bx    lr

+  ENDFUNC

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Mem.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Mem.c
new file mode 100644
index 0000000..7ea6e74
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Mem.c
@@ -0,0 +1,119 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <ArmPlatform.h>

+

+// Number of Virtual Memory Map Descriptors without a Logic Tile

+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          6

+

+// DDR attributes

+#define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK

+#define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;

+  UINTN                         Index = 0;

+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;

+

+  ASSERT(VirtualMemoryMap != NULL);

+

+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));

+  if (VirtualMemoryTable == NULL) {

+      return;

+  }

+

+  if (FeaturePcdGet(PcdCacheEnable) == TRUE) {

+      CacheAttributes = DDR_ATTRIBUTES_CACHED;

+  } else {

+      CacheAttributes = DDR_ATTRIBUTES_UNCACHED;

+  }

+

+  if (FeaturePcdGet(PcdNorFlashRemapping) == FALSE) {

+    // ReMap (Either NOR Flash or DRAM)

+    VirtualMemoryTable[Index].PhysicalBase = ARM_VE_REMAP_BASE;

+    VirtualMemoryTable[Index].VirtualBase  = ARM_VE_REMAP_BASE;

+    VirtualMemoryTable[Index].Length       = ARM_VE_REMAP_SZ;

+    VirtualMemoryTable[Index].Attributes   = CacheAttributes;

+  }

+

+  // DDR

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_DRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_DRAM_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_DRAM_SZ;

+  VirtualMemoryTable[Index].Attributes   = CacheAttributes;

+

+  // SMC CS7

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_SMB_MB_ON_CHIP_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS0-CS1 - NOR Flash 1 & 2

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_SMB_NOR0_SZ + ARM_VE_SMB_NOR1_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS2 - SRAM

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_SMB_SRAM_SZ;

+  VirtualMemoryTable[Index].Attributes   = CacheAttributes;

+

+  // SMB CS3-CS6 - Motherboard Peripherals

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_SMB_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // If a Logic Tile is connected to The ARM Versatile Express Motherboard

+  if (MmioRead32(ARM_VE_SYS_PROCID1_REG) != 0) {

+      VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_EXT_AXI_BASE;

+      VirtualMemoryTable[Index].VirtualBase  = ARM_VE_EXT_AXI_BASE;

+      VirtualMemoryTable[Index].Length       = ARM_VE_EXT_AXI_SZ;

+      VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+      ASSERT((Index + 1) == (MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS + 1));

+  } else {

+    ASSERT((Index + 1) == MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);

+  }

+

+  // End of Table

+  VirtualMemoryTable[++Index].PhysicalBase = 0;

+  VirtualMemoryTable[Index].VirtualBase  = 0;

+  VirtualMemoryTable[Index].Length       = 0;

+  VirtualMemoryTable[Index].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)0;

+

+  *VirtualMemoryMap = VirtualMemoryTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/AArch64/RTSMHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/AArch64/RTSMHelper.S
new file mode 100644
index 0000000..50ff713
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/AArch64/RTSMHelper.S
@@ -0,0 +1,81 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+#

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <Library/ArmLib.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmGetCpuCountPerCluster)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  ret

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x0)

+  ldrh   w0, [x0]

+  ret

+

+# IN None

+# OUT x0 = number of cores present in the system

+ASM_PFX(ArmGetCpuCountPerCluster):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdCoreCount, x0)

+  ldrh  w0, [x0]

+  ret

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, x1)

+  ldrh  w1, [x1]

+  and   x0, x0, x1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x1)

+  ldrh  w1, [x1]

+  cmp   w0, w1

+  b.ne  1f

+  mov   x0, #1

+  ret

+1:

+  mov   x0, #0

+  ret

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+// With this function: CorePos = (ClusterId * 4) + CoreId

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   x1, x0, #ARM_CORE_MASK

+  and   x0, x0, #ARM_CLUSTER_MASK

+  add   x0, x1, x0, LSR #6

+  ret

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/Arm/RTSMHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/Arm/RTSMHelper.S
new file mode 100644
index 0000000..e739050
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/Arm/RTSMHelper.S
@@ -0,0 +1,116 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+#

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmLib.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+#include "AsmMacroIoLib.inc"

+

+#include <Chipset/ArmCortexA9.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmGetCpuCountPerCluster)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  bx    lr

+

+# IN None

+# OUT r0 = SCU Base Address

+ASM_PFX(ArmGetScuBaseAddress):

+  # Read Configuration Base Address Register. ArmCBar cannot be called to get

+  # the Configuration BAR as a stack is not necessary setup. The SCU is at the

+  # offset 0x0000 from the Private Memory Region.

+  mrc   p15, 4, r0, c15, c0, 0

+  bx    lr

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr   r0, [r0]

+  bx    lr

+

+# IN None

+# OUT r0 = number of cores present in the system

+ASM_PFX(ArmGetCpuCountPerCluster):

+  stmfd SP!, {r1-r2}

+

+  # Read CP15 MIDR

+  mrc   p15, 0, r1, c0, c0, 0

+

+  # Check if the CPU is A15

+  mov   r1, r1, LSR #4

+  LoadConstantToReg (ARM_CPU_TYPE_MASK, r0)

+  and   r1, r1, r0

+

+  LoadConstantToReg (ARM_CPU_TYPE_A15, r0)

+  cmp   r1, r0

+  beq   _Read_cp15_reg

+

+_CPU_is_not_A15:

+  mov   r2, lr                           @ Save link register

+  bl    ArmGetScuBaseAddress             @ Read SCU Base Address

+  mov   lr, r2                           @ Restore link register val

+  ldr   r0, [r0, #A9_SCU_CONFIG_OFFSET]     @ Read SCU Config reg to get CPU count

+  b     _Return

+

+_Read_cp15_reg:

+  mrc   p15, 1, r0, c9, c0, 2            @ Read C9 register of CP15 to get CPU count

+  lsr   r0, #24

+

+_Return:

+  and   r0, r0, #3

+  # Add '1' to the number of CPU on the Cluster

+  add   r0, r0, #1

+  ldmfd SP!, {r1-r2}

+  bx lr

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/Arm/RTSMHelper.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/Arm/RTSMHelper.asm
new file mode 100644
index 0000000..f4ad51d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/Arm/RTSMHelper.asm
@@ -0,0 +1,124 @@
+//

+//  Copyright (c) 2011-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmLib.h>

+#include <Library/PcdLib.h>

+

+#include <Chipset/ArmCortexA9.h>

+

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT    ArmPlatformPeiBootAction

+  EXPORT    ArmGetCpuCountPerCluster

+  EXPORT    ArmPlatformIsPrimaryCore

+  EXPORT    ArmPlatformGetPrimaryCoreMpId

+  EXPORT    ArmPlatformGetCorePosition

+

+  IMPORT    _gPcd_FixedAtBuild_PcdArmPrimaryCore

+  IMPORT    _gPcd_FixedAtBuild_PcdArmPrimaryCoreMask

+

+  AREA RTSMHelper, CODE, READONLY

+

+ArmPlatformPeiBootAction FUNCTION

+  bx    lr

+  ENDFUNC

+

+// IN None

+// OUT r0 = SCU Base Address

+ArmGetScuBaseAddress FUNCTION

+  // Read Configuration Base Address Register. ArmCBar cannot be called to get

+  // the Configuration BAR as a stack is not necessary setup. The SCU is at the

+  // offset 0x0000 from the Private Memory Region.

+  mrc   p15, 4, r0, c15, c0, 0

+  bx  lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ArmPlatformGetPrimaryCoreMpId FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr   r0, [r0]

+  bx    lr

+  ENDFUNC

+

+// IN None

+// OUT r0 = number of cores present in the system

+ArmGetCpuCountPerCluster FUNCTION

+  stmfd SP!, {r1-r2}

+

+  // Read CP15 MIDR

+  mrc   p15, 0, r1, c0, c0, 0

+

+  // Check if the CPU is A15

+  mov   r1, r1, LSR #4

+  mov   r0, #ARM_CPU_TYPE_MASK

+  and   r1, r1, r0

+

+  mov   r0, #ARM_CPU_TYPE_A15

+  cmp   r1, r0

+  beq   _Read_cp15_reg

+

+_CPU_is_not_A15

+  mov   r2, lr                              ; Save link register

+  bl    ArmGetScuBaseAddress                ; Read SCU Base Address

+  mov   lr, r2                              ; Restore link register val

+  ldr   r0, [r0, #A9_SCU_CONFIG_OFFSET]     ; Read SCU Config reg to get CPU count

+  b     _Return

+

+_Read_cp15_reg

+  mrc   p15, 1, r0, c9, c0, 2            ; Read C9 register of CP15 to get CPU count

+  lsr   r0, #24

+

+

+_Return

+  and   r0, r0, #3

+  // Add '1' to the number of CPU on the Cluster

+  add   r0, r0, #1

+  ldmfd SP!, {r1-r2}

+  bx lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ArmPlatformIsPrimaryCore FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ArmPlatformGetCorePosition FUNCTION

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+  ENDFUNC

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLib.inf
new file mode 100644
index 0000000..0fe8a32
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLib.inf
@@ -0,0 +1,54 @@
+#/* @file

+#  Copyright (c) 2011-2014, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = RTSMArmVExpressFoundationLib

+  FILE_GUID                      = ce5d91ae-0893-11e2-b6bb-1c6f650265cc

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  MemoryAllocationLib

+  SerialPortLib

+  PrintLib

+  HobLib

+

+[Sources.common]

+  RTSMFoundation.c

+  RTSMFoundationMem.c

+

+[Sources.AARCH64]

+  AArch64/RTSMHelper.S

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLibSec.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLibSec.inf
new file mode 100644
index 0000000..70245b0
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressFoundationLibSec.inf
@@ -0,0 +1,50 @@
+#/* @file

+#  Copyright (c) 2011-2013, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = RTSMArmVExpressFoundationLibSec

+  FILE_GUID                      = bc6e6418-0894-11e2-9dc3-1c6f650265cc

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  SerialPortLib

+

+[Sources.common]

+  RTSMFoundation.c

+

+[Sources.AARCH64]

+  AArch64/RTSMHelper.S

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf
new file mode 100644
index 0000000..5ee51a3
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLib.inf
@@ -0,0 +1,59 @@
+#/* @file

+#  Copyright (c) 2011-2014, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = RTSMArmVExpressLib

+  FILE_GUID                      = b98a6cb7-d472-4128-ad62-a7347f85ce13

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  MemoryAllocationLib

+  SerialPortLib

+  HobLib

+

+[Sources.common]

+  RTSM.c

+  RTSMMem.c

+

+[Sources.ARM]

+  Arm/RTSMHelper.asm    | RVCT

+  Arm/RTSMHelper.S      | GCC

+

+[Sources.AARCH64]

+  AArch64/RTSMHelper.S

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf
new file mode 100644
index 0000000..a535ffd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/ArmVExpressLibSec.inf
@@ -0,0 +1,56 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = RTSMArmVExpressLibSec

+  FILE_GUID                      = a79eed97-4b98-4974-9690-37b32d6a5b56

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  SerialPortLib

+

+[Sources.common]

+  RTSM.c

+

+[Sources.ARM]

+  Arm/RTSMHelper.asm    | RVCT

+  Arm/RTSMHelper.S      | GCC

+

+[Sources.AARCH64]

+  AArch64/RTSMHelper.S

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSM.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSM.c
new file mode 100644
index 0000000..ea73f62
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSM.c
@@ -0,0 +1,203 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+#include <ArmPlatform.h>

+

+UINTN

+ArmGetCpuCountPerCluster (

+  VOID

+  );

+

+ARM_CORE_INFO mVersatileExpressMpCoreInfoTable[] = {

+  {

+    // Cluster 0, Core 0

+    0x0, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 1

+    0x0, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 2

+    0x0, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 3

+    0x0, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 0

+    0x1, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 1

+    0x1, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 2

+    0x1, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 1, Core 3

+    0x1, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_SET_REG,

+    (EFI_PHYSICAL_ADDRESS)ARM_VE_SYS_FLAGS_CLR_REG,

+    (UINT64)0xFFFFFFFF

+  }

+};

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+  @return   Return the current Boot Mode of the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  return BOOT_WITH_FULL_CONFIGURATION;

+}

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // Disable memory remapping and return to normal mapping

+  MmioOr32 (SP810_CTRL_BASE, BIT8);

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+  // Nothing to do here

+}

+

+EFI_STATUS

+PrePeiCoreGetMpCoreInfo (

+  OUT UINTN                   *CoreCount,

+  OUT ARM_CORE_INFO           **ArmCoreTable

+  )

+{

+  UINT32   ProcType;

+

+  ProcType = MmioRead32 (ARM_VE_SYS_PROCID0_REG) & ARM_VE_SYS_PROC_ID_MASK;

+  if ((ProcType == ARM_VE_SYS_PROC_ID_CORTEX_A9) || (ProcType == ARM_VE_SYS_PROC_ID_CORTEX_A15)) {

+    // Only support one cluster on all but ARMv8 FVP platform. FVP still uses CortexA9 ID.

+    *CoreCount    = ArmGetCpuCountPerCluster ();

+    *ArmCoreTable = mVersatileExpressMpCoreInfoTable;

+    return EFI_SUCCESS;

+  } else {

+    return EFI_UNSUPPORTED;

+  }

+}

+

+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore

+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;

+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };

+

+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &mArmMpCoreInfoPpiGuid,

+    &mMpCoreInfoPpi

+  }

+};

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  *PpiListSize = sizeof(gPlatformPpiTable);

+  *PpiList = gPlatformPpiTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMFoundation.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMFoundation.c
new file mode 100644
index 0000000..1b1671a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMFoundation.c
@@ -0,0 +1,165 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+#include <ArmPlatform.h>

+

+

+UINTN

+ArmGetCpuCountPerCluster (

+  VOID

+  );

+

+ARM_CORE_INFO mVersatileExpressMpCoreInfoTable[] = {

+  {

+    // Cluster 0, Core 0

+    0x0, 0x0,

+

+    // NOTE:

+    // The foundation model does not have the VE_SYS_REGS like all the other VE

+    // platforms. We pick a spot in RAM that *should* be safe in the simple case

+    // of no UEFI apps interfering (Only the Linux loader getting used). By the

+    // time we come to load Linux we should have all the cores in a safe place.

+    // The image expects to be loaded at 0xa0000000. We also place the mailboxes

+    // here as it does not matter if we corrupt the image at this time.

+    // NOTE also see: "ArmVExpressSecLibRTSM/AArch64/RTSMFoundationBoot.S"

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (UINT64)0x0

+

+  },

+  {

+    // Cluster 0, Core 1

+    0x0, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (UINT64)0x0

+

+  },

+  {

+    // Cluster 0, Core 2

+    0x0, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (UINT64)0x0

+  },

+  {

+    // Cluster 0, Core 3

+    0x0, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (EFI_PHYSICAL_ADDRESS)0xa0000000,

+    (UINT64)0x0

+  }

+};

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+  @return   Return the current Boot Mode of the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  return BOOT_WITH_FULL_CONFIGURATION;

+}

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/Pei or ArmPlatformPkg/Pei/PlatformPeim

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  /* The Foundation model has no SP810 to initialise. */

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+  // Nothing to do here

+}

+

+EFI_STATUS

+PrePeiCoreGetMpCoreInfo (

+  OUT UINTN                   *CoreCount,

+  OUT ARM_CORE_INFO           **ArmCoreTable

+  )

+{

+  // Foundation model has no VE_SYS_REGS

+  // Only support one cluster

+  *CoreCount    = ArmGetCpuCountPerCluster ();

+  *ArmCoreTable = mVersatileExpressMpCoreInfoTable;

+

+  return EFI_SUCCESS;

+}

+

+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the context of PrePeiCore

+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;

+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };

+

+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &mArmMpCoreInfoPpiGuid,

+    &mMpCoreInfoPpi

+  }

+};

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  *PpiListSize = sizeof(gPlatformPpiTable);

+  *PpiList = gPlatformPpiTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMFoundationMem.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMFoundationMem.c
new file mode 100644
index 0000000..863767c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMFoundationMem.c
@@ -0,0 +1,115 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <ArmPlatform.h>

+

+// Number of Virtual Memory Map Descriptors

+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          5

+

+// DDR attributes

+#define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK

+#define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;

+  EFI_RESOURCE_ATTRIBUTE_TYPE   ResourceAttributes;

+  UINTN                         Index = 0;

+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;

+  EFI_VIRTUAL_ADDRESS           SparseMemoryBase;

+  UINT64                        SparseMemorySize;

+

+  ASSERT(VirtualMemoryMap != NULL);

+

+  ResourceAttributes =

+      EFI_RESOURCE_ATTRIBUTE_PRESENT |

+      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |

+      EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_TESTED;

+

+  // Declared the additional DRAM from 2GB to 8GB

+  SparseMemoryBase = 0x0880000000;

+  SparseMemorySize = SIZE_2GB + SIZE_4GB;

+

+  BuildResourceDescriptorHob (

+      EFI_RESOURCE_SYSTEM_MEMORY,

+      ResourceAttributes,

+      SparseMemoryBase,

+      SparseMemorySize);

+

+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));

+  if (VirtualMemoryTable == NULL) {

+      return;

+  }

+

+  if (FeaturePcdGet(PcdCacheEnable) == TRUE) {

+      CacheAttributes = DDR_ATTRIBUTES_CACHED;

+  } else {

+      CacheAttributes = DDR_ATTRIBUTES_UNCACHED;

+  }

+

+  // DDR

+  VirtualMemoryTable[Index].PhysicalBase = ARM_VE_DRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_DRAM_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_DRAM_SZ;

+  VirtualMemoryTable[Index].Attributes   = CacheAttributes;

+

+  // CPU peripherals. TRM. Manual says not all of them are implemented.

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_ON_CHIP_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // Peripheral CS2 and CS3

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = 2 * ARM_VE_SMB_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // Map sparse memory region if present

+  VirtualMemoryTable[++Index].PhysicalBase = SparseMemoryBase;

+  VirtualMemoryTable[Index].VirtualBase    = SparseMemoryBase;

+  VirtualMemoryTable[Index].Length         = SparseMemorySize;

+  VirtualMemoryTable[Index].Attributes     = CacheAttributes;

+

+  // End of Table

+  VirtualMemoryTable[++Index].PhysicalBase = 0;

+  VirtualMemoryTable[Index].VirtualBase  = 0;

+  VirtualMemoryTable[Index].Length       = 0;

+  VirtualMemoryTable[Index].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)0;

+

+  *VirtualMemoryMap = VirtualMemoryTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMMem.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMMem.c
new file mode 100644
index 0000000..6c5e494
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibRTSM/RTSMMem.c
@@ -0,0 +1,158 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <ArmPlatform.h>

+

+// Number of Virtual Memory Map Descriptors

+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          6

+

+// DDR attributes

+#define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK

+#define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;

+  EFI_RESOURCE_ATTRIBUTE_TYPE   ResourceAttributes;

+  UINTN                         Index = 0;

+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;

+  UINT32                        SysId;

+  BOOLEAN                       HasSparseMemory;

+  EFI_VIRTUAL_ADDRESS           SparseMemoryBase;

+  UINT64                        SparseMemorySize;

+

+  ASSERT (VirtualMemoryMap != NULL);

+

+  // The FVP model has Sparse memory

+  SysId = MmioRead32 (ARM_VE_SYS_ID_REG);

+  if (SysId != ARM_RTSM_SYS_ID) {

+    HasSparseMemory = TRUE;

+

+    ResourceAttributes =

+        EFI_RESOURCE_ATTRIBUTE_PRESENT |

+        EFI_RESOURCE_ATTRIBUTE_INITIALIZED |

+        EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |

+        EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |

+        EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |

+        EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |

+        EFI_RESOURCE_ATTRIBUTE_TESTED;

+

+    // Declared the additional DRAM from 2GB to 4GB

+    SparseMemoryBase = 0x0880000000;

+    SparseMemorySize = SIZE_2GB;

+

+    BuildResourceDescriptorHob (

+        EFI_RESOURCE_SYSTEM_MEMORY,

+        ResourceAttributes,

+        SparseMemoryBase,

+        SparseMemorySize);

+  } else {

+    HasSparseMemory = FALSE;

+    SparseMemoryBase = 0x0;

+    SparseMemorySize = 0x0;

+  }

+

+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));

+  if (VirtualMemoryTable == NULL) {

+      return;

+  }

+

+  if (FeaturePcdGet(PcdCacheEnable) == TRUE) {

+      CacheAttributes = DDR_ATTRIBUTES_CACHED;

+  } else {

+      CacheAttributes = DDR_ATTRIBUTES_UNCACHED;

+  }

+

+  // ReMap (Either NOR Flash or DRAM)

+  VirtualMemoryTable[Index].PhysicalBase = ARM_VE_REMAP_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_REMAP_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_REMAP_SZ;

+

+  if (FeaturePcdGet(PcdNorFlashRemapping) == FALSE) {

+    // Map the NOR Flash as Secure Memory

+    if (FeaturePcdGet(PcdCacheEnable) == TRUE) {

+      VirtualMemoryTable[Index].Attributes   = DDR_ATTRIBUTES_CACHED;

+    } else {

+      VirtualMemoryTable[Index].Attributes   = DDR_ATTRIBUTES_UNCACHED;

+    }

+  } else {

+    // DRAM mapping

+    VirtualMemoryTable[Index].Attributes   = CacheAttributes;

+  }

+

+  // DDR

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_DRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_DRAM_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_DRAM_SZ;

+  VirtualMemoryTable[Index].Attributes   = CacheAttributes;

+

+  // CPU peripherals. TRM. Manual says not all of them are implemented.

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_ON_CHIP_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_ON_CHIP_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS0-CS1 - NOR Flash 1 & 2

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_NOR0_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_SMB_NOR0_SZ + ARM_VE_SMB_NOR1_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // SMB CS2 - SRAM

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_SRAM_BASE;

+  VirtualMemoryTable[Index].Length       = ARM_VE_SMB_SRAM_SZ;

+  VirtualMemoryTable[Index].Attributes   = CacheAttributes;

+

+  // Peripheral CS2 and CS3

+  VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].VirtualBase  = ARM_VE_SMB_PERIPH_BASE;

+  VirtualMemoryTable[Index].Length       = 2 * ARM_VE_SMB_PERIPH_SZ;

+  VirtualMemoryTable[Index].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // Map sparse memory region if present

+  if (HasSparseMemory) {

+    VirtualMemoryTable[++Index].PhysicalBase = SparseMemoryBase;

+    VirtualMemoryTable[Index].VirtualBase    = SparseMemoryBase;

+    VirtualMemoryTable[Index].Length         = SparseMemorySize;

+    VirtualMemoryTable[Index].Attributes     = CacheAttributes;

+  }

+

+  // End of Table

+  VirtualMemoryTable[++Index].PhysicalBase = 0;

+  VirtualMemoryTable[Index].VirtualBase  = 0;

+  VirtualMemoryTable[Index].Length       = 0;

+  VirtualMemoryTable[Index].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)0;

+

+  *VirtualMemoryMap = VirtualMemoryTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/ArmVExpressSecLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/ArmVExpressSecLib.inf
new file mode 100644
index 0000000..5705b8b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/ArmVExpressSecLib.inf
@@ -0,0 +1,55 @@
+#/* @file

+#  Copyright (c) 2011-2014, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = CTA9x4ArmVExpressLib

+  FILE_GUID                      = aac05341-56df-4a77-b20f-f5daa456bd90

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSecLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  ArmTrustZoneLib

+  ArmPlatformLib

+  ArmPlatformSysConfigLib

+  ArmPlatformSecExtraActionLib

+  IoLib

+  L2X0CacheLib

+  PL301AxiLib

+  PL341DmcLib

+  PL35xSmcLib

+  SerialPortLib

+

+[Sources.common]

+  CTA9x4Sec.c

+  CTA9x4Boot.asm     | RVCT

+  CTA9x4Boot.S       | GCC

+

+[FeaturePcd]

+  gArmPlatformTokenSpaceGuid.PcdStandalone

+  gArmPlatformTokenSpaceGuid.PcdNorFlashRemapping

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdTrustzoneSupport

+

+  gArmTokenSpaceGuid.PcdL2x0ControllerBase

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Boot.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Boot.S
new file mode 100644
index 0000000..c14c986
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Boot.S
@@ -0,0 +1,123 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmPlatformLib.h>

+#include <Drivers/PL35xSmc.h>

+#include <ArmPlatform.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformSecBootAction)

+GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit)

+GCC_ASM_IMPORT(PL35xSmcInitialize)

+

+//

+// For each Chip Select: ChipSelect / SetCycle / SetOpMode

+//

+VersatileExpressSmcConfiguration:

+    // NOR Flash 0

+    .word     PL350_SMC_DIRECT_CMD_ADDR_CS(0)

+    .word     PL350_SMC_SET_CYCLE_NAND_T_RC(0xA) | PL350_SMC_SET_CYCLE_NAND_T_WC(0x3) | PL350_SMC_SET_CYCLE_NAND_T_REA(0x1) | PL350_SMC_SET_CYCLE_NAND_T_WP(0x7) | PL350_SMC_SET_CYCLE_NAND_T_AR(0x1)

+    .word     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 | PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_CONT | PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_CONT | PL350_SMC_SET_OPMODE_SET_ADV

+

+    // NOR Flash 1

+    .word     PL350_SMC_DIRECT_CMD_ADDR_CS(4)

+    .word     PL350_SMC_SET_CYCLE_NAND_T_RC(0xA) | PL350_SMC_SET_CYCLE_NAND_T_WC(0x3) | PL350_SMC_SET_CYCLE_NAND_T_REA(0x1) | PL350_SMC_SET_CYCLE_NAND_T_WP(0x7) | PL350_SMC_SET_CYCLE_NAND_T_AR(0x1)

+    .word     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 | PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_CONT | PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_CONT | PL350_SMC_SET_OPMODE_SET_ADV

+

+    // SRAM

+    .word     PL350_SMC_DIRECT_CMD_ADDR_CS(2)

+    .word     PL350_SMC_SET_CYCLE_SRAM_T_RC(0x8) | PL350_SMC_SET_CYCLE_SRAM_T_WC(0x5) | PL350_SMC_SET_CYCLE_SRAM_T_CEOE(0x1) | PL350_SMC_SET_CYCLE_SRAM_T_WP(0x6) | PL350_SMC_SET_CYCLE_SRAM_T_PC(0x1) | PL350_SMC_SET_CYCLE_SRAM_T_TR(0x1)

+    .word     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 | PL350_SMC_SET_OPMODE_SET_ADV

+

+    // Usb/Eth/VRAM

+    .word     PL350_SMC_DIRECT_CMD_ADDR_CS(3)

+    .word     PL350_SMC_SET_CYCLE_SRAM_T_RC(0xA) | PL350_SMC_SET_CYCLE_SRAM_T_WC(0xA) | PL350_SMC_SET_CYCLE_SRAM_T_CEOE(0x2) | PL350_SMC_SET_CYCLE_SRAM_T_WP(0x2) | PL350_SMC_SET_CYCLE_SRAM_T_PC(0x3) | PL350_SMC_SET_CYCLE_SRAM_T_TR(0x6)

+    .word     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 | PL350_SMC_SET_OPMODE_SET_RD_SYNC | PL350_SMC_SET_OPMODE_SET_WR_SYNC

+

+    // Memory Mapped Peripherals

+    .word     PL350_SMC_DIRECT_CMD_ADDR_CS(7)

+    .word     PL350_SMC_SET_CYCLE_SRAM_T_RC(0x6) | PL350_SMC_SET_CYCLE_SRAM_T_WC(0x5) | PL350_SMC_SET_CYCLE_SRAM_T_CEOE(0x1) | PL350_SMC_SET_CYCLE_SRAM_T_WP(0x2) | PL350_SMC_SET_CYCLE_SRAM_T_PC(0x1) | PL350_SMC_SET_CYCLE_SRAM_T_TR(0x1)

+    .word     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 | PL350_SMC_SET_OPMODE_SET_RD_SYNC | PL350_SMC_SET_OPMODE_SET_WR_SYNC

+

+    // VRAM

+    .word     PL350_SMC_DIRECT_CMD_ADDR_CS(1)

+    .word     0x00049249

+    .word     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 | PL350_SMC_SET_OPMODE_SET_RD_SYNC | PL350_SMC_SET_OPMODE_SET_WR_SYNC

+VersatileExpressSmcConfigurationEnd:

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ASM_PFX(ArmPlatformSecBootAction):

+  bx    lr

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ASM_PFX(ArmPlatformSecBootMemoryInit):

+  mov   r5, lr

+

+  //

+  // Initialize PL354 SMC

+  //

+  LoadConstantToReg (ARM_VE_SMC_CTRL_BASE, r1)

+  LoadConstantToReg (VersatileExpressSmcConfiguration, r2)

+  LoadConstantToReg (VersatileExpressSmcConfigurationEnd, r3)

+  blx   ASM_PFX(PL35xSmcInitialize)

+

+  //

+  // Page mode setup for VRAM

+  //

+  LoadConstantToReg (VRAM_MOTHERBOARD_BASE, r2)

+

+  // Read current state

+  ldr     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+  ldr     r0, = 0x00000000

+  str     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+

+  // Enable page mode

+  ldr     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+  ldr     r0, = 0x00000000

+  str     r0, [r2, #0]

+  LoadConstantToReg (0x00900090, r0)

+  str     r0, [r2, #0]

+

+  // Confirm page mode enabled

+  ldr     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+  ldr     r0, = 0x00000000

+  str     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+

+  bx    r5

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Boot.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Boot.asm
new file mode 100644
index 0000000..16fab16
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Boot.asm
@@ -0,0 +1,127 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmPlatformLib.h>

+#include <Drivers/PL35xSmc.h>

+#include <ArmPlatform.h>

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformSecBootAction

+  EXPORT  ArmPlatformSecBootMemoryInit

+  IMPORT  PL35xSmcInitialize

+

+  PRESERVE8

+  AREA    CTA9x4BootMode, CODE, READONLY

+

+//

+// For each Chip Select: ChipSelect / SetCycle / SetOpMode

+//

+VersatileExpressSmcConfiguration

+    // NOR Flash 0

+    DCD     PL350_SMC_DIRECT_CMD_ADDR_CS(0)

+    DCD     PL350_SMC_SET_CYCLE_NAND_T_RC(0xA) :OR: PL350_SMC_SET_CYCLE_NAND_T_WC(0x3) :OR: PL350_SMC_SET_CYCLE_NAND_T_REA(0x1) :OR: PL350_SMC_SET_CYCLE_NAND_T_WP(0x7) :OR: PL350_SMC_SET_CYCLE_NAND_T_AR(0x1)

+    DCD     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 :OR: PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_CONT :OR: PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_CONT :OR: PL350_SMC_SET_OPMODE_SET_ADV

+

+    // NOR Flash 1

+    DCD     PL350_SMC_DIRECT_CMD_ADDR_CS(4)

+    DCD     PL350_SMC_SET_CYCLE_NAND_T_RC(0xA) :OR: PL350_SMC_SET_CYCLE_NAND_T_WC(0x3) :OR: PL350_SMC_SET_CYCLE_NAND_T_REA(0x1) :OR: PL350_SMC_SET_CYCLE_NAND_T_WP(0x7) :OR: PL350_SMC_SET_CYCLE_NAND_T_AR(0x1)

+    DCD     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 :OR: PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_CONT :OR: PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_CONT :OR: PL350_SMC_SET_OPMODE_SET_ADV

+

+    // SRAM

+    DCD     PL350_SMC_DIRECT_CMD_ADDR_CS(2)

+    DCD     PL350_SMC_SET_CYCLE_SRAM_T_RC(0x8) :OR: PL350_SMC_SET_CYCLE_SRAM_T_WC(0x5) :OR: PL350_SMC_SET_CYCLE_SRAM_T_CEOE(0x1) :OR: PL350_SMC_SET_CYCLE_SRAM_T_WP(0x6) :OR: PL350_SMC_SET_CYCLE_SRAM_T_PC(0x1) :OR: PL350_SMC_SET_CYCLE_SRAM_T_TR(0x1)

+    DCD     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 :OR: PL350_SMC_SET_OPMODE_SET_ADV

+

+    // Usb/Eth/VRAM

+    DCD     PL350_SMC_DIRECT_CMD_ADDR_CS(3)

+    DCD     PL350_SMC_SET_CYCLE_SRAM_T_RC(0xA) :OR: PL350_SMC_SET_CYCLE_SRAM_T_WC(0xA) :OR: PL350_SMC_SET_CYCLE_SRAM_T_CEOE(0x2) :OR: PL350_SMC_SET_CYCLE_SRAM_T_WP(0x2) :OR: PL350_SMC_SET_CYCLE_SRAM_T_PC(0x3) :OR: PL350_SMC_SET_CYCLE_SRAM_T_TR(0x6)

+    DCD     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 :OR: PL350_SMC_SET_OPMODE_SET_RD_SYNC :OR: PL350_SMC_SET_OPMODE_SET_WR_SYNC

+

+    // Memory Mapped Peripherals

+    DCD     PL350_SMC_DIRECT_CMD_ADDR_CS(7)

+    DCD     PL350_SMC_SET_CYCLE_SRAM_T_RC(0x6) :OR: PL350_SMC_SET_CYCLE_SRAM_T_WC(0x5) :OR: PL350_SMC_SET_CYCLE_SRAM_T_CEOE(0x1) :OR: PL350_SMC_SET_CYCLE_SRAM_T_WP(0x2) :OR: PL350_SMC_SET_CYCLE_SRAM_T_PC(0x1) :OR: PL350_SMC_SET_CYCLE_SRAM_T_TR(0x1)

+    DCD     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 :OR: PL350_SMC_SET_OPMODE_SET_RD_SYNC :OR: PL350_SMC_SET_OPMODE_SET_WR_SYNC

+

+    // VRAM

+    DCD     PL350_SMC_DIRECT_CMD_ADDR_CS(1)

+    DCD     0x00049249

+    DCD     PL350_SMC_SET_OPMODE_MEM_WIDTH_32 :OR: PL350_SMC_SET_OPMODE_SET_RD_SYNC :OR: PL350_SMC_SET_OPMODE_SET_WR_SYNC

+VersatileExpressSmcConfigurationEnd

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ArmPlatformSecBootAction

+  bx  lr

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ArmPlatformSecBootMemoryInit

+  mov   r5, lr

+

+  //

+  // Initialize PL354 SMC

+  //

+  LoadConstantToReg (ARM_VE_SMC_CTRL_BASE, r1)

+  ldr   r2, =VersatileExpressSmcConfiguration

+  ldr   r3, =VersatileExpressSmcConfigurationEnd

+  blx   PL35xSmcInitialize

+

+  //

+  // Page mode setup for VRAM

+  //

+  LoadConstantToReg (VRAM_MOTHERBOARD_BASE, r2)

+

+  // Read current state

+  ldr     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+  ldr     r0, = 0x00000000

+  str     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+

+  // Enable page mode

+  ldr     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+  ldr     r0, = 0x00000000

+  str     r0, [r2, #0]

+  ldr     r0, = 0x00900090

+  str     r0, [r2, #0]

+

+  // Confirm page mode enabled

+  ldr     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+  ldr     r0, = 0x00000000

+  str     r0, [r2, #0]

+  ldr     r0, [r2, #0]

+

+  bx    r5

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Sec.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Sec.c
new file mode 100644
index 0000000..6fa0774
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibCTA9x4/CTA9x4Sec.c
@@ -0,0 +1,176 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/ArmPlatformSysConfigLib.h>

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+#include <Library/SerialPortLib.h>

+

+#include <Drivers/ArmTrustzone.h>

+#include <Drivers/PL310L2Cache.h>

+

+#include <ArmPlatform.h>

+

+#define SerialPrint(txt)  SerialPortWrite ((UINT8*)(txt), AsciiStrLen(txt)+1)

+

+/**

+  Initialize the Secure peripherals and memory regions

+

+  If Trustzone is supported by your platform then this function makes the required initialization

+  of the secure peripherals and memory regions.

+

+**/

+VOID

+ArmPlatformSecTrustzoneInit (

+  IN  UINTN                     MpId

+  )

+{

+  // Nothing to do

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return;

+  }

+

+  //

+  // Setup TZ Protection Controller

+  //

+

+  if (MmioRead32(ARM_VE_SYS_CFGRW1_REG) & ARM_VE_CFGRW1_TZASC_EN_BIT_MASK) {

+    ASSERT (PcdGetBool (PcdTrustzoneSupport) == TRUE);

+  } else {

+    ASSERT (PcdGetBool (PcdTrustzoneSupport) == FALSE);

+  }

+

+  // Set Non Secure access for all devices

+  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_0, 0xFFFFFFFF);

+  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_1, 0xFFFFFFFF);

+  TZPCSetDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_2, 0xFFFFFFFF);

+

+  // Remove Non secure access to secure devices

+  TZPCClearDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_0,

+       ARM_VE_DECPROT_BIT_TZPC | ARM_VE_DECPROT_BIT_DMC_TZASC | ARM_VE_DECPROT_BIT_NMC_TZASC | ARM_VE_DECPROT_BIT_SMC_TZASC);

+

+  TZPCClearDecProtBits(ARM_VE_TZPC_BASE, TZPC_DECPROT_2,

+       ARM_VE_DECPROT_BIT_EXT_MAST_TZ | ARM_VE_DECPROT_BIT_DMC_TZASC_LOCK | ARM_VE_DECPROT_BIT_NMC_TZASC_LOCK | ARM_VE_DECPROT_BIT_SMC_TZASC_LOCK);

+

+  //

+  // Setup TZ Address Space Controller for the SMC. Create 5 Non Secure regions (NOR0, NOR1, SRAM, SMC Peripheral regions)

+  //

+

+  // NOR Flash 0 non secure (BootMon)

+  TZASCSetRegion(ARM_VE_TZASC_BASE,1,TZASC_REGION_ENABLED,

+      ARM_VE_SMB_NOR0_BASE,0,

+      TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);

+

+  // NOR Flash 1. The first half of the NOR Flash1 must be secure for the secure firmware (sec_uefi.bin)

+  if (PcdGetBool (PcdTrustzoneSupport) == TRUE) {

+    //Note: Your OS Kernel must be aware of the secure regions before to enable this region

+    TZASCSetRegion(ARM_VE_TZASC_BASE,2,TZASC_REGION_ENABLED,

+        ARM_VE_SMB_NOR1_BASE + SIZE_32MB,0,

+        TZASC_REGION_SIZE_32MB, TZASC_REGION_SECURITY_NSRW);

+  } else {

+    TZASCSetRegion(ARM_VE_TZASC_BASE,2,TZASC_REGION_ENABLED,

+        ARM_VE_SMB_NOR1_BASE,0,

+        TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);

+  }

+

+  // Base of SRAM. Only half of SRAM in Non Secure world

+  // First half non secure (16MB) + Second Half secure (16MB) = 32MB of SRAM

+  if (PcdGetBool (PcdTrustzoneSupport) == TRUE) {

+    //Note: Your OS Kernel must be aware of the secure regions before to enable this region

+    TZASCSetRegion(ARM_VE_TZASC_BASE,3,TZASC_REGION_ENABLED,

+        ARM_VE_SMB_SRAM_BASE,0,

+        TZASC_REGION_SIZE_16MB, TZASC_REGION_SECURITY_NSRW);

+  } else {

+    TZASCSetRegion(ARM_VE_TZASC_BASE,3,TZASC_REGION_ENABLED,

+        ARM_VE_SMB_SRAM_BASE,0,

+        TZASC_REGION_SIZE_32MB, TZASC_REGION_SECURITY_NSRW);

+  }

+

+  // Memory Mapped Peripherals. All in non secure world

+  TZASCSetRegion(ARM_VE_TZASC_BASE,4,TZASC_REGION_ENABLED,

+      ARM_VE_SMB_PERIPH_BASE,0,

+      TZASC_REGION_SIZE_64MB, TZASC_REGION_SECURITY_NSRW);

+

+  // MotherBoard Peripherals and On-chip peripherals.

+  TZASCSetRegion(ARM_VE_TZASC_BASE,5,TZASC_REGION_ENABLED,

+      ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE,0,

+      TZASC_REGION_SIZE_256MB, TZASC_REGION_SECURITY_NSRW);

+}

+

+/**

+  Initialize controllers that must setup at the early stage

+

+  Some peripherals must be initialized in Secure World.

+  For example, some L2x0 requires to be initialized in Secure World

+

+**/

+RETURN_STATUS

+ArmPlatformSecInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  UINT32 Value;

+

+  // If the DRAM is remapped at 0x0 then we need to wake up the secondary cores from wfe

+  // (waiting for the memory to be initialized) as the instruction is still in the remapped

+  // flash region at 0x0 to jump in the C-code which lives in the NOR1 at 0x44000000 before

+  // the region 0x0 is remapped as DRAM.

+  if (!FeaturePcdGet (PcdNorFlashRemapping)) {

+    if (!ArmPlatformIsPrimaryCore (MpId)) {

+      // Replaced ArmCallWFE () in ArmPlatformPkg/Sec/SecEntryPoint.(S|asm)

+      ArmCallWFE ();

+    } else {

+      // Wake up the secondary core from ArmCallWFE () in ArmPlatformPkg/Sec/SecEntryPoint.(S|asm)

+      ArmCallSEV ();

+    }

+  }

+

+  // If it is not the primary core then there is nothing to do

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // The L2x0 controller must be intialize in Secure World

+  L2x0CacheInit(PcdGet32(PcdL2x0ControllerBase),

+      PL310_TAG_LATENCIES(L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES),

+      PL310_DATA_LATENCIES(L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES,L2x0_LATENCY_8_CYCLES),

+      0,~0, // Use default setting for the Auxiliary Control Register

+      FALSE);

+

+  // Initialize the System Configuration

+  ArmPlatformSysConfigInitialize ();

+

+  // If we skip the PEI Core we could want to initialize the DRAM in the SEC phase.

+  // If we are in standalone, we need the initialization to copy the UEFI firmware into DRAM

+  if ((FeaturePcdGet (PcdSystemMemoryInitializeInSec)) || (FeaturePcdGet (PcdStandalone) == FALSE)) {

+    // If it is not a standalone build ensure the PcdSystemMemoryInitializeInSec has been set

+    ASSERT(FeaturePcdGet (PcdSystemMemoryInitializeInSec) == TRUE);

+

+    // Initialize system memory (DRAM)

+    ArmPlatformInitializeSystemMemory ();

+  }

+

+  // Memory Map remapping

+  if (FeaturePcdGet (PcdNorFlashRemapping)) {

+    SerialPrint ("Secure ROM at 0x0\n\r");

+  } else {

+    Value = MmioRead32 (ARM_VE_SYS_CFGRW1_REG); //Scc - CFGRW1

+    // Remap the DRAM to 0x0

+    MmioWrite32 (ARM_VE_SYS_CFGRW1_REG, (Value & 0x0FFFFFFF) | ARM_VE_CFGRW1_REMAP_DRAM);

+  }

+

+  return RETURN_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/GicV3.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/GicV3.S
new file mode 100644
index 0000000..035e095
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/GicV3.S
@@ -0,0 +1,70 @@
+//

+//  Copyright (c) 2013-2014, ARM 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.

+//

+//

+

+#include <AsmMacroIoLibV8.h>

+#include <Chipset/AArch64.h>

+

+#ifndef __clang__

+// Register definitions used by GCC for GICv3 access.

+// These are defined by ARMCC, so keep them in the GCC specific code for now.

+#define ICC_SRE_EL2     S3_4_C12_C9_5

+#define ICC_SRE_EL3     S3_6_C12_C12_5

+#define ICC_CTLR_EL1    S3_0_C12_C12_4

+#define ICC_CTLR_EL3    S3_6_C12_C12_4

+#define ICC_PMR_EL1     S3_0_C4_C6_0

+#endif

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(InitializeGicV3)

+

+/* Initialize GICv3 to expose it as a GICv2 as UEFI does not support GICv3 yet */

+ASM_PFX(InitializeGicV3):

+  // We have a GICv3. UEFI still uses the GICv2 mode. We must do enough setup

+  // to allow Linux to use GICv3 if it chooses.

+

+  // In order to setup NS side we need to enable it first.

+  mrs     x0, scr_el3

+  orr     x0, x0, #1

+  msr     scr_el3, x0

+

+  // Enable SRE at EL3 and ICC_SRE_EL2 access

+  mov     x0, #((1 << 3) | (1 << 0))      // Enable | SRE

+  mrs     x1, ICC_SRE_EL3

+  orr     x1, x1, x0

+  msr     ICC_SRE_EL3, x1

+  isb

+

+  // Enable SRE at EL2 and ICC_SRE_EL1 access..

+  mrs     x1, ICC_SRE_EL2

+  orr     x1, x1, x0

+  msr     ICC_SRE_EL2, x1

+  isb

+

+  // Configure CPU interface

+  msr     ICC_CTLR_EL3, xzr

+  isb

+  msr     ICC_CTLR_EL1, xzr

+  isb

+

+  // The MemoryMap view and Register view may not be consistent, So Set PMR again.

+  mov     w1, #1 << 7                        // allow NS access to GICC_PMR

+  msr     ICC_PMR_EL1, x1

+  isb

+

+  // Remove the SCR.NS bit

+  mrs     x0, scr_el3

+  and     x0, x0, #~SCR_NS

+  msr     scr_el3, x0

+  ret

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/RTSMBoot.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/RTSMBoot.S
new file mode 100644
index 0000000..6c73cda
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/RTSMBoot.S
@@ -0,0 +1,64 @@
+//

+//  Copyright (c) 2011 - 2014, ARM 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.

+//

+//

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <Library/ArmPlatformLib.h>

+#include <AutoGen.h>

+#include <ArmPlatform.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformSecBootAction)

+GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit)

+GCC_ASM_EXPORT(ArmSecMpCoreSecondariesWrite)

+GCC_ASM_EXPORT(ArmSecMpCoreSecondariesRead)

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ASM_PFX(ArmPlatformSecBootAction):

+  ret

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ASM_PFX(ArmPlatformSecBootMemoryInit):

+  // The SMC does not need to be initialized for RTSM

+  ret

+

+/* Write the flag register used to start Secondary cores */

+ASM_PFX(ArmSecMpCoreSecondariesWrite):

+  // Write to the CPU Mailbox

+  ret

+

+/* Read the flag register used to start Secondary cores */

+ASM_PFX(ArmSecMpCoreSecondariesRead):

+  // Return the value from the CPU Mailbox

+  mov x0, #0

+  ret

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/RTSMFoundationBoot.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/RTSMFoundationBoot.S
new file mode 100644
index 0000000..a07ed97
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/AArch64/RTSMFoundationBoot.S
@@ -0,0 +1,75 @@
+//

+//  Copyright (c) 2011-2014, ARM 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.

+//

+//

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <Library/ArmPlatformLib.h>

+#include <AutoGen.h>

+#include <ArmPlatform.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformSecBootAction)

+GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit)

+GCC_ASM_EXPORT(ArmSecMpCoreSecondariesWrite)

+GCC_ASM_EXPORT(ArmSecMpCoreSecondariesRead)

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ASM_PFX(ArmPlatformSecBootAction):

+  ret

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the stack has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ASM_PFX(ArmPlatformSecBootMemoryInit):

+  // The SMC does not need to be initialized for RTSM

+  ret

+

+

+// NOTE:

+// The foundation model does not have the VE_SYS_REGS like all the other VE

+// platforms. We pick a spot in RAM that *should* be safe in the simple case

+// of no UEFI apps interfering (Only the Linux loader getting used). By the

+// time we come to load Linux we should have all the cores in a safe place.

+// The image expects to be loaded at 0xa0000000. We also place the mailboxes

+// here as it does not matter if we corrupt the image at this time.

+// NOTE also see: "ArmVExpressLibRTSM/RTSMFoundation.c"

+

+/* Write the flag register used to start Secondary cores */

+ASM_PFX(ArmSecMpCoreSecondariesWrite):

+  ldr x1, =0xa0000000

+  str w0, [x1]

+  ret

+

+

+/* Read the flag register used to start Secondary cores */

+ASM_PFX(ArmSecMpCoreSecondariesRead):

+  ldr x1, =0xa0000000

+  ldr w0, [x1]

+  ret

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/GicV3.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/GicV3.S
new file mode 100644
index 0000000..4a82cdb
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/GicV3.S
@@ -0,0 +1,24 @@
+//

+//  Copyright (c) 2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(InitializeGicV3)

+

+/* Initialize GICv3 to expose it as a GICv2 as UEFI does not support GICv3 yet */

+ASM_PFX(InitializeGicV3):

+  // GICv3 Initialization not Supported yet

+  bx  lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/GicV3.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/GicV3.asm
new file mode 100644
index 0000000..4578c1c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/GicV3.asm
@@ -0,0 +1,27 @@
+//

+//  Copyright (c) 2013, ARM 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.

+//

+//

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  InitializeGicV3

+

+  PRESERVE8

+  AREA    GicV3, CODE, READONLY

+

+/* Initialize GICv3 to expose it as a GICv2 as UEFI does not support GICv3 yet */

+InitializeGicV3 FUNCTION

+  // GICv3 Initialization not Supported yet

+  bx  lr

+  ENDFUNC

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/RTSMBoot.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/RTSMBoot.S
new file mode 100644
index 0000000..371adcb
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/RTSMBoot.S
@@ -0,0 +1,50 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmPlatformLib.h>

+#include <AutoGen.h>

+#include <ArmPlatform.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformSecBootAction)

+GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit)

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ASM_PFX(ArmPlatformSecBootAction):

+  bx  lr

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ASM_PFX(ArmPlatformSecBootMemoryInit):

+  // The SMC does not need to be initialized for RTSM

+  bx    lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/RTSMBoot.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/RTSMBoot.asm
new file mode 100644
index 0000000..2d0b946
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/Arm/RTSMBoot.asm
@@ -0,0 +1,54 @@
+//

+//  Copyright (c) 2011, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmPlatformLib.h>

+#include <AutoGen.h>

+#include <ArmPlatform.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformSecBootAction

+  EXPORT  ArmPlatformSecBootMemoryInit

+

+  PRESERVE8

+  AREA    RTSMVExpressBootMode, CODE, READONLY

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ArmPlatformSecBootAction

+  bx  lr

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ArmPlatformSecBootMemoryInit

+  // The SMC does not need to be initialized for RTSM

+  bx    lr

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressFoundationSecLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressFoundationSecLib.inf
new file mode 100644
index 0000000..2e05bec
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressFoundationSecLib.inf
@@ -0,0 +1,42 @@
+#/* @file

+#

+#  Copyright (c) 2011-2013, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = RTSMArmVExpressFoundationSecLib

+  FILE_GUID                      = 9de85c42-0894-11e2-8ed6-1c6f650265cc

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSecLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  SerialPortLib

+

+[Sources.common]

+  RTSMFoundationSec.c

+

+[Sources.AARCH64]

+  AArch64/RTSMFoundationBoot.S

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf
new file mode 100644
index 0000000..ee7d325
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/ArmVExpressSecLib.inf
@@ -0,0 +1,49 @@
+#/* @file

+#  Copyright (c) 2011-2013, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = RTSMArmVExpressSecLib

+  FILE_GUID                      = 1fdaabb0-ab7d-480c-91ff-428dc1546f3a

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSecLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  SerialPortLib

+

+[Sources.common]

+  RTSMSec.c

+

+[Sources.ARM]

+  Arm/RTSMBoot.asm     | RVCT

+  Arm/RTSMBoot.S       | GCC

+  Arm/GicV3.asm        | RVCT

+  Arm/GicV3.S          | GCC

+

+[Sources.AARCH64]

+  AArch64/RTSMBoot.S

+  AArch64/GicV3.S

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/RTSMFoundationSec.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/RTSMFoundationSec.c
new file mode 100644
index 0000000..bae6d0b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/RTSMFoundationSec.c
@@ -0,0 +1,71 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Drivers/PL310L2Cache.h>

+#include <Drivers/SP804Timer.h>

+

+#include <ArmPlatform.h>

+

+/**

+  Initialize the Secure peripherals and memory regions

+

+  If Trustzone is supported by your platform then this function makes the required initialization

+  of the secure peripherals and memory regions.

+

+**/

+VOID

+ArmPlatformSecTrustzoneInit (

+  IN  UINTN                     MpId

+  )

+{

+  // No TZPC or TZASC on RTSM to initialize

+}

+

+/**

+  Initialize controllers that must setup at the early stage

+

+  Some peripherals must be initialized in Secure World.

+  For example, some L2x0 requires to be initialized in Secure World

+

+**/

+RETURN_STATUS

+ArmPlatformSecInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  /* The Foundation model has no SP810 to initialise. */

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Call before jumping to Normal World

+

+  This function allows the firmware platform to do extra actions before

+  jumping to the Normal World

+

+**/

+VOID

+ArmPlatformSecExtraAction (

+  IN  UINTN         MpId,

+  OUT UINTN*        JumpAddress

+  )

+{

+  *JumpAddress = PcdGet64 (PcdFvBaseAddress);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/RTSMSec.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/RTSMSec.c
new file mode 100644
index 0000000..9023715
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSecLibRTSM/RTSMSec.c
@@ -0,0 +1,100 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/ArmGicLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#include <Drivers/PL310L2Cache.h>

+#include <Drivers/SP804Timer.h>

+

+#include <ArmPlatform.h>

+

+// Initialize GICv3 to expose it as a GICv2 as UEFI does not support GICv3 yet

+VOID

+InitializeGicV3 (

+  VOID

+  );

+

+/**

+  Initialize the Secure peripherals and memory regions

+

+  If Trustzone is supported by your platform then this function makes the required initialization

+  of the secure peripherals and memory regions.

+

+**/

+VOID

+ArmPlatformSecTrustzoneInit (

+  IN  UINTN                     MpId

+  )

+{

+  // No TZPC or TZASC on RTSM to initialize

+}

+

+/**

+  Initialize controllers that must setup at the early stage

+

+  Some peripherals must be initialized in Secure World.

+  For example, some L2x0 requires to be initialized in Secure World

+

+**/

+RETURN_STATUS

+ArmPlatformSecInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  UINT32  Identification;

+

+  // If it is not the primary core then there is nothing to do

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // Configure periodic timer (TIMER0) for 1MHz operation

+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER0_TIMCLK);

+  // Configure 1MHz clock

+  MmioOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER1_TIMCLK);

+  // Configure SP810 to use 1MHz clock and disable

+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);

+  // Configure SP810 to use 1MHz clock and disable

+  MmioAndThenOr32 (SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER3_EN, SP810_SYS_CTRL_TIMER3_TIMCLK);

+

+  // Read the GIC Identification Register

+  Identification = ArmGicGetInterfaceIdentification (PcdGet32 (PcdGicInterruptInterfaceBase));

+

+  // Check if we are GICv3

+  if (ARM_GIC_ICCIIDR_GET_ARCH_VERSION(Identification) >= 0x3) {

+    InitializeGicV3 ();

+  }

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Call before jumping to Normal World

+

+  This function allows the firmware platform to do extra actions before

+  jumping to the Normal World

+

+**/

+VOID

+ArmPlatformSecExtraAction (

+  IN  UINTN         MpId,

+  OUT UINTN*        JumpAddress

+  )

+{

+  *JumpAddress = PcdGet64 (PcdFvBaseAddress);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfig.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfig.c
new file mode 100644
index 0000000..6dfbacd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfig.c
@@ -0,0 +1,273 @@
+/** @file  ArmVExpressSysConfig.c

+

+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+

+  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 <Base.h>

+#include <Library/IoLib.h>

+#include <Library/DebugLib.h>

+

+#include <Library/ArmPlatformSysConfigLib.h>

+#include <ArmPlatform.h>

+

+//

+// SYS_CFGCTRL Bits

+//

+#define SYS_CFGCTRL_START                 BIT31

+#define SYS_CFGCTRL_READ                  (0 << 30)

+#define SYS_CFGCTRL_WRITE                 (1 << 30)

+#define SYS_CFGCTRL_FUNCTION(fun)         (((fun ) &  0x3F) << 20)

+#define SYS_CFGCTRL_SITE(site)            (((site) &   0x3) << 16)

+#define SYS_CFGCTRL_POSITION(pos)         (((pos ) &   0xF) << 12)

+#define SYS_CFGCTRL_DEVICE(dev)            ((dev ) & 0xFFF)

+

+//

+// SYS_CFGSTAT Bits

+//

+#define SYS_CFGSTAT_ERROR                 BIT1

+#define SYS_CFGSTAT_COMPLETE              BIT0

+

+/****************************************************************************

+ *

+ *  This file makes it easier to access the System Configuration Registers

+ *  in the ARM Versatile Express motherboard.

+ *

+ ****************************************************************************/

+

+RETURN_STATUS

+ArmPlatformSysConfigInitialize (

+  VOID

+  )

+{

+  return RETURN_SUCCESS;

+}

+

+/***************************************

+ * GENERAL FUNCTION: AccessSysCfgRegister

+ * Interacts with

+ *    SYS_CFGSTAT

+ *    SYS_CFGDATA

+ *    SYS_CFGCTRL

+ * for setting and for reading out values

+ ***************************************/

+

+RETURN_STATUS

+AccessSysCfgRegister (

+  IN     UINT32   ReadWrite,

+  IN     UINT32   Function,

+  IN     UINT32   Site,

+  IN     UINT32   Position,

+  IN     UINT32   Device,

+  IN OUT UINT32*  Data

+  )

+{

+  UINT32          SysCfgCtrl;

+

+  // Clear the COMPLETE bit

+  MmioAnd32(ARM_VE_SYS_CFGSTAT_REG, ~SYS_CFGSTAT_COMPLETE);

+

+  // If writing, then set the data value

+  if(ReadWrite == SYS_CFGCTRL_WRITE) {

+    MmioWrite32(ARM_VE_SYS_CFGDATA_REG, *Data);

+  }

+

+  // Set the control value

+  SysCfgCtrl = SYS_CFGCTRL_START | ReadWrite | SYS_CFGCTRL_FUNCTION(Function) | SYS_CFGCTRL_SITE(Site) |

+      SYS_CFGCTRL_POSITION(Position) | SYS_CFGCTRL_DEVICE(Device);

+  MmioWrite32(ARM_VE_SYS_CFGCTRL_REG, SysCfgCtrl);

+

+  // Wait until the COMPLETE bit is set

+  while ((MmioRead32(ARM_VE_SYS_CFGSTAT_REG) & SYS_CFGSTAT_COMPLETE) == 0);

+

+  // Check for errors

+  if(MmioRead32(ARM_VE_SYS_CFGSTAT_REG) & SYS_CFGSTAT_ERROR) {

+    return RETURN_DEVICE_ERROR;

+  }

+

+  // If reading then get the data value

+  if(ReadWrite == SYS_CFGCTRL_READ) {

+    *Data = MmioRead32(ARM_VE_SYS_CFGDATA_REG);

+  }

+

+  return RETURN_SUCCESS;

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigGet (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  OUT UINT32*               Value

+  )

+{

+  UINT32          Site;

+  UINT32          Position;

+  UINT32          Device;

+

+  Position = 0;

+  Device = 0;

+

+  // Intercept some functions

+  switch(Function) {

+

+  case SYS_CFG_OSC_SITE1:

+    Function = SYS_CFG_OSC;

+    Site = ARM_VE_DAUGHTERBOARD_1_SITE;

+    break;

+

+  case SYS_CFG_OSC_SITE2:

+    Function = SYS_CFG_OSC;

+    Site = ARM_VE_DAUGHTERBOARD_2_SITE;

+    break;

+

+  case SYS_CFG_MUXFPGA:

+    Site = *Value;

+    break;

+

+  case SYS_CFG_OSC:

+  case SYS_CFG_VOLT:

+  case SYS_CFG_AMP:

+  case SYS_CFG_TEMP:

+  case SYS_CFG_RESET:

+  case SYS_CFG_SCC:

+  case SYS_CFG_DVIMODE:

+  case SYS_CFG_POWER:

+    Site = ARM_VE_MOTHERBOARD_SITE;

+    break;

+

+  case SYS_CFG_SHUTDOWN:

+  case SYS_CFG_REBOOT:

+  case SYS_CFG_RTC:

+  default:

+    return RETURN_UNSUPPORTED;

+  }

+

+  return AccessSysCfgRegister (SYS_CFGCTRL_READ, Function, Site, Position, Device, Value);

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigGetValues (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINTN                 Size,

+  OUT UINT32*               Values

+  )

+{

+  return RETURN_UNSUPPORTED;

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigSet (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINT32                Value

+  )

+{

+  UINT32          Site;

+  UINT32          Position;

+  UINT32          Device;

+

+  Position = 0;

+  Device = 0;

+

+  // Intercept some functions

+  switch(Function) {

+

+  case SYS_CFG_OSC_SITE1:

+    Function = SYS_CFG_OSC;

+    Site = ARM_VE_DAUGHTERBOARD_1_SITE;

+    break;

+

+  case SYS_CFG_OSC_SITE2:

+    Function = SYS_CFG_OSC;

+    Site = ARM_VE_DAUGHTERBOARD_2_SITE;

+    break;

+

+  case SYS_CFG_MUXFPGA:

+    Site = Value;

+    break;

+

+  case SYS_CFG_RESET:

+  case SYS_CFG_SCC:

+  case SYS_CFG_SHUTDOWN:

+  case SYS_CFG_REBOOT:

+  case SYS_CFG_DVIMODE:

+  case SYS_CFG_POWER:

+    Site = ARM_VE_MOTHERBOARD_SITE;

+    break;

+

+  case SYS_CFG_OSC:

+  case SYS_CFG_VOLT:

+  case SYS_CFG_AMP:

+  case SYS_CFG_TEMP:

+  case SYS_CFG_RTC:

+  default:

+    return RETURN_UNSUPPORTED;

+  }

+

+  return AccessSysCfgRegister (SYS_CFGCTRL_WRITE, Function, Site, Position, Device, &Value);

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigSetDevice (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINT32                Device,

+  IN  UINT32                Value

+  )

+{

+  UINT32          Site;

+  UINT32          Position;

+

+  Position = 0;

+

+  // Intercept some functions

+  switch(Function) {

+  case SYS_CFG_SCC:

+#ifdef ARM_VE_SCC_BASE

+    MmioWrite32 ((ARM_VE_SCC_BASE + (Device * 4)),Value);

+    return RETURN_SUCCESS;

+#else

+    // There is no System Configuration Controller on the Model

+    return RETURN_UNSUPPORTED;

+#endif

+

+  case SYS_CFG_OSC_SITE1:

+    Function = SYS_CFG_OSC;

+    Site = ARM_VE_DAUGHTERBOARD_1_SITE;

+    break;

+

+  case SYS_CFG_OSC_SITE2:

+    Function = SYS_CFG_OSC;

+    Site = ARM_VE_DAUGHTERBOARD_2_SITE;

+    break;

+

+  case SYS_CFG_MUXFPGA:

+    Site = Value;

+    break;

+

+  case SYS_CFG_RTC:

+    return RETURN_UNSUPPORTED;

+    //break;

+

+  case SYS_CFG_OSC:

+  case SYS_CFG_VOLT:

+  case SYS_CFG_AMP:

+  case SYS_CFG_TEMP:

+  case SYS_CFG_RESET:

+  case SYS_CFG_SHUTDOWN:

+  case SYS_CFG_REBOOT:

+  case SYS_CFG_DVIMODE:

+  case SYS_CFG_POWER:

+    Site = ARM_VE_MOTHERBOARD_SITE;

+    break;

+  default:

+    return RETURN_UNSUPPORTED;

+  }

+

+  return AccessSysCfgRegister (SYS_CFGCTRL_WRITE, Function, Site, Position, Device, &Value);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf
new file mode 100644
index 0000000..c164775
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf
@@ -0,0 +1,35 @@
+#/** @file

+#

+#  Component description file for ArmVExpressSysConfigLib module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmVExpressSysConfigLib

+  FILE_GUID                      = a05b5cc0-82d2-11e0-82cb-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSysConfigLib

+

+[Sources.common]

+  ArmVExpressSysConfig.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  IoLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c
new file mode 100644
index 0000000..a578467
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c
@@ -0,0 +1,289 @@
+/**

+

+  Copyright (c) 2012, ARM Ltd. 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 <PiDxe.h>

+

+#include <Library/ArmPlatformSysConfigLib.h>

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+#include <Library/DebugLib.h>

+#include <Library/LcdPlatformLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#include <Protocol/Cpu.h>

+#include <Protocol/EdidDiscovered.h>

+#include <Protocol/EdidActive.h>

+

+#include <ArmPlatform.h>

+

+typedef struct {

+  UINT32                     Mode;

+  UINT32                     HorizontalResolution;

+  UINT32                     VerticalResolution;

+  LCD_BPP                    Bpp;

+  UINT32                     OscFreq;

+

+  // These are used by HDLCD

+  UINT32                     HSync;

+  UINT32                     HBackPorch;

+  UINT32                     HFrontPorch;

+  UINT32                     VSync;

+  UINT32                     VBackPorch;

+  UINT32                     VFrontPorch;

+} LCD_RESOLUTION;

+

+

+LCD_RESOLUTION mResolutions[] = {

+  { // Mode 0 : VGA : 640 x 480 x 24 bpp

+    VGA, VGA_H_RES_PIXELS, VGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, VGA_OSC_FREQUENCY,

+    VGA_H_SYNC, VGA_H_BACK_PORCH, VGA_H_FRONT_PORCH,

+    VGA_V_SYNC, VGA_V_BACK_PORCH, VGA_V_FRONT_PORCH

+  },

+  { // Mode 1 : SVGA : 800 x 600 x 24 bpp

+    SVGA, SVGA_H_RES_PIXELS, SVGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, SVGA_OSC_FREQUENCY,

+    SVGA_H_SYNC, SVGA_H_BACK_PORCH, SVGA_H_FRONT_PORCH,

+    SVGA_V_SYNC, SVGA_V_BACK_PORCH, SVGA_V_FRONT_PORCH

+  },

+  { // Mode 2 : XGA : 1024 x 768 x 24 bpp

+    XGA, XGA_H_RES_PIXELS, XGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, XGA_OSC_FREQUENCY,

+    XGA_H_SYNC, XGA_H_BACK_PORCH, XGA_H_FRONT_PORCH,

+    XGA_V_SYNC, XGA_V_BACK_PORCH, XGA_V_FRONT_PORCH

+  },

+  { // Mode 3 : SXGA : 1280 x 1024 x 24 bpp

+    SXGA, SXGA_H_RES_PIXELS, SXGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, (SXGA_OSC_FREQUENCY/2),

+    SXGA_H_SYNC, SXGA_H_BACK_PORCH, SXGA_H_FRONT_PORCH,

+    SXGA_V_SYNC, SXGA_V_BACK_PORCH, SXGA_V_FRONT_PORCH

+  },

+  { // Mode 4 : UXGA : 1600 x 1200 x 24 bpp

+    UXGA, UXGA_H_RES_PIXELS, UXGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, (UXGA_OSC_FREQUENCY/2),

+    UXGA_H_SYNC, UXGA_H_BACK_PORCH, UXGA_H_FRONT_PORCH,

+    UXGA_V_SYNC, UXGA_V_BACK_PORCH, UXGA_V_FRONT_PORCH

+  },

+  { // Mode 5 : HD : 1920 x 1080 x 24 bpp

+    HD, HD_H_RES_PIXELS, HD_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, (HD_OSC_FREQUENCY/2),

+    HD_H_SYNC, HD_H_BACK_PORCH, HD_H_FRONT_PORCH,

+    HD_V_SYNC, HD_V_BACK_PORCH, HD_V_FRONT_PORCH

+  }

+};

+

+EFI_EDID_DISCOVERED_PROTOCOL  mEdidDiscovered = {

+  0,

+  NULL

+};

+

+EFI_EDID_ACTIVE_PROTOCOL      mEdidActive = {

+  0,

+  NULL

+};

+

+EFI_STATUS

+LcdPlatformInitializeDisplay (

+  IN EFI_HANDLE   Handle

+  )

+{

+  EFI_STATUS  Status;

+

+  // Set the FPGA multiplexer to select the video output from the motherboard or the daughterboard

+  Status = ArmPlatformSysConfigSet (SYS_CFG_MUXFPGA, ARM_VE_DAUGHTERBOARD_1_SITE);

+  if (EFI_ERROR(Status)) {

+    return Status;

+  }

+

+  // Install the EDID Protocols

+  Status = gBS->InstallMultipleProtocolInterfaces (

+    &Handle,

+    &gEfiEdidDiscoveredProtocolGuid,  &mEdidDiscovered,

+    &gEfiEdidActiveProtocolGuid,      &mEdidActive,

+    NULL

+  );

+

+  return Status;

+}

+

+EFI_STATUS

+LcdPlatformGetVram (

+  OUT EFI_PHYSICAL_ADDRESS*  VramBaseAddress,

+  OUT UINTN*                 VramSize

+  )

+{

+  EFI_STATUS              Status;

+  EFI_CPU_ARCH_PROTOCOL  *Cpu;

+  EFI_ALLOCATE_TYPE       AllocationType;

+

+  // Set the vram size

+  *VramSize = LCD_VRAM_SIZE;

+

+  *VramBaseAddress = (EFI_PHYSICAL_ADDRESS)LCD_VRAM_CORE_TILE_BASE;

+

+  // Allocate the VRAM from the DRAM so that nobody else uses it.

+  if (*VramBaseAddress == 0) {

+    AllocationType = AllocateAnyPages;

+  } else {

+    AllocationType = AllocateAddress;

+  }

+  Status = gBS->AllocatePages (AllocationType, EfiBootServicesData, EFI_SIZE_TO_PAGES(((UINTN)LCD_VRAM_SIZE)), VramBaseAddress);

+  if (EFI_ERROR(Status)) {

+    return Status;

+  }

+

+  // Ensure the Cpu architectural protocol is already installed

+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);

+  ASSERT_EFI_ERROR(Status);

+

+  // Mark the VRAM as un-cacheable. The VRAM is inside the DRAM, which is cacheable.

+  Status = Cpu->SetMemoryAttributes (Cpu, *VramBaseAddress, *VramSize, EFI_MEMORY_UC);

+  ASSERT_EFI_ERROR(Status);

+  if (EFI_ERROR(Status)) {

+    gBS->FreePool (VramBaseAddress);

+    return Status;

+  }

+

+  return EFI_SUCCESS;

+}

+

+UINT32

+LcdPlatformGetMaxMode (

+  VOID

+  )

+{

+  //

+  // The following line will report correctly the total number of graphics modes

+  // that could be supported by the graphics driver:

+  //

+  return (sizeof(mResolutions) / sizeof(LCD_RESOLUTION));

+}

+

+EFI_STATUS

+LcdPlatformSetMode (

+  IN UINT32                         ModeNumber

+  )

+{

+  EFI_STATUS            Status;

+

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Set the video mode oscillator

+  do {

+    Status = ArmPlatformSysConfigSetDevice (SYS_CFG_OSC_SITE1, PcdGet32(PcdHdLcdVideoModeOscId), mResolutions[ModeNumber].OscFreq);

+  } while (Status == EFI_TIMEOUT);

+  if (EFI_ERROR(Status)) {

+    ASSERT_EFI_ERROR (Status);

+    return Status;

+  }

+

+  // Set the DVI into the new mode

+  do {

+    Status = ArmPlatformSysConfigSet (SYS_CFG_DVIMODE, mResolutions[ModeNumber].Mode);

+  } while (Status == EFI_TIMEOUT);

+  if (EFI_ERROR(Status)) {

+    ASSERT_EFI_ERROR (Status);

+    return Status;

+  }

+

+  // Set the multiplexer

+  Status = ArmPlatformSysConfigSet (SYS_CFG_MUXFPGA, ARM_VE_DAUGHTERBOARD_1_SITE);

+  if (EFI_ERROR(Status)) {

+    ASSERT_EFI_ERROR (Status);

+    return Status;

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+LcdPlatformQueryMode (

+  IN  UINT32                                ModeNumber,

+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Info->Version = 0;

+  Info->HorizontalResolution = mResolutions[ModeNumber].HorizontalResolution;

+  Info->VerticalResolution = mResolutions[ModeNumber].VerticalResolution;

+  Info->PixelsPerScanLine = mResolutions[ModeNumber].HorizontalResolution;

+

+  switch (mResolutions[ModeNumber].Bpp) {

+    case LCD_BITS_PER_PIXEL_24:

+      Info->PixelFormat                   = PixelRedGreenBlueReserved8BitPerColor;

+      Info->PixelInformation.RedMask      = LCD_24BPP_RED_MASK;

+      Info->PixelInformation.GreenMask    = LCD_24BPP_GREEN_MASK;

+      Info->PixelInformation.BlueMask     = LCD_24BPP_BLUE_MASK;

+      Info->PixelInformation.ReservedMask = LCD_24BPP_RESERVED_MASK;

+      break;

+

+    case LCD_BITS_PER_PIXEL_16_555:

+    case LCD_BITS_PER_PIXEL_16_565:

+    case LCD_BITS_PER_PIXEL_12_444:

+    case LCD_BITS_PER_PIXEL_8:

+    case LCD_BITS_PER_PIXEL_4:

+    case LCD_BITS_PER_PIXEL_2:

+    case LCD_BITS_PER_PIXEL_1:

+    default:

+      // These are not supported

+      ASSERT(FALSE);

+      break;

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdPlatformGetTimings (

+  IN  UINT32                              ModeNumber,

+  OUT UINT32*                             HRes,

+  OUT UINT32*                             HSync,

+  OUT UINT32*                             HBackPorch,

+  OUT UINT32*                             HFrontPorch,

+  OUT UINT32*                             VRes,

+  OUT UINT32*                             VSync,

+  OUT UINT32*                             VBackPorch,

+  OUT UINT32*                             VFrontPorch

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *HRes           = mResolutions[ModeNumber].HorizontalResolution;

+  *HSync          = mResolutions[ModeNumber].HSync;

+  *HBackPorch     = mResolutions[ModeNumber].HBackPorch;

+  *HFrontPorch    = mResolutions[ModeNumber].HFrontPorch;

+  *VRes           = mResolutions[ModeNumber].VerticalResolution;

+  *VSync          = mResolutions[ModeNumber].VSync;

+  *VBackPorch     = mResolutions[ModeNumber].VBackPorch;

+  *VFrontPorch    = mResolutions[ModeNumber].VFrontPorch;

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdPlatformGetBpp (

+  IN  UINT32                              ModeNumber,

+  OUT LCD_BPP  *                          Bpp

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *Bpp = mResolutions[ModeNumber].Bpp;

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpressLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpressLib.inf
new file mode 100644
index 0000000..7807247
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpressLib.inf
@@ -0,0 +1,44 @@
+#/** @file

+#

+#  Component description file for HdLcdArmLib module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = HdLcdArmVExpress

+  FILE_GUID                      = 535a720e-06c0-4bb9-b563-452216abbed4

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = LcdPlatformLib

+

+[Sources.common]

+

+HdLcdArmVExpress.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  ArmPlatformSysConfigLib

+

+[Protocols]

+  gEfiEdidDiscoveredProtocolGuid                # Produced

+  gEfiEdidActiveProtocolGuid                    # Produced

+

+[Pcd]

+  gArmVExpressTokenSpaceGuid.PcdPL111LcdMaxMode

+  gArmVExpressTokenSpaceGuid.PcdHdLcdVideoModeOscId

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpress.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpress.c
new file mode 100644
index 0000000..a136bff
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpress.c
@@ -0,0 +1,84 @@
+/** @file

+

+ Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+

+ 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 <PiDxe.h>

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/NorFlashPlatformLib.h>

+#include <ArmPlatform.h>

+

+#define NOR_FLASH_DEVICE_COUNT                     4

+

+NOR_FLASH_DESCRIPTION mNorFlashDevices[NOR_FLASH_DEVICE_COUNT] = {

+  { // BootMon

+    ARM_VE_SMB_NOR0_BASE,

+    ARM_VE_SMB_NOR0_BASE,

+    SIZE_256KB * 255,

+    SIZE_256KB,

+    { 0xE7223039, 0x5836, 0x41E1, { 0xB5, 0x42, 0xD7, 0xEC, 0x73, 0x6C, 0x5E, 0x59 } }

+  },

+  { // BootMon non-volatile storage

+    ARM_VE_SMB_NOR0_BASE,

+    ARM_VE_SMB_NOR0_BASE + SIZE_256KB * 255,

+    SIZE_64KB * 4,

+    SIZE_64KB,

+    { 0x02118005, 0x9DA7, 0x443A, { 0x92, 0xD5, 0x78, 0x1F, 0x02, 0x2A, 0xED, 0xBB } }

+  },

+  { // UEFI

+    ARM_VE_SMB_NOR1_BASE,

+    ARM_VE_SMB_NOR1_BASE,

+    SIZE_256KB * 255,

+    SIZE_256KB,

+    { 0x1F15DA3C, 0x37FF, 0x4070, { 0xB4, 0x71, 0xBB, 0x4A, 0xF1, 0x2A, 0x72, 0x4A } }

+  },

+  { // UEFI Variable Services non-volatile storage

+    ARM_VE_SMB_NOR1_BASE,

+    ARM_VE_SMB_NOR1_BASE + SIZE_256KB * 255,

+    SIZE_64KB * 3, //FIXME: Set 3 blocks because I did not succeed to copy 4 blocks into the ARM Versatile Express NOR Flash in the last NOR Flash. It should be 4 blocks

+    SIZE_64KB,

+    { 0xCC2CBF29, 0x1498, 0x4CDD, { 0x81, 0x71, 0xF8, 0xB6, 0xB4, 0x1D, 0x09, 0x09 } }

+  }

+};

+

+EFI_STATUS

+NorFlashPlatformInitialization (

+  VOID

+  )

+{

+  // Everything seems ok so far, so now we need to disable the platform-specific

+  // flash write protection for Versatile Express

+  if ((MmioRead32 (ARM_VE_SYS_FLASH) & 0x1) == 0) {

+    // Writing to NOR FLASH is disabled, so enable it

+    MmioWrite32 (ARM_VE_SYS_FLASH,1);

+    DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: informational - Had to enable HSYS_FLASH flag.\n" ));

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+NorFlashPlatformGetDevices (

+  OUT NOR_FLASH_DESCRIPTION   **NorFlashDevices,

+  OUT UINT32                  *Count

+  )

+{

+  if ((NorFlashDevices == NULL) || (Count == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *NorFlashDevices = mNorFlashDevices;

+  *Count = NOR_FLASH_DEVICE_COUNT;

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf
new file mode 100644
index 0000000..0798cc3
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf
@@ -0,0 +1,32 @@
+#/** @file

+#

+#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = NorFlashArmVExpressLib

+  FILE_GUID                      = c0f5dfa0-7599-11e0-9665-0002a5d5c51b

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = NorFlashPlatformLib

+

+[Sources.common]

+  NorFlashArmVExpress.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  IoLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c
new file mode 100644
index 0000000..c6b37fc
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c
@@ -0,0 +1,374 @@
+/** @file

+

+  Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>

+  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 <PiDxe.h>

+

+#include <Library/ArmPlatformSysConfigLib.h>

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+#include <Library/DebugLib.h>

+#include <Library/LcdPlatformLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#include <Protocol/Cpu.h>

+#include <Protocol/EdidDiscovered.h>

+#include <Protocol/EdidActive.h>

+

+#include <ArmPlatform.h>

+

+typedef struct {

+  UINT32                     Mode;

+  UINT32                     HorizontalResolution;

+  UINT32                     VerticalResolution;

+  LCD_BPP                    Bpp;

+  UINT32                     OscFreq;

+

+  UINT32                     HSync;

+  UINT32                     HBackPorch;

+  UINT32                     HFrontPorch;

+  UINT32                     VSync;

+  UINT32                     VBackPorch;

+  UINT32                     VFrontPorch;

+} LCD_RESOLUTION;

+

+

+LCD_RESOLUTION mResolutions[] = {

+  { // Mode 0 : VGA : 640 x 480 x 24 bpp

+      VGA, VGA_H_RES_PIXELS, VGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, VGA_OSC_FREQUENCY,

+      VGA_H_SYNC, VGA_H_BACK_PORCH, VGA_H_FRONT_PORCH,

+      VGA_V_SYNC, VGA_V_BACK_PORCH, VGA_V_FRONT_PORCH

+  },

+  { // Mode 1 : SVGA : 800 x 600 x 24 bpp

+      SVGA, SVGA_H_RES_PIXELS, SVGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, SVGA_OSC_FREQUENCY,

+      SVGA_H_SYNC, SVGA_H_BACK_PORCH, SVGA_H_FRONT_PORCH,

+      SVGA_V_SYNC, SVGA_V_BACK_PORCH, SVGA_V_FRONT_PORCH

+  },

+  { // Mode 2 : XGA : 1024 x 768 x 24 bpp

+      XGA, XGA_H_RES_PIXELS, XGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, XGA_OSC_FREQUENCY,

+      XGA_H_SYNC, XGA_H_BACK_PORCH, XGA_H_FRONT_PORCH,

+      XGA_V_SYNC, XGA_V_BACK_PORCH, XGA_V_FRONT_PORCH

+  },

+  { // Mode 3 : SXGA : 1280 x 1024 x 24 bpp

+      SXGA, SXGA_H_RES_PIXELS, SXGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, (SXGA_OSC_FREQUENCY/2),

+      SXGA_H_SYNC, SXGA_H_BACK_PORCH, SXGA_H_FRONT_PORCH,

+      SXGA_V_SYNC, SXGA_V_BACK_PORCH, SXGA_V_FRONT_PORCH

+  },

+  { // Mode 4 : UXGA : 1600 x 1200 x 24 bpp

+      UXGA, UXGA_H_RES_PIXELS, UXGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, (UXGA_OSC_FREQUENCY/2),

+      UXGA_H_SYNC, UXGA_H_BACK_PORCH, UXGA_H_FRONT_PORCH,

+      UXGA_V_SYNC, UXGA_V_BACK_PORCH, UXGA_V_FRONT_PORCH

+  },

+  { // Mode 5 : HD : 1920 x 1080 x 24 bpp

+      HD, HD_H_RES_PIXELS, HD_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, (HD_OSC_FREQUENCY/2),

+      HD_H_SYNC, HD_H_BACK_PORCH, HD_H_FRONT_PORCH,

+      HD_V_SYNC, HD_V_BACK_PORCH, HD_V_FRONT_PORCH

+  },

+  { // Mode 6 : VGA : 640 x 480 x 16 bpp (565 Mode)

+      VGA, VGA_H_RES_PIXELS, VGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_16_565, VGA_OSC_FREQUENCY,

+      VGA_H_SYNC, VGA_H_BACK_PORCH, VGA_H_FRONT_PORCH,

+      VGA_V_SYNC, VGA_V_BACK_PORCH, VGA_V_FRONT_PORCH

+  },

+  { // Mode 7 : SVGA : 800 x 600 x 16 bpp (565 Mode)

+      SVGA, SVGA_H_RES_PIXELS, SVGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_16_565, SVGA_OSC_FREQUENCY,

+      SVGA_H_SYNC, SVGA_H_BACK_PORCH, SVGA_H_FRONT_PORCH,

+      SVGA_V_SYNC, SVGA_V_BACK_PORCH, SVGA_V_FRONT_PORCH

+  },

+  { // Mode 8 : XGA : 1024 x 768 x 16 bpp (565 Mode)

+      XGA, XGA_H_RES_PIXELS, XGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_16_565, XGA_OSC_FREQUENCY,

+      XGA_H_SYNC, XGA_H_BACK_PORCH, XGA_H_FRONT_PORCH,

+      XGA_V_SYNC, XGA_V_BACK_PORCH, XGA_V_FRONT_PORCH

+  },

+  { // Mode 9 : VGA : 640 x 480 x 15 bpp

+      VGA, VGA_H_RES_PIXELS, VGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_16_555, VGA_OSC_FREQUENCY,

+      VGA_H_SYNC, VGA_H_BACK_PORCH, VGA_H_FRONT_PORCH,

+      VGA_V_SYNC, VGA_V_BACK_PORCH, VGA_V_FRONT_PORCH

+  },

+  { // Mode 10 : SVGA : 800 x 600 x 15 bpp

+      SVGA, SVGA_H_RES_PIXELS, SVGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_16_555, SVGA_OSC_FREQUENCY,

+      SVGA_H_SYNC, SVGA_H_BACK_PORCH, SVGA_H_FRONT_PORCH,

+      SVGA_V_SYNC, SVGA_V_BACK_PORCH, SVGA_V_FRONT_PORCH

+  },

+  { // Mode 11 : XGA : 1024 x 768 x 15 bpp

+      XGA, XGA_H_RES_PIXELS, XGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_16_555, XGA_OSC_FREQUENCY,

+      XGA_H_SYNC, XGA_H_BACK_PORCH, XGA_H_FRONT_PORCH,

+      XGA_V_SYNC, XGA_V_BACK_PORCH, XGA_V_FRONT_PORCH

+  },

+  { // Mode 12 : XGA : 1024 x 768 x 15 bpp - All the timing info is derived from Linux Kernel Driver Settings

+      XGA, XGA_H_RES_PIXELS, XGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_16_555, 63500000,

+      XGA_H_SYNC, XGA_H_BACK_PORCH, XGA_H_FRONT_PORCH,

+      XGA_V_SYNC, XGA_V_BACK_PORCH, XGA_V_FRONT_PORCH

+  },

+  { // Mode 13 : VGA : 640 x 480 x 12 bpp (444 Mode)

+      VGA, VGA_H_RES_PIXELS, VGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_12_444, VGA_OSC_FREQUENCY,

+      VGA_H_SYNC, VGA_H_BACK_PORCH, VGA_H_FRONT_PORCH,

+      VGA_V_SYNC, VGA_V_BACK_PORCH, VGA_V_FRONT_PORCH

+  },

+  { // Mode 14 : SVGA : 800 x 600 x 12 bpp (444 Mode)

+      SVGA, SVGA_H_RES_PIXELS, SVGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_12_444, SVGA_OSC_FREQUENCY,

+      SVGA_H_SYNC, SVGA_H_BACK_PORCH, SVGA_H_FRONT_PORCH,

+      SVGA_V_SYNC, SVGA_V_BACK_PORCH, SVGA_V_FRONT_PORCH

+  },

+  { // Mode 15 : XGA : 1024 x 768 x 12 bpp (444 Mode)

+      XGA, XGA_H_RES_PIXELS, XGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_12_444, XGA_OSC_FREQUENCY,

+      XGA_H_SYNC, XGA_H_BACK_PORCH, XGA_H_FRONT_PORCH,

+      XGA_V_SYNC, XGA_V_BACK_PORCH, XGA_V_FRONT_PORCH

+  }

+};

+

+EFI_EDID_DISCOVERED_PROTOCOL  mEdidDiscovered = {

+  0,

+  NULL

+};

+

+EFI_EDID_ACTIVE_PROTOCOL      mEdidActive = {

+  0,

+  NULL

+};

+

+

+EFI_STATUS

+LcdPlatformInitializeDisplay (

+  IN EFI_HANDLE   Handle

+  )

+{

+  EFI_STATUS  Status;

+

+  // Set the FPGA multiplexer to select the video output from the motherboard or the daughterboard

+  Status = ArmPlatformSysConfigSet (SYS_CFG_MUXFPGA, PL111_CLCD_SITE);

+  if (!EFI_ERROR(Status)) {

+    // Install the EDID Protocols

+    Status = gBS->InstallMultipleProtocolInterfaces(

+      &Handle,

+      &gEfiEdidDiscoveredProtocolGuid,  &mEdidDiscovered,

+      &gEfiEdidActiveProtocolGuid,      &mEdidActive,

+      NULL

+    );

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+LcdPlatformGetVram (

+  OUT EFI_PHYSICAL_ADDRESS*  VramBaseAddress,

+  OUT UINTN*                 VramSize

+  )

+{

+  EFI_STATUS              Status;

+  EFI_CPU_ARCH_PROTOCOL  *Cpu;

+

+  Status = EFI_SUCCESS;

+

+  // Is it on the motherboard or on the daughterboard?

+  switch(PL111_CLCD_SITE) {

+

+  case ARM_VE_MOTHERBOARD_SITE:

+    *VramBaseAddress = (EFI_PHYSICAL_ADDRESS) PL111_CLCD_VRAM_MOTHERBOARD_BASE;

+    *VramSize = LCD_VRAM_SIZE;

+    break;

+

+  case ARM_VE_DAUGHTERBOARD_1_SITE:

+    *VramBaseAddress = (EFI_PHYSICAL_ADDRESS) LCD_VRAM_CORE_TILE_BASE;

+    *VramSize = LCD_VRAM_SIZE;

+

+    // Allocate the VRAM from the DRAM so that nobody else uses it.

+    Status = gBS->AllocatePages( AllocateAddress, EfiBootServicesData, EFI_SIZE_TO_PAGES(((UINTN)LCD_VRAM_SIZE)), VramBaseAddress);

+    if (EFI_ERROR(Status)) {

+      return Status;

+    }

+

+    // Ensure the Cpu architectural protocol is already installed

+    Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);

+    ASSERT_EFI_ERROR(Status);

+

+    // Mark the VRAM as un-cachable. The VRAM is inside the DRAM, which is cachable.

+    Status = Cpu->SetMemoryAttributes(Cpu, *VramBaseAddress, *VramSize, EFI_MEMORY_UC);

+    ASSERT_EFI_ERROR(Status);

+    if (EFI_ERROR(Status)) {

+      gBS->FreePool(VramBaseAddress);

+      return Status;

+    }

+    break;

+

+  default:

+    // Unsupported site

+    Status = EFI_UNSUPPORTED;

+    break;

+  }

+

+  return Status;

+}

+

+UINT32

+LcdPlatformGetMaxMode (

+  VOID

+  )

+{

+  // The following line will report correctly the total number of graphics modes

+  // supported by the PL111CLCD.

+  //return (sizeof(mResolutions) / sizeof(CLCD_RESOLUTION)) - 1;

+

+  // However, on some platforms it is desirable to ignore some graphics modes.

+  // This could be because the specific implementation of PL111 has certain limitations.

+

+  // Set the maximum mode allowed

+  return (PcdGet32(PcdPL111LcdMaxMode));

+}

+

+EFI_STATUS

+LcdPlatformSetMode (

+  IN UINT32                         ModeNumber

+  )

+{

+  EFI_STATUS            Status;

+  UINT32                LcdSite;

+  UINT32                OscillatorId;

+  SYS_CONFIG_FUNCTION   Function;

+  UINT32                SysId;

+

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  LcdSite = PL111_CLCD_SITE;

+

+  switch(LcdSite) {

+  case ARM_VE_MOTHERBOARD_SITE:

+    Function = SYS_CFG_OSC;

+    OscillatorId = PL111_CLCD_MOTHERBOARD_VIDEO_MODE_OSC_ID;

+    break;

+  case ARM_VE_DAUGHTERBOARD_1_SITE:

+    Function = SYS_CFG_OSC_SITE1;

+    OscillatorId = (UINT32)PcdGet32(PcdPL111LcdVideoModeOscId);

+    break;

+  default:

+    return EFI_UNSUPPORTED;

+  }

+

+  // Set the video mode oscillator

+  Status = ArmPlatformSysConfigSetDevice (Function, OscillatorId, mResolutions[ModeNumber].OscFreq);

+  if (EFI_ERROR(Status)) {

+    ASSERT_EFI_ERROR (Status);

+    return Status;

+  }

+

+  // The FVP foundation model does not have an LCD.

+  // On the FVP models the GIC variant in encoded in bits [15:12].

+  // Note: The DVI Mode is not modelled by RTSM or FVP models.

+  SysId = MmioRead32 (ARM_VE_SYS_ID_REG);

+  if (SysId != ARM_RTSM_SYS_ID) {

+    // Take out the FVP GIC variant to reduce the permutations.

+    SysId &= ~ARM_FVP_SYS_ID_VARIANT_MASK;

+    if (SysId != (ARM_FVP_BASE_SYS_ID & ~ARM_FVP_SYS_ID_VARIANT_MASK)) {

+      // Set the DVI into the new mode

+      Status = ArmPlatformSysConfigSet (SYS_CFG_DVIMODE, mResolutions[ModeNumber].Mode);

+      if (EFI_ERROR(Status)) {

+        ASSERT_EFI_ERROR (Status);

+        return Status;

+      }

+    }

+  }

+

+  // Set the multiplexer

+  Status = ArmPlatformSysConfigSet (SYS_CFG_MUXFPGA, LcdSite);

+  if (EFI_ERROR(Status)) {

+    ASSERT_EFI_ERROR (Status);

+    return Status;

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+LcdPlatformQueryMode (

+  IN  UINT32                                ModeNumber,

+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Info->Version = 0;

+  Info->HorizontalResolution = mResolutions[ModeNumber].HorizontalResolution;

+  Info->VerticalResolution = mResolutions[ModeNumber].VerticalResolution;

+  Info->PixelsPerScanLine = mResolutions[ModeNumber].HorizontalResolution;

+

+  switch (mResolutions[ModeNumber].Bpp) {

+    case LCD_BITS_PER_PIXEL_24:

+      Info->PixelFormat                   = PixelRedGreenBlueReserved8BitPerColor;

+      Info->PixelInformation.RedMask      = LCD_24BPP_RED_MASK;

+      Info->PixelInformation.GreenMask    = LCD_24BPP_GREEN_MASK;

+      Info->PixelInformation.BlueMask     = LCD_24BPP_BLUE_MASK;

+      Info->PixelInformation.ReservedMask = LCD_24BPP_RESERVED_MASK;

+      break;

+

+    case LCD_BITS_PER_PIXEL_16_555:

+    case LCD_BITS_PER_PIXEL_16_565:

+    case LCD_BITS_PER_PIXEL_12_444:

+    case LCD_BITS_PER_PIXEL_8:

+    case LCD_BITS_PER_PIXEL_4:

+    case LCD_BITS_PER_PIXEL_2:

+    case LCD_BITS_PER_PIXEL_1:

+    default:

+      // These are not supported

+      ASSERT(FALSE);

+      break;

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdPlatformGetTimings (

+  IN  UINT32                              ModeNumber,

+  OUT UINT32*                             HRes,

+  OUT UINT32*                             HSync,

+  OUT UINT32*                             HBackPorch,

+  OUT UINT32*                             HFrontPorch,

+  OUT UINT32*                             VRes,

+  OUT UINT32*                             VSync,

+  OUT UINT32*                             VBackPorch,

+  OUT UINT32*                             VFrontPorch

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *HRes           = mResolutions[ModeNumber].HorizontalResolution;

+  *HSync          = mResolutions[ModeNumber].HSync;

+  *HBackPorch     = mResolutions[ModeNumber].HBackPorch;

+  *HFrontPorch    = mResolutions[ModeNumber].HFrontPorch;

+  *VRes           = mResolutions[ModeNumber].VerticalResolution;

+  *VSync          = mResolutions[ModeNumber].VSync;

+  *VBackPorch     = mResolutions[ModeNumber].VBackPorch;

+  *VFrontPorch    = mResolutions[ModeNumber].VFrontPorch;

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdPlatformGetBpp (

+  IN  UINT32                              ModeNumber,

+  OUT LCD_BPP  *                          Bpp

+  )

+{

+  if (ModeNumber >= LcdPlatformGetMaxMode ()) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *Bpp = mResolutions[ModeNumber].Bpp;

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf
new file mode 100644
index 0000000..d1978e7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpressLib.inf
@@ -0,0 +1,43 @@
+#/** @file

+#

+#  Component description file for ArmVeGraphicsDxe module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PL111LcdArmVExpressLib

+  FILE_GUID                      = b7f06f20-496f-11e0-a8e8-0002a5d5c51b

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = LcdPlatformLib

+

+[Sources.common]

+  PL111LcdArmVExpress.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  ArmPlatformSysConfigLib

+

+[Protocols]

+  gEfiEdidDiscoveredProtocolGuid                # Produced

+  gEfiEdidActiveProtocolGuid                    # Produced

+

+[Pcd]

+  gArmVExpressTokenSpaceGuid.PcdPL111LcdMaxMode

+  gArmVExpressTokenSpaceGuid.PcdPL111LcdVideoModeOscId

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.c
new file mode 100644
index 0000000..bafb6f8
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.c
@@ -0,0 +1,88 @@
+/** @file

+  Template library implementation to support ResetSystem Runtime call.

+

+  Fill in the templates with what ever makes you system reset.

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>

+

+  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 <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/EfiResetSystemLib.h>

+#include <Library/ArmPlatformSysConfigLib.h>

+

+#include <ArmPlatform.h>

+

+/**

+  Resets the entire platform.

+

+  @param  ResetType             The type of reset to perform.

+  @param  ResetStatus           The status code for the reset.

+  @param  DataSize              The size, in bytes, of WatchdogData.

+  @param  ResetData             For a ResetType of EfiResetCold, EfiResetWarm, or

+                                EfiResetShutdown the data buffer starts with a Null-terminated

+                                Unicode string, optionally followed by additional binary data.

+

+**/

+EFI_STATUS

+EFIAPI

+LibResetSystem (

+  IN EFI_RESET_TYPE   ResetType,

+  IN EFI_STATUS       ResetStatus,

+  IN UINTN            DataSize,

+  IN CHAR16           *ResetData OPTIONAL

+  )

+{

+  switch (ResetType) {

+  case EfiResetPlatformSpecific:

+    // Map the platform specific reset as reboot

+  case EfiResetWarm:

+    // Map a warm reset into a cold reset

+  case EfiResetCold:

+    // Send the REBOOT function to the platform microcontroller

+    ArmPlatformSysConfigSet (SYS_CFG_REBOOT, 0);

+

+    // We should never be here

+    while(1);

+  case EfiResetShutdown:

+    // Send the SHUTDOWN function to the platform microcontroller

+    ArmPlatformSysConfigSet (SYS_CFG_SHUTDOWN, 0);

+

+    // We should never be here

+    while(1);

+  }

+

+  ASSERT(FALSE);

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Initialize any infrastructure required for LibResetSystem () to function.

+

+  @param  ImageHandle   The firmware allocated handle for the EFI image.

+  @param  SystemTable   A pointer to the EFI System Table.

+

+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.

+

+**/

+EFI_STATUS

+EFIAPI

+LibInitializeResetSystem (

+  IN EFI_HANDLE        ImageHandle,

+  IN EFI_SYSTEM_TABLE  *SystemTable

+  )

+{

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.inf
new file mode 100644
index 0000000..8c17ea8
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ResetSystemLib/ResetSystemLib.inf
@@ -0,0 +1,35 @@
+#/** @file

+# Reset System lib to make it easy to port new platforms

+#

+# Copyright (c) 2008, Apple Inc. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmVeResetSystemLib

+  FILE_GUID                      = 36885202-0854-4373-bfd2-95d229b44d44

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = EfiResetSystemLib

+

+[Sources.common]

+  ResetSystemLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  BaseLib

+  ArmPlatformSysConfigLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/LICENSE.TXT b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/LICENSE.TXT
new file mode 100644
index 0000000..e33cd4c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/LICENSE.TXT
@@ -0,0 +1,28 @@
+Copyright (c) 2011-2013 ARM Limited

+All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions are

+met:

+

+    * Redistributions of source code must retain the above copyright

+      notice, this list of conditions and the following disclaimer.

+    * Redistributions in binary form must reproduce the above copyright

+      notice, this list of conditions and the following disclaimer in

+      the documentation and/or other materials provided with the

+      distribution.

+    * Neither the name of ARM nor the names of its contributors may be

+      used to endorse or promote products derived from this software

+      without specific prior written permission.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS

+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED

+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A

+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED

+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR

+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF

+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/Makefile b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/Makefile
new file mode 100644
index 0000000..2ac8368
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/Makefile
@@ -0,0 +1,96 @@
+#

+# Makefile - build a UEFI boot image for booting from different exception levels.

+#

+# Copyright (C) 2011-2013 ARM Limited.

+# All rights reserved.

+#

+# Redistribution and use in source and binary forms, with or without

+# modification, are permitted provided that the following conditions are

+# met:

+#

+#     * Redistributions of source code must retain the above copyright

+#        notice, this list of conditions and the following disclaimer.

+#     * Redistributions in binary form must reproduce the above copyright

+#       notice, this list of conditions and the following disclaimer in

+#       the documentation and/or other materials provided with the

+#       distribution.

+#     * Neither the name of ARM nor the names of its contributors may be

+#       used to endorse or promote products derived from this software

+#       without specific prior written permission.

+#

+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS

+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED

+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A

+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED

+# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR

+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF

+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+#

+# This license can also be found in the LICENSE.TXT file.

+

+

+# VE

+PHYS_OFFSET	:= 0x80000000

+UART_BASE	:= 0x1c090000

+GIC_DIST_BASE	:= 0x2c001000

+GIC_CPU_BASE	:= 0x2c002000

+CNTFRQ		:= 0x01800000	# 24Mhz

+

+BOOTLOADER	:= boot.S

+LD_SCRIPT	:= model.lds.S

+IMAGE_1		:= uefi-bootstrap-el1.axf

+IMAGE_2		:= uefi-bootstrap-el2.axf

+IMAGE_3		:= uefi-bootstrap-el3.axf

+IMAGE_3F	:= uefi-bootstrap-el3-foundation.axf

+

+

+CROSS_COMPILE	?= aarch64-none-elf-

+CC		:= $(CROSS_COMPILE)gcc

+LD		:= $(CROSS_COMPILE)ld

+

+all: $(IMAGE_1) $(IMAGE_2) $(IMAGE_3) $(IMAGE_3F)

+

+clean:

+	rm -f *.axf *.o *.lds

+

+$(IMAGE_1): boot1.o model1.lds

+	$(LD) -o $@ --script=model1.lds

+

+$(IMAGE_2): boot2.o model2.lds

+	$(LD) -o $@ --script=model2.lds

+

+$(IMAGE_3): boot3.o model3.lds

+	$(LD) -o $@ --script=model3.lds

+

+$(IMAGE_3F): boot3f.o model3f.lds

+	$(LD) -o $@ --script=model3f.lds

+

+boot1.o: $(BOOTLOADER) Makefile

+	$(CC) $(CPPFLAGS) -DUART_BASE=$(UART_BASE) -DCNTFRQ=$(CNTFRQ) -DGIC_DIST_BASE=$(GIC_DIST_BASE) -DGIC_CPU_BASE=$(GIC_CPU_BASE) -DSTART_EL2=1 -DSTART_EL1=1 -c -o $@ $(BOOTLOADER)

+

+boot2.o: $(BOOTLOADER) Makefile

+	$(CC) $(CPPFLAGS) -DUART_BASE=$(UART_BASE) -DCNTFRQ=$(CNTFRQ) -DGIC_DIST_BASE=$(GIC_DIST_BASE) -DGIC_CPU_BASE=$(GIC_CPU_BASE) -DSTART_EL2=1 -c -o $@ $(BOOTLOADER)

+

+boot3.o: $(BOOTLOADER) Makefile

+	$(CC) $(CPPFLAGS) -DUART_BASE=$(UART_BASE) -DCNTFRQ=$(CNTFRQ) -DGIC_DIST_BASE=$(GIC_DIST_BASE) -DGIC_CPU_BASE=$(GIC_CPU_BASE) -c -o $@ $(BOOTLOADER)

+

+boot3f.o: $(BOOTLOADER) Makefile

+	$(CC) $(CPPFLAGS) -DUART_BASE=$(UART_BASE) -DCNTFRQ=$(CNTFRQ) -DGIC_DIST_BASE=$(GIC_DIST_BASE) -DGIC_CPU_BASE=$(GIC_CPU_BASE) -DFOUNDATION_MODEL=1 -c -o $@ $(BOOTLOADER)

+

+model1.lds: $(LD_SCRIPT) Makefile boot1.o

+	$(CC) $(CPPFLAGS) -DPHYS_OFFSET=$(PHYS_OFFSET) -DBOOT1 -E -P -C -o $@ $<

+

+model2.lds: $(LD_SCRIPT) Makefile boot2.o

+	$(CC) $(CPPFLAGS) -DPHYS_OFFSET=$(PHYS_OFFSET) -DBOOT2 -E -P -C -o $@ $<

+

+model3.lds: $(LD_SCRIPT) Makefile boot3.o

+	$(CC) $(CPPFLAGS) -DPHYS_OFFSET=$(PHYS_OFFSET) -DBOOT3 -E -P -C -o $@ $<

+

+model3f.lds: $(LD_SCRIPT) Makefile boot3f.o

+	$(CC) $(CPPFLAGS) -DPHYS_OFFSET=$(PHYS_OFFSET) -DBOOT3F -E -P -C -o $@ $<

+

+.PHONY: all clean

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/boot.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/boot.S
new file mode 100644
index 0000000..a4b0055
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/boot.S
@@ -0,0 +1,183 @@
+/*

+ * boot.S - simple register setup code for junping to a second stage bootloader

+ *

+ * Copyright (C) 2011-2013 ARM Limited.

+ * All rights reserved.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions are

+ * met:

+ *

+ *     * Redistributions of source code must retain the above copyright

+ *        notice, this list of conditions and the following disclaimer.

+ *     * Redistributions in binary form must reproduce the above copyright

+ *       notice, this list of conditions and the following disclaimer in

+ *       the documentation and/or other materials provided with the

+ *       distribution.

+ *     * Neither the name of ARM nor the names of its contributors may be

+ *       used to endorse or promote products derived from this software

+ *       without specific prior written permission.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS

+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED

+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A

+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED

+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR

+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF

+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ *

+ * This license can also be found in the LICENSE.TXT file.

+ */

+

+	.text

+

+	.globl	_start

+

+.set LED_ADDR, 0x1c010008

+

+_start:

+	/*

+	 * EL3 initialisation

+	 */

+

+	// Set LED to show progress.

+	ldr	x1, =LED_ADDR

+	mov	w0, #0x1

+	str	w0, [x1]

+        dsb	sy

+

+#if defined START_EL2

+

+	mrs	x0, CurrentEL

+	cmp	x0, #0xc			// EL3?

+	b.ne	start_ns			// skip EL3 initialisation

+

+	mov	x0, #0x30			// RES1

+	orr	x0, x0, #(1 << 0)		// Non-secure bit

+	orr	x0, x0, #(1 << 8)		// HVC enable

+	orr	x0, x0, #(1 << 10)		// 64-bit EL2

+	msr	scr_el3, x0

+

+	msr	cptr_el3, xzr			// Disable copro. traps to EL3

+

+	ldr	x0, =CNTFRQ

+	msr	cntfrq_el0, x0

+

+	/*

+	 * Check for the primary CPU to avoid a race on the distributor

+	 * registers.

+	 */

+	mrs	x0, mpidr_el1

+	tst	x0, #15

+	b.ne	1f				// secondary CPU

+

+	ldr	x1, =GIC_DIST_BASE		// GICD_CTLR

+	mov	w0, #3				// EnableGrp0 | EnableGrp1

+	str	w0, [x1]

+

+1:	ldr	x1, =GIC_DIST_BASE + 0x80	// GICD_IGROUPR

+	mov	w0, #~0				// Grp1 interrupts

+	str	w0, [x1], #4

+	b.ne	2f				// Only local interrupts for secondary CPUs

+	str	w0, [x1], #4

+	str	w0, [x1], #4

+

+2:	ldr	x1, =GIC_CPU_BASE		// GICC_CTLR

+	ldr	w0, [x1]

+	orr	w0, w0, #3			// EnableGrp0 | EnableGrp1

+	str	w0, [x1]

+

+	mov	w0, #1 << 7			// allow NS access to GICC_PMR

+	str	w0, [x1, #4]			// GICC_PMR

+

+	msr	sctlr_el2, xzr

+

+#if defined START_EL1

+

+	/* Now setup our EL1. Controlled by EL2 config on Model */

+	mrs	x0, hcr_el2			// Read EL2 Hypervisor configuration Register

+	orr	x0, x0, #(1 << 31)		// Set EL1 to be 64bit

+

+	// Send all interrupts to their respective Exception levels for EL2

+	bic	x0, x0, #(1 << 3)		// Disable virtual FIQ

+	bic	x0, x0, #(1 << 4)		// Disable virtual IRQ

+	bic	x0, x0, #(1 << 5)		// Disable virtual SError and Abort

+	msr	hcr_el2, x0			// Write back our settings

+

+	/*

+	 * Enable architected timer access

+	 */

+	mrs	x0, cnthctl_el2

+	orr	x0, x0, #3			// Enable EL1 access to timers

+	msr	cnthctl_el2, x0

+

+	mrs	x0, cntkctl_el1

+	orr	x0, x0, #3			// EL0 access to counters

+	msr	cntkctl_el1, x0

+

+	/* Set ID regs */

+	mrs	x0, midr_el1

+	mrs	x1, mpidr_el1

+	msr	vpidr_el2, x0

+	msr	vmpidr_el2, x1

+

+	/* Coprocessor traps. */

+	mov	x0, #0x33ff

+	msr	cptr_el2, x0			// Disable copro. traps to EL2

+

+	msr	hstr_el2, xzr			// Disable CP15 traps to EL2

+

+#endif // START_EL1

+

+        /* Configure UART. Primary CPU only */

+	mrs     x4, mpidr_el1

+	tst     x4, #15

+	b.ne    1f

+

+	/*

+	 * UART initialisation (38400 8N1)

+	 */

+	ldr     x4, =UART_BASE                  // UART base

+	mov     w5, #0x10                       // ibrd

+	str     w5, [x4, #0x24]

+	mov     w5, #0xc300

+	orr     w5, w5, #0x0001                 // cr

+	str     w5, [x4, #0x30]

+

+	/*

+	 * Prepare the switch to the EL2_SP2 mode from EL3

+	 */

+1:	ldr	x0, =start_ns			// Return after mode switch

+#if defined START_EL1

+	mov	x1, #0x3c5			// EL1_SP1 | D | A | I | F

+#else

+	mov	x1, #0x3c9			// EL2_SP2 | D | A | I | F

+#endif

+

+	msr	elr_el3, x0

+	msr	spsr_el3, x1

+	eret

+

+#endif // START_EL2

+

+

+start_ns:

+

+/*

+ * We do not have NOR flash on the Foundation model. So run UEFI from RAM.

+ * On the full model we use the NOR FLASH to store UEFI, so start there.

+ */

+#if defined FOUNDATION_MODEL

+	mov	x0, #0xa0000000

+#else

+	mov	x0, #0x0

+#endif

+	br	x0

+

+	.ltorg

+

+	.org	0x200

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/model.lds.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/model.lds.S
new file mode 100644
index 0000000..d963aec
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/model.lds.S
@@ -0,0 +1,77 @@
+/*

+ * model.lds.S - simple linker script for stand-alone Linux booting

+ *

+ * Copyright (C) 2011, 2012 ARM Limited.

+ * All rights reserved.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions are

+ * met:

+ *

+ *     * Redistributions of source code must retain the above copyright

+ *        notice, this list of conditions and the following disclaimer.

+ *     * Redistributions in binary form must reproduce the above copyright

+ *       notice, this list of conditions and the following disclaimer in

+ *       the documentation and/or other materials provided with the

+ *       distribution.

+ *     * Neither the name of ARM nor the names of its contributors may be

+ *       used to endorse or promote products derived from this software

+ *       without specific prior written permission.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS

+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED

+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A

+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED

+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR

+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF

+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ *

+ * This license can also be found in the LICENSE.TXT file.

+ */

+

+OUTPUT_FORMAT("elf64-littleaarch64")

+OUTPUT_ARCH(aarch64)

+TARGET(binary)

+

+#ifdef BOOT1

+INPUT(./boot1.o)

+#endif

+

+#ifdef BOOT2

+INPUT(./boot2.o)

+#endif

+

+#ifdef BOOT3

+INPUT(./boot3.o)

+#endif

+

+#ifdef BOOT3F

+INPUT(./boot3f.o)

+#endif

+

+SECTIONS

+{

+  . = PHYS_OFFSET;

+#ifdef BOOT1

+  .text : { boot1.o }

+#endif

+

+#ifdef BOOT2

+  .text : { boot2.o }

+#endif

+

+#ifdef BOOT3

+  .text : { boot3.o }

+#endif

+

+#ifdef BOOT3F

+  .text : { boot3f.o }

+#endif

+

+  .data : { *(.data) }

+  .bss : { *(.bss) }

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/readme.html b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/readme.html
new file mode 100644
index 0000000..5627285
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/readme.html
@@ -0,0 +1,88 @@
+<h1>AArch64 UEFI bootstraps</h1>

+

+<p>Copyright (c) 2011-2013 ARM Limited. All rights reserved.

+See the <code>LICENSE.TXT</code> file for more information.</p>

+

+<p>Contents:</p>

+

+<ul>

+<li>Introduction</li>

+<li>Build</li>

+<li>Use on ARMv8 RTSM and FVP models</li>

+<li>Use on ARMv8 Foundation model</li>

+</ul>

+

+<h2>Introduction</h2>

+

+<p>A bootstrap can be used to change the model state, like the Exception

+Level (EL), before executing the UEFI binary.</p>

+

+<p>For the ARMv8 RTSM and FVP models this can be used to show/test the UEFI binary

+starting at different exception levels. The ARMv8 models start at EL3 by

+default.</p>

+

+<p>In the case of the Foundation model a bootstrap is required to jump to the

+UEFI binary as loaded in RAM. This is required as the Foundation model cannot

+load and execute UEFI binaries directly. The Foundation model can only load and

+execute ELF binaries.</p>

+

+<h2>Build</h2>

+

+<p>Build the bootstraps using a AArch64 GCC cross-compiler. By default the

+<code>Makefile</code> is configured to assume a GCC bare-metal toolchain:</p>

+

+<pre><code>PATH=$PATH:&lt;path/to/baremetal-tools/bin/&gt; make clean

+PATH=$PATH:&lt;path/to/baremetal-tools/bin/&gt; make

+</code></pre>

+

+<p>To build the bootstraps with a Linux GCC toolchain use the following

+commands:</p>

+

+<pre><code>PATH=$PATH:&lt;path/to/aarch64-linux-gnu-tools/bin/&gt; make clean

+PATH=$PATH:&lt;path/to/aarch64-linux-gnu-tools/bin/&gt; CROSS_COMPILE=&lt;gcc-prefix&gt; make

+</code></pre>

+

+<p>The <code>gcc-prefix</code> depends on the specific toolchain distribution used. It can be

+"aarch64-linux-gnu-" for example.</p>

+

+<p>This will result in four <code>axf</code> files:</p>

+

+<ul>

+<li><p>uefi-bootstrap-el3 : The bootstrap jumps to the UEFI code in FLASH without

+                 changing anything.</p></li>

+<li><p>uefi-bootstrap-el2 : Setup EL3 and switch the model to EL2 before jumping to the

+                 UEFI code in FLASH.</p></li>

+<li><p>uefi-bootstrap-el1 : Setup EL3 and prepare to run at non-secure EL1. Switch to

+                 non-secure EL1 and run the UEFI code in FLASH.</p></li>

+<li><p>uefi-bootstrap-el3-foundation : The bootstrap jumps to the UEFI code in RAM

+                 without changing anything. Only to be used with the

+                 Foundation model. The Foundation model does not have

+                 non-secure memory at address <code>0x0</code> and thus the UEFI image

+                 should be pre-loaded into non-secure RAM at address

+                 <code>0xA0000000</code>.</p></li>

+</ul>

+

+<h2>Use on ARMv8 RTSM and FVP models</h2>

+

+<p>Add the '-a' option to the model start script and point to the required

+bootstrap:</p>

+

+<pre><code>&lt; ... model start script as described in top-level readme file ... &gt;

+ -a &lt;path/to/bootstrap-binary-file&gt;

+</code></pre>

+

+<p>NOTE: The Foundation model bootstrap should not be used with these models.</p>

+

+<h2>Use on ARMv8 Foundation model</h2>

+

+<p>The Foundation model takes an option for an ELF file to be loaded as well as an

+option to load a binary data blob into RAM. This can be used to run UEFI in the

+following manner:</p>

+

+<pre><code>&lt;PATH_TO_INSTALLED_FOUNDATION_MODEL&gt;/Foundation_v8 --cores=2 --visualization

+  --image=uefi-bootstrap-el3-foundation.axf --nsdata=RTSM_VE_FOUNDATIONV8_EFI.fd@0xA0000000

+</code></pre>

+

+<p>NOTE: The RTSM version of the bootstraps and UEFI image will not work as

+      expected on the Foundation model. Foundation model specific versions

+      should be used.</p>

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/readme.txt b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/readme.txt
new file mode 100644
index 0000000..24a1bbe
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVExpressPkg/Scripts/uefi-aarch64-bootstrap/readme.txt
@@ -0,0 +1,92 @@
+AArch64 UEFI bootstraps

+=======================

+

+Copyright (c) 2011-2013 ARM Limited. All rights reserved.

+See the `LICENSE.TXT` file for more information.

+

+Contents:

+

+* Introduction

+* Build

+* Use on ARMv8 RTSM and FVP models

+* Use on ARMv8 Foundation model

+

+

+Introduction

+------------

+

+A bootstrap can be used to change the model state, like the Exception

+Level (EL), before executing the UEFI binary.

+

+For the ARMv8 RTSM and FVP models this can be used to show/test the UEFI binary

+starting at different exception levels. The ARMv8 models start at EL3 by

+default.

+

+In the case of the Foundation model a bootstrap is required to jump to the

+UEFI binary as loaded in RAM. This is required as the Foundation model cannot

+load and execute UEFI binaries directly. The Foundation model can only load and

+execute ELF binaries.

+

+

+Build

+-----

+

+Build the bootstraps using a AArch64 GCC cross-compiler. By default the

+`Makefile` is configured to assume a GCC bare-metal toolchain:

+

+    PATH=$PATH:<path/to/baremetal-tools/bin/> make clean

+    PATH=$PATH:<path/to/baremetal-tools/bin/> make

+

+To build the bootstraps with a Linux GCC toolchain use the following

+commands:

+

+    PATH=$PATH:<path/to/aarch64-linux-gnu-tools/bin/> make clean

+    PATH=$PATH:<path/to/aarch64-linux-gnu-tools/bin/> CROSS_COMPILE=<gcc-prefix> make

+

+The `gcc-prefix` depends on the specific toolchain distribution used. It can be

+"aarch64-linux-gnu-" for example.

+

+This will result in four `axf` files:

+

+* uefi-bootstrap-el3 : The bootstrap jumps to the UEFI code in FLASH without

+                     changing anything.

+

+* uefi-bootstrap-el2 : Setup EL3 and switch the model to EL2 before jumping to the

+                     UEFI code in FLASH.

+

+* uefi-bootstrap-el1 : Setup EL3 and prepare to run at non-secure EL1. Switch to

+                     non-secure EL1 and run the UEFI code in FLASH.

+

+* uefi-bootstrap-el3-foundation : The bootstrap jumps to the UEFI code in RAM

+                     without changing anything. Only to be used with the

+                     Foundation model. The Foundation model does not have

+                     non-secure memory at address `0x0` and thus the UEFI image

+                     should be pre-loaded into non-secure RAM at address

+                     `0xA0000000`.

+

+

+Use on ARMv8 RTSM and FVP models

+--------------------------------

+

+Add the '-a' option to the model start script and point to the required

+bootstrap:

+

+    < ... model start script as described in top-level readme file ... >

+     -a <path/to/bootstrap-binary-file>

+

+NOTE: The Foundation model bootstrap should not be used with these models.

+

+

+Use on ARMv8 Foundation model

+-----------------------------

+

+The Foundation model takes an option for an ELF file to be loaded as well as an

+option to load a binary data blob into RAM. This can be used to run UEFI in the

+following manner:

+

+    <PATH_TO_INSTALLED_FOUNDATION_MODEL>/Foundation_v8 --cores=2 --visualization

+      --image=uefi-bootstrap-el3-foundation.axf --nsdata=RTSM_VE_FOUNDATIONV8_EFI.fd@0xA0000000

+

+NOTE: The RTSM version of the bootstraps and UEFI image will not work as

+      expected on the Foundation model. Foundation model specific versions

+      should be used.

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
new file mode 100644
index 0000000..f17cd2f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
@@ -0,0 +1,327 @@
+#

+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.

+#  Copyright (c) 2014, 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.

+#

+#

+

+[LibraryClasses.common]

+!if $(TARGET) == RELEASE

+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf

+!else

+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

+  UncachedMemoryAllocationLib|ArmPkg/Library/DebugUncachedMemoryAllocationLib/DebugUncachedMemoryAllocationLib.inf

+!endif

+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf

+

+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf

+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf

+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf

+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf

+

+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf

+  HobLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/ArmVirtualizationDxeHobLib.inf

+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf

+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf

+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf

+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf

+

+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf

+  OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf

+

+  #

+  # Allow dynamic PCDs

+  #

+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

+

+  # 1/123 faster than Stm or Vstm version

+  #BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf

+  BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf

+

+  # Networking Requirements

+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf

+  DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf

+  UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf

+  IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf

+

+  # ARM Architectural Libraries

+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf

+  CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf

+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf

+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf

+  ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf

+  ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf

+  ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf

+  ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf

+  ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf

+

+  PlatformPeiLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf

+  EfiResetSystemLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPsciResetSystemLib/ArmVirtualizationPsciResetSystemLib.inf

+

+  # ARM PL031 RTC Driver

+  RealTimeClockLib|ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf

+  # ARM PL011 UART Driver

+  PL011UartLib|ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf

+  SerialPortLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf

+  SerialPortExtLib|EmbeddedPkg/Library/SerialPortExtLibNull/SerialPortExtLibNull.inf

+

+  #

+  # Uncomment (and comment out the next line) For RealView Debugger. The Standard IO window

+  # in the debugger will show load and unload commands for symbols. You can cut and paste this

+  # into the command window to load symbols. We should be able to use a script to do this, but

+  # the version of RVD I have does not support scripts accessing system memory.

+  #

+  #PeCoffExtraActionLib|ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf

+  PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf

+  #PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf

+

+  DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf

+  DebugAgentTimerLib|EmbeddedPkg/Library/DebugAgentTimerLibNull/DebugAgentTimerLibNull.inf

+

+  # BDS Libraries

+  BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf

+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf

+

+[LibraryClasses.common.SEC]

+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

+  ArmPlatformSecExtraActionLib|ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf

+

+  DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf

+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf

+  SerialPortLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.inf

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+

+[LibraryClasses.common.PEI_CORE]

+  PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+  SerialPortLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.inf

+

+[LibraryClasses.common.PEIM]

+  PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf

+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf

+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf

+  PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf

+  ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf

+  OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf

+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf

+  PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf

+

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  PeiServicesTablePointerLib|ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf

+  SerialPortLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.inf

+

+[LibraryClasses.common.DXE_CORE]

+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf

+  MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf

+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf

+

+[LibraryClasses.common.DXE_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf

+

+[LibraryClasses.common.UEFI_APPLICATION]

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

+

+[LibraryClasses.common.UEFI_DRIVER]

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf

+  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+

+[LibraryClasses.common.DXE_RUNTIME_DRIVER]

+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf

+

+[LibraryClasses.ARM]

+  #

+  # It is not possible to prevent the ARM compiler for generic intrinsic functions.

+  # This library provides the instrinsic functions generate by a given compiler.

+  # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.

+  #

+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

+

+  # Add support for GCC stack protector

+  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf

+

+[LibraryClasses.AARCH64]

+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf

+

+

+[BuildOptions]

+  RVCT:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG

+

+  GCC:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE

+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE

+

+  #

+  # Control what commands are supported from the UI

+  # Turn these on and off to add features or save size

+  #

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE

+

+  # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress

+  gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE

+

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE

+

+[PcdsFixedAtBuild.common]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"ARM Virtualization Platform"

+

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000

+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000

+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF

+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1

+  gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0

+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320

+

+  # DEBUG_ASSERT_ENABLED       0x01

+  # DEBUG_PRINT_ENABLED        0x02

+  # DEBUG_CODE_ENABLED         0x04

+  # CLEAR_MEMORY_ENABLED       0x08

+  # ASSERT_BREAKPOINT_ENABLED  0x10

+  # ASSERT_DEADLOOP_ENABLED    0x20

+!if $(TARGET) == RELEASE

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x21

+!else

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2f

+!endif

+

+  #  DEBUG_INIT      0x00000001  // Initialization

+  #  DEBUG_WARN      0x00000002  // Warnings

+  #  DEBUG_LOAD      0x00000004  // Load events

+  #  DEBUG_FS        0x00000008  // EFI File system

+  #  DEBUG_POOL      0x00000010  // Alloc & Free's

+  #  DEBUG_PAGE      0x00000020  // Alloc & Free's

+  #  DEBUG_INFO      0x00000040  // Verbose

+  #  DEBUG_DISPATCH  0x00000080  // PEI/DXE Dispatchers

+  #  DEBUG_VARIABLE  0x00000100  // Variable

+  #  DEBUG_BM        0x00000400  // Boot Manager

+  #  DEBUG_BLKIO     0x00001000  // BlkIo Driver

+  #  DEBUG_NET       0x00004000  // SNI Driver

+  #  DEBUG_UNDI      0x00010000  // UNDI Driver

+  #  DEBUG_LOADFILE  0x00020000  // UNDI Driver

+  #  DEBUG_EVENT     0x00080000  // Event messages

+  #  DEBUG_GCD       0x00100000  // Global Coherency Database changes

+  #  DEBUG_CACHE     0x00200000  // Memory range cachability changes

+  #  DEBUG_ERROR     0x80000000  // Error

+  # gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F

+

+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07

+

+  #

+  # Optional feature to help prevent EFI memory map fragments

+  # Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob

+  # Values are in EFI Pages (4K). DXE Core will make sure that

+  # at least this much of each type of memory can be allocated

+  # from a single memory range. This way you only end up with

+  # maximum of two fragements for each type in the memory map

+  # (the memory used, and the free memory that was prereserved

+  # but not used).

+  #

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|50

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|20

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|20000

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|20

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000000000000

+

+[Components.common]

+  #

+  # Networking stack

+  #

+  MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec
new file mode 100644
index 0000000..9941154
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec
@@ -0,0 +1,58 @@
+#/** @file

+#

+#  Copyright (c) 2014, 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              = 0x00010005

+  PACKAGE_NAME                   = ArmVirtualizationPkg

+  PACKAGE_GUID                   = A0B31216-508E-4025-BEAB-56D836C66F0A

+  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]

+  gArmVirtualizationTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }

+  gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }

+

+[PcdsFixedAtBuild]

+  #

+  # This is the physical address where the device tree is expected to be stored

+  # upon first entry into UEFI. This needs to be a FixedAtBuild PCD, so that we

+  # can do a first pass over the device tree in the SEC phase to discover the

+  # UART base address.

+  #

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x0|UINT64|0x00000001

+

+[PcdsDynamic, PcdsFixedAtBuild]

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0|UINT64|0x00000002

+

+  #

+  # ARM PSCI function invocations can be done either through hypervisor

+  # calls (HVC) or secure monitor calls (SMC).

+  # PcdArmPsciMethod == 1 : use HVC

+  # PcdArmPsciMethod == 2 : use SMC

+  #

+  gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod|0|UINT32|0x00000003

+

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress|0x0|UINT64|0x00000004

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress|0x0|UINT64|0x00000005

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
new file mode 100644
index 0000000..32c8deb
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.dsc
@@ -0,0 +1,288 @@
+#

+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.

+#  Copyright (c) 2014, 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 Section - statements that will be processed to create a Makefile.

+#

+################################################################################

+[Defines]

+  PLATFORM_NAME                  = ArmVirtualizationQemu

+  PLATFORM_GUID                  = 37d7e986-f7e9-45c2-8067-e371421a626c

+  PLATFORM_VERSION               = 0.1

+  DSC_SPECIFICATION              = 0x00010005

+  OUTPUT_DIRECTORY               = Build/ArmVirtualizationQemu-$(ARCH)

+  SUPPORTED_ARCHITECTURES        = AARCH64|ARM

+  BUILD_TARGETS                  = DEBUG|RELEASE

+  SKUID_IDENTIFIER               = DEFAULT

+  FLASH_DEFINITION               = ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.fdf

+

+!include ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc

+

+[LibraryClasses.AARCH64]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf

+

+[LibraryClasses.ARM]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf

+  ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexA15Lib/ArmCortexA15Lib.inf

+

+[LibraryClasses.common]

+  # Virtio Support

+  VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

+  VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf

+  QemuFwCfgLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf

+

+  ArmPlatformLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf

+  ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf

+

+  TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf

+

+!ifdef INTEL_BDS

+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf

+  GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf

+  PlatformBdsLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf

+  CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf

+  QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf

+!endif

+

+[LibraryClasses.common.UEFI_DRIVER]

+  UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf

+

+[LibraryClasses.AARCH64.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/AArch64/AArch64LibSec.inf

+

+[LibraryClasses.ARM.SEC]

+  ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibSec.inf

+

+[BuildOptions]

+  RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include

+  GCC:*_*_ARM_PLATFORM_FLAGS == -mcpu=cortex-a15 -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include

+  *_*_AARCH64_PLATFORM_FLAGS == -I$(WORKSPACE)/ArmPlatformPkg/ArmVirtualizationPkg/Include

+

+

+################################################################################

+#

+# Pcd Section - list of all EDK II PCD Entries defined by this Platform

+#

+################################################################################

+

+[PcdsFeatureFlag.common]

+  gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|FALSE

+  gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|TRUE

+

+  ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.

+  #  It could be set FALSE to save size.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE

+

+[PcdsFixedAtBuild.common]

+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F

+

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"QEMU"

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount|1

+!if $(ARCH) == AARCH64

+  gArmTokenSpaceGuid.PcdVFPEnabled|1

+!endif

+

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x4007c000

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000

+

+  # Size of the region used by UEFI in permanent memory (Reserved 64MB)

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000

+

+  #

+  # ARM Pcds

+  #

+  gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000

+

+  ## Trustzone enable (to make the transition from EL3 to EL2 in ArmPlatformPkg/Sec)

+  gArmTokenSpaceGuid.PcdTrustzoneSupport|FALSE

+

+  #

+  # ARM PrimeCell

+  #

+

+  ## PL011 - Serial Terminal

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|38400

+

+  #

+  # ARM OS Loader

+  #

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"Linux (EFI stub) on virtio31:hd0:part0"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000)/HD(1,MBR,0x00000000,0x3F,0x19FC0)/Image"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/vda2 console=ttyAMA0 earlycon uefi_debug"

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType|0

+

+  # Use the serial console (ConIn & ConOut) and the Graphic driver (ConOut)

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(38400,8,N,1)/VenVt100()"

+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut|3

+

+  #

+  # ARM Virtual Architectural Timer -- fetch frequency from QEMU (TCG) or KVM

+  #

+  gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0

+

+  #

+  # NV Storage PCDs. Use base of 0x04000000 for NOR1

+  #

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x04000000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00040000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x04040000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x00040000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x04080000

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00040000

+

+  # System Memory Base -- fixed at 0x4000_0000

+  gArmTokenSpaceGuid.PcdSystemMemoryBase|0x40000000

+

+  # initial location of the device tree blob passed by QEMU -- base of DRAM

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress|0x40000000

+

+!ifdef INTEL_BDS

+  gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE

+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 }

+!endif

+

+[PcdsDynamicDefault.common]

+  # System Memory Size -- 1 MB initially, actual size will be fetched from DT

+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x00100000

+

+  # location of the device tree blob passed by QEMU

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x0

+

+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0

+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0

+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0

+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0x0

+

+  #

+  # ARM General Interrupt Controller

+  #

+  gArmTokenSpaceGuid.PcdGicDistributorBase|0x0

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x0

+

+  ## PL031 RealTimeClock

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase|0x0

+

+  gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod|0

+

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress|0x0

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress|0x0

+

+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3

+

+################################################################################

+#

+# Components Section - list of all EDK II Modules needed by this Platform

+#

+################################################################################

+[Components.common]

+  #

+  # PEI Phase modules

+  #

+  ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf {

+    <LibraryClasses>

+      ArmPlatformGlobalVariableLib|ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf

+  }

+  MdeModulePkg/Core/Pei/PeiMain.inf

+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  ArmPkg/Drivers/CpuPei/CpuPei.inf

+

+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf {

+    <LibraryClasses>

+      NULL|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

+  }

+

+  #

+  # DXE

+  #

+  MdeModulePkg/Core/Dxe/DxeMain.inf {

+    <LibraryClasses>

+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf

+  }

+  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf

+

+  #

+  # Architectural Protocols

+  #

+  ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+

+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf {

+    <LibraryClasses>

+    NorFlashPlatformLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf

+  }

+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+

+  #

+  # Platform Driver

+  #

+  ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf

+  OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+  OvmfPkg/VirtioScsiDxe/VirtioScsi.inf

+  OvmfPkg/VirtioNetDxe/VirtioNet.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Bds

+  #

+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+!ifdef INTEL_BDS

+  MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf

+  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf

+  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf

+!else

+  ArmPlatformPkg/Bds/Bds.inf

+!endif

+

+  #

+  # SCSI Bus and Disk Driver

+  #

+  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf

+  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf

+

+  #

+  # ACPI Support

+  #

+  MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf

+  OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.fdf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.fdf
new file mode 100644
index 0000000..c90a784
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationQemu.fdf
@@ -0,0 +1,345 @@
+#

+#  Copyright (c) 2011, 2013, ARM Limited. All rights reserved.

+#  Copyright (c) 2014, 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.

+#

+

+################################################################################

+#

+# FD Section

+# The [FD] Section is made up of the definition statements and a

+# description of what goes into  the Flash Device Image.  Each FD section

+# defines one flash "device" image.  A flash device image may be one of

+# the following: Removable media bootable image (like a boot floppy

+# image,) an Option ROM image (that would be "flashed" into an add-in

+# card,) a System "Flash"  image (that would be burned into a system's

+# flash) or an Update ("Capsule") image that will be used to update and

+# existing system flash.

+#

+################################################################################

+

+[FD.QEMU_EFI]

+BaseAddress   = 0x00000000|gArmTokenSpaceGuid.PcdFdBaseAddress  # QEMU assigns 0 - 0x8000000 for a BootROM

+Size          = 0x00200000|gArmTokenSpaceGuid.PcdFdSize         # The size in bytes of the FLASH Device

+ErasePolarity = 1

+

+# This one is tricky, it must be: BlockSize * NumBlocks = Size

+BlockSize     = 0x00001000

+NumBlocks     = 0x200

+

+################################################################################

+#

+# Following are lists of FD Region layout which correspond to the locations of different

+# images within the flash device.

+#

+# Regions must be defined in ascending order and may not overlap.

+#

+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by

+# the pipe "|" character, followed by the size of the region, also in hex with the leading

+# "0x" characters. Like:

+# Offset|Size

+# PcdOffsetCName|PcdSizeCName

+# RegionType <FV, DATA, or FILE>

+#

+################################################################################

+

+#

+# UEFI has trouble dealing with FVs that reside at physical address 0x0.

+# So instead, put a hardcoded 'jump to 0x1000' at offset 0x0, and put the

+# real FV at offset 0x1000

+#

+0x00000000|0x00001000

+DATA = {

+!if $(ARCH) == AARCH64

+  0x00, 0x04, 0x00, 0x14   # 'b 0x1000' in AArch64 ASM

+!else

+  0xfe, 0x03, 0x00, 0xea   # 'b 0x1000' in AArch32 ASM

+!endif

+}

+

+0x00001000|0x001ff000

+gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize

+FV = FVMAIN_COMPACT

+

+

+################################################################################

+#

+# FV Section

+#

+# [FV] section is used to define what components or modules are placed within a flash

+# device file.  This section also defines order the components and modules are positioned

+# within the image.  The [FV] section consists of define statements, set statements and

+# module statements.

+#

+################################################################################

+

+[FV.FvMain]

+BlockSize          = 0x40

+NumBlocks          = 0         # This FV gets compressed so make it just big enough

+FvAlignment        = 16        # FV alignment and FV attributes setting.

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  APRIORI DXE {

+    INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf

+    INF ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf

+  }

+  INF MdeModulePkg/Core/Dxe/DxeMain.inf

+  INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf

+  INF ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf

+

+  #

+  # PI DXE Drivers producing Architectural Protocols (EFI Services)

+  #

+  INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf

+  INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

+  INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

+  INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf

+  INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf

+  INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

+  INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf

+  INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

+  INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf

+  INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf

+

+  #

+  # Multiple Console IO support

+  #

+  INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf

+  INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf

+  INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf

+  INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf

+  INF EmbeddedPkg/SerialDxe/SerialDxe.inf

+

+  INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf

+  INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf

+  INF ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf

+  INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

+

+  #

+  # FAT filesystem + GPT/MBR partitioning

+  #

+  INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf

+  INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf

+  INF FatBinPkg/EnhancedFatDxe/Fat.inf

+  INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf

+

+  #

+  # Platform Driver

+  #

+  INF OvmfPkg/VirtioBlkDxe/VirtioBlk.inf

+  INF OvmfPkg/VirtioNetDxe/VirtioNet.inf

+  INF OvmfPkg/VirtioScsiDxe/VirtioScsi.inf

+

+  #

+  # UEFI application (Shell Embedded Boot Loader)

+  #

+  INF ShellBinPkg/UefiShell/UefiShell.inf

+

+  #

+  # Bds

+  #

+  INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf

+!ifdef INTEL_BDS

+  INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf

+  INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf

+  INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf

+!else

+  INF ArmPlatformPkg/Bds/Bds.inf

+!endif

+

+  #

+  # Networking stack

+  #

+  INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf

+  INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf

+  INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf

+  INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf

+  INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf

+  INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

+  INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

+  INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf

+

+  #

+  # SCSI Bus and Disk Driver

+  #

+  INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf

+  INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf

+

+  #

+  # ACPI Support

+  #

+  INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf

+  INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf

+

+[FV.FVMAIN_COMPACT]

+FvAlignment        = 16

+ERASE_POLARITY     = 1

+MEMORY_MAPPED      = TRUE

+STICKY_WRITE       = TRUE

+LOCK_CAP           = TRUE

+LOCK_STATUS        = TRUE

+WRITE_DISABLED_CAP = TRUE

+WRITE_ENABLED_CAP  = TRUE

+WRITE_STATUS       = TRUE

+WRITE_LOCK_CAP     = TRUE

+WRITE_LOCK_STATUS  = TRUE

+READ_DISABLED_CAP  = TRUE

+READ_ENABLED_CAP   = TRUE

+READ_STATUS        = TRUE

+READ_LOCK_CAP      = TRUE

+READ_LOCK_STATUS   = TRUE

+

+  APRIORI PEI {

+    INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  }

+  INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf

+  INF MdeModulePkg/Core/Pei/PeiMain.inf

+  INF ArmPlatformPkg/PlatformPei/PlatformPeim.inf

+  INF ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf

+  INF ArmPkg/Drivers/CpuPei/CpuPei.inf

+  INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf

+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf

+  INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

+

+  FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {

+    SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {

+      SECTION FV_IMAGE = FVMAIN

+    }

+  }

+

+

+################################################################################

+#

+# Rules are use with the [FV] section's module INF type to define

+# how an FFS file is created for a given INF file. The following Rule are the default

+# rules for the different module type. User can add the customized rules to define the

+# content of the FFS file.

+#

+################################################################################

+

+

+############################################################################

+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   #

+############################################################################

+#

+#[Rule.Common.DXE_DRIVER]

+#  FILE DRIVER = $(NAMED_GUID) {

+#    DXE_DEPEX    DXE_DEPEX               Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+#    COMPRESS PI_STD {

+#      GUIDED {

+#        PE32     PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+#        UI       STRING="$(MODULE_NAME)" Optional

+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+#      }

+#    }

+#  }

+#

+############################################################################

+

+[Rule.Common.SEC]

+  FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {

+    TE  TE Align = 128                  $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.PEI_CORE]

+  FILE PEI_CORE = $(NAMED_GUID) {

+    TE     TE Align = 8                 $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI     STRING ="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM]

+  FILE PEIM = $(NAMED_GUID) {

+     PEI_DEPEX PEI_DEPEX Optional       $(INF_OUTPUT)/$(MODULE_NAME).depex

+     TE       TE Align = 8              $(INF_OUTPUT)/$(MODULE_NAME).efi

+     UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.PEIM.TIANOCOMPRESSED]

+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {

+    PEI_DEPEX PEI_DEPEX Optional        $(INF_OUTPUT)/$(MODULE_NAME).depex

+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {

+      PE32      PE32                    $(INF_OUTPUT)/$(MODULE_NAME).efi

+      UI        STRING="$(MODULE_NAME)" Optional

+    }

+  }

+

+[Rule.Common.DXE_CORE]

+  FILE DXE_CORE = $(NAMED_GUID) {

+    PE32     PE32                       $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI       STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.DXE_RUNTIME_DRIVER]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX    DXE_DEPEX              Optional $(INF_OUTPUT)/$(MODULE_NAME).depex

+    PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi

+    UI           STRING="$(MODULE_NAME)" Optional

+  }

+

+[Rule.Common.UEFI_APPLICATION]

+  FILE APPLICATION = $(NAMED_GUID) {

+    UI     STRING ="$(MODULE_NAME)"     Optional

+    PE32   PE32                         $(INF_OUTPUT)/$(MODULE_NAME).efi

+  }

+

+[Rule.Common.UEFI_DRIVER.BINARY]

+  FILE DRIVER = $(NAMED_GUID) {

+    DXE_DEPEX DXE_DEPEX Optional      |.depex

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.UEFI_APPLICATION.BINARY]

+  FILE APPLICATION = $(NAMED_GUID) {

+    PE32      PE32                    |.efi

+    UI        STRING="$(MODULE_NAME)" Optional

+    VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)

+  }

+

+[Rule.Common.USER_DEFINED.ACPITABLE]

+  FILE FREEFORM = $(NAMED_GUID) {

+    RAW       ACPI                    |.acpi

+    RAW       ASL                     |.aml

+    UI        STRING="$(MODULE_NAME)" Optional

+  }

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Include/ArmPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Include/ArmPlatform.h
new file mode 100644
index 0000000..77178aa
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Include/ArmPlatform.h
@@ -0,0 +1,33 @@
+/** @file

+*  Header defining platform constants (Base addresses, sizes, flags)

+*

+*  Copyright (c) 2011, ARM Limited. All rights reserved.

+*  Copyright (c) 2014, Linaro Limited

+*

+*  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 __PLATFORM_H__

+#define __PLATFORM_H__

+

+//

+// We don't care about this value, but the PL031 driver depends on the macro

+// to exist: it will pass it on to our ArmPlatformSysConfigLib:ConfigGet()

+// function, which just returns EFI_UNSUPPORTED.

+//

+#define SYS_CFG_RTC       0x0

+

+#define QEMU_NOR_BLOCK_SIZE    SIZE_256KB

+#define QEMU_NOR0_BASE         0x0

+#define QEMU_NOR0_SIZE         SIZE_64MB

+#define QEMU_NOR1_BASE         0x04000000

+#define QEMU_NOR1_SIZE         SIZE_64MB

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Include/Guid/EarlyPL011BaseAddress.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Include/Guid/EarlyPL011BaseAddress.h
new file mode 100644
index 0000000..1b703a8
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Include/Guid/EarlyPL011BaseAddress.h
@@ -0,0 +1,27 @@
+/** @file

+  GUID for the HOB that caches the base address of the PL011 serial port, for

+  when PCD access is not available.

+

+  Copyright (C) 2014, Red Hat, Inc.

+

+  This program and the accompanying materials are licensed and made available

+  under the terms and conditions of the BSD License that 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 __EARLY_PL011_BASE_ADDRESS_H__

+#define __EARLY_PL011_BASE_ADDRESS_H__

+

+#define EARLY_PL011_BASE_ADDRESS_GUID { \

+          0xB199DEA9, 0xFD5C, 0x4A84, \

+          { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } \

+        }

+

+extern EFI_GUID gEarlyPL011BaseAddressGuid;

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/ArmVirtualizationDxeHobLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/ArmVirtualizationDxeHobLib.inf
new file mode 100644
index 0000000..b6a2c00
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/ArmVirtualizationDxeHobLib.inf
@@ -0,0 +1,40 @@
+## @file

+# Instance of HOB Library using HOB list from EFI Configuration Table, with

+# DebugLib dependency removed

+#

+# HOB Library implementation that retrieves the HOB List

+#  from the System Configuration Table in the EFI System Table.

+#

+# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>

+# Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmVirtualizationDxeHobLib

+  FILE_GUID                      = 3CD90EEC-EBF3-425D-AAE8-B16215AC4F50

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = HobLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER

+  CONSTRUCTOR                    = HobLibConstructor

+

+[Sources]

+  HobLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+

+[LibraryClasses]

+  BaseMemoryLib

+

+[Guids]

+  gEfiHobListGuid                               ## CONSUMES  ## SystemTable

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/HobLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/HobLib.c
new file mode 100644
index 0000000..81196b2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationDxeHobLib/HobLib.c
@@ -0,0 +1,577 @@
+/** @file

+  HOB Library implemenation for Dxe Phase with DebugLib dependency removed

+

+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+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.

+

+**/

+

+#define ASSERT(Expression)      \

+  do {                          \

+    if (!(Expression)) {        \

+      CpuDeadLoop ();           \

+    }                           \

+  } while (FALSE)

+

+#include <PiDxe.h>

+

+#include <Guid/HobList.h>

+

+#include <Library/HobLib.h>

+#include <Library/UefiLib.h>

+#include <Library/BaseMemoryLib.h>

+

+VOID  *mHobList = NULL;

+

+/**

+  The constructor function caches the pointer to HOB list.

+

+  The constructor function gets the start address of HOB list from system configuration table.

+

+  @param  ImageHandle   The firmware allocated handle for the EFI image.

+  @param  SystemTable   A pointer to the EFI System Table.

+

+  @retval EFI_SUCCESS   The constructor successfully gets HobList.

+  @retval Other value   The constructor can't get HobList.

+

+**/

+EFI_STATUS

+EFIAPI

+HobLibConstructor (

+  IN EFI_HANDLE        ImageHandle,

+  IN EFI_SYSTEM_TABLE  *SystemTable

+  )

+{

+  UINTN             Index;

+

+  for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {

+    if (CompareGuid (&gEfiHobListGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {

+      mHobList = SystemTable->ConfigurationTable[Index].VendorTable;

+      return EFI_SUCCESS;

+    }

+  }

+

+  return EFI_NOT_FOUND;

+}

+

+/**

+  Returns the pointer to the HOB list.

+

+  This function returns the pointer to first HOB in the list.

+  For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer

+  to the HOB list.  For the DXE phase, the HOB list pointer can be retrieved through

+  the EFI System Table by looking up theHOB list GUID in the System Configuration Table.

+  Since the System Configuration Table does not exist that the time the DXE Core is

+  launched, the DXE Core uses a global variable from the DXE Core Entry Point Library

+  to manage the pointer to the HOB list.

+

+  If the pointer to the HOB list is NULL, then ASSERT().

+

+  @return The pointer to the HOB list.

+

+**/

+VOID *

+EFIAPI

+GetHobList (

+  VOID

+  )

+{

+  ASSERT (mHobList != NULL);

+  return mHobList;

+}

+

+/**

+  Returns the next instance of a HOB type from the starting HOB.

+

+  This function searches the first instance of a HOB type from the starting HOB pointer.

+  If there does not exist such HOB type from the starting HOB pointer, it will return NULL.

+  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer

+  unconditionally: it returns HobStart back if HobStart itself meets the requirement;

+  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.

+

+  If HobStart is NULL, then ASSERT().

+

+  @param  Type          The HOB type to return.

+  @param  HobStart      The starting HOB pointer to search from.

+

+  @return The next instance of a HOB type from the starting HOB.

+

+**/

+VOID *

+EFIAPI

+GetNextHob (

+  IN UINT16                 Type,

+  IN CONST VOID             *HobStart

+  )

+{

+  EFI_PEI_HOB_POINTERS  Hob;

+

+  ASSERT (HobStart != NULL);

+

+  Hob.Raw = (UINT8 *) HobStart;

+  //

+  // Parse the HOB list until end of list or matching type is found.

+  //

+  while (!END_OF_HOB_LIST (Hob)) {

+    if (Hob.Header->HobType == Type) {

+      return Hob.Raw;

+    }

+    Hob.Raw = GET_NEXT_HOB (Hob);

+  }

+  return NULL;

+}

+

+/**

+  Returns the first instance of a HOB type among the whole HOB list.

+

+  This function searches the first instance of a HOB type among the whole HOB list.

+  If there does not exist such HOB type in the HOB list, it will return NULL.

+

+  If the pointer to the HOB list is NULL, then ASSERT().

+

+  @param  Type          The HOB type to return.

+

+  @return The next instance of a HOB type from the starting HOB.

+

+**/

+VOID *

+EFIAPI

+GetFirstHob (

+  IN UINT16                 Type

+  )

+{

+  VOID      *HobList;

+

+  HobList = GetHobList ();

+  return GetNextHob (Type, HobList);

+}

+

+/**

+  Returns the next instance of the matched GUID HOB from the starting HOB.

+

+  This function searches the first instance of a HOB from the starting HOB pointer.

+  Such HOB should satisfy two conditions:

+  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.

+  If there does not exist such HOB from the starting HOB pointer, it will return NULL.

+  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()

+  to extract the data section and its size information, respectively.

+  In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer

+  unconditionally: it returns HobStart back if HobStart itself meets the requirement;

+  caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.

+

+  If Guid is NULL, then ASSERT().

+  If HobStart is NULL, then ASSERT().

+

+  @param  Guid          The GUID to match with in the HOB list.

+  @param  HobStart      A pointer to a Guid.

+

+  @return The next instance of the matched GUID HOB from the starting HOB.

+

+**/

+VOID *

+EFIAPI

+GetNextGuidHob (

+  IN CONST EFI_GUID         *Guid,

+  IN CONST VOID             *HobStart

+  )

+{

+  EFI_PEI_HOB_POINTERS  GuidHob;

+

+  GuidHob.Raw = (UINT8 *) HobStart;

+  while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {

+    if (CompareGuid (Guid, &GuidHob.Guid->Name)) {

+      break;

+    }

+    GuidHob.Raw = GET_NEXT_HOB (GuidHob);

+  }

+  return GuidHob.Raw;

+}

+

+/**

+  Returns the first instance of the matched GUID HOB among the whole HOB list.

+

+  This function searches the first instance of a HOB among the whole HOB list.

+  Such HOB should satisfy two conditions:

+  its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.

+  If there does not exist such HOB from the starting HOB pointer, it will return NULL.

+  Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()

+  to extract the data section and its size information, respectively.

+

+  If the pointer to the HOB list is NULL, then ASSERT().

+  If Guid is NULL, then ASSERT().

+

+  @param  Guid          The GUID to match with in the HOB list.

+

+  @return The first instance of the matched GUID HOB among the whole HOB list.

+

+**/

+VOID *

+EFIAPI

+GetFirstGuidHob (

+  IN CONST EFI_GUID         *Guid

+  )

+{

+  VOID      *HobList;

+

+  HobList = GetHobList ();

+  return GetNextGuidHob (Guid, HobList);

+}

+

+/**

+  Get the system boot mode from the HOB list.

+

+  This function returns the system boot mode information from the

+  PHIT HOB in HOB list.

+

+  If the pointer to the HOB list is NULL, then ASSERT().

+

+  @param  VOID

+

+  @return The Boot Mode.

+

+**/

+EFI_BOOT_MODE

+EFIAPI

+GetBootModeHob (

+  VOID

+  )

+{

+  EFI_HOB_HANDOFF_INFO_TABLE    *HandOffHob;

+

+  HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();

+

+  return  HandOffHob->BootMode;

+}

+

+/**

+  Builds a HOB for a loaded PE32 module.

+

+  This function builds a HOB for a loaded PE32 module.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If ModuleName is NULL, then ASSERT().

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  ModuleName              The GUID File Name of the module.

+  @param  MemoryAllocationModule  The 64 bit physical address of the module.

+  @param  ModuleLength            The length of the module in bytes.

+  @param  EntryPoint              The 64 bit physical address of the module entry point.

+

+**/

+VOID

+EFIAPI

+BuildModuleHob (

+  IN CONST EFI_GUID         *ModuleName,

+  IN EFI_PHYSICAL_ADDRESS   MemoryAllocationModule,

+  IN UINT64                 ModuleLength,

+  IN EFI_PHYSICAL_ADDRESS   EntryPoint

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

+

+/**

+  Builds a HOB that describes a chunk of system memory.

+

+  This function builds a HOB that describes a chunk of system memory.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  ResourceType        The type of resource described by this HOB.

+  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.

+  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.

+  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.

+

+**/

+VOID

+EFIAPI

+BuildResourceDescriptorHob (

+  IN EFI_RESOURCE_TYPE            ResourceType,

+  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,

+  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,

+  IN UINT64                       NumberOfBytes

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

+

+/**

+  Builds a customized HOB tagged with a GUID for identification and returns

+  the start address of GUID HOB data.

+

+  This function builds a customized HOB tagged with a GUID for identification

+  and returns the start address of GUID HOB data so that caller can fill the customized data.

+  The HOB Header and Name field is already stripped.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If Guid is NULL, then ASSERT().

+  If there is no additional space for HOB creation, then ASSERT().

+  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().

+  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.

+

+  @param  Guid          The GUID to tag the customized HOB.

+  @param  DataLength    The size of the data payload for the GUID HOB.

+

+  @retval  NULL         The GUID HOB could not be allocated.

+  @retval  others       The start address of GUID HOB data.

+

+**/

+VOID *

+EFIAPI

+BuildGuidHob (

+  IN CONST EFI_GUID              *Guid,

+  IN UINTN                       DataLength

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+  return NULL;

+}

+

+/**

+  Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB

+  data field, and returns the start address of the GUID HOB data.

+

+  This function builds a customized HOB tagged with a GUID for identification and copies the input

+  data to the HOB data field and returns the start address of the GUID HOB data.  It can only be

+  invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+  The HOB Header and Name field is already stripped.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If Guid is NULL, then ASSERT().

+  If Data is NULL and DataLength > 0, then ASSERT().

+  If there is no additional space for HOB creation, then ASSERT().

+  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().

+  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.

+

+  @param  Guid          The GUID to tag the customized HOB.

+  @param  Data          The data to be copied into the data field of the GUID HOB.

+  @param  DataLength    The size of the data payload for the GUID HOB.

+

+  @retval  NULL         The GUID HOB could not be allocated.

+  @retval  others       The start address of GUID HOB data.

+

+**/

+VOID *

+EFIAPI

+BuildGuidDataHob (

+  IN CONST EFI_GUID              *Guid,

+  IN VOID                        *Data,

+  IN UINTN                       DataLength

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+  return NULL;

+}

+

+/**

+  Builds a Firmware Volume HOB.

+

+  This function builds a Firmware Volume HOB.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  BaseAddress   The base address of the Firmware Volume.

+  @param  Length        The size of the Firmware Volume in bytes.

+

+**/

+VOID

+EFIAPI

+BuildFvHob (

+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,

+  IN UINT64                      Length

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

+

+/**

+  Builds a EFI_HOB_TYPE_FV2 HOB.

+

+  This function builds a EFI_HOB_TYPE_FV2 HOB.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  BaseAddress   The base address of the Firmware Volume.

+  @param  Length        The size of the Firmware Volume in bytes.

+  @param  FvName        The name of the Firmware Volume.

+  @param  FileName      The name of the file.

+

+**/

+VOID

+EFIAPI

+BuildFv2Hob (

+  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,

+  IN          UINT64                      Length,

+  IN CONST    EFI_GUID                    *FvName,

+  IN CONST    EFI_GUID                    *FileName

+  )

+{

+  ASSERT (FALSE);

+}

+

+

+/**

+  Builds a Capsule Volume HOB.

+

+  This function builds a Capsule Volume HOB.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If the platform does not support Capsule Volume HOBs, then ASSERT().

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  BaseAddress   The base address of the Capsule Volume.

+  @param  Length        The size of the Capsule Volume in bytes.

+

+**/

+VOID

+EFIAPI

+BuildCvHob (

+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,

+  IN UINT64                      Length

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

+

+/**

+  Builds a HOB for the CPU.

+

+  This function builds a HOB for the CPU.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.

+  @param  SizeOfIoSpace       The maximum physical I/O addressability of the processor.

+

+**/

+VOID

+EFIAPI

+BuildCpuHob (

+  IN UINT8                       SizeOfMemorySpace,

+  IN UINT8                       SizeOfIoSpace

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

+

+/**

+  Builds a HOB for the Stack.

+

+  This function builds a HOB for the stack.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  BaseAddress   The 64 bit physical address of the Stack.

+  @param  Length        The length of the stack in bytes.

+

+**/

+VOID

+EFIAPI

+BuildStackHob (

+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,

+  IN UINT64                      Length

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

+

+/**

+  Builds a HOB for the BSP store.

+

+  This function builds a HOB for BSP store.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  BaseAddress   The 64 bit physical address of the BSP.

+  @param  Length        The length of the BSP store in bytes.

+  @param  MemoryType    Type of memory allocated by this HOB.

+

+**/

+VOID

+EFIAPI

+BuildBspStoreHob (

+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,

+  IN UINT64                      Length,

+  IN EFI_MEMORY_TYPE             MemoryType

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

+

+/**

+  Builds a HOB for the memory allocation.

+

+  This function builds a HOB for the memory allocation.

+  It can only be invoked during PEI phase;

+  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.

+

+  If there is no additional space for HOB creation, then ASSERT().

+

+  @param  BaseAddress   The 64 bit physical address of the memory.

+  @param  Length        The length of the memory allocation in bytes.

+  @param  MemoryType    Type of memory allocated by this HOB.

+

+**/

+VOID

+EFIAPI

+BuildMemoryAllocationHob (

+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,

+  IN UINT64                      Length,

+  IN EFI_MEMORY_TYPE             MemoryType

+  )

+{

+  //

+  // PEI HOB is read only for DXE phase

+  //

+  ASSERT (FALSE);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/AARCH64/VirtHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/AARCH64/VirtHelper.S
new file mode 100644
index 0000000..14200fc
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/AARCH64/VirtHelper.S
@@ -0,0 +1,86 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+#

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <Library/ArmLib.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmGetPhysAddrTop)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  ret

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x0)

+  ldrh   w0, [x0]

+  ret

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  mov   x0, #1

+  ret

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+// With this function: CorePos = (ClusterId * 4) + CoreId

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   x1, x0, #ARM_CORE_MASK

+  and   x0, x0, #ARM_CLUSTER_MASK

+  add   x0, x1, x0, LSR #6

+  ret

+

+//EFI_PHYSICAL_ADDRESS

+//GetPhysAddrTop (

+//  VOID

+//  );

+ASM_PFX(ArmGetPhysAddrTop):

+  mrs   x0, id_aa64mmfr0_el1

+  adr   x1, .LPARanges

+  and   x0, x0, #7

+  ldrb  w1, [x1, x0]

+  mov   x0, #1

+  lsl   x0, x0, x1

+  ret

+

+//

+// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the

+// physical address space support on this CPU:

+// 0 == 32 bits, 1 == 36 bits, etc etc

+// 6 and 7 are reserved

+//

+.LPARanges:

+  .byte 32, 36, 40, 42, 44, 48, -1, -1

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ARM/VirtHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ARM/VirtHelper.S
new file mode 100644
index 0000000..255f995
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ARM/VirtHelper.S
@@ -0,0 +1,74 @@
+#

+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.

+#  Copyright (c) 2014, 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.

+#

+#

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmLib.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmGetPhysAddrTop)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  bx    lr

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr    r0, [r0]

+  bx     lr

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  mov   r0, #1

+  bx    lr

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+// With this function: CorePos = (ClusterId * 4) + CoreId

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #6

+  bx    lr

+

+//EFI_PHYSICAL_ADDRESS

+//GetPhysAddrTop (

+//  VOID

+//  );

+ASM_PFX(ArmGetPhysAddrTop):

+  mov   r0, #0x00000000

+  mov   r1, #0x10000

+  bx    lr

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ARM/VirtHelper.asm b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ARM/VirtHelper.asm
new file mode 100644
index 0000000..7882e63
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ARM/VirtHelper.asm
@@ -0,0 +1,79 @@
+//

+//  Copyright (c) 2011-2014, ARM Limited. All rights reserved.

+//  Copyright (c) 2014, 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.

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/ArmLib.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformPeiBootAction

+  EXPORT  ArmPlatformIsPrimaryCore

+  EXPORT  ArmPlatformGetPrimaryCoreMpId

+  EXPORT  ArmPlatformGetCorePosition

+  EXPORT  ArmGetPhysAddrTop

+

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCore

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCoreMask

+  IMPORT  _gPcd_FixedAtBuild_PcdCoreCount

+

+  AREA VirtHelper, CODE, READONLY

+

+ArmPlatformPeiBootAction FUNCTION

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ArmPlatformGetPrimaryCoreMpId FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr    r0, [r0]

+  bx     lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ArmPlatformIsPrimaryCore FUNCTION

+  mov   r0, #1

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+// With this function: CorePos = (ClusterId * 4) + CoreId

+ArmPlatformGetCorePosition FUNCTION

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #6

+  bx    lr

+  ENDFUNC

+

+//EFI_PHYSICAL_ADDRESS

+//GetPhysAddrTop (

+//  VOID

+//  );

+ArmGetPhysAddrTop FUNCTION

+  mov   r0, #0x00000000

+  mov   r1, #0x10000

+  bx    lr

+  ENDFUNC

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf
new file mode 100644
index 0000000..d157288
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf
@@ -0,0 +1,67 @@
+#/* @file

+#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.

+#  Copyright (c) 2014, 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmVirtualizationPlatformLib

+  FILE_GUID                      = 00214cc1-06d1-45fe-9700-dca5726ad7bf

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib|SEC PEIM

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec

+

+[LibraryClasses]

+  IoLib

+  ArmLib

+  PrintLib

+  FdtLib

+  SerialPortLib

+  HobLib

+

+[Sources.common]

+  Virt.c

+  VirtMem.c

+

+[Sources.AARCH64]

+  AARCH64/VirtHelper.S

+

+[Sources.ARM]

+  ARM/VirtHelper.S          | GCC

+  ARM/VirtHelper.asm        | RVCT

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdCacheEnable

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec

+

+[Pcd]

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+[FixedPcd]

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+[Guids]

+  gEarlyPL011BaseAddressGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c
new file mode 100644
index 0000000..aa4ced4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c
@@ -0,0 +1,197 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.

+*  Copyright (c) 2014, Linaro Limited. All rights reserved.

+*  Copyright (c) 2014, Red Hat, Inc.

+*

+*

+*  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 <Library/IoLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+#include <ArmPlatform.h>

+#include <libfdt.h>

+#include <Pi/PiBootMode.h>

+#include <Uefi/UefiBaseType.h>

+#include <Uefi/UefiMultiPhase.h>

+#include <Pi/PiHob.h>

+#include <Library/HobLib.h>

+#include <Guid/EarlyPL011BaseAddress.h>

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+  @return   Return the current Boot Mode of the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  return BOOT_WITH_FULL_CONFIGURATION;

+}

+

+/**

+  This function is called by PrePeiCore, in the SEC phase.

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  //

+  // We are relying on ArmPlatformInitializeSystemMemory () being called from

+  // InitializeMemory (), which only occurs if the following feature is disabled

+  //

+  ASSERT (!FeaturePcdGet (PcdSystemMemoryInitializeInSec));

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+  This function is called from InitializeMemory() in MemoryInitPeim, in the PEI

+  phase.

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+  VOID         *DeviceTreeBase;

+  INT32        Node, Prev;

+  UINT64       NewBase;

+  UINT64       NewSize;

+  BOOLEAN      HaveMemory, HaveUART;

+  UINT64       *HobData;

+  CONST CHAR8  *Type;

+  CONST CHAR8  *Compatible;

+  CONST CHAR8  *CompItem;

+  INT32        Len;

+  CONST UINT64 *RegProp;

+  UINT64       UartBase;

+

+  NewBase = 0;

+  NewSize = 0;

+

+  HaveMemory = FALSE;

+  HaveUART   = FALSE;

+

+  HobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof *HobData);

+  ASSERT (HobData != NULL);

+  *HobData = 0;

+

+  DeviceTreeBase = (VOID *)(UINTN)FixedPcdGet64 (PcdDeviceTreeInitialBaseAddress);

+  ASSERT (DeviceTreeBase != NULL);

+

+  //

+  // Make sure we have a valid device tree blob

+  //

+  ASSERT (fdt_check_header (DeviceTreeBase) == 0);

+

+  //

+  // Look for a memory node

+  //

+  for (Prev = 0; !(HaveMemory && HaveUART); Prev = Node) {

+    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);

+    if (Node < 0) {

+      break;

+    }

+

+    //

+    // Check for memory node

+    //

+    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);

+    if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {

+      //

+      // Get the 'reg' property of this node. For now, we will assume

+      // two 8 byte quantities for base and size, respectively.

+      //

+      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);

+      if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {

+

+        NewBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));

+        NewSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));

+

+        //

+        // Make sure the start of DRAM matches our expectation

+        //

+        ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);

+        PcdSet64 (PcdSystemMemorySize, NewSize);

+

+        DEBUG ((EFI_D_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",

+               __FUNCTION__, NewBase, NewBase + NewSize - 1));

+      } else {

+        DEBUG ((EFI_D_ERROR, "%a: Failed to parse FDT memory node\n",

+               __FUNCTION__));

+      }

+      HaveMemory = TRUE;

+      continue;

+    }

+

+    //

+    // Check for UART node

+    //

+    Compatible = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len);

+

+    //

+    // Iterate over the NULL-separated items in the compatible string

+    //

+    for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + Len;

+      CompItem += 1 + AsciiStrLen (CompItem)) {

+

+      if (AsciiStrCmp (CompItem, "arm,pl011") == 0) {

+        RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);

+        ASSERT (Len == 16);

+

+        UartBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));

+

+        DEBUG ((EFI_D_INFO, "%a: PL011 UART @ 0x%lx\n", __FUNCTION__, UartBase));

+

+        *HobData = UartBase;

+

+        HaveUART = TRUE;

+        continue;

+      }

+    }

+  }

+

+  //

+  // We need to make sure that the machine we are running on has at least

+  // 128 MB of memory configured, and is currently executing this binary from

+  // NOR flash. This prevents a device tree image in DRAM from getting

+  // clobbered when our caller installs permanent PEI RAM, before we have a

+  // chance of marking its location as reserved or copy it to a freshly

+  // allocated block in the permanent PEI RAM in the platform PEIM.

+  //

+  ASSERT (NewSize >= SIZE_128MB);

+  ASSERT (

+    (((UINT64)PcdGet64 (PcdFdBaseAddress) +

+      (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||

+    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));

+}

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  *PpiListSize = 0;

+  *PpiList = NULL;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/VirtMem.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/VirtMem.c
new file mode 100644
index 0000000..d5d288f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/VirtMem.c
@@ -0,0 +1,107 @@
+/** @file

+*

+*  Copyright (c) 2014, 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/ArmPlatformGlobalVariableLib.h>

+#include <ArmPlatform.h>

+

+// Number of Virtual Memory Map Descriptors

+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          4

+

+// DDR attributes

+#define DDR_ATTRIBUTES_CACHED    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK

+#define DDR_ATTRIBUTES_UNCACHED  ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED

+

+EFI_PHYSICAL_ADDRESS

+ArmGetPhysAddrTop (

+  VOID

+  );

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU

+  on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR

+                                    describing a Physical-to-Virtual Memory

+                                    mapping. This array must be ended by a

+                                    zero-filled entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;

+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;

+

+  ASSERT (VirtualMemoryMap != NULL);

+

+  VirtualMemoryTable = AllocatePages (

+                         EFI_SIZE_TO_PAGES (

+                           sizeof (ARM_MEMORY_REGION_DESCRIPTOR)

+                           * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS

+                           )

+                         );

+

+  if (VirtualMemoryTable == NULL) {

+    DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));

+    return;

+  }

+

+  if (FeaturePcdGet (PcdCacheEnable) == TRUE) {

+    CacheAttributes = DDR_ATTRIBUTES_CACHED;

+  } else {

+    CacheAttributes = DDR_ATTRIBUTES_UNCACHED;

+  }

+

+  // System DRAM

+  VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);

+  VirtualMemoryTable[0].VirtualBase  = VirtualMemoryTable[0].PhysicalBase;

+  VirtualMemoryTable[0].Length       = PcdGet64 (PcdSystemMemorySize);

+  VirtualMemoryTable[0].Attributes   = CacheAttributes;

+

+  DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"

+      "\tPhysicalBase: 0x%lX\n"

+      "\tVirtualBase: 0x%lX\n"

+      "\tLength: 0x%lX\n",

+      __FUNCTION__,

+      VirtualMemoryTable[0].PhysicalBase,

+      VirtualMemoryTable[0].VirtualBase,

+      VirtualMemoryTable[0].Length));

+

+  // Peripheral space before DRAM

+  VirtualMemoryTable[1].PhysicalBase = 0x0;

+  VirtualMemoryTable[1].VirtualBase  = 0x0;

+  VirtualMemoryTable[1].Length       = VirtualMemoryTable[0].PhysicalBase;

+  VirtualMemoryTable[1].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // Peripheral space after DRAM

+  VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;

+  VirtualMemoryTable[2].VirtualBase  = VirtualMemoryTable[2].PhysicalBase;

+  VirtualMemoryTable[2].Length       = ArmGetPhysAddrTop () - VirtualMemoryTable[2].PhysicalBase;

+  VirtualMemoryTable[2].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;

+

+  // End of Table

+  ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));

+

+  *VirtualMemoryMap = VirtualMemoryTable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPsciResetSystemLib/ArmVirtualizationPsciResetSystemLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPsciResetSystemLib/ArmVirtualizationPsciResetSystemLib.c
new file mode 100644
index 0000000..88332f5
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPsciResetSystemLib/ArmVirtualizationPsciResetSystemLib.c
@@ -0,0 +1,125 @@
+/** @file

+  Support ResetSystem Runtime call using PSCI calls

+

+  Note: A similar library is implemented in

+  ArmPkg/Library/ArmPsciResetSystemLib. Similar issues might

+  exist in this implementation too.

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>

+  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+

+  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 <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/EfiResetSystemLib.h>

+#include <Library/ArmSmcLib.h>

+#include <Library/ArmHvcLib.h>

+

+#include <IndustryStandard/ArmStdSmc.h>

+

+STATIC UINT32 mArmPsciMethod;

+

+RETURN_STATUS

+EFIAPI

+ArmPsciResetSystemLibConstructor (

+  VOID

+  )

+{

+  mArmPsciMethod = PcdGet32 (PcdArmPsciMethod);

+  return RETURN_SUCCESS;

+}

+

+/**

+  Resets the entire platform.

+

+  @param  ResetType             The type of reset to perform.

+  @param  ResetStatus           The status code for the reset.

+  @param  DataSize              The size, in bytes, of WatchdogData.

+  @param  ResetData             For a ResetType of EfiResetCold, EfiResetWarm, or

+                                EfiResetShutdown the data buffer starts with a Null-terminated

+                                Unicode string, optionally followed by additional binary data.

+

+**/

+EFI_STATUS

+EFIAPI

+LibResetSystem (

+  IN EFI_RESET_TYPE   ResetType,

+  IN EFI_STATUS       ResetStatus,

+  IN UINTN            DataSize,

+  IN CHAR16           *ResetData OPTIONAL

+  )

+{

+  ARM_SMC_ARGS ArmSmcArgs;

+  ARM_HVC_ARGS ArmHvcArgs;

+

+  switch (ResetType) {

+

+  case EfiResetPlatformSpecific:

+    // Map the platform specific reset as reboot

+  case EfiResetWarm:

+    // Map a warm reset into a cold reset

+  case EfiResetCold:

+    // Send a PSCI 0.2 SYSTEM_RESET command

+    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;

+    ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;

+    break;

+  case EfiResetShutdown:

+    // Send a PSCI 0.2 SYSTEM_OFF command

+    ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;

+    ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;

+    break;

+  default:

+    ASSERT (FALSE);

+    return EFI_UNSUPPORTED;

+  }

+

+  switch (mArmPsciMethod) {

+  case 1:

+    ArmCallHvc (&ArmHvcArgs);

+    break;

+

+  case 2:

+    ArmCallSmc (&ArmSmcArgs);

+    break;

+

+  default:

+    DEBUG ((EFI_D_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));

+    return EFI_UNSUPPORTED;

+  }

+

+  // We should never be here

+  DEBUG ((EFI_D_ERROR, "%a: PSCI Reset failed\n", __FUNCTION__));

+  CpuDeadLoop ();

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Initialize any infrastructure required for LibResetSystem () to function.

+

+  @param  ImageHandle   The firmware allocated handle for the EFI image.

+  @param  SystemTable   A pointer to the EFI System Table.

+

+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.

+

+**/

+EFI_STATUS

+EFIAPI

+LibInitializeResetSystem (

+  IN EFI_HANDLE        ImageHandle,

+  IN EFI_SYSTEM_TABLE  *SystemTable

+  )

+{

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPsciResetSystemLib/ArmVirtualizationPsciResetSystemLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPsciResetSystemLib/ArmVirtualizationPsciResetSystemLib.inf
new file mode 100644
index 0000000..b63507a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPsciResetSystemLib/ArmVirtualizationPsciResetSystemLib.inf
@@ -0,0 +1,42 @@
+#/** @file

+# Reset System lib using PSCI hypervisor or secure monitor calls

+#

+# Copyright (c) 2008, Apple Inc. All rights reserved.<BR>

+# Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmVirtualizationPsciResetSystemLib

+  FILE_GUID                      = c81d76ed-66fa-44a3-ac4a-f163120187a9

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = EfiResetSystemLib

+  CONSTRUCTOR                    = ArmPsciResetSystemLibConstructor

+

+[Sources]

+  ArmVirtualizationPsciResetSystemLib.c

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  BaseLib

+  ArmSmcLib

+  ArmHvcLib

+

+[Pcd]

+  gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c
new file mode 100644
index 0000000..ba6d277
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.c
@@ -0,0 +1,185 @@
+/** @file

+  Serial I/O Port library functions with base address discovered from FDT

+

+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>

+  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+

+  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 <Base.h>

+

+#include <Library/PcdLib.h>

+#include <Library/SerialPortLib.h>

+#include <Library/SerialPortExtLib.h>

+#include <libfdt.h>

+

+#include <Drivers/PL011Uart.h>

+

+RETURN_STATUS

+EFIAPI

+SerialPortInitialize (

+  VOID

+  )

+{

+  //

+  // This SerialPortInitialize() function is completely empty, for a number of

+  // reasons:

+  // - if we are executing from flash, it is hard to keep state (i.e., store the

+  //   discovered base address in a global), and the most robust way to deal

+  //   with this is to discover the base address at every Write ();

+  // - calls to the Write() function in this module may be issued before this

+  //   initialization function is called: this is not a problem when the base

+  //   address of the UART is hardcoded, and only the baud rate may be wrong,

+  //   but if we don't know the base address yet, we may be poking into memory

+  //   that does not tolerate being poked into;

+  // - SEC and PEI phases produce debug output only, so with debug disabled, no

+  //   initialization (or device tree parsing) is performed at all.

+  //

+  // Note that this means that on *every* Write () call, the device tree will be

+  // parsed and the UART re-initialized. However, this is a small price to pay

+  // for having serial debug output on a UART with no fixed base address.

+  //

+  return RETURN_SUCCESS;

+}

+

+STATIC

+UINT64

+SerialPortGetBaseAddress (

+  VOID

+  )

+{

+  UINT64              BaudRate;

+  UINT32              ReceiveFifoDepth;

+  EFI_PARITY_TYPE     Parity;

+  UINT8               DataBits;

+  EFI_STOP_BITS_TYPE  StopBits;

+  VOID                *DeviceTreeBase;

+  INT32               Node, Prev;

+  INT32               Len;

+  CONST CHAR8         *Compatible;

+  CONST CHAR8         *CompatibleItem;

+  CONST UINT64        *RegProperty;

+  UINTN               UartBase;

+  RETURN_STATUS       Status;

+

+  DeviceTreeBase = (VOID *)(UINTN)FixedPcdGet64 (PcdDeviceTreeInitialBaseAddress);

+

+  if ((DeviceTreeBase == NULL) || (fdt_check_header (DeviceTreeBase) != 0)) {

+    return 0;

+  }

+

+  //

+  // Enumerate all FDT nodes looking for a PL011 and capture its base address

+  //

+  for (Prev = 0;; Prev = Node) {

+    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);

+    if (Node < 0) {

+      break;

+    }

+

+    Compatible = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len);

+    if (Compatible == NULL) {

+      continue;

+    }

+

+    //

+    // Iterate over the NULL-separated items in the compatible string

+    //

+    for (CompatibleItem = Compatible; CompatibleItem < Compatible + Len;

+      CompatibleItem += 1 + AsciiStrLen (CompatibleItem)) {

+

+      if (AsciiStrCmp (CompatibleItem, "arm,pl011") == 0) {

+        RegProperty = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);

+        if (Len != 16) {

+          return 0;

+        }

+        UartBase = (UINTN)fdt64_to_cpu (ReadUnaligned64 (RegProperty));

+

+        BaudRate = (UINTN)FixedPcdGet64 (PcdUartDefaultBaudRate);

+        ReceiveFifoDepth = 0; // Use the default value for Fifo depth

+        Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);

+        DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);

+        StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits);

+

+        Status = PL011UartInitializePort (

+                   UartBase,

+                   &BaudRate, &ReceiveFifoDepth, &Parity, &DataBits, &StopBits);

+        if (!EFI_ERROR (Status)) {

+          return UartBase;

+        }

+      }

+    }

+  }

+  return 0;

+}

+

+/**

+  Write data to serial device.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Write data failed.

+  @retval !0               Actual number of bytes written to serial device.

+

+**/

+UINTN

+EFIAPI

+SerialPortWrite (

+  IN UINT8     *Buffer,

+  IN UINTN     NumberOfBytes

+  )

+{

+  UINT64 SerialRegisterBase;

+

+  SerialRegisterBase = SerialPortGetBaseAddress ();

+  if (SerialRegisterBase != 0) {

+    return PL011UartWrite ((UINTN)SerialRegisterBase, Buffer, NumberOfBytes);

+  }

+  return 0;

+}

+

+/**

+  Read data from serial device and save the data in buffer.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Size of Buffer[].

+

+  @retval 0                Read data failed.

+  @retval !0               Actual number of bytes read from serial device.

+

+**/

+UINTN

+EFIAPI

+SerialPortRead (

+  OUT UINT8     *Buffer,

+  IN  UINTN     NumberOfBytes

+)

+{

+  return 0;

+}

+

+/**

+  Check to see if any data is available to be read from the debug device.

+

+  @retval TRUE       At least one byte of data is available to be read

+  @retval FALSE      No data is available to be read

+

+**/

+BOOLEAN

+EFIAPI

+SerialPortPoll (

+  VOID

+  )

+{

+  return FALSE;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.inf
new file mode 100644
index 0000000..d62f87b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.inf
@@ -0,0 +1,45 @@
+#/** @file

+#

+#  Component description file for EarlyFdtPL011SerialPortLib module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = EarlyFdtPL011SerialPortLib

+  FILE_GUID                      = 0983616A-49BC-4732-B531-4AF98D2056F0

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = SerialPortLib|SEC PEI_CORE PEIM

+

+[Sources.common]

+  EarlyFdtPL011SerialPortLib.c

+

+[LibraryClasses]

+  PL011UartLib

+  PcdLib

+  FdtLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec

+

+[FixedPcd]

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress

+

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
new file mode 100644
index 0000000..aced666
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
@@ -0,0 +1,150 @@
+/** @file

+  Serial I/O Port library functions with base address discovered from FDT

+

+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>

+  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+  Copyright (c) 2014, Red Hat, Inc.<BR>

+

+  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 <Base.h>

+

+#include <Library/PcdLib.h>

+#include <Library/SerialPortLib.h>

+#include <Pi/PiBootMode.h>

+#include <Uefi/UefiBaseType.h>

+#include <Uefi/UefiMultiPhase.h>

+#include <Pi/PiHob.h>

+#include <Library/HobLib.h>

+#include <Guid/EarlyPL011BaseAddress.h>

+

+#include <Drivers/PL011Uart.h>

+

+STATIC UINTN mSerialBaseAddress;

+

+RETURN_STATUS

+EFIAPI

+SerialPortInitialize (

+  VOID

+  )

+{

+  return RETURN_SUCCESS;

+}

+

+/**

+

+  Program hardware of Serial port

+

+  @return    RETURN_NOT_FOUND if no PL011 base address could be found

+             Otherwise, result of PL011UartInitializePort () is returned

+

+**/

+RETURN_STATUS

+EFIAPI

+FdtPL011SerialPortLibInitialize (

+  VOID

+  )

+{

+  VOID                *Hob;

+  CONST UINT64        *UartBase;

+  UINT64              BaudRate;

+  UINT32              ReceiveFifoDepth;

+  EFI_PARITY_TYPE     Parity;

+  UINT8               DataBits;

+  EFI_STOP_BITS_TYPE  StopBits;

+

+  Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid);

+  if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase) {

+    return RETURN_NOT_FOUND;

+  }

+  UartBase = GET_GUID_HOB_DATA (Hob);

+

+  mSerialBaseAddress = (UINTN)*UartBase;

+  if (mSerialBaseAddress == 0) {

+    return RETURN_NOT_FOUND;

+  }

+

+  BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);

+  ReceiveFifoDepth = 0; // Use the default value for Fifo depth

+  Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);

+  DataBits = PcdGet8 (PcdUartDefaultDataBits);

+  StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);

+

+  return PL011UartInitializePort (

+           mSerialBaseAddress, &BaudRate, &ReceiveFifoDepth,

+           &Parity, &DataBits, &StopBits);

+}

+

+/**

+  Write data to serial device.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Write data failed.

+  @retval !0               Actual number of bytes written to serial device.

+

+**/

+UINTN

+EFIAPI

+SerialPortWrite (

+  IN UINT8     *Buffer,

+  IN UINTN     NumberOfBytes

+  )

+{

+  if (mSerialBaseAddress != 0) {

+    return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes);

+  }

+  return 0;

+}

+

+/**

+  Read data from serial device and save the data in buffer.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Read data failed.

+  @retval !0               Actual number of bytes read from serial device.

+

+**/

+UINTN

+EFIAPI

+SerialPortRead (

+  OUT UINT8     *Buffer,

+  IN  UINTN     NumberOfBytes

+)

+{

+  if (mSerialBaseAddress != 0) {

+    return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes);

+  }

+  return 0;

+}

+

+/**

+  Check to see if any data is available to be read from the debug device.

+

+  @retval TRUE       At least one byte of data is available to be read

+  @retval FALSE      No data is available to be read

+

+**/

+BOOLEAN

+EFIAPI

+SerialPortPoll (

+  VOID

+  )

+{

+  if (mSerialBaseAddress != 0) {

+    return PL011UartPoll (mSerialBaseAddress);

+  }

+  return FALSE;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf
new file mode 100644
index 0000000..9145afa
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.inf
@@ -0,0 +1,48 @@
+#/** @file

+#

+#  Component description file for PL011SerialPortLib module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = FdtPL011SerialPortLib

+  FILE_GUID                      = CB768406-7DE6-49B6-BC2C-F324E110DE5A

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = SerialPortLib|DXE_CORE DXE_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION

+  CONSTRUCTOR                    = FdtPL011SerialPortLibInitialize

+

+[Sources.common]

+  FdtPL011SerialPortLib.c

+

+[LibraryClasses]

+  PL011UartLib

+  HobLib

+

+[Packages]

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec

+  ArmPkg/ArmPkg.dec

+

+[FixedPcd]

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits

+

+[Guids]

+  gEarlyPL011BaseAddressGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c
new file mode 100644
index 0000000..7f34607
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c
@@ -0,0 +1,51 @@
+/** @file

+

+ Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+

+ 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 <ArmPlatform.h>

+#include <Library/NorFlashPlatformLib.h>

+

+EFI_STATUS

+NorFlashPlatformInitialization (

+  VOID

+  )

+{

+  return EFI_SUCCESS;

+}

+

+NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {

+  {

+    QEMU_NOR0_BASE,

+    QEMU_NOR0_BASE,

+    QEMU_NOR0_SIZE,

+    QEMU_NOR_BLOCK_SIZE,

+    {0xF9B94AE2, 0x8BA6, 0x409B, {0x9D, 0x56, 0xB9, 0xB4, 0x17, 0xF5, 0x3C, 0xB3}}

+  }, {

+    QEMU_NOR1_BASE,

+    QEMU_NOR1_BASE,

+    QEMU_NOR1_SIZE,

+    QEMU_NOR_BLOCK_SIZE,

+    {0x8047DB4B, 0x7E9C, 0x4C0C, {0x8E, 0xBC, 0xDF, 0xBB, 0xAA, 0xCA, 0xCE, 0x8F}}

+  }

+};

+

+EFI_STATUS

+NorFlashPlatformGetDevices (

+  OUT NOR_FLASH_DESCRIPTION   **NorFlashDescriptions,

+  OUT UINT32                  *Count

+  )

+{

+  *NorFlashDescriptions = mNorFlashDevices;

+  *Count = sizeof (mNorFlashDevices) / sizeof (mNorFlashDevices[0]);

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
new file mode 100644
index 0000000..126d167
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
@@ -0,0 +1,30 @@
+#/** @file

+#

+#  Component description file for NorFlashQemuLib module

+#

+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = NorFlashQemuLib

+  FILE_GUID                      = 339B7829-4C5F-4EFC-B2DD-5050E530DECE

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = NorFlashPlatformLib

+

+[Sources.common]

+  NorFlashQemuLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
new file mode 100644
index 0000000..a03e909
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
@@ -0,0 +1,379 @@
+/** @file

+

+Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+

+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 "IntelBdsPlatform.h"

+

+#include <Library/QemuBootOrderLib.h>

+

+//

+// BDS Platform Functions

+//

+/**

+  Platform Bds init. Include the platform firmware vendor, revision

+  and so crc check.

+

+**/

+VOID

+EFIAPI

+PlatformBdsInit (

+  VOID

+  )

+{

+}

+

+STATIC

+EFI_STATUS

+GetConsoleDevicePathFromVariable (

+  IN  CHAR16*             ConsoleVarName,

+  IN  CHAR16*             DefaultConsolePaths,

+  OUT EFI_DEVICE_PATH**   DevicePaths

+  )

+{

+  EFI_STATUS                Status;

+  UINTN                     Size;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;

+  CHAR16*                   DevicePathStr;

+  CHAR16*                   NextDevicePathStr;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;

+

+  Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);

+  if (EFI_ERROR (Status)) {

+    // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)

+    if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {

+      *DevicePaths = NULL;

+      return EFI_SUCCESS;

+    }

+

+    Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+    ASSERT_EFI_ERROR (Status);

+

+    DevicePathInstances = NULL;

+

+    // Extract the Device Path instances from the multi-device path string

+    while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {

+      NextDevicePathStr = StrStr (DefaultConsolePaths, L";");

+      if (NextDevicePathStr == NULL) {

+        DevicePathStr = DefaultConsolePaths;

+        DefaultConsolePaths = NULL;

+      } else {

+        DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof (CHAR16), DefaultConsolePaths);

+        *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';

+        DefaultConsolePaths = NextDevicePathStr;

+        if (DefaultConsolePaths[0] == L';') {

+          DefaultConsolePaths++;

+        }

+      }

+

+      DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);

+      ASSERT (DevicePathInstance != NULL);

+      DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);

+

+      if (NextDevicePathStr != NULL) {

+        FreePool (DevicePathStr);

+      }

+      FreePool (DevicePathInstance);

+    }

+

+    // Set the environment variable with this device path multi-instances

+    Size = GetDevicePathSize (DevicePathInstances);

+    if (Size > 0) {

+      gRT->SetVariable (

+          ConsoleVarName,

+          &gEfiGlobalVariableGuid,

+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+          Size,

+          DevicePathInstances

+          );

+    } else {

+      Status = EFI_INVALID_PARAMETER;

+    }

+  }

+

+  if (!EFI_ERROR (Status)) {

+    *DevicePaths = DevicePathInstances;

+  }

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+InitializeConsolePipe (

+  IN EFI_DEVICE_PATH    *ConsoleDevicePaths,

+  IN EFI_GUID           *Protocol,

+  OUT EFI_HANDLE        *Handle,

+  OUT VOID*             *Interface

+  )

+{

+  EFI_STATUS                Status;

+  UINTN                     Size;

+  UINTN                     NoHandles;

+  EFI_HANDLE                *Buffer;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePath;

+

+  // Connect all the Device Path Consoles

+  while (ConsoleDevicePaths != NULL) {

+    DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);

+

+    Status = BdsConnectDevicePath (DevicePath, Handle, NULL);

+    DEBUG_CODE_BEGIN ();

+      if (EFI_ERROR (Status)) {

+        // We convert back to the text representation of the device Path

+        EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+        CHAR16* DevicePathTxt;

+        EFI_STATUS Status;

+

+        Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+        if (!EFI_ERROR (Status)) {

+          DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);

+

+          DEBUG ((EFI_D_ERROR, "Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));

+

+          FreePool (DevicePathTxt);

+        }

+      }

+    DEBUG_CODE_END ();

+

+    // If the console splitter driver is not supported by the platform then use the first Device Path

+    // instance for the console interface.

+    if (!EFI_ERROR (Status) && (*Interface == NULL)) {

+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);

+    }

+  }

+

+  // No Device Path has been defined for this console interface. We take the first protocol implementation

+  if (*Interface == NULL) {

+    Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);

+    if (EFI_ERROR (Status)) {

+      BdsConnectAllDrivers ();

+      Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);

+    }

+

+    if (!EFI_ERROR (Status)) {

+      *Handle = Buffer[0];

+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);

+      ASSERT_EFI_ERROR (Status);

+    }

+    FreePool (Buffer);

+  } else {

+    Status = EFI_SUCCESS;

+  }

+

+  return Status;

+}

+

+/**

+  Connect the predefined platform default console device. Always try to find

+  and enable the vga device if have.

+

+  @param PlatformConsole          Predefined platform default console device array.

+

+  @retval EFI_SUCCESS             Success connect at least one ConIn and ConOut

+                                  device, there must have one ConOut device is

+                                  active vga device.

+  @return Return the status of BdsLibConnectAllDefaultConsoles ()

+

+**/

+EFI_STATUS

+PlatformBdsConnectConsole (

+  VOID

+  )

+{

+  EFI_STATUS                Status;

+  EFI_DEVICE_PATH*          ConOutDevicePaths;

+  EFI_DEVICE_PATH*          ConInDevicePaths;

+  EFI_DEVICE_PATH*          ConErrDevicePaths;

+

+  // By getting the Console Device Paths from the environment variables before initializing the console pipe, we

+  // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface

+  // of newly installed console drivers

+  Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr (PcdDefaultConOutPaths), &ConOutDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+  Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr (PcdDefaultConInPaths), &ConInDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+  Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr (PcdDefaultConOutPaths), &ConErrDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+

+  // Initialize the Consoles

+  Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);

+  ASSERT_EFI_ERROR (Status);

+  Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);

+  ASSERT_EFI_ERROR (Status);

+  Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);

+  if (EFI_ERROR (Status)) {

+    // In case of error, we reuse the console output for the error output

+    gST->StandardErrorHandle = gST->ConsoleOutHandle;

+    gST->StdErr = gST->ConOut;

+  }

+

+  return Status;

+}

+

+/**

+  Connect with predefined platform connect sequence,

+  the OEM/IBV can customize with their own connect sequence.

+**/

+VOID

+PlatformBdsConnectSequence (

+  VOID

+  )

+{

+}

+

+/**

+  Load the predefined driver option, OEM/IBV can customize this

+  to load their own drivers

+

+  @param BdsDriverLists  - The header of the driver option link list.

+

+**/

+VOID

+PlatformBdsGetDriverOption (

+  IN OUT LIST_ENTRY              *BdsDriverLists

+  )

+{

+}

+

+/**

+  Perform the platform diagnostic, such like test memory. OEM/IBV also

+  can customize this function to support specific platform diagnostic.

+

+  @param MemoryTestLevel  The memory test intensive level

+  @param QuietBoot        Indicate if need to enable the quiet boot

+  @param BaseMemoryTest   A pointer to BdsMemoryTest()

+

+**/

+VOID

+PlatformBdsDiagnostics (

+  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,

+  IN BOOLEAN                     QuietBoot,

+  IN BASEM_MEMORY_TEST           BaseMemoryTest

+  )

+{

+}

+

+/**

+  The function will execute with as the platform policy, current policy

+  is driven by boot mode. IBV/OEM can customize this code for their specific

+  policy action.

+

+  @param  DriverOptionList        The header of the driver option link list

+  @param  BootOptionList          The header of the boot option link list

+  @param  ProcessCapsules         A pointer to ProcessCapsules()

+  @param  BaseMemoryTest          A pointer to BaseMemoryTest()

+

+**/

+VOID

+EFIAPI

+PlatformBdsPolicyBehavior (

+  IN LIST_ENTRY                      *DriverOptionList,

+  IN LIST_ENTRY                      *BootOptionList,

+  IN PROCESS_CAPSULES                ProcessCapsules,

+  IN BASEM_MEMORY_TEST               BaseMemoryTest

+  )

+{

+  EFI_STATUS Status;

+

+  Status = PlatformBdsConnectConsole ();

+  ASSERT_EFI_ERROR (Status);

+

+  //

+  // Process QEMU's -kernel command line option

+  //

+  TryRunningQemuKernel ();

+

+  BdsLibConnectAll ();

+  BdsLibEnumerateAllBootOption (BootOptionList);

+

+  SetBootOrderFromQemu (BootOptionList);

+  //

+  // The BootOrder variable may have changed, reload the in-memory list with

+  // it.

+  //

+  BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");

+

+  PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE);

+}

+

+/**

+  Hook point after a boot attempt succeeds. We don't expect a boot option to

+  return, so the UEFI 2.0 specification defines that you will default to an

+  interactive mode and stop processing the BootOrder list in this case. This

+  is also a platform implementation and can be customized by IBV/OEM.

+

+  @param  Option                  Pointer to Boot Option that succeeded to boot.

+

+**/

+VOID

+EFIAPI

+PlatformBdsBootSuccess (

+  IN  BDS_COMMON_OPTION *Option

+  )

+{

+}

+

+/**

+  Hook point after a boot attempt fails.

+

+  @param  Option                  Pointer to Boot Option that failed to boot.

+  @param  Status                  Status returned from failed boot.

+  @param  ExitData                Exit data returned from failed boot.

+  @param  ExitDataSize            Exit data size returned from failed boot.

+

+**/

+VOID

+EFIAPI

+PlatformBdsBootFail (

+  IN  BDS_COMMON_OPTION  *Option,

+  IN  EFI_STATUS         Status,

+  IN  CHAR16             *ExitData,

+  IN  UINTN              ExitDataSize

+  )

+{

+}

+

+/**

+  This function locks platform flash that is not allowed to be updated during normal boot path.

+  The flash layout is platform specific.

+**/

+VOID

+EFIAPI

+PlatformBdsLockNonUpdatableFlash (

+  VOID

+  )

+{

+  return;

+}

+

+

+/**

+  Lock the ConsoleIn device in system table. All key

+  presses will be ignored until the Password is typed in. The only way to

+  disable the password is to type it in to a ConIn device.

+

+  @param  Password        Password used to lock ConIn device.

+

+  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.

+  @retval EFI_UNSUPPORTED Password not found

+

+**/

+EFI_STATUS

+EFIAPI

+LockKeyboards (

+  IN  CHAR16    *Password

+  )

+{

+    return EFI_UNSUPPORTED;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.h
new file mode 100644
index 0000000..cfc496d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.h
@@ -0,0 +1,63 @@
+/** @file

+  Head file for BDS Platform specific code

+

+Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>

+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 _INTEL_BDS_PLATFORM_H_

+#define _INTEL_BDS_PLATFORM_H_

+

+#include <Protocol/DevicePathFromText.h>

+#include <Protocol/DevicePathToText.h>

+

+#include <Library/BaseMemoryLib.h>

+#include <Library/BdsLib.h>

+#include <Library/DebugLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/BaseLib.h>

+#include <Library/PcdLib.h>

+#include <Library/GenericBdsLib.h>

+#include <Library/PlatformBdsLib.h>

+

+#include <Guid/GlobalVariable.h>

+

+VOID

+PlatformBdsEnterFrontPage (

+  IN UINT16                 TimeoutDefault,

+  IN BOOLEAN                ConnectAllHappened

+  );

+

+/**

+  Download the kernel, the initial ramdisk, and the kernel command line from

+  QEMU's fw_cfg. Construct a minimal SimpleFileSystem that contains the two

+  image files, and load and start the kernel from it.

+

+  The kernel will be instructed via its command line to load the initrd from

+  the same Simple FileSystem.

+

+  @retval EFI_NOT_FOUND         Kernel image was not found.

+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.

+  @retval EFI_PROTOCOL_ERROR    Unterminated kernel command line.

+

+  @return                       Error codes from any of the underlying

+                                functions. On success, the function doesn't

+                                return.

+**/

+EFI_STATUS

+EFIAPI

+TryRunningQemuKernel (

+  VOID

+  );

+

+#endif // _INTEL_BDS_PLATFORM_H

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf
new file mode 100644
index 0000000..6542705
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf
@@ -0,0 +1,75 @@
+## @file

+#  Implementation for PlatformBdsLib library class interfaces.

+#  using ARM Platform framework.

+#

+#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>

+#  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PlatformIntelBdsLib

+  FILE_GUID                      = 46DF84EB-F603-4D39-99D8-E1E86B50BCC2

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PlatformBdsLib|DXE_DRIVER

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+#  VALID_ARCHITECTURES           = ARM AARCH64

+#

+

+[Sources]

+  IntelBdsPlatform.c

+  IntelBdsPlatform.h

+  QemuKernel.c

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec

+  OvmfPkg/OvmfPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  BaseMemoryLib

+  BdsLib

+  DebugLib

+  DevicePathLib

+  MemoryAllocationLib

+  UefiBootServicesTableLib

+  PcdLib

+  GenericBdsLib

+  QemuBootOrderLib

+  QemuFwCfgLib

+  PrintLib

+  UefiRuntimeServicesTableLib

+

+[Guids]

+  gArmGlobalVariableGuid

+  gEfiFileInfoGuid

+  gEfiFileSystemInfoGuid

+  gEfiFileSystemVolumeLabelInfoIdGuid

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths

+

+[Protocols]

+  gEfiDevicePathFromTextProtocolGuid

+  gEfiDevicePathToTextProtocolGuid

+  gEfiDevicePathProtocolGuid

+  gEfiLoadedImageProtocolGuid

+  gEfiSimpleFileSystemProtocolGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/QemuKernel.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/QemuKernel.c
new file mode 100644
index 0000000..abcac77
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformIntelBdsLib/QemuKernel.c
@@ -0,0 +1,1103 @@
+/** @file

+  Try to load an EFI-stubbed ARM Linux kernel from QEMU's fw_cfg.

+

+  This implementation differs from OvmfPkg/Library/LoadLinuxLib. An EFI

+  stub in the subject kernel is a hard requirement here.

+

+  Copyright (C) 2014, Red Hat, Inc.

+

+  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 <Guid/FileInfo.h>

+#include <Guid/FileSystemInfo.h>

+#include <Guid/FileSystemVolumeLabelInfo.h>

+#include <Library/PrintLib.h>

+#include <Library/QemuFwCfgLib.h>

+#include <Protocol/DevicePath.h>

+#include <Protocol/LoadedImage.h>

+#include <Protocol/SimpleFileSystem.h>

+

+#include "IntelBdsPlatform.h"

+

+//

+// Static data that hosts the fw_cfg blobs and serves file requests.

+//

+typedef enum {

+  KernelBlobTypeKernel,

+  KernelBlobTypeInitrd,

+  KernelBlobTypeCommandLine,

+  KernelBlobTypeMax

+} KERNEL_BLOB_TYPE;

+

+typedef struct {

+  FIRMWARE_CONFIG_ITEM CONST SizeKey;

+  FIRMWARE_CONFIG_ITEM CONST DataKey;

+  CONST CHAR16 *       CONST Name;

+  UINT32                     Size;

+  UINT8                      *Data;

+} KERNEL_BLOB;

+

+STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] = {

+  { QemuFwCfgItemKernelSize,      QemuFwCfgItemKernelData,      L"kernel"  },

+  { QemuFwCfgItemInitrdSize,      QemuFwCfgItemInitrdData,      L"initrd"  },

+  { QemuFwCfgItemCommandLineSize, QemuFwCfgItemCommandLineData, L"cmdline" }

+};

+

+STATIC UINT64 mTotalBlobBytes;

+

+//

+// Device path for the handle that incorporates our "EFI stub filesystem". The

+// GUID is arbitrary and need not be standardized or advertized.

+//

+#pragma pack(1)

+typedef struct {

+  VENDOR_DEVICE_PATH       VenHwNode;

+  EFI_DEVICE_PATH_PROTOCOL EndNode;

+} SINGLE_VENHW_NODE_DEVPATH;

+#pragma pack()

+

+STATIC CONST SINGLE_VENHW_NODE_DEVPATH mFileSystemDevicePath = {

+  {

+    { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, { sizeof (VENDOR_DEVICE_PATH) } },

+    {

+      0xb0fae7e7, 0x6b07, 0x49d0,

+      { 0x9e, 0x5b, 0x3b, 0xde, 0xc8, 0x3b, 0x03, 0x9d }

+    }

+  },

+

+  {

+    END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,

+    { sizeof (EFI_DEVICE_PATH_PROTOCOL) }

+  }

+};

+

+//

+// The "file in the EFI stub filesystem" abstraction.

+//

+STATIC EFI_TIME mInitTime;

+

+#define STUB_FILE_SIG SIGNATURE_64 ('S', 'T', 'U', 'B', 'F', 'I', 'L', 'E')

+

+typedef struct {

+  UINT64            Signature; // Carries STUB_FILE_SIG.

+

+  KERNEL_BLOB_TYPE  BlobType;  // Index into mKernelBlob. KernelBlobTypeMax

+                               // denotes the root directory of the filesystem.

+

+  UINT64            Position;  // Byte position for regular files;

+                               // next directory entry to return for the root

+                               // directory.

+

+  EFI_FILE_PROTOCOL File;      // Standard protocol interface.

+} STUB_FILE;

+

+#define STUB_FILE_FROM_FILE(FilePointer) \

+        CR (FilePointer, STUB_FILE, File, STUB_FILE_SIG)

+

+//

+// Tentative definition of the file protocol template. The initializer

+// (external definition) will be provided later.

+//

+STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate;

+

+

+//

+// Protocol member functions for File.

+//

+

+/**

+  Opens a new file relative to the source file's location.

+

+  @param[in]  This        A pointer to the EFI_FILE_PROTOCOL instance that is

+                          the file handle to the source location. This would

+                          typically be an open handle to a directory.

+

+  @param[out] NewHandle   A pointer to the location to return the opened handle

+                          for the new file.

+

+  @param[in]  FileName    The Null-terminated string of the name of the file to

+                          be opened. The file name may contain the following

+                          path modifiers: "\", ".", and "..".

+

+  @param[in]  OpenMode    The mode to open the file. The only valid

+                          combinations that the file may be opened with are:

+                          Read, Read/Write, or Create/Read/Write.

+

+  @param[in]  Attributes  Only valid for EFI_FILE_MODE_CREATE, in which case

+                          these are the attribute bits for the newly created

+                          file.

+

+  @retval EFI_SUCCESS           The file was opened.

+  @retval EFI_NOT_FOUND         The specified file could not be found on the

+                                device.

+  @retval EFI_NO_MEDIA          The device has no medium.

+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the

+                                medium is no longer supported.

+  @retval EFI_DEVICE_ERROR      The device reported an error.

+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.

+  @retval EFI_WRITE_PROTECTED   An attempt was made to create a file, or open a

+                                file for write when the media is

+                                write-protected.

+  @retval EFI_ACCESS_DENIED     The service denied access to the file.

+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the

+                                file.

+  @retval EFI_VOLUME_FULL       The volume is full.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileOpen (

+  IN EFI_FILE_PROTOCOL  *This,

+  OUT EFI_FILE_PROTOCOL **NewHandle,

+  IN CHAR16             *FileName,

+  IN UINT64             OpenMode,

+  IN UINT64             Attributes

+  )

+{

+  CONST STUB_FILE *StubFile;

+  UINTN           BlobType;

+  STUB_FILE       *NewStubFile;

+

+  //

+  // We're read-only.

+  //

+  switch (OpenMode) {

+    case EFI_FILE_MODE_READ:

+      break;

+

+    case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:

+    case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE:

+      return EFI_WRITE_PROTECTED;

+

+    default:

+      return EFI_INVALID_PARAMETER;

+  }

+

+  //

+  // Only the root directory supports opening files in it.

+  //

+  StubFile = STUB_FILE_FROM_FILE (This);

+  if (StubFile->BlobType != KernelBlobTypeMax) {

+    return EFI_UNSUPPORTED;

+  }

+

+  //

+  // Locate the file.

+  //

+  for (BlobType = 0; BlobType < KernelBlobTypeMax; ++BlobType) {

+    if (StrCmp (FileName, mKernelBlob[BlobType].Name) == 0) {

+      break;

+    }

+  }

+  if (BlobType == KernelBlobTypeMax) {

+    return EFI_NOT_FOUND;

+  }

+

+  //

+  // Found it.

+  //

+  NewStubFile = AllocatePool (sizeof *NewStubFile);

+  if (NewStubFile == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  NewStubFile->Signature = STUB_FILE_SIG;

+  NewStubFile->BlobType  = (KERNEL_BLOB_TYPE)BlobType;

+  NewStubFile->Position  = 0;

+  CopyMem (&NewStubFile->File, &mEfiFileProtocolTemplate,

+    sizeof mEfiFileProtocolTemplate);

+  *NewHandle = &NewStubFile->File;

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Closes a specified file handle.

+

+  @param[in] This  A pointer to the EFI_FILE_PROTOCOL instance that is the file

+                   handle to close.

+

+  @retval EFI_SUCCESS  The file was closed.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileClose (

+  IN EFI_FILE_PROTOCOL *This

+  )

+{

+  FreePool (STUB_FILE_FROM_FILE (This));

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Close and delete the file handle.

+

+  @param[in] This  A pointer to the EFI_FILE_PROTOCOL instance that is the

+                   handle to the file to delete.

+

+  @retval EFI_SUCCESS              The file was closed and deleted, and the

+                                   handle was closed.

+  @retval EFI_WARN_DELETE_FAILURE  The handle was closed, but the file was not

+                                   deleted.

+

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileDelete (

+  IN EFI_FILE_PROTOCOL *This

+  )

+{

+  FreePool (STUB_FILE_FROM_FILE (This));

+  return EFI_WARN_DELETE_FAILURE;

+}

+

+

+/**

+  Helper function that formats an EFI_FILE_INFO structure into the

+  user-allocated buffer, for any valid KERNEL_BLOB_TYPE value (including

+  KernelBlobTypeMax, which stands for the root directory).

+

+  The interface follows the EFI_FILE_GET_INFO -- and for directories, the

+  EFI_FILE_READ -- interfaces.

+

+  @param[in]     BlobType     The KERNEL_BLOB_TYPE value identifying the fw_cfg

+                              blob backing the STUB_FILE that information is

+                              being requested about. If BlobType equals

+                              KernelBlobTypeMax, then information will be

+                              provided about the root directory of the

+                              filesystem.

+

+  @param[in,out] BufferSize  On input, the size of Buffer. On output, the

+                             amount of data returned in Buffer. In both cases,

+                             the size is measured in bytes.

+

+  @param[out]    Buffer      A pointer to the data buffer to return. The

+                             buffer's type is EFI_FILE_INFO.

+

+  @retval EFI_SUCCESS           The information was returned.

+  @retval EFI_BUFFER_TOO_SMALL  BufferSize is too small to store the

+                                EFI_FILE_INFO structure. BufferSize has been

+                                updated with the size needed to complete the

+                                request.

+**/

+STATIC

+EFI_STATUS

+ConvertKernelBlobTypeToFileInfo (

+  IN KERNEL_BLOB_TYPE BlobType,

+  IN OUT UINTN        *BufferSize,

+  OUT VOID            *Buffer

+  )

+{

+  CONST CHAR16  *Name;

+  UINT64        FileSize;

+  UINT64        Attribute;

+

+  UINTN         NameSize;

+  UINTN         FileInfoSize;

+  EFI_FILE_INFO *FileInfo;

+  UINTN         OriginalBufferSize;

+

+  if (BlobType == KernelBlobTypeMax) {

+    //

+    // getting file info about the root directory

+    //

+    Name      = L"\\";

+    FileSize  = KernelBlobTypeMax;

+    Attribute = EFI_FILE_READ_ONLY | EFI_FILE_DIRECTORY;

+  } else {

+    CONST KERNEL_BLOB *Blob;

+

+    Blob      = &mKernelBlob[BlobType];

+    Name      = Blob->Name;

+    FileSize  = Blob->Size;

+    Attribute = EFI_FILE_READ_ONLY;

+  }

+

+  NameSize     = (StrLen(Name) + 1) * 2;

+  FileInfoSize = OFFSET_OF (EFI_FILE_INFO, FileName) + NameSize;

+  ASSERT (FileInfoSize >= sizeof *FileInfo);

+

+  OriginalBufferSize = *BufferSize;

+  *BufferSize        = FileInfoSize;

+  if (OriginalBufferSize < *BufferSize) {

+    return EFI_BUFFER_TOO_SMALL;

+  }

+

+  FileInfo               = (EFI_FILE_INFO *)Buffer;

+  FileInfo->Size         = FileInfoSize;

+  FileInfo->FileSize     = FileSize;

+  FileInfo->PhysicalSize = FileSize;

+  FileInfo->Attribute    = Attribute;

+

+  CopyMem (&FileInfo->CreateTime,       &mInitTime, sizeof mInitTime);

+  CopyMem (&FileInfo->LastAccessTime,   &mInitTime, sizeof mInitTime);

+  CopyMem (&FileInfo->ModificationTime, &mInitTime, sizeof mInitTime);

+  CopyMem (FileInfo->FileName,          Name,       NameSize);

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Reads data from a file, or continues scanning a directory.

+

+  @param[in]     This        A pointer to the EFI_FILE_PROTOCOL instance that

+                             is the file handle to read data from.

+

+  @param[in,out] BufferSize  On input, the size of the Buffer. On output, the

+                             amount of data returned in Buffer. In both cases,

+                             the size is measured in bytes. If the read goes

+                             beyond the end of the file, the read length is

+                             truncated to the end of the file.

+

+                             If This is a directory, the function reads the

+                             directory entry at the current position and

+                             returns the entry (as EFI_FILE_INFO) in Buffer. If

+                             there are no more directory entries, the

+                             BufferSize is set to zero on output.

+

+  @param[out]    Buffer      The buffer into which the data is read.

+

+  @retval EFI_SUCCESS           Data was read.

+  @retval EFI_NO_MEDIA          The device has no medium.

+  @retval EFI_DEVICE_ERROR      The device reported an error.

+  @retval EFI_DEVICE_ERROR      An attempt was made to read from a deleted

+                                file.

+  @retval EFI_DEVICE_ERROR      On entry, the current file position is beyond

+                                the end of the file.

+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.

+  @retval EFI_BUFFER_TOO_SMALL  The BufferSize is too small to store the

+                                current directory entry as a EFI_FILE_INFO

+                                structure. BufferSize has been updated with the

+                                size needed to complete the request, and the

+                                directory position has not been advanced.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileRead (

+  IN EFI_FILE_PROTOCOL *This,

+  IN OUT UINTN         *BufferSize,

+  OUT VOID             *Buffer

+  )

+{

+  STUB_FILE         *StubFile;

+  CONST KERNEL_BLOB *Blob;

+  UINT64            Left;

+

+  StubFile = STUB_FILE_FROM_FILE (This);

+

+  //

+  // Scanning the root directory?

+  //

+  if (StubFile->BlobType == KernelBlobTypeMax) {

+    EFI_STATUS Status;

+

+    if (StubFile->Position == KernelBlobTypeMax) {

+      //

+      // Scanning complete.

+      //

+      *BufferSize = 0;

+      return EFI_SUCCESS;

+    }

+

+    Status = ConvertKernelBlobTypeToFileInfo (StubFile->Position, BufferSize,

+               Buffer);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    ++StubFile->Position;

+    return EFI_SUCCESS;

+  }

+

+  //

+  // Reading a file.

+  //

+  Blob = &mKernelBlob[StubFile->BlobType];

+  if (StubFile->Position > Blob->Size) {

+    return EFI_DEVICE_ERROR;

+  }

+

+  Left = Blob->Size - StubFile->Position;

+  if (*BufferSize > Left) {

+    *BufferSize = (UINTN)Left;

+  }

+  if (Blob->Data != NULL) {

+    CopyMem (Buffer, Blob->Data + StubFile->Position, *BufferSize);

+  }

+  StubFile->Position += *BufferSize;

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Writes data to a file.

+

+  @param[in]     This        A pointer to the EFI_FILE_PROTOCOL instance that

+                             is the file handle to write data to.

+

+  @param[in,out] BufferSize  On input, the size of the Buffer. On output, the

+                             amount of data actually written. In both cases,

+                             the size is measured in bytes.

+

+  @param[in]     Buffer      The buffer of data to write.

+

+  @retval EFI_SUCCESS           Data was written.

+  @retval EFI_UNSUPPORTED       Writes to open directory files are not

+                                supported.

+  @retval EFI_NO_MEDIA          The device has no medium.

+  @retval EFI_DEVICE_ERROR      The device reported an error.

+  @retval EFI_DEVICE_ERROR      An attempt was made to write to a deleted file.

+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.

+  @retval EFI_WRITE_PROTECTED   The file or medium is write-protected.

+  @retval EFI_ACCESS_DENIED     The file was opened read only.

+  @retval EFI_VOLUME_FULL       The volume is full.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileWrite (

+  IN EFI_FILE_PROTOCOL *This,

+  IN OUT UINTN         *BufferSize,

+  IN VOID              *Buffer

+  )

+{

+  STUB_FILE *StubFile;

+

+  StubFile = STUB_FILE_FROM_FILE (This);

+  return (StubFile->BlobType == KernelBlobTypeMax) ?

+         EFI_UNSUPPORTED :

+         EFI_WRITE_PROTECTED;

+}

+

+

+/**

+  Returns a file's current position.

+

+  @param[in]  This      A pointer to the EFI_FILE_PROTOCOL instance that is the

+                        file handle to get the current position on.

+

+  @param[out] Position  The address to return the file's current position

+                        value.

+

+  @retval EFI_SUCCESS      The position was returned.

+  @retval EFI_UNSUPPORTED  The request is not valid on open directories.

+  @retval EFI_DEVICE_ERROR An attempt was made to get the position from a

+                           deleted file.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileGetPosition (

+  IN EFI_FILE_PROTOCOL *This,

+  OUT UINT64           *Position

+  )

+{

+  STUB_FILE *StubFile;

+

+  StubFile = STUB_FILE_FROM_FILE (This);

+  if (StubFile->BlobType == KernelBlobTypeMax) {

+    return EFI_UNSUPPORTED;

+  }

+

+  *Position = StubFile->Position;

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Sets a file's current position.

+

+  @param[in] This      A pointer to the EFI_FILE_PROTOCOL instance that is the

+                       file handle to set the requested position on.

+

+  @param[in] Position  The byte position from the start of the file to set. For

+                       regular files, MAX_UINT64 means "seek to end". For

+                       directories, zero means "rewind directory scan".

+

+  @retval EFI_SUCCESS       The position was set.

+  @retval EFI_UNSUPPORTED   The seek request for nonzero is not valid on open

+                            directories.

+  @retval EFI_DEVICE_ERROR  An attempt was made to set the position of a

+                            deleted file.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileSetPosition (

+  IN EFI_FILE_PROTOCOL *This,

+  IN UINT64            Position

+  )

+{

+  STUB_FILE   *StubFile;

+  KERNEL_BLOB *Blob;

+

+  StubFile = STUB_FILE_FROM_FILE (This);

+

+  if (StubFile->BlobType == KernelBlobTypeMax) {

+    if (Position == 0) {

+      //

+      // rewinding a directory scan is allowed

+      //

+      StubFile->Position = 0;

+      return EFI_SUCCESS;

+    }

+    return EFI_UNSUPPORTED;

+  }

+

+  //

+  // regular file seek

+  //

+  Blob = &mKernelBlob[StubFile->BlobType];

+  if (Position == MAX_UINT64) {

+    //

+    // seek to end

+    //

+    StubFile->Position = Blob->Size;

+  } else {

+    //

+    // absolute seek from beginning -- seeking past the end is allowed

+    //

+    StubFile->Position = Position;

+  }

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Returns information about a file.

+

+  @param[in]     This             A pointer to the EFI_FILE_PROTOCOL instance

+                                  that is the file handle the requested

+                                  information is for.

+

+  @param[in]     InformationType  The type identifier GUID for the information

+                                  being requested. The following information

+                                  types are supported, storing the

+                                  corresponding structures in Buffer:

+

+                                  - gEfiFileInfoGuid: EFI_FILE_INFO

+

+                                  - gEfiFileSystemInfoGuid:

+                                    EFI_FILE_SYSTEM_INFO

+

+                                  - gEfiFileSystemVolumeLabelInfoIdGuid:

+                                    EFI_FILE_SYSTEM_VOLUME_LABEL

+

+  @param[in,out] BufferSize       On input, the size of Buffer. On output, the

+                                  amount of data returned in Buffer. In both

+                                  cases, the size is measured in bytes.

+

+  @param[out]    Buffer           A pointer to the data buffer to return. The

+                                  buffer's type is indicated by

+                                  InformationType.

+

+  @retval EFI_SUCCESS           The information was returned.

+  @retval EFI_UNSUPPORTED       The InformationType is not known.

+  @retval EFI_NO_MEDIA          The device has no medium.

+  @retval EFI_DEVICE_ERROR      The device reported an error.

+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.

+  @retval EFI_BUFFER_TOO_SMALL  The BufferSize is too small to store the

+                                information structure requested by

+                                InformationType. BufferSize has been updated

+                                with the size needed to complete the request.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileGetInfo (

+  IN EFI_FILE_PROTOCOL *This,

+  IN EFI_GUID          *InformationType,

+  IN OUT UINTN         *BufferSize,

+  OUT VOID             *Buffer

+  )

+{

+  CONST STUB_FILE *StubFile;

+  UINTN           OriginalBufferSize;

+

+  StubFile = STUB_FILE_FROM_FILE (This);

+

+  if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {

+    return ConvertKernelBlobTypeToFileInfo (StubFile->BlobType, BufferSize,

+             Buffer);

+  }

+

+  OriginalBufferSize = *BufferSize;

+

+  if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {

+    EFI_FILE_SYSTEM_INFO *FileSystemInfo;

+

+    *BufferSize = sizeof *FileSystemInfo;

+    if (OriginalBufferSize < *BufferSize) {

+      return EFI_BUFFER_TOO_SMALL;

+    }

+

+    FileSystemInfo                 = (EFI_FILE_SYSTEM_INFO *)Buffer;

+    FileSystemInfo->Size           = sizeof *FileSystemInfo;

+    FileSystemInfo->ReadOnly       = TRUE;

+    FileSystemInfo->VolumeSize     = mTotalBlobBytes;

+    FileSystemInfo->FreeSpace      = 0;

+    FileSystemInfo->BlockSize      = 1;

+    FileSystemInfo->VolumeLabel[0] = L'\0';

+

+    return EFI_SUCCESS;

+  }

+

+  if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {

+    EFI_FILE_SYSTEM_VOLUME_LABEL *FileSystemVolumeLabel;

+

+    *BufferSize = sizeof *FileSystemVolumeLabel;

+    if (OriginalBufferSize < *BufferSize) {

+      return EFI_BUFFER_TOO_SMALL;

+    }

+

+    FileSystemVolumeLabel = (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer;

+    FileSystemVolumeLabel->VolumeLabel[0] = L'\0';

+

+    return EFI_SUCCESS;

+  }

+

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  Sets information about a file.

+

+  @param[in] File             A pointer to the EFI_FILE_PROTOCOL instance that

+                              is the file handle the information is for.

+

+  @param[in] InformationType  The type identifier for the information being

+                              set.

+

+  @param[in] BufferSize       The size, in bytes, of Buffer.

+

+  @param[in] Buffer           A pointer to the data buffer to write. The

+                              buffer's type is indicated by InformationType.

+

+  @retval EFI_SUCCESS           The information was set.

+  @retval EFI_UNSUPPORTED       The InformationType is not known.

+  @retval EFI_NO_MEDIA          The device has no medium.

+  @retval EFI_DEVICE_ERROR      The device reported an error.

+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.

+  @retval EFI_WRITE_PROTECTED   InformationType is EFI_FILE_INFO_ID and the

+                                media is read-only.

+  @retval EFI_WRITE_PROTECTED   InformationType is

+                                EFI_FILE_PROTOCOL_SYSTEM_INFO_ID and the media

+                                is read only.

+  @retval EFI_WRITE_PROTECTED   InformationType is

+                                EFI_FILE_SYSTEM_VOLUME_LABEL_ID and the media

+                                is read-only.

+  @retval EFI_ACCESS_DENIED     An attempt is made to change the name of a file

+                                to a file that is already present.

+  @retval EFI_ACCESS_DENIED     An attempt is being made to change the

+                                EFI_FILE_DIRECTORY Attribute.

+  @retval EFI_ACCESS_DENIED     An attempt is being made to change the size of

+                                a directory.

+  @retval EFI_ACCESS_DENIED     InformationType is EFI_FILE_INFO_ID and the

+                                file was opened read-only and an attempt is

+                                being made to modify a field other than

+                                Attribute.

+  @retval EFI_VOLUME_FULL       The volume is full.

+  @retval EFI_BAD_BUFFER_SIZE   BufferSize is smaller than the size of the type

+                                indicated by InformationType.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileSetInfo (

+  IN EFI_FILE_PROTOCOL *This,

+  IN EFI_GUID          *InformationType,

+  IN UINTN             BufferSize,

+  IN VOID              *Buffer

+  )

+{

+  return EFI_WRITE_PROTECTED;

+}

+

+

+/**

+  Flushes all modified data associated with a file to a device.

+

+  @param [in] This  A pointer to the EFI_FILE_PROTOCOL instance that is the

+                    file handle to flush.

+

+  @retval EFI_SUCCESS           The data was flushed.

+  @retval EFI_NO_MEDIA          The device has no medium.

+  @retval EFI_DEVICE_ERROR      The device reported an error.

+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.

+  @retval EFI_WRITE_PROTECTED   The file or medium is write-protected.

+  @retval EFI_ACCESS_DENIED     The file was opened read-only.

+  @retval EFI_VOLUME_FULL       The volume is full.

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileFlush (

+  IN EFI_FILE_PROTOCOL *This

+  )

+{

+  return EFI_WRITE_PROTECTED;

+}

+

+//

+// External definition of the file protocol template.

+//

+STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate = {

+  EFI_FILE_PROTOCOL_REVISION, // revision 1

+  StubFileOpen,

+  StubFileClose,

+  StubFileDelete,

+  StubFileRead,

+  StubFileWrite,

+  StubFileGetPosition,

+  StubFileSetPosition,

+  StubFileGetInfo,

+  StubFileSetInfo,

+  StubFileFlush,

+  NULL,                       // OpenEx, revision 2

+  NULL,                       // ReadEx, revision 2

+  NULL,                       // WriteEx, revision 2

+  NULL                        // FlushEx, revision 2

+};

+

+

+//

+// Protocol member functions for SimpleFileSystem.

+//

+

+/**

+  Open the root directory on a volume.

+

+  @param[in]  This  A pointer to the volume to open the root directory on.

+

+  @param[out] Root  A pointer to the location to return the opened file handle

+                    for the root directory in.

+

+  @retval EFI_SUCCESS           The device was opened.

+  @retval EFI_UNSUPPORTED       This volume does not support the requested file

+                                system type.

+  @retval EFI_NO_MEDIA          The device has no medium.

+  @retval EFI_DEVICE_ERROR      The device reported an error.

+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.

+  @retval EFI_ACCESS_DENIED     The service denied access to the file.

+  @retval EFI_OUT_OF_RESOURCES  The volume was not opened due to lack of

+                                resources.

+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the

+                                medium is no longer supported. Any existing

+                                file handles for this volume are no longer

+                                valid. To access the files on the new medium,

+                                the volume must be reopened with OpenVolume().

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+StubFileSystemOpenVolume (

+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,

+  OUT EFI_FILE_PROTOCOL              **Root

+  )

+{

+  STUB_FILE *StubFile;

+

+  StubFile = AllocatePool (sizeof *StubFile);

+  if (StubFile == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  StubFile->Signature = STUB_FILE_SIG;

+  StubFile->BlobType  = KernelBlobTypeMax;

+  StubFile->Position  = 0;

+  CopyMem (&StubFile->File, &mEfiFileProtocolTemplate,

+    sizeof mEfiFileProtocolTemplate);

+  *Root = &StubFile->File;

+

+  return EFI_SUCCESS;

+}

+

+STATIC CONST EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mFileSystem = {

+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,

+  StubFileSystemOpenVolume

+};

+

+

+//

+// Utility functions.

+//

+

+/**

+  Populate a blob in mKernelBlob.

+

+  param[in,out] Blob  Pointer to the KERNEL_BLOB element in mKernelBlob that is

+                      to be filled from fw_cfg.

+

+  @retval EFI_SUCCESS           Blob has been populated. If fw_cfg reported a

+                                size of zero for the blob, then Blob->Data has

+                                been left unchanged.

+

+  @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory for Blob->Data.

+**/

+STATIC

+EFI_STATUS

+FetchBlob (

+  IN OUT KERNEL_BLOB *Blob

+  )

+{

+  UINT32 Left;

+

+  //

+  // Read blob size.

+  //

+  QemuFwCfgSelectItem (Blob->SizeKey);

+  Blob->Size = QemuFwCfgRead32 ();

+  if (Blob->Size == 0) {

+    return EFI_SUCCESS;

+  }

+

+  //

+  // Read blob.

+  //

+  Blob->Data = AllocatePool (Blob->Size);

+  if (Blob->Data == NULL) {

+    DEBUG ((EFI_D_ERROR, "%a: failed to allocate %Ld bytes for \"%s\"\n",

+      __FUNCTION__, (INT64)Blob->Size, Blob->Name));

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  DEBUG ((EFI_D_INFO, "%a: loading %Ld bytes for \"%s\"\n", __FUNCTION__,

+    (INT64)Blob->Size, Blob->Name));

+  QemuFwCfgSelectItem (Blob->DataKey);

+

+  Left = Blob->Size;

+  do {

+    UINT32 Chunk;

+

+    Chunk = (Left < SIZE_1MB) ? Left : SIZE_1MB;

+    QemuFwCfgReadBytes (Chunk, Blob->Data + (Blob->Size - Left));

+    Left -= Chunk;

+    DEBUG ((EFI_D_VERBOSE, "%a: %Ld bytes remaining for \"%s\"\n",

+      __FUNCTION__, (INT64)Left, Blob->Name));

+  } while (Left > 0);

+  return EFI_SUCCESS;

+}

+

+

+//

+// The entry point of the feature.

+//

+

+/**

+  Download the kernel, the initial ramdisk, and the kernel command line from

+  QEMU's fw_cfg. Construct a minimal SimpleFileSystem that contains the two

+  image files, and load and start the kernel from it.

+

+  The kernel will be instructed via its command line to load the initrd from

+  the same Simple FileSystem.

+

+  @retval EFI_NOT_FOUND         Kernel image was not found.

+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.

+  @retval EFI_PROTOCOL_ERROR    Unterminated kernel command line.

+

+  @return                       Error codes from any of the underlying

+                                functions. On success, the function doesn't

+                                return.

+**/

+EFI_STATUS

+EFIAPI

+TryRunningQemuKernel (

+  VOID

+  )

+{

+  UINTN                     BlobType;

+  KERNEL_BLOB               *CurrentBlob;

+  KERNEL_BLOB               *KernelBlob, *InitrdBlob, *CommandLineBlob;

+  EFI_STATUS                Status;

+  EFI_HANDLE                FileSystemHandle;

+  EFI_DEVICE_PATH_PROTOCOL  *KernelDevicePath;

+  EFI_HANDLE                KernelImageHandle;

+  EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage;

+

+  Status = gRT->GetTime (&mInitTime, NULL /* Capabilities */);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "%a: GetTime(): %r\n", __FUNCTION__, Status));

+    return Status;

+  }

+

+  //

+  // Fetch all blobs.

+  //

+  for (BlobType = 0; BlobType < KernelBlobTypeMax; ++BlobType) {

+    CurrentBlob = &mKernelBlob[BlobType];

+    Status = FetchBlob (CurrentBlob);

+    if (EFI_ERROR (Status)) {

+      goto FreeBlobs;

+    }

+    mTotalBlobBytes += CurrentBlob->Size;

+  }

+  KernelBlob      = &mKernelBlob[KernelBlobTypeKernel];

+  InitrdBlob      = &mKernelBlob[KernelBlobTypeInitrd];

+  CommandLineBlob = &mKernelBlob[KernelBlobTypeCommandLine];

+

+  //

+  // Create a new handle with a single VenHw() node device path protocol on it,

+  // plus a custom SimpleFileSystem protocol on it.

+  //

+  FileSystemHandle = NULL;

+  Status = gBS->InstallMultipleProtocolInterfaces (&FileSystemHandle,

+                  &gEfiDevicePathProtocolGuid,       &mFileSystemDevicePath,

+                  &gEfiSimpleFileSystemProtocolGuid, &mFileSystem,

+                  NULL);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "%a: InstallMultipleProtocolInterfaces(): %r\n",

+      __FUNCTION__, Status));

+    goto FreeBlobs;

+  }

+

+  //

+  // Create a device path for the kernel image to be loaded from that will call

+  // back into our file system.

+  //

+  KernelDevicePath = FileDevicePath (FileSystemHandle, KernelBlob->Name);

+  if (KernelDevicePath == NULL) {

+    DEBUG ((EFI_D_ERROR, "%a: failed to allocate kernel device path\n",

+      __FUNCTION__));

+    Status = EFI_OUT_OF_RESOURCES;

+    goto UninstallProtocols;

+  }

+

+  //

+  // Load the image. This should call back into our file system.

+  //

+  Status = gBS->LoadImage (

+                  FALSE,             // BootPolicy: exact match required

+                  gImageHandle,      // ParentImageHandle

+                  KernelDevicePath,

+                  NULL,              // SourceBuffer

+                  0,                 // SourceSize

+                  &KernelImageHandle

+                  );

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "%a: LoadImage(): %r\n", __FUNCTION__, Status));

+    goto FreeKernelDevicePath;

+  }

+

+  //

+  // Construct the kernel command line.

+  //

+  Status = gBS->OpenProtocol (

+                  KernelImageHandle,

+                  &gEfiLoadedImageProtocolGuid,

+                  (VOID **)&KernelLoadedImage,

+                  gImageHandle,                  // AgentHandle

+                  NULL,                          // ControllerHandle

+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  if (CommandLineBlob->Data == NULL) {

+    KernelLoadedImage->LoadOptionsSize = 0;

+  } else {

+    //

+    // Verify NUL-termination of the command line.

+    //

+    if (CommandLineBlob->Data[CommandLineBlob->Size - 1] != '\0') {

+      DEBUG ((EFI_D_ERROR, "%a: kernel command line is not NUL-terminated\n",

+        __FUNCTION__));

+      Status = EFI_PROTOCOL_ERROR;

+      goto UnloadKernelImage;

+    }

+

+    //

+    // Drop the terminating NUL, convert to UTF-16.

+    //

+    KernelLoadedImage->LoadOptionsSize = (CommandLineBlob->Size - 1) * 2;

+  }

+

+  if (InitrdBlob->Data != NULL) {

+    //

+    // Append ' initrd=<name>' in UTF-16.

+    //

+    KernelLoadedImage->LoadOptionsSize +=

+                                        (8 + StrLen(InitrdBlob->Name)) * 2;

+  }

+

+  if (KernelLoadedImage->LoadOptionsSize == 0) {

+    KernelLoadedImage->LoadOptions = NULL;

+  } else {

+    //

+    // NUL-terminate in UTF-16.

+    //

+    KernelLoadedImage->LoadOptionsSize += 2;

+

+    KernelLoadedImage->LoadOptions = AllocatePool (

+                                       KernelLoadedImage->LoadOptionsSize);

+    if (KernelLoadedImage->LoadOptions == NULL) {

+      KernelLoadedImage->LoadOptionsSize = 0;

+      Status = EFI_OUT_OF_RESOURCES;

+      goto UnloadKernelImage;

+    }

+

+    UnicodeSPrintAsciiFormat (

+      KernelLoadedImage->LoadOptions,

+      KernelLoadedImage->LoadOptionsSize,

+      "%a%a%s",

+      (CommandLineBlob->Data == NULL) ?  "" : (CHAR8 *)CommandLineBlob->Data,

+      (InitrdBlob->Data      == NULL) ?  "" : " initrd=",

+      (InitrdBlob->Data      == NULL) ? L"" : InitrdBlob->Name

+      );

+    DEBUG ((EFI_D_INFO, "%a: command line: \"%s\"\n", __FUNCTION__,

+      (CHAR16 *)KernelLoadedImage->LoadOptions));

+  }

+

+  //

+  // Start the image.

+  //

+  Status = gBS->StartImage (

+                KernelImageHandle,

+                NULL,              // ExitDataSize

+                NULL               // ExitData

+                );

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "%a: StartImage(): %r\n", __FUNCTION__, Status));

+  }

+

+  if (KernelLoadedImage->LoadOptions != NULL) {

+    FreePool (KernelLoadedImage->LoadOptions);

+  }

+  KernelLoadedImage->LoadOptionsSize = 0;

+

+UnloadKernelImage:

+  gBS->UnloadImage (KernelImageHandle);

+

+FreeKernelDevicePath:

+  FreePool (KernelDevicePath);

+

+UninstallProtocols:

+  gBS->UninstallMultipleProtocolInterfaces (FileSystemHandle,

+         &gEfiSimpleFileSystemProtocolGuid, &mFileSystem,

+         &gEfiDevicePathProtocolGuid,       &mFileSystemDevicePath,

+         NULL);

+

+FreeBlobs:

+  while (BlobType > 0) {

+    CurrentBlob = &mKernelBlob[--BlobType];

+    if (CurrentBlob->Data != NULL) {

+      FreePool (CurrentBlob->Data);

+      CurrentBlob->Size = 0;

+      CurrentBlob->Data = NULL;

+    }

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
new file mode 100644
index 0000000..af0d6e8
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
@@ -0,0 +1,47 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.

+*  Copyright (c) 2014, 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.

+*

+**/

+

+#include <PiPei.h>

+

+#include <Library/MemoryAllocationLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/PcdLib.h>

+#include <libfdt.h>

+

+EFI_STATUS

+EFIAPI

+PlatformPeim (

+  VOID

+  )

+{

+  VOID               *Base;

+  VOID               *NewBase;

+  UINTN              FdtSize;

+

+  Base = (VOID*)(UINTN)FixedPcdGet64 (PcdDeviceTreeInitialBaseAddress);

+  ASSERT (fdt_check_header (Base) == 0);

+

+  FdtSize = fdt_totalsize (Base);

+  NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));

+  ASSERT (NewBase != NULL);

+

+  CopyMem (NewBase, Base, FdtSize);

+  PcdSet64 (PcdDeviceTreeBaseAddress, (UINT64)(UINTN)NewBase);

+

+  BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
new file mode 100644
index 0000000..e544b52
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
@@ -0,0 +1,48 @@
+#/** @file

+#

+#  Copyright (c) 2011-2012, ARM Limited. All rights reserved.

+#  Copyright (c) 2014, 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PlatformPeiLib

+  FILE_GUID                      = 59C11815-F8DA-4F49-B4FB-EC1E41ED1F06

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PlatformPeiLib

+

+[Sources]

+  PlatformPeiLib.c

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  HobLib

+  FdtLib

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdFvSize

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress

+

+[Pcd]

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress

+

+[Depex]

+  gEfiPeiMemoryDiscoveredPpiGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
new file mode 100644
index 0000000..e9e96d7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
@@ -0,0 +1,358 @@
+/** @file

+

+  Stateful and implicitly initialized fw_cfg library implementation.

+

+  Copyright (C) 2013 - 2014, Red Hat, Inc.

+  Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>

+

+  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 <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+#include <Library/QemuFwCfgLib.h>

+

+STATIC UINTN mFwCfgSelectorAddress;

+STATIC UINTN mFwCfgDataAddress;

+

+

+/**

+  Returns a boolean indicating if the firmware configuration interface is

+  available for library-internal purposes.

+

+  This function never changes fw_cfg state.

+

+  @retval TRUE   The interface is available internally.

+  @retval FALSE  The interface is not available internally.

+**/

+BOOLEAN

+EFIAPI

+InternalQemuFwCfgIsAvailable (

+  VOID

+  )

+{

+  return (BOOLEAN)(mFwCfgSelectorAddress != 0 && mFwCfgDataAddress != 0);

+}

+

+

+/**

+  Returns a boolean indicating if the firmware configuration interface

+  is available or not.

+

+  This function may change fw_cfg state.

+

+  @retval TRUE   The interface is available

+  @retval FALSE  The interface is not available

+

+**/

+BOOLEAN

+EFIAPI

+QemuFwCfgIsAvailable (

+  VOID

+  )

+{

+  return InternalQemuFwCfgIsAvailable ();

+}

+

+

+RETURN_STATUS

+EFIAPI

+QemuFwCfgInitialize (

+  VOID

+  )

+{

+  mFwCfgSelectorAddress = (UINTN)PcdGet64 (PcdFwCfgSelectorAddress);

+  mFwCfgDataAddress     = (UINTN)PcdGet64 (PcdFwCfgDataAddress);

+

+  if (InternalQemuFwCfgIsAvailable ()) {

+    UINT32 Signature;

+

+    QemuFwCfgSelectItem (QemuFwCfgItemSignature);

+    Signature = QemuFwCfgRead32 ();

+    if (Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) {

+      mFwCfgSelectorAddress = 0;

+      mFwCfgDataAddress     = 0;

+    }

+  }

+  return RETURN_SUCCESS;

+}

+

+

+/**

+  Selects a firmware configuration item for reading.

+

+  Following this call, any data read from this item will start from the

+  beginning of the configuration item's data.

+

+  @param[in] QemuFwCfgItem  Firmware Configuration item to read

+

+**/

+VOID

+EFIAPI

+QemuFwCfgSelectItem (

+  IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem

+  )

+{

+  if (InternalQemuFwCfgIsAvailable ()) {

+    MmioWrite16 (mFwCfgSelectorAddress, SwapBytes16 ((UINT16)QemuFwCfgItem));

+  }

+}

+

+

+/**

+  Reads firmware configuration bytes into a buffer

+

+  @param[in] Size    Size in bytes to read

+  @param[in] Buffer  Buffer to store data into  (OPTIONAL if Size is 0)

+

+**/

+STATIC

+VOID

+EFIAPI

+InternalQemuFwCfgReadBytes (

+  IN UINTN Size,

+  IN VOID  *Buffer OPTIONAL

+  )

+{

+  UINTN Left;

+  UINT8 *Ptr;

+  UINT8 *End;

+

+#ifdef MDE_CPU_AARCH64

+  Left = Size & 7;

+#else

+  Left = Size & 3;

+#endif

+

+  Size -= Left;

+  Ptr = Buffer;

+  End = Ptr + Size;

+

+#ifdef MDE_CPU_AARCH64

+  while (Ptr < End) {

+    *(UINT64 *)Ptr = MmioRead64 (mFwCfgDataAddress);

+    Ptr += 8;

+  }

+  if (Left & 4) {

+    *(UINT32 *)Ptr = MmioRead32 (mFwCfgDataAddress);

+    Ptr += 4;

+  }

+#else

+  while (Ptr < End) {

+    *(UINT32 *)Ptr = MmioRead32 (mFwCfgDataAddress);

+    Ptr += 4;

+  }

+#endif

+

+  if (Left & 2) {

+    *(UINT16 *)Ptr = MmioRead16 (mFwCfgDataAddress);

+    Ptr += 2;

+  }

+  if (Left & 1) {

+    *Ptr = MmioRead8 (mFwCfgDataAddress);

+  }

+}

+

+

+/**

+  Reads firmware configuration bytes into a buffer

+

+  If called multiple times, then the data read will continue at the offset of

+  the firmware configuration item where the previous read ended.

+

+  @param[in] Size    Size in bytes to read

+  @param[in] Buffer  Buffer to store data into

+

+**/

+VOID

+EFIAPI

+QemuFwCfgReadBytes (

+  IN UINTN Size,

+  IN VOID  *Buffer

+  )

+{

+  if (InternalQemuFwCfgIsAvailable ()) {

+    InternalQemuFwCfgReadBytes (Size, Buffer);

+  } else {

+    ZeroMem (Buffer, Size);

+  }

+}

+

+/**

+  Write firmware configuration bytes from a buffer

+

+  If called multiple times, then the data written will continue at the offset

+  of the firmware configuration item where the previous write ended.

+

+  @param[in] Size    Size in bytes to write

+  @param[in] Buffer  Buffer to read data from

+

+**/

+VOID

+EFIAPI

+QemuFwCfgWriteBytes (

+  IN UINTN                  Size,

+  IN VOID                   *Buffer

+  )

+{

+  if (InternalQemuFwCfgIsAvailable ()) {

+    UINTN Idx;

+

+    for (Idx = 0; Idx < Size; ++Idx) {

+      MmioWrite8 (mFwCfgDataAddress, ((UINT8 *)Buffer)[Idx]);

+    }

+  }

+}

+

+

+/**

+  Reads a UINT8 firmware configuration value

+

+  @return  Value of Firmware Configuration item read

+

+**/

+UINT8

+EFIAPI

+QemuFwCfgRead8 (

+  VOID

+  )

+{

+  UINT8 Result;

+

+  QemuFwCfgReadBytes (sizeof Result, &Result);

+  return Result;

+}

+

+

+/**

+  Reads a UINT16 firmware configuration value

+

+  @return  Value of Firmware Configuration item read

+

+**/

+UINT16

+EFIAPI

+QemuFwCfgRead16 (

+  VOID

+  )

+{

+  UINT16 Result;

+

+  QemuFwCfgReadBytes (sizeof Result, &Result);

+  return Result;

+}

+

+

+/**

+  Reads a UINT32 firmware configuration value

+

+  @return  Value of Firmware Configuration item read

+

+**/

+UINT32

+EFIAPI

+QemuFwCfgRead32 (

+  VOID

+  )

+{

+  UINT32 Result;

+

+  QemuFwCfgReadBytes (sizeof Result, &Result);

+  return Result;

+}

+

+

+/**

+  Reads a UINT64 firmware configuration value

+

+  @return  Value of Firmware Configuration item read

+

+**/

+UINT64

+EFIAPI

+QemuFwCfgRead64 (

+  VOID

+  )

+{

+  UINT64 Result;

+

+  QemuFwCfgReadBytes (sizeof Result, &Result);

+  return Result;

+}

+

+

+/**

+  Find the configuration item corresponding to the firmware configuration file.

+

+  @param[in]  Name  Name of file to look up.

+  @param[out] Item  Configuration item corresponding to the file, to be passed

+                    to QemuFwCfgSelectItem ().

+  @param[out] Size  Number of bytes in the file.

+

+  @retval RETURN_SUCCESS      If file is found.

+  @retval RETURN_NOT_FOUND    If file is not found.

+  @retval RETURN_UNSUPPORTED  If firmware configuration is unavailable.

+

+**/

+RETURN_STATUS

+EFIAPI

+QemuFwCfgFindFile (

+  IN   CONST CHAR8           *Name,

+  OUT  FIRMWARE_CONFIG_ITEM  *Item,

+  OUT  UINTN                 *Size

+  )

+{

+  UINT32 Count;

+  UINT32 Idx;

+

+  if (!InternalQemuFwCfgIsAvailable ()) {

+    return RETURN_UNSUPPORTED;

+  }

+

+  QemuFwCfgSelectItem (QemuFwCfgItemFileDir);

+  Count = SwapBytes32 (QemuFwCfgRead32 ());

+

+  for (Idx = 0; Idx < Count; ++Idx) {

+    UINT32 FileSize;

+    UINT16 FileSelect;

+    CHAR8  FName[QEMU_FW_CFG_FNAME_SIZE];

+

+    FileSize   = QemuFwCfgRead32 ();

+    FileSelect = QemuFwCfgRead16 ();

+    QemuFwCfgRead16 (); // skip the field called "reserved"

+    InternalQemuFwCfgReadBytes (sizeof (FName), FName);

+

+    if (AsciiStrCmp (Name, FName) == 0) {

+      *Item = SwapBytes16 (FileSelect);

+      *Size = SwapBytes32 (FileSize);

+      return RETURN_SUCCESS;

+    }

+  }

+

+  return RETURN_NOT_FOUND;

+}

+

+

+/**

+  Determine if S3 support is explicitly enabled.

+

+  @retval TRUE   if S3 support is explicitly enabled.

+          FALSE  otherwise. This includes unavailability of the firmware

+                 configuration interface.

+**/

+BOOLEAN

+EFIAPI

+QemuFwCfgS3Enabled (

+  VOID

+  )

+{

+  return FALSE;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
new file mode 100644
index 0000000..21ab2bf
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
@@ -0,0 +1,52 @@
+## @file

+#

+#  Stateful, implicitly initialized fw_cfg library.

+#

+#  Copyright (C) 2013 - 2014, Red Hat, Inc.

+#  Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = QemuFwCfgLib

+  FILE_GUID                      = B271F41F-B841-48A9-BA8D-545B4BC2E2BF

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = QemuFwCfgLib|DXE_DRIVER

+

+  CONSTRUCTOR                    = QemuFwCfgInitialize

+

+#

+# The following information is for reference only and not required by the build

+# tools.

+#

+#  VALID_ARCHITECTURES           = ARM AARCH64

+#

+

+[Sources]

+  QemuFwCfgLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  OvmfPkg/OvmfPkg.dec

+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  BaseMemoryLib

+  IoLib

+  PcdLib

+

+[Pcd]

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c
new file mode 100644
index 0000000..751864d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.c
@@ -0,0 +1,327 @@
+/** @file

+*  Device tree enumeration DXE driver for ARM Virtual Machines

+*

+*  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+*

+*  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 <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/UefiDriverEntryPoint.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/VirtioMmioDeviceLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/PcdLib.h>

+#include <Library/DxeServicesLib.h>

+#include <libfdt.h>

+

+#include <Guid/Fdt.h>

+#include <Guid/VirtioMmioTransport.h>

+

+#pragma pack (1)

+typedef struct {

+  VENDOR_DEVICE_PATH                  Vendor;

+  UINT64                              PhysBase;

+  EFI_DEVICE_PATH_PROTOCOL            End;

+} VIRTIO_TRANSPORT_DEVICE_PATH;

+#pragma pack ()

+

+typedef enum {

+  PropertyTypeUnknown,

+  PropertyTypeGic,

+  PropertyTypeRtc,

+  PropertyTypeVirtio,

+  PropertyTypeUart,

+  PropertyTypeTimer,

+  PropertyTypePsci,

+  PropertyTypeFwCfg,

+} PROPERTY_TYPE;

+

+typedef struct {

+  PROPERTY_TYPE Type;

+  CHAR8         Compatible[20];

+} PROPERTY;

+

+STATIC CONST PROPERTY CompatibleProperties[] = {

+  { PropertyTypeGic,     "arm,cortex-a15-gic"  },

+  { PropertyTypeRtc,     "arm,pl031"           },

+  { PropertyTypeVirtio,  "virtio,mmio"         },

+  { PropertyTypeUart,    "arm,pl011"           },

+  { PropertyTypeTimer,   "arm,armv7-timer"     },

+  { PropertyTypeTimer,   "arm,armv8-timer"     },

+  { PropertyTypePsci,    "arm,psci-0.2"        },

+  { PropertyTypeFwCfg,   "qemu,fw-cfg-mmio"    },

+  { PropertyTypeUnknown, ""                    }

+};

+

+typedef struct {

+  UINT32  Type;

+  UINT32  Number;

+  UINT32  Flags;

+} INTERRUPT_PROPERTY;

+

+STATIC

+PROPERTY_TYPE

+GetTypeFromNode (

+  IN CONST CHAR8 *NodeType,

+  IN UINTN       Size

+  )

+{

+  CONST CHAR8    *Compatible;

+  CONST PROPERTY *CompatibleProperty;

+

+  //

+  // A 'compatible' node may contain a sequence of NULL terminated

+  // compatible strings so check each one

+  //

+  for (Compatible = NodeType; Compatible < NodeType + Size && *Compatible;

+       Compatible += 1 + AsciiStrLen (Compatible)) {

+    for (CompatibleProperty = CompatibleProperties; CompatibleProperty->Compatible[0]; CompatibleProperty++) {

+      if (AsciiStrCmp (CompatibleProperty->Compatible, Compatible) == 0) {

+        return CompatibleProperty->Type;

+      }

+    }

+  }

+  return PropertyTypeUnknown;

+}

+

+EFI_STATUS

+EFIAPI

+InitializeVirtFdtDxe (

+  IN EFI_HANDLE           ImageHandle,

+  IN EFI_SYSTEM_TABLE     *SystemTable

+  )

+{

+  VOID                           *DeviceTreeBase;

+  INT32                          Node, Prev;

+  INT32                          RtcNode;

+  EFI_STATUS                     Status;

+  CONST CHAR8                    *Type;

+  INT32                          Len;

+  PROPERTY_TYPE                  PropType;

+  CONST VOID                     *RegProp;

+  VIRTIO_TRANSPORT_DEVICE_PATH   *DevicePath;

+  EFI_HANDLE                     Handle;

+  UINT64                         RegBase;

+  UINT64                         DistBase, CpuBase;

+  CONST INTERRUPT_PROPERTY       *InterruptProp;

+  INT32                          SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum;

+  CONST CHAR8                    *PsciMethod;

+  UINT64                         FwCfgSelectorAddress;

+  UINT64                         FwCfgSelectorSize;

+  UINT64                         FwCfgDataAddress;

+  UINT64                         FwCfgDataSize;

+

+  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress);

+  ASSERT (DeviceTreeBase != NULL);

+

+  if (fdt_check_header (DeviceTreeBase) != 0) {

+    DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__, DeviceTreeBase));

+    return EFI_NOT_FOUND;

+  }

+

+  Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DeviceTreeBase);

+  ASSERT_EFI_ERROR (Status);

+

+  DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, DeviceTreeBase));

+

+  RtcNode = -1;

+  //

+  // Now enumerate the nodes and install peripherals that we are interested in,

+  // i.e., GIC, RTC and virtio MMIO nodes

+  //

+  for (Prev = 0;; Prev = Node) {

+    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);

+    if (Node < 0) {

+      break;

+    }

+

+    Type = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len);

+    if (Type == NULL) {

+      continue;

+    }

+

+    PropType = GetTypeFromNode (Type, Len);

+    if (PropType == PropertyTypeUnknown) {

+      continue;

+    }

+

+    //

+    // Get the 'reg' property of this node. For now, we will assume

+    // 8 byte quantities for base and size, respectively.

+    // TODO use #cells root properties instead

+    //

+    RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);

+    ASSERT ((RegProp != NULL) || (PropType == PropertyTypeTimer) ||

+      (PropType == PropertyTypePsci));

+

+    switch (PropType) {

+    case PropertyTypeFwCfg:

+      ASSERT (Len == 2 * sizeof (UINT64));

+

+      FwCfgDataAddress     = fdt64_to_cpu (((UINT64 *)RegProp)[0]);

+      FwCfgDataSize        = 8;

+      FwCfgSelectorAddress = FwCfgDataAddress + FwCfgDataSize;

+      FwCfgSelectorSize    = 2;

+

+      //

+      // The following ASSERT()s express

+      //

+      //   Address + Size - 1 <= MAX_UINTN

+      //

+      // for both registers, that is, that the last byte in each MMIO range is

+      // expressible as a MAX_UINTN. The form below is mathematically

+      // equivalent, and it also prevents any unsigned overflow before the

+      // comparison.

+      //

+      ASSERT (FwCfgSelectorAddress <= MAX_UINTN - FwCfgSelectorSize + 1);

+      ASSERT (FwCfgDataAddress     <= MAX_UINTN - FwCfgDataSize     + 1);

+

+      PcdSet64 (PcdFwCfgSelectorAddress, FwCfgSelectorAddress);

+      PcdSet64 (PcdFwCfgDataAddress,     FwCfgDataAddress);

+

+      DEBUG ((EFI_D_INFO, "Found FwCfg @ 0x%Lx/0x%Lx\n", FwCfgSelectorAddress,

+        FwCfgDataAddress));

+      break;

+

+    case PropertyTypeVirtio:

+      ASSERT (Len == 16);

+      //

+      // Create a unique device path for this transport on the fly

+      //

+      RegBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);

+      DevicePath = (VIRTIO_TRANSPORT_DEVICE_PATH *)CreateDeviceNode (

+                                    HARDWARE_DEVICE_PATH,

+                                    HW_VENDOR_DP,

+                                    sizeof (VIRTIO_TRANSPORT_DEVICE_PATH));

+      if (DevicePath == NULL) {

+        DEBUG ((EFI_D_ERROR, "%a: Out of memory\n", __FUNCTION__));

+        break;

+      }

+

+      CopyMem (&DevicePath->Vendor.Guid, &gVirtioMmioTransportGuid,

+        sizeof (EFI_GUID));

+      DevicePath->PhysBase = RegBase;

+      SetDevicePathNodeLength (&DevicePath->Vendor,

+                               sizeof (*DevicePath) - sizeof (DevicePath->End));

+      SetDevicePathEndNode (&DevicePath->End);

+

+      Handle = NULL;

+      Status = gBS->InstallProtocolInterface (&Handle,

+                     &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,

+                     DevicePath);

+      if (EFI_ERROR (Status)) {

+        DEBUG ((EFI_D_ERROR, "%a: Failed to install the EFI_DEVICE_PATH "

+          "protocol on a new handle (Status == %r)\n",

+          __FUNCTION__, Status));

+        FreePool (DevicePath);

+        break;

+      }

+

+      Status = VirtioMmioInstallDevice (RegBase, Handle);

+      if (EFI_ERROR (Status)) {

+        DEBUG ((EFI_D_ERROR, "%a: Failed to install VirtIO transport @ 0x%Lx "

+          "on handle %p (Status == %r)\n", __FUNCTION__, RegBase,

+          Handle, Status));

+

+        Status = gBS->UninstallProtocolInterface (Handle,

+                        &gEfiDevicePathProtocolGuid, DevicePath);

+        ASSERT_EFI_ERROR (Status);

+        FreePool (DevicePath);

+      }

+      break;

+

+    case PropertyTypeGic:

+      ASSERT (Len == 32);

+

+      DistBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);

+      CpuBase  = fdt64_to_cpu (((UINT64 *)RegProp)[2]);

+      ASSERT (DistBase < MAX_UINT32);

+      ASSERT (CpuBase < MAX_UINT32);

+

+      PcdSet32 (PcdGicDistributorBase, (UINT32)DistBase);

+      PcdSet32 (PcdGicInterruptInterfaceBase, (UINT32)CpuBase);

+

+      DEBUG ((EFI_D_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase));

+      break;

+

+    case PropertyTypeRtc:

+      ASSERT (Len == 16);

+

+      RegBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);

+      ASSERT (RegBase < MAX_UINT32);

+

+      PcdSet32 (PcdPL031RtcBase, (UINT32)RegBase);

+

+      DEBUG ((EFI_D_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));

+      RtcNode = Node;

+      break;

+

+    case PropertyTypeTimer:

+      //

+      // - interrupts : Interrupt list for secure, non-secure, virtual and

+      //  hypervisor timers, in that order.

+      //

+      InterruptProp = fdt_getprop (DeviceTreeBase, Node, "interrupts", &Len);

+      ASSERT (Len == 48);

+

+      SecIntrNum = fdt32_to_cpu (InterruptProp[0].Number)

+                   + (InterruptProp[0].Type ? 16 : 0);

+      IntrNum = fdt32_to_cpu (InterruptProp[1].Number)

+                + (InterruptProp[1].Type ? 16 : 0);

+      VirtIntrNum = fdt32_to_cpu (InterruptProp[2].Number)

+                    + (InterruptProp[2].Type ? 16 : 0);

+      HypIntrNum = fdt32_to_cpu (InterruptProp[3].Number)

+                   + (InterruptProp[3].Type ? 16 : 0);

+

+      DEBUG ((EFI_D_INFO, "Found Timer interrupts %d, %d, %d, %d\n",

+        SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum));

+

+      PcdSet32 (PcdArmArchTimerSecIntrNum, SecIntrNum);

+      PcdSet32 (PcdArmArchTimerIntrNum, IntrNum);

+      PcdSet32 (PcdArmArchTimerVirtIntrNum, VirtIntrNum);

+      PcdSet32 (PcdArmArchTimerHypIntrNum, HypIntrNum);

+      break;

+

+    case PropertyTypePsci:

+      PsciMethod = fdt_getprop (DeviceTreeBase, Node, "method", &Len);

+

+      if (PsciMethod && AsciiStrnCmp (PsciMethod, "hvc", 3) == 0) {

+        PcdSet32 (PcdArmPsciMethod, 1);

+      } else if (PsciMethod && AsciiStrnCmp (PsciMethod, "smc", 3) == 0) {

+        PcdSet32 (PcdArmPsciMethod, 2);

+      } else {

+        DEBUG ((EFI_D_ERROR, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__,

+          PsciMethod));

+      }

+      break;

+

+    default:

+      break;

+    }

+  }

+

+  //

+  // UEFI takes ownership of the RTC hardware, and exposes its functionality

+  // through the UEFI Runtime Services GetTime, SetTime, etc. This means we

+  // need to disable it in the device tree to prevent the OS from attaching its

+  // device driver as well.

+  //

+  if ((RtcNode != -1) &&

+      fdt_setprop_string (DeviceTreeBase, RtcNode, "status",

+        "disabled") != 0) {

+    DEBUG ((EFI_D_WARN, "Failed to set PL031 status to 'disabled'\n"));

+  }

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
new file mode 100644
index 0000000..514ce2f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/ArmVirtualizationPkg/VirtFdtDxe/VirtFdtDxe.inf
@@ -0,0 +1,65 @@
+## @file

+#  Device tree enumeration DXE driver for ARM Virtual Machines

+#

+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = VirtFdtDxe

+  FILE_GUID                      = 9AD7DCB4-E6EC-472E-96BF-81C219A3F77E

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = InitializeVirtFdtDxe

+

+[Sources]

+  VirtFdtDxe.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  OvmfPkg/OvmfPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  PcdLib

+  UefiDriverEntryPoint

+  DxeServicesLib

+  FdtLib

+  VirtioMmioDeviceLib

+

+[Guids]

+  gFdtTableGuid

+  gVirtioMmioTransportGuid

+

+[Pcd]

+  gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress

+  gArmVirtualizationTokenSpaceGuid.PcdArmPsciMethod

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgSelectorAddress

+  gArmVirtualizationTokenSpaceGuid.PcdFwCfgDataAddress

+  gArmTokenSpaceGuid.PcdGicDistributorBase

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase

+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum

+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum

+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum

+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase

+

+[Protocols]

+  gEfiDevicePathProtocolGuid

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Bds/Bds.c b/uefi/linaro-edk2/ArmPlatformPkg/Bds/Bds.c
new file mode 100644
index 0000000..512e8e1
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Bds/Bds.c
@@ -0,0 +1,587 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include "BdsInternal.h"

+

+#include <Library/PcdLib.h>

+#include <Library/PerformanceLib.h>

+

+#include <Protocol/Bds.h>

+

+#include <Guid/EventGroup.h>

+

+#define EFI_SET_TIMER_TO_SECOND   10000000

+

+STATIC

+EFI_STATUS

+GetConsoleDevicePathFromVariable (

+  IN  CHAR16*             ConsoleVarName,

+  IN  CHAR16*             DefaultConsolePaths,

+  OUT EFI_DEVICE_PATH**   DevicePaths

+  )

+{

+  EFI_STATUS                Status;

+  UINTN                     Size;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;

+  CHAR16*                   DevicePathStr;

+  CHAR16*                   NextDevicePathStr;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;

+

+  Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);

+  if (EFI_ERROR(Status)) {

+    // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)

+    if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {

+      *DevicePaths = NULL;

+      return EFI_SUCCESS;

+    }

+

+    Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+    ASSERT_EFI_ERROR(Status);

+

+    DevicePathInstances = NULL;

+

+    // Extract the Device Path instances from the multi-device path string

+    while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {

+      NextDevicePathStr = StrStr (DefaultConsolePaths, L";");

+      if (NextDevicePathStr == NULL) {

+        DevicePathStr = DefaultConsolePaths;

+        DefaultConsolePaths = NULL;

+      } else {

+        DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof(CHAR16), DefaultConsolePaths);

+        *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';

+        DefaultConsolePaths = NextDevicePathStr;

+        if (DefaultConsolePaths[0] == L';') {

+          DefaultConsolePaths++;

+        }

+      }

+

+      DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);

+      ASSERT(DevicePathInstance != NULL);

+      DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);

+

+      if (NextDevicePathStr != NULL) {

+        FreePool (DevicePathStr);

+      }

+      FreePool (DevicePathInstance);

+    }

+

+    // Set the environment variable with this device path multi-instances

+    Size = GetDevicePathSize (DevicePathInstances);

+    if (Size > 0) {

+      gRT->SetVariable (

+          ConsoleVarName,

+          &gEfiGlobalVariableGuid,

+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+          Size,

+          DevicePathInstances

+          );

+    } else {

+      Status = EFI_INVALID_PARAMETER;

+    }

+  }

+

+  if (!EFI_ERROR(Status)) {

+    *DevicePaths = DevicePathInstances;

+  }

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+InitializeConsolePipe (

+  IN EFI_DEVICE_PATH    *ConsoleDevicePaths,

+  IN EFI_GUID           *Protocol,

+  OUT EFI_HANDLE        *Handle,

+  OUT VOID*             *Interface

+  )

+{

+  EFI_STATUS                Status;

+  UINTN                     Size;

+  UINTN                     NoHandles;

+  EFI_HANDLE                *Buffer;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePath;

+

+  // Connect all the Device Path Consoles

+  while (ConsoleDevicePaths != NULL) {

+    DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);

+

+    Status = BdsConnectDevicePath (DevicePath, Handle, NULL);

+    DEBUG_CODE_BEGIN();

+      if (EFI_ERROR(Status)) {

+        // We convert back to the text representation of the device Path

+        EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+        CHAR16* DevicePathTxt;

+        EFI_STATUS Status;

+

+        Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+        if (!EFI_ERROR(Status)) {

+          DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);

+

+          DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));

+

+          FreePool (DevicePathTxt);

+        }

+      }

+    DEBUG_CODE_END();

+

+    // If the console splitter driver is not supported by the platform then use the first Device Path

+    // instance for the console interface.

+    if (!EFI_ERROR(Status) && (*Interface == NULL)) {

+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);

+    }

+  }

+

+  // No Device Path has been defined for this console interface. We take the first protocol implementation

+  if (*Interface == NULL) {

+    Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);

+    if (EFI_ERROR (Status)) {

+      BdsConnectAllDrivers();

+      Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);

+    }

+

+    if (!EFI_ERROR(Status)) {

+      *Handle = Buffer[0];

+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);

+      ASSERT_EFI_ERROR(Status);

+    }

+    FreePool (Buffer);

+  } else {

+    Status = EFI_SUCCESS;

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+InitializeConsole (

+  VOID

+  )

+{

+  EFI_STATUS                Status;

+  EFI_DEVICE_PATH*          ConOutDevicePaths;

+  EFI_DEVICE_PATH*          ConInDevicePaths;

+  EFI_DEVICE_PATH*          ConErrDevicePaths;

+

+  // By getting the Console Device Paths from the environment variables before initializing the console pipe, we

+  // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface

+  // of newly installed console drivers

+  Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+  Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+  Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+

+  // Initialize the Consoles

+  Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);

+  ASSERT_EFI_ERROR (Status);

+  Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);

+  ASSERT_EFI_ERROR (Status);

+  Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);

+  if (EFI_ERROR(Status)) {

+    // In case of error, we reuse the console output for the error output

+    gST->StandardErrorHandle = gST->ConsoleOutHandle;

+    gST->StdErr = gST->ConOut;

+  }

+

+  // Free Memory allocated for reading the UEFI Variables

+  if (ConOutDevicePaths) {

+    FreePool (ConOutDevicePaths);

+  }

+  if (ConInDevicePaths) {

+    FreePool (ConInDevicePaths);

+  }

+  if (ConErrDevicePaths) {

+    FreePool (ConErrDevicePaths);

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+DefineDefaultBootEntries (

+  VOID

+  )

+{

+  BDS_LOAD_OPTION*                    BdsLoadOption;

+  UINTN                               Size;

+  EFI_STATUS                          Status;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol;

+  EFI_DEVICE_PATH*                    BootDevicePath;

+  UINT8*                              OptionalData;

+  UINTN                               OptionalDataSize;

+  ARM_BDS_LOADER_ARGUMENTS*           BootArguments;

+  ARM_BDS_LOADER_TYPE                 BootType;

+  EFI_DEVICE_PATH*                    InitrdPath;

+  UINTN                               InitrdSize;

+  UINTN                               CmdLineSize;

+  UINTN                               CmdLineAsciiSize;

+  CHAR16*                             DefaultBootArgument;

+  CHAR8*                              AsciiDefaultBootArgument;

+

+  //

+  // If Boot Order does not exist then create a default entry

+  //

+  Size = 0;

+  Status = gRT->GetVariable (L"BootOrder", &gEfiGlobalVariableGuid, NULL, &Size, NULL);

+  if (Status == EFI_NOT_FOUND) {

+    if ((PcdGetPtr(PcdDefaultBootDevicePath) == NULL) || (StrLen ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath)) == 0)) {

+      return EFI_UNSUPPORTED;

+    }

+

+    Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+    if (EFI_ERROR(Status)) {

+      // You must provide an implementation of DevicePathFromTextProtocol in your firmware (eg: DevicePathDxe)

+      DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathFromTextProtocol\n"));

+      return Status;

+    }

+    BootDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath));

+

+    DEBUG_CODE_BEGIN();

+      // We convert back to the text representation of the device Path to see if the initial text is correct

+      EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+      CHAR16* DevicePathTxt;

+

+      Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+      ASSERT_EFI_ERROR(Status);

+      DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootDevicePath, TRUE, TRUE);

+

+      ASSERT (StrCmp ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath), DevicePathTxt) == 0);

+

+      FreePool (DevicePathTxt);

+    DEBUG_CODE_END();

+

+    // Create the entry is the Default values are correct

+    if (BootDevicePath != NULL) {

+      BootType = (ARM_BDS_LOADER_TYPE)PcdGet32 (PcdDefaultBootType);

+

+      // We do not support NULL pointer

+      ASSERT (PcdGetPtr (PcdDefaultBootArgument) != NULL);

+

+      //

+      // Logic to handle ASCII or Unicode default parameters

+      //

+      if (*(CHAR8*)PcdGetPtr (PcdDefaultBootArgument) == '\0') {

+        CmdLineSize = 0;

+        CmdLineAsciiSize = 0;

+        DefaultBootArgument = NULL;

+        AsciiDefaultBootArgument = NULL;

+      } else if (IsUnicodeString ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument))) {

+        // The command line is a Unicode string

+        DefaultBootArgument = (CHAR16*)PcdGetPtr (PcdDefaultBootArgument);

+        CmdLineSize = StrSize (DefaultBootArgument);

+

+        // Initialize ASCII variables

+        CmdLineAsciiSize = CmdLineSize / 2;

+        AsciiDefaultBootArgument = AllocatePool (CmdLineAsciiSize);

+        if (AsciiDefaultBootArgument == NULL) {

+          return EFI_OUT_OF_RESOURCES;

+        }

+        UnicodeStrToAsciiStr ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument), AsciiDefaultBootArgument);

+      } else {

+        // The command line is a ASCII string

+        AsciiDefaultBootArgument = (CHAR8*)PcdGetPtr (PcdDefaultBootArgument);

+        CmdLineAsciiSize = AsciiStrSize (AsciiDefaultBootArgument);

+

+        // Initialize ASCII variables

+        CmdLineSize = CmdLineAsciiSize * 2;

+        DefaultBootArgument = AllocatePool (CmdLineSize);

+        if (DefaultBootArgument == NULL) {

+          return EFI_OUT_OF_RESOURCES;

+        }

+        AsciiStrToUnicodeStr (AsciiDefaultBootArgument, DefaultBootArgument);

+      }

+

+      if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {

+        InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));

+        InitrdSize = GetDevicePathSize (InitrdPath);

+

+        OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineAsciiSize + InitrdSize;

+        BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);

+        if (BootArguments == NULL) {

+          return EFI_OUT_OF_RESOURCES;

+        }

+        BootArguments->LinuxArguments.CmdLineSize = CmdLineAsciiSize;

+        BootArguments->LinuxArguments.InitrdSize = InitrdSize;

+

+        CopyMem ((VOID*)(BootArguments + 1), AsciiDefaultBootArgument, CmdLineAsciiSize);

+        CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineAsciiSize), InitrdPath, InitrdSize);

+

+        OptionalData = (UINT8*)BootArguments;

+      } else {

+        OptionalData = (UINT8*)DefaultBootArgument;

+        OptionalDataSize = CmdLineSize;

+      }

+

+      BootOptionCreate (LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,

+        (CHAR16*)PcdGetPtr(PcdDefaultBootDescription),

+        BootDevicePath,

+        BootType,

+        OptionalData,

+        OptionalDataSize,

+        &BdsLoadOption

+        );

+      FreePool (BdsLoadOption);

+

+      if (DefaultBootArgument == (CHAR16*)PcdGetPtr (PcdDefaultBootArgument)) {

+        FreePool (AsciiDefaultBootArgument);

+      } else if (DefaultBootArgument != NULL) {

+        FreePool (DefaultBootArgument);

+      }

+    } else {

+      Status = EFI_UNSUPPORTED;

+    }

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+StartDefaultBootOnTimeout (

+  VOID

+  )

+{

+  UINTN               Size;

+  UINT16              Timeout;

+  UINT16              *TimeoutPtr;

+  EFI_EVENT           WaitList[2];

+  UINTN               WaitIndex;

+  UINT16              *BootOrder;

+  UINTN               BootOrderSize;

+  UINTN               Index;

+  CHAR16              BootVariableName[9];

+  EFI_STATUS          Status;

+  EFI_INPUT_KEY       Key;

+

+  Size = sizeof(UINT16);

+  Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);

+  Status = GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);

+  if (!EFI_ERROR (Status)) {

+    Timeout = *TimeoutPtr;

+    FreePool (TimeoutPtr);

+  }

+

+  if (Timeout != 0xFFFF) {

+    if (Timeout > 0) {

+      // Create the waiting events (keystroke and 1sec timer)

+      gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &WaitList[0]);

+      gBS->SetTimer (WaitList[0], TimerPeriodic, EFI_SET_TIMER_TO_SECOND);

+      WaitList[1] = gST->ConIn->WaitForKey;

+

+      // Start the timer

+      WaitIndex = 0;

+      Print(L"The default boot selection will start in ");

+      while ((Timeout > 0) && (WaitIndex == 0)) {

+        Print(L"%3d seconds",Timeout);

+        gBS->WaitForEvent (2, WaitList, &WaitIndex);

+        if (WaitIndex == 0) {

+          Print(L"\b\b\b\b\b\b\b\b\b\b\b");

+          Timeout--;

+        }

+      }

+      // Discard key in the buffer

+      do {

+        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);

+      } while(!EFI_ERROR(Status));

+      gBS->CloseEvent (WaitList[0]);

+      Print(L"\n\r");

+    }

+

+    // In case of Timeout we start the default boot selection

+    if (Timeout == 0) {

+      // Get the Boot Option Order from the environment variable (a default value should have been created)

+      GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);

+

+      for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {

+        UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]);

+        Status = BdsStartBootOption (BootVariableName);

+        if(!EFI_ERROR(Status)){

+          // Boot option returned successfully, hence don't need to start next boot option

+          break;

+        }

+        // In case of success, we should not return from this call.

+      }

+      FreePool (BootOrder);

+    }

+  }

+  return EFI_SUCCESS;

+}

+

+/**

+  An empty function to pass error checking of CreateEventEx ().

+

+  @param  Event                 Event whose notification function is being invoked.

+  @param  Context               Pointer to the notification function's context,

+                                which is implementation-dependent.

+

+**/

+VOID

+EFIAPI

+EmptyCallbackFunction (

+  IN EFI_EVENT                Event,

+  IN VOID                     *Context

+  )

+{

+  return;

+}

+

+/**

+  This function uses policy data from the platform to determine what operating

+  system or system utility should be loaded and invoked.  This function call

+  also optionally make the use of user input to determine the operating system

+  or system utility to be loaded and invoked.  When the DXE Core has dispatched

+  all the drivers on the dispatch queue, this function is called.  This

+  function will attempt to connect the boot devices required to load and invoke

+  the selected operating system or system utility.  During this process,

+  additional firmware volumes may be discovered that may contain addition DXE

+  drivers that can be dispatched by the DXE Core.   If a boot device cannot be

+  fully connected, this function calls the DXE Service Dispatch() to allow the

+  DXE drivers from any newly discovered firmware volumes to be dispatched.

+  Then the boot device connection can be attempted again.  If the same boot

+  device connection operation fails twice in a row, then that boot device has

+  failed, and should be skipped.  This function should never return.

+

+  @param  This             The EFI_BDS_ARCH_PROTOCOL instance.

+

+  @return None.

+

+**/

+VOID

+EFIAPI

+BdsEntry (

+  IN EFI_BDS_ARCH_PROTOCOL  *This

+  )

+{

+  UINTN               Size;

+  EFI_STATUS          Status;

+  UINT16             *BootNext;

+  UINTN               BootNextSize;

+  CHAR16              BootVariableName[9];

+  EFI_EVENT           EndOfDxeEvent;

+

+  //

+  // Signal EndOfDxe PI Event

+  //

+  Status = gBS->CreateEventEx (

+      EVT_NOTIFY_SIGNAL,

+      TPL_NOTIFY,

+      EmptyCallbackFunction,

+      NULL,

+      &gEfiEndOfDxeEventGroupGuid,

+      &EndOfDxeEvent

+      );

+  if (!EFI_ERROR (Status)) {

+    gBS->SignalEvent (EndOfDxeEvent);

+  }

+

+  PERF_END   (NULL, "DXE", NULL, 0);

+

+  //

+  // Declare the Firmware Vendor

+  //

+  if (FixedPcdGetPtr(PcdFirmwareVendor) != NULL) {

+    Size = 0x100;

+    gST->FirmwareVendor = AllocateRuntimePool (Size);

+    ASSERT (gST->FirmwareVendor != NULL);

+    UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__);

+  }

+

+  //

+  // Fixup Table CRC after we updated Firmware Vendor

+  //

+  gST->Hdr.CRC32 = 0;

+  Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);

+  ASSERT_EFI_ERROR (Status);

+

+  // Now we need to setup the EFI System Table with information about the console devices.

+  InitializeConsole ();

+

+  // If BootNext environment variable is defined then we just load it !

+  BootNextSize = sizeof(UINT16);

+  Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext);

+  if (!EFI_ERROR(Status)) {

+    ASSERT(BootNextSize == sizeof(UINT16));

+

+    // Generate the requested Boot Entry variable name

+    UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", *BootNext);

+

+    // Set BootCurrent variable

+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,

+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+              BootNextSize, BootNext);

+

+    FreePool (BootNext);

+

+    // Start the requested Boot Entry

+    Status = BdsStartBootOption (BootVariableName);

+    if (Status != EFI_NOT_FOUND) {

+      // BootNext has not been succeeded launched

+      if (EFI_ERROR(Status)) {

+        Print(L"Fail to start BootNext.\n");

+

+        // Delete the BootNext environment variable

+        gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid,

+            EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+            0, NULL);

+      }

+    }

+

+    // Clear BootCurrent variable

+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,

+        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+        0, NULL);

+  }

+

+  // If Boot Order does not exist then create a default entry

+  DefineDefaultBootEntries ();

+

+  //

+  // Update the CRC32 in the EFI System Table header

+  //

+  gST->Hdr.CRC32 = 0;

+  Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);

+  ASSERT_EFI_ERROR (Status);

+

+  // Timer before initiating the default boot selection

+  StartDefaultBootOnTimeout ();

+

+  // Start the Boot Menu

+  Status = BootMenuMain ();

+  ASSERT_EFI_ERROR (Status);

+

+}

+

+EFI_BDS_ARCH_PROTOCOL  gBdsProtocol = {

+  BdsEntry,

+};

+

+EFI_STATUS

+EFIAPI

+BdsInitialize (

+  IN EFI_HANDLE                            ImageHandle,

+  IN EFI_SYSTEM_TABLE                      *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+

+  Status = gBS->InstallMultipleProtocolInterfaces (

+                  &ImageHandle,

+                  &gEfiBdsArchProtocolGuid, &gBdsProtocol,

+                  NULL

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Bds/Bds.inf b/uefi/linaro-edk2/ArmPlatformPkg/Bds/Bds.inf
new file mode 100644
index 0000000..9872ce3
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Bds/Bds.inf
@@ -0,0 +1,83 @@
+#/** @file

+#

+#  Component description file for Bds module

+#

+#  Copyright (c) 2011-2015, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmPlatformBds

+  FILE_GUID                      = 5a50aa81-c3ae-4608-a0e3-41a2e69baf94

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = BdsInitialize

+

+[Sources.common]

+  Bds.c

+  BdsHelper.c

+  BootMenu.c

+  BootOption.c

+  BootOptionSupport.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BdsLib

+  TimerLib

+  PerformanceLib

+  UefiBootServicesTableLib

+  DxeServicesTableLib

+  UefiDriverEntryPoint

+  DebugLib

+  PrintLib

+  BaseLib

+  NetLib

+

+[Guids]

+  gEfiEndOfDxeEventGroupGuid

+  gEfiFileSystemInfoGuid

+  gArmGlobalVariableGuid

+  gArmPlatformUpdateFdtEventGuid

+

+[Protocols]

+  gEfiBdsArchProtocolGuid

+  gEfiBlockIoProtocolGuid

+  gEfiSimpleTextInProtocolGuid

+  gEfiPxeBaseCodeProtocolGuid

+  gEfiSimpleNetworkProtocolGuid

+  gEfiDevicePathToTextProtocolGuid

+  gEfiFirmwareVolumeBlockProtocolGuid

+  gEfiFirmwareVolumeBlock2ProtocolGuid

+  gEfiDhcp4ServiceBindingProtocolGuid

+  gEfiMtftp4ServiceBindingProtocolGuid

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdFirmwareVendor

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootInitrdPath

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument

+  gArmPlatformTokenSpaceGuid.PcdDefaultBootType

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath

+  gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Bds/BdsHelper.c b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BdsHelper.c
new file mode 100644
index 0000000..b3003e9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BdsHelper.c
@@ -0,0 +1,474 @@
+/** @file

+*

+*  Copyright (c) 2011 - 2014, ARM 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.

+*

+**/

+

+#include <Library/NetLib.h>

+#include "BdsInternal.h"

+

+EFI_STATUS

+EditHIInputStr (

+  IN OUT CHAR16  *CmdLine,

+  IN     UINTN   MaxCmdLine

+  )

+{

+  UINTN           CmdLineIndex;

+  UINTN           WaitIndex;

+  CHAR8           Char;

+  EFI_INPUT_KEY   Key;

+  EFI_STATUS      Status;

+

+  // The command line must be at least one character long

+  ASSERT (MaxCmdLine > 0);

+

+  // Ensure the last character of the buffer is the NULL character

+  CmdLine[MaxCmdLine - 1] = '\0';

+

+  Print (CmdLine);

+

+  // To prevent a buffer overflow, we only allow to enter (MaxCmdLine-1) characters

+  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {

+    Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);

+    ASSERT_EFI_ERROR (Status);

+

+    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);

+    ASSERT_EFI_ERROR (Status);

+

+    // Unicode character is valid when Scancode is NUll

+    if (Key.ScanCode == SCAN_NULL) {

+      // Scan code is NUll, hence read Unicode character

+      Char = (CHAR8)Key.UnicodeChar;

+    } else {

+      Char = CHAR_NULL;

+    }

+

+    if ((Char == CHAR_LINEFEED) || (Char == CHAR_CARRIAGE_RETURN) || (Char == 0x7f)) {

+      CmdLine[CmdLineIndex] = '\0';

+      Print (L"\r\n");

+

+      return EFI_SUCCESS;

+    } else if ((Key.UnicodeChar == L'\b') || (Key.ScanCode == SCAN_LEFT) || (Key.ScanCode == SCAN_DELETE)){

+      if (CmdLineIndex != 0) {

+        CmdLineIndex--;

+        Print (L"\b \b");

+      }

+    } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {

+      return EFI_INVALID_PARAMETER;

+    } else if (CmdLineIndex < (MaxCmdLine-1)) {

+      CmdLine[CmdLineIndex++] = Key.UnicodeChar;

+      Print (L"%c", Key.UnicodeChar);

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+GetHIInputStr (

+  IN OUT CHAR16  *CmdLine,

+  IN     UINTN   MaxCmdLine

+  )

+{

+  EFI_STATUS  Status;

+

+  // For a new input just passed an empty string

+  CmdLine[0] = L'\0';

+

+  Status = EditHIInputStr (CmdLine, MaxCmdLine);

+

+  return Status;

+}

+

+EFI_STATUS

+EditHIInputAscii (

+  IN OUT CHAR8   *CmdLine,

+  IN     UINTN   MaxCmdLine

+  )

+{

+  CHAR16*     Str;

+  EFI_STATUS  Status;

+

+  Str = (CHAR16*)AllocatePool (MaxCmdLine * sizeof(CHAR16));

+  AsciiStrToUnicodeStr (CmdLine, Str);

+

+  Status = EditHIInputStr (Str, MaxCmdLine);

+  if (!EFI_ERROR(Status)) {

+    UnicodeStrToAsciiStr (Str, CmdLine);

+  }

+  FreePool (Str);

+

+  return Status;

+}

+

+EFI_STATUS

+GetHIInputAscii (

+  IN OUT CHAR8   *CmdLine,

+  IN     UINTN   MaxCmdLine

+  )

+{

+  // For a new input just passed an empty string

+  CmdLine[0] = '\0';

+

+  return EditHIInputAscii (CmdLine,MaxCmdLine);

+}

+

+EFI_STATUS

+GetHIInputInteger (

+  OUT UINTN   *Integer

+  )

+{

+  CHAR16      CmdLine[255];

+  EFI_STATUS  Status;

+

+  CmdLine[0] = '\0';

+  Status = EditHIInputStr (CmdLine, 255);

+  if (!EFI_ERROR(Status)) {

+    *Integer = StrDecimalToUintn (CmdLine);

+  }

+

+  return Status;

+}

+

+/**

+  Get an IPv4 address

+

+  The function asks the user for an IPv4 address. If the input

+  string defines a valid IPv4 address, the four bytes of the

+  corresponding IPv4 address are extracted from the string and returned by

+  the function. As long as the user does not define a valid IP

+  address, he is asked for one. He can always escape by

+  pressing ESC.

+

+  @param[out]  EFI_IP_ADDRESS  OutIpAddr  Returned IPv4 address. Valid if

+                                          and only if the returned value

+                                          is equal to EFI_SUCCESS

+

+  @retval  EFI_SUCCESS            Input completed

+  @retval  EFI_ABORTED            Editing aborted by the user

+  @retval  EFI_OUT_OF_RESOURCES   Fail to perform the operation due to

+                                  lack of resource

+**/

+EFI_STATUS

+GetHIInputIP (

+  OUT  EFI_IP_ADDRESS  *OutIpAddr

+  )

+{

+  EFI_STATUS  Status;

+  CHAR16      CmdLine[48];

+

+  while (TRUE) {

+    CmdLine[0] = '\0';

+    Status = EditHIInputStr (CmdLine, 48);

+    if (EFI_ERROR (Status)) {

+      return EFI_ABORTED;

+    }

+

+    Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);

+    if (Status == EFI_INVALID_PARAMETER) {

+      Print (L"Invalid address\n");

+    } else {

+      return Status;

+    }

+  }

+}

+

+/**

+  Edit an IPv4 address

+

+  The function displays as a string following the "%d.%d.%d.%d" format the

+  IPv4 address that is passed in and asks the user to modify it. If the

+  resulting string defines a valid IPv4 address, the four bytes of the

+  corresponding IPv4 address are extracted from the string and returned by

+  the function. As long as the user does not define a valid IP

+  address, he is asked for one. He can always escape by

+  pressing ESC.

+

+  @param[in ]  EFI_IP_ADDRESS  InIpAddr   Input IPv4 address

+  @param[out]  EFI_IP_ADDRESS  OutIpAddr  Returned IPv4 address. Valid if

+                                          and only if the returned value

+                                          is equal to EFI_SUCCESS

+

+  @retval  EFI_SUCCESS            Update completed

+  @retval  EFI_ABORTED            Editing aborted by the user

+  @retval  EFI_INVALID_PARAMETER  The string returned by the user is

+                                  mal-formated

+  @retval  EFI_OUT_OF_RESOURCES   Fail to perform the operation due to

+                                  lack of resource

+**/

+EFI_STATUS

+EditHIInputIP (

+  IN   EFI_IP_ADDRESS  *InIpAddr,

+  OUT  EFI_IP_ADDRESS  *OutIpAddr

+  )

+{

+  EFI_STATUS  Status;

+  CHAR16      CmdLine[48];

+

+  while (TRUE) {

+    UnicodeSPrint (

+      CmdLine, 48, L"%d.%d.%d.%d",

+      InIpAddr->v4.Addr[0], InIpAddr->v4.Addr[1],

+      InIpAddr->v4.Addr[2], InIpAddr->v4.Addr[3]

+      );

+

+    Status = EditHIInputStr (CmdLine, 48);

+    if (EFI_ERROR (Status)) {

+      return EFI_ABORTED;

+    }

+    Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);

+    if (Status == EFI_INVALID_PARAMETER) {

+      Print (L"Invalid address\n");

+    } else {

+      return Status;

+    }

+  }

+}

+

+EFI_STATUS

+GetHIInputBoolean (

+  OUT BOOLEAN *Value

+  )

+{

+  CHAR16      CmdBoolean[2];

+  EFI_STATUS  Status;

+

+  while(1) {

+    Print (L"[y/n] ");

+    Status = GetHIInputStr (CmdBoolean, 2);

+    if (EFI_ERROR(Status)) {

+      return Status;

+    } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {

+      if (Value) *Value = TRUE;

+      return EFI_SUCCESS;

+    } else if ((CmdBoolean[0] == L'n') || (CmdBoolean[0] == L'N')) {

+      if (Value) *Value = FALSE;

+      return EFI_SUCCESS;

+    }

+  }

+}

+

+BOOLEAN

+HasFilePathEfiExtension (

+  IN CHAR16* FilePath

+  )

+{

+  return (StrCmp (FilePath + (StrSize (FilePath) / sizeof (CHAR16)) - 5, L".EFI") == 0) ||

+         (StrCmp (FilePath + (StrSize (FilePath) / sizeof (CHAR16)) - 5, L".efi") == 0);

+}

+

+// Return the last non end-type Device Path Node from a Device Path

+EFI_DEVICE_PATH*

+GetLastDevicePathNode (

+  IN EFI_DEVICE_PATH*  DevicePath

+  )

+{

+  EFI_DEVICE_PATH*     PrevDevicePathNode;

+

+  PrevDevicePathNode = DevicePath;

+  while (!IsDevicePathEndType (DevicePath)) {

+    PrevDevicePathNode = DevicePath;

+    DevicePath = NextDevicePathNode (DevicePath);

+  }

+

+  return PrevDevicePathNode;

+}

+

+EFI_STATUS

+GenerateDeviceDescriptionName (

+  IN  EFI_HANDLE  Handle,

+  IN OUT CHAR16*  Description

+  )

+{

+  EFI_STATUS                        Status;

+  EFI_COMPONENT_NAME_PROTOCOL*      ComponentName2Protocol;

+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+  EFI_DEVICE_PATH_PROTOCOL*         DevicePathProtocol;

+  CHAR16*                           DriverName;

+  CHAR16*                           DevicePathTxt;

+  EFI_DEVICE_PATH*                  DevicePathNode;

+

+  ComponentName2Protocol = NULL;

+  Status = gBS->HandleProtocol (Handle, &gEfiComponentName2ProtocolGuid, (VOID **)&ComponentName2Protocol);

+  if (!EFI_ERROR(Status)) {

+    //TODO: Fixme. we must find the best langague

+    Status = ComponentName2Protocol->GetDriverName (ComponentName2Protocol,"en",&DriverName);

+    if (!EFI_ERROR(Status)) {

+      StrnCpy (Description, DriverName, BOOT_DEVICE_DESCRIPTION_MAX);

+    }

+  }

+

+  if (EFI_ERROR(Status)) {

+    // Use the lastest non null entry of the Device path as a description

+    Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);

+    if (EFI_ERROR(Status)) {

+      return Status;

+    }

+

+    // Convert the last non end-type Device Path Node in text for the description

+    DevicePathNode = GetLastDevicePathNode (DevicePathProtocol);

+    Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+    ASSERT_EFI_ERROR(Status);

+    DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePathNode, TRUE, TRUE);

+    StrnCpy (Description, DevicePathTxt, BOOT_DEVICE_DESCRIPTION_MAX);

+    FreePool (DevicePathTxt);

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BdsStartBootOption (

+  IN CHAR16* BootOption

+  )

+{

+  EFI_STATUS          Status;

+  BDS_LOAD_OPTION     *BdsLoadOption;

+

+  Status = BootOptionFromLoadOptionVariable (BootOption, &BdsLoadOption);

+  if (!EFI_ERROR(Status)) {

+    Status = BootOptionStart (BdsLoadOption);

+    FreePool (BdsLoadOption);

+

+    if (!EFI_ERROR(Status)) {

+      Status = EFI_SUCCESS;

+    } else {

+      Status = EFI_NOT_STARTED;

+    }

+  } else {

+    Status = EFI_NOT_FOUND;

+  }

+  return Status;

+}

+

+UINTN

+GetUnalignedDevicePathSize (

+  IN EFI_DEVICE_PATH* DevicePath

+  )

+{

+  UINTN Size;

+  EFI_DEVICE_PATH* AlignedDevicePath;

+

+  if ((UINTN)DevicePath & 0x1) {

+    AlignedDevicePath = DuplicateDevicePath (DevicePath);

+    Size = GetDevicePathSize (AlignedDevicePath);

+    FreePool (AlignedDevicePath);

+  } else {

+    Size = GetDevicePathSize (DevicePath);

+  }

+  return Size;

+}

+

+EFI_DEVICE_PATH*

+GetAlignedDevicePath (

+  IN EFI_DEVICE_PATH* DevicePath

+  )

+{

+  if ((UINTN)DevicePath & 0x1) {

+    return DuplicateDevicePath (DevicePath);

+  } else {

+    return DevicePath;

+  }

+}

+

+BOOLEAN

+IsUnicodeString (

+  IN VOID* String

+  )

+{

+  // We do not support NULL pointer

+  ASSERT (String != NULL);

+

+  if (*(CHAR16*)String < 0x100) {

+    //Note: We could get issue if the string is an empty Ascii string...

+    return TRUE;

+  } else {

+    return FALSE;

+  }

+}

+

+/*

+ * Try to detect if the given string is an ASCII or Unicode string

+ *

+ * There are actually few limitation to this function but it is mainly to give

+ * a user friendly output.

+ *

+ * Some limitations:

+ *   - it only supports unicode string that use ASCII character (< 0x100)

+ *   - single character ASCII strings are interpreted as Unicode string

+ *   - string cannot be longer than BOOT_DEVICE_OPTION_MAX characters and

+ *     thus (BOOT_DEVICE_OPTION_MAX*2) bytes for an Unicode string and

+ *     BOOT_DEVICE_OPTION_MAX bytes for an ASCII string.

+ *

+ * @param String    Buffer that might contain a Unicode or Ascii string

+ * @param IsUnicode If not NULL this boolean value returns if the string is an

+ *                  ASCII or Unicode string.

+ */

+BOOLEAN

+IsPrintableString (

+  IN  VOID*    String,

+  OUT BOOLEAN *IsUnicode

+  )

+{

+  BOOLEAN UnicodeDetected;

+  BOOLEAN IsPrintable;

+  UINTN Index;

+  CHAR16 Character;

+

+  // We do not support NULL pointer

+  ASSERT (String != NULL);

+

+  // Test empty string

+  if (*(CHAR16*)String == L'\0') {

+    if (IsUnicode) {

+      *IsUnicode = TRUE;

+    }

+    return TRUE;

+  } else if (*(CHAR16*)String == '\0') {

+    if (IsUnicode) {

+      *IsUnicode = FALSE;

+    }

+    return TRUE;

+  }

+

+  // Limitation: if the string is an ASCII single character string. This comparison

+  // will assume it is a Unicode string.

+  if (*(CHAR16*)String < 0x100) {

+    UnicodeDetected = TRUE;

+  } else {

+    UnicodeDetected = FALSE;

+  }

+

+  IsPrintable = FALSE;

+  for (Index = 0; Index < BOOT_DEVICE_OPTION_MAX; Index++) {

+    if (UnicodeDetected) {

+      Character = ((CHAR16*)String)[Index];

+    } else {

+      Character = ((CHAR8*)String)[Index];

+    }

+

+    if (Character == '\0') {

+      // End of the string

+      IsPrintable = TRUE;

+      break;

+    } else if ((Character < 0x20) || (Character > 0x7f)) {

+      // We only support the range of printable ASCII character

+      IsPrintable = FALSE;

+      break;

+    }

+  }

+

+  if (IsPrintable && IsUnicode) {

+    *IsUnicode = UnicodeDetected;

+  }

+

+  return IsPrintable;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Bds/BdsInternal.h b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BdsInternal.h
new file mode 100644
index 0000000..95cc0b6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BdsInternal.h
@@ -0,0 +1,307 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#ifndef _BDSINTERNAL_H_

+#define _BDSINTERNAL_H_

+

+#include <PiDxe.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/BdsLib.h>

+#include <Library/DebugLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/UefiLib.h>

+#include <Library/PrintLib.h>

+#include <Library/PcdLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+

+#include <Protocol/DevicePathFromText.h>

+#include <Protocol/DevicePathToText.h>

+

+#include <Guid/GlobalVariable.h>

+

+#define BOOT_DEVICE_DESCRIPTION_MAX   100

+#define BOOT_DEVICE_FILEPATH_MAX      100

+#define BOOT_DEVICE_OPTION_MAX        300

+#define BOOT_DEVICE_ADDRESS_MAX       (sizeof(L"0x0000000000000000"))

+

+#define ARM_BDS_OPTIONAL_DATA_SIGNATURE   SIGNATURE_32('a', 'b', 'o', 'd')

+

+#define IS_ARM_BDS_BOOTENTRY(ptr)  \

+  (((ptr)->OptionalData != NULL) && \

+   (ReadUnaligned32 ((CONST UINT32*)&((ARM_BDS_LOADER_OPTIONAL_DATA*)((ptr)->OptionalData))->Header.Signature) \

+      == ARM_BDS_OPTIONAL_DATA_SIGNATURE))

+

+#define UPDATE_BOOT_ENTRY L"Update entry: "

+#define DELETE_BOOT_ENTRY L"Delete entry: "

+#define MOVE_BOOT_ENTRY   L"Move entry: "

+

+typedef enum {

+    BDS_LOADER_EFI_APPLICATION = 0,

+    BDS_LOADER_KERNEL_LINUX_ATAG,

+    BDS_LOADER_KERNEL_LINUX_FDT,

+} ARM_BDS_LOADER_TYPE;

+

+typedef struct {

+  UINT16                     CmdLineSize;

+  UINT16                     InitrdSize;

+

+  // These following fields have variable length and are packed:

+  //CHAR8                      *CmdLine;

+  //EFI_DEVICE_PATH_PROTOCOL   *InitrdPathList;

+} ARM_BDS_LINUX_ARGUMENTS;

+

+typedef union {

+  ARM_BDS_LINUX_ARGUMENTS    LinuxArguments;

+} ARM_BDS_LOADER_ARGUMENTS;

+

+typedef struct {

+  UINT32                     Signature;

+  ARM_BDS_LOADER_TYPE        LoaderType;

+} ARM_BDS_LOADER_OPTIONAL_DATA_HEADER;

+

+typedef struct {

+  ARM_BDS_LOADER_OPTIONAL_DATA_HEADER Header;

+  ARM_BDS_LOADER_ARGUMENTS            Arguments;

+} ARM_BDS_LOADER_OPTIONAL_DATA;

+

+typedef struct {

+  LIST_ENTRY                  Link;

+  BDS_LOAD_OPTION*            BdsLoadOption;

+} BDS_LOAD_OPTION_ENTRY;

+

+typedef enum {

+  BDS_DEVICE_FILESYSTEM = 0,

+  BDS_DEVICE_MEMMAP,

+  BDS_DEVICE_PXE,

+  BDS_DEVICE_TFTP,

+  BDS_DEVICE_MAX

+} BDS_SUPPORTED_DEVICE_TYPE;

+

+typedef struct {

+  LIST_ENTRY                          Link;

+  CHAR16                              Description[BOOT_DEVICE_DESCRIPTION_MAX];

+  EFI_DEVICE_PATH_PROTOCOL*           DevicePathProtocol;

+  struct _BDS_LOAD_OPTION_SUPPORT*    Support;

+} BDS_SUPPORTED_DEVICE;

+

+#define SUPPORTED_BOOT_DEVICE_FROM_LINK(a)   BASE_CR(a, BDS_SUPPORTED_DEVICE, Link)

+

+typedef struct _BDS_LOAD_OPTION_SUPPORT {

+  BDS_SUPPORTED_DEVICE_TYPE   Type;

+  EFI_STATUS    (*ListDevices)(IN OUT LIST_ENTRY* BdsLoadOptionList);

+  BOOLEAN       (*IsSupported)(IN  EFI_DEVICE_PATH *DevicePath);

+  EFI_STATUS    (*CreateDevicePathNode)(IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes);

+  EFI_STATUS    (*UpdateDevicePathNode)(IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath);

+

+  /// Define if the boot menu should request if the file is a EFI binary or a Linux kernel

+  /// Example: PXE boot always deliver a UEFI application.

+  BOOLEAN       RequestBootType;

+} BDS_LOAD_OPTION_SUPPORT;

+

+#define LOAD_OPTION_ENTRY_FROM_LINK(a)  BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link)

+#define LOAD_OPTION_FROM_LINK(a)        ((BDS_LOAD_OPTION_ENTRY*)BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link))->BdsLoadOption

+

+EFI_STATUS

+BootDeviceListSupportedInit (

+  IN OUT LIST_ENTRY *SupportedDeviceList

+  );

+

+EFI_STATUS

+BootDeviceListSupportedFree (

+  IN LIST_ENTRY *SupportedDeviceList,

+  IN BDS_SUPPORTED_DEVICE *Except

+  );

+

+EFI_STATUS

+BootDeviceGetDeviceSupport (

+  IN  EFI_DEVICE_PATH           *DevicePath,

+  OUT BDS_LOAD_OPTION_SUPPORT   **DeviceSupport

+  );

+

+EFI_STATUS

+GetHIInputStr (

+  IN OUT CHAR16  *CmdLine,

+  IN     UINTN   MaxCmdLine

+  );

+

+EFI_STATUS

+EditHIInputStr (

+  IN OUT CHAR16  *CmdLine,

+  IN     UINTN   MaxCmdLine

+  );

+

+EFI_STATUS

+GetHIInputAscii (

+  IN OUT CHAR8   *CmdLine,

+  IN     UINTN   MaxCmdLine

+  );

+

+EFI_STATUS

+EditHIInputAscii (

+  IN OUT CHAR8   *CmdLine,

+  IN     UINTN   MaxCmdLine

+  );

+

+EFI_STATUS

+GetHIInputInteger (

+  IN OUT UINTN   *Integer

+  );

+

+EFI_STATUS

+GetHIInputIP (

+  OUT EFI_IP_ADDRESS   *Ip

+  );

+

+EFI_STATUS

+EditHIInputIP (

+  IN  EFI_IP_ADDRESS  *InIpAddr,

+  OUT EFI_IP_ADDRESS  *OutIpAddr

+  );

+

+EFI_STATUS

+GetHIInputBoolean (

+  OUT BOOLEAN *Value

+  );

+

+BOOLEAN

+HasFilePathEfiExtension (

+  IN CHAR16* FilePath

+  );

+

+EFI_DEVICE_PATH*

+GetLastDevicePathNode (

+  IN EFI_DEVICE_PATH*  DevicePath

+  );

+

+EFI_STATUS

+BdsStartBootOption (

+  IN CHAR16* BootOption

+  );

+

+UINTN

+GetUnalignedDevicePathSize (

+  IN EFI_DEVICE_PATH* DevicePath

+  );

+

+EFI_DEVICE_PATH*

+GetAlignedDevicePath (

+  IN EFI_DEVICE_PATH* DevicePath

+  );

+

+EFI_STATUS

+GenerateDeviceDescriptionName (

+  IN  EFI_HANDLE  Handle,

+  IN OUT CHAR16*  Description

+  );

+

+EFI_STATUS

+BootOptionList (

+  IN OUT LIST_ENTRY *BootOptionList

+  );

+

+EFI_STATUS

+BootOptionParseLoadOption (

+  IN  EFI_LOAD_OPTION EfiLoadOption,

+  IN  UINTN           EfiLoadOptionSize,

+  OUT BDS_LOAD_OPTION **BdsLoadOption

+  );

+

+EFI_STATUS

+BootOptionStart (

+  IN BDS_LOAD_OPTION *BootOption

+  );

+

+EFI_STATUS

+BootOptionCreate (

+  IN  UINT32                    Attributes,

+  IN  CHAR16*                   BootDescription,

+  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,

+  IN  ARM_BDS_LOADER_TYPE       BootType,

+  IN  UINT8*                    OptionalData,

+  IN  UINTN                     OptionalDataSize,

+  OUT BDS_LOAD_OPTION**         BdsLoadOption

+  );

+

+EFI_STATUS

+BootOptionUpdate (

+  IN  BDS_LOAD_OPTION*          BdsLoadOption,

+  IN  UINT32                    Attributes,

+  IN  CHAR16*                   BootDescription,

+  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,

+  IN  ARM_BDS_LOADER_TYPE       BootType,

+  IN UINT8*                     OptionalData,

+  IN UINTN                      OptionalDataSize

+  );

+

+EFI_STATUS

+BootOptionDelete (

+  IN  BDS_LOAD_OPTION *BootOption

+  );

+

+EFI_STATUS

+BootDeviceGetType (

+  IN  EFI_DEVICE_PATH* DevicePath,

+  OUT ARM_BDS_LOADER_TYPE *BootType,

+  OUT UINT32 *Attributes

+  );

+

+EFI_STATUS

+BootMenuMain (

+  VOID

+  );

+

+BOOLEAN

+IsUnicodeString (

+  IN VOID* String

+  );

+

+/*

+ * Try to detect if the given string is an ASCII or Unicode string

+ *

+ * There are actually few limitation to this function but it is mainly to give

+ * a user friendly output.

+ *

+ * Some limitations:

+ *   - it only supports unicode string that use ASCII character (< 0x100)

+ *   - single character ASCII strings are interpreted as Unicode string

+ *   - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)

+ *

+ * @param String    Buffer that might contain a Unicode or Ascii string

+ * @param IsUnicode If not NULL this boolean value returns if the string is an

+ *                  ASCII or Unicode string.

+ */

+BOOLEAN

+IsPrintableString (

+  IN  VOID*    String,

+  OUT BOOLEAN *IsUnicode

+  );

+

+/**

+  An empty function to pass error checking of CreateEventEx ().

+

+  @param  Event                 Event whose notification function is being invoked.

+  @param  Context               Pointer to the notification function's context,

+                                which is implementation-dependent.

+

+**/

+VOID

+EFIAPI

+EmptyCallbackFunction (

+  IN EFI_EVENT                Event,

+  IN VOID                     *Context

+  );

+

+#endif /* _BDSINTERNAL_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootMenu.c b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootMenu.c
new file mode 100644
index 0000000..3676bf0
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootMenu.c
@@ -0,0 +1,1164 @@
+/** @file

+*

+*  Copyright (c) 2011 - 2015, ARM 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.

+*

+**/

+

+#include "BdsInternal.h"

+

+#include <Guid/ArmGlobalVariableHob.h>

+#include <Guid/ArmPlatformEvents.h>

+

+extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;

+

+/**

+  Worker function that displays the list of boot options that is passed in.

+

+  The function loops over the entries of the list of boot options that is passed

+  in. For each entry, the boot option description is displayed on a single line

+  along with the position of the option in the list. In debug mode, the UEFI

+  device path and the arguments of the boot option are displayed as well in

+  subsequent lines.

+

+  @param[in]  BootOptionsList  List of the boot options

+

+**/

+STATIC

+VOID

+DisplayBootOptions (

+  IN  LIST_ENTRY*   BootOptionsList

+  )

+{

+  EFI_STATUS        Status;

+  UINTN             BootOptionCount;

+  LIST_ENTRY       *Entry;

+  BDS_LOAD_OPTION  *BdsLoadOption;

+  BOOLEAN           IsUnicode;

+

+  BootOptionCount = 0 ;

+  for (Entry = GetFirstNode (BootOptionsList);

+       !IsNull (BootOptionsList, Entry);

+       Entry = GetNextNode (BootOptionsList, Entry)

+      ) {

+

+    BdsLoadOption = LOAD_OPTION_FROM_LINK (Entry);

+    Print (L"[%d] %s\n", ++BootOptionCount, BdsLoadOption->Description);

+

+    DEBUG_CODE_BEGIN ();

+      CHAR16*                           DevicePathTxt;

+      EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+      ARM_BDS_LOADER_TYPE               LoaderType;

+      ARM_BDS_LOADER_OPTIONAL_DATA*     OptionalData;

+

+      Status = gBS->LocateProtocol (

+                     &gEfiDevicePathToTextProtocolGuid,

+                     NULL,

+                     (VOID **)&DevicePathToTextProtocol

+                     );

+      ASSERT_EFI_ERROR (Status);

+      DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (

+                                                  BdsLoadOption->FilePathList,

+                                                  TRUE,

+                                                  TRUE

+                                                  );

+      Print (L"\t- %s\n", DevicePathTxt);

+

+      OptionalData = BdsLoadOption->OptionalData;

+      if (IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {

+        LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);

+        if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) ||

+            (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT )   ) {

+          Print (L"\t- Arguments: %a\n", &OptionalData->Arguments.LinuxArguments + 1);

+        }

+      } else if (OptionalData != NULL) {

+        if (IsPrintableString (OptionalData, &IsUnicode)) {

+          if (IsUnicode) {

+            Print (L"\t- Arguments: %s\n", OptionalData);

+          } else {

+            AsciiPrint ("\t- Arguments: %a\n", OptionalData);

+          }

+        }

+      }

+

+      FreePool (DevicePathTxt);

+    DEBUG_CODE_END ();

+  }

+}

+

+/**

+  Worker function that asks for a boot option to be selected and returns a

+  pointer to the structure describing the selected boot option.

+

+  @param[in]  BootOptionsList  List of the boot options

+

+  @retval     EFI_SUCCESS      Selection succeeded

+  @retval     !EFI_SUCCESS     Input error or input cancelled

+

+**/

+STATIC

+EFI_STATUS

+SelectBootOption (

+  IN  LIST_ENTRY*               BootOptionsList,

+  IN  CONST CHAR16*             InputStatement,

+  OUT BDS_LOAD_OPTION_ENTRY**   BdsLoadOptionEntry

+  )

+{

+  EFI_STATUS                    Status;

+  UINTN                         BootOptionCount;

+  UINT16                       *BootOrder;

+  LIST_ENTRY*                   Entry;

+  UINTN                         BootOptionSelected;

+  UINTN                         Index;

+

+  // Get the number of boot options

+  Status = GetGlobalEnvironmentVariable (

+            L"BootOrder", NULL, &BootOptionCount, (VOID**)&BootOrder

+            );

+  if (EFI_ERROR (Status)) {

+    goto ErrorExit;

+  }

+  FreePool (BootOrder);

+  BootOptionCount /= sizeof (UINT16);

+

+  // Check if a valid boot option(s) is found

+  if (BootOptionCount == 0) {

+    if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {

+      Print (L"Nothing to remove!\n");

+    } else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {

+      Print (L"Nothing to update!\n");

+    } else if (StrCmp (InputStatement, MOVE_BOOT_ENTRY) == 0) {

+      Print (L"Nothing to move!\n");

+    } else {

+      Print (L"No supported Boot Entry.\n");

+    }

+    return EFI_NOT_FOUND;

+  }

+

+  // Get the index of the boot device to delete

+  BootOptionSelected = 0;

+  while (BootOptionSelected == 0) {

+    Print (InputStatement);

+    Status = GetHIInputInteger (&BootOptionSelected);

+    if (EFI_ERROR (Status)) {

+      Print (L"\n");

+      goto ErrorExit;

+    } else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {

+      Print (L"Invalid input (max %d)\n", BootOptionCount);

+      BootOptionSelected = 0;

+    }

+  }

+

+  // Get the structure of the Boot device to delete

+  Index = 1;

+  for (Entry = GetFirstNode (BootOptionsList);

+       !IsNull (BootOptionsList, Entry);

+       Entry = GetNextNode (BootOptionsList,Entry)

+       )

+  {

+    if (Index == BootOptionSelected) {

+      *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK (Entry);

+      break;

+    }

+    Index++;

+  }

+

+ErrorExit:

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+SelectBootDevice (

+  OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice

+  )

+{

+  EFI_STATUS  Status;

+  LIST_ENTRY  SupportedDeviceList;

+  UINTN       SupportedDeviceCount;

+  LIST_ENTRY* Entry;

+  UINTN       SupportedDeviceSelected;

+  UINTN       Index;

+

+  //

+  // List the Boot Devices supported

+  //

+

+  // Start all the drivers first

+  BdsConnectAllDrivers ();

+

+  // List the supported devices

+  Status = BootDeviceListSupportedInit (&SupportedDeviceList);

+  ASSERT_EFI_ERROR(Status);

+

+  SupportedDeviceCount = 0;

+  for (Entry = GetFirstNode (&SupportedDeviceList);

+       !IsNull (&SupportedDeviceList,Entry);

+       Entry = GetNextNode (&SupportedDeviceList,Entry)

+       )

+  {

+    *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);

+    Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);

+

+    DEBUG_CODE_BEGIN();

+      CHAR16*                           DevicePathTxt;

+      EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+

+      Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+      ASSERT_EFI_ERROR(Status);

+      DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);

+

+      Print(L"\t- %s\n",DevicePathTxt);

+

+      FreePool(DevicePathTxt);

+    DEBUG_CODE_END();

+

+    SupportedDeviceCount++;

+  }

+

+  if (SupportedDeviceCount == 0) {

+    Print(L"There is no supported device.\n");

+    Status = EFI_ABORTED;

+    goto EXIT;

+  }

+

+  //

+  // Select the Boot Device

+  //

+  SupportedDeviceSelected = 0;

+  while (SupportedDeviceSelected == 0) {

+    Print(L"Select the Boot Device: ");

+    Status = GetHIInputInteger (&SupportedDeviceSelected);

+    if (EFI_ERROR(Status)) {

+      Status = EFI_ABORTED;

+      goto EXIT;

+    } else if ((SupportedDeviceSelected == 0) || (SupportedDeviceSelected > SupportedDeviceCount)) {

+      Print(L"Invalid input (max %d)\n",SupportedDeviceCount);

+      SupportedDeviceSelected = 0;

+    }

+  }

+

+  //

+  // Get the Device Path for the selected boot device

+  //

+  Index = 1;

+  for (Entry = GetFirstNode (&SupportedDeviceList);

+       !IsNull (&SupportedDeviceList,Entry);

+       Entry = GetNextNode (&SupportedDeviceList,Entry)

+       )

+  {

+    if (Index == SupportedDeviceSelected) {

+      *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);

+      break;

+    }

+    Index++;

+  }

+

+EXIT:

+  BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);

+  return Status;

+}

+

+EFI_STATUS

+BootMenuAddBootOption (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  EFI_STATUS                Status;

+  BDS_SUPPORTED_DEVICE*     SupportedBootDevice;

+  ARM_BDS_LOADER_ARGUMENTS* BootArguments;

+  CHAR16                    BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];

+  CHAR8                     AsciiCmdLine[BOOT_DEVICE_OPTION_MAX];

+  CHAR16                    CmdLine[BOOT_DEVICE_OPTION_MAX];

+  UINT32                    Attributes;

+  ARM_BDS_LOADER_TYPE       BootType;

+  BDS_LOAD_OPTION_ENTRY     *BdsLoadOptionEntry;

+  EFI_DEVICE_PATH           *DevicePath;

+  EFI_DEVICE_PATH_PROTOCOL  *DevicePathNodes;

+  EFI_DEVICE_PATH_PROTOCOL  *InitrdPathNodes;

+  EFI_DEVICE_PATH_PROTOCOL  *InitrdPath;

+  UINTN                     CmdLineSize;

+  BOOLEAN                   InitrdSupport;

+  UINTN                     InitrdSize;

+  UINT8*                    OptionalData;

+  UINTN                     OptionalDataSize;

+

+  Attributes                = 0;

+  SupportedBootDevice = NULL;

+

+  // List the Boot Devices supported

+  Status = SelectBootDevice (&SupportedBootDevice);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_ABORTED;

+    goto EXIT;

+  }

+

+  // Create the specific device path node

+  Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_ABORTED;

+    goto EXIT;

+  }

+  // Append the Device Path to the selected device path

+  DevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNodes);

+  if (DevicePath == NULL) {

+    Status = EFI_OUT_OF_RESOURCES;

+    goto EXIT;

+  }

+

+  if (SupportedBootDevice->Support->RequestBootType) {

+    Status = BootDeviceGetType (DevicePath, &BootType, &Attributes);

+    if (EFI_ERROR(Status)) {

+      Status = EFI_ABORTED;

+      goto EXIT;

+    }

+  } else {

+    BootType = BDS_LOADER_EFI_APPLICATION;

+  }

+

+  if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {

+    Print(L"Add an initrd: ");

+    Status = GetHIInputBoolean (&InitrdSupport);

+    if (EFI_ERROR(Status)) {

+      Status = EFI_ABORTED;

+      goto EXIT;

+    }

+

+    if (InitrdSupport) {

+      // Create the specific device path node

+      Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes);

+      if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd

+        Status = EFI_ABORTED;

+        goto EXIT;

+      }

+

+      if (InitrdPathNodes != NULL) {

+        // Append the Device Path to the selected device path

+        InitrdPath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);

+        // Free the InitrdPathNodes created by Support->CreateDevicePathNode()

+        FreePool (InitrdPathNodes);

+

+        if (InitrdPath == NULL) {

+          Status = EFI_OUT_OF_RESOURCES;

+          goto EXIT;

+        }

+      } else {

+        InitrdPath = NULL;

+      }

+    } else {

+      InitrdPath = NULL;

+    }

+

+    Print(L"Arguments to pass to the binary: ");

+    Status = GetHIInputAscii (AsciiCmdLine, BOOT_DEVICE_OPTION_MAX);

+    if (EFI_ERROR(Status)) {

+      Status = EFI_ABORTED;

+      goto FREE_DEVICE_PATH;

+    }

+

+    CmdLineSize = AsciiStrSize (AsciiCmdLine);

+    InitrdSize = GetDevicePathSize (InitrdPath);

+

+    OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;

+    BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);

+

+    BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;

+    BootArguments->LinuxArguments.InitrdSize = InitrdSize;

+    CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), AsciiCmdLine, CmdLineSize);

+    CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);

+

+    OptionalData = (UINT8*)BootArguments;

+  } else {

+    Print (L"Arguments to pass to the EFI Application: ");

+    Status = GetHIInputStr (CmdLine, BOOT_DEVICE_OPTION_MAX);

+    if (EFI_ERROR (Status)) {

+      Status = EFI_ABORTED;

+      goto EXIT;

+    }

+

+    OptionalData = (UINT8*)CmdLine;

+    OptionalDataSize = StrSize (CmdLine);

+  }

+

+  Print(L"Description for this new Entry: ");

+  Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_ABORTED;

+    goto FREE_DEVICE_PATH;

+  }

+

+  // Create new entry

+  BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));

+  Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize, &BdsLoadOptionEntry->BdsLoadOption);

+  if (!EFI_ERROR(Status)) {

+    InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);

+  }

+

+FREE_DEVICE_PATH:

+  FreePool (DevicePath);

+

+EXIT:

+  if (Status == EFI_ABORTED) {

+    Print(L"\n");

+  }

+  FreePool(SupportedBootDevice);

+  return Status;

+}

+

+EFI_STATUS

+BootMenuRemoveBootOption (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  EFI_STATUS                    Status;

+  BDS_LOAD_OPTION_ENTRY*        BootOptionEntry;

+

+  DisplayBootOptions (BootOptionsList);

+  Status = SelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, &BootOptionEntry);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // If the Boot Option was attached to a list remove it

+  if (!IsListEmpty (&BootOptionEntry->Link)) {

+    // Remove the entry from the list

+    RemoveEntryList (&BootOptionEntry->Link);

+  }

+

+  // Delete the BDS Load option structures

+  BootOptionDelete (BootOptionEntry->BdsLoadOption);

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BootMenuUpdateBootOption (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  EFI_STATUS                    Status;

+  BDS_LOAD_OPTION_ENTRY         *BootOptionEntry;

+  BDS_LOAD_OPTION               *BootOption;

+  BDS_LOAD_OPTION_SUPPORT*      DeviceSupport;

+  ARM_BDS_LOADER_ARGUMENTS*     BootArguments;

+  CHAR16                        BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];

+  CHAR8                         CmdLine[BOOT_DEVICE_OPTION_MAX];

+  CHAR16                        UnicodeCmdLine[BOOT_DEVICE_OPTION_MAX];

+  EFI_DEVICE_PATH               *DevicePath;

+  EFI_DEVICE_PATH               *TempInitrdPath;

+  ARM_BDS_LOADER_TYPE           BootType;

+  ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData;

+  ARM_BDS_LINUX_ARGUMENTS*      LinuxArguments;

+  EFI_DEVICE_PATH               *InitrdPathNodes;

+  EFI_DEVICE_PATH               *InitrdPath;

+  UINTN                         InitrdSize;

+  UINTN                         CmdLineSize;

+  BOOLEAN                       InitrdSupport;

+  UINT8*                        OptionalData;

+  UINTN                         OptionalDataSize;

+  BOOLEAN                       IsPrintable;

+  BOOLEAN                       IsUnicode;

+

+  DisplayBootOptions (BootOptionsList);

+  Status = SelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, &BootOptionEntry);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+  BootOption = BootOptionEntry->BdsLoadOption;

+

+  // Get the device support for this Boot Option

+  Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);

+  if (EFI_ERROR(Status)) {

+    Print(L"Not possible to retrieve the supported device for the update\n");

+    return EFI_UNSUPPORTED;

+  }

+

+  Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_ABORTED;

+    goto EXIT;

+  }

+

+  if (DeviceSupport->RequestBootType) {

+    Status = BootDeviceGetType (DevicePath, &BootType, &BootOption->Attributes);

+    if (EFI_ERROR(Status)) {

+      Status = EFI_ABORTED;

+      goto EXIT;

+    }

+  }

+

+  LoaderOptionalData = BootOption->OptionalData;

+  if (LoaderOptionalData != NULL) {

+    BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType));

+  } else {

+    BootType = BDS_LOADER_EFI_APPLICATION;

+  }

+

+  if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {

+    LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments;

+

+    CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);

+

+    InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);

+    if (InitrdSize > 0) {

+      Print(L"Keep the initrd: ");

+    } else {

+      Print(L"Add an initrd: ");

+    }

+    Status = GetHIInputBoolean (&InitrdSupport);

+    if (EFI_ERROR(Status)) {

+      Status = EFI_ABORTED;

+      goto EXIT;

+    }

+

+    if (InitrdSupport) {

+      if (InitrdSize > 0) {

+        // Case we update the initrd device path

+        Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath);

+        if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd

+          Status = EFI_ABORTED;

+          goto EXIT;

+        }

+        InitrdSize = GetDevicePathSize (InitrdPath);

+      } else {

+        // Case we create the initrd device path

+

+        Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes);

+        if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd

+          Status = EFI_ABORTED;

+          goto EXIT;

+        }

+

+        if (InitrdPathNodes != NULL) {

+          // Duplicate Linux kernel Device Path

+          TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);

+          // Replace Linux kernel Node by EndNode

+          SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));

+          // Append the Device Path to the selected device path

+          InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);

+          FreePool (TempInitrdPath);

+          // Free the InitrdPathNodes created by Support->CreateDevicePathNode()

+          FreePool (InitrdPathNodes);

+          if (InitrdPath == NULL) {

+            Status = EFI_OUT_OF_RESOURCES;

+            goto EXIT;

+          }

+          InitrdSize = GetDevicePathSize (InitrdPath);

+        } else {

+          InitrdPath = NULL;

+        }

+      }

+    } else {

+      InitrdSize = 0;

+    }

+

+    Print(L"Arguments to pass to the binary: ");

+    if (CmdLineSize > 0) {

+      AsciiStrnCpy (CmdLine, (CONST CHAR8*)(LinuxArguments + 1), sizeof (CmdLine));

+      CmdLine[sizeof (CmdLine) - 1] = '\0';

+    } else {

+      CmdLine[0] = '\0';

+    }

+    Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);

+    if (EFI_ERROR(Status)) {

+      Status = EFI_ABORTED;

+      goto FREE_DEVICE_PATH;

+    }

+

+    CmdLineSize = AsciiStrSize (CmdLine);

+

+    OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;

+    BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);

+    BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;

+    BootArguments->LinuxArguments.InitrdSize = InitrdSize;

+    CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);

+    CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);

+

+    OptionalData = (UINT8*)BootArguments;

+  } else {

+    Print (L"Arguments to pass to the EFI Application: ");

+

+    if (BootOption->OptionalDataSize > 0) {

+      IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);

+      if (IsPrintable) {

+          //

+          // The size in bytes of the string, final zero included, should

+          // be equal to or at least lower than "BootOption->OptionalDataSize"

+          // and the "IsPrintableString()" has already tested that the length

+          // in number of characters is smaller than BOOT_DEVICE_OPTION_MAX,

+          // final '\0' included. We can thus copy the string for editing

+          // using "CopyMem()". Furthermore, note that in the case of an Unicode

+          // string "StrnCpy()" and "StrCpy()" can not be used to copy the

+          // string because the data pointed to by "BootOption->OptionalData"

+          // is not necessarily 2-byte aligned.

+          //

+        if (IsUnicode) {

+          CopyMem (

+            UnicodeCmdLine, BootOption->OptionalData,

+            MIN (sizeof (UnicodeCmdLine),

+                 BootOption->OptionalDataSize)

+            );

+        } else {

+          CopyMem (

+            CmdLine, BootOption->OptionalData,

+            MIN (sizeof (CmdLine),

+                 BootOption->OptionalDataSize)

+            );

+        }

+      }

+    } else {

+      UnicodeCmdLine[0] = L'\0';

+      IsPrintable = TRUE;

+      IsUnicode = TRUE;

+    }

+

+    // We do not request arguments for OptionalData that cannot be printed

+    if (IsPrintable) {

+      if (IsUnicode) {

+        Status = EditHIInputStr (UnicodeCmdLine, BOOT_DEVICE_OPTION_MAX);

+        if (EFI_ERROR (Status)) {

+          Status = EFI_ABORTED;

+          goto FREE_DEVICE_PATH;

+        }

+

+        OptionalData = (UINT8*)UnicodeCmdLine;

+        OptionalDataSize = StrSize (UnicodeCmdLine);

+      } else {

+        Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);

+        if (EFI_ERROR (Status)) {

+          Status = EFI_ABORTED;

+          goto FREE_DEVICE_PATH;

+        }

+

+        OptionalData = (UINT8*)CmdLine;

+        OptionalDataSize = AsciiStrSize (CmdLine);

+      }

+    } else {

+      // We keep the former OptionalData

+      OptionalData = BootOption->OptionalData;

+      OptionalDataSize = BootOption->OptionalDataSize;

+    }

+  }

+

+  Print(L"Description for this new Entry: ");

+  StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);

+  Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_ABORTED;

+    goto FREE_DEVICE_PATH;

+  }

+

+  // Update the entry

+  Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);

+

+FREE_DEVICE_PATH:

+  FreePool (DevicePath);

+

+EXIT:

+  if (Status == EFI_ABORTED) {

+    Print(L"\n");

+  }

+  return Status;

+}

+

+/**

+  Reorder boot options

+

+  Ask for the boot option to move and then move it when up or down arrows

+  are pressed. This function is called when the user selects the "Reorder Boot

+  Device Entries" entry in the boot manager menu.

+  The order of the boot options in BootOptionList and in the UEFI BootOrder

+  global variable are kept coherent until the user confirm his reordering (ie:

+  he does not exit by pressing escape).

+

+  @param[in]  BootOptionsList  List of the boot devices constructed in

+                               BootMenuMain()

+

+  @retval  EFI_SUCCESS   No error encountered.

+  @retval  !EFI_SUCCESS  An error has occured either in the selection of the

+                         boot option to move or while interacting with the user.

+

+**/

+STATIC

+EFI_STATUS

+BootMenuReorderBootOptions (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  EFI_STATUS              Status;

+  BDS_LOAD_OPTION_ENTRY  *BootOptionEntry;

+  LIST_ENTRY             *SelectedEntry;

+  LIST_ENTRY             *PrevEntry;

+  BOOLEAN                 Move;

+  BOOLEAN                 Save;

+  BOOLEAN                 Cancel;

+  UINTN                   WaitIndex;

+  EFI_INPUT_KEY           Key;

+  LIST_ENTRY             *SecondEntry;

+  UINTN                   BootOrderSize;

+  UINT16                 *BootOrder;

+  LIST_ENTRY             *Entry;

+  UINTN                   Index;

+

+  DisplayBootOptions (BootOptionsList);

+

+  // Ask to select the boot option to move

+  while (TRUE) {

+    Status = SelectBootOption (BootOptionsList, MOVE_BOOT_ENTRY, &BootOptionEntry);

+    if (EFI_ERROR (Status)) {

+      goto ErrorExit;

+    }

+

+    SelectedEntry = &BootOptionEntry->Link;

+    SecondEntry = NULL;

+    // Note down the previous entry in the list to be able to cancel changes

+    PrevEntry = GetPreviousNode (BootOptionsList, SelectedEntry);

+

+    //  Start of interaction

+    while (TRUE) {

+      Print (

+        L"* Use up/down arrows to move the entry '%s'",

+        BootOptionEntry->BdsLoadOption->Description

+        );

+

+      // Wait for a move, save or cancel request

+      Move   = FALSE;

+      Save   = FALSE;

+      Cancel = FALSE;

+      do {

+        Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);

+        if (!EFI_ERROR (Status)) {

+          Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);

+        }

+        if (EFI_ERROR (Status)) {

+          Print (L"\n");

+          goto ErrorExit;

+        }

+

+        switch (Key.ScanCode) {

+        case SCAN_NULL:

+          Save = (Key.UnicodeChar == CHAR_LINEFEED)        ||

+                 (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) ||

+                 (Key.UnicodeChar == 0x7f);

+          break;

+

+        case SCAN_UP:

+          SecondEntry = GetPreviousNode (BootOptionsList, SelectedEntry);

+          Move = SecondEntry != BootOptionsList;

+          break;

+

+        case SCAN_DOWN:

+          SecondEntry = GetNextNode (BootOptionsList, SelectedEntry);

+          Move = SecondEntry != BootOptionsList;

+          break;

+

+        case SCAN_ESC:

+          Cancel = TRUE;

+          break;

+        }

+      } while ((!Move) && (!Save) && (!Cancel));

+

+      if (Move) {

+        if ((SelectedEntry != NULL) && (SecondEntry != NULL)) {

+          SwapListEntries (SelectedEntry, SecondEntry);

+        }

+      } else {

+        if (Save) {

+          Status = GetGlobalEnvironmentVariable (

+                    L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder

+                    );

+          BootOrderSize /= sizeof (UINT16);

+

+          if (!EFI_ERROR (Status)) {

+            // The order of the boot options in the 'BootOptionsList' is the

+            // new order that has been just defined by the user. Save this new

+            // order in "BootOrder" UEFI global variable.

+            Entry = GetFirstNode (BootOptionsList);

+            for (Index = 0; Index < BootOrderSize; Index++) {

+              BootOrder[Index] = (LOAD_OPTION_FROM_LINK (Entry))->LoadOptionIndex;

+              Entry = GetNextNode (BootOptionsList, Entry);

+            }

+            Status = gRT->SetVariable (

+                           (CHAR16*)L"BootOrder",

+                           &gEfiGlobalVariableGuid,

+                           EFI_VARIABLE_NON_VOLATILE       |

+                           EFI_VARIABLE_BOOTSERVICE_ACCESS |

+                           EFI_VARIABLE_RUNTIME_ACCESS,

+                           BootOrderSize * sizeof (UINT16),

+                           BootOrder

+                           );

+            FreePool (BootOrder);

+          }

+

+          if (EFI_ERROR (Status)) {

+            Print (L"\nAn error occurred, move not completed!\n");

+            Cancel = TRUE;

+          }

+        }

+

+        if (Cancel) {

+          //

+          // Restore initial position of the selected boot option

+          //

+          RemoveEntryList (SelectedEntry);

+          InsertHeadList (PrevEntry, SelectedEntry);

+        }

+      }

+

+      Print (L"\n");

+      DisplayBootOptions (BootOptionsList);

+      // Saved or cancelled, back to the choice of boot option to move

+      if (!Move) {

+        break;

+      }

+    }

+  }

+

+ErrorExit:

+  return Status ;

+}

+

+EFI_STATUS

+UpdateFdtPath (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  EFI_STATUS                Status;

+  UINTN                     FdtDevicePathSize;

+  BDS_SUPPORTED_DEVICE      *SupportedBootDevice;

+  EFI_DEVICE_PATH_PROTOCOL  *FdtDevicePathNodes;

+  EFI_DEVICE_PATH_PROTOCOL  *FdtDevicePath;

+  EFI_EVENT                 UpdateFdtEvent;

+

+  Status = SelectBootDevice (&SupportedBootDevice);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_ABORTED;

+    goto EXIT;

+  }

+

+  // Create the specific device path node

+  Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_ABORTED;

+    goto EXIT;

+  }

+

+  if (FdtDevicePathNodes != NULL) {

+    // Append the Device Path node to the select device path

+    FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);

+    // Free the FdtDevicePathNodes created by Support->CreateDevicePathNode()

+    FreePool (FdtDevicePathNodes);

+    FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);

+    Status = gRT->SetVariable (

+                    (CHAR16*)L"Fdt",

+                    &gArmGlobalVariableGuid,

+                    EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,

+                    FdtDevicePathSize,

+                    FdtDevicePath

+                    );

+    ASSERT_EFI_ERROR(Status);

+  } else {

+    Status = gRT->SetVariable (

+           (CHAR16*)L"Fdt",

+           &gArmGlobalVariableGuid,

+           EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,

+           0,

+           NULL

+           );

+    ASSERT_EFI_ERROR(Status);

+  }

+

+  if (!EFI_ERROR (Status)) {

+    //

+    // Signal FDT has been updated

+    //

+    Status = gBS->CreateEventEx (

+        EVT_NOTIFY_SIGNAL,

+        TPL_NOTIFY,

+        EmptyCallbackFunction,

+        NULL,

+        &gArmPlatformUpdateFdtEventGuid,

+        &UpdateFdtEvent

+        );

+    if (!EFI_ERROR (Status)) {

+      gBS->SignalEvent (UpdateFdtEvent);

+    }

+  }

+

+EXIT:

+  if (Status == EFI_ABORTED) {

+    Print(L"\n");

+  }

+  FreePool(SupportedBootDevice);

+  return Status;

+}

+

+/**

+  Set boot timeout

+

+  Ask for the boot timeout in seconds and if the input succeeds assign the

+  input value to the UEFI global variable "Timeout". This function is called

+  when the user selects the "Set Boot Timeout" of the boot manager menu.

+

+  @param[in]  BootOptionsList  List of the boot devices, not used here

+

+  @retval  EFI_SUCCESS   Boot timeout in second retrieved from the standard

+                         input and assigned to the UEFI "Timeout" global

+                         variable

+  @retval  !EFI_SUCCESS  Either the input or the setting of the UEFI global

+                         variable "Timeout" has failed.

+**/

+EFI_STATUS

+STATIC

+BootMenuSetBootTimeout (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  EFI_STATUS  Status;

+  UINTN       Input;

+  UINT16      Timeout;

+

+  Print (L"Timeout duration (in seconds): ");

+  Status = GetHIInputInteger (&Input);

+  if (EFI_ERROR (Status)) {

+    Print (L"\n");

+    goto ErrorExit;

+  }

+

+  Timeout = Input;

+  Status = gRT->SetVariable (

+                 (CHAR16*)L"Timeout",

+                 &gEfiGlobalVariableGuid,

+                 EFI_VARIABLE_NON_VOLATILE       |

+                 EFI_VARIABLE_BOOTSERVICE_ACCESS |

+                 EFI_VARIABLE_RUNTIME_ACCESS,

+                 sizeof (UINT16),

+                 &Timeout

+                 );

+  ASSERT_EFI_ERROR (Status);

+

+ErrorExit:

+  return Status;

+}

+

+struct BOOT_MANAGER_ENTRY {

+  CONST CHAR16* Description;

+  EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);

+} BootManagerEntries[] = {

+    { L"Add Boot Device Entry", BootMenuAddBootOption },

+    { L"Update Boot Device Entry", BootMenuUpdateBootOption },

+    { L"Remove Boot Device Entry", BootMenuRemoveBootOption },

+    { L"Reorder Boot Device Entries", BootMenuReorderBootOptions },

+    { L"Update FDT path", UpdateFdtPath },

+    { L"Set Boot Timeout", BootMenuSetBootTimeout },

+};

+

+EFI_STATUS

+BootMenuManager (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  UINTN Index;

+  UINTN OptionSelected;

+  UINTN BootManagerEntryCount;

+  EFI_STATUS Status;

+

+  BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);

+

+  while (TRUE) {

+    // Display Boot Manager menu

+    for (Index = 0; Index < BootManagerEntryCount; Index++) {

+      Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);

+    }

+    Print(L"[%d] Return to main menu\n",Index+1);

+

+    // Select which entry to call

+    Print(L"Choice: ");

+    Status = GetHIInputInteger (&OptionSelected);

+    if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {

+      if (EFI_ERROR(Status)) {

+        Print(L"\n");

+      }

+      return EFI_SUCCESS;

+    } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount))  {

+      BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);

+    }

+  }

+  // Should never go here

+}

+

+EFI_STATUS

+BootShell (

+  IN LIST_ENTRY *BootOptionsList

+  )

+{

+  EFI_STATUS Status;

+

+  // Start EFI Shell

+  Status = BdsLoadApplication (gImageHandle, L"Shell", 0, NULL);

+  if (Status == EFI_NOT_FOUND) {

+    Print (L"Error: EFI Application not found.\n");

+  } else if (EFI_ERROR(Status)) {

+    Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);

+  }

+

+  return Status;

+}

+

+struct BOOT_MAIN_ENTRY {

+  CONST CHAR16* Description;

+  EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);

+} BootMainEntries[] = {

+    { L"Shell", BootShell },

+    { L"Boot Manager", BootMenuManager },

+};

+

+

+EFI_STATUS

+BootMenuMain (

+  VOID

+  )

+{

+  LIST_ENTRY                    BootOptionsList;

+  UINTN                         OptionCount;

+  UINTN                         BootOptionCount;

+  EFI_STATUS                    Status;

+  LIST_ENTRY*                   Entry;

+  BDS_LOAD_OPTION*              BootOption;

+  UINTN                         BootOptionSelected;

+  UINTN                         Index;

+  UINTN                         BootMainEntryCount;

+  BOOLEAN                       IsUnicode;

+

+  BootOption         = NULL;

+  BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);

+

+  while (TRUE) {

+    // Get Boot#### list

+    BootOptionList (&BootOptionsList);

+

+    OptionCount = 1;

+

+    // Display the Boot options

+    for (Entry = GetFirstNode (&BootOptionsList);

+         !IsNull (&BootOptionsList,Entry);

+         Entry = GetNextNode (&BootOptionsList,Entry)

+         )

+    {

+      BootOption = LOAD_OPTION_FROM_LINK(Entry);

+

+      Print(L"[%d] %s\n", OptionCount, BootOption->Description);

+

+      DEBUG_CODE_BEGIN();

+        CHAR16*                           DevicePathTxt;

+        EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+        ARM_BDS_LOADER_OPTIONAL_DATA*     OptionalData;

+        UINTN                             CmdLineSize;

+        ARM_BDS_LOADER_TYPE               LoaderType;

+

+        Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+        if (EFI_ERROR(Status)) {

+          // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)

+          DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));

+          return Status;

+        }

+        DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);

+

+        Print(L"\t- %s\n",DevicePathTxt);

+

+        // If it is a supported BootEntry then print its details

+        if (IS_ARM_BDS_BOOTENTRY (BootOption)) {

+          OptionalData = BootOption->OptionalData;

+          LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);

+          if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {

+            if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {

+              CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);

+              DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (

+                  GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);

+              Print(L"\t- Initrd: %s\n", DevicePathTxt);

+            }

+            if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize) > 0) {

+              Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));

+            }

+          }

+

+          switch (LoaderType) {

+            case BDS_LOADER_EFI_APPLICATION:

+              Print(L"\t- LoaderType: EFI Application\n");

+              break;

+

+            case BDS_LOADER_KERNEL_LINUX_ATAG:

+              Print(L"\t- LoaderType: Linux kernel with ATAG support\n");

+              break;

+

+            case BDS_LOADER_KERNEL_LINUX_FDT:

+              Print(L"\t- LoaderType: Linux kernel with FDT support\n");

+              break;

+

+            default:

+              Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);

+          }

+        } else if (BootOption->OptionalData != NULL) {

+          if (IsPrintableString (BootOption->OptionalData, &IsUnicode)) {

+            if (IsUnicode) {

+              Print (L"\t- Arguments: %s\n", BootOption->OptionalData);

+            } else {

+              AsciiPrint ("\t- Arguments: %a\n", BootOption->OptionalData);

+            }

+          }

+        }

+        FreePool(DevicePathTxt);

+      DEBUG_CODE_END();

+

+      OptionCount++;

+    }

+    BootOptionCount = OptionCount-1;

+

+    // Display the hardcoded Boot entries

+    for (Index = 0; Index < BootMainEntryCount; Index++) {

+      Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);

+      OptionCount++;

+    }

+

+    // Request the boot entry from the user

+    BootOptionSelected = 0;

+    while (BootOptionSelected == 0) {

+      Print(L"Start: ");

+      Status = GetHIInputInteger (&BootOptionSelected);

+      if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {

+        Print(L"Invalid input (max %d)\n",(OptionCount-1));

+        BootOptionSelected = 0;

+      }

+    }

+

+    // Start the selected entry

+    if (BootOptionSelected > BootOptionCount) {

+      // Start the hardcoded entry

+      Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);

+    } else {

+      // Find the selected entry from the Boot#### list

+      Index = 1;

+      for (Entry = GetFirstNode (&BootOptionsList);

+           !IsNull (&BootOptionsList,Entry);

+           Entry = GetNextNode (&BootOptionsList,Entry)

+           )

+      {

+        if (Index == BootOptionSelected) {

+          BootOption = LOAD_OPTION_FROM_LINK(Entry);

+          break;

+        }

+        Index++;

+      }

+

+      Status = BootOptionStart (BootOption);

+    }

+  }

+  // Should never go here

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootOption.c b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootOption.c
new file mode 100644
index 0000000..8098222
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootOption.c
@@ -0,0 +1,420 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Guid/ArmGlobalVariableHob.h>

+#include "BdsInternal.h"

+

+EFI_STATUS

+BootOptionStart (

+  IN BDS_LOAD_OPTION *BootOption

+  )

+{

+  EFI_STATUS                            Status;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL*   EfiDevicePathFromTextProtocol;

+  UINT32                                LoaderType;

+  ARM_BDS_LOADER_OPTIONAL_DATA*         OptionalData;

+  ARM_BDS_LINUX_ARGUMENTS*              LinuxArguments;

+  EFI_DEVICE_PATH_PROTOCOL*             FdtDevicePath;

+  EFI_DEVICE_PATH_PROTOCOL*             DefaultFdtDevicePath;

+  UINTN                                 FdtDevicePathSize;

+  UINTN                                 CmdLineSize;

+  UINTN                                 InitrdSize;

+  EFI_DEVICE_PATH*                      Initrd;

+  UINT16                                LoadOptionIndexSize;

+

+  if (IS_ARM_BDS_BOOTENTRY (BootOption)) {

+    Status = EFI_UNSUPPORTED;

+    OptionalData = BootOption->OptionalData;

+    LoaderType = ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);

+

+    if (LoaderType == BDS_LOADER_EFI_APPLICATION) {

+      if ((BootOption->Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_APP) {

+        // Need to connect every drivers to ensure no dependencies are missing for the application

+        BdsConnectAllDrivers ();

+      }

+

+      Status = BdsStartEfiApplication (gImageHandle, BootOption->FilePathList, 0, NULL);

+    } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) {

+      LinuxArguments = &(OptionalData->Arguments.LinuxArguments);

+      CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);

+      InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);

+

+      if (InitrdSize > 0) {

+        Initrd = GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize));

+      } else {

+        Initrd = NULL;

+      }

+

+      Status = BdsBootLinuxAtag (BootOption->FilePathList,

+                                 Initrd, // Initrd

+                                 (CHAR8*)(LinuxArguments + 1)); // CmdLine

+    } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT) {

+      LinuxArguments = &(OptionalData->Arguments.LinuxArguments);

+      CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);

+      InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);

+

+      if (InitrdSize > 0) {

+        Initrd = GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize));

+      } else {

+        Initrd = NULL;

+      }

+

+      // Get the default FDT device path

+      Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+      ASSERT_EFI_ERROR(Status);

+      DefaultFdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtDevicePath));

+

+      // Get the FDT device path

+      FdtDevicePathSize = GetDevicePathSize (DefaultFdtDevicePath);

+      Status = GetEnvironmentVariable ((CHAR16 *)L"Fdt", &gArmGlobalVariableGuid,

+                 DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath);

+      ASSERT_EFI_ERROR(Status);

+

+      Status = BdsBootLinuxFdt (BootOption->FilePathList,

+                                Initrd, // Initrd

+                                (CHAR8*)(LinuxArguments + 1),

+                                FdtDevicePath);

+

+      FreePool (DefaultFdtDevicePath);

+      FreePool (FdtDevicePath);

+    }

+  } else {

+    // Connect all the drivers if the EFI Application is not a EFI OS Loader

+    if ((BootOption->Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_APP) {

+      BdsConnectAllDrivers ();

+    }

+

+    // Set BootCurrent variable

+    LoadOptionIndexSize = sizeof(UINT16);

+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,

+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+              LoadOptionIndexSize, &(BootOption->LoadOptionIndex));

+

+    Status = BdsStartEfiApplication (gImageHandle, BootOption->FilePathList, BootOption->OptionalDataSize, BootOption->OptionalData);

+

+    // Clear BootCurrent variable

+    LoadOptionIndexSize = sizeof(UINT16);

+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,

+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+              0, NULL);

+  }

+

+  return Status;

+}

+

+EFI_STATUS

+BootOptionList (

+  IN OUT LIST_ENTRY *BootOptionList

+  )

+{

+  EFI_STATUS                    Status;

+  UINTN                         Index;

+  UINT16*                       BootOrder;

+  UINTN                         BootOrderSize;

+  BDS_LOAD_OPTION*              BdsLoadOption;

+  BDS_LOAD_OPTION_ENTRY*        BdsLoadOptionEntry;

+

+  InitializeListHead (BootOptionList);

+

+  // Get the Boot Option Order from the environment variable

+  Status = GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);

+  if (EFI_ERROR(Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {

+    Status = BootOptionFromLoadOptionIndex (BootOrder[Index], &BdsLoadOption);

+    if (!EFI_ERROR(Status)) {

+      BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool(sizeof(BDS_LOAD_OPTION_ENTRY));

+      BdsLoadOptionEntry->BdsLoadOption = BdsLoadOption;

+      InsertTailList (BootOptionList,&BdsLoadOptionEntry->Link);

+    }

+  }

+

+  FreePool (BootOrder);

+

+  return EFI_SUCCESS;

+}

+

+STATIC

+EFI_STATUS

+BootOptionSetFields (

+  IN BDS_LOAD_OPTION*           BootOption,

+  IN UINT32                     Attributes,

+  IN CHAR16*                    BootDescription,

+  IN EFI_DEVICE_PATH_PROTOCOL*  DevicePath,

+  IN ARM_BDS_LOADER_TYPE        BootType,

+  IN UINT8*                     OptionalData,

+  IN UINTN                      OptionalDataSize

+  )

+{

+  EFI_LOAD_OPTION               EfiLoadOption;

+  UINTN                         EfiLoadOptionSize;

+  UINTN                         BootDescriptionSize;

+  UINT16                        FilePathListLength;

+  UINT8*                        EfiLoadOptionPtr;

+  UINT8*                        InitrdPathListPtr;

+  ARM_BDS_LINUX_ARGUMENTS*      DestLinuxArguments;

+  ARM_BDS_LINUX_ARGUMENTS*      SrcLinuxArguments;

+  ARM_BDS_LOADER_ARGUMENTS*     BootArguments;

+

+  // If we are overwriting an existent Boot Option then we have to free previously allocated memory

+  if (BootOption->LoadOption) {

+    FreePool (BootOption->LoadOption);

+  }

+

+  BootDescriptionSize = StrSize (BootDescription);

+

+  // Fixup the size in case of entry specific to ArmPlatformPkg/Bds

+  if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {

+    OptionalDataSize += sizeof(ARM_BDS_LOADER_OPTIONAL_DATA_HEADER);

+  }

+

+  // Compute the size of the FilePath list

+  FilePathListLength = GetUnalignedDevicePathSize (DevicePath);

+

+  // Allocate the memory for the EFI Load Option

+  EfiLoadOptionSize = sizeof(UINT32) + sizeof(UINT16) + BootDescriptionSize + FilePathListLength + OptionalDataSize;

+  EfiLoadOption = (EFI_LOAD_OPTION)AllocatePool(EfiLoadOptionSize);

+  EfiLoadOptionPtr = EfiLoadOption;

+

+  //

+  // Populate the EFI Load Option and BDS Boot Option structures

+  //

+

+  // Attributes fields

+  BootOption->Attributes = Attributes;

+  *(UINT32*)EfiLoadOptionPtr = Attributes;

+  EfiLoadOptionPtr += sizeof(UINT32);

+

+  // FilePath List fields

+  BootOption->FilePathListLength = FilePathListLength;

+  *(UINT16*)EfiLoadOptionPtr = FilePathListLength;

+  EfiLoadOptionPtr += sizeof(UINT16);

+

+  // Boot description fields

+  BootOption->Description = (CHAR16*)EfiLoadOptionPtr;

+  CopyMem (EfiLoadOptionPtr, BootDescription, BootDescriptionSize);

+  EfiLoadOptionPtr += BootDescriptionSize;

+

+  // File path fields

+  BootOption->FilePathList = (EFI_DEVICE_PATH_PROTOCOL*)EfiLoadOptionPtr;

+  CopyMem (EfiLoadOptionPtr, DevicePath, FilePathListLength);

+  EfiLoadOptionPtr += FilePathListLength;

+

+  // Optional Data fields, Do unaligned writes

+  BootOption->OptionalData = EfiLoadOptionPtr;

+

+  if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {

+    // Write the header

+    WriteUnaligned32 ((UINT32 *)EfiLoadOptionPtr, ARM_BDS_OPTIONAL_DATA_SIGNATURE);

+    WriteUnaligned32 ((UINT32 *)(EfiLoadOptionPtr + 4), BootType);

+

+    // OptionalData should have been initialized by the caller of this function

+    ASSERT (OptionalData != NULL);

+    BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)OptionalData;

+    SrcLinuxArguments = &(BootArguments->LinuxArguments);

+    DestLinuxArguments = &((ARM_BDS_LOADER_OPTIONAL_DATA*)EfiLoadOptionPtr)->Arguments.LinuxArguments;

+

+    WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->CmdLineSize), SrcLinuxArguments->CmdLineSize);

+    WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->InitrdSize), SrcLinuxArguments->InitrdSize);

+

+    if (SrcLinuxArguments->CmdLineSize > 0) {

+      CopyMem ((VOID*)(DestLinuxArguments + 1), (VOID*)(SrcLinuxArguments + 1), SrcLinuxArguments->CmdLineSize);

+    }

+

+    if (SrcLinuxArguments->InitrdSize > 0) {

+      InitrdPathListPtr = (UINT8*)((UINTN)(DestLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize);

+      CopyMem (InitrdPathListPtr, (VOID*)((UINTN)(SrcLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize), SrcLinuxArguments->InitrdSize);

+    }

+  } else {

+    if (OptionalData != NULL) {

+      CopyMem (BootOption->OptionalData, OptionalData, OptionalDataSize);

+    }

+  }

+  BootOption->OptionalDataSize = OptionalDataSize;

+

+  // If this function is called at the creation of the Boot Device entry (not at the update) the

+  // BootOption->LoadOptionSize must be zero then we get a new BootIndex for this entry

+  if (BootOption->LoadOptionSize == 0) {

+    BootOption->LoadOptionIndex = BootOptionAllocateBootIndex ();

+  }

+

+  // Fill the EFI Load option fields

+  BootOption->LoadOption = EfiLoadOption;

+  BootOption->LoadOptionSize = EfiLoadOptionSize;

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BootOptionCreate (

+  IN  UINT32                    Attributes,

+  IN  CHAR16*                   BootDescription,

+  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,

+  IN  ARM_BDS_LOADER_TYPE       BootType,

+  IN  UINT8*                    OptionalData,

+  IN  UINTN                     OptionalDataSize,

+  OUT BDS_LOAD_OPTION**         BdsLoadOption

+  )

+{

+  EFI_STATUS                    Status;

+  BDS_LOAD_OPTION_ENTRY*        BootOptionEntry;

+  BDS_LOAD_OPTION*              BootOption;

+  CHAR16                        BootVariableName[9];

+  UINT16*                       BootOrder;

+  UINTN                         BootOrderSize;

+

+  //

+  // Allocate and fill the memory for the BDS Load Option structure

+  //

+  BootOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof (BDS_LOAD_OPTION_ENTRY));

+  InitializeListHead (&BootOptionEntry->Link);

+  BootOptionEntry->BdsLoadOption = (BDS_LOAD_OPTION*)AllocateZeroPool (sizeof(BDS_LOAD_OPTION));

+

+  BootOption = BootOptionEntry->BdsLoadOption;

+  BootOptionSetFields (BootOption, Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);

+

+  //

+  // Set the related environment variables

+  //

+

+  // Create Boot#### environment variable

+  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOption->LoadOptionIndex);

+  Status = gRT->SetVariable (

+      BootVariableName,

+      &gEfiGlobalVariableGuid,

+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+      BootOption->LoadOptionSize,

+      BootOption->LoadOption

+      );

+

+  // Add the new Boot Index to the list

+  Status = GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);

+  if (!EFI_ERROR(Status)) {

+    BootOrder = ReallocatePool (BootOrderSize, BootOrderSize + sizeof(UINT16), BootOrder);

+    // Add the new index at the end

+    BootOrder[BootOrderSize / sizeof(UINT16)] = BootOption->LoadOptionIndex;

+    BootOrderSize += sizeof(UINT16);

+  } else {

+    // BootOrder does not exist. Create it

+    BootOrderSize = sizeof(UINT16);

+    BootOrder = &(BootOption->LoadOptionIndex);

+  }

+

+  // Update (or Create) the BootOrder environment variable

+  Status = gRT->SetVariable (

+      L"BootOrder",

+      &gEfiGlobalVariableGuid,

+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+      BootOrderSize,

+      BootOrder

+      );

+

+  // We only free it if the UEFI Variable 'BootOrder' was already existing

+  if (BootOrderSize > sizeof(UINT16)) {

+    FreePool (BootOrder);

+  }

+

+  *BdsLoadOption = BootOption;

+  return Status;

+}

+

+EFI_STATUS

+BootOptionUpdate (

+  IN  BDS_LOAD_OPTION*          BdsLoadOption,

+  IN  UINT32                    Attributes,

+  IN  CHAR16*                   BootDescription,

+  IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,

+  IN  ARM_BDS_LOADER_TYPE       BootType,

+  IN UINT8*                     OptionalData,

+  IN UINTN                      OptionalDataSize

+  )

+{

+  EFI_STATUS      Status;

+  CHAR16          BootVariableName[9];

+

+  // Update the BDS Load Option structure

+  BootOptionSetFields (BdsLoadOption, Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);

+

+  // Update the related environment variables

+  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BdsLoadOption->LoadOptionIndex);

+

+  Status = gRT->SetVariable (

+      BootVariableName,

+      &gEfiGlobalVariableGuid,

+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+      BdsLoadOption->LoadOptionSize,

+      BdsLoadOption->LoadOption

+      );

+

+  return Status;

+}

+

+EFI_STATUS

+BootOptionDelete (

+  IN  BDS_LOAD_OPTION *BootOption

+  )

+{

+  UINTN         Index;

+  UINTN         BootOrderSize;

+  UINT16*       BootOrder;

+  UINTN         BootOrderCount;

+  CHAR16        BootVariableName[9];

+  EFI_STATUS    Status;

+

+  // Remove the entry from the BootOrder environment variable

+  Status = GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);

+  if (!EFI_ERROR(Status)) {

+    BootOrderCount = BootOrderSize / sizeof(UINT16);

+

+    // Find the index of the removed entry

+    for (Index = 0; Index < BootOrderCount; Index++) {

+      if (BootOrder[Index] == BootOption->LoadOptionIndex) {

+        // If it the last entry we do not need to rearrange the BootOrder list

+        if (Index + 1 != BootOrderCount) {

+          CopyMem (

+            &BootOrder[Index],

+            &BootOrder[Index + 1],

+            (BootOrderCount - (Index + 1)) * sizeof(UINT16)

+            );

+        }

+        break;

+      }

+    }

+

+    // Update the BootOrder environment variable

+    Status = gRT->SetVariable (

+        L"BootOrder",

+        &gEfiGlobalVariableGuid,

+        EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+        BootOrderSize - sizeof(UINT16),

+        BootOrder

+        );

+  }

+

+  // Delete Boot#### environment variable

+  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOption->LoadOptionIndex);

+  Status = gRT->SetVariable (

+      BootVariableName,

+      &gEfiGlobalVariableGuid,

+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+      0,

+      NULL

+      );

+

+  FreePool (BootOrder);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootOptionSupport.c b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootOptionSupport.c
new file mode 100644
index 0000000..974f220
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Bds/BootOptionSupport.c
@@ -0,0 +1,1306 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include "BdsInternal.h"

+

+#include <Library/NetLib.h>

+

+#include <Protocol/BlockIo.h>

+#include <Protocol/DevicePathToText.h>

+#include <Protocol/FirmwareVolumeBlock.h>

+#include <Protocol/PxeBaseCode.h>

+#include <Protocol/SimpleFileSystem.h>

+#include <Protocol/SimpleNetwork.h>

+#include <Protocol/Dhcp4.h>

+#include <Protocol/Mtftp4.h>

+

+#include <Guid/FileSystemInfo.h>

+

+#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))

+

+EFI_STATUS

+BdsLoadOptionFileSystemList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  );

+

+EFI_STATUS

+BdsLoadOptionFileSystemCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  );

+

+EFI_STATUS

+BdsLoadOptionFileSystemUpdateDevicePath (

+  IN EFI_DEVICE_PATH            *OldDevicePath,

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  );

+

+BOOLEAN

+BdsLoadOptionFileSystemIsSupported (

+  IN  EFI_DEVICE_PATH           *DevicePath

+  );

+

+EFI_STATUS

+BdsLoadOptionMemMapList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  );

+

+EFI_STATUS

+BdsLoadOptionMemMapCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  );

+

+EFI_STATUS

+BdsLoadOptionMemMapUpdateDevicePath (

+  IN EFI_DEVICE_PATH            *OldDevicePath,

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  );

+

+BOOLEAN

+BdsLoadOptionMemMapIsSupported (

+  IN  EFI_DEVICE_PATH           *DevicePath

+  );

+

+EFI_STATUS

+BdsLoadOptionPxeList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  );

+

+EFI_STATUS

+BdsLoadOptionPxeCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  );

+

+EFI_STATUS

+BdsLoadOptionPxeUpdateDevicePath (

+  IN EFI_DEVICE_PATH            *OldDevicePath,

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  );

+

+BOOLEAN

+BdsLoadOptionPxeIsSupported (

+  IN  EFI_DEVICE_PATH           *DevicePath

+  );

+

+EFI_STATUS

+BdsLoadOptionTftpList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  );

+

+EFI_STATUS

+BdsLoadOptionTftpCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  );

+

+EFI_STATUS

+BdsLoadOptionTftpUpdateDevicePath (

+  IN EFI_DEVICE_PATH            *OldDevicePath,

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  );

+

+BOOLEAN

+BdsLoadOptionTftpIsSupported (

+  IN  EFI_DEVICE_PATH           *DevicePath

+  );

+

+BDS_LOAD_OPTION_SUPPORT BdsLoadOptionSupportList[] = {

+  {

+    BDS_DEVICE_FILESYSTEM,

+    BdsLoadOptionFileSystemList,

+    BdsLoadOptionFileSystemIsSupported,

+    BdsLoadOptionFileSystemCreateDevicePath,

+    BdsLoadOptionFileSystemUpdateDevicePath,

+    TRUE

+  },

+  {

+    BDS_DEVICE_MEMMAP,

+    BdsLoadOptionMemMapList,

+    BdsLoadOptionMemMapIsSupported,

+    BdsLoadOptionMemMapCreateDevicePath,

+    BdsLoadOptionMemMapUpdateDevicePath,

+    TRUE

+  },

+  {

+    BDS_DEVICE_PXE,

+    BdsLoadOptionPxeList,

+    BdsLoadOptionPxeIsSupported,

+    BdsLoadOptionPxeCreateDevicePath,

+    BdsLoadOptionPxeUpdateDevicePath,

+    FALSE

+  },

+  {

+    BDS_DEVICE_TFTP,

+    BdsLoadOptionTftpList,

+    BdsLoadOptionTftpIsSupported,

+    BdsLoadOptionTftpCreateDevicePath,

+    BdsLoadOptionTftpUpdateDevicePath,

+    TRUE

+  }

+};

+

+EFI_STATUS

+BootDeviceListSupportedInit (

+  IN OUT LIST_ENTRY *SupportedDeviceList

+  )

+{

+  UINTN   Index;

+

+  // Initialize list of supported devices

+  InitializeListHead (SupportedDeviceList);

+

+  for (Index = 0; Index < BDS_DEVICE_MAX; Index++) {

+    BdsLoadOptionSupportList[Index].ListDevices (SupportedDeviceList);

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BootDeviceListSupportedFree (

+  IN LIST_ENTRY *SupportedDeviceList,

+  IN BDS_SUPPORTED_DEVICE *Except

+  )

+{

+  LIST_ENTRY  *Entry;

+  BDS_SUPPORTED_DEVICE* SupportedDevice;

+

+  Entry = GetFirstNode (SupportedDeviceList);

+  while (Entry != SupportedDeviceList) {

+    SupportedDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);

+    Entry = RemoveEntryList (Entry);

+    if (SupportedDevice != Except) {

+      FreePool (SupportedDevice);

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BootDeviceGetDeviceSupport (

+  IN  EFI_DEVICE_PATH           *DevicePath,

+  OUT BDS_LOAD_OPTION_SUPPORT   **DeviceSupport

+  )

+{

+  UINTN Index;

+

+  // Find which supported device is the most appropriate

+  for (Index = 0; Index < BDS_DEVICE_MAX; Index++) {

+    if (BdsLoadOptionSupportList[Index].IsSupported (DevicePath)) {

+      *DeviceSupport = &BdsLoadOptionSupportList[Index];

+      return EFI_SUCCESS;

+    }

+  }

+

+  return EFI_UNSUPPORTED;

+}

+

+EFI_STATUS

+BootDeviceGetType (

+  IN  EFI_DEVICE_PATH* DevicePath,

+  OUT ARM_BDS_LOADER_TYPE *BootType,

+  OUT UINT32 *Attributes

+  )

+{

+  EFI_STATUS              Status;

+  BOOLEAN                 IsEfiApp;

+  BOOLEAN                 IsBootLoader;

+  BOOLEAN                 HasFDTSupport;

+  CHAR16*                 FileName;

+  EFI_DEVICE_PATH*        PrevDevicePathNode;

+  EFI_DEVICE_PATH*        DevicePathNode;

+  EFI_PHYSICAL_ADDRESS    Image;

+  UINTN                   FileSize;

+  EFI_IMAGE_DOS_HEADER*   DosHeader;

+  UINTN                   PeCoffHeaderOffset;

+  EFI_IMAGE_NT_HEADERS32* NtHeader;

+

+  //

+  // Check if the last node of the device path is a FilePath node

+  //

+  PrevDevicePathNode = NULL;

+  DevicePathNode = DevicePath;

+  while ((DevicePathNode != NULL) && !IsDevicePathEnd (DevicePathNode)) {

+    PrevDevicePathNode = DevicePathNode;

+    DevicePathNode = NextDevicePathNode (DevicePathNode);

+  }

+

+  if ((PrevDevicePathNode != NULL) &&

+      (PrevDevicePathNode->Type == MEDIA_DEVICE_PATH) &&

+      (PrevDevicePathNode->SubType == MEDIA_FILEPATH_DP))

+  {

+    FileName = ((FILEPATH_DEVICE_PATH*)PrevDevicePathNode)->PathName;

+  } else {

+    FileName = NULL;

+  }

+

+  if (FileName == NULL) {

+    Print(L"Is an EFI Application? ");

+    Status = GetHIInputBoolean (&IsEfiApp);

+    if (EFI_ERROR(Status)) {

+      return EFI_ABORTED;

+    }

+  } else if (HasFilePathEfiExtension(FileName)) {

+    IsEfiApp = TRUE;

+  } else {

+    // Check if the file exist

+    Status = BdsLoadImage (DevicePath, AllocateAnyPages, &Image, &FileSize);

+    if (!EFI_ERROR (Status)) {

+

+      DosHeader = (EFI_IMAGE_DOS_HEADER *)(UINTN) Image;

+      if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {

+        //

+        // DOS image header is present,

+        // so read the PE header after the DOS image header.

+        //

+        PeCoffHeaderOffset = DosHeader->e_lfanew;

+      } else {

+        PeCoffHeaderOffset = 0;

+      }

+

+      //

+      // Check PE/COFF image.

+      //

+      NtHeader = (EFI_IMAGE_NT_HEADERS32 *)(UINTN) (Image + PeCoffHeaderOffset);

+      if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {

+        IsEfiApp = FALSE;

+      } else {

+        IsEfiApp = TRUE;

+      }

+

+      // Free memory

+      gBS->FreePages (Image, EFI_SIZE_TO_PAGES(FileSize));

+    } else {

+      // If we did not manage to open it then ask for the type

+      Print(L"Is an EFI Application? ");

+      Status = GetHIInputBoolean (&IsEfiApp);

+      if (EFI_ERROR(Status)) {

+        return EFI_ABORTED;

+      }

+    }

+  }

+

+  if (IsEfiApp) {

+    Print(L"Is your application an OS loader? ");

+    Status = GetHIInputBoolean (&IsBootLoader);

+    if (EFI_ERROR(Status)) {

+      return EFI_ABORTED;

+    }

+    if (!IsBootLoader) {

+      *Attributes |= LOAD_OPTION_CATEGORY_APP;

+    }

+    *BootType = BDS_LOADER_EFI_APPLICATION;

+  } else {

+    Print(L"Has FDT support? ");

+    Status = GetHIInputBoolean (&HasFDTSupport);

+    if (EFI_ERROR(Status)) {

+      return EFI_ABORTED;

+    }

+    if (HasFDTSupport) {

+      *BootType = BDS_LOADER_KERNEL_LINUX_FDT;

+    } else {

+      *BootType = BDS_LOADER_KERNEL_LINUX_ATAG;

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BdsLoadOptionFileSystemList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  )

+{

+  EFI_STATUS                        Status;

+  UINTN                             HandleCount;

+  EFI_HANDLE                        *HandleBuffer;

+  UINTN                             Index;

+  BDS_SUPPORTED_DEVICE              *SupportedDevice;

+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL*  FileProtocol;

+  EFI_FILE_HANDLE                   Fs;

+  UINTN                             Size;

+  EFI_FILE_SYSTEM_INFO*             FsInfo;

+  EFI_DEVICE_PATH_PROTOCOL*         DevicePathProtocol;

+

+  // List all the Simple File System Protocols

+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &HandleBuffer);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < HandleCount; Index++) {

+    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);

+    if (!EFI_ERROR(Status)) {

+      // Allocate BDS Supported Device structure

+      SupportedDevice = (BDS_SUPPORTED_DEVICE*)AllocatePool (sizeof(BDS_SUPPORTED_DEVICE));

+

+      FileProtocol = NULL;

+      Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&FileProtocol);

+      ASSERT_EFI_ERROR(Status);

+

+      FileProtocol->OpenVolume (FileProtocol, &Fs);

+

+      // Generate a Description from the file system

+      Size = 0;

+      FsInfo = NULL;

+      Status = Fs->GetInfo (Fs, &gEfiFileSystemInfoGuid, &Size, FsInfo);

+      if (Status == EFI_BUFFER_TOO_SMALL) {

+        FsInfo = AllocatePool (Size);

+        Status = Fs->GetInfo (Fs, &gEfiFileSystemInfoGuid, &Size, FsInfo);

+      }

+      UnicodeSPrint (SupportedDevice->Description,BOOT_DEVICE_DESCRIPTION_MAX,L"%s (%d MB)",FsInfo->VolumeLabel,(UINT32)(FsInfo->VolumeSize / (1024 * 1024)));

+      FreePool(FsInfo);

+      Fs->Close (Fs);

+

+      SupportedDevice->DevicePathProtocol = DevicePathProtocol;

+      SupportedDevice->Support = &BdsLoadOptionSupportList[BDS_DEVICE_FILESYSTEM];

+

+      InsertTailList (BdsLoadOptionList,&SupportedDevice->Link);

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BdsLoadOptionFileSystemCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  )

+{

+  EFI_STATUS  Status;

+  FILEPATH_DEVICE_PATH* FilePathDevicePath;

+  CHAR16      BootFilePath[BOOT_DEVICE_FILEPATH_MAX];

+  UINTN       BootFilePathSize;

+

+  Print(L"File path of the %s: ", FileName);

+  Status = GetHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);

+  if (EFI_ERROR(Status)) {

+    return EFI_ABORTED;

+  }

+

+  BootFilePathSize = StrSize (BootFilePath);

+  if (BootFilePathSize == 2) {

+    *DevicePathNodes = NULL;

+    return EFI_NOT_FOUND;

+  }

+

+  // Create the FilePath Device Path node

+  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH);

+  FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH;

+  FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP;

+  SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);

+  CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);

+  SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));

+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath;

+

+  return Status;

+}

+

+EFI_STATUS

+BdsLoadOptionFileSystemUpdateDevicePath (

+  IN EFI_DEVICE_PATH            *OldDevicePath,

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  )

+{

+  EFI_STATUS  Status;

+  CHAR16      BootFilePath[BOOT_DEVICE_FILEPATH_MAX];

+  UINTN       BootFilePathSize;

+  FILEPATH_DEVICE_PATH* EndingDevicePath;

+  FILEPATH_DEVICE_PATH* FilePathDevicePath;

+  EFI_DEVICE_PATH*  DevicePath;

+

+  DevicePath = DuplicateDevicePath (OldDevicePath);

+

+  EndingDevicePath = (FILEPATH_DEVICE_PATH*)GetLastDevicePathNode (DevicePath);

+

+  Print(L"File path of the %s: ", FileName);

+  StrnCpy (BootFilePath, EndingDevicePath->PathName, BOOT_DEVICE_FILEPATH_MAX);

+  Status = EditHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);

+  if (EFI_ERROR(Status)) {

+    return Status;

+  }

+

+  BootFilePathSize = StrSize(BootFilePath);

+  if (BootFilePathSize == 2) {

+    *NewDevicePath = NULL;

+    return EFI_NOT_FOUND;

+  }

+

+  // Create the FilePath Device Path node

+  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);

+  FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH;

+  FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP;

+  SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);

+  CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);

+

+  // Generate the new Device Path by replacing the last node by the updated node

+  SetDevicePathEndNode (EndingDevicePath);

+  *NewDevicePath = AppendDevicePathNode (DevicePath, (CONST EFI_DEVICE_PATH_PROTOCOL *)FilePathDevicePath);

+  FreePool(DevicePath);

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Check if a boot option path is a file system boot option path or not.

+

+  The device specified by the beginning of the path has to support the Simple File

+  System protocol. Furthermore, the remaining part of the path has to be composed of

+  a single node of type MEDIA_DEVICE_PATH and sub-type MEDIA_FILEPATH_DP.

+

+  @param[in]  DevicePath  Complete device path of a boot option.

+

+  @retval  FALSE  The boot option path has not been identified as that of a

+                  file system boot option.

+  @retval  TRUE   The boot option path is a file system boot option.

+**/

+BOOLEAN

+BdsLoadOptionFileSystemIsSupported (

+  IN  EFI_DEVICE_PATH  *DevicePath

+  )

+{

+  EFI_STATUS                        Status;

+  EFI_HANDLE                        Handle;

+  EFI_DEVICE_PATH                  *RemainingDevicePath;

+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  *FileProtocol;

+

+  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);

+  if (EFI_ERROR (Status)) {

+    return FALSE;

+  }

+

+  Status = gBS->HandleProtocol (

+                   Handle,

+                   &gEfiSimpleFileSystemProtocolGuid,

+                   (VOID **)(&FileProtocol)

+                   );

+  if (EFI_ERROR (Status)) {

+    return FALSE;

+  }

+

+  if (!IS_DEVICE_PATH_NODE (RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP))

+    return FALSE;

+

+  return TRUE;

+}

+

+STATIC

+BOOLEAN

+IsParentDevicePath (

+  IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,

+  IN EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath

+  )

+{

+  UINTN ParentSize;

+  UINTN ChildSize;

+

+  ParentSize = GetDevicePathSize (ParentDevicePath);

+  ChildSize = GetDevicePathSize (ChildDevicePath);

+

+  if (ParentSize > ChildSize) {

+    return FALSE;

+  }

+

+  if (CompareMem (ParentDevicePath, ChildDevicePath, ParentSize - END_DEVICE_PATH_LENGTH) != 0) {

+    return FALSE;

+  }

+

+  return TRUE;

+}

+

+EFI_STATUS

+BdsLoadOptionMemMapList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  )

+{

+  EFI_STATUS                          Status;

+  UINTN                               HandleCount;

+  EFI_HANDLE                         *HandleBuffer;

+  UINTN                               DevicePathHandleCount;

+  EFI_HANDLE                         *DevicePathHandleBuffer;

+  BOOLEAN                             IsParent;

+  UINTN                               Index;

+  UINTN                               Index2;

+  BDS_SUPPORTED_DEVICE               *SupportedDevice;

+  EFI_DEVICE_PATH_PROTOCOL*           DevicePathProtocol;

+  EFI_DEVICE_PATH*                    DevicePath;

+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL    *FileProtocol;

+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;

+

+  // List all the BlockIo Protocols

+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &HandleCount, &HandleBuffer);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < HandleCount; Index++) {

+    // We only select handles WITH a Device Path AND not part of Media (to

+    // avoid duplication with HardDisk, CDROM, etc). Skip handles used by

+    // Simple Filesystem or used for Variable Storage.

+

+

+    Status = gBS->HandleProtocol (HandleBuffer[Index],

+                                  &gEfiSimpleFileSystemProtocolGuid,

+                                  (VOID *)&FileProtocol);

+    if (!EFI_ERROR(Status)) {

+      // SimpleFilesystem supported on this handle, skip

+      continue;

+    }

+

+    Status = gBS->HandleProtocol (HandleBuffer[Index],

+                                  &gEfiFirmwareVolumeBlockProtocolGuid,

+                                  (VOID *)&FvbProtocol);

+    if (!EFI_ERROR(Status)) {

+      // Firmware Volme Block / Variable storage supported on this handle, skip

+      continue;

+    }

+

+    Status = gBS->HandleProtocol (HandleBuffer[Index],

+                                  &gEfiFirmwareVolumeBlock2ProtocolGuid,

+                                  (VOID *)&FvbProtocol);

+    if (!EFI_ERROR(Status)) {

+      // Firmware Volme Block / Variable storage supported on this handle, skip

+      continue;

+    }

+

+    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);

+    if (!EFI_ERROR(Status)) {

+      // BlockIo is not part of Media Device Path

+      DevicePath = DevicePathProtocol;

+      while (!IsDevicePathEndType (DevicePath) && (DevicePathType (DevicePath) != MEDIA_DEVICE_PATH)) {

+        DevicePath = NextDevicePathNode (DevicePath);

+      }

+      if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) {

+        continue;

+      }

+

+      // Open all the handle supporting the DevicePath protocol and verify this handle has not got any child

+      Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiDevicePathProtocolGuid, NULL, &DevicePathHandleCount, &DevicePathHandleBuffer);

+      ASSERT_EFI_ERROR (Status);

+      IsParent = FALSE;

+      for (Index2 = 0; (Index2 < DevicePathHandleCount) && !IsParent; Index2++) {

+        if (HandleBuffer[Index] != DevicePathHandleBuffer[Index2]) {

+          gBS->HandleProtocol (DevicePathHandleBuffer[Index2], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);

+          if (IsParentDevicePath (DevicePathProtocol, DevicePath)) {

+            IsParent = TRUE;

+          }

+        }

+      }

+      if (IsParent) {

+        continue;

+      }

+

+      // Allocate BDS Supported Device structure

+      SupportedDevice = (BDS_SUPPORTED_DEVICE*)AllocatePool(sizeof(BDS_SUPPORTED_DEVICE));

+

+      Status = GenerateDeviceDescriptionName (HandleBuffer[Index], SupportedDevice->Description);

+      ASSERT_EFI_ERROR (Status);

+

+      SupportedDevice->DevicePathProtocol = DevicePathProtocol;

+      SupportedDevice->Support = &BdsLoadOptionSupportList[BDS_DEVICE_MEMMAP];

+

+      InsertTailList (BdsLoadOptionList,&SupportedDevice->Link);

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BdsLoadOptionMemMapCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  )

+{

+  EFI_STATUS              Status;

+  MEMMAP_DEVICE_PATH      *MemMapDevicePath;

+  CHAR16                  StrStartingAddress[BOOT_DEVICE_ADDRESS_MAX];

+  CHAR16                  StrEndingAddress[BOOT_DEVICE_ADDRESS_MAX];

+

+  Print(L"Starting Address of the %s: ", FileName);

+  Status = GetHIInputStr (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX);

+  if (EFI_ERROR(Status)) {

+    return EFI_ABORTED;

+  }

+

+  Print(L"Ending Address of the %s: ", FileName);

+  Status = GetHIInputStr (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX);

+  if (EFI_ERROR(Status)) {

+    return EFI_ABORTED;

+  }

+

+  // Create the MemMap Device Path Node

+  MemMapDevicePath = (MEMMAP_DEVICE_PATH*)AllocatePool (sizeof(MEMMAP_DEVICE_PATH) + END_DEVICE_PATH_LENGTH);

+  MemMapDevicePath->Header.Type = HARDWARE_DEVICE_PATH;

+  MemMapDevicePath->Header.SubType = HW_MEMMAP_DP;

+  SetDevicePathNodeLength (MemMapDevicePath, sizeof(MEMMAP_DEVICE_PATH));

+  MemMapDevicePath->MemoryType = EfiBootServicesData;

+  MemMapDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress);

+  MemMapDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress);

+

+  // Set a Device Path End Node after the Memory Map Device Path Node

+  SetDevicePathEndNode (MemMapDevicePath + 1);

+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath;

+

+  return Status;

+}

+

+EFI_STATUS

+BdsLoadOptionMemMapUpdateDevicePath (

+  IN EFI_DEVICE_PATH            *OldDevicePath,

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  )

+{

+  EFI_STATUS          Status;

+  CHAR16              StrStartingAddress[BOOT_DEVICE_ADDRESS_MAX];

+  CHAR16              StrEndingAddress[BOOT_DEVICE_ADDRESS_MAX];

+  MEMMAP_DEVICE_PATH* EndingDevicePath;

+  EFI_DEVICE_PATH*    DevicePath;

+

+  DevicePath = DuplicateDevicePath (OldDevicePath);

+  EndingDevicePath = (MEMMAP_DEVICE_PATH*)GetLastDevicePathNode (DevicePath);

+

+  Print(L"Starting Address of the %s: ", FileName);

+  UnicodeSPrint (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX, L"0x%X", (UINTN)EndingDevicePath->StartingAddress);

+  Status = EditHIInputStr (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX);

+  if (EFI_ERROR(Status)) {

+    return EFI_ABORTED;

+  }

+

+  Print(L"Ending Address of the %s: ", FileName);

+  UnicodeSPrint (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX, L"0x%X", (UINTN)EndingDevicePath->EndingAddress);

+  Status = EditHIInputStr (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX);

+  if (EFI_ERROR(Status)) {

+    return EFI_ABORTED;

+  }

+

+  EndingDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress);

+  EndingDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress);

+

+  if (EFI_ERROR(Status)) {

+    FreePool(DevicePath);

+  } else {

+    *NewDevicePath = DevicePath;

+  }

+

+  return Status;

+}

+

+/**

+  Check if a boot option path is a memory map boot option path or not.

+

+  The device specified by the beginning of the path has to support the BlockIo

+  protocol. Furthermore, the remaining part of the path has to be composed of

+  a single node of type HARDWARE_DEVICE_PATH and sub-type HW_MEMMAP_DP.

+

+  @param[in]  DevicePath  Complete device path of a boot option.

+

+  @retval  FALSE  The boot option path has not been identified as that of a

+                  memory map boot option.

+  @retval  TRUE   The boot option path is a a memory map boot option.

+**/

+BOOLEAN

+BdsLoadOptionMemMapIsSupported (

+  IN  EFI_DEVICE_PATH  *DevicePath

+  )

+{

+  EFI_STATUS              Status;

+  EFI_HANDLE              Handle;

+  EFI_DEVICE_PATH        *RemainingDevicePath;

+  EFI_BLOCK_IO_PROTOCOL  *BlockIoProtocol;

+

+  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);

+  if (EFI_ERROR (Status)) {

+    return FALSE;

+  }

+

+  Status = gBS->HandleProtocol (

+                  Handle,

+                  &gEfiBlockIoProtocolGuid,

+                  (VOID **)(&BlockIoProtocol)

+                  );

+  if (EFI_ERROR (Status)) {

+    return FALSE;

+  }

+

+  if (!IS_DEVICE_PATH_NODE (RemainingDevicePath, HARDWARE_DEVICE_PATH, HW_MEMMAP_DP))

+    return FALSE;

+

+  return TRUE;

+}

+

+EFI_STATUS

+BdsLoadOptionPxeList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  )

+{

+  EFI_STATUS                        Status;

+  UINTN                             HandleCount;

+  EFI_HANDLE                        *HandleBuffer;

+  UINTN                             Index;

+  BDS_SUPPORTED_DEVICE              *SupportedDevice;

+  EFI_DEVICE_PATH_PROTOCOL*         DevicePathProtocol;

+  EFI_SIMPLE_NETWORK_PROTOCOL*      SimpleNet;

+  CHAR16                            DeviceDescription[BOOT_DEVICE_DESCRIPTION_MAX];

+  EFI_MAC_ADDRESS                   *Mac;

+

+  // List all the PXE Protocols

+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiPxeBaseCodeProtocolGuid, NULL, &HandleCount, &HandleBuffer);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < HandleCount; Index++) {

+    // We only select the handle WITH a Device Path AND the PXE Protocol

+    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);

+    if (!EFI_ERROR(Status)) {

+      // Allocate BDS Supported Device structure

+      SupportedDevice = (BDS_SUPPORTED_DEVICE*)AllocatePool(sizeof(BDS_SUPPORTED_DEVICE));

+

+      Status = gBS->LocateProtocol (&gEfiSimpleNetworkProtocolGuid, NULL, (VOID **)&SimpleNet);

+      if (!EFI_ERROR(Status)) {

+        Mac = &SimpleNet->Mode->CurrentAddress;

+        UnicodeSPrint (DeviceDescription,BOOT_DEVICE_DESCRIPTION_MAX,L"MAC Address: %02x:%02x:%02x:%02x:%02x:%02x", Mac->Addr[0],  Mac->Addr[1],  Mac->Addr[2],  Mac->Addr[3],  Mac->Addr[4],  Mac->Addr[5]);

+      } else {

+        Status = GenerateDeviceDescriptionName (HandleBuffer[Index], DeviceDescription);

+        ASSERT_EFI_ERROR (Status);

+      }

+      UnicodeSPrint (SupportedDevice->Description,BOOT_DEVICE_DESCRIPTION_MAX,L"PXE on %s",DeviceDescription);

+

+      SupportedDevice->DevicePathProtocol = DevicePathProtocol;

+      SupportedDevice->Support = &BdsLoadOptionSupportList[BDS_DEVICE_PXE];

+

+      InsertTailList (BdsLoadOptionList,&SupportedDevice->Link);

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BdsLoadOptionPxeCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  )

+{

+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);

+  SetDevicePathEndNode (*DevicePathNodes);

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Update the parameters of a Pxe boot option

+

+  @param[in]   OldDevicePath  Current complete device path of the Pxe boot option.

+                              This has to be a valid complete Pxe boot option path.

+  @param[in]   FileName       Description of the file the path is asked for

+  @param[out]  NewDevicePath  Pointer to the new complete device path.

+

+  @retval  EFI_SUCCESS            Update completed

+  @retval  EFI_OUT_OF_RESOURCES   Fail to perform the update due to lack of resource

+**/

+EFI_STATUS

+BdsLoadOptionPxeUpdateDevicePath (

+  IN EFI_DEVICE_PATH            *OldDevicePath,

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  )

+{

+  //

+  // Make a copy of the complete device path that is made of :

+  // the device path of the device supporting the Pxe base code protocol

+  // followed by an end node.

+  //

+  *NewDevicePath = DuplicateDevicePath (OldDevicePath);

+  if (*NewDevicePath == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  } else {

+    return EFI_SUCCESS;

+  }

+}

+

+BOOLEAN

+BdsLoadOptionPxeIsSupported (

+  IN  EFI_DEVICE_PATH  *DevicePath

+  )

+{

+  EFI_STATUS  Status;

+  EFI_HANDLE Handle;

+  EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath;

+  EFI_PXE_BASE_CODE_PROTOCOL  *PxeBcProtocol;

+

+  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);

+  if (EFI_ERROR(Status)) {

+    return FALSE;

+  }

+

+  if (!IsDevicePathEnd(RemainingDevicePath)) {

+    return FALSE;

+  }

+

+  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, (VOID **)&PxeBcProtocol);

+  if (EFI_ERROR (Status)) {

+    return FALSE;

+  } else {

+    return TRUE;

+  }

+}

+

+/**

+  Add to the list of boot devices the devices allowing a TFTP boot

+

+  @param[in]   BdsLoadOptionList  List of devices to boot from

+

+  @retval  EFI_SUCCESS            Update completed

+  @retval  EFI_OUT_OF_RESOURCES   Fail to perform the update due to lack of resource

+**/

+EFI_STATUS

+BdsLoadOptionTftpList (

+  IN OUT LIST_ENTRY* BdsLoadOptionList

+  )

+{

+  EFI_STATUS                   Status;

+  UINTN                        HandleCount;

+  EFI_HANDLE                   *HandleBuffer;

+  EFI_HANDLE                   Handle;

+  UINTN                        Index;

+  EFI_DEVICE_PATH_PROTOCOL     *DevicePathProtocol;

+  VOID                         *Interface;

+  EFI_SIMPLE_NETWORK_PROTOCOL  *SimpleNetworkProtocol;

+  BDS_SUPPORTED_DEVICE         *SupportedDevice;

+  EFI_MAC_ADDRESS              *Mac;

+

+  //

+  // List all the handles on which the Simple Network Protocol is installed.

+  //

+  Status = gBS->LocateHandleBuffer (

+                  ByProtocol,

+                  &gEfiSimpleNetworkProtocolGuid,

+                  NULL,

+                  &HandleCount,

+                  &HandleBuffer

+                  );

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < HandleCount; Index++) {

+    Handle = HandleBuffer[Index];

+    //

+    // We select the handles that support :

+    // . the Device Path Protocol

+    // . the MTFTP4 Protocol

+    //

+    Status = gBS->HandleProtocol (

+                    Handle,

+                    &gEfiDevicePathProtocolGuid,

+                    (VOID **)&DevicePathProtocol

+                    );

+    if (EFI_ERROR (Status)) {

+      continue;

+    }

+

+    Status = gBS->HandleProtocol (

+                    Handle,

+                    &gEfiMtftp4ServiceBindingProtocolGuid,

+                    &Interface

+                    );

+    if (EFI_ERROR (Status)) {

+      continue;

+    }

+

+    Status = gBS->HandleProtocol (

+                    Handle,

+                    &gEfiSimpleNetworkProtocolGuid,

+                    (VOID **)&SimpleNetworkProtocol

+                    );

+    if (EFI_ERROR (Status)) {

+      continue;

+    }

+

+    // Allocate BDS Supported Device structure

+    SupportedDevice = (BDS_SUPPORTED_DEVICE*)AllocatePool (sizeof (BDS_SUPPORTED_DEVICE));

+    if (SupportedDevice == NULL) {

+      continue;

+    }

+

+    Mac = &SimpleNetworkProtocol->Mode->CurrentAddress;

+    UnicodeSPrint (

+      SupportedDevice->Description,

+      BOOT_DEVICE_DESCRIPTION_MAX,

+      L"TFTP on MAC Address: %02x:%02x:%02x:%02x:%02x:%02x",

+      Mac->Addr[0],  Mac->Addr[1],  Mac->Addr[2],  Mac->Addr[3],  Mac->Addr[4],  Mac->Addr[5]

+      );

+

+    SupportedDevice->DevicePathProtocol = DevicePathProtocol;

+    SupportedDevice->Support = &BdsLoadOptionSupportList[BDS_DEVICE_TFTP];

+

+    InsertTailList (BdsLoadOptionList, &SupportedDevice->Link);

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BdsLoadOptionTftpCreateDevicePath (

+  IN CHAR16*                    FileName,

+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes

+  )

+{

+  EFI_STATUS            Status;

+  BOOLEAN               IsDHCP;

+  EFI_IP_ADDRESS        LocalIp;

+  EFI_IP_ADDRESS        SubnetMask;

+  EFI_IP_ADDRESS        GatewayIp;

+  EFI_IP_ADDRESS        RemoteIp;

+  IPv4_DEVICE_PATH      *IPv4DevicePathNode;

+  FILEPATH_DEVICE_PATH  *FilePathDevicePath;

+  CHAR16                BootFilePath[BOOT_DEVICE_FILEPATH_MAX];

+  UINTN                 BootFilePathSize;

+

+  Print (L"Get the IP address from DHCP: ");

+  Status = GetHIInputBoolean (&IsDHCP);

+  if (EFI_ERROR (Status)) {

+    return EFI_ABORTED;

+  }

+

+  if (!IsDHCP) {

+    Print (L"Local static IP address: ");

+    Status = GetHIInputIP (&LocalIp);

+    if (EFI_ERROR (Status)) {

+      return EFI_ABORTED;

+    }

+    Print (L"Get the network mask: ");

+    Status = GetHIInputIP (&SubnetMask);

+    if (EFI_ERROR (Status)) {

+      return EFI_ABORTED;

+    }

+    Print (L"Get the gateway IP address: ");

+    Status = GetHIInputIP (&GatewayIp);

+    if (EFI_ERROR (Status)) {

+      return EFI_ABORTED;

+    }

+  }

+

+  Print (L"Get the TFTP server IP address: ");

+  Status = GetHIInputIP (&RemoteIp);

+  if (EFI_ERROR (Status)) {

+    return EFI_ABORTED;

+  }

+

+  Print (L"File path of the %s : ", FileName);

+  Status = GetHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);

+  if (EFI_ERROR (Status)) {

+    return EFI_ABORTED;

+  }

+

+  BootFilePathSize = StrSize(BootFilePath);

+  if (BootFilePathSize == 2) {

+    return EFI_NOT_FOUND;

+  }

+

+  // Allocate the memory for the IPv4 + File Path Device Path Nodes

+  IPv4DevicePathNode = (IPv4_DEVICE_PATH*)AllocatePool(sizeof(IPv4_DEVICE_PATH) + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH);

+

+  // Create the IPv4 Device Path

+  IPv4DevicePathNode->Header.Type    = MESSAGING_DEVICE_PATH;

+  IPv4DevicePathNode->Header.SubType = MSG_IPv4_DP;

+  SetDevicePathNodeLength (&IPv4DevicePathNode->Header, sizeof(IPv4_DEVICE_PATH));

+

+  if (!IsDHCP) {

+    CopyMem (&IPv4DevicePathNode->LocalIpAddress, &LocalIp.v4, sizeof (EFI_IPv4_ADDRESS));

+    CopyMem (&IPv4DevicePathNode->SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));

+    CopyMem (&IPv4DevicePathNode->GatewayIpAddress, &GatewayIp.v4, sizeof (EFI_IPv4_ADDRESS));

+  }

+

+  CopyMem (&IPv4DevicePathNode->RemoteIpAddress, &RemoteIp.v4, sizeof (EFI_IPv4_ADDRESS));

+  IPv4DevicePathNode->LocalPort  = 0;

+  IPv4DevicePathNode->RemotePort = 0;

+  IPv4DevicePathNode->Protocol = EFI_IP_PROTO_TCP;

+  IPv4DevicePathNode->StaticIpAddress = (IsDHCP != TRUE);

+

+  // Create the FilePath Device Path node

+  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)(IPv4DevicePathNode + 1);

+  FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH;

+  FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP;

+  SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);

+  CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);

+

+  // Set the End Device Path Node

+  SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));

+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode;

+

+  return Status;

+}

+

+/**

+  Update the parameters of a TFTP boot option

+

+  The function asks sequentially to update the IPv4 parameters as well as the boot file path,

+  providing the previously set value if any.

+

+  @param[in]   OldDevicePath  Current complete device path of the Tftp boot option.

+                              This has to be a valid complete Tftp boot option path.

+                              By complete, we mean that it is not only the Tftp

+                              specific end part built by the

+                              "BdsLoadOptionTftpCreateDevicePath()" function.

+                              This path is handled as read only.

+  @param[in]   FileName       Description of the file the path is asked for

+  @param[out]  NewDevicePath  Pointer to the new complete device path.

+

+  @retval  EFI_SUCCESS            Update completed

+  @retval  EFI_ABORTED            Update aborted by the user

+  @retval  EFI_OUT_OF_RESOURCES   Fail to perform the update due to lack of resource

+**/

+EFI_STATUS

+BdsLoadOptionTftpUpdateDevicePath (

+  IN   EFI_DEVICE_PATH            *OldDevicePath,

+  IN   CHAR16                     *FileName,

+  OUT  EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath

+  )

+{

+  EFI_STATUS             Status;

+  EFI_DEVICE_PATH       *DevicePath;

+  EFI_DEVICE_PATH       *DevicePathNode;

+  UINT8                 *Ipv4NodePtr;

+  IPv4_DEVICE_PATH       Ipv4Node;

+  BOOLEAN                IsDHCP;

+  EFI_IP_ADDRESS         OldIp;

+  EFI_IP_ADDRESS         OldSubnetMask;

+  EFI_IP_ADDRESS         OldGatewayIp;

+  EFI_IP_ADDRESS         LocalIp;

+  EFI_IP_ADDRESS         SubnetMask;

+  EFI_IP_ADDRESS         GatewayIp;

+  EFI_IP_ADDRESS         RemoteIp;

+  UINT8                 *FileNodePtr;

+  CHAR16                 BootFilePath[BOOT_DEVICE_FILEPATH_MAX];

+  UINTN                  PathSize;

+  UINTN                  BootFilePathSize;

+  FILEPATH_DEVICE_PATH  *NewFilePathNode;

+

+  Ipv4NodePtr = NULL;

+

+  //

+  // Make a copy of the complete device path that is made of :

+  // the device path of the device that support the Simple Network protocol

+  // followed by an IPv4 node (type IPv4_DEVICE_PATH),

+  // followed by a file path node (type FILEPATH_DEVICE_PATH) and ended up

+  // by an end node. The IPv6 case is not handled yet.

+  //

+

+  DevicePath = DuplicateDevicePath (OldDevicePath);

+  if (DevicePath == NULL) {

+    Status = EFI_OUT_OF_RESOURCES;

+    goto ErrorExit;

+  }

+

+  //

+  // Because of the check done by "BdsLoadOptionTftpIsSupported()" prior to the

+  // call to this function, we know that the device path ends with an IPv4 node

+  // followed by a file path node and finally an end node. To get the address of

+  // the last IPv4 node, we loop over the whole device path, noting down the

+  // address of each encountered IPv4 node.

+  //

+

+  for (DevicePathNode = DevicePath;

+       !IsDevicePathEnd (DevicePathNode);

+       DevicePathNode = NextDevicePathNode (DevicePathNode))

+  {

+    if (IS_DEVICE_PATH_NODE (DevicePathNode, MESSAGING_DEVICE_PATH, MSG_IPv4_DP)) {

+      Ipv4NodePtr = (UINT8*)DevicePathNode;

+    }

+  }

+

+  // Copy for alignment of the IPv4 node data

+  CopyMem (&Ipv4Node, Ipv4NodePtr, sizeof (IPv4_DEVICE_PATH));

+

+  Print (L"Get the IP address from DHCP: ");

+  Status = GetHIInputBoolean (&IsDHCP);

+  if (EFI_ERROR (Status)) {

+    goto ErrorExit;

+  }

+

+  if (!IsDHCP) {

+    Print (L"Local static IP address: ");

+    if (Ipv4Node.StaticIpAddress) {

+      CopyMem (&OldIp.v4, &Ipv4Node.LocalIpAddress, sizeof (EFI_IPv4_ADDRESS));

+      Status = EditHIInputIP (&OldIp, &LocalIp);

+    } else {

+      Status = GetHIInputIP (&LocalIp);

+    }

+    if (EFI_ERROR (Status)) {

+      goto ErrorExit;

+    }

+

+    Print (L"Get the network mask: ");

+    if (Ipv4Node.StaticIpAddress) {

+      CopyMem (&OldSubnetMask.v4, &Ipv4Node.SubnetMask, sizeof (EFI_IPv4_ADDRESS));

+      Status = EditHIInputIP (&OldSubnetMask, &SubnetMask);

+    } else {

+      Status = GetHIInputIP (&SubnetMask);

+    }

+    if (EFI_ERROR (Status)) {

+      goto ErrorExit;

+    }

+

+    Print (L"Get the gateway IP address: ");

+    if (Ipv4Node.StaticIpAddress) {

+      CopyMem (&OldGatewayIp.v4, &Ipv4Node.GatewayIpAddress, sizeof (EFI_IPv4_ADDRESS));

+      Status = EditHIInputIP (&OldGatewayIp, &GatewayIp);

+    } else {

+      Status = GetHIInputIP (&GatewayIp);

+    }

+    if (EFI_ERROR (Status)) {

+      goto ErrorExit;

+    }

+  }

+

+  Print (L"TFTP server IP address: ");

+  // Copy remote IPv4 address into IPv4 or IPv6 union

+  CopyMem (&OldIp.v4, &Ipv4Node.RemoteIpAddress, sizeof (EFI_IPv4_ADDRESS));

+

+  Status = EditHIInputIP (&OldIp, &RemoteIp);

+  if (EFI_ERROR (Status)) {

+    goto ErrorExit;

+  }

+

+  // Get the path of the boot file and its size in number of bytes

+  FileNodePtr = Ipv4NodePtr + sizeof (IPv4_DEVICE_PATH);

+  BootFilePathSize = DevicePathNodeLength (FileNodePtr) - SIZE_OF_FILEPATH_DEVICE_PATH;

+

+  //

+  // Ask for update of the boot file path

+  //

+  do {

+    // Copy for 2-byte alignment of the Unicode string

+    CopyMem (

+      BootFilePath, FileNodePtr + SIZE_OF_FILEPATH_DEVICE_PATH,

+      MIN (BootFilePathSize, BOOT_DEVICE_FILEPATH_MAX)

+      );

+    BootFilePath[BOOT_DEVICE_FILEPATH_MAX - 1] = L'\0';

+

+    Print (L"File path of the %s: ", FileName);

+    Status = EditHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);

+    if (EFI_ERROR (Status)) {

+      goto ErrorExit;

+    }

+    PathSize = StrSize (BootFilePath);

+    if (PathSize > 2) {

+      break;

+    }

+    // Empty string, give the user another try

+    Print (L"Empty string - Invalid path\n");

+  } while (PathSize <= 2) ;

+

+  //

+  // Update the IPv4 node. IPv6 case not handled yet.

+  //

+  if (IsDHCP) {

+    Ipv4Node.StaticIpAddress = FALSE;

+    ZeroMem (&Ipv4Node.LocalIpAddress, sizeof (EFI_IPv4_ADDRESS));

+    ZeroMem (&Ipv4Node.SubnetMask, sizeof (EFI_IPv4_ADDRESS));

+    ZeroMem (&Ipv4Node.GatewayIpAddress, sizeof (EFI_IPv4_ADDRESS));

+  } else {

+    Ipv4Node.StaticIpAddress = TRUE;

+    CopyMem (&Ipv4Node.LocalIpAddress, &LocalIp.v4, sizeof (EFI_IPv4_ADDRESS));

+    CopyMem (&Ipv4Node.SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));

+    CopyMem (&Ipv4Node.GatewayIpAddress, &GatewayIp.v4, sizeof (EFI_IPv4_ADDRESS));

+  }

+

+  CopyMem (&Ipv4Node.RemoteIpAddress, &RemoteIp.v4, sizeof (EFI_IPv4_ADDRESS));

+  CopyMem (Ipv4NodePtr, &Ipv4Node, sizeof (IPv4_DEVICE_PATH));

+

+  //

+  // Create the new file path node

+  //

+  NewFilePathNode = (FILEPATH_DEVICE_PATH*)AllocatePool (

+                                             SIZE_OF_FILEPATH_DEVICE_PATH +

+                                             PathSize

+                                             );

+  NewFilePathNode->Header.Type    = MEDIA_DEVICE_PATH;

+  NewFilePathNode->Header.SubType = MEDIA_FILEPATH_DP;

+  SetDevicePathNodeLength (

+    NewFilePathNode,

+    SIZE_OF_FILEPATH_DEVICE_PATH + PathSize

+    );

+  CopyMem (NewFilePathNode->PathName, BootFilePath, PathSize);

+

+  //

+  // Generate the new Device Path by replacing the file path node at address

+  // "FileNodePtr" by the new one "NewFilePathNode" and return its address.

+  //

+  SetDevicePathEndNode (FileNodePtr);

+  *NewDevicePath = AppendDevicePathNode (

+                     DevicePath,

+                     (CONST EFI_DEVICE_PATH_PROTOCOL*)NewFilePathNode

+                     );

+

+ErrorExit:

+  if (DevicePath != NULL) {

+    FreePool (DevicePath) ;

+  }

+

+  return Status;

+}

+

+BOOLEAN

+BdsLoadOptionTftpIsSupported (

+  IN  EFI_DEVICE_PATH           *DevicePath

+  )

+{

+  EFI_STATUS  Status;

+  EFI_HANDLE Handle;

+  EFI_DEVICE_PATH  *RemainingDevicePath;

+  EFI_DEVICE_PATH  *NextDevicePath;

+  EFI_PXE_BASE_CODE_PROTOCOL  *PxeBcProtocol;

+

+  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);

+  if (EFI_ERROR(Status)) {

+    return FALSE;

+  }

+

+  // Validate the Remaining Device Path

+  if (IsDevicePathEnd(RemainingDevicePath)) {

+    return FALSE;

+  }

+  if (!IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv4_DP) &&

+      !IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv6_DP)) {

+    return FALSE;

+  }

+  NextDevicePath = NextDevicePathNode (RemainingDevicePath);

+  if (IsDevicePathEnd(NextDevicePath)) {

+    return FALSE;

+  }

+  if (!IS_DEVICE_PATH_NODE(NextDevicePath,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP)) {

+    return FALSE;

+  }

+

+  Status = gBS->HandleProtocol (Handle, &gEfiPxeBaseCodeProtocolGuid, (VOID **)&PxeBcProtocol);

+  if (EFI_ERROR (Status)) {

+    return FALSE;

+  } else {

+    return TRUE;

+  }

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Contributions.txt b/uefi/linaro-edk2/ArmPlatformPkg/Contributions.txt
new file mode 100644
index 0000000..f87cbd7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Contributions.txt
@@ -0,0 +1,218 @@
+

+======================

+= Code Contributions =

+======================

+

+To make a contribution to a TianoCore project, follow these steps.

+1. Create a change description in the format specified below to

+   use in the source control commit log.

+2. Your commit message must include your "Signed-off-by" signature,

+   and "Contributed-under" message.

+3. Your "Contributed-under" message explicitly states that the

+   contribution is made under the terms of the specified

+   contribution agreement.  Your "Contributed-under" message

+   must include the name of contribution agreement and version.

+   For example: Contributed-under: TianoCore Contribution Agreement 1.0

+   The "TianoCore Contribution Agreement" is included below in

+   this document.

+4. Submit your code to the TianoCore project using the process

+   that the project documents on its web page.  If the process is

+   not documented, then submit the code on development email list

+   for the project.

+5. It is preferred that contributions are submitted using the same

+   copyright license as the base project. When that is not possible,

+   then contributions using the following licenses can be accepted:

+   * BSD (2-clause): http://opensource.org/licenses/BSD-2-Clause

+   * BSD (3-clause): http://opensource.org/licenses/BSD-3-Clause

+   * MIT: http://opensource.org/licenses/MIT

+   * Python-2.0: http://opensource.org/licenses/Python-2.0

+   * Zlib: http://opensource.org/licenses/Zlib

+

+   Contributions of code put into the public domain can also be

+   accepted.

+

+   Contributions using other licenses might be accepted, but further

+   review will be required.

+

+=====================================================

+= Change Description / Commit Message / Patch Email =

+=====================================================

+

+Your change description should use the standard format for a

+commit message, and must include your "Signed-off-by" signature

+and the "Contributed-under" message.

+

+== Sample Change Description / Commit Message =

+

+=== Start of sample patch email message ===

+

+From: Contributor Name <contributor@example.com>

+Subject: [PATCH] CodeModule: Brief-single-line-summary

+

+Full-commit-message

+

+Contributed-under: TianoCore Contribution Agreement 1.0

+Signed-off-by: Contributor Name <contributor@example.com>

+---

+

+An extra message for the patch email which will not be considered part

+of the commit message can be added here.

+

+Patch content inline or attached

+

+=== End of sample patch email message ===

+

+=== Notes for sample patch email ===

+

+* The first line of commit message is taken from the email's subject

+  line following [PATCH]. The remaining portion of the commit message

+  is the email's content until the '---' line.

+* git format-patch is one way to create this format

+

+=== Definitions for sample patch email ===

+

+* "CodeModule" is a short idenfier for the affected code.  For

+  example MdePkg, or MdeModulePkg UsbBusDxe.

+* "Brief-single-line-summary" is a short summary of the change.

+* The entire first line should be less than ~70 characters.

+* "Full-commit-message" a verbose multiple line comment describing

+  the change.  Each line should be less than ~70 characters.

+* "Contributed-under" explicitely states that the contribution is

+  made under the terms of the contribtion agreement.  This

+  agreement is included below in this document.

+* "Signed-off-by" is the contributor's signature identifying them

+  by their real/legal name and their email address.

+

+========================================

+= TianoCore Contribution Agreement 1.0 =

+========================================

+

+INTEL CORPORATION ("INTEL") MAKES AVAILABLE SOFTWARE, DOCUMENTATION,

+INFORMATION AND/OR OTHER MATERIALS FOR USE IN THE TIANOCORE OPEN SOURCE

+PROJECT (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE

+TERMS AND CONDITIONS OF THIS AGREEMENT BETWEEN YOU AND INTEL AND/OR THE

+TERMS AND CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR

+REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE OF THE

+CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS

+OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED

+BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS

+AGREEMENT AND THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE

+AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT

+USE THE CONTENT.

+

+Unless otherwise indicated, all Content made available on the TianoCore

+site is provided to you under the terms and conditions of the BSD

+License ("BSD"). A copy of the BSD License is available at

+http://opensource.org/licenses/bsd-license.php

+or when applicable, in the associated License.txt file.

+

+Certain other content may be made available under other licenses as

+indicated in or with such Content. (For example, in a License.txt file.)

+

+You accept and agree to the following terms and conditions for Your

+present and future Contributions submitted to TianoCore site. Except

+for the license granted to Intel hereunder, You reserve all right,

+title, and interest in and to Your Contributions.

+

+== SECTION 1: Definitions ==

+* "You" or "Contributor" shall mean the copyright owner or legal

+  entity authorized by the copyright owner that is making a

+  Contribution hereunder. All other entities that control, are

+  controlled by, or are under common control with that entity are

+  considered to be a single Contributor. For the purposes of this

+  definition, "control" means (i) the power, direct or indirect, to

+  cause the direction or management of such entity, whether by

+  contract or otherwise, or (ii) ownership of fifty percent (50%)

+  or more of the outstanding shares, or (iii) beneficial ownership

+  of such entity.

+* "Contribution" shall mean any original work of authorship,

+  including any modifications or additions to an existing work,

+  that is intentionally submitted by You to the TinaoCore site for

+  inclusion in, or documentation of, any of the Content. For the

+  purposes of this definition, "submitted" means any form of

+  electronic, verbal, or written communication sent to the

+  TianoCore site or its representatives, including but not limited

+  to communication on electronic mailing lists, source code

+  control systems, and issue tracking systems that are managed by,

+  or on behalf of, the TianoCore site for the purpose of

+  discussing and improving the Content, but excluding

+  communication that is conspicuously marked or otherwise

+  designated in writing by You as "Not a Contribution."

+

+== SECTION 2: License for Contributions ==

+* Contributor hereby agrees that redistribution and use of the

+  Contribution in source and binary forms, with or without

+  modification, are permitted provided that the following

+  conditions are met:

+** Redistributions of source code must retain the Contributor's

+   copyright notice, this list of conditions and the following

+   disclaimer.

+** Redistributions in binary form must reproduce the Contributor's

+   copyright notice, this list of conditions and the following

+   disclaimer in the documentation and/or other materials provided

+   with the distribution.

+* Disclaimer. None of the names of Contributor, Intel, or the names

+  of their respective contributors may be used to endorse or

+  promote products derived from this software without specific

+  prior written permission.

+* Contributor grants a license (with the right to sublicense) under

+  claims of Contributor's patents that Contributor can license that

+  are infringed by the Contribution (as delivered by Contributor) to

+  make, use, distribute, sell, offer for sale, and import the

+  Contribution and derivative works thereof solely to the minimum

+  extent necessary for licensee to exercise the granted copyright

+  license; this patent license applies solely to those portions of

+  the Contribution that are unmodified. No hardware per se is

+  licensed.

+* EXCEPT AS EXPRESSLY SET FORTH IN SECTION 3 BELOW, THE

+  CONTRIBUTION IS PROVIDED BY THE CONTRIBUTOR "AS IS" AND ANY

+  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,

+  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A

+  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE

+  CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT

+  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN

+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR

+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE

+  CONTRIBUTION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH

+  DAMAGE.

+

+== SECTION 3: Representations ==

+* You represent that You are legally entitled to grant the above

+  license. If your employer(s) has rights to intellectual property

+  that You create that includes Your Contributions, You represent

+  that You have received permission to make Contributions on behalf

+  of that employer, that Your employer has waived such rights for

+  Your Contributions.

+* You represent that each of Your Contributions is Your original

+  creation (see Section 4 for submissions on behalf of others).

+  You represent that Your Contribution submissions include complete

+  details of any third-party license or other restriction

+  (including, but not limited to, related patents and trademarks)

+  of which You are personally aware and which are associated with

+  any part of Your Contributions.

+

+== SECTION 4: Third Party Contributions ==

+* Should You wish to submit work that is not Your original creation,

+  You may submit it to TianoCore site separately from any

+  Contribution, identifying the complete details of its source

+  and of any license or other restriction (including, but not

+  limited to, related patents, trademarks, and license agreements)

+  of which You are personally aware, and conspicuously marking the

+  work as "Submitted on behalf of a third-party: [named here]".

+

+== SECTION 5: Miscellaneous ==

+* Applicable Laws. Any claims arising under or relating to this

+  Agreement shall be governed by the internal substantive laws of

+  the State of Delaware or federal courts located in Delaware,

+  without regard to principles of conflict of laws.

+* Language. This Agreement is in the English language only, which

+  language shall be controlling in all respects, and all versions

+  of this Agreement in any other language shall be for accommodation

+  only and shall not be binding. All communications and notices made

+  or given pursuant to this Agreement, and all documentation and

+  support to be provided, unless otherwise noted, shall be in the

+  English language.

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ARM-EDK2-Overview.png b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ARM-EDK2-Overview.png
new file mode 100755
index 0000000..37cb394
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ARM-EDK2-Overview.png
Binary files differ
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformLib-2nd-Stage.png b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformLib-2nd-Stage.png
new file mode 100755
index 0000000..fbb952c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformLib-2nd-Stage.png
Binary files differ
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformLib-Full-Boot.png b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformLib-Full-Boot.png
new file mode 100755
index 0000000..d9098aa
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformLib-Full-Boot.png
Binary files differ
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformPkg.txt b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformPkg.txt
new file mode 100644
index 0000000..e591767
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmPlatformPkg.txt
@@ -0,0 +1,75 @@
+Porting UEFI to a ARM platform :

+--------------------------------

+1. Create the new platform directory under ArmPlatformPkg

+

+2. Create its DSC and FDF files into this new directory. These files can be copied from ArmVExpress-CTA9x4.dsc and ArmVExpress-CTA9x4.fdf; and adapted following the requirement of your platform. 

+

+3. Set up the PCDs required by ArmPlatformPkg in your FDF or DSC files 

+

+4. Implement 'ArmPlatformLib' for your platform following the interface defined by ArmPlatformPkg\Include\Library\ArmPlatformLib.h.

+

+

+PCDs	Description :

+-------------------

+

+# Firmware Device / Volume

+gArmTokenSpaceGuid.PcdSecureFdBaseAddress       : Base address of your Secure Firmware Device 

+gArmTokenSpaceGuid.PcdSecureFdSize              : Size in byte of your Secure Firmware Device.

+gArmTokenSpaceGuid.PcdFdBaseAddress       : Base Address of your Non-Secure/Normal World Firmware Device.

+gArmTokenSpaceGuid.PcdFdSize              : Size in bytes of your Non-Secure/Normal World Firmware Device 

+

+# Stacks

+gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase             : Base of Secure Stack for Secure World

+gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize       : Size of the stack for the Primary Core in Secure World

+gArmPlatformTokenSpaceGuid.PcdCPUCoreSecSecondaryStackSize     : Size of the stack for the Secondary Cores in Secure World

+gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase          : Base of Stack for Monitor World

+gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize           : Size of the stack for each cores

+gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase                : Base of SEC Stack for Normal World

+gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize          : Size of the stack for the Primary Core

+gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize        : Size of the stack for the Secondary Core

+

+# CPU / Architectural controllers

+gArmTokenSpaceGuid.PcdGicDistributorBase        : Base address of the Distributor of your General Interrupt Controller

+gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase : Base address of the Interface of your General Interrupt Controller

+

+# Memory Regions

+gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize  : Size of the region reserve for PI & UEFI

+gArmTokenSpaceGuid.PcdSystemMemoryBase                    : Base Address of the System Memory (DRAM)

+gArmTokenSpaceGuid.PcdSystemMemorySize                    : Size of the System Memory (DRAM)

+

+# Features

+gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec : TRUE if System Memory initialized by the SEC phase

+gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores : TRUE if the PrePi or PrePeiCore modules have to send an SGI to resume the excution of the secondary cores 

+

+# Boot Manager

+gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription      : Description of the Default Boot Entry

+gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath       : DevicePath of the Default Boot Entry

+gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument         : Argument for the Default Boot Entry

+gArmPlatformTokenSpaceGuid.PcdDefaultBootType             : Define the binary type of the Default Boot Entry (0=EFI application, 1=Linux kernel with ATAG support, 2=Linux Kernel with FDT support)  

+gArmPlatformTokenSpaceGuid.PcdFdtDevicePath               : DevicePath of the Platform Device Tree

+gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut         : Timeout before booting on the Device Boot entry (by default the auto boot is skipped)

+gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths           : List of Device Path use for the Console Input

+gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths          : List of Device Path use for the Console Output

+

+

+FAQ :

+-----

+# When to use PrePi or PrePeiCore ?

+- PrePi: when the memory has already been initialized by the first stage boot loader

+    Boot sequence: PlatformFirmware/PrePi/Dxe/Bds

+    Example: Beagle Board

+

+- PrePeiCore: when the firmware is started from XIP memory and in Secure world. The PeiCore shadows the firmware itself in System Memory (DRAM)

+    Boot sequence: Sec/PrePiCore/PeiCore/Dxe/Bds

+    Example: ARM Versatile Express

+

+See:

+- ArmPlatformPkg/Documentation/ARM-EDK2-Overview.png

+- ArmPlatformPkg/Documentation/ArmPlatformLib-Full-Boot.png

+- ArmPlatformPkg/Documentation/ArmPlatformLib-2nd-Stage.png

+

+# What is the PcdStandalone

+gArmPlatformTokenSpaceGuid.PcdStandalone=FALSE is used on ARM Development Platforms during the development stage.

+To avoid to reflash the NOR Flash after each build, the SEC (in NOR Flash) intializes thd DRAM and wait until the Normal World firmware is copied into the DRAM.

+Copying the firmware in DRAM is much faster than reflashing the NOR Flash. It is also more convenient to debug the firmware form DRAM than NOR Flash (eg: use of software breakpoint)

+ 

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmRealViewRTSMInstructions.txt b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmRealViewRTSMInstructions.txt
new file mode 100644
index 0000000..5d86e9a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmRealViewRTSMInstructions.txt
@@ -0,0 +1,43 @@
+==============================================

+= ARM RealView Emulation Board Documentation =

+==============================================

+

+

+Howto build UEFI RealView EB for RealTime System Model

+------------------------------------------------------

+

+For Linux

+---------

+

+1. Get EDK2 from Tianocore Subversion repository

+svn co https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2 edk2 --username guest

+ 

+2. Get FatPkg from EDK2 SVN repository: 

+cd edk2

+svn co https://edk2-fatdriver2.svn.sourceforge.net/svnroot/edk2-fatdriver2/trunk/FatPkg FatPkg --username guest

+

+3. Set up the environment. And build the EDK2Â’s tools

+export EDK_TOOLS_PATH=`pwd`/BaseTools

+. edksetup.sh `pwd`/BaseTools/

+make -C $EDK_TOOLS_PATH

+

+4. Build the ARM RealView EB UEFI Firmware

+build -a ARM -p ArmPlatformPkg/ArmRealViewEBPkg/ArmRealViewEb-RTSM-A8.dsc -t RVCTLINUX

+

+

+Howto test UEFI RealView EB on RealTime System Model - Example Cortex A8

+------------------------------------------------------------------------

+

+   1. Build 'ArmRealViewEb-RTSM-A8.dsc'

+

+   2. To Run ArmRealViewEbPkg on the RTSM

+         1. Start RealView Debugger

+         2. Target > "Connect to Target"

+         3. Add RTSM

+         4. Configure this new RTSM.

+         5. Choose CortexA8

+         6. Setup the 'fname' of baseboard.flashldr_0 with your FD file (eg: c:\dev\edk2\Build\ArmRealViewEb-RTSM-A8\DEBUG_RVCT\FV\ARMREALVIEWEB_EFI.fd)

+         7. Turn use_s8 to TRUE in baseboard.sp810_sysctrl

+         8. Turn uart_enable to TRUE in baseboard.uart_0 

+   4. Connect a telnet client to the port 5000 of your localhost

+   5. Launch the program 
\ No newline at end of file
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmVExpressInstructions.txt b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmVExpressInstructions.txt
new file mode 100644
index 0000000..a3fe9d7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Documentation/ArmVExpressInstructions.txt
@@ -0,0 +1,169 @@
+=======================================

+= ARM Versatile Express Documentation =

+=======================================

+

+Status

+------

+Build and Run on EDK2 Subversion revision 11837

+Requirements 

+-	RVCTv3 (untested) or RVCTv4 or ARMGCC (Code Sourcery q201009)

+-	Using Ubuntu: gcc, make, uuid-dev 

+-	Using Cygwin: gcc, make, e2fsprogs (needed for uuid.h) 

+

+Serial Terminal settings 

+-	Baud Rates: 38400

+- Data: 8 bit

+- Parity: None

+- Flow Control: None 

+

+

+Use ICE debugger with Versatile Express 

+---------------------------------------

+Prior to use ICE debugger with Versatile Express, you will need to update the version of the ICE's firmware.

+If you have not installed RealView 4.0 SP3, do it.

+Open "RealView ICE Update" and "Install Firmware Update ...". Install "[ARM_INSTALL_PATH]\RVI\Firmware\3.4\11\ARM-RVI-3.4.0-25-base.rvi" and "[ARM_INSTALL_PATH]\RVI\Firmware\3.4\22\ARM-RVI-3.4.59-59-patch.rvi". 

+

+

+Howto build UEFI Versatile Express

+----------------------------------

+For Linux

+---------

+

+For the first time 

+******************

+1. Get EDK2 from Tianocore Subversion repository

+svn co https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2 edk2 --username guest

+ 

+2. Get FatPkg from EDK2 SVN repository: 

+cd edk2

+svn co https://edk2-fatdriver2.svn.sourceforge.net/svnroot/edk2-fatdriver2/trunk/FatPkg FatPkg --username guest

+

+3. Set up the environment. And build the EDK2Â’s tools

+export EDK_TOOLS_PATH=`pwd`/BaseTools

+. edksetup.sh

+make -C $EDK_TOOLS_PATH

+

+4. Ensure the ARMGCC toolchain is in your PATH environment variable or defined by the ARMGCC_TOOLS_PATH environment variable. Example:

+export ARMGCC_TOOLS_PATH=/opt/toolchains/arm-2010.09-arm-none-eabi-i686-pc-linux-gnu/bin/

+

+5. Build the ARM Versatile Express UEFI Firmware

+build -a ARM -p ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc -t ARMGCC

+

+6. Edit the ARM Versatile Express configuration file config.txt to declare the location of the UEFI firmware in NOR Flash

+TOTALIMAGES: 5                   ;Number of Images (Max : 32)

+NOR0UPDATE: AUTO                 ;Image Update:NONE/AUTO/FORCE

+NOR0ADDRESS: BOOT                ;Image Flash Address

+NOR0FILE: \SOFTWARE\bm_v209.axf  ;Image File Name

+NOR1UPDATE: AUTO                 ;IMAGE UPDATE:NONE/AUTO/FORCE

+NOR1ADDRESS: 44000000            ;Image Flash Address

+NOR1FILE: \SOFTWARE\sec_uefi.bin ;Image File Name

+NOR1LOAD: 0                      ;Image Load Address

+NOR1ENTRY: 0                     ;Image Entry Point

+NOR2UPDATE: AUTO                 ;IMAGE UPDATE:NONE/AUTO/FORCE

+NOR2ADDRESS: 45000000            ;Image Flash Address

+NOR2FILE: \SOFTWARE\uefi.bin     ;Image File Name

+NOR2LOAD: 45000000               ;Image Load Address

+NOR2ENTRY: 45000000              ;Image Entry Point

+NOR3UPDATE: AUTO                 ;IMAGE UPDATE:NONE/AUTO/FORCE

+NOR3ADDRESS: 46000000            ;Image Flash Address

+NOR3FILE: \SOFTWARE\kernel.bin   ;Image File Name

+NOR3LOAD: 46000000               ;Image Load Address

+NOR3ENTRY: 46000000              ;Image Entry Point

+NOR4UPDATE: AUTO                 ;IMAGE UPDATE:NONE/AUTO/FORCE

+NOR4ADDRESS: 40000000            ;Image Flash Address

+NOR4NAME: BOOTSCRIPT             ;Image Name

+NOR4FILE: \SOFTWARE\bootscr.txt  ;Image File Name

+

+7. To select second NOR Flash as a booting device, replace in the ARM Versatile Express file \SITE1\HBI0191B\board.txt:

+SCC: 0x004 0x00001F09

+By:

+SCC: 0x004 0x10001F09

+

+8. Copy Build/ArmVExpress-CTA9x4/DEBUG_ARMGCC/FV/SEC_ARMVEXPRESS_EFI.fd to the ARM Versatile Express mass storage (available when the board is connected through USB to your host machine) under the folder SOTWARE and name sec_uefi.bin. Example for cygwin:

+cp Build/ArmVExpress-CTA9x4/DEBUG_ARMGCC/FV/SEC_ARMVEXPRESS_EFI.fd /cygdrive/e/SOFTWARE/sec_uefi.bin

+

+9. Start the ARM Versatile Express board. You should read “Waiting for firmware at 0x80000000 ...” on the serial port. 

+

+10. Copy ARMVEXPRESS_EFI.fd at 0x80000000 with RealView Debugger

+readfile,raw,nowarn "[EDK2_PATH]\Build\ArmVExpress-CTA9x4\DEBUG_ARMGCC\FV\ARMVEXPRESS_EFI.fd"=0x80000000

+

+11. Resume the execution from RealView Debugger

+

+For all subsequent times

+************************

+1. Build ARM Versatile Express UEFI Firmware

+build -a ARM -p ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc -t ARMGCC

+

+2. Start the ARM Versatile Express board. You should read “Waiting for firmware at 0x80000000 ...” on the serial port. 

+

+3. Copy ARMVEXPRESS_EFI.fd at 0x80000000 with RealView Debugger

+readfile,raw,nowarn "[EDK2_PATH]\Build\ArmVExpress-CTA9x4\DEBUG_ARMGCC\FV\ARMVEXPRESS_EFI.fd"=0x80000000

+

+4. Resume the execution 

+

+

+For RealView Compiler Toolchain on Windows

+------------------------------------------

+The command line window needs to be the one from Visual Studio to get the environment variables required to get some development tools (the windows compiler for BaseTools and `nmake`).

+The EDK2 toolchain name for ARM RealView Compiler Toolchain under a Windows environment is `RVCT`. The EDK2 build system will automatically pick up the RVCT toolchain defined in your PATH. If you want to use a specific version, set the environment variable 'RVCT_TOOLS_PATH': 

+set RVCT_TOOLS_PATH=[YOUR_TOOLCHAIN_PATH]

+

+

+For RealView Compiler Toolchain on Linux

+----------------------------------------

+The EDK2 toolchain name for ARM RealView under a Linux environment is `RVCTLINUX`. The EDK2 build system will automatically pick up the RVCT toolchain defined in your PATH. If you want to use a specific version, set the environment variable 'RVCT_TOOLS_PATH': 

+export RVCT_TOOLS_PATH=[YOUR_TOOLCHAIN_PATH]

+

+

+For RVCT on Cygwin

+------------------

+The EDK2 toolchain name for ARM RealView under a Cygwin environment is `RVCTCYGWIN`. The EDK2 build system will automatically pick up the RVCT toolchain defined in your PATH. If you want to use a specific version, set the environment variable 'RVCT_TOOLS_PATH': 

+export RVCT_TOOLS_PATH=[YOUR_TOOLCHAIN_PATH]

+

+

+To support the standalone mode:

+-------------------------------

+The full ArmVe UEFI firmware can be written into NOR Flash to allow the entire boot sequence to be done after a cold boot.

+

+build -a ARM -p ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc -t ARMGCC -D EDK2_ARMVE_STANDALONE=1

+ARMVEXPRESS_EFI.fd is required to be copied into the ARM Versatile Express board:

+cp Build/ArmVExpress-CTA9x4-Standalone/DEBUG_ARMGCC/FV/SEC_ARMVEXPRESS_EFI.fd /cygdrive/e/SOFTWARE/sec_uefi.bin

+cp Build/ArmVExpress-CTA9x4-Standalone/DEBUG_ARMGCC/FV/ARMVEXPRESS_EFI.fd /cygdrive/e/SOFTWARE/uefi.bin

+

+

+Trustzone Support

+-----------------

+ArmVE's UEFI supports booting Trustzone (two worlds: Secure and Normal Worlds) and No Trustzone (one world: the CPU remains in Secure World) supports. Trustzone support is enabled by Enabling SMC TZASC in the Test Chip SCC Register 1. This register can only be changed by editing the configuration file of your Versatile Express board: E:\SITE1\HBI0191B\board.txt Changing: 

+SCC: 0x004 0x10001F09

+For: 

+SCC: 0x004 0x10003F09

+

+

+Booting Linux

+-------------

+The default entry in the ARM Boot Manager is defined by the PCDs:

+

+- gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"NorFlash"

+- gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"VenHw(E7223039-5836-41E1-B542-D7EC736C5E59)/MemoryMapped(0,0x46000000,0x462F0000)"

+- gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|"root=/dev/sda2 rootwait debug earlyprintk console=ttyAMA0,38400 mem=1G"

+- gArmPlatformTokenSpaceGuid.PcdDefaultBootType|1

+

+The PCD PcdDefaultBootDevicePath expects a Device Path conforms to the UEFI specification.

+PcdDefaultBootType defines the type of the image pointed by PcdDefaultBootDevicePath.

+-	PcdDefaultBootDevicePath = 0 for an EFI Application

+-	PcdDefaultBootDevicePath = 1 for a legacy kernel with ATAG support

+-	PcdDefaultBootDevicePath = 2 for a kernel with Flat Device Tree (FDT) support

+

+Example of UEFI Device Path: 

+

+// Load FDT binary from the Firmware Volume (mapped at 0x80000000)

+#define LINUX_KERNEL  L"MemoryMapped(11,0x80000000,0x6FEFFFFF)\\zImage.fdt"

+

+// Linux Kernel from a SD Card

+#define LINUX_KERNEL    L"VenHw(621B6FA5-4DC1-476F-B9D8-52C557D81070)/HD(1,MBR,0x00000000,0xF9,0x3C8907)\\boot\\zImage.fdt"

+

+// Kernel from SATA HD - Partition 2

+#define LINUX_KERNEL    L"Acpi(PNP0A03,0)/Pci(0|0)/Pci(0|0)/Pci(5|0)/Pci(0|0)/Sata(0,0,0)/HD(2,MBR,0x00076730,0x1F21BF,0x1F21BF)\\boot\\zImage.fdt"

+

+// Kernel from NOR Flash

+#define LINUX_KERNEL            L"VenHw(02118005-9DA7-443a-92D5-781F022AEDBB)/MemoryMapped(0,0x46000000,0x462F0000)"

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.c
new file mode 100644
index 0000000..070c0dc
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.c
@@ -0,0 +1,106 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <Library/BaseLib.h>

+#include <Library/IoLib.h>

+

+#include <Drivers/ArmTrustzone.h>

+

+#define TZPC_DECPROT0_STATUS_REG        0x800

+#define TZPC_DECPROT0_SET_REG           0x804

+#define TZPC_DECPROT0_CLEAR_REG         0x808

+

+#define TZASC_CONFIGURATION_REG         0x000

+#define TZASC_REGIONS_REG               0x100

+#define TZASC_REGION0_LOW_ADDRESS_REG   0x100

+#define TZASC_REGION0_HIGH_ADDRESS_REG  0x104

+#define TZASC_REGION0_ATTRIBUTES        0x108

+

+/**

+    FIXME: Need documentation

+**/

+EFI_STATUS

+TZPCSetDecProtBits (

+  IN  UINTN TzpcBase,

+  IN  UINTN TzpcId,

+  IN  UINTN Bits

+  )

+{

+  if (TzpcId > TZPC_DECPROT_MAX) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_SET_REG + (TzpcId * 0x0C), Bits);

+

+  return EFI_SUCCESS;

+}

+

+/**

+    FIXME: Need documentation

+**/

+EFI_STATUS

+TZPCClearDecProtBits (

+  IN  UINTN TzpcBase,

+  IN  UINTN TzpcId,

+  IN  UINTN Bits

+  )

+{

+  if (TzpcId> TZPC_DECPROT_MAX) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  MmioWrite32 ((UINTN)TzpcBase + TZPC_DECPROT0_CLEAR_REG + (TzpcId * 0x0C), Bits);

+

+  return EFI_SUCCESS;

+}

+

+/**

+    FIXME: Need documentation

+**/

+UINT32

+TZASCGetNumRegions (

+  IN UINTN TzascBase

+  )

+{

+  return (MmioRead32 ((UINTN)TzascBase + TZASC_CONFIGURATION_REG) & 0xF);

+}

+

+/**

+    FIXME: Need documentation

+**/

+EFI_STATUS

+TZASCSetRegion (

+  IN  INTN  TzascBase,

+  IN  UINTN RegionId,

+  IN  UINTN Enabled,

+  IN  UINTN LowAddress,

+  IN  UINTN HighAddress,

+  IN  UINTN Size,

+  IN  UINTN Security

+  )

+{

+  UINT32*     Region;

+

+  if (RegionId > TZASCGetNumRegions(TzascBase)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Region = (UINT32*)((UINTN)TzascBase + TZASC_REGIONS_REG + (RegionId * 0x10));

+

+  MmioWrite32((UINTN)(Region), LowAddress&0xFFFF8000);

+  MmioWrite32((UINTN)(Region+1), HighAddress);

+  MmioWrite32((UINTN)(Region+2), ((Security & 0xF) <<28) | ((Size & 0x3F) << 1) | (Enabled & 0x1));

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.inf
new file mode 100644
index 0000000..6f90589
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.inf
@@ -0,0 +1,33 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmTrustZoneLib

+  FILE_GUID                      = 5962d040-8b8a-11df-9a71-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmTrustZoneLib

+

+

+[Sources.common]

+  ArmTrustZone.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  IoLib

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c
new file mode 100644
index 0000000..9186912
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c
@@ -0,0 +1,125 @@
+/** @file  Lcd.c

+

+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+

+  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 <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/LcdPlatformLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PcdLib.h>

+

+#include <Drivers/HdLcd.h>

+

+#include "LcdGraphicsOutputDxe.h"

+

+/**********************************************************************

+ *

+ *  This file contains all the bits of the Lcd that are

+ *  platform independent.

+ *

+ **********************************************************************/

+

+EFI_STATUS

+LcdInitialize (

+  IN EFI_PHYSICAL_ADDRESS   VramBaseAddress

+  )

+{

+  // Disable the controller

+  MmioWrite32(HDLCD_REG_COMMAND, HDLCD_DISABLE);

+

+  // Disable all interrupts

+  MmioWrite32(HDLCD_REG_INT_MASK, 0);

+

+  // Define start of the VRAM. This never changes for any graphics mode

+  MmioWrite32(HDLCD_REG_FB_BASE, (UINT32) VramBaseAddress);

+

+  // Setup various registers that never change

+  MmioWrite32(HDLCD_REG_BUS_OPTIONS,  (4 << 8) | HDLCD_BURST_8);

+  MmioWrite32(HDLCD_REG_POLARITIES,   HDLCD_PXCLK_LOW | HDLCD_DATA_HIGH | HDLCD_DATEN_HIGH | HDLCD_HSYNC_LOW | HDLCD_VSYNC_HIGH);

+  MmioWrite32(HDLCD_REG_PIXEL_FORMAT, HDLCD_LITTLE_ENDIAN | HDLCD_4BYTES_PER_PIXEL);

+  MmioWrite32(HDLCD_REG_RED_SELECT,   (0 << 16 | 8 << 8 |  0));

+  MmioWrite32(HDLCD_REG_GREEN_SELECT, (0 << 16 | 8 << 8 |  8));

+  MmioWrite32(HDLCD_REG_BLUE_SELECT,  (0 << 16 | 8 << 8 | 16));

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdSetMode (

+  IN UINT32  ModeNumber

+  )

+{

+  EFI_STATUS        Status;

+  UINT32            HRes;

+  UINT32            HSync;

+  UINT32            HBackPorch;

+  UINT32            HFrontPorch;

+  UINT32            VRes;

+  UINT32            VSync;

+  UINT32            VBackPorch;

+  UINT32            VFrontPorch;

+  UINT32            BytesPerPixel;

+  LCD_BPP           LcdBpp;

+

+

+  // Set the video mode timings and other relevant information

+  Status = LcdPlatformGetTimings (ModeNumber,

+                                  &HRes,&HSync,&HBackPorch,&HFrontPorch,

+                                  &VRes,&VSync,&VBackPorch,&VFrontPorch);

+  ASSERT_EFI_ERROR (Status);

+  if (EFI_ERROR( Status )) {

+    return EFI_DEVICE_ERROR;

+  }

+

+  Status = LcdPlatformGetBpp (ModeNumber,&LcdBpp);

+  ASSERT_EFI_ERROR (Status);

+  if (EFI_ERROR( Status )) {

+    return EFI_DEVICE_ERROR;

+  }

+

+  BytesPerPixel = GetBytesPerPixel(LcdBpp);

+

+  // Disable the controller

+  MmioWrite32(HDLCD_REG_COMMAND, HDLCD_DISABLE);

+

+  // Update the frame buffer information with the new settings

+  MmioWrite32(HDLCD_REG_FB_LINE_LENGTH, HRes * BytesPerPixel);

+  MmioWrite32(HDLCD_REG_FB_LINE_PITCH,  HRes * BytesPerPixel);

+  MmioWrite32(HDLCD_REG_FB_LINE_COUNT,  VRes - 1);

+

+  // Set the vertical timing information

+  MmioWrite32(HDLCD_REG_V_SYNC,         VSync);

+  MmioWrite32(HDLCD_REG_V_BACK_PORCH,   VBackPorch);

+  MmioWrite32(HDLCD_REG_V_DATA,         VRes - 1);

+  MmioWrite32(HDLCD_REG_V_FRONT_PORCH,  VFrontPorch);

+

+  // Set the horizontal timing information

+  MmioWrite32(HDLCD_REG_H_SYNC,         HSync);

+  MmioWrite32(HDLCD_REG_H_BACK_PORCH,   HBackPorch);

+  MmioWrite32(HDLCD_REG_H_DATA,         HRes - 1);

+  MmioWrite32(HDLCD_REG_H_FRONT_PORCH,  HFrontPorch);

+

+  // Enable the controller

+  MmioWrite32(HDLCD_REG_COMMAND, HDLCD_ENABLE);

+

+  return EFI_SUCCESS;

+}

+

+VOID

+LcdShutdown (

+  VOID

+  )

+{

+  // Disable the controller

+  MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcdGraphicsOutputDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcdGraphicsOutputDxe.inf
new file mode 100644
index 0000000..462d1fa
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcdGraphicsOutputDxe.inf
@@ -0,0 +1,63 @@
+#/** @file

+#

+#  Component description file for HDLCD module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = HdLcdGraphicsDxe

+  FILE_GUID                      = ce660500-824d-11e0-ac72-0002a5d5c51b

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  ENTRY_POINT                    = LcdGraphicsOutputDxeInitialize

+

+[Sources.common]

+  LcdGraphicsOutputDxe.c

+  LcdGraphicsOutputBlt.c

+  HdLcd.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  UefiLib

+  BaseLib

+  DebugLib

+  TimerLib

+  UefiDriverEntryPoint

+  UefiBootServicesTableLib

+  IoLib

+  BaseMemoryLib

+  LcdPlatformLib

+

+[Protocols]

+  gEfiDevicePathProtocolGuid

+  gEfiGraphicsOutputProtocolGuid                # Produced

+  gEfiEdidDiscoveredProtocolGuid                # Produced

+  gEfiEdidActiveProtocolGuid                    # Produced

+  gEfiEdidOverrideProtocolGuid                  # Produced

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdArmHdLcdBase

+

+[FeaturePcd]

+  gArmPlatformTokenSpaceGuid.PcdGopDisableOnExitBootServices

+

+[Depex]

+  gEfiCpuArchProtocolGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputBlt.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputBlt.c
new file mode 100644
index 0000000..77f93cb
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputBlt.c
@@ -0,0 +1,882 @@
+/** @file

+

+ Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>

+ 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 <PiDxe.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <Guid/GlobalVariable.h>

+

+#include "LcdGraphicsOutputDxe.h"

+

+extern BOOLEAN mDisplayInitialized;

+

+//

+// Function Definitions

+//

+

+STATIC

+EFI_STATUS

+VideoCopyNoHorizontalOverlap (

+  IN UINTN          BitsPerPixel,

+  IN volatile VOID  *FrameBufferBase,

+  IN UINT32         HorizontalResolution,

+  IN UINTN          SourceX,

+  IN UINTN          SourceY,

+  IN UINTN          DestinationX,

+  IN UINTN          DestinationY,

+  IN UINTN          Width,

+  IN UINTN          Height

+)

+{

+  EFI_STATUS    Status = EFI_SUCCESS;

+  UINTN         SourceLine;

+  UINTN         DestinationLine;

+  UINTN         WidthInBytes;

+  UINTN         LineCount;

+  INTN          Step;

+  VOID          *SourceAddr;

+  VOID          *DestinationAddr;

+

+  if( DestinationY <= SourceY ) {

+    // scrolling up (or horizontally but without overlap)

+    SourceLine       = SourceY;

+    DestinationLine  = DestinationY;

+    Step             = 1;

+  } else {

+    // scrolling down

+    SourceLine       = SourceY + Height;

+    DestinationLine  = DestinationY + Height;

+    Step             = -1;

+  }

+

+  switch (BitsPerPixel) {

+

+  case LCD_BITS_PER_PIXEL_24:

+

+    WidthInBytes = Width * 4;

+

+    for( LineCount = 0; LineCount < Height; LineCount++ ) {

+      // Update the start addresses of source & destination using 32bit pointer arithmetic

+      SourceAddr      = (VOID *)((UINT32 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );

+      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);

+

+      // Copy the entire line Y from video ram to the temp buffer

+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);

+

+      // Update the line numbers

+      SourceLine      += Step;

+      DestinationLine += Step;

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_16_555:

+  case LCD_BITS_PER_PIXEL_16_565:

+  case LCD_BITS_PER_PIXEL_12_444:

+

+    WidthInBytes = Width * 2;

+

+    for( LineCount = 0; LineCount < Height; LineCount++ ) {

+      // Update the start addresses of source & destination using 16bit pointer arithmetic

+      SourceAddr      = (VOID *)((UINT16 *)FrameBufferBase + SourceLine      * HorizontalResolution + SourceX     );

+      DestinationAddr = (VOID *)((UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);

+

+      // Copy the entire line Y from video ram to the temp buffer

+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);

+

+      // Update the line numbers

+      SourceLine      += Step;

+      DestinationLine += Step;

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_8:

+  case LCD_BITS_PER_PIXEL_4:

+  case LCD_BITS_PER_PIXEL_2:

+  case LCD_BITS_PER_PIXEL_1:

+  default:

+    // Can't handle this case

+    DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+    // break;

+

+  }

+

+  EXIT:

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+VideoCopyHorizontalOverlap (

+  IN UINTN          BitsPerPixel,

+  IN volatile VOID  *FrameBufferBase,

+  UINT32            HorizontalResolution,

+  IN UINTN          SourceX,

+  IN UINTN          SourceY,

+  IN UINTN          DestinationX,

+  IN UINTN          DestinationY,

+  IN UINTN          Width,

+  IN UINTN          Height

+)

+{

+  EFI_STATUS      Status = EFI_SUCCESS;

+

+  UINT32 *PixelBuffer32bit;

+  UINT32 *SourcePixel32bit;

+  UINT32 *DestinationPixel32bit;

+

+  UINT16 *PixelBuffer16bit;

+  UINT16 *SourcePixel16bit;

+  UINT16 *DestinationPixel16bit;

+

+  UINT32          SourcePixelY;

+  UINT32          DestinationPixelY;

+  UINTN           SizeIn32Bits;

+  UINTN           SizeIn16Bits;

+

+  switch (BitsPerPixel) {

+

+  case LCD_BITS_PER_PIXEL_24:

+    // Allocate a temporary buffer

+

+    PixelBuffer32bit = (UINT32 *) AllocatePool((Height * Width) * sizeof(UINT32));

+

+    if (PixelBuffer32bit == NULL) {

+      Status = EFI_OUT_OF_RESOURCES;

+      goto EXIT;

+    }

+

+    SizeIn32Bits = Width * 4;

+

+    // Copy from the video ram (source region) to a temp buffer

+    for (SourcePixelY = SourceY, DestinationPixel32bit = PixelBuffer32bit;

+         SourcePixelY < SourceY + Height;

+         SourcePixelY++, DestinationPixel32bit += Width)

+    {

+      // Update the start address of line Y (source)

+      SourcePixel32bit = (UINT32 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;

+

+      // Copy the entire line Y from video ram to the temp buffer

+      CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);

+    }

+

+    // Copy from the temp buffer to the video ram (destination region)

+    for (DestinationPixelY = DestinationY, SourcePixel32bit = PixelBuffer32bit;

+         DestinationPixelY < DestinationY + Height;

+         DestinationPixelY++, SourcePixel32bit += Width)

+    {

+      // Update the start address of line Y (target)

+      DestinationPixel32bit = (UINT32 *)FrameBufferBase + DestinationPixelY * HorizontalResolution + DestinationX;

+

+      // Copy the entire line Y from the temp buffer to video ram

+      CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);

+    }

+

+    // Free up the allocated memory

+    FreePool((VOID *) PixelBuffer32bit);

+

+    break;

+

+

+  case LCD_BITS_PER_PIXEL_16_555:

+  case LCD_BITS_PER_PIXEL_16_565:

+  case LCD_BITS_PER_PIXEL_12_444:

+    // Allocate a temporary buffer

+    PixelBuffer16bit = (UINT16 *) AllocatePool((Height * Width) * sizeof(UINT16));

+

+    if (PixelBuffer16bit == NULL) {

+      Status = EFI_OUT_OF_RESOURCES;

+      goto EXIT;

+    }

+

+    // Access each pixel inside the source area of the Video Memory and copy it to the temp buffer

+

+    SizeIn16Bits = Width * 2;

+

+    for (SourcePixelY = SourceY, DestinationPixel16bit = PixelBuffer16bit;

+         SourcePixelY < SourceY + Height;

+         SourcePixelY++, DestinationPixel16bit += Width)

+    {

+      // Calculate the source address:

+      SourcePixel16bit = (UINT16 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;

+

+      // Copy the entire line Y from Video to the temp buffer

+      CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);

+    }

+

+    // Copy from the temp buffer into the destination area of the Video Memory

+

+    for (DestinationPixelY = DestinationY, SourcePixel16bit = PixelBuffer16bit;

+         DestinationPixelY < DestinationY + Height;

+         DestinationPixelY++, SourcePixel16bit += Width)

+    {

+      // Calculate the target address:

+      DestinationPixel16bit = (UINT16 *)FrameBufferBase + (DestinationPixelY * HorizontalResolution + DestinationX);

+

+      // Copy the entire line Y from the temp buffer to Video

+      CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);

+    }

+

+    // Free the allocated memory

+    FreePool((VOID *) PixelBuffer16bit);

+

+    break;

+

+

+  case LCD_BITS_PER_PIXEL_8:

+  case LCD_BITS_PER_PIXEL_4:

+  case LCD_BITS_PER_PIXEL_2:

+  case LCD_BITS_PER_PIXEL_1:

+  default:

+    // Can't handle this case

+    DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+    // break;

+

+  }

+

+EXIT:

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+BltVideoFill (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,

+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *EfiSourcePixel,     OPTIONAL

+  IN UINTN                               SourceX,

+  IN UINTN                               SourceY,

+  IN UINTN                               DestinationX,

+  IN UINTN                               DestinationY,

+  IN UINTN                               Width,

+  IN UINTN                               Height,

+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer

+  )

+{

+  EFI_PIXEL_BITMASK*  PixelInformation;

+  EFI_STATUS         Status;

+  UINT32             HorizontalResolution;

+  LCD_BPP            BitsPerPixel;

+  VOID            *FrameBufferBase;

+  VOID            *DestinationAddr;

+  UINT16          *DestinationPixel16bit;

+  UINT16          Pixel16bit;

+  UINT32          DestinationPixelX;

+  UINT32          DestinationLine;

+  UINTN           WidthInBytes;

+

+  Status           = EFI_SUCCESS;

+  PixelInformation = &This->Mode->Info->PixelInformation;

+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));

+  HorizontalResolution = This->Mode->Info->HorizontalResolution;

+

+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);

+

+  switch (BitsPerPixel) {

+  case LCD_BITS_PER_PIXEL_24:

+    WidthInBytes = Width * 4;

+

+    // Copy the SourcePixel into every pixel inside the target rectangle

+    for (DestinationLine = DestinationY;

+         DestinationLine < DestinationY + Height;

+         DestinationLine++)

+    {

+      // Calculate the target address using 32bit pointer arithmetic:

+      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationX);

+

+      // Fill the entire line

+      SetMem32 (DestinationAddr, WidthInBytes, *((UINT32 *)EfiSourcePixel));

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_16_555:

+    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel

+    Pixel16bit = (UINT16) (

+        ( (EfiSourcePixel->Red      <<  7) & PixelInformation->RedMask      )

+      | ( (EfiSourcePixel->Green    <<  2) & PixelInformation->GreenMask    )

+      | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )

+//      | ( 0                           & PixelInformation->ReservedMask )

+     );

+

+    // Copy the SourcePixel into every pixel inside the target rectangle

+    for (DestinationLine = DestinationY;

+         DestinationLine < DestinationY + Height;

+         DestinationLine++)

+    {

+      for (DestinationPixelX = DestinationX;

+           DestinationPixelX < DestinationX + Width;

+           DestinationPixelX++)

+      {

+        // Calculate the target address:

+        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;

+

+        // Copy the pixel into the new target

+        *DestinationPixel16bit = Pixel16bit;

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_16_565:

+    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel

+    Pixel16bit = (UINT16) (

+        ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )

+      | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )

+      | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )

+     );

+

+    // Copy the SourcePixel into every pixel inside the target rectangle

+    for (DestinationLine = DestinationY;

+         DestinationLine < DestinationY + Height;

+         DestinationLine++)

+    {

+      for (DestinationPixelX = DestinationX;

+           DestinationPixelX < DestinationX + Width;

+           DestinationPixelX++)

+      {

+        // Calculate the target address:

+        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;

+

+        // Copy the pixel into the new target

+        *DestinationPixel16bit = Pixel16bit;

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_12_444:

+    // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel

+    Pixel16bit = (UINT16) (

+        ( (EfiSourcePixel->Red      >> 4) & PixelInformation->RedMask      )

+      | ( (EfiSourcePixel->Green        ) & PixelInformation->GreenMask    )

+      | ( (EfiSourcePixel->Blue     << 4) & PixelInformation->BlueMask     )

+     );

+

+    // Copy the SourcePixel into every pixel inside the target rectangle

+    for (DestinationLine = DestinationY;

+         DestinationLine < DestinationY + Height;

+         DestinationLine++)

+    {

+      for (DestinationPixelX = DestinationX;

+           DestinationPixelX < DestinationX + Width;

+           DestinationPixelX++)

+      {

+        // Calculate the target address:

+        DestinationPixel16bit =  (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution  + DestinationPixelX;

+

+        // Copy the pixel into the new target

+        *DestinationPixel16bit = Pixel16bit;

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_8:

+  case LCD_BITS_PER_PIXEL_4:

+  case LCD_BITS_PER_PIXEL_2:

+  case LCD_BITS_PER_PIXEL_1:

+  default:

+    // Can't handle this case

+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoFill: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));

+    Status = EFI_INVALID_PARAMETER;

+    break;

+  }

+

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+BltVideoToBltBuffer (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,

+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL

+  IN UINTN                               SourceX,

+  IN UINTN                               SourceY,

+  IN UINTN                               DestinationX,

+  IN UINTN                               DestinationY,

+  IN UINTN                               Width,

+  IN UINTN                               Height,

+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer

+  )

+{

+  EFI_STATUS         Status;

+  UINT32             HorizontalResolution;

+  LCD_BPP            BitsPerPixel;

+  EFI_PIXEL_BITMASK  *PixelInformation;

+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiDestinationPixel;

+  VOID   *FrameBufferBase;

+  VOID            *SourceAddr;

+  VOID            *DestinationAddr;

+  UINT16 *SourcePixel16bit;

+  UINT16          Pixel16bit;

+  UINT32          SourcePixelX;

+  UINT32          SourceLine;

+  UINT32          DestinationPixelX;

+  UINT32          DestinationLine;

+  UINT32          BltBufferHorizontalResolution;

+  UINTN           WidthInBytes;

+

+  Status = EFI_SUCCESS;

+  PixelInformation = &This->Mode->Info->PixelInformation;

+  HorizontalResolution = This->Mode->Info->HorizontalResolution;

+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));

+

+  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {

+    // Delta is not zero and it is different from the width.

+    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.

+    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));

+  } else {

+    BltBufferHorizontalResolution = Width;

+  }

+

+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);

+

+  switch (BitsPerPixel) {

+  case LCD_BITS_PER_PIXEL_24:

+    WidthInBytes = Width * 4;

+

+    // Access each line inside the Video Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+         SourceLine < SourceY + Height;

+         SourceLine++, DestinationLine++)

+    {

+      // Calculate the source and target addresses using 32bit pointer arithmetic:

+      SourceAddr      = (VOID *)((UINT32 *)FrameBufferBase + SourceLine      * HorizontalResolution          + SourceX     );

+      DestinationAddr = (VOID *)((UINT32 *)BltBuffer       + DestinationLine * BltBufferHorizontalResolution + DestinationX);

+

+      // Copy the entire line

+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_16_555:

+    // Access each pixel inside the Video Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+         SourceLine < SourceY + Height;

+         SourceLine++, DestinationLine++)

+    {

+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;

+           SourcePixelX < SourceX + Width;

+           SourcePixelX++, DestinationPixelX++)

+      {

+        // Calculate the source and target addresses:

+        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;

+        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;

+

+        // Snapshot the pixel from the video buffer once, to speed up the operation.

+        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.

+        Pixel16bit = *SourcePixel16bit;

+

+        // Copy the pixel into the new target

+        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >>  7 );

+        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >>  2);

+        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) <<  3 );

+        // EfiDestinationPixel->Reserved = (UINT8) 0;

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_16_565:

+    // Access each pixel inside the Video Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+         SourceLine < SourceY + Height;

+         SourceLine++, DestinationLine++)

+    {

+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;

+           SourcePixelX < SourceX + Width;

+           SourcePixelX++, DestinationPixelX++)

+      {

+        // Calculate the source and target addresses:

+        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;

+        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;

+

+        // Snapshot the pixel from the video buffer once, to speed up the operation.

+        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.

+        Pixel16bit = *SourcePixel16bit;

+

+        // Copy the pixel into the new target

+        // There is no info for the Reserved byte, so we set it to zero

+        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >> 8 );

+        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   ) >> 3);

+        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) << 3 );

+        // EfiDestinationPixel->Reserved = (UINT8) 0;

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_12_444:

+    // Access each pixel inside the Video Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+         SourceLine < SourceY + Height;

+         SourceLine++, DestinationLine++)

+    {

+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;

+           SourcePixelX < SourceX + Width;

+           SourcePixelX++, DestinationPixelX++)

+      {

+        // Calculate the source and target addresses:

+        SourcePixel16bit = (UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourcePixelX;

+        EfiDestinationPixel = BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationPixelX;

+

+        // Snapshot the pixel from the video buffer once, to speed up the operation.

+        // If we were dereferencing the pointer, as it is volatile, we would perform 3 memory read operations.

+        Pixel16bit = *SourcePixel16bit;

+

+        // Copy the pixel into the new target

+        EfiDestinationPixel->Red      = (UINT8) ( (Pixel16bit & PixelInformation->RedMask     ) >> 4 );

+        EfiDestinationPixel->Green    = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask   )     );

+        EfiDestinationPixel->Blue     = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask    ) << 4 );

+        // EfiDestinationPixel->Reserved = (UINT8) 0;

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_8:

+  case LCD_BITS_PER_PIXEL_4:

+  case LCD_BITS_PER_PIXEL_2:

+  case LCD_BITS_PER_PIXEL_1:

+  default:

+    // Can't handle this case

+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoToBltBuffer: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));

+    Status = EFI_INVALID_PARAMETER;

+    break;

+  }

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+BltBufferToVideo (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,

+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL

+  IN UINTN                               SourceX,

+  IN UINTN                               SourceY,

+  IN UINTN                               DestinationX,

+  IN UINTN                               DestinationY,

+  IN UINTN                               Width,

+  IN UINTN                               Height,

+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer

+  )

+{

+  EFI_STATUS         Status;

+  UINT32             HorizontalResolution;

+  LCD_BPP            BitsPerPixel;

+  EFI_PIXEL_BITMASK  *PixelInformation;

+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *EfiSourcePixel;

+  VOID   *FrameBufferBase;

+  VOID            *SourceAddr;

+  VOID            *DestinationAddr;

+  UINT16 *DestinationPixel16bit;

+  UINT32          SourcePixelX;

+  UINT32          SourceLine;

+  UINT32          DestinationPixelX;

+  UINT32          DestinationLine;

+  UINT32          BltBufferHorizontalResolution;

+  UINTN           WidthInBytes;

+

+  Status = EFI_SUCCESS;

+  PixelInformation = &This->Mode->Info->PixelInformation;

+  HorizontalResolution = This->Mode->Info->HorizontalResolution;

+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));

+

+  if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {

+    // Delta is not zero and it is different from the width.

+    // Divide it by the size of a pixel to find out the buffer's horizontal resolution.

+    BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));

+  } else {

+    BltBufferHorizontalResolution = Width;

+  }

+

+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);

+

+  switch (BitsPerPixel) {

+  case LCD_BITS_PER_PIXEL_24:

+    WidthInBytes = Width * 4;

+

+    // Access each pixel inside the BltBuffer Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+       SourceLine < SourceY + Height;

+       SourceLine++, DestinationLine++)

+    {

+      // Calculate the source and target addresses using 32bit pointer arithmetic:

+      SourceAddr      = (VOID *)((UINT32 *)BltBuffer       + SourceLine      * BltBufferHorizontalResolution + SourceX     );

+      DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution          + DestinationX);

+

+      // Copy the entire row Y

+      CopyMem( DestinationAddr, SourceAddr, WidthInBytes);

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_16_555:

+    // Access each pixel inside the BltBuffer Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+       SourceLine < SourceY + Height;

+       SourceLine++, DestinationLine++) {

+

+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;

+           SourcePixelX < SourceX + Width;

+           SourcePixelX++, DestinationPixelX++)

+      {

+        // Calculate the source and target addresses:

+        EfiSourcePixel  = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;

+        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;

+

+        // Copy the pixel into the new target

+        // Only the most significant bits will be copied across:

+        // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits

+        *DestinationPixel16bit = (UINT16) (

+              ( (EfiSourcePixel->Red      <<  7) & PixelInformation->RedMask      )

+            | ( (EfiSourcePixel->Green    <<  2) & PixelInformation->GreenMask    )

+            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )

+      //            | ( 0                                & PixelInformation->ReservedMask )

+            );

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_16_565:

+    // Access each pixel inside the BltBuffer Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+         SourceLine < SourceY + Height;

+         SourceLine++, DestinationLine++) {

+

+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;

+           SourcePixelX < SourceX + Width;

+           SourcePixelX++, DestinationPixelX++)

+      {

+        // Calculate the source and target addresses:

+        EfiSourcePixel = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;

+        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;

+

+        // Copy the pixel into the new target

+        // Only the most significant bits will be copied across:

+        // To convert from 8 bits to 5 or 6 bits per pixel we throw away the 3 or 2  least significant bits

+        // There is no room for the Reserved byte so we ignore that completely

+        *DestinationPixel16bit = (UINT16) (

+              ( (EfiSourcePixel->Red      <<  8) & PixelInformation->RedMask      )

+            | ( (EfiSourcePixel->Green    <<  3) & PixelInformation->GreenMask    )

+            | ( (EfiSourcePixel->Blue     >>  3) & PixelInformation->BlueMask     )

+           );

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_12_444:

+    // Access each pixel inside the BltBuffer Memory

+    for (SourceLine = SourceY, DestinationLine = DestinationY;

+         SourceLine < SourceY + Height;

+         SourceLine++, DestinationLine++) {

+

+      for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;

+           SourcePixelX < SourceX + Width;

+           SourcePixelX++, DestinationPixelX++)

+      {

+        // Calculate the source and target addresses:

+        EfiSourcePixel = BltBuffer + SourceLine * BltBufferHorizontalResolution + SourcePixelX;

+        DestinationPixel16bit = (UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationPixelX;

+

+        // Copy the pixel into the new target

+        // Only the most significant bits will be copied across:

+        // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits

+        *DestinationPixel16bit = (UINT16) (

+              ( (EfiSourcePixel->Red      << 4) & PixelInformation->RedMask      )

+            | ( (EfiSourcePixel->Green        ) & PixelInformation->GreenMask    )

+            | ( (EfiSourcePixel->Blue     >> 4) & PixelInformation->BlueMask     )

+  //            | ( 0                               & PixelInformation->ReservedMask )

+           );

+      }

+    }

+    break;

+

+  case LCD_BITS_PER_PIXEL_8:

+  case LCD_BITS_PER_PIXEL_4:

+  case LCD_BITS_PER_PIXEL_2:

+  case LCD_BITS_PER_PIXEL_1:

+  default:

+    // Can't handle this case

+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltBufferToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));

+    Status = EFI_INVALID_PARAMETER;

+    break;

+  }

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+BltVideoToVideo (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,

+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL

+  IN UINTN                               SourceX,

+  IN UINTN                               SourceY,

+  IN UINTN                               DestinationX,

+  IN UINTN                               DestinationY,

+  IN UINTN                               Width,

+  IN UINTN                               Height,

+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer

+  )

+{

+  EFI_STATUS         Status;

+  UINT32             HorizontalResolution;

+  LCD_BPP            BitsPerPixel;

+  VOID   *FrameBufferBase;

+

+  HorizontalResolution = This->Mode->Info->HorizontalResolution;

+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));

+

+  //

+  // BltVideo to BltVideo:

+  //

+  //  Source is the Video Memory,

+  //  Destination is the Video Memory

+

+  LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel);

+  FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));

+

+  // The UEFI spec currently states:

+  // "There is no limitation on the overlapping of the source and destination rectangles"

+  // Therefore, we must be careful to avoid overwriting the source data

+  if( SourceY == DestinationY ) {

+    // Copying within the same height, e.g. horizontal shift

+    if( SourceX == DestinationX ) {

+      // Nothing to do

+      Status = EFI_SUCCESS;

+    } else if( ((SourceX>DestinationX)?(SourceX - DestinationX):(DestinationX - SourceX)) < Width ) {

+      // There is overlap

+      Status = VideoCopyHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );

+    } else {

+      // No overlap

+      Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );

+    }

+  } else {

+    // Copying from different heights

+    Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height );

+  }

+

+  return Status;

+}

+

+/***************************************

+ * GraphicsOutput Protocol function, mapping to

+ * EFI_GRAPHICS_OUTPUT_PROTOCOL.Blt

+ *

+ * PRESUMES: 1 pixel = 4 bytes (32bits)

+ *  ***************************************/

+EFI_STATUS

+EFIAPI

+LcdGraphicsBlt (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL        *This,

+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *BltBuffer,     OPTIONAL

+  IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION   BltOperation,

+  IN UINTN                               SourceX,

+  IN UINTN                               SourceY,

+  IN UINTN                               DestinationX,

+  IN UINTN                               DestinationY,

+  IN UINTN                               Width,

+  IN UINTN                               Height,

+  IN UINTN                               Delta           OPTIONAL   // Number of BYTES in a row of the BltBuffer

+  )

+{

+  EFI_STATUS         Status;

+  UINT32             HorizontalResolution;

+  UINT32             VerticalResolution;

+  LCD_INSTANCE*      Instance;

+

+  Instance = LCD_INSTANCE_FROM_GOP_THIS(This);

+

+  // Setup the hardware if not already done

+  if (!mDisplayInitialized) {

+    Status = InitializeDisplay (Instance);

+    if (EFI_ERROR(Status)) {

+      goto EXIT;

+    }

+  }

+

+  HorizontalResolution = This->Mode->Info->HorizontalResolution;

+  VerticalResolution   = This->Mode->Info->VerticalResolution;

+

+  DEBUG((DEBUG_INFO, "LcdGraphicsBlt (BltOperation:%d,DestX:%d,DestY:%d,Width:%d,Height:%d) res(%d,%d)\n",

+      BltOperation,DestinationX,DestinationY,Width,Height,HorizontalResolution,VerticalResolution));

+

+  // Check we have reasonable parameters

+  if (Width == 0 || Height == 0) {

+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid dimension: Zero size area.\n" ));

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+  }

+

+  if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToBltBuffer)) {

+    ASSERT( BltBuffer != NULL);

+  }

+

+  /*if ((DestinationX >= HorizontalResolution) || (DestinationY >= VerticalResolution)) {

+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid destination.\n" ));

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+  }*/

+

+  // If we are reading data out of the video buffer, check that the source area is within the display limits

+  if ((BltOperation == EfiBltVideoToBltBuffer) || (BltOperation == EfiBltVideoToVideo)) {

+    if ((SourceY + Height > VerticalResolution) || (SourceX + Width > HorizontalResolution)) {

+      DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid source resolution.\n" ));

+      DEBUG((DEBUG_INFO, "                      - SourceY=%d + Height=%d > VerticalResolution=%d.\n", SourceY, Height, VerticalResolution ));

+      DEBUG((DEBUG_INFO, "                      - SourceX=%d + Width=%d > HorizontalResolution=%d.\n", SourceX, Width, HorizontalResolution ));

+      Status = EFI_INVALID_PARAMETER;

+      goto EXIT;

+    }

+  }

+

+  // If we are writing data into the video buffer, that the destination area is within the display limits

+  if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToVideo)) {

+    if ((DestinationY + Height > VerticalResolution) || (DestinationX + Width > HorizontalResolution)) {

+      DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid destination resolution.\n" ));

+      DEBUG((DEBUG_INFO, "                      - DestinationY=%d + Height=%d > VerticalResolution=%d.\n", DestinationY, Height, VerticalResolution ));

+      DEBUG((DEBUG_INFO, "                      - DestinationX=%d + Width=%d > HorizontalResolution=%d.\n", DestinationX, Width, HorizontalResolution ));

+      Status = EFI_INVALID_PARAMETER;

+      goto EXIT;

+    }

+  }

+

+  //

+  // Perform the Block Transfer Operation

+  //

+

+  switch (BltOperation) {

+  case EfiBltVideoFill:

+    Status = BltVideoFill (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);

+    break;

+

+  case EfiBltVideoToBltBuffer:

+    Status = BltVideoToBltBuffer (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);

+    break;

+

+  case EfiBltBufferToVideo:

+    Status = BltBufferToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);

+    break;

+

+  case EfiBltVideoToVideo:

+    Status = BltVideoToVideo (This, BltBuffer, SourceX, SourceY, DestinationX, DestinationY, Width, Height, Delta);

+    break;

+

+  case EfiGraphicsOutputBltOperationMax:

+  default:

+    DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: Invalid Operation\n"));

+    Status = EFI_INVALID_PARAMETER;

+    break;

+  }

+

+EXIT:

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.c
new file mode 100644
index 0000000..cbc2034
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.c
@@ -0,0 +1,388 @@
+/** @file

+

+ Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+ 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 <PiDxe.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <Guid/GlobalVariable.h>

+

+#include "LcdGraphicsOutputDxe.h"

+

+/**********************************************************************

+ *

+ *  This file implements the Graphics Output protocol on ArmVersatileExpress

+ *  using the Lcd controller

+ *

+ **********************************************************************/

+

+//

+// Global variables

+//

+

+BOOLEAN mDisplayInitialized = FALSE;

+

+LCD_INSTANCE mLcdTemplate = {

+  LCD_INSTANCE_SIGNATURE,

+  NULL, // Handle

+  { // ModeInfo

+    0, // Version

+    0, // HorizontalResolution

+    0, // VerticalResolution

+    PixelBltOnly, // PixelFormat

+    { 0 }, // PixelInformation

+    0, // PixelsPerScanLine

+  },

+  {

+    0, // MaxMode;

+    0, // Mode;

+    NULL, // Info;

+    0, // SizeOfInfo;

+    0, // FrameBufferBase;

+    0 // FrameBufferSize;

+  },

+  { // Gop

+    LcdGraphicsQueryMode,  // QueryMode

+    LcdGraphicsSetMode,    // SetMode

+    LcdGraphicsBlt,        // Blt

+    NULL                     // *Mode

+  },

+  { // DevicePath

+    {

+      {

+        HARDWARE_DEVICE_PATH, HW_VENDOR_DP,

+        { (UINT8) (sizeof(VENDOR_DEVICE_PATH)), (UINT8) ((sizeof(VENDOR_DEVICE_PATH)) >> 8) },

+      },

+      // Hardware Device Path for Lcd

+      EFI_CALLER_ID_GUID // Use the driver's GUID

+    },

+

+    {

+      END_DEVICE_PATH_TYPE,

+      END_ENTIRE_DEVICE_PATH_SUBTYPE,

+      { sizeof(EFI_DEVICE_PATH_PROTOCOL), 0 }

+    }

+  },

+  (EFI_EVENT) NULL // ExitBootServicesEvent

+};

+

+EFI_STATUS

+LcdInstanceContructor (

+  OUT LCD_INSTANCE** NewInstance

+  )

+{

+  LCD_INSTANCE* Instance;

+

+  Instance = AllocateCopyPool (sizeof(LCD_INSTANCE), &mLcdTemplate);

+  if (Instance == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  Instance->Gop.Mode          = &Instance->Mode;

+  Instance->Gop.Mode->MaxMode = LcdPlatformGetMaxMode ();

+  Instance->Mode.Info         = &Instance->ModeInfo;

+

+  *NewInstance = Instance;

+  return EFI_SUCCESS;

+}

+

+//

+// Function Definitions

+//

+

+EFI_STATUS

+InitializeDisplay (

+  IN LCD_INSTANCE* Instance

+  )

+{

+  EFI_STATUS             Status = EFI_SUCCESS;

+  EFI_PHYSICAL_ADDRESS   VramBaseAddress;

+  UINTN                  VramSize;

+

+  Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);

+  if (EFI_ERROR(Status)) {

+    return Status;

+  }

+

+  // Setup the LCD

+  Status = LcdInitialize (VramBaseAddress);

+  if (EFI_ERROR(Status)) {

+    goto EXIT_ERROR_LCD_SHUTDOWN;

+  }

+

+  Status = LcdPlatformInitializeDisplay (Instance->Handle);

+  if (EFI_ERROR(Status)) {

+    goto EXIT_ERROR_LCD_SHUTDOWN;

+  }

+

+  // Setup all the relevant mode information

+  Instance->Gop.Mode->SizeOfInfo      = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);

+  Instance->Gop.Mode->FrameBufferBase = VramBaseAddress;

+

+  // Set the flag before changing the mode, to avoid infinite loops

+  mDisplayInitialized = TRUE;

+

+  // All is ok, so don't deal with any errors

+  goto EXIT;

+

+EXIT_ERROR_LCD_SHUTDOWN:

+  DEBUG((DEBUG_ERROR, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status));

+  LcdShutdown ();

+

+EXIT:

+  return Status;

+}

+

+EFI_STATUS

+EFIAPI

+LcdGraphicsOutputDxeInitialize (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS  Status = EFI_SUCCESS;

+  LCD_INSTANCE* Instance;

+

+  Status = LcdInstanceContructor (&Instance);

+  if (EFI_ERROR(Status)) {

+    goto EXIT;

+  }

+

+  // Install the Graphics Output Protocol and the Device Path

+  Status = gBS->InstallMultipleProtocolInterfaces(

+            &Instance->Handle,

+            &gEfiGraphicsOutputProtocolGuid, &Instance->Gop,

+            &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,

+            NULL

+            );

+

+  if (EFI_ERROR(Status)) {

+    DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));

+    goto EXIT;

+  }

+

+  // Register for an ExitBootServicesEvent

+  // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,

+  // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.

+  Status = gBS->CreateEvent (

+            EVT_SIGNAL_EXIT_BOOT_SERVICES,

+            TPL_NOTIFY,

+            LcdGraphicsExitBootServicesEvent, NULL,

+            &Instance->ExitBootServicesEvent

+            );

+

+  if (EFI_ERROR(Status)) {

+    DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));

+    goto EXIT_ERROR_UNINSTALL_PROTOCOL;

+  }

+

+  // To get here, everything must be fine, so just exit

+  goto EXIT;

+

+EXIT_ERROR_UNINSTALL_PROTOCOL:

+  /* The following function could return an error message,

+   * however, to get here something must have gone wrong already,

+   * so preserve the original error, i.e. don't change

+   * the Status variable, even it fails to uninstall the protocol.

+   */

+  gBS->UninstallMultipleProtocolInterfaces (

+    Instance->Handle,

+    &gEfiGraphicsOutputProtocolGuid, &Instance->Gop, // Uninstall Graphics Output protocol

+    &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,     // Uninstall device path

+    NULL

+    );

+

+EXIT:

+  return Status;

+

+}

+

+/***************************************

+ * This function should be called

+ * on Event: ExitBootServices

+ * to free up memory, stop the driver

+ * and uninstall the protocols

+ ***************************************/

+VOID

+LcdGraphicsExitBootServicesEvent (

+  IN EFI_EVENT  Event,

+  IN VOID       *Context

+  )

+{

+  // By default, this PCD is FALSE. But if a platform starts a predefined OS that

+  // does not use a framebuffer then we might want to disable the display controller

+  // to avoid to display corrupted information on the screen.

+  if (FeaturePcdGet (PcdGopDisableOnExitBootServices)) {

+    // Turn-off the Display controller

+    LcdShutdown ();

+  }

+}

+

+/***************************************

+ * GraphicsOutput Protocol function, mapping to

+ * EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode

+ ***************************************/

+EFI_STATUS

+EFIAPI

+LcdGraphicsQueryMode (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL            *This,

+  IN UINT32                                  ModeNumber,

+  OUT UINTN                                  *SizeOfInfo,

+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION   **Info

+  )

+{

+  EFI_STATUS Status = EFI_SUCCESS;

+  LCD_INSTANCE *Instance;

+

+  Instance = LCD_INSTANCE_FROM_GOP_THIS(This);

+

+  // Setup the hardware if not already done

+  if( !mDisplayInitialized ) {

+    Status = InitializeDisplay(Instance);

+    if (EFI_ERROR(Status)) {

+      goto EXIT;

+    }

+  }

+

+  // Error checking

+  if ( (This == NULL) || (Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode) ) {

+    DEBUG((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber ));

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+  }

+

+  *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));

+  if (*Info == NULL) {

+    Status = EFI_OUT_OF_RESOURCES;

+    goto EXIT;

+  }

+

+  *SizeOfInfo = sizeof( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);

+

+  Status = LcdPlatformQueryMode (ModeNumber,*Info);

+  if (EFI_ERROR(Status)) {

+    FreePool(*Info);

+  }

+

+EXIT:

+  return Status;

+}

+

+/***************************************

+ * GraphicsOutput Protocol function, mapping to

+ * EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode

+ ***************************************/

+EFI_STATUS

+EFIAPI

+LcdGraphicsSetMode (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL   *This,

+  IN UINT32                         ModeNumber

+  )

+{

+  EFI_STATUS                      Status = EFI_SUCCESS;

+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL   FillColour;

+  LCD_INSTANCE*                   Instance;

+  LCD_BPP                         Bpp;

+

+  Instance = LCD_INSTANCE_FROM_GOP_THIS (This);

+

+  // Setup the hardware if not already done

+  if(!mDisplayInitialized) {

+    Status = InitializeDisplay (Instance);

+    if (EFI_ERROR(Status)) {

+      goto EXIT;

+    }

+  }

+

+  // Check if this mode is supported

+  if( ModeNumber >= This->Mode->MaxMode ) {

+    DEBUG((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber ));

+    Status = EFI_UNSUPPORTED;

+    goto EXIT;

+  }

+

+  // Set the oscillator frequency to support the new mode

+  Status = LcdPlatformSetMode (ModeNumber);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_DEVICE_ERROR;

+    goto EXIT;

+  }

+

+  // Update the UEFI mode information

+  This->Mode->Mode = ModeNumber;

+  LcdPlatformQueryMode (ModeNumber,&Instance->ModeInfo);

+  Status = LcdPlatformGetBpp(ModeNumber, &Bpp);

+  if (EFI_ERROR(Status)) {

+    DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status));

+    goto EXIT;

+  }

+  This->Mode->FrameBufferSize =  Instance->ModeInfo.VerticalResolution

+                               * Instance->ModeInfo.PixelsPerScanLine

+                               * GetBytesPerPixel(Bpp);

+

+  // Set the hardware to the new mode

+  Status = LcdSetMode (ModeNumber);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_DEVICE_ERROR;

+    goto EXIT;

+  }

+

+  // The UEFI spec requires that we now clear the visible portions of the output display to black.

+

+  // Set the fill colour to black

+  SetMem (&FillColour, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);

+

+  // Fill the entire visible area with the same colour.

+  Status = This->Blt (

+      This,

+      &FillColour,

+      EfiBltVideoFill,

+      0,

+      0,

+      0,

+      0,

+      This->Mode->Info->HorizontalResolution,

+      This->Mode->Info->VerticalResolution,

+      0);

+

+EXIT:

+  return Status;

+}

+

+UINTN

+GetBytesPerPixel (

+  IN  LCD_BPP       Bpp

+  )

+{

+  switch(Bpp) {

+  case LCD_BITS_PER_PIXEL_24:

+    return 4;

+

+  case LCD_BITS_PER_PIXEL_16_565:

+  case LCD_BITS_PER_PIXEL_16_555:

+  case LCD_BITS_PER_PIXEL_12_444:

+    return 2;

+

+  case LCD_BITS_PER_PIXEL_8:

+  case LCD_BITS_PER_PIXEL_4:

+  case LCD_BITS_PER_PIXEL_2:

+  case LCD_BITS_PER_PIXEL_1:

+    return 1;

+

+  default:

+    return 0;

+  }

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.h b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.h
new file mode 100644
index 0000000..dfbf2ed
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.h
@@ -0,0 +1,128 @@
+/** @file

+

+  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>

+  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 __ARM_VE_GRAPHICS_DXE_H__

+#define __ARM_VE_GRAPHICS_DXE_H__

+

+

+#include <Base.h>

+

+#include <Library/DebugLib.h>

+#include <Library/LcdPlatformLib.h>

+#include <Library/PcdLib.h>

+#include <Library/UefiLib.h>

+

+#include <Protocol/DevicePath.h>

+

+

+//

+// Device structures

+//

+typedef struct {

+  VENDOR_DEVICE_PATH            Guid;

+  EFI_DEVICE_PATH_PROTOCOL      End;

+} LCD_GRAPHICS_DEVICE_PATH;

+

+typedef struct {

+  UINT32                                Signature;

+  EFI_HANDLE                            Handle;

+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  ModeInfo;

+  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE     Mode;

+  EFI_GRAPHICS_OUTPUT_PROTOCOL          Gop;

+  LCD_GRAPHICS_DEVICE_PATH              DevicePath;

+  EFI_EVENT                             ExitBootServicesEvent;

+} LCD_INSTANCE;

+

+#define LCD_INSTANCE_SIGNATURE  SIGNATURE_32('l', 'c', 'd', '0')

+

+#define LCD_INSTANCE_FROM_GOP_THIS(a)     CR (a, LCD_INSTANCE, Gop, LCD_INSTANCE_SIGNATURE)

+

+//

+// Function Prototypes

+//

+

+VOID

+LcdGraphicsExitBootServicesEvent (

+    IN EFI_EVENT  Event,

+    IN VOID       *Context

+);

+

+EFI_STATUS

+EFIAPI

+LcdGraphicsQueryMode (

+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL          *This,

+  IN  UINT32                                ModeNumber,

+  OUT UINTN                                 *SizeOfInfo,

+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  **Info

+);

+

+EFI_STATUS

+EFIAPI

+LcdGraphicsSetMode (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL  *This,

+  IN UINT32                        ModeNumber

+);

+

+EFI_STATUS

+EFIAPI

+LcdGraphicsBlt (

+  IN EFI_GRAPHICS_OUTPUT_PROTOCOL       *This,

+  IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *BltBuffer,     OPTIONAL

+  IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION  BltOperation,

+  IN UINTN                              SourceX,

+  IN UINTN                              SourceY,

+  IN UINTN                              DestinationX,

+  IN UINTN                              DestinationY,

+  IN UINTN                              Width,

+  IN UINTN                              Height,

+  IN UINTN                              Delta           OPTIONAL

+);

+

+UINTN

+GetBytesPerPixel (

+  IN  LCD_BPP       Bpp

+  );

+

+EFI_STATUS

+EFIAPI

+GraphicsOutputDxeInitialize (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+);

+

+EFI_STATUS

+InitializeDisplay (

+  IN LCD_INSTANCE* Instance

+);

+

+EFI_STATUS

+LcdIndentify (

+  VOID

+);

+

+EFI_STATUS

+LcdInitialize (

+  EFI_PHYSICAL_ADDRESS  VramBaseAddress

+);

+

+EFI_STATUS

+LcdSetMode (

+  IN UINT32  ModeNumber

+);

+

+VOID

+LcdShutdown (

+  VOID

+);

+

+#endif /* __ARM_VE_GRAPHICS_DXE_H__ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c
new file mode 100644
index 0000000..ad841cd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c
@@ -0,0 +1,104 @@
+/** @file  PL111Lcd.c

+

+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+

+  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 <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <Drivers/PL111Lcd.h>

+

+#include "LcdGraphicsOutputDxe.h"

+

+/**********************************************************************

+ *

+ *  This file contains all the bits of the PL111 that are

+ *  platform independent.

+ *

+ **********************************************************************/

+

+EFI_STATUS

+LcdInitialize (

+  IN EFI_PHYSICAL_ADDRESS   VramBaseAddress

+  )

+{

+  // Define start of the VRAM. This never changes for any graphics mode

+  MmioWrite32(PL111_REG_LCD_UP_BASE, (UINT32) VramBaseAddress);

+  MmioWrite32(PL111_REG_LCD_LP_BASE, 0); // We are not using a double buffer

+

+  // Disable all interrupts from the PL111

+  MmioWrite32(PL111_REG_LCD_IMSC, 0);

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+LcdSetMode (

+  IN UINT32  ModeNumber

+  )

+{

+  EFI_STATUS        Status;

+  UINT32            HRes;

+  UINT32            HSync;

+  UINT32            HBackPorch;

+  UINT32            HFrontPorch;

+  UINT32            VRes;

+  UINT32            VSync;

+  UINT32            VBackPorch;

+  UINT32            VFrontPorch;

+  UINT32            LcdControl;

+  LCD_BPP           LcdBpp;

+

+  // Set the video mode timings and other relevant information

+  Status = LcdPlatformGetTimings (ModeNumber,

+                                  &HRes,&HSync,&HBackPorch,&HFrontPorch,

+                                  &VRes,&VSync,&VBackPorch,&VFrontPorch);

+  ASSERT_EFI_ERROR (Status);

+  if (EFI_ERROR( Status )) {

+    return EFI_DEVICE_ERROR;

+  }

+

+  Status = LcdPlatformGetBpp (ModeNumber,&LcdBpp);

+  ASSERT_EFI_ERROR (Status);

+  if (EFI_ERROR( Status )) {

+    return EFI_DEVICE_ERROR;

+  }

+

+  // Disable the CLCD_LcdEn bit

+  LcdControl = MmioRead32( PL111_REG_LCD_CONTROL);

+  MmioWrite32(PL111_REG_LCD_CONTROL,  LcdControl & ~1);

+

+  // Set Timings

+  MmioWrite32 (PL111_REG_LCD_TIMING_0, HOR_AXIS_PANEL(HBackPorch, HFrontPorch, HSync, HRes));

+  MmioWrite32 (PL111_REG_LCD_TIMING_1, VER_AXIS_PANEL(VBackPorch, VFrontPorch, VSync, VRes));

+  MmioWrite32 (PL111_REG_LCD_TIMING_2, CLK_SIG_POLARITY(HRes));

+  MmioWrite32 (PL111_REG_LCD_TIMING_3, 0);

+

+  // PL111_REG_LCD_CONTROL

+  LcdControl = PL111_CTRL_LCD_EN | PL111_CTRL_LCD_BPP(LcdBpp) | PL111_CTRL_LCD_TFT | PL111_CTRL_BGR;

+  MmioWrite32(PL111_REG_LCD_CONTROL,  LcdControl);

+

+  // Turn on power to the LCD Panel

+  LcdControl |= PL111_CTRL_LCD_PWR;

+  MmioWrite32(PL111_REG_LCD_CONTROL,  LcdControl);

+

+  return EFI_SUCCESS;

+}

+

+VOID

+LcdShutdown (

+  VOID

+  )

+{

+  // Disable the controller

+  MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf
new file mode 100644
index 0000000..003cc2f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111LcdGraphicsOutputDxe.inf
@@ -0,0 +1,59 @@
+#/** @file

+#

+#  Component description file for PL111LcdGraphicsOutputDxe module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = PL111LcdGraphicsDxe

+  FILE_GUID                      = 407B4008-BF5B-11DF-9547-CF16E0D72085

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  ENTRY_POINT                    = LcdGraphicsOutputDxeInitialize

+

+[Sources.common]

+  LcdGraphicsOutputDxe.c

+  LcdGraphicsOutputBlt.c

+  PL111Lcd.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  UefiLib

+  BaseLib

+  DebugLib

+  TimerLib

+  UefiDriverEntryPoint

+  UefiBootServicesTableLib

+  IoLib

+  BaseMemoryLib

+  LcdPlatformLib

+

+[Protocols]

+  gEfiDevicePathProtocolGuid

+  gEfiGraphicsOutputProtocolGuid

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdPL111LcdBase

+

+[FeaturePcd]

+  gArmPlatformTokenSpaceGuid.PcdGopDisableOnExitBootServices

+

+[Depex]

+  gEfiCpuArchProtocolGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
new file mode 100644
index 0000000..279b77c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
@@ -0,0 +1,129 @@
+/** @file  NorFlashBlockIoDxe.c

+

+  Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>

+

+  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 <Library/BaseMemoryLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#include "NorFlashDxe.h"

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoReset (

+  IN EFI_BLOCK_IO_PROTOCOL  *This,

+  IN BOOLEAN                ExtendedVerification

+  )

+{

+  NOR_FLASH_INSTANCE *Instance;

+

+  Instance = INSTANCE_FROM_BLKIO_THIS(This);

+

+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));

+

+  return NorFlashReset (Instance);

+}

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoReadBlocks (

+  IN  EFI_BLOCK_IO_PROTOCOL   *This,

+  IN  UINT32                  MediaId,

+  IN  EFI_LBA                 Lba,

+  IN  UINTN                   BufferSizeInBytes,

+  OUT VOID                    *Buffer

+  )

+{

+  NOR_FLASH_INSTANCE  *Instance;

+  EFI_STATUS          Status;

+  EFI_BLOCK_IO_MEDIA  *Media;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Instance = INSTANCE_FROM_BLKIO_THIS(This);

+  Media = This->Media;

+

+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));

+

+  if (!Media) {

+    Status = EFI_INVALID_PARAMETER;

+  } else if (!Media->MediaPresent) {

+    Status = EFI_NO_MEDIA;

+  } else if (Media->MediaId != MediaId) {

+    Status = EFI_MEDIA_CHANGED;

+  } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1)) != 0)) {

+    Status = EFI_INVALID_PARAMETER;

+  } else {

+    Status = NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer);

+  }

+

+  return Status;

+}

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoWriteBlocks (

+  IN  EFI_BLOCK_IO_PROTOCOL   *This,

+  IN  UINT32                  MediaId,

+  IN  EFI_LBA                 Lba,

+  IN  UINTN                   BufferSizeInBytes,

+  IN  VOID                    *Buffer

+  )

+{

+  NOR_FLASH_INSTANCE  *Instance;

+  EFI_STATUS          Status;

+

+  Instance = INSTANCE_FROM_BLKIO_THIS(This);

+

+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));

+

+  if( !This->Media->MediaPresent ) {

+    Status = EFI_NO_MEDIA;

+  } else if( This->Media->MediaId != MediaId ) {

+    Status = EFI_MEDIA_CHANGED;

+  } else if( This->Media->ReadOnly ) {

+    Status = EFI_WRITE_PROTECTED;

+  } else {

+    Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer);

+  }

+

+  return Status;

+}

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoFlushBlocks (

+  IN EFI_BLOCK_IO_PROTOCOL  *This

+  )

+{

+  // No Flush required for the NOR Flash driver

+  // because cache operations are not permitted.

+

+  DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));

+

+  // Nothing to do so just return without error

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
new file mode 100644
index 0000000..3abbe5c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
@@ -0,0 +1,1288 @@
+/** @file  NorFlashDxe.c

+

+  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+

+  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 <Library/UefiLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/PcdLib.h>

+

+#include "NorFlashDxe.h"

+

+STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent;

+

+//

+// Global variable declarations

+//

+NOR_FLASH_INSTANCE **mNorFlashInstances;

+UINT32               mNorFlashDeviceCount;

+

+NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {

+  NOR_FLASH_SIGNATURE, // Signature

+  NULL, // Handle ... NEED TO BE FILLED

+

+  FALSE, // Initialized

+  NULL, // Initialize

+

+  0, // DeviceBaseAddress ... NEED TO BE FILLED

+  0, // RegionBaseAddress ... NEED TO BE FILLED

+  0, // Size ... NEED TO BE FILLED

+  0, // StartLba

+

+  {

+    EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision

+    NULL, // Media ... NEED TO BE FILLED

+    NorFlashBlockIoReset, // Reset;

+    NorFlashBlockIoReadBlocks,          // ReadBlocks

+    NorFlashBlockIoWriteBlocks,         // WriteBlocks

+    NorFlashBlockIoFlushBlocks          // FlushBlocks

+  }, // BlockIoProtocol

+

+  {

+    0, // MediaId ... NEED TO BE FILLED

+    FALSE, // RemovableMedia

+    TRUE, // MediaPresent

+    FALSE, // LogicalPartition

+    FALSE, // ReadOnly

+    FALSE, // WriteCaching;

+    0, // BlockSize ... NEED TO BE FILLED

+    4, //  IoAlign

+    0, // LastBlock ... NEED TO BE FILLED

+    0, // LowestAlignedLba

+    1, // LogicalBlocksPerPhysicalBlock

+  }, //Media;

+

+  {

+    EFI_DISK_IO_PROTOCOL_REVISION, // Revision

+    NorFlashDiskIoReadDisk,        // ReadDisk

+    NorFlashDiskIoWriteDisk        // WriteDisk

+  },

+

+  FALSE, // SupportFvb ... NEED TO BE FILLED

+  {

+    FvbGetAttributes, // GetAttributes

+    FvbSetAttributes, // SetAttributes

+    FvbGetPhysicalAddress,  // GetPhysicalAddress

+    FvbGetBlockSize,  // GetBlockSize

+    FvbRead,  // Read

+    FvbWrite, // Write

+    FvbEraseBlocks, // EraseBlocks

+    NULL, //ParentHandle

+  }, //  FvbProtoccol;

+  NULL, // ShadowBuffer

+  {

+    {

+      {

+        HARDWARE_DEVICE_PATH,

+        HW_VENDOR_DP,

+        { (UINT8)sizeof(VENDOR_DEVICE_PATH), (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8) }

+      },

+      { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED

+    },

+    {

+      END_DEVICE_PATH_TYPE,

+      END_ENTIRE_DEVICE_PATH_SUBTYPE,

+      { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }

+    }

+    } // DevicePath

+};

+

+EFI_STATUS

+NorFlashCreateInstance (

+  IN UINTN                  NorFlashDeviceBase,

+  IN UINTN                  NorFlashRegionBase,

+  IN UINTN                  NorFlashSize,

+  IN UINT32                 MediaId,

+  IN UINT32                 BlockSize,

+  IN BOOLEAN                SupportFvb,

+  IN CONST GUID             *NorFlashGuid,

+  OUT NOR_FLASH_INSTANCE**  NorFlashInstance

+  )

+{

+  EFI_STATUS Status;

+  NOR_FLASH_INSTANCE* Instance;

+

+  ASSERT(NorFlashInstance != NULL);

+

+  Instance = AllocateRuntimeCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);

+  if (Instance == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  Instance->DeviceBaseAddress = NorFlashDeviceBase;

+  Instance->RegionBaseAddress = NorFlashRegionBase;

+  Instance->Size = NorFlashSize;

+

+  Instance->BlockIoProtocol.Media = &Instance->Media;

+  Instance->Media.MediaId = MediaId;

+  Instance->Media.BlockSize = BlockSize;

+  Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;

+

+  CopyGuid (&Instance->DevicePath.Vendor.Guid, NorFlashGuid);

+

+  Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);;

+  if (Instance->ShadowBuffer == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  if (SupportFvb) {

+    Instance->SupportFvb = TRUE;

+    Instance->Initialize = NorFlashFvbInitialize;

+

+    Status = gBS->InstallMultipleProtocolInterfaces (

+                  &Instance->Handle,

+                  &gEfiDevicePathProtocolGuid, &Instance->DevicePath,

+                  &gEfiBlockIoProtocolGuid,  &Instance->BlockIoProtocol,

+                  &gEfiFirmwareVolumeBlockProtocolGuid, &Instance->FvbProtocol,

+                  NULL

+                  );

+    if (EFI_ERROR(Status)) {

+      FreePool (Instance);

+      return Status;

+    }

+  } else {

+    Instance->Initialized = TRUE;

+

+    Status = gBS->InstallMultipleProtocolInterfaces (

+                    &Instance->Handle,

+                    &gEfiDevicePathProtocolGuid, &Instance->DevicePath,

+                    &gEfiBlockIoProtocolGuid,  &Instance->BlockIoProtocol,

+                    &gEfiDiskIoProtocolGuid, &Instance->DiskIoProtocol,

+                    NULL

+                    );

+    if (EFI_ERROR(Status)) {

+      FreePool (Instance);

+      return Status;

+    }

+  }

+

+  *NorFlashInstance = Instance;

+  return Status;

+}

+

+UINT32

+NorFlashReadStatusRegister (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  SR_Address

+  )

+{

+  // Prepare to read the status register

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_STATUS_REGISTER);

+  return MmioRead32 (Instance->DeviceBaseAddress);

+}

+

+STATIC

+BOOLEAN

+NorFlashBlockIsLocked (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  BlockAddress

+  )

+{

+  UINT32                LockStatus;

+

+  // Send command for reading device id

+  SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);

+

+  // Read block lock status

+  LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));

+

+  // Decode block lock status

+  LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);

+

+  if ((LockStatus & 0x2) != 0) {

+    DEBUG((EFI_D_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));

+  }

+

+  return ((LockStatus & 0x1) != 0);

+}

+

+STATIC

+EFI_STATUS

+NorFlashUnlockSingleBlock (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  BlockAddress

+  )

+{

+  UINT32                LockStatus;

+

+  // Raise the Task Priority Level to TPL_NOTIFY to serialise all its operations

+  // and to protect shared data structures.

+

+  if (FeaturePcdGet (PcdNorFlashCheckBlockLocked) == TRUE) {

+    do {

+      // Request a lock setup

+      SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_LOCK_BLOCK_SETUP);

+

+      // Request an unlock

+      SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_UNLOCK_BLOCK);

+

+      // Send command for reading device id

+      SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);

+

+      // Read block lock status

+      LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));

+

+      // Decode block lock status

+      LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);

+    } while ((LockStatus & 0x1) == 1);

+  } else {

+    // Request a lock setup

+    SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_LOCK_BLOCK_SETUP);

+

+    // Request an unlock

+    SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_UNLOCK_BLOCK);

+

+    // Wait until the status register gives us the all clear

+    do {

+      LockStatus = NorFlashReadStatusRegister (Instance, BlockAddress);

+    } while ((LockStatus & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);

+  }

+

+  // Put device back into Read Array mode

+  SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY);

+

+  DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x\n", BlockAddress));

+

+  return EFI_SUCCESS;

+}

+

+STATIC

+EFI_STATUS

+NorFlashUnlockSingleBlockIfNecessary (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  BlockAddress

+  )

+{

+  EFI_STATUS Status;

+

+  Status = EFI_SUCCESS;

+

+  if (NorFlashBlockIsLocked (Instance, BlockAddress) == TRUE) {

+    Status = NorFlashUnlockSingleBlock (Instance, BlockAddress);

+  }

+

+  return Status;

+}

+

+

+/**

+ * The following function presumes that the block has already been unlocked.

+ **/

+STATIC

+EFI_STATUS

+NorFlashEraseSingleBlock (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  BlockAddress

+  )

+{

+  EFI_STATUS            Status;

+  UINT32                StatusRegister;

+

+  Status = EFI_SUCCESS;

+

+  // Request a block erase and then confirm it

+  SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP);

+  SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM);

+

+  // Wait until the status register gives us the all clear

+  do {

+    StatusRegister = NorFlashReadStatusRegister (Instance, BlockAddress);

+  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);

+

+  if (StatusRegister & P30_SR_BIT_VPP) {

+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if ((StatusRegister & (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) == (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) {

+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (StatusRegister & P30_SR_BIT_ERASE) {

+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {

+    // The debug level message has been reduced because a device lock might happen. In this case we just retry it ...

+    DEBUG((EFI_D_INFO,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress));

+    Status = EFI_WRITE_PROTECTED;

+  }

+

+  if (EFI_ERROR(Status)) {

+    // Clear the Status Register

+    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);

+  }

+

+  // Put device back into Read Array mode

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);

+

+  return Status;

+}

+

+/**

+ * This function unlock and erase an entire NOR Flash block.

+ **/

+EFI_STATUS

+NorFlashUnlockAndEraseSingleBlock (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  BlockAddress

+  )

+{

+  EFI_STATUS      Status;

+  UINTN           Index;

+  EFI_TPL         OriginalTPL;

+

+  if (!EfiAtRuntime ()) {

+    // Raise TPL to TPL_HIGH to stop anyone from interrupting us.

+    OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);

+  } else {

+    // This initialization is only to prevent the compiler to complain about the

+    // use of uninitialized variables

+    OriginalTPL = TPL_HIGH_LEVEL;

+  }

+

+  Index = 0;

+  // The block erase might fail a first time (SW bug ?). Retry it ...

+  do {

+    // Unlock the block if we have to

+    Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);

+    if (EFI_ERROR (Status)) {

+      break;

+    }

+    Status = NorFlashEraseSingleBlock (Instance, BlockAddress);

+    Index++;

+  } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));

+

+  if (Index == NOR_FLASH_ERASE_RETRY) {

+    DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index));

+  }

+

+  if (!EfiAtRuntime ()) {

+    // Interruptions can resume.

+    gBS->RestoreTPL (OriginalTPL);

+  }

+

+  return Status;

+}

+

+

+STATIC

+EFI_STATUS

+NorFlashWriteSingleWord (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  WordAddress,

+  IN UINT32                 WriteData

+  )

+{

+  EFI_STATUS            Status;

+  UINT32                StatusRegister;

+

+  Status = EFI_SUCCESS;

+

+  // Request a write single word command

+  SEND_NOR_COMMAND(WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP);

+

+  // Store the word into NOR Flash;

+  MmioWrite32 (WordAddress, WriteData);

+

+  // Wait for the write to complete and then check for any errors; i.e. check the Status Register

+  do {

+    // Prepare to read the status register

+    StatusRegister = NorFlashReadStatusRegister (Instance, WordAddress);

+    // The chip is busy while the WRITE bit is not asserted

+  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);

+

+

+  // Perform a full status check:

+  // Mask the relevant bits of Status Register.

+  // Everything should be zero, if not, we have a problem

+

+  if (StatusRegister & P30_SR_BIT_VPP) {

+    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n",WordAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (StatusRegister & P30_SR_BIT_PROGRAM) {

+    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n",WordAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {

+    DEBUG((EFI_D_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n",WordAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (!EFI_ERROR(Status)) {

+    // Clear the Status Register

+    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);

+  }

+

+  // Put device back into Read Array mode

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);

+

+  return Status;

+}

+

+/*

+ * Writes data to the NOR Flash using the Buffered Programming method.

+ *

+ * The maximum size of the on-chip buffer is 32-words, because of hardware restrictions.

+ * Therefore this function will only handle buffers up to 32 words or 128 bytes.

+ * To deal with larger buffers, call this function again.

+ *

+ * This function presumes that both the TargetAddress and the TargetAddress+BufferSize

+ * exist entirely within the NOR Flash. Therefore these conditions will not be checked here.

+ *

+ * In buffered programming, if the target address not at the beginning of a 32-bit word boundary,

+ * then programming time is doubled and power consumption is increased.

+ * Therefore, it is a requirement to align buffer writes to 32-bit word boundaries.

+ * i.e. the last 4 bits of the target start address must be zero: 0x......00

+ */

+EFI_STATUS

+NorFlashWriteBuffer (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  TargetAddress,

+  IN UINTN                  BufferSizeInBytes,

+  IN UINT32                 *Buffer

+  )

+{

+  EFI_STATUS            Status;

+  UINTN                 BufferSizeInWords;

+  UINTN                 Count;

+  volatile UINT32       *Data;

+  UINTN                 WaitForBuffer;

+  BOOLEAN               BufferAvailable;

+  UINT32                StatusRegister;

+

+  WaitForBuffer   = MAX_BUFFERED_PROG_ITERATIONS;

+  BufferAvailable = FALSE;

+

+  // Check that the target address does not cross a 32-word boundary.

+  if ((TargetAddress & BOUNDARY_OF_32_WORDS) != 0) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Check there are some data to program

+  if (BufferSizeInBytes == 0) {

+    return EFI_BUFFER_TOO_SMALL;

+  }

+

+  // Check that the buffer size does not exceed the maximum hardware buffer size on chip.

+  if (BufferSizeInBytes > P30_MAX_BUFFER_SIZE_IN_BYTES) {

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // Check that the buffer size is a multiple of 32-bit words

+  if ((BufferSizeInBytes % 4) != 0) {

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // Pre-programming conditions checked, now start the algorithm.

+

+  // Prepare the data destination address

+  Data = (UINT32 *)TargetAddress;

+

+  // Check the availability of the buffer

+  do {

+    // Issue the Buffered Program Setup command

+    SEND_NOR_COMMAND(TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP);

+

+    // Read back the status register bit#7 from the same address

+    if (((*Data) & P30_SR_BIT_WRITE) == P30_SR_BIT_WRITE) {

+      BufferAvailable = TRUE;

+    }

+

+    // Update the loop counter

+    WaitForBuffer--;

+

+  } while ((WaitForBuffer > 0) && (BufferAvailable == FALSE));

+

+  // The buffer was not available for writing

+  if (WaitForBuffer == 0) {

+    Status = EFI_DEVICE_ERROR;

+    goto EXIT;

+  }

+

+  // From now on we work in 32-bit words

+  BufferSizeInWords = BufferSizeInBytes / (UINTN)4;

+

+  // Write the word count, which is (buffer_size_in_words - 1),

+  // because word count 0 means one word.

+  SEND_NOR_COMMAND(TargetAddress, 0, (BufferSizeInWords - 1));

+

+  // Write the data to the NOR Flash, advancing each address by 4 bytes

+  for(Count=0; Count < BufferSizeInWords; Count++, Data++, Buffer++) {

+    MmioWrite32 ((UINTN)Data, *Buffer);

+  }

+

+  // Issue the Buffered Program Confirm command, to start the programming operation

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_BUFFERED_PROGRAM_CONFIRM);

+

+  // Wait for the write to complete and then check for any errors; i.e. check the Status Register

+  do {

+    StatusRegister = NorFlashReadStatusRegister (Instance, TargetAddress);

+    // The chip is busy while the WRITE bit is not asserted

+  } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);

+

+

+  // Perform a full status check:

+  // Mask the relevant bits of Status Register.

+  // Everything should be zero, if not, we have a problem

+

+  Status          = EFI_SUCCESS;

+

+  if (StatusRegister & P30_SR_BIT_VPP) {

+    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (StatusRegister & P30_SR_BIT_PROGRAM) {

+    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {

+    DEBUG((EFI_D_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n",TargetAddress));

+    Status = EFI_DEVICE_ERROR;

+  }

+

+  if (!EFI_ERROR(Status)) {

+    // Clear the Status Register

+    SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);

+  }

+

+EXIT:

+  // Put device back into Read Array mode

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);

+

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+NorFlashWriteFullBlock (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN EFI_LBA                Lba,

+  IN UINT32                 *DataBuffer,

+  IN UINT32                 BlockSizeInWords

+  )

+{

+  EFI_STATUS    Status;

+  UINTN         WordAddress;

+  UINT32        WordIndex;

+  UINTN         BufferIndex;

+  UINTN         BlockAddress;

+  UINTN         BuffersInBlock;

+  UINTN         RemainingWords;

+  EFI_TPL       OriginalTPL;

+  UINTN         Cnt;

+

+  Status = EFI_SUCCESS;

+

+  // Get the physical address of the block

+  BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSizeInWords * 4);

+

+  // Start writing from the first address at the start of the block

+  WordAddress = BlockAddress;

+

+  if (!EfiAtRuntime ()) {

+    // Raise TPL to TPL_HIGH to stop anyone from interrupting us.

+    OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);

+  } else {

+    // This initialization is only to prevent the compiler to complain about the

+    // use of uninitialized variables

+    OriginalTPL = TPL_HIGH_LEVEL;

+  }

+

+  Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);

+  if (EFI_ERROR(Status)) {

+    DEBUG((EFI_D_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));

+    goto EXIT;

+  }

+

+  // To speed up the programming operation, NOR Flash is programmed using the Buffered Programming method.

+

+  // Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero

+  if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) {

+

+    // First, break the entire block into buffer-sized chunks.

+    BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES;

+

+    // Then feed each buffer chunk to the NOR Flash

+    // If a buffer does not contain any data, don't write it.

+    for(BufferIndex=0;

+         BufferIndex < BuffersInBlock;

+         BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS

+      ) {

+      // Check the buffer to see if it contains any data (not set all 1s).

+      for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) {

+        if (~DataBuffer[Cnt] != 0 ) {

+          // Some data found, write the buffer.

+          Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES,

+                                        DataBuffer);

+          if (EFI_ERROR(Status)) {

+            goto EXIT;

+          }

+          break;

+        }

+      }

+    }

+

+    // Finally, finish off any remaining words that are less than the maximum size of the buffer

+    RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS;

+

+    if(RemainingWords != 0) {

+      Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);

+      if (EFI_ERROR(Status)) {

+        goto EXIT;

+      }

+    }

+

+  } else {

+    // For now, use the single word programming algorithm

+    // It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,

+    // i.e. which ends in the range 0x......01 - 0x......7F.

+    for(WordIndex=0; WordIndex<BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {

+      Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);

+      if (EFI_ERROR(Status)) {

+        goto EXIT;

+      }

+    }

+  }

+

+EXIT:

+  if (!EfiAtRuntime ()) {

+    // Interruptions can resume.

+    gBS->RestoreTPL (OriginalTPL);

+  }

+

+  if (EFI_ERROR(Status)) {

+    DEBUG((EFI_D_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));

+  }

+  return Status;

+}

+

+

+EFI_STATUS

+NorFlashWriteBlocks (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN EFI_LBA                Lba,

+  IN UINTN                  BufferSizeInBytes,

+  IN VOID                   *Buffer

+  )

+{

+  UINT32          *pWriteBuffer;

+  EFI_STATUS      Status = EFI_SUCCESS;

+  EFI_LBA         CurrentBlock;

+  UINT32          BlockSizeInWords;

+  UINT32          NumBlocks;

+  UINT32          BlockCount;

+

+  // The buffer must be valid

+  if (Buffer == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if(Instance->Media.ReadOnly == TRUE) {

+    return EFI_WRITE_PROTECTED;

+  }

+

+  // We must have some bytes to read

+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes));

+  if(BufferSizeInBytes == 0) {

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // The size of the buffer must be a multiple of the block size

+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize));

+  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // All blocks must be within the device

+  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;

+

+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));

+

+  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {

+    DEBUG((EFI_D_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));

+    return EFI_INVALID_PARAMETER;

+  }

+

+  BlockSizeInWords = Instance->Media.BlockSize / 4;

+

+  // Because the target *Buffer is a pointer to VOID, we must put all the data into a pointer

+  // to a proper data type, so use *ReadBuffer

+  pWriteBuffer = (UINT32 *)Buffer;

+

+  CurrentBlock = Lba;

+  for (BlockCount=0; BlockCount < NumBlocks; BlockCount++, CurrentBlock++, pWriteBuffer = pWriteBuffer + BlockSizeInWords) {

+

+    DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN)CurrentBlock));

+

+    Status = NorFlashWriteFullBlock (Instance, CurrentBlock, pWriteBuffer, BlockSizeInWords);

+

+    if (EFI_ERROR(Status)) {

+      break;

+    }

+  }

+

+  DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status));

+  return Status;

+}

+

+EFI_STATUS

+NorFlashReadBlocks (

+  IN NOR_FLASH_INSTANCE   *Instance,

+  IN EFI_LBA              Lba,

+  IN UINTN                BufferSizeInBytes,

+  OUT VOID                *Buffer

+  )

+{

+  UINT32              NumBlocks;

+  UINTN               StartAddress;

+

+  DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n",

+      BufferSizeInBytes, Instance->Media.BlockSize, Instance->Media.LastBlock, Lba));

+

+  // The buffer must be valid

+  if (Buffer == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Return if we have not any byte to read

+  if (BufferSizeInBytes == 0) {

+    return EFI_SUCCESS;

+  }

+

+  // The size of the buffer must be a multiple of the block size

+  if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // All blocks must be within the device

+  NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;

+

+  if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {

+    DEBUG((EFI_D_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Get the address to start reading from

+  StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,

+                                        Lba,

+                                        Instance->Media.BlockSize

+                                       );

+

+  // Put the device into Read Array mode

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);

+

+  // Readout the data

+  CopyMem(Buffer, (UINTN *)StartAddress, BufferSizeInBytes);

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+NorFlashRead (

+  IN NOR_FLASH_INSTANCE   *Instance,

+  IN EFI_LBA              Lba,

+  IN UINTN                Offset,

+  IN UINTN                BufferSizeInBytes,

+  OUT VOID                *Buffer

+  )

+{

+  UINTN  StartAddress;

+

+  // The buffer must be valid

+  if (Buffer == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Return if we have not any byte to read

+  if (BufferSizeInBytes == 0) {

+    return EFI_SUCCESS;

+  }

+

+  if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > Instance->Size) {

+    DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n"));

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Get the address to start reading from

+  StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,

+                                        Lba,

+                                        Instance->Media.BlockSize

+                                       );

+

+  // Put the device into Read Array mode

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);

+

+  // Readout the data

+  CopyMem (Buffer, (UINTN *)(StartAddress + Offset), BufferSizeInBytes);

+

+  return EFI_SUCCESS;

+}

+

+/*

+  Write a full or portion of a block. It must not span block boundaries; that is,

+  Offset + *NumBytes <= Instance->Media.BlockSize.

+*/

+EFI_STATUS

+NorFlashWriteSingleBlock (

+  IN        NOR_FLASH_INSTANCE   *Instance,

+  IN        EFI_LBA               Lba,

+  IN        UINTN                 Offset,

+  IN OUT    UINTN                *NumBytes,

+  IN        UINT8                *Buffer

+  )

+{

+  EFI_STATUS  TempStatus;

+  UINT32      Tmp;

+  UINT32      TmpBuf;

+  UINT32      WordToWrite;

+  UINT32      Mask;

+  BOOLEAN     DoErase;

+  UINTN       BytesToWrite;

+  UINTN       CurOffset;

+  UINTN       WordAddr;

+  UINTN       BlockSize;

+  UINTN       BlockAddress;

+  UINTN       PrevBlockAddress;

+

+  PrevBlockAddress = 0;

+

+  if (!Instance->Initialized && Instance->Initialize) {

+    Instance->Initialize(Instance);

+  }

+

+  DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes, Buffer));

+

+  // Detect WriteDisabled state

+  if (Instance->Media.ReadOnly == TRUE) {

+    DEBUG ((EFI_D_ERROR, "NorFlashWriteSingleBlock: ERROR - Can not write: Device is in WriteDisabled state.\n"));

+    // It is in WriteDisabled state, return an error right away

+    return EFI_ACCESS_DENIED;

+  }

+

+  // Cache the block size to avoid de-referencing pointers all the time

+  BlockSize = Instance->Media.BlockSize;

+

+  // The write must not span block boundaries.

+  // We need to check each variable individually because adding two large values together overflows.

+  if ( ( Offset               >= BlockSize ) ||

+       ( *NumBytes            >  BlockSize ) ||

+       ( (Offset + *NumBytes) >  BlockSize )    ) {

+    DEBUG ((EFI_D_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // We must have some bytes to write

+  if (*NumBytes == 0) {

+    DEBUG ((EFI_D_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // Pick 128bytes as a good start for word operations as opposed to erasing the

+  // block and writing the data regardless if an erase is really needed.

+  // It looks like most individual NV variable writes are smaller than 128bytes.

+  if (*NumBytes <= 128) {

+    // Check to see if we need to erase before programming the data into NOR.

+    // If the destination bits are only changing from 1s to 0s we can just write.

+    // After a block is erased all bits in the block is set to 1.

+    // If any byte requires us to erase we just give up and rewrite all of it.

+    DoErase      = FALSE;

+    BytesToWrite = *NumBytes;

+    CurOffset    = Offset;

+

+    while (BytesToWrite > 0) {

+      // Read full word from NOR, splice as required. A word is the smallest

+      // unit we can write.

+      TempStatus = NorFlashRead (Instance, Lba, CurOffset & ~(0x3), sizeof(Tmp), &Tmp);

+      if (EFI_ERROR (TempStatus)) {

+        return EFI_DEVICE_ERROR;

+      }

+

+      // Physical address of word in NOR to write.

+      WordAddr = (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,

+                                                               Lba, BlockSize);

+      // The word of data that is to be written.

+      TmpBuf = *((UINT32*)(Buffer + (*NumBytes - BytesToWrite)));

+

+      // First do word aligned chunks.

+      if ((CurOffset & 0x3) == 0) {

+        if (BytesToWrite >= 4) {

+          // Is the destination still in 'erased' state?

+          if (~Tmp != 0) {

+            // Check to see if we are only changing bits to zero.

+            if ((Tmp ^ TmpBuf) & TmpBuf) {

+              DoErase = TRUE;

+              break;

+            }

+          }

+          // Write this word to NOR

+          WordToWrite = TmpBuf;

+          CurOffset += sizeof(TmpBuf);

+          BytesToWrite -= sizeof(TmpBuf);

+        } else {

+          // BytesToWrite < 4. Do small writes and left-overs

+          Mask = ~((~0) << (BytesToWrite * 8));

+          // Mask out the bytes we want.

+          TmpBuf &= Mask;

+          // Is the destination still in 'erased' state?

+          if ((Tmp & Mask) != Mask) {

+            // Check to see if we are only changing bits to zero.

+            if ((Tmp ^ TmpBuf) & TmpBuf) {

+              DoErase = TRUE;

+              break;

+            }

+          }

+          // Merge old and new data. Write merged word to NOR

+          WordToWrite = (Tmp & ~Mask) | TmpBuf;

+          CurOffset += BytesToWrite;

+          BytesToWrite = 0;

+        }

+      } else {

+        // Do multiple words, but starting unaligned.

+        if (BytesToWrite > (4 - (CurOffset & 0x3))) {

+          Mask = ((~0) << ((CurOffset & 0x3) * 8));

+          // Mask out the bytes we want.

+          TmpBuf &= Mask;

+          // Is the destination still in 'erased' state?

+          if ((Tmp & Mask) != Mask) {

+            // Check to see if we are only changing bits to zero.

+            if ((Tmp ^ TmpBuf) & TmpBuf) {

+              DoErase = TRUE;

+              break;

+            }

+          }

+          // Merge old and new data. Write merged word to NOR

+          WordToWrite = (Tmp & ~Mask) | TmpBuf;

+          BytesToWrite -= (4 - (CurOffset & 0x3));

+          CurOffset += (4 - (CurOffset & 0x3));

+        } else {

+          // Unaligned and fits in one word.

+          Mask = (~((~0) << (BytesToWrite * 8))) << ((CurOffset & 0x3) * 8);

+          // Mask out the bytes we want.

+          TmpBuf = (TmpBuf << ((CurOffset & 0x3) * 8)) & Mask;

+          // Is the destination still in 'erased' state?

+          if ((Tmp & Mask) != Mask) {

+            // Check to see if we are only changing bits to zero.

+            if ((Tmp ^ TmpBuf) & TmpBuf) {

+              DoErase = TRUE;

+              break;

+            }

+          }

+          // Merge old and new data. Write merged word to NOR

+          WordToWrite = (Tmp & ~Mask) | TmpBuf;

+          CurOffset += BytesToWrite;

+          BytesToWrite = 0;

+        }

+      }

+

+      //

+      // Write the word to NOR.

+      //

+

+      BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSize);

+      if (BlockAddress != PrevBlockAddress) {

+        TempStatus = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);

+        if (EFI_ERROR (TempStatus)) {

+          return EFI_DEVICE_ERROR;

+        }

+        PrevBlockAddress = BlockAddress;

+      }

+      TempStatus = NorFlashWriteSingleWord (Instance, WordAddr, WordToWrite);

+      if (EFI_ERROR (TempStatus)) {

+        return EFI_DEVICE_ERROR;

+      }

+    }

+    // Exit if we got here and could write all the data. Otherwise do the

+    // Erase-Write cycle.

+    if (!DoErase) {

+      return EFI_SUCCESS;

+    }

+  }

+

+  // Check we did get some memory. Buffer is BlockSize.

+  if (Instance->ShadowBuffer == NULL) {

+    DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Buffer not ready\n"));

+    return EFI_DEVICE_ERROR;

+  }

+

+  // Read NOR Flash data into shadow buffer

+  TempStatus = NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);

+  if (EFI_ERROR (TempStatus)) {

+    // Return one of the pre-approved error statuses

+    return EFI_DEVICE_ERROR;

+  }

+

+  // Put the data at the appropriate location inside the buffer area

+  CopyMem ((VOID*)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);

+

+  // Write the modified buffer back to the NorFlash

+  TempStatus = NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);

+  if (EFI_ERROR (TempStatus)) {

+    // Return one of the pre-approved error statuses

+    return EFI_DEVICE_ERROR;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/*

+  Although DiskIoDxe will automatically install the DiskIO protocol whenever

+  we install the BlockIO protocol, its implementation is sub-optimal as it reads

+  and writes entire blocks using the BlockIO protocol. In fact we can access

+  NOR flash with a finer granularity than that, so we can improve performance

+  by directly producing the DiskIO protocol.

+*/

+

+/**

+  Read BufferSize bytes from Offset into Buffer.

+

+  @param  This                  Protocol instance pointer.

+  @param  MediaId               Id of the media, changes every time the media is replaced.

+  @param  Offset                The starting byte offset to read from

+  @param  BufferSize            Size of Buffer

+  @param  Buffer                Buffer containing read data

+

+  @retval EFI_SUCCESS           The data was read correctly from the device.

+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.

+  @retval EFI_NO_MEDIA          There is no media in the device.

+  @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.

+  @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not

+                                valid for the device.

+

+**/

+EFI_STATUS

+EFIAPI

+NorFlashDiskIoReadDisk (

+  IN EFI_DISK_IO_PROTOCOL         *This,

+  IN UINT32                       MediaId,

+  IN UINT64                       DiskOffset,

+  IN UINTN                        BufferSize,

+  OUT VOID                        *Buffer

+  )

+{

+  NOR_FLASH_INSTANCE *Instance;

+  UINT32              BlockSize;

+  UINT32              BlockOffset;

+  EFI_LBA             Lba;

+

+  Instance = INSTANCE_FROM_DISKIO_THIS(This);

+

+  if (MediaId != Instance->Media.MediaId) {

+    return EFI_MEDIA_CHANGED;

+  }

+

+  BlockSize = Instance->Media.BlockSize;

+  Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);

+

+  return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer);

+}

+

+/**

+  Writes a specified number of bytes to a device.

+

+  @param  This       Indicates a pointer to the calling context.

+  @param  MediaId    ID of the medium to be written.

+  @param  Offset     The starting byte offset on the logical block I/O device to write.

+  @param  BufferSize The size in bytes of Buffer. The number of bytes to write to the device.

+  @param  Buffer     A pointer to the buffer containing the data to be written.

+

+  @retval EFI_SUCCESS           The data was written correctly to the device.

+  @retval EFI_WRITE_PROTECTED   The device can not be written to.

+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.

+  @retval EFI_NO_MEDIA          There is no media in the device.

+  @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.

+  @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not

+                                 valid for the device.

+

+**/

+EFI_STATUS

+EFIAPI

+NorFlashDiskIoWriteDisk (

+  IN EFI_DISK_IO_PROTOCOL         *This,

+  IN UINT32                       MediaId,

+  IN UINT64                       DiskOffset,

+  IN UINTN                        BufferSize,

+  IN VOID                         *Buffer

+  )

+{

+  NOR_FLASH_INSTANCE *Instance;

+  UINT32              BlockSize;

+  UINT32              BlockOffset;

+  EFI_LBA             Lba;

+  UINTN               RemainingBytes;

+  UINTN               WriteSize;

+  EFI_STATUS          Status;

+

+  Instance = INSTANCE_FROM_DISKIO_THIS(This);

+

+  if (MediaId != Instance->Media.MediaId) {

+    return EFI_MEDIA_CHANGED;

+  }

+

+  BlockSize = Instance->Media.BlockSize;

+  Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);

+

+  RemainingBytes = BufferSize;

+

+  // Write either all the remaining bytes, or the number of bytes that bring

+  // us up to a block boundary, whichever is less.

+  // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next

+  // block boundary (even if it is already on one).

+  WriteSize = MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) - DiskOffset);

+

+  do {

+    if (WriteSize == BlockSize) {

+      // Write a full block

+      Status = NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize / sizeof (UINT32));

+    } else {

+      // Write a partial block

+      Status = NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &WriteSize, Buffer);

+    }

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+    // Now continue writing either all the remaining bytes or single blocks.

+    RemainingBytes -= WriteSize;

+    Buffer = (UINT8 *) Buffer + WriteSize;

+    Lba++;

+    BlockOffset = 0;

+    WriteSize = MIN (RemainingBytes, BlockSize);

+  } while (RemainingBytes);

+

+  return Status;

+}

+

+EFI_STATUS

+NorFlashReset (

+  IN  NOR_FLASH_INSTANCE *Instance

+  )

+{

+  // As there is no specific RESET to perform, ensure that the devices is in the default Read Array mode

+  SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);

+  return EFI_SUCCESS;

+}

+

+/**

+  Fixup internal data so that EFI can be call in virtual mode.

+  Call the passed in Child Notify event and convert any pointers in

+  lib to virtual mode.

+

+  @param[in]    Event   The Event that is being processed

+  @param[in]    Context Event Context

+**/

+VOID

+EFIAPI

+NorFlashVirtualNotifyEvent (

+  IN EFI_EVENT        Event,

+  IN VOID             *Context

+  )

+{

+  UINTN Index;

+

+  for (Index = 0; Index < mNorFlashDeviceCount; Index++) {

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->DeviceBaseAddress);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->RegionBaseAddress);

+

+    // Convert BlockIo protocol

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.Reset);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks);

+

+    // Convert Fvb

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetBlockSize);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Read);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.SetAttributes);

+    EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Write);

+

+    if (mNorFlashInstances[Index]->ShadowBuffer != NULL) {

+      EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->ShadowBuffer);

+    }

+  }

+

+  return;

+}

+

+EFI_STATUS

+EFIAPI

+NorFlashInitialise (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS              Status;

+  UINT32                  Index;

+  NOR_FLASH_DESCRIPTION*  NorFlashDevices;

+  BOOLEAN                 ContainVariableStorage;

+

+  Status = NorFlashPlatformInitialization ();

+  if (EFI_ERROR(Status)) {

+    DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n"));

+    return Status;

+  }

+

+  Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount);

+  if (EFI_ERROR(Status)) {

+    DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n"));

+    return Status;

+  }

+

+  mNorFlashInstances = AllocateRuntimePool (sizeof(NOR_FLASH_INSTANCE*) * mNorFlashDeviceCount);

+

+  for (Index = 0; Index < mNorFlashDeviceCount; Index++) {

+    // Check if this NOR Flash device contain the variable storage region

+    ContainVariableStorage =

+        (NorFlashDevices[Index].RegionBaseAddress <= PcdGet32 (PcdFlashNvStorageVariableBase)) &&

+        (PcdGet32 (PcdFlashNvStorageVariableBase) + PcdGet32 (PcdFlashNvStorageVariableSize) <= NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);

+

+    Status = NorFlashCreateInstance (

+      NorFlashDevices[Index].DeviceBaseAddress,

+      NorFlashDevices[Index].RegionBaseAddress,

+      NorFlashDevices[Index].Size,

+      Index,

+      NorFlashDevices[Index].BlockSize,

+      ContainVariableStorage,

+      &NorFlashDevices[Index].Guid,

+      &mNorFlashInstances[Index]

+    );

+    if (EFI_ERROR(Status)) {

+      DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index));

+    }

+  }

+

+  //

+  // Register for the virtual address change event

+  //

+  Status = gBS->CreateEventEx (

+                  EVT_NOTIFY_SIGNAL,

+                  TPL_NOTIFY,

+                  NorFlashVirtualNotifyEvent,

+                  NULL,

+                  &gEfiEventVirtualAddressChangeGuid,

+                  &mNorFlashVirtualAddrChangeEvent

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
new file mode 100644
index 0000000..c246800
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
@@ -0,0 +1,367 @@
+/** @file  NorFlashDxe.h

+

+  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+

+  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 __NOR_FLASH_DXE_H__

+#define __NOR_FLASH_DXE_H__

+

+

+#include <Base.h>

+#include <PiDxe.h>

+

+#include <Guid/EventGroup.h>

+

+#include <Protocol/BlockIo.h>

+#include <Protocol/DiskIo.h>

+#include <Protocol/FirmwareVolumeBlock.h>

+

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/NorFlashPlatformLib.h>

+#include <Library/UefiLib.h>

+#include <Library/UefiRuntimeLib.h>

+

+#define NOR_FLASH_ERASE_RETRY                     10

+

+// Device access macros

+// These are necessary because we use 2 x 16bit parts to make up 32bit data

+

+#define HIGH_16_BITS                              0xFFFF0000

+#define LOW_16_BITS                               0x0000FFFF

+#define LOW_8_BITS                                0x000000FF

+

+#define FOLD_32BIT_INTO_16BIT(value)              ( ( value >> 16 ) | ( value & LOW_16_BITS ) )

+

+#define GET_LOW_BYTE(value)                       ( value & LOW_8_BITS )

+#define GET_HIGH_BYTE(value)                      ( GET_LOW_BYTE( value >> 16 ) )

+

+// Each command must be sent simultaneously to both chips,

+// i.e. at the lower 16 bits AND at the higher 16 bits

+#define CREATE_NOR_ADDRESS(BaseAddr,OffsetAddr)   ((BaseAddr) + ((OffsetAddr) << 2))

+#define CREATE_DUAL_CMD(Cmd)                      ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) )

+#define SEND_NOR_COMMAND(BaseAddr,Offset,Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))

+#define GET_NOR_BLOCK_ADDRESS(BaseAddr,Lba,LbaSize)( BaseAddr + (UINTN)((Lba) * LbaSize) )

+

+// Status Register Bits

+#define P30_SR_BIT_WRITE                          (BIT7 << 16 | BIT7)

+#define P30_SR_BIT_ERASE_SUSPEND                  (BIT6 << 16 | BIT6)

+#define P30_SR_BIT_ERASE                          (BIT5 << 16 | BIT5)

+#define P30_SR_BIT_PROGRAM                        (BIT4 << 16 | BIT4)

+#define P30_SR_BIT_VPP                            (BIT3 << 16 | BIT3)

+#define P30_SR_BIT_PROGRAM_SUSPEND                (BIT2 << 16 | BIT2)

+#define P30_SR_BIT_BLOCK_LOCKED                   (BIT1 << 16 | BIT1)

+#define P30_SR_BIT_BEFP                           (BIT0 << 16 | BIT0)

+

+// Device Commands for Intel StrataFlash(R) Embedded Memory (P30) Family

+

+// On chip buffer size for buffered programming operations

+// There are 2 chips, each chip can buffer up to 32 (16-bit)words, and each word is 2 bytes.

+// Therefore the total size of the buffer is 2 x 32 x 2 = 128 bytes

+#define P30_MAX_BUFFER_SIZE_IN_BYTES              ((UINTN)128)

+#define P30_MAX_BUFFER_SIZE_IN_WORDS              (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINTN)4))

+#define MAX_BUFFERED_PROG_ITERATIONS              10000000

+#define BOUNDARY_OF_32_WORDS                      0x7F

+

+// CFI Addresses

+#define P30_CFI_ADDR_QUERY_UNIQUE_QRY             0x10

+#define P30_CFI_ADDR_VENDOR_ID                    0x13

+

+// CFI Data

+#define CFI_QRY                                   0x00595251

+

+// READ Commands

+#define P30_CMD_READ_DEVICE_ID                    0x0090

+#define P30_CMD_READ_STATUS_REGISTER              0x0070

+#define P30_CMD_CLEAR_STATUS_REGISTER             0x0050

+#define P30_CMD_READ_ARRAY                        0x00FF

+#define P30_CMD_READ_CFI_QUERY                    0x0098

+

+// WRITE Commands

+#define P30_CMD_WORD_PROGRAM_SETUP                0x0040

+#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP      0x0010

+#define P30_CMD_BUFFERED_PROGRAM_SETUP            0x00E8

+#define P30_CMD_BUFFERED_PROGRAM_CONFIRM          0x00D0

+#define P30_CMD_BEFP_SETUP                        0x0080

+#define P30_CMD_BEFP_CONFIRM                      0x00D0

+

+// ERASE Commands

+#define P30_CMD_BLOCK_ERASE_SETUP                 0x0020

+#define P30_CMD_BLOCK_ERASE_CONFIRM               0x00D0

+

+// SUSPEND Commands

+#define P30_CMD_PROGRAM_OR_ERASE_SUSPEND          0x00B0

+#define P30_CMD_SUSPEND_RESUME                    0x00D0

+

+// BLOCK LOCKING / UNLOCKING Commands

+#define P30_CMD_LOCK_BLOCK_SETUP                  0x0060

+#define P30_CMD_LOCK_BLOCK                        0x0001

+#define P30_CMD_UNLOCK_BLOCK                      0x00D0

+#define P30_CMD_LOCK_DOWN_BLOCK                   0x002F

+

+// PROTECTION Commands

+#define P30_CMD_PROGRAM_PROTECTION_REGISTER_SETUP 0x00C0

+

+// CONFIGURATION Commands

+#define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060

+#define P30_CMD_READ_CONFIGURATION_REGISTER       0x0003

+

+#define NOR_FLASH_SIGNATURE                       SIGNATURE_32('n', 'o', 'r', '0')

+#define INSTANCE_FROM_FVB_THIS(a)                 CR(a, NOR_FLASH_INSTANCE, FvbProtocol, NOR_FLASH_SIGNATURE)

+#define INSTANCE_FROM_BLKIO_THIS(a)               CR(a, NOR_FLASH_INSTANCE, BlockIoProtocol, NOR_FLASH_SIGNATURE)

+#define INSTANCE_FROM_DISKIO_THIS(a)              CR(a, NOR_FLASH_INSTANCE, DiskIoProtocol, NOR_FLASH_SIGNATURE)

+

+typedef struct _NOR_FLASH_INSTANCE                NOR_FLASH_INSTANCE;

+

+typedef EFI_STATUS (*NOR_FLASH_INITIALIZE)        (NOR_FLASH_INSTANCE* Instance);

+

+typedef struct {

+  VENDOR_DEVICE_PATH                  Vendor;

+  EFI_DEVICE_PATH_PROTOCOL            End;

+} NOR_FLASH_DEVICE_PATH;

+

+struct _NOR_FLASH_INSTANCE {

+  UINT32                              Signature;

+  EFI_HANDLE                          Handle;

+

+  BOOLEAN                             Initialized;

+  NOR_FLASH_INITIALIZE                Initialize;

+

+  UINTN                               DeviceBaseAddress;

+  UINTN                               RegionBaseAddress;

+  UINTN                               Size;

+  EFI_LBA                             StartLba;

+

+  EFI_BLOCK_IO_PROTOCOL               BlockIoProtocol;

+  EFI_BLOCK_IO_MEDIA                  Media;

+  EFI_DISK_IO_PROTOCOL                DiskIoProtocol;

+

+  BOOLEAN                             SupportFvb;

+  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;

+  VOID*                               ShadowBuffer;

+

+  NOR_FLASH_DEVICE_PATH               DevicePath;

+};

+

+EFI_STATUS

+NorFlashReadCfiData (

+  IN  UINTN                   DeviceBaseAddress,

+  IN  UINTN                   CFI_Offset,

+  IN  UINT32                  NumberOfBytes,

+  OUT UINT32                  *Data

+  );

+

+EFI_STATUS

+NorFlashWriteBuffer (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  TargetAddress,

+  IN UINTN                  BufferSizeInBytes,

+  IN UINT32                 *Buffer

+  );

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoReset (

+  IN EFI_BLOCK_IO_PROTOCOL    *This,

+  IN BOOLEAN                  ExtendedVerification

+  );

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoReadBlocks (

+  IN  EFI_BLOCK_IO_PROTOCOL   *This,

+  IN  UINT32                  MediaId,

+  IN  EFI_LBA                 Lba,

+  IN  UINTN                   BufferSizeInBytes,

+  OUT VOID                    *Buffer

+);

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoWriteBlocks (

+  IN  EFI_BLOCK_IO_PROTOCOL   *This,

+  IN  UINT32                  MediaId,

+  IN  EFI_LBA                 Lba,

+  IN  UINTN                   BufferSizeInBytes,

+  IN  VOID                    *Buffer

+);

+

+//

+// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks

+//

+EFI_STATUS

+EFIAPI

+NorFlashBlockIoFlushBlocks (

+  IN EFI_BLOCK_IO_PROTOCOL    *This

+);

+

+//

+// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk

+//

+EFI_STATUS

+EFIAPI

+NorFlashDiskIoReadDisk (

+  IN EFI_DISK_IO_PROTOCOL         *This,

+  IN UINT32                       MediaId,

+  IN UINT64                       Offset,

+  IN UINTN                        BufferSize,

+  OUT VOID                        *Buffer

+  );

+

+//

+// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.WriteDisk

+//

+EFI_STATUS

+EFIAPI

+NorFlashDiskIoWriteDisk (

+  IN EFI_DISK_IO_PROTOCOL         *This,

+  IN UINT32                       MediaId,

+  IN UINT64                       Offset,

+  IN UINTN                        BufferSize,

+  IN VOID                         *Buffer

+  );

+

+//

+// NorFlashFvbDxe.c

+//

+

+EFI_STATUS

+EFIAPI

+NorFlashFvbInitialize (

+  IN NOR_FLASH_INSTANCE*                            Instance

+  );

+

+EFI_STATUS

+EFIAPI

+FvbGetAttributes(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,

+  OUT       EFI_FVB_ATTRIBUTES_2                    *Attributes

+  );

+

+EFI_STATUS

+EFIAPI

+FvbSetAttributes(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,

+  IN OUT    EFI_FVB_ATTRIBUTES_2                    *Attributes

+  );

+

+EFI_STATUS

+EFIAPI

+FvbGetPhysicalAddress(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,

+  OUT       EFI_PHYSICAL_ADDRESS                    *Address

+  );

+

+EFI_STATUS

+EFIAPI

+FvbGetBlockSize(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,

+  IN        EFI_LBA                                 Lba,

+  OUT       UINTN                                   *BlockSize,

+  OUT       UINTN                                   *NumberOfBlocks

+  );

+

+EFI_STATUS

+EFIAPI

+FvbRead(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,

+  IN        EFI_LBA                                 Lba,

+  IN        UINTN                                   Offset,

+  IN OUT    UINTN                                   *NumBytes,

+  IN OUT    UINT8                                   *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+FvbWrite(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,

+  IN        EFI_LBA                                 Lba,

+  IN        UINTN                                   Offset,

+  IN OUT    UINTN                                   *NumBytes,

+  IN        UINT8                                   *Buffer

+  );

+

+EFI_STATUS

+EFIAPI

+FvbEraseBlocks(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL     *This,

+  ...

+  );

+

+//

+// NorFlashDxe.c

+//

+

+EFI_STATUS

+NorFlashUnlockAndEraseSingleBlock (

+  IN NOR_FLASH_INSTANCE     *Instance,

+  IN UINTN                  BlockAddress

+  );

+

+EFI_STATUS

+NorFlashWriteSingleBlock (

+  IN        NOR_FLASH_INSTANCE   *Instance,

+  IN        EFI_LBA               Lba,

+  IN        UINTN                 Offset,

+  IN OUT    UINTN                *NumBytes,

+  IN        UINT8                *Buffer

+  );

+

+EFI_STATUS

+NorFlashWriteBlocks (

+  IN  NOR_FLASH_INSTANCE *Instance,

+  IN  EFI_LBA           Lba,

+  IN  UINTN             BufferSizeInBytes,

+  IN  VOID              *Buffer

+  );

+

+EFI_STATUS

+NorFlashReadBlocks (

+  IN NOR_FLASH_INSTANCE   *Instance,

+  IN EFI_LBA              Lba,

+  IN UINTN                BufferSizeInBytes,

+  OUT VOID                *Buffer

+  );

+

+EFI_STATUS

+NorFlashRead (

+  IN NOR_FLASH_INSTANCE   *Instance,

+  IN EFI_LBA              Lba,

+  IN UINTN                Offset,

+  IN UINTN                BufferSizeInBytes,

+  OUT VOID                *Buffer

+  );

+

+EFI_STATUS

+NorFlashWrite (

+  IN        NOR_FLASH_INSTANCE   *Instance,

+  IN        EFI_LBA               Lba,

+  IN        UINTN                 Offset,

+  IN OUT    UINTN                *NumBytes,

+  IN        UINT8                *Buffer

+  );

+

+EFI_STATUS

+NorFlashReset (

+  IN  NOR_FLASH_INSTANCE *Instance

+  );

+

+#endif /* __NOR_FLASH_DXE_H__ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
new file mode 100644
index 0000000..a161c03
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf
@@ -0,0 +1,72 @@
+#/** @file

+#

+#  Component description file for NorFlashDxe module

+#

+#  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmVeNorFlashDxe

+  FILE_GUID                      = 93E34C7E-B50E-11DF-9223-2443DFD72085

+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER

+  VERSION_STRING                 = 1.0

+  ENTRY_POINT                    = NorFlashInitialise

+

+[Sources.common]

+  NorFlashDxe.c

+  NorFlashFvbDxe.c

+  NorFlashBlockIoDxe.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  BaseLib

+  DebugLib

+  HobLib

+  NorFlashPlatformLib

+  UefiLib

+  UefiDriverEntryPoint

+  UefiBootServicesTableLib

+  UefiRuntimeLib

+  DxeServicesTableLib

+

+[Guids]

+  gEfiSystemNvDataFvGuid

+  gEfiVariableGuid

+  gEfiEventVirtualAddressChangeGuid

+

+[Protocols]

+  gEfiBlockIoProtocolGuid

+  gEfiDevicePathProtocolGuid

+  gEfiFirmwareVolumeBlockProtocolGuid

+  gEfiDiskIoProtocolGuid

+

+[Pcd.common]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize

+

+  gArmPlatformTokenSpaceGuid.PcdNorFlashCheckBlockLocked

+

+[Depex]

+  #

+  # NorFlashDxe must be loaded before VariableRuntimeDxe in case empty flash needs populating with default values

+  #

+  BEFORE gVariableRuntimeDxeFileGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
new file mode 100644
index 0000000..4f56bae
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
@@ -0,0 +1,787 @@
+/*++ @file  NorFlashFvbDxe.c

+

+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+

+ 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 <PiDxe.h>

+

+#include <Library/PcdLib.h>

+#include <Library/BaseLib.h>

+#include <Library/HobLib.h>

+#include <Library/UefiLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/DxeServicesTableLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#include <Guid/VariableFormat.h>

+#include <Guid/SystemNvDataGuid.h>

+

+#include "NorFlashDxe.h"

+

+STATIC EFI_EVENT mFvbVirtualAddrChangeEvent;

+STATIC UINTN     mFlashNvStorageVariableBase;

+

+///

+/// The Firmware Volume Block Protocol is the low-level interface

+/// to a firmware volume. File-level access to a firmware volume

+/// should not be done using the Firmware Volume Block Protocol.

+/// Normal access to a firmware volume must use the Firmware

+/// Volume Protocol. Typically, only the file system driver that

+/// produces the Firmware Volume Protocol will bind to the

+/// Firmware Volume Block Protocol.

+///

+

+/**

+  Initialises the FV Header and Variable Store Header

+  to support variable operations.

+

+  @param[in]  Ptr - Location to initialise the headers

+

+**/

+EFI_STATUS

+InitializeFvAndVariableStoreHeaders (

+  IN NOR_FLASH_INSTANCE *Instance

+  )

+{

+  EFI_STATUS                          Status;

+  VOID*                               Headers;

+  UINTN                               HeadersLength;

+  EFI_FIRMWARE_VOLUME_HEADER          *FirmwareVolumeHeader;

+  VARIABLE_STORE_HEADER               *VariableStoreHeader;

+

+  if (!Instance->Initialized && Instance->Initialize) {

+    Instance->Initialize (Instance);

+  }

+

+  HeadersLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(VARIABLE_STORE_HEADER);

+  Headers = AllocateZeroPool(HeadersLength);

+

+  // FirmwareVolumeHeader->FvLength is declared to have the Variable area AND the FTW working area AND the FTW Spare contiguous.

+  ASSERT(PcdGet32(PcdFlashNvStorageVariableBase) + PcdGet32(PcdFlashNvStorageVariableSize) == PcdGet32(PcdFlashNvStorageFtwWorkingBase));

+  ASSERT(PcdGet32(PcdFlashNvStorageFtwWorkingBase) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) == PcdGet32(PcdFlashNvStorageFtwSpareBase));

+

+  // Check if the size of the area is at least one block size

+  ASSERT((PcdGet32(PcdFlashNvStorageVariableSize) > 0) && (PcdGet32(PcdFlashNvStorageVariableSize) / Instance->Media.BlockSize > 0));

+  ASSERT((PcdGet32(PcdFlashNvStorageFtwWorkingSize) > 0) && (PcdGet32(PcdFlashNvStorageFtwWorkingSize) / Instance->Media.BlockSize > 0));

+  ASSERT((PcdGet32(PcdFlashNvStorageFtwSpareSize) > 0) && (PcdGet32(PcdFlashNvStorageFtwSpareSize) / Instance->Media.BlockSize > 0));

+

+  // Ensure the Variable area Base Addresses are aligned on a block size boundaries

+  ASSERT(PcdGet32(PcdFlashNvStorageVariableBase) % Instance->Media.BlockSize == 0);

+  ASSERT(PcdGet32(PcdFlashNvStorageFtwWorkingBase) % Instance->Media.BlockSize == 0);

+  ASSERT(PcdGet32(PcdFlashNvStorageFtwSpareBase) % Instance->Media.BlockSize == 0);

+

+  //

+  // EFI_FIRMWARE_VOLUME_HEADER

+  //

+  FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Headers;

+  CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid);

+  FirmwareVolumeHeader->FvLength =

+      PcdGet32(PcdFlashNvStorageVariableSize) +

+      PcdGet32(PcdFlashNvStorageFtwWorkingSize) +

+      PcdGet32(PcdFlashNvStorageFtwSpareSize);

+  FirmwareVolumeHeader->Signature = EFI_FVH_SIGNATURE;

+  FirmwareVolumeHeader->Attributes = (EFI_FVB_ATTRIBUTES_2) (

+                                          EFI_FVB2_READ_ENABLED_CAP   | // Reads may be enabled

+                                          EFI_FVB2_READ_STATUS        | // Reads are currently enabled

+                                          EFI_FVB2_STICKY_WRITE       | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY

+                                          EFI_FVB2_MEMORY_MAPPED      | // It is memory mapped

+                                          EFI_FVB2_ERASE_POLARITY     | // After erasure all bits take this value (i.e. '1')

+                                          EFI_FVB2_WRITE_STATUS       | // Writes are currently enabled

+                                          EFI_FVB2_WRITE_ENABLED_CAP    // Writes may be enabled

+                                      );

+  FirmwareVolumeHeader->HeaderLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY);

+  FirmwareVolumeHeader->Revision = EFI_FVH_REVISION;

+  FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1;

+  FirmwareVolumeHeader->BlockMap[0].Length      = Instance->Media.BlockSize;

+  FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;

+  FirmwareVolumeHeader->BlockMap[1].Length      = 0;

+  FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ((UINT16*)FirmwareVolumeHeader,FirmwareVolumeHeader->HeaderLength);

+

+  //

+  // VARIABLE_STORE_HEADER

+  //

+  VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength);

+  CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid);

+  VariableStoreHeader->Size = PcdGet32(PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;

+  VariableStoreHeader->Format            = VARIABLE_STORE_FORMATTED;

+  VariableStoreHeader->State             = VARIABLE_STORE_HEALTHY;

+

+  // Install the combined super-header in the NorFlash

+  Status = FvbWrite (&Instance->FvbProtocol, 0, 0, &HeadersLength, Headers);

+

+  FreePool (Headers);

+  return Status;

+}

+

+/**

+  Check the integrity of firmware volume header.

+

+  @param[in] FwVolHeader - A pointer to a firmware volume header

+

+  @retval  EFI_SUCCESS   - The firmware volume is consistent

+  @retval  EFI_NOT_FOUND - The firmware volume has been corrupted.

+

+**/

+EFI_STATUS

+ValidateFvHeader (

+  IN  NOR_FLASH_INSTANCE *Instance

+  )

+{

+  UINT16                      Checksum;

+  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;

+  VARIABLE_STORE_HEADER       *VariableStoreHeader;

+  UINTN                       VariableStoreLength;

+  UINTN                       FvLength;

+

+  FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Instance->RegionBaseAddress;

+

+  FvLength = PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) +

+      PcdGet32(PcdFlashNvStorageFtwSpareSize);

+

+  //

+  // Verify the header revision, header signature, length

+  // Length of FvBlock cannot be 2**64-1

+  // HeaderLength cannot be an odd number

+  //

+  if (   (FwVolHeader->Revision  != EFI_FVH_REVISION)

+      || (FwVolHeader->Signature != EFI_FVH_SIGNATURE)

+      || (FwVolHeader->FvLength  != FvLength)

+      )

+  {

+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: No Firmware Volume header present\n"));

+    return EFI_NOT_FOUND;

+  }

+

+  // Check the Firmware Volume Guid

+  if( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) {

+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Firmware Volume Guid non-compatible\n"));

+    return EFI_NOT_FOUND;

+  }

+

+  // Verify the header checksum

+  Checksum = CalculateSum16((UINT16*)FwVolHeader, FwVolHeader->HeaderLength);

+  if (Checksum != 0) {

+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: FV checksum is invalid (Checksum:0x%X)\n",Checksum));

+    return EFI_NOT_FOUND;

+  }

+

+  VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)FwVolHeader + FwVolHeader->HeaderLength);

+

+  // Check the Variable Store Guid

+  if( CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) == FALSE ) {

+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Guid non-compatible\n"));

+    return EFI_NOT_FOUND;

+  }

+

+  VariableStoreLength = PcdGet32 (PcdFlashNvStorageVariableSize) - FwVolHeader->HeaderLength;

+  if (VariableStoreHeader->Size != VariableStoreLength) {

+    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Length does not match\n"));

+    return EFI_NOT_FOUND;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+ The GetAttributes() function retrieves the attributes and

+ current settings of the block.

+

+ @param This         Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+ @param Attributes   Pointer to EFI_FVB_ATTRIBUTES_2 in which the attributes and

+                     current settings are returned.

+                     Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_VOLUME_HEADER.

+

+ @retval EFI_SUCCESS The firmware volume attributes were returned.

+

+ **/

+EFI_STATUS

+EFIAPI

+FvbGetAttributes(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL    *This,

+  OUT       EFI_FVB_ATTRIBUTES_2                   *Attributes

+  )

+{

+  EFI_FVB_ATTRIBUTES_2  FlashFvbAttributes;

+  NOR_FLASH_INSTANCE *Instance;

+

+  Instance = INSTANCE_FROM_FVB_THIS(This);

+

+  FlashFvbAttributes = (EFI_FVB_ATTRIBUTES_2) (

+

+      EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled

+      EFI_FVB2_READ_STATUS      | // Reads are currently enabled

+      EFI_FVB2_STICKY_WRITE     | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY

+      EFI_FVB2_MEMORY_MAPPED    | // It is memory mapped

+      EFI_FVB2_ERASE_POLARITY     // After erasure all bits take this value (i.e. '1')

+

+      );

+

+  // Check if it is write protected

+  if (Instance->Media.ReadOnly != TRUE) {

+

+    FlashFvbAttributes = FlashFvbAttributes         |

+                         EFI_FVB2_WRITE_STATUS      | // Writes are currently enabled

+                         EFI_FVB2_WRITE_ENABLED_CAP;  // Writes may be enabled

+  }

+

+  *Attributes = FlashFvbAttributes;

+

+  DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes));

+

+  return EFI_SUCCESS;

+}

+

+/**

+ The SetAttributes() function sets configurable firmware volume attributes

+ and returns the new settings of the firmware volume.

+

+

+ @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+ @param Attributes               On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2

+                                 that contains the desired firmware volume settings.

+                                 On successful return, it contains the new settings of

+                                 the firmware volume.

+                                 Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_VOLUME_HEADER.

+

+ @retval EFI_SUCCESS             The firmware volume attributes were returned.

+

+ @retval EFI_INVALID_PARAMETER   The attributes requested are in conflict with the capabilities

+                                 as declared in the firmware volume header.

+

+ **/

+EFI_STATUS

+EFIAPI

+FvbSetAttributes(

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  IN OUT    EFI_FVB_ATTRIBUTES_2                 *Attributes

+  )

+{

+  DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n",*Attributes));

+  return EFI_UNSUPPORTED;

+}

+

+/**

+ The GetPhysicalAddress() function retrieves the base address of

+ a memory-mapped firmware volume. This function should be called

+ only for memory-mapped firmware volumes.

+

+ @param This               Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+ @param Address            Pointer to a caller-allocated

+                           EFI_PHYSICAL_ADDRESS that, on successful

+                           return from GetPhysicalAddress(), contains the

+                           base address of the firmware volume.

+

+ @retval EFI_SUCCESS       The firmware volume base address was returned.

+

+ @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.

+

+ **/

+EFI_STATUS

+EFIAPI

+FvbGetPhysicalAddress (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  OUT       EFI_PHYSICAL_ADDRESS                 *Address

+  )

+{

+  NOR_FLASH_INSTANCE *Instance;

+

+  Instance = INSTANCE_FROM_FVB_THIS(This);

+

+  DEBUG ((DEBUG_BLKIO, "FvbGetPhysicalAddress(BaseAddress=0x%08x)\n", Instance->RegionBaseAddress));

+

+  ASSERT(Address != NULL);

+

+  *Address = mFlashNvStorageVariableBase;

+  return EFI_SUCCESS;

+}

+

+/**

+ The GetBlockSize() function retrieves the size of the requested

+ block. It also returns the number of additional blocks with

+ the identical size. The GetBlockSize() function is used to

+ retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).

+

+

+ @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+ @param Lba                      Indicates the block for which to return the size.

+

+ @param BlockSize                Pointer to a caller-allocated UINTN in which

+                                 the size of the block is returned.

+

+ @param NumberOfBlocks           Pointer to a caller-allocated UINTN in

+                                 which the number of consecutive blocks,

+                                 starting with Lba, is returned. All

+                                 blocks in this range have a size of

+                                 BlockSize.

+

+

+ @retval EFI_SUCCESS             The firmware volume base address was returned.

+

+ @retval EFI_INVALID_PARAMETER   The requested LBA is out of range.

+

+ **/

+EFI_STATUS

+EFIAPI

+FvbGetBlockSize (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,

+  IN        EFI_LBA                              Lba,

+  OUT       UINTN                                *BlockSize,

+  OUT       UINTN                                *NumberOfBlocks

+  )

+{

+  EFI_STATUS Status;

+  NOR_FLASH_INSTANCE *Instance;

+

+  Instance = INSTANCE_FROM_FVB_THIS(This);

+

+  DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock));

+

+  if (Lba > Instance->Media.LastBlock) {

+    DEBUG ((EFI_D_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is beyond the last Lba (%ld).\n", Lba, Instance->Media.LastBlock));

+    Status = EFI_INVALID_PARAMETER;

+  } else {

+    // This is easy because in this platform each NorFlash device has equal sized blocks.

+    *BlockSize = (UINTN) Instance->Media.BlockSize;

+    *NumberOfBlocks = (UINTN) (Instance->Media.LastBlock - Lba + 1);

+

+    DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, *NumberOfBlocks));

+

+    Status = EFI_SUCCESS;

+  }

+

+  return Status;

+}

+

+/**

+ Reads the specified number of bytes into a buffer from the specified block.

+

+ The Read() function reads the requested number of bytes from the

+ requested block and stores them in the provided buffer.

+ Implementations should be mindful that the firmware volume

+ might be in the ReadDisabled state. If it is in this state,

+ the Read() function must return the status code

+ EFI_ACCESS_DENIED without modifying the contents of the

+ buffer. The Read() function must also prevent spanning block

+ boundaries. If a read is requested that would span a block

+ boundary, the read must read up to the boundary but not

+ beyond. The output parameter NumBytes must be set to correctly

+ indicate the number of bytes actually read. The caller must be

+ aware that a read may be partially completed.

+

+ @param This                 Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+ @param Lba                  The starting logical block index from which to read.

+

+ @param Offset               Offset into the block at which to begin reading.

+

+ @param NumBytes             Pointer to a UINTN.

+                             At entry, *NumBytes contains the total size of the buffer.

+                             At exit, *NumBytes contains the total number of bytes read.

+

+ @param Buffer               Pointer to a caller-allocated buffer that will be used

+                             to hold the data that is read.

+

+ @retval EFI_SUCCESS         The firmware volume was read successfully,  and contents are

+                             in Buffer.

+

+ @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary.

+                             On output, NumBytes contains the total number of bytes

+                             returned in Buffer.

+

+ @retval EFI_ACCESS_DENIED   The firmware volume is in the ReadDisabled state.

+

+ @retval EFI_DEVICE_ERROR    The block device is not functioning correctly and could not be read.

+

+ **/

+EFI_STATUS

+EFIAPI

+FvbRead (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL   *This,

+  IN        EFI_LBA                               Lba,

+  IN        UINTN                                 Offset,

+  IN OUT    UINTN                                 *NumBytes,

+  IN OUT    UINT8                                 *Buffer

+  )

+{

+  EFI_STATUS    TempStatus;

+  UINTN         BlockSize;

+  NOR_FLASH_INSTANCE *Instance;

+

+  Instance = INSTANCE_FROM_FVB_THIS(This);

+

+  DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));

+

+  if (!Instance->Initialized && Instance->Initialize) {

+    Instance->Initialize(Instance);

+  }

+

+  TempStatus = EFI_SUCCESS;

+

+  // Cache the block size to avoid de-referencing pointers all the time

+  BlockSize = Instance->Media.BlockSize;

+

+  DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));

+

+  // The read must not span block boundaries.

+  // We need to check each variable individually because adding two large values together overflows.

+  if ((Offset               >= BlockSize) ||

+      (*NumBytes            >  BlockSize) ||

+      ((Offset + *NumBytes) >  BlockSize)) {

+    DEBUG ((EFI_D_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // We must have some bytes to read

+  if (*NumBytes == 0) {

+    return EFI_BAD_BUFFER_SIZE;

+  }

+

+  // Decide if we are doing full block reads or not.

+  if (*NumBytes % BlockSize != 0) {

+    TempStatus = NorFlashRead (Instance, Instance->StartLba + Lba, Offset, *NumBytes, Buffer);

+    if (EFI_ERROR (TempStatus)) {

+      return EFI_DEVICE_ERROR;

+    }

+  } else {

+    // Read NOR Flash data into shadow buffer

+    TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, Buffer);

+    if (EFI_ERROR (TempStatus)) {

+      // Return one of the pre-approved error statuses

+      return EFI_DEVICE_ERROR;

+    }

+  }

+  return EFI_SUCCESS;

+}

+

+/**

+ Writes the specified number of bytes from the input buffer to the block.

+

+ The Write() function writes the specified number of bytes from

+ the provided buffer to the specified block and offset. If the

+ firmware volume is sticky write, the caller must ensure that

+ all the bits of the specified range to write are in the

+ EFI_FVB_ERASE_POLARITY state before calling the Write()

+ function, or else the result will be unpredictable. This

+ unpredictability arises because, for a sticky-write firmware

+ volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY

+ state but cannot flip it back again.  Before calling the

+ Write() function,  it is recommended for the caller to first call

+ the EraseBlocks() function to erase the specified block to

+ write. A block erase cycle will transition bits from the

+ (NOT)EFI_FVB_ERASE_POLARITY state back to the

+ EFI_FVB_ERASE_POLARITY state. Implementations should be

+ mindful that the firmware volume might be in the WriteDisabled

+ state. If it is in this state, the Write() function must

+ return the status code EFI_ACCESS_DENIED without modifying the

+ contents of the firmware volume. The Write() function must

+ also prevent spanning block boundaries. If a write is

+ requested that spans a block boundary, the write must store up

+ to the boundary but not beyond. The output parameter NumBytes

+ must be set to correctly indicate the number of bytes actually

+ written. The caller must be aware that a write may be

+ partially completed. All writes, partial or otherwise, must be

+ fully flushed to the hardware before the Write() service

+ returns.

+

+ @param This                 Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.

+

+ @param Lba                  The starting logical block index to write to.

+

+ @param Offset               Offset into the block at which to begin writing.

+

+ @param NumBytes             The pointer to a UINTN.

+                             At entry, *NumBytes contains the total size of the buffer.

+                             At exit, *NumBytes contains the total number of bytes actually written.

+

+ @param Buffer               The pointer to a caller-allocated buffer that contains the source for the write.

+

+ @retval EFI_SUCCESS         The firmware volume was written successfully.

+

+ @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.

+                             On output, NumBytes contains the total number of bytes

+                             actually written.

+

+ @retval EFI_ACCESS_DENIED   The firmware volume is in the WriteDisabled state.

+

+ @retval EFI_DEVICE_ERROR    The block device is malfunctioning and could not be written.

+

+

+ **/

+EFI_STATUS

+EFIAPI

+FvbWrite (

+  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL   *This,

+  IN        EFI_LBA                               Lba,

+  IN        UINTN                                 Offset,

+  IN OUT    UINTN                                 *NumBytes,

+  IN        UINT8                                 *Buffer

+  )

+{

+  NOR_FLASH_INSTANCE *Instance;

+

+  Instance = INSTANCE_FROM_FVB_THIS (This);

+

+  return NorFlashWriteSingleBlock (Instance, Instance->StartLba + Lba, Offset, NumBytes, Buffer);

+}

+

+/**

+ Erases and initialises a firmware volume block.

+

+ The EraseBlocks() function erases one or more blocks as denoted

+ by the variable argument list. The entire parameter list of

+ blocks must be verified before erasing any blocks. If a block is

+ requested that does not exist within the associated firmware

+ volume (it has a larger index than the last block of the

+ firmware volume), the EraseBlocks() function must return the

+ status code EFI_INVALID_PARAMETER without modifying the contents

+ of the firmware volume. Implementations should be mindful that

+ the firmware volume might be in the WriteDisabled state. If it

+ is in this state, the EraseBlocks() function must return the

+ status code EFI_ACCESS_DENIED without modifying the contents of

+ the firmware volume. All calls to EraseBlocks() must be fully

+ flushed to the hardware before the EraseBlocks() service

+ returns.

+

+ @param This                     Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL

+ instance.

+

+ @param ...                      The variable argument list is a list of tuples.

+                                 Each tuple describes a range of LBAs to erase

+                                 and consists of the following:

+                                 - An EFI_LBA that indicates the starting LBA

+                                 - A UINTN that indicates the number of blocks to erase.

+

+                                 The list is terminated with an EFI_LBA_LIST_TERMINATOR.

+                                 For example, the following indicates that two ranges of blocks

+                                 (5-7 and 10-11) are to be erased:

+                                 EraseBlocks (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);

+

+ @retval EFI_SUCCESS             The erase request successfully completed.

+

+ @retval EFI_ACCESS_DENIED       The firmware volume is in the WriteDisabled state.

+

+ @retval EFI_DEVICE_ERROR        The block device is not functioning correctly and could not be written.

+                                 The firmware device may have been partially erased.

+

+ @retval EFI_INVALID_PARAMETER   One or more of the LBAs listed in the variable argument list do

+                                 not exist in the firmware volume.

+

+ **/

+EFI_STATUS

+EFIAPI

+FvbEraseBlocks (

+  IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,

+  ...

+  )

+{

+  EFI_STATUS  Status;

+  VA_LIST     Args;

+  UINTN       BlockAddress; // Physical address of Lba to erase

+  EFI_LBA     StartingLba; // Lba from which we start erasing

+  UINTN       NumOfLba; // Number of Lba blocks to erase

+  NOR_FLASH_INSTANCE *Instance;

+

+  Instance = INSTANCE_FROM_FVB_THIS(This);

+

+  DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks()\n"));

+

+  Status = EFI_SUCCESS;

+

+  // Detect WriteDisabled state

+  if (Instance->Media.ReadOnly == TRUE) {

+    // Firmware volume is in WriteDisabled state

+    DEBUG ((EFI_D_ERROR, "FvbEraseBlocks: ERROR - Device is in WriteDisabled state.\n"));

+    return EFI_ACCESS_DENIED;

+  }

+

+  // Before erasing, check the entire list of parameters to ensure all specified blocks are valid

+

+  VA_START (Args, This);

+  do {

+    // Get the Lba from which we start erasing

+    StartingLba = VA_ARG (Args, EFI_LBA);

+

+    // Have we reached the end of the list?

+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {

+      //Exit the while loop

+      break;

+    }

+

+    // How many Lba blocks are we requested to erase?

+    NumOfLba = VA_ARG (Args, UINT32);

+

+    // All blocks must be within range

+    DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Check if: ( StartingLba=%ld + NumOfLba=%d - 1 ) > LastBlock=%ld.\n", Instance->StartLba + StartingLba, NumOfLba, Instance->Media.LastBlock));

+    if ((NumOfLba == 0) || ((Instance->StartLba + StartingLba + NumOfLba - 1) > Instance->Media.LastBlock)) {

+      VA_END (Args);

+      DEBUG ((EFI_D_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past the last Lba.\n"));

+      Status = EFI_INVALID_PARAMETER;

+      goto EXIT;

+    }

+  } while (TRUE);

+  VA_END (Args);

+

+  //

+  // To get here, all must be ok, so start erasing

+  //

+  VA_START (Args, This);

+  do {

+    // Get the Lba from which we start erasing

+    StartingLba = VA_ARG (Args, EFI_LBA);

+

+    // Have we reached the end of the list?

+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {

+      // Exit the while loop

+      break;

+    }

+

+    // How many Lba blocks are we requested to erase?

+    NumOfLba = VA_ARG (Args, UINT32);

+

+    // Go through each one and erase it

+    while (NumOfLba > 0) {

+

+      // Get the physical address of Lba to erase

+      BlockAddress = GET_NOR_BLOCK_ADDRESS (

+          Instance->RegionBaseAddress,

+          Instance->StartLba + StartingLba,

+          Instance->Media.BlockSize

+      );

+

+      // Erase it

+      DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=%ld @ 0x%08x.\n", Instance->StartLba + StartingLba, BlockAddress));

+      Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);

+      if (EFI_ERROR(Status)) {

+        VA_END (Args);

+        Status = EFI_DEVICE_ERROR;

+        goto EXIT;

+      }

+

+      // Move to the next Lba

+      StartingLba++;

+      NumOfLba--;

+    }

+  } while (TRUE);

+  VA_END (Args);

+

+EXIT:

+  return Status;

+}

+

+/**

+  Fixup internal data so that EFI can be call in virtual mode.

+  Call the passed in Child Notify event and convert any pointers in

+  lib to virtual mode.

+

+  @param[in]    Event   The Event that is being processed

+  @param[in]    Context Event Context

+**/

+VOID

+EFIAPI

+FvbVirtualNotifyEvent (

+  IN EFI_EVENT        Event,

+  IN VOID             *Context

+  )

+{

+  EfiConvertPointer (0x0, (VOID**)&mFlashNvStorageVariableBase);

+  return;

+}

+

+EFI_STATUS

+EFIAPI

+NorFlashFvbInitialize (

+  IN NOR_FLASH_INSTANCE* Instance

+  )

+{

+  EFI_STATUS  Status;

+  UINT32      FvbNumLba;

+  EFI_BOOT_MODE BootMode;

+  UINTN       RuntimeMmioRegionSize;

+

+  DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));

+

+  Instance->Initialized = TRUE;

+  mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase);

+

+  // Set the index of the first LBA for the FVB

+  Instance->StartLba = (PcdGet32 (PcdFlashNvStorageVariableBase) - Instance->RegionBaseAddress) / Instance->Media.BlockSize;

+

+  BootMode = GetBootModeHob ();

+  if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {

+    Status = EFI_INVALID_PARAMETER;

+  } else {

+    // Determine if there is a valid header at the beginning of the NorFlash

+    Status = ValidateFvHeader (Instance);

+  }

+

+  // Install the Default FVB header if required

+  if (EFI_ERROR(Status)) {

+    // There is no valid header, so time to install one.

+    DEBUG((EFI_D_ERROR,"NorFlashFvbInitialize: ERROR - The FVB Header is not valid. Installing a correct one for this volume.\n"));

+

+    // Erase all the NorFlash that is reserved for variable storage

+    FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;

+

+    Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);

+    if (EFI_ERROR(Status)) {

+      return Status;

+    }

+

+    // Install all appropriate headers

+    Status = InitializeFvAndVariableStoreHeaders (Instance);

+    if (EFI_ERROR(Status)) {

+      return Status;

+    }

+  }

+

+  //

+  // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME

+  //

+

+  // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory;

+  //       even if we only use the small block region at the top of the NOR Flash.

+  //       The reason is when the NOR Flash memory is set into program mode, the command

+  //       is written as the base of the flash region (ie: Instance->DeviceBaseAddress)

+  RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;

+

+  Status = gDS->AddMemorySpace (

+      EfiGcdMemoryTypeMemoryMappedIo,

+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,

+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME

+      );

+  ASSERT_EFI_ERROR (Status);

+

+  Status = gDS->SetMemorySpaceAttributes (

+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,

+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);

+  ASSERT_EFI_ERROR (Status);

+

+  //

+  // Register for the virtual address change event

+  //

+  Status = gBS->CreateEventEx (

+                  EVT_NOTIFY_SIGNAL,

+                  TPL_NOTIFY,

+                  FvbVirtualNotifyEvent,

+                  NULL,

+                  &gEfiEventVirtualAddressChangeGuid,

+                  &mFvbVirtualAddrChangeEvent

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.c
new file mode 100644
index 0000000..8b256de
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.c
@@ -0,0 +1,403 @@
+/** @file

+  Serial I/O Port library functions with no library constructor/destructor

+

+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+

+  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 <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+

+#include <Drivers/PL011Uart.h>

+

+//

+// EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE is the only

+// control bit that is not supported.

+//

+STATIC CONST UINT32 mInvalidControlBits = EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE;

+

+/*

+

+  Initialise the serial port to the specified settings.

+  All unspecified settings will be set to the default values.

+

+  @return    Always return EFI_SUCCESS or EFI_INVALID_PARAMETER.

+

+**/

+RETURN_STATUS

+EFIAPI

+PL011UartInitializePort (

+  IN OUT UINTN               UartBase,

+  IN OUT UINT64              *BaudRate,

+  IN OUT UINT32              *ReceiveFifoDepth,

+  IN OUT EFI_PARITY_TYPE     *Parity,

+  IN OUT UINT8               *DataBits,

+  IN OUT EFI_STOP_BITS_TYPE  *StopBits

+  )

+{

+  UINT32      LineControl;

+  UINT32      Divisor;

+

+  LineControl = 0;

+

+  // The PL011 supports a buffer of 1, 16 or 32 chars. Therefore we can accept

+  // 1 char buffer as the minimum fifo size. Because everything can be rounded down,

+  // there is no maximum fifo size.

+  if ((*ReceiveFifoDepth == 0) || (*ReceiveFifoDepth >= 32)) {

+    LineControl |= PL011_UARTLCR_H_FEN;

+    if (PL011_UARTPID2_VER (MmioRead32 (UartBase + UARTPID2)) > PL011_VER_R1P4)

+      *ReceiveFifoDepth = 32;

+    else

+      *ReceiveFifoDepth = 16;

+  } else {

+    ASSERT (*ReceiveFifoDepth < 32);

+    // Nothing else to do. 1 byte fifo is default.

+    *ReceiveFifoDepth = 1;

+  }

+

+  //

+  // Parity

+  //

+  switch (*Parity) {

+  case DefaultParity:

+    *Parity = NoParity;

+  case NoParity:

+    // Nothing to do. Parity is disabled by default.

+    break;

+  case EvenParity:

+    LineControl |= (PL011_UARTLCR_H_PEN | PL011_UARTLCR_H_EPS);

+    break;

+  case OddParity:

+    LineControl |= PL011_UARTLCR_H_PEN;

+    break;

+  case MarkParity:

+    LineControl |= (PL011_UARTLCR_H_PEN | PL011_UARTLCR_H_SPS | PL011_UARTLCR_H_EPS);

+    break;

+  case SpaceParity:

+    LineControl |= (PL011_UARTLCR_H_PEN | PL011_UARTLCR_H_SPS);

+    break;

+  default:

+    return RETURN_INVALID_PARAMETER;

+  }

+

+  //

+  // Data Bits

+  //

+  switch (*DataBits) {

+  case 0:

+    *DataBits = 8;

+  case 8:

+    LineControl |= PL011_UARTLCR_H_WLEN_8;

+    break;

+  case 7:

+    LineControl |= PL011_UARTLCR_H_WLEN_7;

+    break;

+  case 6:

+    LineControl |= PL011_UARTLCR_H_WLEN_6;

+    break;

+  case 5:

+    LineControl |= PL011_UARTLCR_H_WLEN_5;

+    break;

+  default:

+    return RETURN_INVALID_PARAMETER;

+  }

+

+  //

+  // Stop Bits

+  //

+  switch (*StopBits) {

+  case DefaultStopBits:

+    *StopBits = OneStopBit;

+  case OneStopBit:

+    // Nothing to do. One stop bit is enabled by default.

+    break;

+  case TwoStopBits:

+    LineControl |= PL011_UARTLCR_H_STP2;

+    break;

+  case OneFiveStopBits:

+    // Only 1 or 2 stops bits are supported

+  default:

+    return RETURN_INVALID_PARAMETER;

+  }

+

+  // Don't send the LineControl value to the PL011 yet,

+  // wait until after the Baud Rate setting.

+  // This ensures we do not mess up the UART settings halfway through

+  // in the rare case when there is an error with the Baud Rate.

+

+  //

+  // Baud Rate

+  //

+

+  // If PL011 Integral value has been defined then always ignore the BAUD rate

+  if (PcdGet32 (PL011UartInteger) != 0) {

+      MmioWrite32 (UartBase + UARTIBRD, PcdGet32 (PL011UartInteger));

+      MmioWrite32 (UartBase + UARTFBRD, PcdGet32 (PL011UartFractional));

+  } else {

+    // If BAUD rate is zero then replace it with the system default value

+    if (*BaudRate == 0) {

+      *BaudRate = PcdGet32 (PcdSerialBaudRate);

+      ASSERT (*BaudRate != 0);

+    }

+

+    Divisor = (PcdGet32 (PL011UartClkInHz) * 4) / *BaudRate;

+    MmioWrite32 (UartBase + UARTIBRD, Divisor >> 6);

+    MmioWrite32 (UartBase + UARTFBRD, Divisor & 0x3F);

+  }

+

+  // No parity, 1 stop, no fifo, 8 data bits

+  MmioWrite32 (UartBase + UARTLCR_H, LineControl);

+

+  // Clear any pending errors

+  MmioWrite32 (UartBase + UARTECR, 0);

+

+  // Enable tx, rx, and uart overall

+  MmioWrite32 (UartBase + UARTCR, PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN);

+

+  return RETURN_SUCCESS;

+}

+

+/**

+

+  Assert or deassert the control signals on a serial port.

+  The following control signals are set according their bit settings :

+  . Request to Send

+  . Data Terminal Ready

+

+  @param[in]  UartBase  UART registers base address

+  @param[in]  Control   The following bits are taken into account :

+                        . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the

+                          "Request To Send" control signal if this bit is

+                          equal to one/zero.

+                        . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert

+                          the "Data Terminal Ready" control signal if this

+                          bit is equal to one/zero.

+                        . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable

+                          the hardware loopback if this bit is equal to

+                          one/zero.

+                        . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.

+                        . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/

+                          disable the hardware flow control based on CTS (Clear

+                          To Send) and RTS (Ready To Send) control signals.

+

+  @retval  RETURN_SUCCESS      The new control bits were set on the serial device.

+  @retval  RETURN_UNSUPPORTED  The serial device does not support this operation.

+

+**/

+RETURN_STATUS

+EFIAPI

+PL011UartSetControl (

+    IN UINTN   UartBase,

+    IN UINT32  Control

+  )

+{

+  UINT32  Bits;

+

+  if (Control & (mInvalidControlBits)) {

+    return RETURN_UNSUPPORTED;

+  }

+

+  Bits = MmioRead32 (UartBase + UARTCR);

+

+  if (Control & EFI_SERIAL_REQUEST_TO_SEND) {

+    Bits |= PL011_UARTCR_RTS;

+  } else {

+    Bits &= ~PL011_UARTCR_RTS;

+  }

+

+  if (Control & EFI_SERIAL_DATA_TERMINAL_READY) {

+    Bits |= PL011_UARTCR_DTR;

+  } else {

+    Bits &= ~PL011_UARTCR_DTR;

+  }

+

+  if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) {

+    Bits |= PL011_UARTCR_LBE;

+  } else {

+    Bits &= ~PL011_UARTCR_LBE;

+  }

+

+  if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) {

+    Bits |= (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN);

+  } else {

+    Bits &= ~(PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN);

+  }

+

+  MmioWrite32 (UartBase + UARTCR, Bits);

+

+  return RETURN_SUCCESS;

+}

+

+/**

+

+  Retrieve the status of the control bits on a serial device.

+

+  @param[in]   UartBase  UART registers base address

+  @param[out]  Control   Status of the control bits on a serial device :

+

+                         . EFI_SERIAL_DATA_CLEAR_TO_SEND, EFI_SERIAL_DATA_SET_READY,

+                           EFI_SERIAL_RING_INDICATE, EFI_SERIAL_CARRIER_DETECT,

+                           EFI_SERIAL_REQUEST_TO_SEND, EFI_SERIAL_DATA_TERMINAL_READY

+                           are all related to the DTE (Data Terminal Equipment) and

+                           DCE (Data Communication Equipment) modes of operation of

+                           the serial device.

+                         . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the receive

+                           buffer is empty, 0 otherwise.

+                         . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the transmit

+                           buffer is empty, 0 otherwise.

+                         . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if the

+                           hardware loopback is enabled (the ouput feeds the receive

+                           buffer), 0 otherwise.

+                         . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if a

+                           loopback is accomplished by software, 0 otherwise.

+                         . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to one if the

+                           hardware flow control based on CTS (Clear To Send) and RTS

+                           (Ready To Send) control signals is enabled, 0 otherwise.

+

+  @retval RETURN_SUCCESS  The control bits were read from the serial device.

+

+**/

+RETURN_STATUS

+EFIAPI

+PL011UartGetControl (

+    IN UINTN     UartBase,

+    OUT UINT32  *Control

+  )

+{

+  UINT32      FlagRegister;

+  UINT32      ControlRegister;

+

+

+  FlagRegister = MmioRead32 (UartBase + UARTFR);

+  ControlRegister = MmioRead32 (UartBase + UARTCR);

+

+  *Control = 0;

+

+  if ((FlagRegister & PL011_UARTFR_CTS) == PL011_UARTFR_CTS) {

+    *Control |= EFI_SERIAL_CLEAR_TO_SEND;

+  }

+

+  if ((FlagRegister & PL011_UARTFR_DSR) == PL011_UARTFR_DSR) {

+    *Control |= EFI_SERIAL_DATA_SET_READY;

+  }

+

+  if ((FlagRegister & PL011_UARTFR_RI) == PL011_UARTFR_RI) {

+    *Control |= EFI_SERIAL_RING_INDICATE;

+  }

+

+  if ((FlagRegister & PL011_UARTFR_DCD) == PL011_UARTFR_DCD) {

+    *Control |= EFI_SERIAL_CARRIER_DETECT;

+  }

+

+  if ((ControlRegister & PL011_UARTCR_RTS) == PL011_UARTCR_RTS) {

+    *Control |= EFI_SERIAL_REQUEST_TO_SEND;

+  }

+

+  if ((ControlRegister & PL011_UARTCR_DTR) == PL011_UARTCR_DTR) {

+    *Control |= EFI_SERIAL_DATA_TERMINAL_READY;

+  }

+

+  if ((FlagRegister & PL011_UARTFR_RXFE) == PL011_UARTFR_RXFE) {

+    *Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;

+  }

+

+  if ((FlagRegister & PL011_UARTFR_TXFE) == PL011_UARTFR_TXFE) {

+    *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;

+  }

+

+  if ((ControlRegister & (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN))

+       == (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN)) {

+    *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;

+  }

+

+  if ((ControlRegister & PL011_UARTCR_LBE) == PL011_UARTCR_LBE) {

+    *Control |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;

+  }

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Write data to serial device.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Write data failed.

+  @retval !0               Actual number of bytes written to serial device.

+

+**/

+UINTN

+EFIAPI

+PL011UartWrite (

+  IN  UINTN    UartBase,

+  IN UINT8     *Buffer,

+  IN UINTN     NumberOfBytes

+  )

+{

+  UINT8* CONST Final = &Buffer[NumberOfBytes];

+

+  while (Buffer < Final) {

+    // Wait until UART able to accept another char

+    while ((MmioRead32 (UartBase + UARTFR) & UART_TX_FULL_FLAG_MASK));

+

+    MmioWrite8 (UartBase + UARTDR, *Buffer++);

+  }

+

+  return NumberOfBytes;

+}

+

+/**

+  Read data from serial device and save the data in buffer.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Read data failed.

+  @retval !0               Actual number of bytes read from serial device.

+

+**/

+UINTN

+EFIAPI

+PL011UartRead (

+  IN  UINTN     UartBase,

+  OUT UINT8     *Buffer,

+  IN  UINTN     NumberOfBytes

+  )

+{

+  UINTN   Count;

+

+  for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {

+    while ((MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) != 0);

+    *Buffer = MmioRead8 (UartBase + UARTDR);

+  }

+

+  return NumberOfBytes;

+}

+

+/**

+  Check to see if any data is available to be read from the debug device.

+

+  @retval EFI_SUCCESS       At least one byte of data is available to be read

+  @retval EFI_NOT_READY     No data is available to be read

+  @retval EFI_DEVICE_ERROR  The serial device is not functioning properly

+

+**/

+BOOLEAN

+EFIAPI

+PL011UartPoll (

+  IN  UINTN     UartBase

+  )

+{

+  return ((MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) == 0);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf
new file mode 100644
index 0000000..18df7c9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf
@@ -0,0 +1,42 @@
+#/** @file

+#

+#  Component description file for PL011Uart module

+#

+#  Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PL011Uart

+  FILE_GUID                      = 4ec8b120-8307-11e0-bc91-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PL011UartLib

+

+[Sources.common]

+  PL011Uart.c

+

+[LibraryClasses]

+  DebugLib

+  IoLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[Pcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate

+

+  gArmPlatformTokenSpaceGuid.PL011UartClkInHz

+  gArmPlatformTokenSpaceGuid.PL011UartInteger

+  gArmPlatformTokenSpaceGuid.PL011UartFractional

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
new file mode 100644
index 0000000..02da8e1
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
@@ -0,0 +1,409 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+

+#include <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PcdLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+

+#include <Protocol/EmbeddedGpio.h>

+#include <Drivers/PL061Gpio.h>

+

+BOOLEAN     mPL061Initialized = FALSE;

+PLATFORM_GPIO_CONTROLLER *mPL061PlatformGpio;

+

+/**

+  Function implementations

+**/

+

+EFI_STATUS

+PL061Identify (

+  VOID

+  )

+{

+  UINTN    Index;

+  UINTN    RegisterBase;

+

+  if (   (mPL061PlatformGpio->GpioCount == 0)

+      || (mPL061PlatformGpio->GpioControllerCount == 0)) {

+     return EFI_NOT_FOUND;

+  }

+

+  for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {

+    if (mPL061PlatformGpio->GpioController[Index].InternalGpioCount != PL061_GPIO_PINS) {

+      return EFI_INVALID_PARAMETER;

+    }

+

+    RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;

+

+    // Check if this is a PrimeCell Peripheral

+    if (    (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D)

+        ||  (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0)

+        ||  (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05)

+        ||  (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1)) {

+      return EFI_NOT_FOUND;

+    }

+   

+    // Check if this PrimeCell Peripheral is the PL061 GPIO

+    if (    (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61)

+        ||  (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10)

+        ||  ((MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)

+        ||  (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00)) {

+      return EFI_NOT_FOUND;

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+PL061Initialize (

+  VOID

+  )

+{

+  EFI_STATUS  Status;

+

+  // Check if the PL061 GPIO module exists on board

+  Status = PL061Identify();

+  if (EFI_ERROR (Status)) {

+    Status = EFI_DEVICE_ERROR;

+    goto EXIT;

+  }

+

+  // Do other hardware initialisation things here as required

+

+  // Disable Interrupts

+  //if (MmioRead8 (PL061_GPIO_IE_REG) != 0) {

+  //   // Ensure interrupts are disabled

+  //}

+

+  mPL061Initialized = TRUE;

+

+  EXIT:

+  return Status;

+}

+

+EFI_STATUS

+EFIAPI

+PL061Locate (

+  IN  EMBEDDED_GPIO_PIN Gpio,

+  OUT UINTN             *ControllerIndex,

+  OUT UINTN             *ControllerOffset,

+  OUT UINTN             *RegisterBase

+  )

+{

+  UINT32    Index;

+

+  for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {

+    if (    (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex)

+        &&  (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex

+             + mPL061PlatformGpio->GpioController[Index].InternalGpioCount)) {

+      *ControllerIndex = Index;

+      *ControllerOffset = Gpio % mPL061PlatformGpio->GpioController[Index].InternalGpioCount;

+      *RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;

+      return EFI_SUCCESS;

+    }

+  }

+  DEBUG ((EFI_D_ERROR, "%a, failed to locate gpio %d\n", __func__, Gpio));

+  return EFI_INVALID_PARAMETER;

+}

+

+/**

+

+Routine Description:

+

+  Gets the state of a GPIO pin

+

+Arguments:

+

+  This  - pointer to protocol

+  Gpio  - which pin to read

+  Value - state of the pin

+

+Returns:

+

+  EFI_SUCCESS           - GPIO state returned in Value

+  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range

+**/

+EFI_STATUS

+EFIAPI

+Get (

+  IN  EMBEDDED_GPIO     *This,

+  IN  EMBEDDED_GPIO_PIN Gpio,

+  OUT UINTN             *Value

+  )

+{

+  EFI_STATUS    Status = EFI_SUCCESS;

+  UINTN         Index, Offset, RegisterBase;

+

+  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);

+  if (EFI_ERROR (Status))

+    goto EXIT;

+

+  if (Value == NULL) {

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+  }

+

+  // Initialize the hardware if not already done

+  if (!mPL061Initialized) {

+    Status = PL061Initialize();

+    if (EFI_ERROR(Status)) {

+      goto EXIT;

+    }

+  }

+

+  if (MmioRead8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2))) {

+    *Value = 1;

+  } else {

+    *Value = 0;

+  }

+

+  EXIT:

+  return Status;

+}

+

+/**

+

+Routine Description:

+

+  Sets the state of a GPIO pin

+

+Arguments:

+

+  This  - pointer to protocol

+  Gpio  - which pin to modify

+  Mode  - mode to set

+

+Returns:

+

+  EFI_SUCCESS           - GPIO set as requested

+  EFI_UNSUPPORTED       - Mode is not supported

+  EFI_INVALID_PARAMETER - Gpio pin is out of range

+**/

+EFI_STATUS

+EFIAPI

+Set (

+  IN  EMBEDDED_GPIO       *This,

+  IN  EMBEDDED_GPIO_PIN   Gpio,

+  IN  EMBEDDED_GPIO_MODE  Mode

+  )

+{

+  EFI_STATUS    Status = EFI_SUCCESS;

+  UINTN         Index, Offset, RegisterBase;

+

+  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);

+  if (EFI_ERROR (Status))

+    goto EXIT;

+

+  // Initialize the hardware if not already done

+  if (!mPL061Initialized) {

+    Status = PL061Initialize();

+    if (EFI_ERROR(Status)) {

+      goto EXIT;

+    }

+  }

+

+  switch (Mode)

+  {

+    case GPIO_MODE_INPUT:

+      // Set the corresponding direction bit to LOW for input

+      MmioAnd8 (RegisterBase + PL061_GPIO_DIR_REG, ~GPIO_PIN_MASK(Gpio));

+      break;

+

+    case GPIO_MODE_OUTPUT_0:

+      // Set the corresponding data bit to LOW for 0

+      MmioWrite8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2), 0);

+      // Set the corresponding direction bit to HIGH for output

+      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));

+      break;

+

+    case GPIO_MODE_OUTPUT_1:

+      // Set the corresponding data bit to HIGH for 1

+      MmioWrite8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2), 0xff);

+      // Set the corresponding direction bit to HIGH for output

+      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));

+      break;

+

+    default:

+      // Other modes are not supported

+      return EFI_UNSUPPORTED;

+  }

+

+EXIT:

+  return Status;

+}

+

+/**

+

+Routine Description:

+

+  Gets the mode (function) of a GPIO pin

+

+Arguments:

+

+  This  - pointer to protocol

+  Gpio  - which pin

+  Mode  - pointer to output mode value

+

+Returns:

+

+  EFI_SUCCESS           - mode value retrieved

+  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range

+

+**/

+EFI_STATUS

+EFIAPI

+GetMode (

+  IN  EMBEDDED_GPIO       *This,

+  IN  EMBEDDED_GPIO_PIN   Gpio,

+  OUT EMBEDDED_GPIO_MODE  *Mode

+  )

+{

+  EFI_STATUS    Status;

+  UINTN         Index, Offset, RegisterBase;

+

+  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);

+  if (EFI_ERROR (Status))

+    return Status;

+

+  // Initialize the hardware if not already done

+  if (!mPL061Initialized) {

+    Status = PL061Initialize();

+    if (EFI_ERROR(Status)) {

+      return Status;

+    }

+  }

+

+  // Check if it is input or output

+  if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK(Offset)) {

+    // Pin set to output

+    if (MmioRead8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2))) {

+      *Mode = GPIO_MODE_OUTPUT_1;

+    } else {

+      *Mode = GPIO_MODE_OUTPUT_0;

+    }

+  } else {

+    // Pin set to input

+    *Mode = GPIO_MODE_INPUT;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+

+Routine Description:

+

+  Sets the pull-up / pull-down resistor of a GPIO pin

+

+Arguments:

+

+  This  - pointer to protocol

+  Gpio  - which pin

+  Direction - pull-up, pull-down, or none

+

+Returns:

+

+  EFI_UNSUPPORTED - Can not perform the requested operation

+

+**/

+EFI_STATUS

+EFIAPI

+SetPull (

+  IN  EMBEDDED_GPIO       *This,

+  IN  EMBEDDED_GPIO_PIN   Gpio,

+  IN  EMBEDDED_GPIO_PULL  Direction

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+/**

+ Protocol variable definition

+ **/

+EMBEDDED_GPIO gGpio = {

+  Get,

+  Set,

+  GetMode,

+  SetPull

+};

+

+/**

+  Initialize the state information for the Embedded Gpio protocol.

+

+  @param  ImageHandle   of the loaded driver

+  @param  SystemTable   Pointer to the System Table

+

+  @retval EFI_SUCCESS           Protocol registered

+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure

+  @retval EFI_DEVICE_ERROR      Hardware problems

+

+**/

+EFI_STATUS

+EFIAPI

+PL061InstallProtocol (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS            Status;

+  EFI_HANDLE            Handle;

+  GPIO_CONTROLLER       *GpioController;

+

+  //

+  // Make sure the Gpio protocol has not been installed in the system yet.

+  //

+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEmbeddedGpioProtocolGuid);

+

+  Status = gBS->LocateProtocol (&gPlatformGpioProtocolGuid, NULL, (VOID **)&mPL061PlatformGpio);

+  if (EFI_ERROR (Status) && (Status == EFI_NOT_FOUND)) {

+    // Create the mPL061PlatformGpio

+    mPL061PlatformGpio = (PLATFORM_GPIO_CONTROLLER *)AllocateZeroPool (sizeof (PLATFORM_GPIO_CONTROLLER) + sizeof (GPIO_CONTROLLER));

+    if (mPL061PlatformGpio == NULL) {

+      DEBUG ((EFI_D_ERROR, "%a: failed to allocate PLATFORM_GPIO_CONTROLLER\n", __func__));

+      return EFI_BAD_BUFFER_SIZE;

+    }

+

+    mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS;

+    mPL061PlatformGpio->GpioControllerCount = 1;

+    mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN) mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER));

+

+    GpioController = mPL061PlatformGpio->GpioController;

+    GpioController->RegisterBase = (UINTN) PcdGet32 (PcdPL061GpioBase);

+    GpioController->GpioIndex = 0;

+    GpioController->InternalGpioCount = PL061_GPIO_PINS;

+  }

+

+  // Install the Embedded GPIO Protocol onto a new handle

+  Handle = NULL;

+  Status = gBS->InstallMultipleProtocolInterfaces(

+                  &Handle,

+                  &gEmbeddedGpioProtocolGuid, &gGpio,

+                  NULL

+                 );

+  if (EFI_ERROR(Status)) {

+    Status = EFI_OUT_OF_RESOURCES;

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf
new file mode 100644
index 0000000..405a3a9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf
@@ -0,0 +1,51 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PL061GpioDxe

+  FILE_GUID                      = 5c1997d7-8d45-4f21-af3c-2206b8ed8bec

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = PL061InstallProtocol

+[Sources.common]

+  PL061Gpio.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  BaseMemoryLib

+  DebugLib

+  IoLib

+  PcdLib

+  UefiBootServicesTableLib

+  UefiDriverEntryPoint

+  UefiLib

+  UefiRuntimeServicesTableLib

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdPL061GpioBase

+

+[Protocols]

+  gEmbeddedGpioProtocolGuid

+  gPlatformGpioProtocolGuid

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180Mci.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180Mci.c
new file mode 100644
index 0000000..411a61e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180Mci.c
@@ -0,0 +1,537 @@
+/** @file

+  This file implement the MMC Host Protocol for the ARM PrimeCell PL180.

+

+  Copyright (c) 2011-2012, ARM 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.

+

+**/

+

+#include "PL180Mci.h"

+

+#include <Library/DevicePathLib.h>

+#include <Library/BaseMemoryLib.h>

+

+EFI_MMC_HOST_PROTOCOL     *gpMmcHost;

+

+// Untested ...

+//#define USE_STREAM

+

+#define MMCI0_BLOCKLEN 512

+#define MMCI0_POW2_BLOCKLEN     9

+#define MMCI0_TIMEOUT           1000

+

+#define SYS_MCI_CARDIN          BIT0

+#define SYS_MCI_WPROT           BIT1

+

+BOOLEAN

+MciIsPowerOn (

+  VOID

+  )

+{

+  return ((MmioRead32 (MCI_POWER_CONTROL_REG) & MCI_POWER_ON) == MCI_POWER_ON);

+}

+

+EFI_STATUS

+MciInitialize (

+  VOID

+  )

+{

+  MCI_TRACE ("MciInitialize()");

+  return EFI_SUCCESS;

+}

+

+BOOLEAN

+MciIsCardPresent (

+  IN EFI_MMC_HOST_PROTOCOL     *This

+  )

+{

+  return (MmioRead32 (FixedPcdGet32 (PcdPL180SysMciRegAddress)) & SYS_MCI_CARDIN);

+}

+

+BOOLEAN

+MciIsReadOnly (

+  IN EFI_MMC_HOST_PROTOCOL     *This

+  )

+{

+  return (MmioRead32 (FixedPcdGet32 (PcdPL180SysMciRegAddress)) & SYS_MCI_WPROT);

+}

+

+#if 0

+//Note: This function has been commented out because it is not used yet.

+//      This function could be used to remove the hardcoded BlockLen used

+//      in MciPrepareDataPath

+

+// Convert block size to 2^n

+STATIC

+UINT32

+GetPow2BlockLen (

+  IN UINT32 BlockLen

+  )

+{

+  UINTN Loop;

+  UINTN Pow2BlockLen;

+

+  Loop    = 0x8000;

+  Pow2BlockLen = 15;

+  do {

+    Loop = (Loop >> 1) & 0xFFFF;

+    Pow2BlockLen--;

+  } while (Pow2BlockLen && (!(Loop & BlockLen)));

+

+  return Pow2BlockLen;

+}

+#endif

+

+VOID

+MciPrepareDataPath (

+  IN UINTN TransferDirection

+  )

+{

+  // Set Data Length & Data Timer

+  MmioWrite32 (MCI_DATA_TIMER_REG, 0xFFFFFFF);

+  MmioWrite32 (MCI_DATA_LENGTH_REG, MMCI0_BLOCKLEN);

+

+#ifndef USE_STREAM

+  //Note: we are using a hardcoded BlockLen (==512). If we decide to use a variable size, we could

+  // compute the pow2 of BlockLen with the above function GetPow2BlockLen ()

+  MmioWrite32 (MCI_DATA_CTL_REG, MCI_DATACTL_ENABLE | MCI_DATACTL_DMA_ENABLE | TransferDirection | (MMCI0_POW2_BLOCKLEN << 4));

+#else

+  MmioWrite32 (MCI_DATA_CTL_REG, MCI_DATACTL_ENABLE | MCI_DATACTL_DMA_ENABLE | TransferDirection | MCI_DATACTL_STREAM_TRANS);

+#endif

+}

+

+EFI_STATUS

+MciSendCommand (

+  IN EFI_MMC_HOST_PROTOCOL     *This,

+  IN MMC_CMD                    MmcCmd,

+  IN UINT32                     Argument

+  )

+{

+  UINT32  Status;

+  UINT32  Cmd;

+  UINTN   RetVal;

+  UINTN   CmdCtrlReg;

+  UINT32  DoneMask;

+

+  RetVal = EFI_SUCCESS;

+

+  if ((MmcCmd == MMC_CMD17) || (MmcCmd == MMC_CMD11)) {

+    MciPrepareDataPath (MCI_DATACTL_CARD_TO_CONT);

+  } else if ((MmcCmd == MMC_CMD24) || (MmcCmd == MMC_CMD20)) {

+    MciPrepareDataPath (MCI_DATACTL_CONT_TO_CARD);

+  }

+

+  // Create Command for PL180

+  Cmd = (MMC_GET_INDX (MmcCmd) & INDX_MASK)  | MCI_CPSM_ENABLE;

+  if (MmcCmd & MMC_CMD_WAIT_RESPONSE) {

+    Cmd |= MCI_CPSM_WAIT_RESPONSE;

+  }

+

+  if (MmcCmd & MMC_CMD_LONG_RESPONSE) {

+    Cmd |= MCI_CPSM_LONG_RESPONSE;

+  }

+

+  // Clear Status register static flags

+  MmioWrite32 (MCI_CLEAR_STATUS_REG, MCI_CLR_ALL_STATUS);

+

+  // Write to command argument register

+  MmioWrite32 (MCI_ARGUMENT_REG, Argument);

+

+  // Write to command register

+  MmioWrite32 (MCI_COMMAND_REG, Cmd);

+

+  DoneMask  = (Cmd & MCI_CPSM_WAIT_RESPONSE)

+                ? (MCI_STATUS_CMD_RESPEND | MCI_STATUS_CMD_ERROR)

+                : (MCI_STATUS_CMD_SENT    | MCI_STATUS_CMD_ERROR);

+  do {

+    Status = MmioRead32 (MCI_STATUS_REG);

+  } while (! (Status & DoneMask));

+

+  if ((Status & MCI_STATUS_CMD_ERROR)) {

+    // Clear Status register error flags

+    MmioWrite32 (MCI_CLEAR_STATUS_REG, MCI_STATUS_CMD_ERROR);

+

+    if ((Status & MCI_STATUS_CMD_START_BIT_ERROR)) {

+      DEBUG ((EFI_D_ERROR, "MciSendCommand(CmdIndex:%d) Start bit Error! Response:0x%X Status:0x%x\n", (Cmd & 0x3F), MmioRead32 (MCI_RESPONSE0_REG), Status));

+      RetVal = EFI_NO_RESPONSE;

+    } else if ((Status & MCI_STATUS_CMD_CMDTIMEOUT)) {

+      //DEBUG ((EFI_D_ERROR, "MciSendCommand(CmdIndex:%d) TIMEOUT! Response:0x%X Status:0x%x\n", (Cmd & 0x3F), MmioRead32 (MCI_RESPONSE0_REG), Status));

+      RetVal = EFI_TIMEOUT;

+    } else if ((!(MmcCmd & MMC_CMD_NO_CRC_RESPONSE)) && (Status & MCI_STATUS_CMD_CMDCRCFAIL)) {

+      // The CMD1 and response type R3 do not contain CRC. We should ignore the CRC failed Status.

+      RetVal = EFI_CRC_ERROR;

+    }

+  }

+

+  // Disable Command Path

+  CmdCtrlReg = MmioRead32 (MCI_COMMAND_REG);

+  MmioWrite32 (MCI_COMMAND_REG, (CmdCtrlReg & ~MCI_CPSM_ENABLE));

+  return RetVal;

+}

+

+EFI_STATUS

+MciReceiveResponse (

+  IN EFI_MMC_HOST_PROTOCOL     *This,

+  IN MMC_RESPONSE_TYPE          Type,

+  IN UINT32*                    Buffer

+  )

+{

+  if (Buffer == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (   (Type == MMC_RESPONSE_TYPE_R1)

+      || (Type == MMC_RESPONSE_TYPE_R1b)

+      || (Type == MMC_RESPONSE_TYPE_R3)

+      || (Type == MMC_RESPONSE_TYPE_R6)

+      || (Type == MMC_RESPONSE_TYPE_R7))

+  {

+    Buffer[0] = MmioRead32 (MCI_RESPONSE3_REG);

+  } else if (Type == MMC_RESPONSE_TYPE_R2) {

+    Buffer[0] = MmioRead32 (MCI_RESPONSE0_REG);

+    Buffer[1] = MmioRead32 (MCI_RESPONSE1_REG);

+    Buffer[2] = MmioRead32 (MCI_RESPONSE2_REG);

+    Buffer[3] = MmioRead32 (MCI_RESPONSE3_REG);

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+MciReadBlockData (

+  IN EFI_MMC_HOST_PROTOCOL     *This,

+  IN EFI_LBA                    Lba,

+  IN UINTN                      Length,

+  IN UINT32*                    Buffer

+  )

+{

+  UINTN Loop;

+  UINTN Finish;

+  UINTN Status;

+  EFI_STATUS RetVal;

+  UINTN  DataCtrlReg;

+  EFI_TPL Tpl;

+

+  RetVal = EFI_SUCCESS;

+

+  // Read data from the RX FIFO

+  Loop   = 0;

+  Finish = MMCI0_BLOCKLEN / 4;

+

+  // Raise the TPL at the highest level to disable Interrupts.

+  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);

+

+  do {

+    // Read the Status flags

+    Status = MmioRead32 (MCI_STATUS_REG);

+

+    // Do eight reads if possible else a single read

+    if (Status & MCI_STATUS_CMD_RXFIFOHALFFULL) {

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+    } else if (Status & MCI_STATUS_CMD_RXDATAAVAILBL) {

+      Buffer[Loop] = MmioRead32(MCI_FIFO_REG);

+      Loop++;

+    } else {

+      //Check for error conditions and timeouts

+      if (Status & MCI_STATUS_CMD_DATATIMEOUT) {

+        DEBUG ((EFI_D_ERROR, "MciReadBlockData(): TIMEOUT! Response:0x%X Status:0x%x\n", MmioRead32 (MCI_RESPONSE0_REG), Status));

+        RetVal = EFI_TIMEOUT;

+        break;

+      } else if (Status & MCI_STATUS_CMD_DATACRCFAIL) {

+        DEBUG ((EFI_D_ERROR, "MciReadBlockData(): CRC Error! Response:0x%X Status:0x%x\n", MmioRead32 (MCI_RESPONSE0_REG), Status));

+        RetVal = EFI_CRC_ERROR;

+        break;

+      } else if (Status & MCI_STATUS_CMD_START_BIT_ERROR) {

+        DEBUG ((EFI_D_ERROR, "MciReadBlockData(): Start-bit Error! Response:0x%X Status:0x%x\n", MmioRead32 (MCI_RESPONSE0_REG), Status));

+        RetVal = EFI_NO_RESPONSE;

+        break;

+      }

+    }

+    //clear RX over run flag

+    if(Status & MCI_STATUS_CMD_RXOVERRUN) {

+      MmioWrite32(MCI_CLEAR_STATUS_REG, MCI_STATUS_CMD_RXOVERRUN);

+    }

+  } while ((Loop < Finish));

+

+  // Restore Tpl

+  gBS->RestoreTPL (Tpl);

+

+  // Clear Status flags

+  MmioWrite32 (MCI_CLEAR_STATUS_REG, MCI_CLR_ALL_STATUS);

+

+  //Disable Data path

+  DataCtrlReg = MmioRead32 (MCI_DATA_CTL_REG);

+  MmioWrite32 (MCI_DATA_CTL_REG, (DataCtrlReg & MCI_DATACTL_DISABLE_MASK));

+

+  return RetVal;

+}

+

+EFI_STATUS

+MciWriteBlockData (

+  IN EFI_MMC_HOST_PROTOCOL     *This,

+  IN EFI_LBA                   Lba,

+  IN UINTN                     Length,

+  IN UINT32*                   Buffer

+  )

+{

+  UINTN Loop;

+  UINTN Finish;

+  UINTN Timer;

+  UINTN Status;

+  EFI_STATUS RetVal;

+  UINTN  DataCtrlReg;

+  EFI_TPL Tpl;

+

+  RetVal = EFI_SUCCESS;

+

+  // Write the data to the TX FIFO

+  Loop   = 0;

+  Finish = MMCI0_BLOCKLEN / 4;

+  Timer  = MMCI0_TIMEOUT * 100;

+

+  // Raise the TPL at the highest level to disable Interrupts.

+  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);

+

+  do {

+    // Read the Status flags

+    Status = MmioRead32 (MCI_STATUS_REG);

+

+    // Do eight writes if possible else a single write

+    if (Status & MCI_STATUS_CMD_TXFIFOHALFEMPTY) {

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+      MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+      Loop++;

+    } else if (!(Status & MCI_STATUS_CMD_TXFIFOFULL)) {

+        MmioWrite32(MCI_FIFO_REG, Buffer[Loop]);

+        Loop++;

+    } else {

+      // Check for error conditions and timeouts

+      if (Status & MCI_STATUS_CMD_DATATIMEOUT) {

+        DEBUG ((EFI_D_ERROR, "MciWriteBlockData(): TIMEOUT! Response:0x%X Status:0x%x\n", MmioRead32 (MCI_RESPONSE0_REG), Status));

+        RetVal = EFI_TIMEOUT;

+        goto Exit;

+      } else if (Status & MCI_STATUS_CMD_DATACRCFAIL) {

+        DEBUG ((EFI_D_ERROR, "MciWriteBlockData(): CRC Error! Response:0x%X Status:0x%x\n", MmioRead32 (MCI_RESPONSE0_REG), Status));

+        RetVal = EFI_CRC_ERROR;

+        goto Exit;

+      } else if (Status & MCI_STATUS_CMD_TX_UNDERRUN) {

+        DEBUG ((EFI_D_ERROR, "MciWriteBlockData(): TX buffer Underrun! Response:0x%X Status:0x%x, Number of bytes written 0x%x\n",MmioRead32(MCI_RESPONSE0_REG),Status, Loop));

+        RetVal = EFI_BUFFER_TOO_SMALL;

+        ASSERT(0);

+        goto Exit;

+      }

+    }

+  } while (Loop < Finish);

+

+  // Restore Tpl

+  gBS->RestoreTPL (Tpl);

+

+  // Wait for FIFO to drain

+  Timer  = MMCI0_TIMEOUT * 60;

+  Status = MmioRead32 (MCI_STATUS_REG);

+#ifndef USE_STREAM

+  // Single block

+  while (((Status & MCI_STATUS_TXDONE) != MCI_STATUS_TXDONE) && Timer) {

+#else

+  // Stream

+  while (((Status & MCI_STATUS_CMD_DATAEND) != MCI_STATUS_CMD_DATAEND) && Timer) {

+#endif

+    NanoSecondDelay(10);

+    Status = MmioRead32 (MCI_STATUS_REG);

+    Timer--;

+  }

+

+  // Clear Status flags

+  MmioWrite32 (MCI_CLEAR_STATUS_REG, MCI_CLR_ALL_STATUS);

+

+  if (Timer == 0) {

+    DEBUG ((EFI_D_ERROR, "MciWriteBlockData(): Data End timeout Number of words written 0x%x\n", Loop));

+    RetVal = EFI_TIMEOUT;

+  }

+

+Exit:

+  // Disable Data path

+  DataCtrlReg = MmioRead32 (MCI_DATA_CTL_REG);

+  MmioWrite32 (MCI_DATA_CTL_REG, (DataCtrlReg & MCI_DATACTL_DISABLE_MASK));

+  return RetVal;

+}

+

+EFI_STATUS

+MciNotifyState (

+  IN  EFI_MMC_HOST_PROTOCOL     *This,

+  IN MMC_STATE                  State

+  )

+{

+  UINT32      Data32;

+

+  switch (State) {

+  case MmcInvalidState:

+    ASSERT (0);

+    break;

+  case MmcHwInitializationState:

+    // If device already turn on then restart it

+    Data32 = MmioRead32 (MCI_POWER_CONTROL_REG);

+    if ((Data32 & 0x2) == MCI_POWER_UP) {

+      MCI_TRACE ("MciNotifyState(MmcHwInitializationState): TurnOff MCI");

+

+      // Turn off

+      MmioWrite32 (MCI_CLOCK_CONTROL_REG, 0);

+      MmioWrite32 (MCI_POWER_CONTROL_REG, 0);

+      MicroSecondDelay (100);

+    }

+

+    MCI_TRACE ("MciNotifyState(MmcHwInitializationState): TurnOn MCI");

+    // Setup clock

+    //  - 0x1D = 29 => should be the clock divider to be less than 400kHz at MCLK = 24Mhz

+    MmioWrite32 (MCI_CLOCK_CONTROL_REG, 0x1D | MCI_CLOCK_ENABLE | MCI_CLOCK_POWERSAVE);

+

+    // Set the voltage

+    MmioWrite32 (MCI_POWER_CONTROL_REG, MCI_POWER_OPENDRAIN | (15<<2));

+    MmioWrite32 (MCI_POWER_CONTROL_REG, MCI_POWER_ROD | MCI_POWER_OPENDRAIN | (15<<2) | MCI_POWER_UP);

+    MicroSecondDelay (10);

+    MmioWrite32 (MCI_POWER_CONTROL_REG, MCI_POWER_ROD | MCI_POWER_OPENDRAIN | (15<<2) | MCI_POWER_ON);

+    MicroSecondDelay (100);

+

+    // Set Data Length & Data Timer

+    MmioWrite32 (MCI_DATA_TIMER_REG, 0xFFFFF);

+    MmioWrite32 (MCI_DATA_LENGTH_REG, 8);

+

+    ASSERT ((MmioRead32 (MCI_POWER_CONTROL_REG) & 0x3) == MCI_POWER_ON);

+    break;

+  case MmcIdleState:

+    MCI_TRACE ("MciNotifyState(MmcIdleState)");

+    break;

+  case MmcReadyState:

+    MCI_TRACE ("MciNotifyState(MmcReadyState)");

+    break;

+  case MmcIdentificationState:

+    MCI_TRACE ("MciNotifyState (MmcIdentificationState)");

+    break;

+  case MmcStandByState:{

+    volatile UINT32 PwrCtrlReg;

+    MCI_TRACE ("MciNotifyState (MmcStandByState)");

+

+    // Enable MCICMD push-pull drive

+    PwrCtrlReg = MmioRead32 (MCI_POWER_CONTROL_REG);

+    //Disable Open Drain output

+    PwrCtrlReg &= ~ (MCI_POWER_OPENDRAIN);

+    MmioWrite32 (MCI_POWER_CONTROL_REG, PwrCtrlReg);

+

+    // Set MMCI0 clock to 4MHz (24MHz may be possible with cache enabled)

+    //

+    // Note: Increasing clock speed causes TX FIFO under-run errors.

+    //       So careful when optimising this driver for higher performance.

+    //

+    MmioWrite32(MCI_CLOCK_CONTROL_REG,0x02 | MCI_CLOCK_ENABLE | MCI_CLOCK_POWERSAVE);

+    // Set MMCI0 clock to 24MHz (by bypassing the divider)

+    //MmioWrite32(MCI_CLOCK_CONTROL_REG,MCI_CLOCK_BYPASS | MCI_CLOCK_ENABLE);

+    break;

+  }

+  case MmcTransferState:

+    //MCI_TRACE ("MciNotifyState(MmcTransferState)");

+    break;

+  case MmcSendingDataState:

+    MCI_TRACE ("MciNotifyState(MmcSendingDataState)");

+    break;

+  case MmcReceiveDataState:

+    MCI_TRACE ("MciNotifyState(MmcReceiveDataState)");

+    break;

+  case MmcProgrammingState:

+    MCI_TRACE ("MciNotifyState(MmcProgrammingState)");

+    break;

+  case MmcDisconnectState:

+    MCI_TRACE ("MciNotifyState(MmcDisconnectState)");

+    break;

+  default:

+    ASSERT (0);

+  }

+  return EFI_SUCCESS;

+}

+

+EFI_GUID mPL180MciDevicePathGuid = EFI_CALLER_ID_GUID;

+

+EFI_STATUS

+MciBuildDevicePath (

+  IN EFI_MMC_HOST_PROTOCOL      *This,

+  IN EFI_DEVICE_PATH_PROTOCOL   **DevicePath

+  )

+{

+  EFI_DEVICE_PATH_PROTOCOL    *NewDevicePathNode;

+

+  NewDevicePathNode = CreateDeviceNode (HARDWARE_DEVICE_PATH, HW_VENDOR_DP, sizeof (VENDOR_DEVICE_PATH));

+  CopyGuid (& ((VENDOR_DEVICE_PATH*)NewDevicePathNode)->Guid, &mPL180MciDevicePathGuid);

+

+  *DevicePath = NewDevicePathNode;

+  return EFI_SUCCESS;

+}

+

+EFI_MMC_HOST_PROTOCOL gMciHost = {

+  MMC_HOST_PROTOCOL_REVISION,

+  MciIsCardPresent,

+  MciIsReadOnly,

+  MciBuildDevicePath,

+  MciNotifyState,

+  MciSendCommand,

+  MciReceiveResponse,

+  MciReadBlockData,

+  MciWriteBlockData

+};

+

+EFI_STATUS

+PL180MciDxeInitialize (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS    Status;

+  EFI_HANDLE    Handle;

+

+  Handle = NULL;

+

+  MCI_TRACE ("PL180MciDxeInitialize()");

+

+  //Publish Component Name, BlockIO protocol interfaces

+  Status = gBS->InstallMultipleProtocolInterfaces (

+                  &Handle,

+                  &gEfiMmcHostProtocolGuid,         &gMciHost,

+                  NULL

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180Mci.h b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180Mci.h
new file mode 100644
index 0000000..6dc155e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180Mci.h
@@ -0,0 +1,151 @@
+/** @file

+  Header for the MMC Host Protocol implementation for the ARM PrimeCell PL180.

+

+  Copyright (c) 2011-2012, ARM 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.

+

+**/

+

+#ifndef __PL180_MCI_H

+#define __PL180_MCI_H

+

+#include <Uefi.h>

+

+#include <Protocol/MmcHost.h>

+

+#include <Library/UefiLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/IoLib.h>

+#include <Library/TimerLib.h>

+#include <Library/PcdLib.h>

+

+#define PL180_MCI_DXE_VERSION           0x10

+

+#define MCI_SYSCTL  FixedPcdGet32 (PcdPL180MciBaseAddress)

+

+#define MCI_POWER_CONTROL_REG           (MCI_SYSCTL + 0x000)

+#define MCI_CLOCK_CONTROL_REG           (MCI_SYSCTL + 0x004)

+#define MCI_ARGUMENT_REG                (MCI_SYSCTL + 0x008)

+#define MCI_COMMAND_REG                 (MCI_SYSCTL + 0x00C)

+#define MCI_RESPCMD_REG                 (MCI_SYSCTL + 0x010)

+#define MCI_RESPONSE3_REG               (MCI_SYSCTL + 0x014)

+#define MCI_RESPONSE2_REG               (MCI_SYSCTL + 0x018)

+#define MCI_RESPONSE1_REG               (MCI_SYSCTL + 0x01C)

+#define MCI_RESPONSE0_REG               (MCI_SYSCTL + 0x020)

+#define MCI_DATA_TIMER_REG              (MCI_SYSCTL + 0x024)

+#define MCI_DATA_LENGTH_REG             (MCI_SYSCTL + 0x028)

+#define MCI_DATA_CTL_REG                (MCI_SYSCTL + 0x02C)

+#define MCI_DATA_COUNTER                (MCI_SYSCTL + 0x030)

+#define MCI_STATUS_REG                  (MCI_SYSCTL + 0x034)

+#define MCI_CLEAR_STATUS_REG            (MCI_SYSCTL + 0x038)

+#define MCI_INT0_MASK_REG               (MCI_SYSCTL + 0x03C)

+#define MCI_INT1_MASK_REG               (MCI_SYSCTL + 0x040)

+#define MCI_SELECT_REG                  (MCI_SYSCTL + 0x044)

+#define MCI_FIFOCOUNT_REG               (MCI_SYSCTL + 0x048)

+#define MCI_FIFO_REG                    (MCI_SYSCTL + 0x080)

+

+#define MCI_POWER_OFF                   0

+#define MCI_POWER_UP                    BIT1

+#define MCI_POWER_ON                    (BIT1 | BIT0)

+#define MCI_POWER_OPENDRAIN             BIT6

+#define MCI_POWER_ROD                   BIT7

+

+#define MCI_CLOCK_ENABLE                BIT8

+#define MCI_CLOCK_POWERSAVE             BIT9

+#define MCI_CLOCK_BYPASS                BIT10

+#define MCI_CLOCK_WIDEBUS               BIT11

+

+#define MCI_STATUS_CMD_CMDCRCFAIL       BIT0

+#define MCI_STATUS_CMD_DATACRCFAIL      BIT1

+#define MCI_STATUS_CMD_CMDTIMEOUT       BIT2

+#define MCI_STATUS_CMD_DATATIMEOUT      BIT3

+#define MCI_STATUS_CMD_TX_UNDERRUN      BIT4

+#define MCI_STATUS_CMD_RXOVERRUN        BIT5

+#define MCI_STATUS_CMD_RESPEND          BIT6

+#define MCI_STATUS_CMD_SENT             BIT7

+#define MCI_STATUS_CMD_DATAEND          BIT8

+#define MCI_STATUS_CMD_START_BIT_ERROR  BIT9

+#define MCI_STATUS_CMD_DATABLOCKEND     BIT10

+#define MCI_STATUS_CMD_ACTIVE           BIT11

+#define MCI_STATUS_CMD_TXACTIVE         BIT12

+#define MCI_STATUS_CMD_RXACTIVE         BIT13

+#define MCI_STATUS_CMD_TXFIFOHALFEMPTY  BIT14

+#define MCI_STATUS_CMD_RXFIFOHALFFULL   BIT15

+#define MCI_STATUS_CMD_TXFIFOFULL       BIT16

+#define MCI_STATUS_CMD_RXFIFOFULL       BIT17

+#define MCI_STATUS_CMD_TXFIFOEMPTY      BIT18

+#define MCI_STATUS_CMD_RXFIFOEMPTY      BIT19

+#define MCI_STATUS_CMD_TXDATAAVAILBL    BIT20

+#define MCI_STATUS_CMD_RXDATAAVAILBL    BIT21

+

+#define MCI_STATUS_TXDONE               (MCI_STATUS_CMD_DATAEND | MCI_STATUS_CMD_DATABLOCKEND)

+#define MCI_STATUS_RXDONE               (MCI_STATUS_CMD_DATAEND | MCI_STATUS_CMD_DATABLOCKEND)

+#define MCI_STATUS_READ_ERROR           (  MCI_STATUS_CMD_DATACRCFAIL     \

+                                         | MCI_STATUS_CMD_DATATIMEOUT     \

+                                         | MCI_STATUS_CMD_RXOVERRUN       \

+                                         | MCI_STATUS_CMD_START_BIT_ERROR )

+#define MCI_STATUS_WRITE_ERROR          (  MCI_STATUS_CMD_DATACRCFAIL \

+                                         | MCI_STATUS_CMD_DATATIMEOUT \

+                                         | MCI_STATUS_CMD_TX_UNDERRUN )

+#define MCI_STATUS_CMD_ERROR            (  MCI_STATUS_CMD_CMDCRCFAIL      \

+                                         | MCI_STATUS_CMD_CMDTIMEOUT      \

+                                         | MCI_STATUS_CMD_START_BIT_ERROR )

+

+#define MCI_CLR_CMD_STATUS              (  MCI_STATUS_CMD_RESPEND \

+                                         | MCI_STATUS_CMD_SENT    \

+                                         | MCI_STATUS_CMD_ERROR )

+

+#define MCI_CLR_READ_STATUS             (  MCI_STATUS_RXDONE     \

+                                         | MCI_STATUS_READ_ERROR )

+

+#define MCI_CLR_WRITE_STATUS            (  MCI_STATUS_TXDONE      \

+                                         | MCI_STATUS_WRITE_ERROR )

+

+#define MCI_CLR_ALL_STATUS              (BIT11 - 1)

+

+#define MCI_DATACTL_DISABLE_MASK        0xFE

+#define MCI_DATACTL_ENABLE              BIT0

+#define MCI_DATACTL_CONT_TO_CARD        0

+#define MCI_DATACTL_CARD_TO_CONT        BIT1

+#define MCI_DATACTL_BLOCK_TRANS         0

+#define MCI_DATACTL_STREAM_TRANS        BIT2

+#define MCI_DATACTL_DMA_DISABLED        0

+#define MCI_DATACTL_DMA_ENABLE          BIT3

+

+#define INDX_MASK                       0x3F

+

+#define MCI_CPSM_WAIT_RESPONSE          BIT6

+#define MCI_CPSM_LONG_RESPONSE          BIT7

+#define MCI_CPSM_LONG_INTERRUPT         BIT8

+#define MCI_CPSM_LONG_PENDING           BIT9

+#define MCI_CPSM_ENABLE                 BIT10

+

+#define MCI_TRACE(txt)                  DEBUG ((EFI_D_BLKIO, "ARM_MCI: " txt "\n"))

+

+EFI_STATUS

+EFIAPI

+MciGetDriverName (

+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,

+  IN  CHAR8                        *Language,

+  OUT CHAR16                       **DriverName

+  );

+

+EFI_STATUS

+EFIAPI

+MciGetControllerName (

+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,

+  IN  EFI_HANDLE                                      ControllerHandle,

+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,

+  IN  CHAR8                                           *Language,

+  OUT CHAR16                                          **ControllerName

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf
new file mode 100755
index 0000000..418fbac
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL180MciDxe/PL180MciDxe.inf
@@ -0,0 +1,52 @@
+#/** @file

+#  INF file for the MMC Host Protocol implementation for the ARM PrimeCell PL180.

+#

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PL180MciDxe

+  FILE_GUID                      = 09831032-6fa3-4484-af4f-0a000a8d3a82

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = PL180MciDxeInitialize

+

+[Sources.common]

+  PL180Mci.c

+

+[Packages]

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+

+[LibraryClasses]

+  BaseLib

+  UefiLib

+  UefiDriverEntryPoint

+  BaseMemoryLib

+  ArmLib

+  IoLib

+  TimerLib

+

+[Protocols]

+  gEfiCpuArchProtocolGuid

+  gEfiDevicePathProtocolGuid

+  gEfiMmcHostProtocolGuid

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdPL180SysMciRegAddress

+  gArmPlatformTokenSpaceGuid.PcdPL180MciBaseAddress

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL301Axi/PL301Axi.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL301Axi/PL301Axi.c
new file mode 100644
index 0000000..8600721
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL301Axi/PL301Axi.c
@@ -0,0 +1,108 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/DebugLib.h>

+

+#define PL301_QOS_TIDEMARK_MI_0                  0x400

+#define PL301_QOS_ACCESSCONTROL_MI_0             0x404

+

+#define PL301_QOS_TIDEMARK_MI_1                  0x420

+#define PL301_QOS_ACCESSCONTROL_MI_1             0x424

+

+#define PL301_QOS_TIDEMARK_MI_2                  0x440

+#define PL301_QOS_ACCESSCONTROL_MI_2             0x444

+

+#define PL301_AR_ARB_MI_0                        0x408

+#define PL301_AW_ARB_MI_0                        0x40C

+

+#define PL301_AR_ARB_MI_1                        0x428

+#define PL301_AW_ARB_MI_1                        0x42C

+

+#define PL301_AR_ARB_MI_2                        0x448

+#define PL301_AW_ARB_MI_2                        0x44C

+

+#define PL301_MI_1_OFFSET                        0x20

+#define PL301_MI_2_OFFSET                        0x40

+#define PL301_MI_3_OFFSET                        0x60

+#define PL301_MI_4_OFFSET                        0x80

+#define PL301_MI_5_OFFSET                        0xa0

+

+#define V2P_CA9_FAXI_MI0_TIDEMARK_VAL            0x6

+#define V2P_CA9_FAXI_MI0_ACCESSCNTRL_VAL         0x1

+

+#define V2P_CA9_FAXI_MI1_TIDEMARK_VAL            0x6

+#define V2P_CA9_FAXI_MI1_ACCESSCNTRL_VAL         0x1

+

+#define V2P_CA9_FAXI_MI2_TIDEMARK_VAL            0x6

+#define V2P_CA9_FAXI_MI2_ACCESSCNTRL_VAL         0x1

+

+

+#define FAxiWriteReg(reg,val)                    MmioWrite32(FAxiBase + reg, val)

+#define FAxiReadReg(reg)                         MmioRead32(FAxiBase + reg)

+

+// IN FAxiBase

+// Initialize PL301 Dynamic Memory Controller

+VOID PL301AxiInit(UINTN FAxiBase) {

+    // Configure Tidemark Register for Master Port 0 (MI 0)

+    FAxiWriteReg(PL301_QOS_TIDEMARK_MI_0, V2P_CA9_FAXI_MI0_TIDEMARK_VAL);

+

+    // Configure the Access Control Register (MI 0)

+    FAxiWriteReg(PL301_QOS_ACCESSCONTROL_MI_0, V2P_CA9_FAXI_MI0_ACCESSCNTRL_VAL);

+

+    // MP0

+    // Set priority for Read

+    FAxiWriteReg(PL301_AR_ARB_MI_0, 0x00000100);

+    FAxiWriteReg(PL301_AR_ARB_MI_0, 0x01000200);

+    FAxiWriteReg(PL301_AR_ARB_MI_0, 0x02000200);

+    FAxiWriteReg(PL301_AR_ARB_MI_0, 0x03000200);

+    FAxiWriteReg(PL301_AR_ARB_MI_0, 0x04000200);

+

+    // Set priority for Write

+    FAxiWriteReg(PL301_AW_ARB_MI_0, 0x00000100);

+    FAxiWriteReg(PL301_AW_ARB_MI_0, 0x01000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_0, 0x02000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_0, 0x03000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_0, 0x04000200);

+

+    // MP1

+    // Set priority for Read

+    FAxiWriteReg(PL301_AR_ARB_MI_1, 0x00000100);

+    FAxiWriteReg(PL301_AR_ARB_MI_1, 0x01000200);

+    FAxiWriteReg(PL301_AR_ARB_MI_1, 0x02000200);

+    FAxiWriteReg(PL301_AR_ARB_MI_1, 0x03000200);

+    FAxiWriteReg(PL301_AR_ARB_MI_1, 0x04000200);

+

+    // Set priority for Write

+    FAxiWriteReg(PL301_AW_ARB_MI_1, 0x00000100);

+    FAxiWriteReg(PL301_AW_ARB_MI_1, 0x01000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_1, 0x02000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_1, 0x03000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_1, 0x04000200);

+

+    // MP2

+    // Set priority for Read

+    FAxiWriteReg(PL301_AR_ARB_MI_2, 0x00000100);

+    FAxiWriteReg(PL301_AR_ARB_MI_2, 0x01000100);

+    FAxiWriteReg(PL301_AR_ARB_MI_2, 0x02000100);

+    FAxiWriteReg(PL301_AR_ARB_MI_2, 0x03000100);

+    FAxiWriteReg(PL301_AR_ARB_MI_2, 0x04000100);

+

+    // Set priority for Write

+    FAxiWriteReg(PL301_AW_ARB_MI_2, 0x00000100);

+    FAxiWriteReg(PL301_AW_ARB_MI_2, 0x01000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_2, 0x02000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_2, 0x03000200);

+    FAxiWriteReg(PL301_AW_ARB_MI_2, 0x04000200);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL301Axi/PL301Axi.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL301Axi/PL301Axi.inf
new file mode 100755
index 0000000..108161f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL301Axi/PL301Axi.inf
@@ -0,0 +1,27 @@
+#/* @file

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PL301Axi

+  FILE_GUID                      = 2ea84160-aba0-11df-9896-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PL301AxiLib

+

+[Sources]

+  PL301Axi.c

+

+[Packages]

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2Cache.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2Cache.c
new file mode 100644
index 0000000..1a6ab33
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2Cache.c
@@ -0,0 +1,126 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/DebugLib.h>

+#include <Library/ArmLib.h>

+#include <Drivers/PL310L2Cache.h>

+#include <Library/PcdLib.h>

+

+#define L2x0WriteReg(reg,val)               MmioWrite32(PcdGet32(PcdL2x0ControllerBase) + reg, val)

+#define L2x0ReadReg(reg)                    MmioRead32(PcdGet32(PcdL2x0ControllerBase) + reg)

+

+// Initialize PL320 L2 Cache Controller

+VOID

+L2x0CacheInit (

+  IN  UINTN   L2x0Base,

+  IN  UINT32  L2x0TagLatencies,

+  IN  UINT32  L2x0DataLatencies,

+  IN  UINT32  L2x0AuxValue,

+  IN  UINT32  L2x0AuxMask,

+  IN  BOOLEAN CacheEnabled

+  )

+{

+  UINT32 Data;

+  UINT32 Revision;

+  UINT32 Aux;

+  UINT32 PfCtl;

+  UINT32 PwrCtl;

+

+  // Check if L2x0 is present and is an ARM implementation

+  Data = L2x0ReadReg(L2X0_CACHEID);

+  if ((Data >> 24) != L2X0_CACHEID_IMPLEMENTER_ARM) {

+    ASSERT(0);

+    return;

+  }

+

+  // Check if L2x0 is PL310

+  if (((Data >> 6) & 0xF) != L2X0_CACHEID_PARTNUM_PL310) {

+    ASSERT(0);

+    return;

+  }

+

+  // RTL release

+  Revision = Data & 0x3F;

+

+  // Check if L2x0 is already enabled then we disable it

+  Data = L2x0ReadReg(L2X0_CTRL);

+  if (Data & L2X0_CTRL_ENABLED) {

+    L2x0WriteReg(L2X0_CTRL, L2X0_CTRL_DISABLED);

+  }

+

+  //

+  // Set up global configurations

+  //

+

+  // Auxiliary register: Non-secure interrupt access Control + Event monitor bus enable + SBO

+  Aux = L2X0_AUXCTRL_NSAC | L2X0_AUXCTRL_EM | L2X0_AUXCTRL_SBO;

+  // Use AWCACHE attributes for WA

+  Aux |= L2x0_AUXCTRL_AW_AWCACHE;

+  // Use default Size

+  Data = L2x0ReadReg(L2X0_AUXCTRL);

+  Aux |= Data & L2X0_AUXCTRL_WAYSIZE_MASK;

+  // Use default associativity

+  Aux |= Data & L2X0_AUXCTRL_ASSOCIATIVITY;

+  // Enabled I & D Prefetch

+  Aux |= L2x0_AUXCTRL_IPREFETCH | L2x0_AUXCTRL_DPREFETCH;

+

+  if (Revision >= 5) {

+    // Prefetch Offset Register

+    PfCtl = L2x0ReadReg(L2X0_PFCTRL);

+    // - Prefetch increment set to 0

+    // - Prefetch dropping off

+    // - Double linefills off

+    L2x0WriteReg(L2X0_PFCTRL, PfCtl);

+

+    // Power Control Register - L2X0_PWRCTRL

+    PwrCtl = L2x0ReadReg(L2X0_PWRCTRL);

+    // - Standby when idle off

+    // - Dynamic clock gating off

+    // - Nc,NC-shared dropping off

+    L2x0WriteReg(L2X0_PWRCTRL, PwrCtl);

+  }

+

+  if (Revision >= 2) {

+    L2x0WriteReg(L230_TAG_LATENCY, L2x0TagLatencies);

+    L2x0WriteReg(L230_DATA_LATENCY, L2x0DataLatencies);

+  } else {

+    // PL310 old style latency is not supported yet

+    ASSERT(0);

+  }

+

+  // Set the platform specific values

+  Aux = (Aux & L2x0AuxMask) | L2x0AuxValue;

+

+  // Write Auxiliary value

+  L2x0WriteReg(L2X0_AUXCTRL, Aux);

+

+  //

+  // Invalidate all entries in cache

+  //

+  L2x0WriteReg(L2X0_INVWAY, 0xffff);

+  // Poll cache maintenance register until invalidate operation is complete

+  while(L2x0ReadReg(L2X0_INVWAY) & 0xffff);

+

+  // Write to the Lockdown D and Lockdown I Register 9 if required

+  // - Not required

+

+  // Clear any residual raw interrupts

+  L2x0WriteReg(L2X0_INTCLEAR, 0x1FF);

+

+  // Enable the cache

+  if (CacheEnabled) {

+    L2x0WriteReg(L2X0_CTRL, L2X0_CTRL_ENABLED);

+  }

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2CacheSec.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2CacheSec.inf
new file mode 100755
index 0000000..78f952a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2CacheSec.inf
@@ -0,0 +1,31 @@
+#/* @file

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PL310L2Cache

+  FILE_GUID                      = 16ad4fe0-b5b1-11df-8cbf-0002a5d5c51b

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = L2X0CacheLib

+

+[Sources]

+  PL310L2Cache.c

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdL2x0ControllerBase

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL34xDmc/PL341Dmc.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL34xDmc/PL341Dmc.c
new file mode 100644
index 0000000..08eba6e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL34xDmc/PL341Dmc.c
@@ -0,0 +1,227 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <Uefi.h>

+

+#include <Library/IoLib.h>

+#include <Library/DebugLib.h>

+

+#include <Drivers/PL341Dmc.h>

+

+// Macros for writing to DDR2 controller.

+#define DmcWriteReg(reg,val)                    MmioWrite32(DmcBase + reg, val)

+#define DmcReadReg(reg)                         MmioRead32(DmcBase + reg)

+

+// Macros for writing/reading to DDR2 PHY controller

+#define DmcPhyWriteReg(reg,val)                    MmioWrite32(DmcPhyBase + reg, val)

+#define DmcPhyReadReg(reg)                         MmioRead32(DmcPhyBase + reg)

+

+// Initialise PL341 Dynamic Memory Controller

+VOID

+PL341DmcInit (

+  IN  UINTN             DmcBase,

+  IN  PL341_DMC_CONFIG* DmcConfig

+  )

+{

+  UINTN Index;

+  UINT32 Chip;

+

+  // Set config mode

+  DmcWriteReg(DMC_COMMAND_REG, DMC_COMMAND_CONFIGURE);

+

+  //

+  // Setup the QoS AXI ID bits

+  //

+  if (DmcConfig->HasQos) {

+    // CLCD AXIID = 000

+    DmcWriteReg(DMC_ID_0_CFG_REG, DMC_ID_CFG_QOS_ENABLE | DMC_ID_CFG_QOS_MIN);

+

+    // Default disable QoS

+    DmcWriteReg(DMC_ID_1_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_2_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_3_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_4_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_5_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_6_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_7_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_8_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_9_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_10_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_11_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_12_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_13_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_14_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+    DmcWriteReg(DMC_ID_15_CFG_REG, DMC_ID_CFG_QOS_DISABLE);

+  }

+

+  //

+  // Initialise memory controlller

+  //

+  DmcWriteReg(DMC_REFRESH_PRD_REG, DmcConfig->RefreshPeriod);

+  DmcWriteReg(DMC_CAS_LATENCY_REG, DmcConfig->CasLatency);

+  DmcWriteReg(DMC_WRITE_LATENCY_REG, DmcConfig->WriteLatency);

+  DmcWriteReg(DMC_T_MRD_REG, DmcConfig->t_mrd);

+  DmcWriteReg(DMC_T_RAS_REG, DmcConfig->t_ras);

+  DmcWriteReg(DMC_T_RC_REG, DmcConfig->t_rc);

+  DmcWriteReg(DMC_T_RCD_REG, DmcConfig->t_rcd);

+  DmcWriteReg(DMC_T_RFC_REG, DmcConfig->t_rfc);

+  DmcWriteReg(DMC_T_RP_REG, DmcConfig->t_rp);

+  DmcWriteReg(DMC_T_RRD_REG, DmcConfig->t_rrd);

+  DmcWriteReg(DMC_T_WR_REG, DmcConfig->t_wr);

+  DmcWriteReg(DMC_T_WTR_REG, DmcConfig->t_wtr);

+  DmcWriteReg(DMC_T_XP_REG, DmcConfig->t_xp);

+  DmcWriteReg(DMC_T_XSR_REG, DmcConfig->t_xsr);

+  DmcWriteReg(DMC_T_ESR_REG, DmcConfig->t_esr);

+  DmcWriteReg(DMC_T_FAW_REG, DmcConfig->t_faw);

+  DmcWriteReg(DMC_T_WRLAT_DIFF, DmcConfig->t_wdata_en);

+  DmcWriteReg(DMC_T_RDATA_EN, DmcConfig->t_data_en);

+

+  //

+  // Initialise PL341 Mem Config Registers

+  //

+

+  // Set PL341 Memory Config

+  DmcWriteReg(DMC_MEMORY_CONFIG_REG, DmcConfig->MemoryCfg);

+

+  // Set PL341 Memory Config 2

+  DmcWriteReg(DMC_MEMORY_CFG2_REG, DmcConfig->MemoryCfg2);

+

+  // Set PL341 Memory Config 3

+  DmcWriteReg(DMC_MEMORY_CFG3_REG, DmcConfig->MemoryCfg3);

+

+  // Set PL341 Chip Select <n>

+  DmcWriteReg(DMC_CHIP_0_CFG_REG, DmcConfig->ChipCfg0);

+  DmcWriteReg(DMC_CHIP_1_CFG_REG, DmcConfig->ChipCfg1);

+  DmcWriteReg(DMC_CHIP_2_CFG_REG, DmcConfig->ChipCfg2);

+  DmcWriteReg(DMC_CHIP_3_CFG_REG, DmcConfig->ChipCfg3);

+

+  // Delay

+  for (Index = 0; Index < 10; Index++) {

+    DmcReadReg(DMC_STATUS_REG);

+  }

+

+  if (DmcConfig->IsUserCfg) {

+    //

+    // Set Test Chip PHY Registers via PL341 User Config Reg

+    // Note that user_cfgX registers are Write Only

+    //

+    // DLL Freq set = 250MHz - 266MHz

+    //

+    DmcWriteReg(DMC_USER_0_CFG_REG, DmcConfig->User0Cfg);

+

+    // user_config2

+    // ------------

+    // Set defaults before calibrating the DDR2 buffer impendence

+    // - Disable ODT

+    // - Default drive strengths

+    DmcWriteReg(DMC_USER_2_CFG_REG, 0x40000198);

+

+    //

+    // Auto calibrate the DDR2 buffers impendence

+    //

+    while (!(DmcReadReg(DMC_USER_STATUS_REG) & 0x100));

+

+    // Set the output driven strength

+    DmcWriteReg(DMC_USER_2_CFG_REG, 0x40800000 | DmcConfig->User2Cfg);

+

+    //

+    // Set PL341 Feature Control Register

+    //

+    // Disable early BRESP - use to optimise CLCD performance

+    DmcWriteReg(DMC_FEATURE_CRTL_REG, 0x00000001);

+  }

+

+  //

+  // Config memories

+  //

+  for (Chip = 0; Chip < DmcConfig->MaxChip; Chip++) {

+    // Send nop

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_MEMCMD_NOP);

+

+    // Pre-charge all

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_MEMCMD_PRECHARGEALL);

+

+    // Delay

+    for (Index = 0; Index < 10; Index++) {

+      DmcReadReg(DMC_STATUS_REG);

+    }

+

+    // Set (EMR2) extended mode register 2

+    DmcWriteReg(DMC_DIRECT_CMD_REG,

+      DMC_DIRECT_CMD_CHIP_ADDR(Chip) |

+      DMC_DIRECT_CMD_BANKADDR(2) |

+      DMC_DIRECT_CMD_MEMCMD_EXTMODEREG);

+

+    // Set (EMR3) extended mode register 3

+    DmcWriteReg(DMC_DIRECT_CMD_REG,

+      DMC_DIRECT_CMD_CHIP_ADDR(Chip) |

+      DMC_DIRECT_CMD_BANKADDR(3) |

+      DMC_DIRECT_CMD_MEMCMD_EXTMODEREG);

+

+    //

+    // Set (EMR) Extended Mode Register

+    //

+    // Put into OCD default state

+    DmcWriteReg(DMC_DIRECT_CMD_REG,DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_BANKADDR(1) | DMC_DIRECT_CMD_MEMCMD_EXTMODEREG);

+

+    //

+    // Set (MR) mode register - With DLL reset

+    //

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_MEMCMD_EXTMODEREG | DmcConfig->ModeReg | DDR2_MR_DLL_RESET);

+

+    // Pre-charge all

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_MEMCMD_PRECHARGEALL);

+    // Auto-refresh

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_MEMCMD_AUTOREFRESH);

+    // Auto-refresh

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_MEMCMD_AUTOREFRESH);

+

+    //

+    // Set (MR) mode register - Without DLL reset

+    //

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | DMC_DIRECT_CMD_MEMCMD_EXTMODEREG | DmcConfig->ModeReg);

+

+    // Delay

+    for (Index = 0; Index < 10; Index++) {

+      DmcReadReg(DMC_STATUS_REG);

+    }

+

+    //

+    // Set (EMR) extended mode register - Enable OCD defaults

+    //

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | (0x00090000) |

+        (1 << DDR_MODESET_SHFT) | (DDR_EMR_OCD_DEFAULT << DDR_EMR_OCD_SHIFT) | DmcConfig->ExtModeReg);

+

+    // Delay

+    for (Index = 0; Index < 10; Index++) {

+      DmcReadReg(DMC_STATUS_REG);

+    }

+

+    // Set (EMR) extended mode register - OCD Exit

+    DmcWriteReg(DMC_DIRECT_CMD_REG, DMC_DIRECT_CMD_CHIP_ADDR(Chip) | (0x00090000) |

+        (1 << DDR_MODESET_SHFT) | (DDR_EMR_OCD_NS << DDR_EMR_OCD_SHIFT) | DmcConfig->ExtModeReg);

+

+    // Delay

+    for (Index = 0; Index < 10; Index++) {

+      DmcReadReg(DMC_STATUS_REG);

+    }

+  }

+

+  // Move DDR2 Controller to Ready state by issueing GO command

+  DmcWriteReg(DMC_COMMAND_REG, DMC_COMMAND_GO);

+

+  // wait for ready

+  while (!(DmcReadReg(DMC_STATUS_REG) & DMC_STATUS_READY));

+

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL34xDmc/PL341Dmc.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL34xDmc/PL341Dmc.inf
new file mode 100755
index 0000000..0f3d862
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL34xDmc/PL341Dmc.inf
@@ -0,0 +1,29 @@
+#/* @file

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PL341Dmc

+  FILE_GUID                      = edf8da40-aad1-11df-a1f4-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PL341DmcLib

+

+[Sources]

+  PL341Dmc.c

+

+[Packages]

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

+

+[FixedPcd]

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/InitializeSMC.S b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/InitializeSMC.S
new file mode 100755
index 0000000..a26a4d4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/InitializeSMC.S
@@ -0,0 +1,60 @@
+#

+#  Copyright (c) 2011-2012, ARM 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.

+#

+#

+

+#include <AsmMacroIoLib.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+#include <Drivers/PL35xSmc.h>

+

+.text

+

+#Maintain 8 byte alignment

+.align 3

+

+GCC_ASM_EXPORT(PL35xSmcInitialize)

+GCC_ASM_EXPORT(PL35xSmcSetRefresh)

+

+// IN r1 Smc Base Address

+// IN r2 Smc Configuration Start Address

+// IN r3 Smc Configuration End Address

+// NOTE: This code is been called before any stack has been setup. It means some registers

+//       could be overwritten (case of 'r0')

+ASM_PFX(PL35xSmcInitialize):

+  // While (SmcConfigurationStart < SmcConfigurationEnd)

+  cmp   r2, r3

+  blxge lr

+

+  // Write to set_cycle register(holding register for NOR 1 cycle register or NAND cycle register)

+  ldr   r0, [r2, #0x4]

+  str   r0, [r1, #PL350_SMC_SET_CYCLES_OFFSET]

+

+  // Write to set_opmode register(holding register for NOR 1 opomode register or NAND opmode register)

+  ldr   r0, [r2, #0x8]

+  str   r0, [r1, #PL350_SMC_SET_OPMODE_OFFSET]

+

+  // Write to direct_cmd register so that the NOR 1 registers(set-cycles and opmode) are updated with holding registers

+  ldr   r0, =PL350_SMC_DIRECT_CMD_ADDR_CMD_UPDATE

+  ldr   r4, [r2, #0x0]

+  orr   r0, r0, r4

+  str   r0, [r1, #PL350_SMC_DIRECT_CMD_OFFSET]

+

+  add   r2, #0xC

+  b     ASM_PFX(PL35xSmcInitialize)

+

+// IN r1 Smc Base Address

+// IN r2 Smc Refresh Period 0

+// IN r3 Smc Refresh Period 1

+ASM_PFX(PL35xSmcSetRefresh):

+  str   r2, [r1, #PL350_SMC_REFRESH_0_OFFSET]

+  str   r3, [r1, #PL350_SMC_REFRESH_1_OFFSET]

+  blx lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/InitializeSMC.asm b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/InitializeSMC.asm
new file mode 100755
index 0000000..661b068
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/InitializeSMC.asm
@@ -0,0 +1,62 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/PcdLib.h>

+#include <Drivers/PL35xSmc.h>

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  PL35xSmcInitialize

+  EXPORT  PL35xSmcSetRefresh

+

+  PRESERVE8

+  AREA    ModuleInitializeSMC, CODE, READONLY

+

+// IN r1 Smc Base Address

+// IN r2 Smc Configuration Start Address

+// IN r3 Smc Configuration End Address

+// NOTE: This code is been called before any stack has been setup. It means some registers

+//       could be overwritten (case of 'r0')

+PL35xSmcInitialize

+  // While (SmcConfigurationStart < SmcConfigurationEnd)

+  cmp   r2, r3

+  blxge lr

+

+  // Write to set_cycle register(holding register for NOR 1 cycle register or NAND cycle register)

+  ldr   r0, [r2, #0x4]

+  str   r0, [r1, #PL350_SMC_SET_CYCLES_OFFSET]

+

+  // Write to set_opmode register(holding register for NOR 1 opomode register or NAND opmode register)

+  ldr   r0, [r2, #0x8]

+  str   r0, [r1, #PL350_SMC_SET_OPMODE_OFFSET]

+

+  // Write to direct_cmd register so that the NOR 1 registers(set-cycles and opmode) are updated with holding registers

+  ldr   r0, =PL350_SMC_DIRECT_CMD_ADDR_CMD_UPDATE

+  ldr   r4, [r2, #0x0]

+  orr   r0, r0, r4

+  str   r0, [r1, #PL350_SMC_DIRECT_CMD_OFFSET]

+

+  add   r2, #0xC

+  b     PL35xSmcInitialize

+

+// IN r1 Smc Base Address

+// IN r2 Smc Refresh Period 0

+// IN r3 Smc Refresh Period 1

+PL35xSmcSetRefresh

+  str   r2, [r1, #PL350_SMC_REFRESH_0_OFFSET]

+  str   r3, [r1, #PL350_SMC_REFRESH_1_OFFSET]

+  blx lr

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/PL35xSmc.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/PL35xSmc.inf
new file mode 100755
index 0000000..2eee5ab
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/PL35xSmc/PL35xSmc.inf
@@ -0,0 +1,29 @@
+#/* @file

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PL35xSmc

+  FILE_GUID                      = 10952220-aa32-11df-a438-0002a5d5c51b

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PL35xSmcLib

+

+[Sources.common]

+  InitializeSMC.asm  | RVCT

+  InitializeSMC.S    | GCC

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c
new file mode 100644
index 0000000..7ae25e9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c
@@ -0,0 +1,395 @@
+/** @file

+  Template for Timer Architecture Protocol driver of the ARM flavor

+

+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>

+

+  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 <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+

+#include <Protocol/Timer.h>

+#include <Protocol/HardwareInterrupt.h>

+

+#include <Drivers/SP804Timer.h>

+

+#define SP804_TIMER_PERIODIC_BASE     ((UINTN)PcdGet32 (PcdSP804TimerPeriodicBase))

+#define SP804_TIMER_METRONOME_BASE    ((UINTN)PcdGet32 (PcdSP804TimerMetronomeBase))

+#define SP804_TIMER_PERFORMANCE_BASE  ((UINTN)PcdGet32 (PcdSP804TimerPerformanceBase))

+

+// The notification function to call on every timer interrupt.

+EFI_TIMER_NOTIFY      mTimerNotifyFunction     = (EFI_TIMER_NOTIFY)NULL;

+EFI_EVENT             EfiExitBootServicesEvent = (EFI_EVENT)NULL;

+

+// The current period of the timer interrupt

+UINT64 mTimerPeriod = 0;

+

+// Cached copy of the Hardware Interrupt protocol instance

+EFI_HARDWARE_INTERRUPT_PROTOCOL *gInterrupt = NULL;

+

+// Cached interrupt vector

+UINTN  gVector;

+

+

+/**

+

+  C Interrupt Handler called in the interrupt context when Source interrupt is active.

+

+

+  @param Source         Source of the interrupt. Hardware routing off a specific platform defines

+                        what source means.

+

+  @param SystemContext  Pointer to system register context. Mostly used by debuggers and will

+                        update the system context after the return from the interrupt if

+                        modified. Don't change these values unless you know what you are doing

+

+**/

+VOID

+EFIAPI

+TimerInterruptHandler (

+  IN  HARDWARE_INTERRUPT_SOURCE   Source,

+  IN  EFI_SYSTEM_CONTEXT          SystemContext

+  )

+{

+  EFI_TPL OriginalTPL;

+

+  //

+  // DXE core uses this callback for the EFI timer tick. The DXE core uses locks

+  // that raise to TPL_HIGH and then restore back to current level. Thus we need

+  // to make sure TPL level is set to TPL_HIGH while we are handling the timer tick.

+  //

+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);

+

+  // If the interrupt is shared then we must check if this interrupt source is the one associated to this Timer

+  if (MmioRead32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_MSK_INT_STS_REG) != 0) {

+    // Clear the periodic interrupt

+    MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_INT_CLR_REG, 0);

+

+    // Signal end of interrupt early to help avoid losing subsequent ticks from long duration handlers

+    gInterrupt->EndOfInterrupt (gInterrupt, Source);

+

+    if (mTimerNotifyFunction) {

+      mTimerNotifyFunction (mTimerPeriod);

+    }

+  }

+

+  gBS->RestoreTPL (OriginalTPL);

+}

+

+/**

+  This function registers the handler NotifyFunction so it is called every time

+  the timer interrupt fires.  It also passes the amount of time since the last

+  handler call to the NotifyFunction.  If NotifyFunction is NULL, then the

+  handler is unregistered.  If the handler is registered, then EFI_SUCCESS is

+  returned.  If the CPU does not support registering a timer interrupt handler,

+  then EFI_UNSUPPORTED is returned.  If an attempt is made to register a handler

+  when a handler is already registered, then EFI_ALREADY_STARTED is returned.

+  If an attempt is made to unregister a handler when a handler is not registered,

+  then EFI_INVALID_PARAMETER is returned.  If an error occurs attempting to

+  register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR

+  is returned.

+

+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.

+  @param  NotifyFunction   The function to call when a timer interrupt fires. This

+                           function executes at TPL_HIGH_LEVEL. The DXE Core will

+                           register a handler for the timer interrupt, so it can know

+                           how much time has passed. This information is used to

+                           signal timer based events. NULL will unregister the handler.

+  @retval EFI_SUCCESS           The timer handler was registered.

+  @retval EFI_UNSUPPORTED       The platform does not support timer interrupts.

+  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already

+                                registered.

+  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not

+                                previously registered.

+  @retval EFI_DEVICE_ERROR      The timer handler could not be registered.

+

+**/

+EFI_STATUS

+EFIAPI

+TimerDriverRegisterHandler (

+  IN EFI_TIMER_ARCH_PROTOCOL  *This,

+  IN EFI_TIMER_NOTIFY         NotifyFunction

+  )

+{

+  if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {

+    return EFI_ALREADY_STARTED;

+  }

+

+  mTimerNotifyFunction = NotifyFunction;

+

+  return EFI_SUCCESS;

+}

+

+/**

+    Make sure all Dual Timers are disabled

+**/

+VOID

+EFIAPI

+ExitBootServicesEvent (

+  IN EFI_EVENT  Event,

+  IN VOID       *Context

+  )

+{

+  // Disable 'Periodic Operation' timer if enabled

+  if (MmioRead32(SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {

+    MmioAnd32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, 0);

+  }

+

+  // Disable 'Metronome/Delay' timer if enabled

+  if (MmioRead32(SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {

+    MmioAnd32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, 0);

+  }

+

+  // Disable 'Performance' timer if enabled

+  if (MmioRead32(SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) {

+    MmioAnd32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, 0);

+  }

+}

+

+/**

+

+  This function adjusts the period of timer interrupts to the value specified

+  by TimerPeriod.  If the timer period is updated, then the selected timer

+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If

+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.

+  If an error occurs while attempting to update the timer period, then the

+  timer hardware will be put back in its state prior to this call, and

+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt

+  is disabled.  This is not the same as disabling the CPU's interrupts.

+  Instead, it must either turn off the timer hardware, or it must adjust the

+  interrupt controller so that a CPU interrupt is not generated when the timer

+  interrupt fires.

+

+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.

+  @param  TimerPeriod      The rate to program the timer interrupt in 100 nS units. If

+                           the timer hardware is not programmable, then EFI_UNSUPPORTED is

+                           returned. If the timer is programmable, then the timer period

+                           will be rounded up to the nearest timer period that is supported

+                           by the timer hardware. If TimerPeriod is set to 0, then the

+                           timer interrupts will be disabled.

+

+

+  @retval EFI_SUCCESS           The timer period was changed.

+  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.

+  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.

+

+**/

+EFI_STATUS

+EFIAPI

+TimerDriverSetTimerPeriod (

+  IN EFI_TIMER_ARCH_PROTOCOL  *This,

+  IN UINT64                   TimerPeriod

+  )

+{

+  EFI_STATUS  Status;

+  UINT64      TimerTicks;

+

+  // always disable the timer

+  MmioAnd32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, ~SP804_TIMER_CTRL_ENABLE);

+

+  if (TimerPeriod == 0) {

+    // Leave timer disabled from above, and...

+

+    // Disable timer 0/1 interrupt for a TimerPeriod of 0

+    Status = gInterrupt->DisableInterruptSource (gInterrupt, gVector);

+  } else {

+    // Convert TimerPeriod into 1MHz clock counts (us units = 100ns units * 10)

+    TimerTicks = DivU64x32 (TimerPeriod, 10);

+    TimerTicks = MultU64x32 (TimerTicks, PcdGet32(PcdSP804TimerFrequencyInMHz));

+

+    // if it's larger than 32-bits, pin to highest value

+    if (TimerTicks > 0xffffffff) {

+      TimerTicks = 0xffffffff;

+    }

+

+    // Program the SP804 timer with the new count value

+    MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_LOAD_REG, TimerTicks);

+

+    // enable the timer

+    MmioOr32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);

+

+    // enable timer 0/1 interrupts

+    Status = gInterrupt->EnableInterruptSource (gInterrupt, gVector);

+  }

+

+  // Save the new timer period

+  mTimerPeriod = TimerPeriod;

+  return Status;

+}

+

+/**

+  This function retrieves the period of timer interrupts in 100 ns units,

+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod

+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is

+  returned, then the timer is currently disabled.

+

+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.

+  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If

+                           0 is returned, then the timer is currently disabled.

+

+

+  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.

+  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.

+

+**/

+EFI_STATUS

+EFIAPI

+TimerDriverGetTimerPeriod (

+  IN EFI_TIMER_ARCH_PROTOCOL   *This,

+  OUT UINT64                   *TimerPeriod

+  )

+{

+  if (TimerPeriod == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *TimerPeriod = mTimerPeriod;

+  return EFI_SUCCESS;

+}

+

+/**

+  This function generates a soft timer interrupt. If the platform does not support soft

+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.

+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()

+  service, then a soft timer interrupt will be generated. If the timer interrupt is

+  enabled when this service is called, then the registered handler will be invoked. The

+  registered handler should not be able to distinguish a hardware-generated timer

+  interrupt from a software-generated timer interrupt.

+

+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.

+

+  @retval EFI_SUCCESS           The soft timer interrupt was generated.

+  @retval EFI_UNSUPPORTED       The platform does not support the generation of soft timer interrupts.

+

+**/

+EFI_STATUS

+EFIAPI

+TimerDriverGenerateSoftInterrupt (

+  IN EFI_TIMER_ARCH_PROTOCOL  *This

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Interface structure for the Timer Architectural Protocol.

+

+  @par Protocol Description:

+  This protocol provides the services to initialize a periodic timer

+  interrupt, and to register a handler that is called each time the timer

+  interrupt fires.  It may also provide a service to adjust the rate of the

+  periodic timer interrupt.  When a timer interrupt occurs, the handler is

+  passed the amount of time that has passed since the previous timer

+  interrupt.

+

+  @param RegisterHandler

+  Registers a handler that will be called each time the

+  timer interrupt fires.  TimerPeriod defines the minimum

+  time between timer interrupts, so TimerPeriod will also

+  be the minimum time between calls to the registered

+  handler.

+

+  @param SetTimerPeriod

+  Sets the period of the timer interrupt in 100 nS units.

+  This function is optional, and may return EFI_UNSUPPORTED.

+  If this function is supported, then the timer period will

+  be rounded up to the nearest supported timer period.

+

+

+  @param GetTimerPeriod

+  Retrieves the period of the timer interrupt in 100 nS units.

+

+  @param GenerateSoftInterrupt

+  Generates a soft timer interrupt that simulates the firing of

+  the timer interrupt. This service can be used to invoke the   registered handler if the timer interrupt has been masked for

+  a period of time.

+

+**/

+EFI_TIMER_ARCH_PROTOCOL   gTimer = {

+  TimerDriverRegisterHandler,

+  TimerDriverSetTimerPeriod,

+  TimerDriverGetTimerPeriod,

+  TimerDriverGenerateSoftInterrupt

+};

+

+

+/**

+  Initialize the state information for the Timer Architectural Protocol and

+  the Timer Debug support protocol that allows the debugger to break into a

+  running program.

+

+  @param  ImageHandle   of the loaded driver

+  @param  SystemTable   Pointer to the System Table

+

+  @retval EFI_SUCCESS           Protocol registered

+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure

+  @retval EFI_DEVICE_ERROR      Hardware problems

+

+**/

+EFI_STATUS

+EFIAPI

+TimerInitialize (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_HANDLE  Handle = NULL;

+  EFI_STATUS  Status;

+

+  // Set the interrupt timer number

+  gVector = PcdGet32(PcdSP804TimerPeriodicInterruptNum);

+

+  // Find the interrupt controller protocol.  ASSERT if not found.

+  Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, (VOID **)&gInterrupt);

+  ASSERT_EFI_ERROR (Status);

+

+  // Disable the timer

+  Status = TimerDriverSetTimerPeriod (&gTimer, 0);

+  ASSERT_EFI_ERROR (Status);

+

+  // Install interrupt handler

+  Status = gInterrupt->RegisterInterruptSource (gInterrupt, gVector, TimerInterruptHandler);

+  ASSERT_EFI_ERROR (Status);

+

+  // configure timer 0 for periodic operation, 32 bits, no prescaler, and interrupt enabled

+  MmioWrite32 (SP804_TIMER_PERIODIC_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_PERIODIC | SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1 | SP804_TIMER_CTRL_INT_ENABLE);

+

+  // Set up default timer

+  Status = TimerDriverSetTimerPeriod (&gTimer, FixedPcdGet32(PcdTimerPeriod)); // TIMER_DEFAULT_PERIOD

+  ASSERT_EFI_ERROR (Status);

+

+  // Install the Timer Architectural Protocol onto a new handle

+  Status = gBS->InstallMultipleProtocolInterfaces(

+                  &Handle,

+                  &gEfiTimerArchProtocolGuid,      &gTimer,

+                  NULL

+                  );

+  ASSERT_EFI_ERROR(Status);

+

+  // Register for an ExitBootServicesEvent

+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf
new file mode 100644
index 0000000..386d964
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf
@@ -0,0 +1,59 @@
+#/** @file

+#

+#    Component description file for Timer module

+#

+#  Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmVeTimerDxe

+  FILE_GUID                      = a73d663d-a491-4278-9a69-9521be3379f2

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = TimerInitialize

+

+[Sources.common]

+  SP804Timer.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  UefiRuntimeServicesTableLib

+  UefiLib

+  UefiBootServicesTableLib

+  BaseMemoryLib

+  DebugLib

+  UefiDriverEntryPoint

+  IoLib

+

+[Guids]

+

+[Protocols]

+  gEfiTimerArchProtocolGuid

+  gHardwareInterruptProtocolGuid

+

+[Pcd.common]

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerFrequencyInMHz

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicInterruptNum

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPeriodicBase

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase

+  gEmbeddedTokenSpaceGuid.PcdTimerPeriod

+

+[Depex]

+  gHardwareInterruptProtocolGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c
new file mode 100644
index 0000000..c78d2b9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c
@@ -0,0 +1,387 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+

+#include <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+#include <Library/UefiLib.h>

+

+#include <Protocol/WatchdogTimer.h>

+#include <Drivers/SP805Watchdog.h>

+

+EFI_EVENT                           EfiExitBootServicesEvent = (EFI_EVENT)NULL;

+

+/**

+  Make sure the SP805 registers are unlocked for writing.

+

+  Note: The SP805 Watchdog Timer supports locking of its registers,

+  i.e. it inhibits all writes to avoid rogue software accidentally

+  corrupting their contents.

+**/

+STATIC

+VOID

+SP805Unlock (

+  VOID

+  )

+{

+  if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_LOCKED ) {

+    MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_SPECIAL_UNLOCK_CODE);

+  }

+}

+

+/**

+  Make sure the SP805 registers are locked and can not be overwritten.

+

+  Note: The SP805 Watchdog Timer supports locking of its registers,

+  i.e. it inhibits all writes to avoid rogue software accidentally

+  corrupting their contents.

+**/

+STATIC

+VOID

+SP805Lock (

+  VOID

+  )

+{

+  if( MmioRead32(SP805_WDOG_LOCK_REG) == SP805_WDOG_LOCK_IS_UNLOCKED ) {

+    // To lock it, just write in any number (except the special unlock code).

+    MmioWrite32(SP805_WDOG_LOCK_REG, SP805_WDOG_LOCK_IS_LOCKED);

+  }

+}

+

+/**

+  Stop the SP805 watchdog timer from counting down by disabling interrupts.

+**/

+STATIC

+VOID

+SP805Stop (

+  VOID

+  )

+{

+  // Disable interrupts

+  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) != 0 ) {

+    MmioAnd32(SP805_WDOG_CONTROL_REG, ~SP805_WDOG_CTRL_INTEN);

+  }

+}

+

+/**

+  Starts the SP805 counting down by enabling interrupts.

+  The count down will start from the value stored in the Load register,

+  not from the value where it was previously stopped.

+**/

+STATIC

+VOID

+SP805Start (

+  VOID

+  )

+{

+  // Enable interrupts

+  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {

+    MmioOr32(SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_INTEN);

+  }

+}

+

+/**

+    On exiting boot services we must make sure the SP805 Watchdog Timer

+    is stopped.

+**/

+VOID

+EFIAPI

+ExitBootServicesEvent (

+  IN EFI_EVENT  Event,

+  IN VOID       *Context

+  )

+{

+  SP805Unlock();

+  SP805Stop();

+  SP805Lock();

+}

+

+/**

+  This function registers the handler NotifyFunction so it is called every time

+  the watchdog timer expires.  It also passes the amount of time since the last

+  handler call to the NotifyFunction.

+  If NotifyFunction is not NULL and a handler is not already registered,

+  then the new handler is registered and EFI_SUCCESS is returned.

+  If NotifyFunction is NULL, and a handler is already registered,

+  then that handler is unregistered.

+  If an attempt is made to register a handler when a handler is already registered,

+  then EFI_ALREADY_STARTED is returned.

+  If an attempt is made to unregister a handler when a handler is not registered,

+  then EFI_INVALID_PARAMETER is returned.

+

+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.

+  @param  NotifyFunction   The function to call when a timer interrupt fires. This

+                           function executes at TPL_HIGH_LEVEL. The DXE Core will

+                           register a handler for the timer interrupt, so it can know

+                           how much time has passed. This information is used to

+                           signal timer based events. NULL will unregister the handler.

+

+  @retval EFI_SUCCESS           The watchdog timer handler was registered.

+  @retval EFI_ALREADY_STARTED   NotifyFunction is not NULL, and a handler is already

+                                registered.

+  @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not

+                                previously registered.

+

+**/

+EFI_STATUS

+EFIAPI

+SP805RegisterHandler (

+  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,

+  IN EFI_WATCHDOG_TIMER_NOTIFY                NotifyFunction

+  )

+{

+  // ERROR: This function is not supported.

+  // The hardware watchdog will reset the board

+  return EFI_INVALID_PARAMETER;

+}

+

+/**

+

+  This function adjusts the period of timer interrupts to the value specified

+  by TimerPeriod.  If the timer period is updated, then the selected timer

+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If

+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.

+  If an error occurs while attempting to update the timer period, then the

+  timer hardware will be put back in its state prior to this call, and

+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt

+  is disabled.  This is not the same as disabling the CPU's interrupts.

+  Instead, it must either turn off the timer hardware, or it must adjust the

+  interrupt controller so that a CPU interrupt is not generated when the timer

+  interrupt fires.

+

+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.

+  @param  TimerPeriod      The rate to program the timer interrupt in 100 nS units. If

+                           the timer hardware is not programmable, then EFI_UNSUPPORTED is

+                           returned. If the timer is programmable, then the timer period

+                           will be rounded up to the nearest timer period that is supported

+                           by the timer hardware. If TimerPeriod is set to 0, then the

+                           timer interrupts will be disabled.

+

+

+  @retval EFI_SUCCESS           The timer period was changed.

+  @retval EFI_UNSUPPORTED       The platform cannot change the period of the timer interrupt.

+  @retval EFI_DEVICE_ERROR      The timer period could not be changed due to a device error.

+

+**/

+EFI_STATUS

+EFIAPI

+SP805SetTimerPeriod (

+  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,

+  IN UINT64                                   TimerPeriod   // In 100ns units

+  )

+{

+  EFI_STATUS  Status = EFI_SUCCESS;

+  UINT64      Ticks64bit;

+

+  SP805Unlock();

+

+  if( TimerPeriod == 0 ) {

+    // This is a watchdog stop request

+    SP805Stop();

+    goto EXIT;

+  } else {

+    // Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds

+    // The SP805 will count down to ZERO once, generate an interrupt and

+    // then it will again reload the initial value and start again.

+    // On the second time when it reaches ZERO, it will actually reset the board.

+    // Therefore, we need to load half the required delay.

+    //

+    // WatchdogTicks = ((TimerPeriod * 100 * SP805_CLOCK_FREQUENCY) / 1GHz) / 2 ;

+    //

+    // i.e.:

+    //

+    // WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;

+

+    Ticks64bit = DivU64x32(MultU64x32(TimerPeriod, (UINTN)PcdGet32(PcdSP805WatchdogClockFrequencyInHz)), 20000000);

+

+    // The registers in the SP805 are only 32 bits

+    if(Ticks64bit > (UINT64)0xFFFFFFFF) {

+      // We could load the watchdog with the maximum supported value but

+      // if a smaller value was requested, this could have the watchdog

+      // triggering before it was intended.

+      // Better generate an error to let the caller know.

+      Status = EFI_DEVICE_ERROR;

+      goto EXIT;

+    }

+

+    // Update the watchdog with a 32-bit value.

+    MmioWrite32(SP805_WDOG_LOAD_REG, (UINT32)Ticks64bit);

+

+    // Start the watchdog

+    SP805Start();

+  }

+

+  EXIT:

+  // Ensure the watchdog is locked before exiting.

+  SP805Lock();

+  return Status;

+}

+

+/**

+  This function retrieves the period of timer interrupts in 100 ns units,

+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod

+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is

+  returned, then the timer is currently disabled.

+

+  @param  This             The EFI_TIMER_ARCH_PROTOCOL instance.

+  @param  TimerPeriod      A pointer to the timer period to retrieve in 100 ns units. If

+                           0 is returned, then the timer is currently disabled.

+

+

+  @retval EFI_SUCCESS           The timer period was returned in TimerPeriod.

+  @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.

+

+**/

+EFI_STATUS

+EFIAPI

+SP805GetTimerPeriod (

+  IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL   *This,

+  OUT UINT64                                  *TimerPeriod

+  )

+{

+  EFI_STATUS  Status = EFI_SUCCESS;

+  UINT64      ReturnValue;

+

+  if (TimerPeriod == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Check if the watchdog is stopped

+  if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {

+    // It is stopped, so return zero.

+    ReturnValue = 0;

+  } else {

+    // Convert the Watchdog ticks into TimerPeriod

+    // Ensure 64bit arithmetic throughout because the Watchdog ticks may already

+    // be at the maximum 32 bit value and we still need to multiply that by 600.

+    ReturnValue = MultU64x32( MmioRead32(SP805_WDOG_LOAD_REG), 600 );

+  }

+

+  *TimerPeriod = ReturnValue;

+

+  return Status;

+}

+

+/**

+  Interface structure for the Watchdog Architectural Protocol.

+

+  @par Protocol Description:

+  This protocol provides a service to set the amount of time to wait

+  before firing the watchdog timer, and it also provides a service to

+  register a handler that is invoked when the watchdog timer fires.

+

+  @par When the watchdog timer fires, control will be passed to a handler

+  if one has been registered.  If no handler has been registered,

+  or the registered handler returns, then the system will be

+  reset by calling the Runtime Service ResetSystem().

+

+  @param RegisterHandler

+  Registers a handler that will be called each time the

+  watchdogtimer interrupt fires.  TimerPeriod defines the minimum

+  time between timer interrupts, so TimerPeriod will also

+  be the minimum time between calls to the registered

+  handler.

+  NOTE: If the watchdog resets the system in hardware, then

+        this function will not have any chance of executing.

+

+  @param SetTimerPeriod

+  Sets the period of the timer interrupt in 100 nS units.

+  This function is optional, and may return EFI_UNSUPPORTED.

+  If this function is supported, then the timer period will

+  be rounded up to the nearest supported timer period.

+

+  @param GetTimerPeriod

+  Retrieves the period of the timer interrupt in 100 nS units.

+

+**/

+EFI_WATCHDOG_TIMER_ARCH_PROTOCOL    gWatchdogTimer = {

+  (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) SP805RegisterHandler,

+  (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) SP805SetTimerPeriod,

+  (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) SP805GetTimerPeriod

+};

+

+/**

+  Initialize the state information for the Watchdog Timer Architectural Protocol.

+

+  @param  ImageHandle   of the loaded driver

+  @param  SystemTable   Pointer to the System Table

+

+  @retval EFI_SUCCESS           Protocol registered

+  @retval EFI_OUT_OF_RESOURCES  Cannot allocate protocol data structure

+  @retval EFI_DEVICE_ERROR      Hardware problems

+

+**/

+EFI_STATUS

+EFIAPI

+SP805Initialize (

+  IN EFI_HANDLE         ImageHandle,

+  IN EFI_SYSTEM_TABLE   *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+  EFI_HANDLE  Handle;

+

+  // Unlock access to the SP805 registers

+  SP805Unlock ();

+

+  // Stop the watchdog from triggering unexpectedly

+  SP805Stop ();

+

+  // Set the watchdog to reset the board when triggered

+  if ((MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_RESEN) == 0) {

+    MmioOr32 (SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_RESEN);

+  }

+

+  // Prohibit any rogue access to SP805 registers

+  SP805Lock();

+

+  //

+  // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.

+  // This will avoid conflicts with the universal watchdog

+  //

+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);

+

+  // Register for an ExitBootServicesEvent

+  Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);

+  if (EFI_ERROR(Status)) {

+    Status = EFI_OUT_OF_RESOURCES;

+    goto EXIT;

+  }

+

+  // Install the Timer Architectural Protocol onto a new handle

+  Handle = NULL;

+  Status = gBS->InstallMultipleProtocolInterfaces(

+                  &Handle,

+                  &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,

+                  NULL

+                  );

+  if (EFI_ERROR(Status)) {

+    Status = EFI_OUT_OF_RESOURCES;

+    goto EXIT;

+  }

+

+EXIT:

+  if(EFI_ERROR(Status)) {

+    // The watchdog failed to initialize

+    ASSERT(FALSE);

+  }

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf
new file mode 100644
index 0000000..37924f2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805WatchdogDxe.inf
@@ -0,0 +1,52 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = SP805WatchdogDxe

+  FILE_GUID                      = ebd705fb-fa92-46a7-b32b-7f566d944614

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = SP805Initialize

+

+[Sources.common]

+  SP805Watchdog.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  BaseMemoryLib

+  DebugLib

+  IoLib

+  PcdLib

+  UefiLib

+  UefiBootServicesTableLib

+  UefiDriverEntryPoint

+  UefiRuntimeServicesTableLib

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase

+  gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz

+

+[Protocols]

+  gEfiWatchdogTimerArchProtocolGuid

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf
new file mode 100644
index 0000000..b42d205
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFs.inf
@@ -0,0 +1,61 @@
+#/** @file

+#  Support for ARM Boot Monitor File System

+#

+#  Copyright (c) 2012-2015, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = BootMonFs

+  FILE_GUID                      = 7abbc454-f737-4322-931c-b1bb62a01d6f

+  MODULE_TYPE                    = UEFI_DRIVER

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = BootMonFsEntryPoint

+

+[Sources]

+  BootMonFsEntryPoint.c

+  BootMonFsOpenClose.c

+  BootMonFsDir.c

+  BootMonFsImages.c

+  BootMonFsReadWrite.c

+  BootMonFsUnsupported.c

+

+[Packages]

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DevicePathLib

+  MemoryAllocationLib

+  PrintLib

+  UefiDriverEntryPoint

+  UefiLib

+

+[Guids]

+  gArmBootMonFsFileInfoGuid

+  gEfiFileSystemInfoGuid

+  gEfiFileInfoGuid

+  gEfiFileSystemVolumeLabelInfoIdGuid

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdBootMonFsSupportedDevicePaths

+

+[Protocols]

+  gEfiDiskIoProtocolGuid

+  gEfiBlockIoProtocolGuid

+  gEfiSimpleFileSystemProtocolGuid

+  gEfiDevicePathProtocolGuid

+  gEfiDevicePathFromTextProtocolGuid

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h
new file mode 100644
index 0000000..d690520
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h
@@ -0,0 +1,388 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#ifndef __BOOTMON_FS_API_H

+#define __BOOTMON_FS_API_H

+

+#include <Protocol/SimpleFileSystem.h>

+

+EFI_STATUS

+BootMonFsInitialize (

+  IN BOOTMON_FS_INSTANCE *Instance

+  );

+

+UINT32

+BootMonFsChecksum (

+  IN VOID   *Data,

+  IN UINT32 Size

+  );

+

+EFI_STATUS

+BootMonFsComputeFooterChecksum (

+  IN OUT HW_IMAGE_DESCRIPTION *Footer

+  );

+

+EFIAPI

+EFI_STATUS

+OpenBootMonFsOpenVolume (

+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,

+  OUT EFI_FILE_PROTOCOL              **Root

+  );

+

+UINT32

+BootMonFsGetImageLength (

+  IN BOOTMON_FS_FILE      *File

+  );

+

+UINTN

+BootMonFsGetPhysicalSize (

+  IN BOOTMON_FS_FILE* File

+  );

+

+EFI_STATUS

+BootMonFsCreateFile (

+  IN  BOOTMON_FS_INSTANCE *Instance,

+  OUT BOOTMON_FS_FILE     **File

+  );

+

+EFIAPI

+EFI_STATUS

+BootMonFsGetInfo (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN EFI_GUID           *InformationType,

+  IN OUT UINTN          *BufferSize,

+  OUT VOID              *Buffer

+  );

+

+EFIAPI

+EFI_STATUS

+BootMonFsReadDirectory (

+  IN EFI_FILE_PROTOCOL    *This,

+  IN OUT UINTN            *BufferSize,

+  OUT VOID                *Buffer

+  );

+

+EFIAPI

+EFI_STATUS

+BootMonFsFlushDirectory (

+  IN EFI_FILE_PROTOCOL  *This

+  );

+

+/**

+  Flush all modified data associated with a file to a device.

+

+  @param[in]  This  A pointer to the EFI_FILE_PROTOCOL instance that is the

+                    file handle to flush.

+

+  @retval  EFI_SUCCESS            The data was flushed.

+  @retval  EFI_ACCESS_DENIED      The file was opened read-only.

+  @retval  EFI_DEVICE_ERROR       The device reported an error.

+  @retval  EFI_VOLUME_FULL        The volume is full.

+  @retval  EFI_OUT_OF_RESOURCES   Not enough resources were available to flush the data.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsFlushFile (

+  IN EFI_FILE_PROTOCOL  *This

+  );

+

+/**

+  Close a specified file handle.

+

+  @param[in]  This  A pointer to the EFI_FILE_PROTOCOL instance that is the file

+                    handle to close.

+

+  @retval  EFI_SUCCESS            The file was closed.

+  @retval  EFI_INVALID_PARAMETER  The parameter "This" is NULL or is not an open

+                                  file handle.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsCloseFile (

+  IN EFI_FILE_PROTOCOL  *This

+  );

+

+/**

+  Open a file on the boot monitor file system.

+

+  The boot monitor file system does not allow for sub-directories. There is only

+  one directory, the root one. On any attempt to create a directory, the function

+  returns in error with the EFI_WRITE_PROTECTED error code.

+

+  @param[in]   This        A pointer to the EFI_FILE_PROTOCOL instance that is

+                           the file handle to source location.

+  @param[out]  NewHandle   A pointer to the location to return the opened

+                           handle for the new file.

+  @param[in]   FileName    The Null-terminated string of the name of the file

+                           to be opened.

+  @param[in]   OpenMode    The mode to open the file : Read or Read/Write or

+                           Read/Write/Create

+  @param[in]   Attributes  Attributes of the file in case of a file creation

+

+  @retval  EFI_SUCCESS            The file was open.

+  @retval  EFI_NOT_FOUND          The specified file could not be found or the specified

+                                  directory in which to create a file could not be found.

+  @retval  EFI_DEVICE_ERROR       The device reported an error.

+  @retval  EFI_WRITE_PROTECTED    Attempt to create a directory. This is not possible

+                                  with the Boot Monitor file system.

+  @retval  EFI_OUT_OF_RESOURCES   Not enough resources were available to open the file.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsOpenFile (

+  IN EFI_FILE_PROTOCOL  *This,

+  OUT EFI_FILE_PROTOCOL **NewHandle,

+  IN CHAR16             *FileName,

+  IN UINT64             OpenMode,

+  IN UINT64             Attributes

+  );

+

+/**

+  Read data from an open file.

+

+  @param[in]      This        A pointer to the EFI_FILE_PROTOCOL instance that

+                              is the file handle to read data from.

+  @param[in out]  BufferSize  On input, the size of the Buffer. On output, the

+                              amount of data returned in Buffer. In both cases,

+                              the size is measured in bytes.

+  @param[out]     Buffer      The buffer into which the data is read.

+

+  @retval  EFI_SUCCESS            The data was read.

+  @retval  EFI_DEVICE_ERROR       On entry, the current file position is

+                                  beyond the end of the file, or the device

+                                  reported an error while performing the read

+                                  operation.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsReadFile (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN OUT UINTN          *BufferSize,

+  OUT VOID              *Buffer

+  );

+

+EFIAPI

+EFI_STATUS

+BootMonFsSetDirPosition (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN UINT64             Position

+  );

+

+EFIAPI

+EFI_STATUS

+BootMonFsGetPosition (

+  IN EFI_FILE_PROTOCOL  *This,

+  OUT UINT64            *Position

+  );

+

+/**

+  Write data to an open file.

+

+  The data is not written to the flash yet. It will be written when the file

+  will be either read, closed or flushed.

+

+  @param[in]      This        A pointer to the EFI_FILE_PROTOCOL instance that

+                              is the file handle to write data to.

+  @param[in out]  BufferSize  On input, the size of the Buffer. On output, the

+                              size of the data actually written. In both cases,

+                              the size is measured in bytes.

+  @param[in]      Buffer      The buffer of data to write.

+

+  @retval  EFI_SUCCESS            The data was written.

+  @retval  EFI_ACCESS_DENIED      The file was opened read only.

+  @retval  EFI_OUT_OF_RESOURCES   Unable to allocate the buffer to store the

+                                  data to write.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsWriteFile (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN OUT UINTN          *BufferSize,

+  IN VOID               *Buffer

+  );

+

+EFIAPI

+EFI_STATUS

+BootMonFsDeleteFail (

+  IN EFI_FILE_PROTOCOL *This

+  );

+

+/**

+  Close and delete a file from the boot monitor file system.

+

+  @param[in]  This  A pointer to the EFI_FILE_PROTOCOL instance that is the file

+                    handle to delete.

+

+  @retval  EFI_SUCCESS              The file was closed and deleted.

+  @retval  EFI_INVALID_PARAMETER    The parameter "This" is NULL or is not an open

+                                    file handle.

+  @retval  EFI_WARN_DELETE_FAILURE  The handle was closed, but the file was not deleted.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsDelete (

+  IN EFI_FILE_PROTOCOL *This

+  );

+

+/**

+  Set a file's current position.

+

+  @param[in]  This      A pointer to the EFI_FILE_PROTOCOL instance that is

+                        the file handle to set the requested position on.

+  @param[in]  Position  The byte position from the start of the file to set.

+

+  @retval  EFI_SUCCESS            The position was set.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsSetPosition (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN UINT64             Position

+  );

+

+/**

+  Return a file's current position.

+

+  @param[in]   This      A pointer to the EFI_FILE_PROTOCOL instance that is

+                         the file handle to get the current position on.

+  @param[out]  Position  The address to return the file's current position value.

+

+  @retval  EFI_SUCCESS            The position was returned.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsGetPosition(

+  IN EFI_FILE_PROTOCOL  *This,

+  OUT UINT64            *Position

+  );

+

+//

+// UNSUPPORTED OPERATIONS

+//

+

+EFIAPI

+EFI_STATUS

+BootMonFsGetPositionUnsupported (

+  IN EFI_FILE_PROTOCOL  *This,

+  OUT UINT64            *Position

+  );

+

+/**

+  Set information about a file or a volume.

+

+  @param[in]  This             A pointer to the EFI_FILE_PROTOCOL instance that

+                               is the file handle the information is for.

+  @param[in]  InformationType  The type identifier for the information being set :

+                               EFI_FILE_INFO_ID or EFI_FILE_SYSTEM_INFO_ID or

+                               EFI_FILE_SYSTEM_VOLUME_LABEL_ID

+  @param[in]  BufferSize       The size, in bytes, of Buffer.

+  @param[in]  Buffer           A pointer to the data buffer to write. The type of the

+                               data inside the buffer is indicated by InformationType.

+

+  @retval  EFI_SUCCESS            The information was set.

+  @retval  EFI_UNSUPPORTED        The InformationType is not known.

+  @retval  EFI_DEVICE_ERROR       The last issued semi-hosting operation failed.

+  @retval  EFI_ACCESS_DENIED      An attempt is made to change the name of a file

+                                  to a file that is already present.

+  @retval  EFI_ACCESS_DENIED      An attempt is being made to change the

+                                  EFI_FILE_DIRECTORY Attribute.

+  @retval  EFI_ACCESS_DENIED      InformationType is EFI_FILE_INFO_ID and

+                                  the file was opened in read-only mode and an

+                                  attempt is being made to modify a field other

+                                  than Attribute.

+  @retval  EFI_WRITE_PROTECTED    An attempt is being made to modify a read-only

+                                  attribute.

+  @retval  EFI_BAD_BUFFER_SIZE    The size of the buffer is lower than that indicated by

+                                  the data inside the buffer.

+  @retval  EFI_OUT_OF_RESOURCES   A allocation needed to process the request failed.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsSetInfo (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN EFI_GUID           *InformationType,

+  IN UINTN              BufferSize,

+  IN VOID               *Buffer

+  );

+

+//

+// Directory API

+//

+

+EFI_STATUS

+BootMonFsOpenDirectory (

+  OUT EFI_FILE_PROTOCOL **NewHandle,

+  IN CHAR16             *FileName,

+  IN BOOTMON_FS_INSTANCE *Volume

+  );

+

+//

+// Internal API

+//

+

+/**

+  Search for a file given its name coded in Ascii.

+

+  When searching through the files of the volume, if a file is currently not

+  open, its name was written on the media and is kept in RAM in the

+  "HwDescription.Footer.Filename[]" field of the file's description.

+

+  If a file is currently open, its name might not have been written on the

+  media yet, and as the "HwDescription" is a mirror in RAM of what is on the

+  media the "HwDescription.Footer.Filename[]" might be outdated. In that case,

+  the up to date name of the file is stored in the "Info" field of the file's

+  description.

+

+  @param[in]   Instance       Pointer to the description of the volume in which

+                              the file has to be search for.

+  @param[in]   AsciiFileName  Name of the file.

+

+  @param[out]  File           Pointer to the description of the file if the

+                              file was found.

+

+  @retval  EFI_SUCCESS    The file was found.

+  @retval  EFI_NOT_FOUND  The file was not found.

+

+**/

+EFI_STATUS

+BootMonGetFileFromAsciiFileName (

+  IN  BOOTMON_FS_INSTANCE   *Instance,

+  IN  CHAR8*                AsciiFileName,

+  OUT BOOTMON_FS_FILE       **File

+  );

+

+EFI_STATUS

+BootMonGetFileFromPosition (

+  IN  BOOTMON_FS_INSTANCE   *Instance,

+  IN  UINTN                 Position,

+  OUT BOOTMON_FS_FILE       **File

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c
new file mode 100644
index 0000000..450a707
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsDir.c
@@ -0,0 +1,768 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#include "BootMonFsInternal.h"

+

+EFIAPI

+EFI_STATUS

+OpenBootMonFsOpenVolume (

+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,

+  OUT EFI_FILE_PROTOCOL              **Root

+  )

+{

+  BOOTMON_FS_INSTANCE *Instance;

+

+  Instance = BOOTMON_FS_FROM_FS_THIS (This);

+  if (Instance == NULL) {

+    return EFI_DEVICE_ERROR;

+  }

+

+  Instance->RootFile->Info->Attribute = EFI_FILE_READ_ONLY | EFI_FILE_DIRECTORY;

+

+  *Root = &Instance->RootFile->File;

+

+  return EFI_SUCCESS;

+}

+

+UINT32

+BootMonFsGetImageLength (

+  IN BOOTMON_FS_FILE      *File

+  )

+{

+  UINT32                   Index;

+  UINT32                   FileSize;

+  LIST_ENTRY              *RegionToFlushLink;

+  BOOTMON_FS_FILE_REGION  *Region;

+

+  FileSize = 0;

+

+  // Look at all Flash areas to determine file size

+  for (Index = 0; Index < HW_IMAGE_DESCRIPTION_REGION_MAX; Index++) {

+    FileSize += File->HwDescription.Region[Index].Size;

+  }

+

+  // Add the regions that have not been flushed yet

+  for (RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);

+       !IsNull (&File->RegionToFlushLink, RegionToFlushLink);

+       RegionToFlushLink = GetNextNode (&File->RegionToFlushLink, RegionToFlushLink)

+       )

+  {

+    Region = (BOOTMON_FS_FILE_REGION*)RegionToFlushLink;

+    if (Region->Offset + Region->Size > FileSize) {

+      FileSize += Region->Offset + Region->Size;

+    }

+  }

+

+  return FileSize;

+}

+

+UINTN

+BootMonFsGetPhysicalSize (

+  IN BOOTMON_FS_FILE* File

+  )

+{

+  // Return 0 for files that haven't yet been flushed to media

+  if (File->HwDescription.RegionCount == 0) {

+    return 0;

+  }

+

+  return ((File->HwDescription.BlockEnd - File->HwDescription.BlockStart) + 1 )

+          * File->Instance->Media->BlockSize;

+}

+

+EFIAPI

+EFI_STATUS

+BootMonFsSetDirPosition (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN UINT64             Position

+  )

+{

+  BOOTMON_FS_FILE       *File;

+

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // UEFI Spec section 12.5:

+  // "The seek request for nonzero is not valid on open directories."

+  if (Position != 0) {

+    return EFI_UNSUPPORTED;

+  }

+  File->Position = Position;

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+BootMonFsOpenDirectory (

+  OUT EFI_FILE_PROTOCOL **NewHandle,

+  IN CHAR16             *FileName,

+  IN BOOTMON_FS_INSTANCE *Volume

+  )

+{

+  ASSERT(0);

+

+  return EFI_UNSUPPORTED;

+}

+

+STATIC

+EFI_STATUS

+GetFileSystemVolumeLabelInfo (

+  IN BOOTMON_FS_INSTANCE *Instance,

+  IN OUT UINTN          *BufferSize,

+  OUT VOID              *Buffer

+  )

+{

+  UINTN                         Size;

+  EFI_FILE_SYSTEM_VOLUME_LABEL *Label;

+  EFI_STATUS                    Status;

+

+  Label = Buffer;

+

+  // Value returned by StrSize includes null terminator.

+  Size = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL

+         + StrSize (Instance->FsInfo.VolumeLabel);

+

+  if (*BufferSize >= Size) {

+    CopyMem (&Label->VolumeLabel, &Instance->FsInfo.VolumeLabel, Size);

+    Status = EFI_SUCCESS;

+  } else {

+    Status = EFI_BUFFER_TOO_SMALL;

+  }

+  *BufferSize = Size;

+  return Status;

+}

+

+// Helper function that calculates a rough "free space" by:

+// - Taking the media size

+// - Subtracting the sum of all file sizes

+// - Subtracting the block size times the number of files

+//    (To account for the blocks containing the HW_IMAGE_INFO

+STATIC

+UINT64

+ComputeFreeSpace (

+  IN BOOTMON_FS_INSTANCE *Instance

+  )

+{

+  LIST_ENTRY   *FileLink;

+  UINT64        FileSizeSum;

+  UINT64        MediaSize;

+  UINTN         NumFiles;

+  EFI_BLOCK_IO_MEDIA *Media;

+  BOOTMON_FS_FILE *File;

+

+  Media = Instance->BlockIo->Media;

+  MediaSize = Media->BlockSize * (Media->LastBlock + 1);

+

+  NumFiles = 0;

+  FileSizeSum = 0;

+  for (FileLink = GetFirstNode (&Instance->RootFile->Link);

+         !IsNull (&Instance->RootFile->Link, FileLink);

+         FileLink = GetNextNode (&Instance->RootFile->Link, FileLink)

+         )

+  {

+    File = BOOTMON_FS_FILE_FROM_LINK_THIS (FileLink);

+    FileSizeSum += BootMonFsGetImageLength (File);

+

+    NumFiles++;

+  }

+

+  return MediaSize - (FileSizeSum + (Media->BlockSize + NumFiles));

+}

+

+STATIC

+EFI_STATUS

+GetFilesystemInfo (

+  IN BOOTMON_FS_INSTANCE *Instance,

+  IN OUT UINTN          *BufferSize,

+  OUT VOID              *Buffer

+  )

+{

+  EFI_STATUS              Status;

+

+  if (*BufferSize >= Instance->FsInfo.Size) {

+    Instance->FsInfo.FreeSpace = ComputeFreeSpace (Instance);

+    CopyMem (Buffer, &Instance->FsInfo, Instance->FsInfo.Size);

+    Status = EFI_SUCCESS;

+  } else {

+    Status = EFI_BUFFER_TOO_SMALL;

+  }

+

+  *BufferSize = Instance->FsInfo.Size;

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+GetFileInfo (

+  IN BOOTMON_FS_INSTANCE  *Instance,

+  IN BOOTMON_FS_FILE      *File,

+  IN OUT UINTN            *BufferSize,

+  OUT VOID                *Buffer

+  )

+{

+  EFI_FILE_INFO  *Info;

+  UINTN          ResultSize;

+

+  ResultSize = SIZE_OF_EFI_FILE_INFO + StrSize (File->Info->FileName);

+

+  if (*BufferSize < ResultSize) {

+    *BufferSize = ResultSize;

+    return EFI_BUFFER_TOO_SMALL;

+  }

+

+  Info = Buffer;

+

+  CopyMem (Info, File->Info, ResultSize);

+  // Size of the information

+  Info->Size = ResultSize;

+

+  *BufferSize = ResultSize;

+

+  return EFI_SUCCESS;

+}

+

+STATIC

+EFI_STATUS

+GetBootMonFsFileInfo (

+  IN BOOTMON_FS_INSTANCE *Instance,

+  IN BOOTMON_FS_FILE     *File,

+  IN OUT UINTN           *BufferSize,

+  OUT VOID               *Buffer

+  )

+{

+  EFI_STATUS             Status;

+  BOOTMON_FS_FILE_INFO   *Info;

+  UINTN                  ResultSize;

+  UINTN                  Index;

+

+  if (File == Instance->RootFile) {

+    Status = EFI_UNSUPPORTED;

+  } else {

+    ResultSize = SIZE_OF_BOOTMON_FS_FILE_INFO;

+

+    if (*BufferSize < ResultSize) {

+      *BufferSize = ResultSize;

+      Status = EFI_BUFFER_TOO_SMALL;

+    } else {

+      Info = Buffer;

+

+      // Zero out the structure

+      ZeroMem (Info, ResultSize);

+

+      // Fill in the structure

+      Info->Size = ResultSize;

+

+      Info->EntryPoint  = File->HwDescription.EntryPoint;

+      Info->RegionCount = File->HwDescription.RegionCount;

+      for (Index = 0; Index < File->HwDescription.RegionCount; Index++) {

+        Info->Region[Index].LoadAddress = File->HwDescription.Region[Index].LoadAddress;

+        Info->Region[Index].Size        = File->HwDescription.Region[Index].Size;

+        Info->Region[Index].Offset      = File->HwDescription.Region[Index].Offset;

+        Info->Region[Index].Checksum    = File->HwDescription.Region[Index].Checksum;

+      }

+      *BufferSize = ResultSize;

+      Status = EFI_SUCCESS;

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Set the name of a file.

+

+  This is a helper function for SetFileInfo().

+

+  @param[in]  Instance  A pointer to the description of the volume

+                        the file belongs to.

+  @param[in]  File      A pointer to the description of the file.

+  @param[in]  FileName  A pointer to the new name of the file.

+

+  @retval  EFI_SUCCESS        The name was set.

+  @retval  EFI_ACCESS_DENIED  An attempt is made to change the name of a file

+                              to a file that is already present.

+

+**/

+STATIC

+EFI_STATUS

+SetFileName (

+  IN  BOOTMON_FS_INSTANCE  *Instance,

+  IN  BOOTMON_FS_FILE      *File,

+  IN  CONST CHAR16         *FileName

+  )

+{

+  CHAR16           TruncFileName[MAX_NAME_LENGTH];

+  CHAR8            AsciiFileName[MAX_NAME_LENGTH];

+  BOOTMON_FS_FILE  *SameFile;

+

+  // If the file path start with a \ strip it. The EFI Shell may

+  // insert a \ in front of the file name.

+  if (FileName[0] == L'\\') {

+    FileName++;

+  }

+

+  StrnCpy (TruncFileName, FileName, MAX_NAME_LENGTH - 1);

+  TruncFileName[MAX_NAME_LENGTH - 1] = 0;

+  UnicodeStrToAsciiStr (TruncFileName, AsciiFileName);

+

+  if (BootMonGetFileFromAsciiFileName (

+        File->Instance,

+        AsciiFileName,

+        &SameFile

+        ) != EFI_NOT_FOUND) {

+    // A file with that name already exists.

+    return EFI_ACCESS_DENIED;

+  } else {

+    // OK, change the filename.

+    AsciiStrToUnicodeStr (AsciiFileName, File->Info->FileName);

+    return EFI_SUCCESS;

+  }

+}

+

+/**

+  Set the size of a file.

+

+  This is a helper function for SetFileInfo().

+

+  @param[in]  Instance  A pointer to the description of the volume

+                        the file belongs to.

+  @param[in]  File      A pointer to the description of the file.

+  @param[in]  NewSize   The requested new size for the file.

+

+  @retval  EFI_SUCCESS           The size was set.

+  @retval  EFI_OUT_OF_RESOURCES  An allocation needed to process the request failed.

+

+**/

+STATIC

+EFI_STATUS

+SetFileSize (

+  IN BOOTMON_FS_INSTANCE  *Instance,

+  IN BOOTMON_FS_FILE      *BootMonFsFile,

+  IN UINTN                 NewSize

+  )

+{

+  EFI_STATUS              Status;

+  UINT32                  OldSize;

+  LIST_ENTRY              *RegionToFlushLink;

+  LIST_ENTRY              *NextRegionToFlushLink;

+  BOOTMON_FS_FILE_REGION  *Region;

+  EFI_FILE_PROTOCOL       *File;

+  CHAR8                   *Buffer;

+  UINTN                   BufferSize;

+  UINT64                  StoredPosition;

+

+  OldSize = BootMonFsFile->Info->FileSize;

+

+  //

+  // In case of file truncation, force the regions waiting for writing to

+  // not overflow the new size of the file.

+  //

+  if (NewSize < OldSize) {

+    for (RegionToFlushLink = GetFirstNode (&BootMonFsFile->RegionToFlushLink);

+         !IsNull (&BootMonFsFile->RegionToFlushLink, RegionToFlushLink);

+         )

+    {

+      NextRegionToFlushLink = GetNextNode (&BootMonFsFile->RegionToFlushLink, RegionToFlushLink);

+      Region = (BOOTMON_FS_FILE_REGION*)RegionToFlushLink;

+      if (Region->Offset > NewSize) {

+        RemoveEntryList (RegionToFlushLink);

+        FreePool (Region->Buffer);

+        FreePool (Region);

+      } else {

+        Region->Size = MIN (Region->Size, NewSize - Region->Offset);

+      }

+      RegionToFlushLink = NextRegionToFlushLink;

+    }

+

+  } else if (NewSize > OldSize) {

+    // Increasing a file's size is potentially complicated as it may require

+    // moving the image description on media. The simplest way to do it is to

+    // seek past the end of the file (which is valid in UEFI) and perform a

+    // Write.

+    File = &BootMonFsFile->File;

+

+    // Save position

+    Status = File->GetPosition (File, &StoredPosition);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+    // Set position at the end of the file

+    Status = File->SetPosition (File, OldSize);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    BufferSize = NewSize - OldSize;

+    Buffer = AllocateZeroPool (BufferSize);

+    if (Buffer == NULL) {

+      return EFI_OUT_OF_RESOURCES;

+    }

+

+    Status = File->Write (File, &BufferSize, Buffer);

+    FreePool (Buffer);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    // Restore saved position

+    Status = File->SetPosition (File, StoredPosition);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  }

+

+  BootMonFsFile->Info->FileSize = NewSize;

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Set information about a file.

+

+  @param[in]  Instance  A pointer to the description of the volume

+                        the file belongs to.

+  @param[in]  File      A pointer to the description of the file.

+  @param[in]  Info      A pointer to the file information to write.

+

+  @retval  EFI_SUCCESS           The information was set.

+  @retval  EFI_ACCESS_DENIED     An attempt is being made to change the

+                                 EFI_FILE_DIRECTORY Attribute.

+  @retval  EFI_ACCESS_DENIED     The file was opened in read-only mode and an

+                                 attempt is being made to modify a field other

+                                 than Attribute.

+  @retval  EFI_ACCESS_DENIED     An attempt is made to change the name of a file

+                                 to a file that is already present.

+  @retval  EFI_WRITE_PROTECTED   An attempt is being made to modify a read-only

+                                 attribute.

+  @retval  EFI_OUT_OF_RESOURCES  An allocation needed to process the request

+                                 failed.

+

+**/

+STATIC

+EFI_STATUS

+SetFileInfo (

+  IN BOOTMON_FS_INSTANCE  *Instance,

+  IN BOOTMON_FS_FILE      *File,

+  IN EFI_FILE_INFO        *Info

+  )

+{

+  EFI_STATUS  Status;

+  BOOLEAN     FileSizeIsDifferent;

+  BOOLEAN     FileNameIsDifferent;

+  BOOLEAN     TimeIsDifferent;

+

+  //

+  // A directory can not be changed to a file and a file can

+  // not be changed to a directory.

+  //

+  if ((Info->Attribute & EFI_FILE_DIRECTORY)      !=

+      (File->Info->Attribute & EFI_FILE_DIRECTORY)  ) {

+    return EFI_ACCESS_DENIED;

+  }

+

+  FileSizeIsDifferent = (Info->FileSize != File->Info->FileSize);

+  FileNameIsDifferent = (StrnCmp (

+                           Info->FileName,

+                           File->Info->FileName,

+                           MAX_NAME_LENGTH - 1

+                           ) != 0);

+  //

+  // Check if the CreateTime, LastAccess or ModificationTime

+  // have been changed. The file system does not support file

+  // timestamps thus the three times in "File->Info" are

+  // always equal to zero. The following comparison actually

+  // checks if all three times are still equal to 0 or not.

+  //

+  TimeIsDifferent = CompareMem (

+                      &Info->CreateTime,

+                      &File->Info->CreateTime,

+                      3 * sizeof (EFI_TIME)

+                      ) != 0;

+

+  //

+  // For a file opened in read-only mode, only the Attribute field can be

+  // modified. The root directory open mode is forced to read-only at opening

+  // thus the following test protects the root directory to be somehow modified.

+  //

+  if (File->OpenMode == EFI_FILE_MODE_READ) {

+    if (FileSizeIsDifferent || FileNameIsDifferent || TimeIsDifferent) {

+      return EFI_ACCESS_DENIED;

+    }

+  }

+

+  if (TimeIsDifferent) {

+    return EFI_WRITE_PROTECTED;

+  }

+

+  if (FileSizeIsDifferent) {

+    Status = SetFileSize (Instance, File, Info->FileSize);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  }

+

+  //

+  // Note down in RAM the Attribute field but we can not

+  // ask to store it in flash for the time being.

+  //

+  File->Info->Attribute = Info->Attribute;

+

+  if (FileNameIsDifferent) {

+    Status = SetFileName (Instance, File, Info->FileName);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+EFIAPI

+EFI_STATUS

+BootMonFsGetInfo (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN EFI_GUID           *InformationType,

+  IN OUT UINTN          *BufferSize,

+  OUT VOID              *Buffer

+  )

+{

+  EFI_STATUS           Status;

+  BOOTMON_FS_FILE     *File;

+  BOOTMON_FS_INSTANCE *Instance;

+

+  if ((This == NULL)                         ||

+      (InformationType == NULL)              ||

+      (BufferSize == NULL)                   ||

+      ((Buffer == NULL) && (*BufferSize > 0))  ) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+  Instance = File->Instance;

+

+  // If the instance has not been initialized yet then do it ...

+  if (!Instance->Initialized) {

+    Status = BootMonFsInitialize (Instance);

+  } else {

+    Status = EFI_SUCCESS;

+  }

+

+  if (!EFI_ERROR (Status)) {

+    if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)

+        != 0) {

+      Status = GetFileSystemVolumeLabelInfo (Instance, BufferSize, Buffer);

+    } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid) != 0) {

+      Status = GetFilesystemInfo (Instance, BufferSize, Buffer);

+    } else if (CompareGuid (InformationType, &gEfiFileInfoGuid) != 0) {

+      Status = GetFileInfo (Instance, File, BufferSize, Buffer);

+    } else if (CompareGuid (InformationType, &gArmBootMonFsFileInfoGuid) != 0) {

+      Status = GetBootMonFsFileInfo (Instance, File, BufferSize, Buffer);

+    } else {

+      Status = EFI_UNSUPPORTED;

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Set information about a file or a volume.

+

+  @param[in]  This             A pointer to the EFI_FILE_PROTOCOL instance that

+                               is the file handle the information is for.

+  @param[in]  InformationType  The type identifier for the information being set :

+                               EFI_FILE_INFO_ID or EFI_FILE_SYSTEM_INFO_ID or

+                               EFI_FILE_SYSTEM_VOLUME_LABEL_ID

+  @param[in]  BufferSize       The size, in bytes, of Buffer.

+  @param[in]  Buffer           A pointer to the data buffer to write. The type of the

+                               data inside the buffer is indicated by InformationType.

+

+  @retval  EFI_SUCCESS            The information was set.

+  @retval  EFI_UNSUPPORTED        The InformationType is not known.

+  @retval  EFI_DEVICE_ERROR       The last issued semi-hosting operation failed.

+  @retval  EFI_ACCESS_DENIED      An attempt is made to change the name of a file

+                                  to a file that is already present.

+  @retval  EFI_ACCESS_DENIED      An attempt is being made to change the

+                                  EFI_FILE_DIRECTORY Attribute.

+  @retval  EFI_ACCESS_DENIED      InformationType is EFI_FILE_INFO_ID and

+                                  the file was opened in read-only mode and an

+                                  attempt is being made to modify a field other

+                                  than Attribute.

+  @retval  EFI_WRITE_PROTECTED    An attempt is being made to modify a read-only

+                                  attribute.

+  @retval  EFI_BAD_BUFFER_SIZE    The size of the buffer is lower than that indicated by

+                                  the data inside the buffer.

+  @retval  EFI_OUT_OF_RESOURCES   A allocation needed to process the request failed.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsSetInfo (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN EFI_GUID           *InformationType,

+  IN UINTN              BufferSize,

+  IN VOID               *Buffer

+  )

+{

+  BOOTMON_FS_FILE       *File;

+  EFI_FILE_INFO         *Info;

+  EFI_FILE_SYSTEM_INFO  *SystemInfo;

+

+  if ((This == NULL)            ||

+      (InformationType == NULL) ||

+      (Buffer == NULL)             ) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {

+    Info = Buffer;

+    if (Info->Size < (SIZE_OF_EFI_FILE_INFO + StrSize (Info->FileName))) {

+      return EFI_INVALID_PARAMETER;

+    }

+    if (BufferSize < Info->Size) {

+      return EFI_BAD_BUFFER_SIZE;

+    }

+    return (SetFileInfo (File->Instance, File, Info));

+  }

+

+  //

+  // The only writable field in the other two information types

+  // (i.e. EFI_FILE_SYSTEM_INFO and EFI_FILE_SYSTEM_VOLUME_LABEL) is the

+  // filesystem volume label. This can be retrieved with GetInfo, but it is

+  // hard-coded into this driver, not stored on media.

+  //

+

+  if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {

+    SystemInfo = Buffer;

+    if (SystemInfo->Size <

+        (SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (SystemInfo->VolumeLabel))) {

+      return EFI_INVALID_PARAMETER;

+    }

+    if (BufferSize < SystemInfo->Size) {

+      return EFI_BAD_BUFFER_SIZE;

+    }

+    return EFI_WRITE_PROTECTED;

+  }

+

+  if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {

+    return EFI_WRITE_PROTECTED;

+  }

+

+  return EFI_UNSUPPORTED;

+}

+

+EFIAPI

+EFI_STATUS

+BootMonFsReadDirectory (

+  IN EFI_FILE_PROTOCOL    *This,

+  IN OUT UINTN            *BufferSize,

+  OUT VOID                *Buffer

+  )

+{

+  BOOTMON_FS_INSTANCE *Instance;

+  BOOTMON_FS_FILE     *RootFile;

+  BOOTMON_FS_FILE     *File;

+  EFI_FILE_INFO       *Info;

+  UINTN               NameSize;

+  UINTN               ResultSize;

+  EFI_STATUS          Status;

+  UINTN               Index;

+

+  RootFile = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (RootFile == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Instance = RootFile->Instance;

+  Status = BootMonGetFileFromPosition (Instance, RootFile->Position, &File);

+  if (EFI_ERROR (Status)) {

+    // No more file

+    *BufferSize = 0;

+    return EFI_SUCCESS;

+  }

+

+  NameSize   = AsciiStrLen (File->HwDescription.Footer.Filename) + 1;

+  ResultSize = SIZE_OF_EFI_FILE_INFO + (NameSize * sizeof (CHAR16));

+  if (*BufferSize < ResultSize) {

+    *BufferSize = ResultSize;

+    return EFI_BUFFER_TOO_SMALL;

+  }

+

+  // Zero out the structure

+  Info = Buffer;

+  ZeroMem (Info, ResultSize);

+

+  // Fill in the structure

+  Info->Size         = ResultSize;

+  Info->FileSize     = BootMonFsGetImageLength (File);

+  Info->PhysicalSize = BootMonFsGetPhysicalSize (File);

+  for (Index = 0; Index < NameSize; Index++) {

+    Info->FileName[Index] = File->HwDescription.Footer.Filename[Index];

+  }

+

+  *BufferSize = ResultSize;

+  RootFile->Position++;

+

+  return EFI_SUCCESS;

+}

+

+EFIAPI

+EFI_STATUS

+BootMonFsFlushDirectory (

+  IN EFI_FILE_PROTOCOL  *This

+  )

+{

+  BOOTMON_FS_FILE *RootFile;

+  LIST_ENTRY      *ListFiles;

+  LIST_ENTRY      *Link;

+  BOOTMON_FS_FILE *File;

+

+  RootFile = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (RootFile == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  ListFiles = &RootFile->Link;

+

+  if (IsListEmpty (ListFiles)) {

+    return EFI_SUCCESS;

+  }

+

+  //

+  // Flush all the files that need to be flushed

+  //

+

+  // Go through all the list of files to flush them

+  for (Link = GetFirstNode (ListFiles);

+       !IsNull (ListFiles, Link);

+       Link = GetNextNode (ListFiles, Link)

+       )

+  {

+    File = BOOTMON_FS_FILE_FROM_LINK_THIS (Link);

+    File->File.Flush (&File->File);

+  }

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
new file mode 100644
index 0000000..3d71760
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
@@ -0,0 +1,528 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#include <Library/BaseMemoryLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PrintLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+#include <Protocol/DevicePathFromText.h>

+#include <Protocol/DriverBinding.h>

+

+#include "BootMonFsInternal.h"

+

+EFI_DEVICE_PATH* mBootMonFsSupportedDevicePaths;

+LIST_ENTRY       mInstances;

+

+EFI_FILE_PROTOCOL mBootMonFsRootTemplate = {

+  EFI_FILE_PROTOCOL_REVISION,

+  BootMonFsOpenFile,

+  BootMonFsCloseFile,

+  BootMonFsDeleteFail,

+  BootMonFsReadDirectory,

+  BootMonFsWriteFile,

+  BootMonFsGetPositionUnsupported,  // UEFI Spec: GetPosition not valid on dirs

+  BootMonFsSetDirPosition,

+  BootMonFsGetInfo,

+  BootMonFsSetInfo,

+  BootMonFsFlushDirectory

+};

+

+EFI_FILE_PROTOCOL mBootMonFsFileTemplate = {

+  EFI_FILE_PROTOCOL_REVISION,

+  BootMonFsOpenFile,

+  BootMonFsCloseFile,

+  BootMonFsDelete,

+  BootMonFsReadFile,

+  BootMonFsWriteFile,

+  BootMonFsGetPosition,

+  BootMonFsSetPosition,

+  BootMonFsGetInfo,

+  BootMonFsSetInfo,

+  BootMonFsFlushFile

+};

+

+/**

+  Search for a file given its name coded in Ascii.

+

+  When searching through the files of the volume, if a file is currently not

+  open, its name was written on the media and is kept in RAM in the

+  "HwDescription.Footer.Filename[]" field of the file's description.

+

+  If a file is currently open, its name might not have been written on the

+  media yet, and as the "HwDescription" is a mirror in RAM of what is on the

+  media the "HwDescription.Footer.Filename[]" might be outdated. In that case,

+  the up to date name of the file is stored in the "Info" field of the file's

+  description.

+

+  @param[in]   Instance       Pointer to the description of the volume in which

+                              the file has to be search for.

+  @param[in]   AsciiFileName  Name of the file.

+

+  @param[out]  File           Pointer to the description of the file if the

+                              file was found.

+

+  @retval  EFI_SUCCESS    The file was found.

+  @retval  EFI_NOT_FOUND  The file was not found.

+

+**/

+EFI_STATUS

+BootMonGetFileFromAsciiFileName (

+  IN  BOOTMON_FS_INSTANCE   *Instance,

+  IN  CHAR8*                AsciiFileName,

+  OUT BOOTMON_FS_FILE       **File

+  )

+{

+  LIST_ENTRY       *Entry;

+  BOOTMON_FS_FILE  *FileEntry;

+  CHAR8            OpenFileAsciiFileName[MAX_NAME_LENGTH];

+  CHAR8            *AsciiFileNameToCompare;

+

+  // Go through all the files in the list and return the file handle

+  for (Entry = GetFirstNode (&Instance->RootFile->Link);

+       !IsNull (&Instance->RootFile->Link, Entry);

+       Entry = GetNextNode (&Instance->RootFile->Link, Entry)

+       )

+  {

+    FileEntry = BOOTMON_FS_FILE_FROM_LINK_THIS (Entry);

+    if (FileEntry->Info != NULL) {

+      UnicodeStrToAsciiStr (FileEntry->Info->FileName, OpenFileAsciiFileName);

+      AsciiFileNameToCompare = OpenFileAsciiFileName;

+    } else {

+      AsciiFileNameToCompare = FileEntry->HwDescription.Footer.Filename;

+    }

+

+    if (AsciiStrCmp (AsciiFileNameToCompare, AsciiFileName) == 0) {

+      *File = FileEntry;

+      return EFI_SUCCESS;

+    }

+  }

+  return EFI_NOT_FOUND;

+}

+

+EFI_STATUS

+BootMonGetFileFromPosition (

+  IN  BOOTMON_FS_INSTANCE   *Instance,

+  IN  UINTN                 Position,

+  OUT BOOTMON_FS_FILE       **File

+  )

+{

+  LIST_ENTRY        *Entry;

+  BOOTMON_FS_FILE   *FileEntry;

+

+  // Go through all the files in the list and return the file handle

+  for (Entry = GetFirstNode (&Instance->RootFile->Link);

+       !IsNull (&Instance->RootFile->Link, Entry) && (&Instance->RootFile->Link != Entry);

+       Entry = GetNextNode (&Instance->RootFile->Link, Entry)

+       )

+  {

+    if (Position == 0) {

+      FileEntry = BOOTMON_FS_FILE_FROM_LINK_THIS (Entry);

+      *File = FileEntry;

+      return EFI_SUCCESS;

+    }

+    Position--;

+  }

+  return EFI_NOT_FOUND;

+}

+

+EFI_STATUS

+BootMonFsCreateFile (

+  IN  BOOTMON_FS_INSTANCE *Instance,

+  OUT BOOTMON_FS_FILE     **File

+  )

+{

+  BOOTMON_FS_FILE *NewFile;

+

+  NewFile = (BOOTMON_FS_FILE*)AllocateZeroPool (sizeof (BOOTMON_FS_FILE));

+  if (NewFile == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  NewFile->Signature = BOOTMON_FS_FILE_SIGNATURE;

+  InitializeListHead (&NewFile->Link);

+  InitializeListHead (&NewFile->RegionToFlushLink);

+  NewFile->Instance = Instance;

+

+  // If the created file is the root file then create a directory EFI_FILE_PROTOCOL

+  if (Instance->RootFile == *File) {

+    CopyMem (&NewFile->File, &mBootMonFsRootTemplate, sizeof (mBootMonFsRootTemplate));

+  } else {

+    CopyMem (&NewFile->File, &mBootMonFsFileTemplate, sizeof (mBootMonFsFileTemplate));

+  }

+  *File = NewFile;

+  return EFI_SUCCESS;

+}

+

+STATIC

+EFI_STATUS

+SupportedDevicePathsInit (

+  VOID

+  )

+{

+  EFI_STATUS                          Status;

+  CHAR16*                             DevicePathListStr;

+  CHAR16*                             DevicePathStr;

+  CHAR16*                             NextDevicePathStr;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;

+  EFI_DEVICE_PATH_PROTOCOL           *Instance;

+

+  Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+  ASSERT_EFI_ERROR (Status);

+

+  // Initialize Variable

+  DevicePathListStr = (CHAR16*)PcdGetPtr (PcdBootMonFsSupportedDevicePaths);

+  mBootMonFsSupportedDevicePaths = NULL;

+

+  // Extract the Device Path instances from the multi-device path string

+  while ((DevicePathListStr != NULL) && (DevicePathListStr[0] != L'\0')) {

+    NextDevicePathStr = StrStr (DevicePathListStr, L";");

+    if (NextDevicePathStr == NULL) {

+      DevicePathStr = DevicePathListStr;

+      DevicePathListStr = NULL;

+    } else {

+      DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DevicePathListStr + 1) * sizeof (CHAR16), DevicePathListStr);

+      if (DevicePathStr == NULL) {

+        return EFI_OUT_OF_RESOURCES;

+      }

+      *(DevicePathStr + (NextDevicePathStr - DevicePathListStr)) = L'\0';

+      DevicePathListStr = NextDevicePathStr;

+      if (DevicePathListStr[0] == L';') {

+        DevicePathListStr++;

+      }

+    }

+

+    Instance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);

+    ASSERT (Instance != NULL);

+    mBootMonFsSupportedDevicePaths = AppendDevicePathInstance (mBootMonFsSupportedDevicePaths, Instance);

+

+    if (NextDevicePathStr != NULL) {

+      FreePool (DevicePathStr);

+    }

+    FreePool (Instance);

+  }

+

+  if (mBootMonFsSupportedDevicePaths == NULL) {

+    return EFI_UNSUPPORTED;

+  } else {

+    return EFI_SUCCESS;

+  }

+}

+

+EFI_STATUS

+EFIAPI

+BootMonFsDriverSupported (

+  IN        EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,

+  IN        EFI_HANDLE                   ControllerHandle,

+  IN        EFI_DEVICE_PATH_PROTOCOL    *DevicePath OPTIONAL

+  )

+{

+  EFI_DISK_IO_PROTOCOL  *DiskIo;

+  EFI_DEVICE_PATH_PROTOCOL *DevicePathProtocol;

+  EFI_DEVICE_PATH_PROTOCOL *SupportedDevicePath;

+  EFI_DEVICE_PATH_PROTOCOL *SupportedDevicePaths;

+  EFI_STATUS Status;

+  UINTN Size1;

+  UINTN Size2;

+

+  //

+  // Open the IO Abstraction(s) needed to perform the supported test

+  //

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiDiskIoProtocolGuid,

+                  (VOID **) &DiskIo,

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_BY_DRIVER

+                  );

+

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+  //

+  // Close the I/O Abstraction(s) used to perform the supported test

+  //

+  gBS->CloseProtocol (

+         ControllerHandle,

+         &gEfiDiskIoProtocolGuid,

+         gImageHandle,

+         ControllerHandle

+         );

+

+  // Check that BlockIo protocol instance exists

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiBlockIoProtocolGuid,

+                  NULL,

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL

+                  );

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Check if a DevicePath is attached to the handle

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiDevicePathProtocolGuid,

+                  (VOID **)&DevicePathProtocol,

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_BY_DRIVER

+                  );

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Check if the Device Path is the one which contains the Boot Monitor File System

+  Size1 = GetDevicePathSize (DevicePathProtocol);

+

+  // Go through the list of Device Path Instances

+  Status = EFI_UNSUPPORTED;

+  SupportedDevicePaths = mBootMonFsSupportedDevicePaths;

+  while (SupportedDevicePaths != NULL) {

+    SupportedDevicePath = GetNextDevicePathInstance (&SupportedDevicePaths, &Size2);

+

+    if ((Size1 == Size2) && (CompareMem (DevicePathProtocol, SupportedDevicePath, Size1) == 0)) {

+      // The Device Path is supported

+      Status = EFI_SUCCESS;

+      break;

+    }

+  }

+

+  gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, gImageHandle, ControllerHandle);

+  return Status;

+}

+

+EFI_STATUS

+EFIAPI

+BootMonFsDriverStart (

+  IN        EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,

+  IN        EFI_HANDLE                   ControllerHandle,

+  IN        EFI_DEVICE_PATH_PROTOCOL    *DevicePath OPTIONAL

+  )

+{

+  BOOTMON_FS_INSTANCE *Instance;

+  EFI_STATUS           Status;

+  UINTN                VolumeNameSize;

+  EFI_FILE_INFO       *Info;

+

+  Instance = AllocateZeroPool (sizeof (BOOTMON_FS_INSTANCE));

+  if (Instance == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  // Initialize the BlockIo of the Instance

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiBlockIoProtocolGuid,

+                  (VOID **)&(Instance->BlockIo),

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL

+                  );

+  if (EFI_ERROR (Status)) {

+    goto Error;

+  }

+

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiDiskIoProtocolGuid,

+                  (VOID **)&(Instance->DiskIo),

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_BY_DRIVER

+                  );

+  if (EFI_ERROR (Status)) {

+    goto Error;

+  }

+

+  //

+  // Initialize the attributes of the Instance

+  //

+  Instance->Signature = BOOTMON_FS_SIGNATURE;

+  Instance->ControllerHandle = ControllerHandle;

+  Instance->Media = Instance->BlockIo->Media;

+  Instance->Binding = DriverBinding;

+

+    // Initialize the Simple File System Protocol

+  Instance->Fs.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;

+  Instance->Fs.OpenVolume = OpenBootMonFsOpenVolume;

+

+  // Volume name + L' ' + '2' digit number

+  VolumeNameSize = StrSize (BOOTMON_FS_VOLUME_LABEL) + (3 * sizeof (CHAR16));

+

+  // Initialize FileSystem Information

+  Instance->FsInfo.Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + VolumeNameSize;

+  Instance->FsInfo.BlockSize = Instance->Media->BlockSize;

+  Instance->FsInfo.ReadOnly = FALSE;

+  Instance->FsInfo.VolumeSize =

+    Instance->Media->BlockSize * (Instance->Media->LastBlock - Instance->Media->LowestAlignedLba);

+  CopyMem (Instance->FsInfo.VolumeLabel, BOOTMON_FS_VOLUME_LABEL, StrSize (BOOTMON_FS_VOLUME_LABEL));

+

+  // Initialize the root file

+  Status = BootMonFsCreateFile (Instance, &Instance->RootFile);

+  if (EFI_ERROR (Status)) {

+    goto Error;

+  }

+

+  Info = AllocateZeroPool (sizeof (EFI_FILE_INFO));

+  if (Info == NULL) {

+    Status = EFI_OUT_OF_RESOURCES;

+    goto Error;

+  }

+  Instance->RootFile->Info = Info;

+

+  // Initialize the DevicePath of the Instance

+  Status = gBS->OpenProtocol (

+                  ControllerHandle,

+                  &gEfiDevicePathProtocolGuid,

+                  (VOID **)&(Instance->DevicePath),

+                  gImageHandle,

+                  ControllerHandle,

+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL

+                  );

+  if (EFI_ERROR (Status)) {

+    goto Error;

+  }

+

+  //

+  // Install the Simple File System Protocol

+  //

+  Status = gBS->InstallMultipleProtocolInterfaces (

+                      &ControllerHandle,

+                      &gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,

+                      NULL

+                      );

+  if (EFI_ERROR (Status)) {

+    goto Error;

+  }

+

+  InsertTailList (&mInstances, &Instance->Link);

+

+  return EFI_SUCCESS;

+

+Error:

+

+    if (Instance->RootFile != NULL) {

+      if (Instance->RootFile->Info != NULL) {

+        FreePool (Instance->RootFile->Info);

+      }

+      FreePool (Instance->RootFile);

+    }

+    FreePool (Instance);

+

+  return Status;

+}

+

+

+EFI_STATUS

+EFIAPI

+BootMonFsDriverStop (

+  IN        EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,

+  IN        EFI_HANDLE                   ControllerHandle,

+  IN        UINTN                        NumberOfChildren,

+  IN        EFI_HANDLE                  *ChildHandleBuffer OPTIONAL

+  )

+{

+  BOOTMON_FS_INSTANCE *Instance;

+  LIST_ENTRY          *Link;

+  EFI_STATUS           Status;

+  BOOLEAN              InstanceFound;

+

+  // Find instance from ControllerHandle.

+  Instance = NULL;

+  InstanceFound = FALSE;

+  // For each instance in mInstances:

+  for (Link = GetFirstNode (&mInstances); !IsNull (&mInstances, Link); Link = GetNextNode (&mInstances, Link)) {

+    Instance = BOOTMON_FS_FROM_LINK (Link);

+

+    if (Instance->ControllerHandle == ControllerHandle) {

+      InstanceFound = TRUE;

+      break;

+    }

+  }

+  ASSERT (InstanceFound == TRUE);

+

+  gBS->CloseProtocol (

+      ControllerHandle,

+      &gEfiDevicePathProtocolGuid,

+      DriverBinding->ImageHandle,

+      ControllerHandle);

+

+  gBS->CloseProtocol (

+      ControllerHandle,

+      &gEfiDiskIoProtocolGuid,

+      DriverBinding->ImageHandle,

+      ControllerHandle);

+

+  gBS->CloseProtocol (

+      ControllerHandle,

+      &gEfiBlockIoProtocolGuid,

+      DriverBinding->ImageHandle,

+      ControllerHandle);

+

+  Status = gBS->UninstallMultipleProtocolInterfaces (

+      &ControllerHandle,

+      &gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,

+      NULL);

+

+  FreePool (Instance->RootFile->Info);

+  FreePool (Instance->RootFile);

+  FreePool (Instance);

+

+  return Status;

+}

+

+//

+// Simple Network Protocol Driver Global Variables

+//

+EFI_DRIVER_BINDING_PROTOCOL mBootMonFsDriverBinding = {

+  BootMonFsDriverSupported,

+  BootMonFsDriverStart,

+  BootMonFsDriverStop,

+  0xa,

+  NULL,

+  NULL

+};

+

+EFI_STATUS

+EFIAPI

+BootMonFsEntryPoint (

+  IN EFI_HANDLE                            ImageHandle,

+  IN EFI_SYSTEM_TABLE                      *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+

+  InitializeListHead (&mInstances);

+

+  // Initialize the list of Device Paths that could support BootMonFs

+  Status = SupportedDevicePathsInit ();

+  if (!EFI_ERROR (Status)) {

+    Status = gBS->InstallMultipleProtocolInterfaces (

+                    &ImageHandle,

+                    &gEfiDriverBindingProtocolGuid, &mBootMonFsDriverBinding,

+                    NULL

+                    );

+    ASSERT_EFI_ERROR (Status);

+  } else {

+    DEBUG((EFI_D_ERROR,"Warning: No Device Paths supporting BootMonFs have been defined in the PCD.\n"));

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsHw.h b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsHw.h
new file mode 100644
index 0000000..c1bef75
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsHw.h
@@ -0,0 +1,57 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#ifndef __BOOTMON_FS_HW_H__

+#define __BOOTMON_FS_HW_H__

+

+#define MAX_NAME_LENGTH 32

+

+#define HW_IMAGE_FOOTER_SIGNATURE_1 0x464C5348

+#define HW_IMAGE_FOOTER_SIGNATURE_2 0x464F4F54

+

+#define HW_IMAGE_FOOTER_VERSION     1

+#define HW_IMAGE_FOOTER_OFFSET      92

+

+#define HW_IMAGE_FOOTER_VERSION2    2

+#define HW_IMAGE_FOOTER_OFFSET2     96

+

+typedef struct {

+  CHAR8  Filename[MAX_NAME_LENGTH];

+  UINT32 Offset;

+  UINT32 Version;

+  UINT32 FooterSignature1;

+  UINT32 FooterSignature2;

+} HW_IMAGE_FOOTER;

+

+#define HW_IMAGE_DESCRIPTION_REGION_MAX 4

+

+// This structure is located at the end of a block when a file is present

+typedef struct {

+  UINT32  EntryPoint;

+  UINT32  Attributes;

+  UINT32  RegionCount;

+  struct {

+    UINT32 LoadAddress;

+    UINT32 Size;

+    UINT32 Offset;

+    UINT32 Checksum;

+  } Region[HW_IMAGE_DESCRIPTION_REGION_MAX];

+  UINT32  BlockStart;

+  UINT32  BlockEnd;

+  UINT32  FooterChecksum;

+

+  HW_IMAGE_FOOTER Footer;

+} HW_IMAGE_DESCRIPTION;

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c
new file mode 100644
index 0000000..346c360
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c
@@ -0,0 +1,222 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#include <Library/IoLib.h>

+#include <Library/NorFlashPlatformLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <Protocol/SimpleFileSystem.h>

+

+#include "BootMonFsInternal.h"

+

+UINT32

+BootMonFsChecksum (

+  IN VOID   *Data,

+  IN UINT32 Size

+  )

+{

+  UINT32  *Ptr;

+  UINT32  Word;

+  UINT32  Checksum;

+

+  ASSERT (Size % 4 == 0);

+

+  Checksum = 0;

+  Ptr = (UINT32*)Data;

+

+  while (Size > 0) {

+    Word = *Ptr++;

+    Size -= 4;

+

+    if (Word > ~Checksum) {

+      Checksum++;

+    }

+

+    Checksum += Word;

+  }

+

+  return ~Checksum;

+}

+

+EFI_STATUS

+BootMonFsComputeFooterChecksum (

+  IN OUT HW_IMAGE_DESCRIPTION *Footer

+  )

+{

+  HW_IMAGE_DESCRIPTION *Description;

+  UINT32                Index;

+

+  Footer->Attributes = 1;

+

+  Description = AllocateZeroPool (sizeof (HW_IMAGE_DESCRIPTION));

+  if (Description == NULL) {

+    DEBUG ((DEBUG_ERROR, "BootMonFsComputeFooterChecksum: Unable to allocate memory.\n"));

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  // Copy over to temporary shim

+  CopyMem (Description, Footer, sizeof (HW_IMAGE_DESCRIPTION));

+

+  // BootMon doesn't checksum the previous checksum

+  Description->FooterChecksum = 0;

+

+  // Blank out regions which aren't being used.

+  for (Index = Footer->RegionCount; Index < HW_IMAGE_DESCRIPTION_REGION_MAX; Index++) {

+    Description->Region[Index].Checksum = 0;

+    Description->Region[Index].LoadAddress = 0;

+    Description->Region[Index].Offset = 0;

+    Description->Region[Index].Size = 0;

+  }

+

+  // Compute the checksum

+  Footer->FooterChecksum = BootMonFsChecksum (Description, sizeof (HW_IMAGE_DESCRIPTION));

+

+  FreePool (Description);

+

+  return EFI_SUCCESS;

+}

+

+BOOLEAN

+BootMonFsIsImageValid (

+  IN HW_IMAGE_DESCRIPTION  *Desc,

+  IN EFI_LBA                Lba

+  )

+{

+  EFI_STATUS            Status;

+  HW_IMAGE_FOOTER      *Footer;

+  UINT32                Checksum;

+

+  Footer = &Desc->Footer;

+

+  // Check that the verification bytes are present

+  if ((Footer->FooterSignature1 != HW_IMAGE_FOOTER_SIGNATURE_1) ||

+      (Footer->FooterSignature2 != HW_IMAGE_FOOTER_SIGNATURE_2)) {

+    return FALSE;

+  }

+

+  if (Footer->Version == HW_IMAGE_FOOTER_VERSION) {

+    if (Footer->Offset != HW_IMAGE_FOOTER_OFFSET) {

+      return FALSE;

+    }

+  } else if (Footer->Version == HW_IMAGE_FOOTER_VERSION2) {

+    if (Footer->Offset != HW_IMAGE_FOOTER_OFFSET2) {

+      return FALSE;

+    }

+  } else {

+    return FALSE;

+  }

+

+  Checksum = Desc->FooterChecksum;

+  Status = BootMonFsComputeFooterChecksum (Desc);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((DEBUG_ERROR, "Warning: failed to compute checksum for image '%a'\n", Desc->Footer.Filename));

+  }

+

+  if (Desc->FooterChecksum != Checksum) {

+    DEBUG ((DEBUG_ERROR, "Warning: image '%a' checksum mismatch.\n", Desc->Footer.Filename));

+  }

+

+  if ((Desc->BlockEnd != Lba) || (Desc->BlockStart > Desc->BlockEnd)) {

+    return FALSE;

+  }

+

+  return TRUE;

+}

+

+STATIC

+EFI_STATUS

+BootMonFsDiscoverNextImage (

+  IN     BOOTMON_FS_INSTANCE      *Instance,

+  IN OUT EFI_LBA                  *LbaStart,

+  IN OUT BOOTMON_FS_FILE          *File

+  )

+{

+  EFI_DISK_IO_PROTOCOL  *DiskIo;

+  EFI_LBA                CurrentLba;

+  UINT64                 DescOffset;

+  EFI_STATUS             Status;

+

+  DiskIo = Instance->DiskIo;

+

+  CurrentLba = *LbaStart;

+

+  // Look for images in the rest of this block

+  while (CurrentLba <= Instance->Media->LastBlock) {

+    // Work out the byte offset into media of the image description in this block

+    // If present, the image description is at the very end of the block.

+    DescOffset = ((CurrentLba + 1) * Instance->Media->BlockSize) - sizeof (HW_IMAGE_DESCRIPTION);

+

+    // Read the image description from media

+    Status = DiskIo->ReadDisk (DiskIo,

+                       Instance->Media->MediaId,

+                       DescOffset,

+                       sizeof (HW_IMAGE_DESCRIPTION),

+                       &File->HwDescription

+                       );

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    // If we found a valid image description...

+    if (BootMonFsIsImageValid (&File->HwDescription, (CurrentLba - Instance->Media->LowestAlignedLba))) {

+      DEBUG ((EFI_D_ERROR, "Found image: %a in block %d.\n",

+        &(File->HwDescription.Footer.Filename),

+        (UINTN)(CurrentLba - Instance->Media->LowestAlignedLba)

+        ));

+      File->HwDescAddress = DescOffset;

+

+      *LbaStart = CurrentLba + 1;

+      return EFI_SUCCESS;

+    } else {

+      CurrentLba++;

+    }

+  }

+

+  *LbaStart = CurrentLba;

+  return EFI_NOT_FOUND;

+}

+

+EFI_STATUS

+BootMonFsInitialize (

+  IN BOOTMON_FS_INSTANCE *Instance

+  )

+{

+  EFI_STATUS               Status;

+  EFI_LBA                  Lba;

+  UINT32                   ImageCount;

+  BOOTMON_FS_FILE          *NewFile;

+

+  ImageCount = 0;

+  Lba = 0;

+

+  while (1) {

+    Status = BootMonFsCreateFile (Instance, &NewFile);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    Status = BootMonFsDiscoverNextImage (Instance, &Lba, NewFile);

+    if (EFI_ERROR (Status)) {

+      // Free NewFile allocated by BootMonFsCreateFile ()

+      FreePool (NewFile);

+      break;

+    }

+    InsertTailList (&Instance->RootFile->Link, &NewFile->Link);

+    ImageCount++;

+  }

+

+  Instance->Initialized = TRUE;

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h
new file mode 100644
index 0000000..c0c6599
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h
@@ -0,0 +1,101 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#ifndef __BOOTMONFS_INTERNAL_H__

+#define __BOOTMONFS_INTERNAL_H__

+

+#include <PiDxe.h>

+#include <Library/UefiLib.h>

+#include <Library/DebugLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <Protocol/BlockIo.h>

+#include <Protocol/DiskIo.h>

+#include <Protocol/FirmwareVolumeBlock.h>

+#include <Protocol/SimpleFileSystem.h>

+

+#include <Guid/BootMonFsFileInfo.h>

+#include <Guid/FileInfo.h>

+#include <Guid/FileSystemInfo.h>

+#include <Guid/FileSystemVolumeLabelInfo.h>

+

+#include "BootMonFsHw.h"

+

+#define BOOTMON_FS_VOLUME_LABEL   L"NOR Flash"

+

+typedef struct _BOOTMON_FS_INSTANCE BOOTMON_FS_INSTANCE;

+

+typedef struct {

+  LIST_ENTRY            Link;

+  VOID*                 Buffer;

+  UINTN                 Size;

+  UINT64                Offset; // Offset from the start of the file

+} BOOTMON_FS_FILE_REGION;

+

+typedef struct {

+  UINT32                Signature;

+  LIST_ENTRY            Link;

+  BOOTMON_FS_INSTANCE   *Instance;

+

+  UINTN                 HwDescAddress;

+  HW_IMAGE_DESCRIPTION  HwDescription;

+

+  EFI_FILE_PROTOCOL     File;

+

+  //

+  // The following fields are relevant only if the file is open.

+  //

+

+  EFI_FILE_INFO         *Info;

+  UINT64                Position;

+  // If the file needs to be flushed then this list contain the memory

+  // buffer that creates this file

+  LIST_ENTRY            RegionToFlushLink;

+  UINT64                OpenMode;

+} BOOTMON_FS_FILE;

+

+#define BOOTMON_FS_FILE_SIGNATURE              SIGNATURE_32('b', 'o', 't', 'f')

+#define BOOTMON_FS_FILE_FROM_FILE_THIS(a)      CR (a, BOOTMON_FS_FILE, File, BOOTMON_FS_FILE_SIGNATURE)

+#define BOOTMON_FS_FILE_FROM_LINK_THIS(a)      CR (a, BOOTMON_FS_FILE, Link, BOOTMON_FS_FILE_SIGNATURE)

+

+struct _BOOTMON_FS_INSTANCE {

+  UINT32                               Signature;

+  EFI_HANDLE                           ControllerHandle;

+

+  LIST_ENTRY                           Link;

+

+  EFI_DRIVER_BINDING_PROTOCOL         *Binding;

+  EFI_DISK_IO_PROTOCOL                *DiskIo;

+  EFI_BLOCK_IO_PROTOCOL               *BlockIo;

+  EFI_BLOCK_IO_MEDIA                  *Media;

+  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;

+

+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL      Fs;

+

+  EFI_FILE_SYSTEM_INFO                 FsInfo;

+  CHAR16                               Label[20];

+

+  BOOTMON_FS_FILE                     *RootFile; // All the other files are linked to this root

+  BOOLEAN                              Initialized;

+};

+

+#define BOOTMON_FS_SIGNATURE            SIGNATURE_32('b', 'o', 't', 'm')

+#define BOOTMON_FS_FROM_FS_THIS(a)      CR (a, BOOTMON_FS_INSTANCE, Fs, BOOTMON_FS_SIGNATURE)

+#define BOOTMON_FS_FROM_LINK(a)         CR (a, BOOTMON_FS_INSTANCE, Link, BOOTMON_FS_SIGNATURE)

+

+#include "BootMonFsApi.h"

+

+#endif

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c
new file mode 100644
index 0000000..af2fe51
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c
@@ -0,0 +1,792 @@
+/** @file

+*

+*  Copyright (c) 2012-2015, ARM 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.

+*

+**/

+

+#include "BootMonFsInternal.h"

+

+// Clear a file's image description on storage media:

+// UEFI allows you to seek past the end of a file, a subsequent write will grow

+// the file. It does not specify how space between the former end of the file

+// and the beginning of the write should be filled. It's therefore possible that

+// BootMonFs metadata, that comes after the end of a file, could be left there

+// and wrongly detected by BootMonFsImageInBlock.

+STATIC

+EFI_STATUS

+InvalidateImageDescription (

+  IN  BOOTMON_FS_FILE  *File

+  )

+{

+  EFI_DISK_IO_PROTOCOL   *DiskIo;

+  EFI_BLOCK_IO_PROTOCOL  *BlockIo;

+  UINT32                  MediaId;

+  VOID                   *Buffer;

+  EFI_STATUS              Status;

+

+  DiskIo = File->Instance->DiskIo;

+  BlockIo = File->Instance->BlockIo;

+  MediaId = BlockIo->Media->MediaId;

+

+  Buffer = AllocateZeroPool (sizeof (HW_IMAGE_DESCRIPTION));

+

+  if (Buffer == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  Status = DiskIo->WriteDisk (DiskIo,

+                    MediaId,

+                    File->HwDescAddress,

+                    sizeof (HW_IMAGE_DESCRIPTION),

+                    Buffer

+                    );

+

+  FreePool(Buffer);

+

+  return Status;

+}

+

+/**

+  Write the description of a file to storage media.

+

+  This function uses DiskIo to write to the media, so call BlockIo->FlushBlocks()

+  after calling it to ensure the data are written on the media.

+

+  @param[in]  File       Description of the file whose description on the

+                         storage media has to be updated.

+  @param[in]  FileName   Name of the file. Its length is assumed to be

+                         lower than MAX_NAME_LENGTH.

+  @param[in]  DataSize   Number of data bytes of the file.

+  @param[in]  FileStart  File's starting position on media. FileStart must

+                         be aligned to the media's block size.

+

+  @retval  EFI_WRITE_PROTECTED  The device cannot be written to.

+  @retval  EFI_DEVICE_ERROR     The device reported an error while performing

+                                the write operation.

+

+**/

+STATIC

+EFI_STATUS

+WriteFileDescription (

+  IN  BOOTMON_FS_FILE  *File,

+  IN  CHAR8            *FileName,

+  IN  UINT32            DataSize,

+  IN  UINT64            FileStart

+  )

+{

+  EFI_STATUS            Status;

+  EFI_DISK_IO_PROTOCOL  *DiskIo;

+  UINTN                 BlockSize;

+  UINT32                FileSize;

+  HW_IMAGE_DESCRIPTION  *Description;

+

+  DiskIo    = File->Instance->DiskIo;

+  BlockSize = File->Instance->BlockIo->Media->BlockSize;

+  ASSERT (FileStart % BlockSize == 0);

+

+  //

+  // Construct the file description

+  //

+

+  FileSize = DataSize + sizeof (HW_IMAGE_DESCRIPTION);

+  Description = &File->HwDescription;

+  Description->Attributes = 1;

+  Description->BlockStart = FileStart / BlockSize;

+  Description->BlockEnd   = Description->BlockStart + (FileSize / BlockSize);

+  AsciiStrCpy (Description->Footer.Filename, FileName);

+

+#ifdef MDE_CPU_ARM

+  Description->Footer.Offset  = HW_IMAGE_FOOTER_OFFSET;

+  Description->Footer.Version = HW_IMAGE_FOOTER_VERSION;

+#else

+  Description->Footer.Offset  = HW_IMAGE_FOOTER_OFFSET2;

+  Description->Footer.Version = HW_IMAGE_FOOTER_VERSION2;

+#endif

+  Description->Footer.FooterSignature1 = HW_IMAGE_FOOTER_SIGNATURE_1;

+  Description->Footer.FooterSignature2 = HW_IMAGE_FOOTER_SIGNATURE_2;

+  Description->RegionCount = 1;

+  Description->Region[0].Checksum = 0;

+  Description->Region[0].Offset = Description->BlockStart * BlockSize;

+  Description->Region[0].Size = DataSize;

+

+  Status = BootMonFsComputeFooterChecksum (Description);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  File->HwDescAddress = ((Description->BlockEnd + 1) * BlockSize) - sizeof (HW_IMAGE_DESCRIPTION);

+

+  // Update the file description on the media

+  Status = DiskIo->WriteDisk (

+                    DiskIo,

+                    File->Instance->Media->MediaId,

+                    File->HwDescAddress,

+                    sizeof (HW_IMAGE_DESCRIPTION),

+                    Description

+                    );

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

+

+// Find a space on media for a file that has not yet been flushed to disk.

+// Just returns the first space that's big enough.

+// This function could easily be adapted to:

+// - Find space for moving an existing file that has outgrown its space

+//   (We do not currently move files, just return EFI_VOLUME_FULL)

+// - Find space for a fragment of a file that has outgrown its space

+//   (We do not currently fragment files - it's not clear whether fragmentation

+//    is actually part of BootMonFs as there is no spec)

+// - Be more clever about finding space (choosing the largest or smallest

+//   suitable space)

+// Parameters:

+// File - the new (not yet flushed) file for which we need to find space.

+// FileStart - the position on media of the file (in bytes).

+STATIC

+EFI_STATUS

+BootMonFsFindSpaceForNewFile (

+  IN  BOOTMON_FS_FILE     *File,

+  IN  UINT64              FileSize,

+  OUT UINT64              *FileStart

+  )

+{

+  LIST_ENTRY              *FileLink;

+  BOOTMON_FS_FILE         *RootFile;

+  BOOTMON_FS_FILE         *FileEntry;

+  UINTN                    BlockSize;

+  EFI_BLOCK_IO_MEDIA      *Media;

+

+  Media = File->Instance->BlockIo->Media;

+  BlockSize = Media->BlockSize;

+  RootFile = File->Instance->RootFile;

+

+  // This function must only be called for file which has not been flushed into

+  // Flash yet

+  ASSERT (File->HwDescription.RegionCount == 0);

+

+  *FileStart = 0;

+  // Go through all the files in the list

+  for (FileLink = GetFirstNode (&RootFile->Link);

+         !IsNull (&RootFile->Link, FileLink);

+         FileLink = GetNextNode (&RootFile->Link, FileLink)

+         )

+  {

+    FileEntry = BOOTMON_FS_FILE_FROM_LINK_THIS (FileLink);

+    // Skip files that aren't on disk yet

+    if (FileEntry->HwDescription.RegionCount == 0) {

+      continue;

+    }

+

+    // If the free space preceding the file is big enough to contain the new

+    // file then use it!

+    if (((FileEntry->HwDescription.BlockStart * BlockSize) - *FileStart)

+        >= FileSize) {

+      // The file list must be in disk-order

+      RemoveEntryList (&File->Link);

+      File->Link.BackLink = FileLink->BackLink;

+      File->Link.ForwardLink = FileLink;

+      FileLink->BackLink->ForwardLink = &File->Link;

+      FileLink->BackLink = &File->Link;

+

+      return EFI_SUCCESS;

+    } else {

+      *FileStart = (FileEntry->HwDescription.BlockEnd + 1) * BlockSize;

+    }

+  }

+  // See if there's space after the last file

+  if ((((Media->LastBlock + 1) * BlockSize) - *FileStart) >= FileSize) {

+    return EFI_SUCCESS;

+  } else {

+    return EFI_VOLUME_FULL;

+  }

+}

+

+// Free the resources in the file's Region list.

+STATIC

+VOID

+FreeFileRegions (

+  IN  BOOTMON_FS_FILE *File

+  )

+{

+  LIST_ENTRY              *RegionToFlushLink;

+  BOOTMON_FS_FILE_REGION  *Region;

+

+  RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);

+  while (!IsNull (&File->RegionToFlushLink, RegionToFlushLink)) {

+    // Repeatedly remove the first node from the list and free its resources.

+    Region = (BOOTMON_FS_FILE_REGION *) RegionToFlushLink;

+    RemoveEntryList (RegionToFlushLink);

+    FreePool (Region->Buffer);

+    FreePool (Region);

+

+    RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);

+  }

+}

+

+/**

+  Flush all modified data associated with a file to a device.

+

+  @param[in]  This  A pointer to the EFI_FILE_PROTOCOL instance that is the

+                    file handle to flush.

+

+  @retval  EFI_SUCCESS            The data was flushed.

+  @retval  EFI_ACCESS_DENIED      The file was opened read-only.

+  @retval  EFI_DEVICE_ERROR       The device reported an error.

+  @retval  EFI_VOLUME_FULL        The volume is full.

+  @retval  EFI_OUT_OF_RESOURCES   Not enough resources were available to flush the data.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsFlushFile (

+  IN EFI_FILE_PROTOCOL  *This

+  )

+{

+  EFI_STATUS               Status;

+  BOOTMON_FS_INSTANCE     *Instance;

+  EFI_FILE_INFO           *Info;

+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;

+  EFI_BLOCK_IO_MEDIA      *Media;

+  EFI_DISK_IO_PROTOCOL    *DiskIo;

+  UINTN                    BlockSize;

+  CHAR8                    AsciiFileName[MAX_NAME_LENGTH];

+  LIST_ENTRY              *RegionToFlushLink;

+  BOOTMON_FS_FILE         *File;

+  BOOTMON_FS_FILE         *NextFile;

+  BOOTMON_FS_FILE_REGION  *Region;

+  LIST_ENTRY              *FileLink;

+  UINTN                    CurrentPhysicalSize;

+  UINT64                   FileStart;

+  UINT64                   FileEnd;

+  UINT64                   RegionStart;

+  UINT64                   RegionEnd;

+  UINT64                   NewDataSize;

+  UINT64                   NewFileSize;

+  UINT64                   EndOfAppendSpace;

+  BOOLEAN                  HasSpace;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (File->OpenMode == EFI_FILE_MODE_READ) {

+    return EFI_ACCESS_DENIED;

+  }

+

+  Instance  = File->Instance;

+  Info      = File->Info;

+  BlockIo   = Instance->BlockIo;

+  Media     = BlockIo->Media;

+  DiskIo    = Instance->DiskIo;

+  BlockSize = Media->BlockSize;

+

+  UnicodeStrToAsciiStr (Info->FileName, AsciiFileName);

+

+  // If the file doesn't exist then find a space for it

+  if (File->HwDescription.RegionCount == 0) {

+    Status = BootMonFsFindSpaceForNewFile (

+               File,

+               Info->FileSize + sizeof (HW_IMAGE_DESCRIPTION),

+               &FileStart

+               );

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  } else {

+    FileStart = File->HwDescription.BlockStart * BlockSize;

+  }

+  // FileEnd is the current NOR address of the end of the file's data

+  FileEnd = FileStart + File->HwDescription.Region[0].Size;

+

+  for (RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);

+       !IsNull (&File->RegionToFlushLink, RegionToFlushLink);

+       RegionToFlushLink = GetNextNode (&File->RegionToFlushLink, RegionToFlushLink)

+       )

+  {

+    Region = (BOOTMON_FS_FILE_REGION*)RegionToFlushLink;

+    if (Region->Size == 0) {

+      continue;

+    }

+

+    // RegionStart and RegionEnd are the the intended NOR address of the

+    // start and end of the region

+    RegionStart = FileStart   + Region->Offset;

+    RegionEnd   = RegionStart + Region->Size;

+

+    if (RegionEnd < FileEnd) {

+      // Handle regions representing edits to existing portions of the file

+      // Write the region data straight into the file

+      Status = DiskIo->WriteDisk (DiskIo,

+                        Media->MediaId,

+                        RegionStart,

+                        Region->Size,

+                        Region->Buffer

+                        );

+      if (EFI_ERROR (Status)) {

+        return Status;

+      }

+    } else {

+      // Handle regions representing appends to the file

+      //

+      // Note: Since seeking past the end of the file with SetPosition() is

+      //  valid, it's possible there will be a gap between the current end of

+      //  the file and the beginning of the new region. Since the UEFI spec

+      //  says nothing about this case (except "a subsequent write would grow

+      //  the file"), we just leave garbage in the gap.

+

+      // Check if there is space to append the new region

+      HasSpace = FALSE;

+      NewDataSize = RegionEnd - FileStart;

+      NewFileSize = NewDataSize + sizeof (HW_IMAGE_DESCRIPTION);

+      CurrentPhysicalSize = BootMonFsGetPhysicalSize (File);

+      if (NewFileSize <= CurrentPhysicalSize) {

+        HasSpace = TRUE;

+      } else {

+        // Get the File Description for the next file

+        FileLink = GetNextNode (&Instance->RootFile->Link, &File->Link);

+        if (!IsNull (&Instance->RootFile->Link, FileLink)) {

+          NextFile = BOOTMON_FS_FILE_FROM_LINK_THIS (FileLink);

+

+          // If there is space between the beginning of the current file and the

+          // beginning of the next file then use it

+          EndOfAppendSpace = NextFile->HwDescription.BlockStart * BlockSize;

+        } else {

+          // We are flushing the last file.

+          EndOfAppendSpace = (Media->LastBlock + 1) * BlockSize;

+        }

+        if (EndOfAppendSpace - FileStart >= NewFileSize) {

+          HasSpace = TRUE;

+        }

+      }

+

+      if (HasSpace == TRUE) {

+        // Invalidate the current image description of the file if any.

+        if (File->HwDescAddress != 0) {

+          Status = InvalidateImageDescription (File);

+          if (EFI_ERROR (Status)) {

+            return Status;

+          }

+        }

+

+        // Write the new file data

+        Status = DiskIo->WriteDisk (

+                    DiskIo,

+                    Media->MediaId,

+                    RegionStart,

+                    Region->Size,

+                    Region->Buffer

+                    );

+        if (EFI_ERROR (Status)) {

+          return Status;

+        }

+

+        Status = WriteFileDescription (File, AsciiFileName, NewDataSize, FileStart);

+        if (EFI_ERROR (Status)) {

+          return Status;

+        }

+

+      } else {

+        // There isn't a space for the file.

+        // Options here are to move the file or fragment it. However as files

+        // may represent boot images at fixed positions, these options will

+        // break booting if the bootloader doesn't use BootMonFs to find the

+        // image.

+

+        return EFI_VOLUME_FULL;

+      }

+    }

+  }

+

+  FreeFileRegions (File);

+  Info->PhysicalSize = BootMonFsGetPhysicalSize (File);

+

+  if ((AsciiStrCmp (AsciiFileName, File->HwDescription.Footer.Filename) != 0) ||

+      (Info->FileSize != File->HwDescription.Region[0].Size)               ) {

+    Status = WriteFileDescription (File, AsciiFileName, Info->FileSize, FileStart);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  }

+

+  // Flush DiskIo Buffers (see UEFI Spec 12.7 - DiskIo buffers are flushed by

+  // calling FlushBlocks on the same device's BlockIo).

+  BlockIo->FlushBlocks (BlockIo);

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Close a specified file handle.

+

+  @param[in]  This  A pointer to the EFI_FILE_PROTOCOL instance that is the file

+                    handle to close.

+

+  @retval  EFI_SUCCESS            The file was closed.

+  @retval  EFI_INVALID_PARAMETER  The parameter "This" is NULL or is not an open

+                                  file handle.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsCloseFile (

+  IN EFI_FILE_PROTOCOL  *This

+  )

+{

+  BOOTMON_FS_FILE  *File;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // In the case of a file and not the root directory

+  if (This != &File->Instance->RootFile->File) {

+    This->Flush (This);

+    FreePool (File->Info);

+    File->Info = NULL;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Open a file on the boot monitor file system.

+

+  The boot monitor file system does not allow for sub-directories. There is only

+  one directory, the root one. On any attempt to create a directory, the function

+  returns in error with the EFI_WRITE_PROTECTED error code.

+

+  @param[in]   This        A pointer to the EFI_FILE_PROTOCOL instance that is

+                           the file handle to source location.

+  @param[out]  NewHandle   A pointer to the location to return the opened

+                           handle for the new file.

+  @param[in]   FileName    The Null-terminated string of the name of the file

+                           to be opened.

+  @param[in]   OpenMode    The mode to open the file : Read or Read/Write or

+                           Read/Write/Create

+  @param[in]   Attributes  Attributes of the file in case of a file creation

+

+  @retval  EFI_SUCCESS            The file was open.

+  @retval  EFI_NOT_FOUND          The specified file could not be found or the specified

+                                  directory in which to create a file could not be found.

+  @retval  EFI_DEVICE_ERROR       The device reported an error.

+  @retval  EFI_WRITE_PROTECTED    Attempt to create a directory. This is not possible

+                                  with the Boot Monitor file system.

+  @retval  EFI_OUT_OF_RESOURCES   Not enough resources were available to open the file.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsOpenFile (

+  IN EFI_FILE_PROTOCOL   *This,

+  OUT EFI_FILE_PROTOCOL  **NewHandle,

+  IN CHAR16              *FileName,

+  IN UINT64              OpenMode,

+  IN UINT64              Attributes

+  )

+{

+  EFI_STATUS           Status;

+  BOOTMON_FS_FILE      *Directory;

+  BOOTMON_FS_FILE      *File;

+  BOOTMON_FS_INSTANCE  *Instance;

+  CHAR8                *Buf;

+  CHAR16               *Path;

+  CHAR16               *Separator;

+  CHAR8                *AsciiFileName;

+  EFI_FILE_INFO        *Info;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Directory = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (Directory->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if ((FileName == NULL) || (NewHandle == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  //

+  // The only valid modes are read, read/write, and read/write/create

+  //

+  if ( (OpenMode != EFI_FILE_MODE_READ) &&

+       (OpenMode != (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE)) &&

+       (OpenMode != (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE)) ) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Instance = Directory->Instance;

+

+  //

+  // If the instance has not been initialized yet then do it ...

+  //

+  if (!Instance->Initialized) {

+    Status = BootMonFsInitialize (Instance);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+  }

+

+  //

+  // Copy the file path to be able to work on it. We do not want to

+  // modify the input file name string "FileName".

+  //

+  Buf = AllocateCopyPool (StrSize (FileName), FileName);

+  if (Buf == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+  Path = (CHAR16*)Buf;

+  AsciiFileName = NULL;

+  Info = NULL;

+

+  //

+  // Handle single periods, double periods and convert forward slashes '/'

+  // to backward '\' ones. Does not handle a '.' at the beginning of the

+  // path for the time being.

+  //

+  if (PathCleanUpDirectories (Path) == NULL) {

+    Status = EFI_INVALID_PARAMETER;

+    goto Error;

+  }

+

+  //

+  // Detect if the first component of the path refers to a directory.

+  // This is done to return the correct error code when trying to

+  // access or create a directory other than the root directory.

+  //

+

+  //

+  // Search for the '\\' sequence and if found return in error

+  // with the EFI_INVALID_PARAMETER error code. ere in the path.

+  //

+  if (StrStr (Path, L"\\\\") != NULL) {

+    Status = EFI_INVALID_PARAMETER;

+    goto Error;

+  }

+  //

+  // Get rid of the leading '\' if any.

+  //

+  Path += (Path[0] == L'\\');

+

+  //

+  // Look for a '\' in the file path. If one is found then

+  // the first component of the path refers to a directory

+  // that is not the root directory.

+  //

+  Separator = StrStr (Path, L"\\");

+  if (Separator != NULL) {

+    //

+    // In the case '<dir name>\' and a creation, return

+    // EFI_WRITE_PROTECTED if this is for a directory

+    // creation, EFI_INVALID_PARAMETER otherwise.

+    //

+    if ((*(Separator + 1) == '\0') && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)) {

+      if (Attributes & EFI_FILE_DIRECTORY) {

+        Status = EFI_WRITE_PROTECTED;

+      } else {

+        Status = EFI_INVALID_PARAMETER;

+      }

+    } else {

+      //

+      // Attempt to open a file or a directory that is not in the

+      // root directory or to open without creation a directory

+      // located in the root directory, returns EFI_NOT_FOUND.

+      //

+      Status = EFI_NOT_FOUND;

+    }

+    goto Error;

+  }

+

+  //

+  // BootMonFs interface requires ASCII filenames

+  //

+  AsciiFileName = AllocatePool (StrLen (Path) + 1);

+  if (AsciiFileName == NULL) {

+    Status = EFI_OUT_OF_RESOURCES;

+    goto Error;

+  }

+  UnicodeStrToAsciiStr (Path, AsciiFileName);

+  if (AsciiStrSize (AsciiFileName) > MAX_NAME_LENGTH) {

+   AsciiFileName[MAX_NAME_LENGTH - 1] = '\0';

+  }

+

+  if ((AsciiFileName[0] == '\0') ||

+      (AsciiFileName[0] == '.' )    ) {

+    //

+    // Opening the root directory

+    //

+

+    *NewHandle = &Instance->RootFile->File;

+    Instance->RootFile->Position = 0;

+    Status = EFI_SUCCESS;

+  } else {

+

+    if ((OpenMode & EFI_FILE_MODE_CREATE) &&

+        (Attributes & EFI_FILE_DIRECTORY)    ) {

+      Status = EFI_WRITE_PROTECTED;

+      goto Error;

+    }

+

+    //

+    // Allocate a buffer to store the characteristics of the file while the

+    // file is open. We allocate the maximum size to not have to reallocate

+    // if the file name is changed.

+    //

+    Info = AllocateZeroPool (

+             SIZE_OF_EFI_FILE_INFO + (sizeof (CHAR16) * MAX_NAME_LENGTH));

+    if (Info == NULL) {

+      Status = EFI_OUT_OF_RESOURCES;

+      goto Error;

+    }

+

+    //

+    // Open or create a file in the root directory.

+    //

+

+    Status = BootMonGetFileFromAsciiFileName (Instance, AsciiFileName, &File);

+    if (Status == EFI_NOT_FOUND) {

+      if ((OpenMode & EFI_FILE_MODE_CREATE) == 0) {

+        goto Error;

+      }

+

+      Status = BootMonFsCreateFile (Instance, &File);

+      if (EFI_ERROR (Status)) {

+        goto Error;

+      }

+      InsertHeadList (&Instance->RootFile->Link, &File->Link);

+      Info->Attribute = Attributes;

+    } else {

+      //

+      // File already open, not supported yet.

+      //

+      if (File->Info != NULL) {

+        Status = EFI_UNSUPPORTED;

+        goto Error;

+      }

+    }

+

+    Info->FileSize     = BootMonFsGetImageLength (File);

+    Info->PhysicalSize = BootMonFsGetPhysicalSize (File);

+    AsciiStrToUnicodeStr (AsciiFileName, Info->FileName);

+

+    File->Info = Info;

+    Info = NULL;

+    File->Position = 0;

+    File->OpenMode = OpenMode;

+

+    *NewHandle = &File->File;

+  }

+

+Error:

+

+  FreePool (Buf);

+  if (AsciiFileName != NULL) {

+    FreePool (AsciiFileName);

+  }

+  if (Info != NULL) {

+    FreePool (Info);

+  }

+

+  return Status;

+}

+

+// Delete() for the root directory's EFI_FILE_PROTOCOL instance

+EFIAPI

+EFI_STATUS

+BootMonFsDeleteFail (

+  IN EFI_FILE_PROTOCOL *This

+  )

+{

+  This->Close(This);

+  // You can't delete the root directory

+  return EFI_WARN_DELETE_FAILURE;

+}

+

+/**

+  Close and delete a file from the boot monitor file system.

+

+  @param[in]  This  A pointer to the EFI_FILE_PROTOCOL instance that is the file

+                    handle to delete.

+

+  @retval  EFI_SUCCESS              The file was closed and deleted.

+  @retval  EFI_INVALID_PARAMETER    The parameter "This" is NULL or is not an open

+                                    file handle.

+  @retval  EFI_WARN_DELETE_FAILURE  The handle was closed, but the file was not deleted.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsDelete (

+  IN EFI_FILE_PROTOCOL *This

+  )

+{

+  EFI_STATUS               Status;

+  BOOTMON_FS_FILE         *File;

+  LIST_ENTRY              *RegionToFlushLink;

+  BOOTMON_FS_FILE_REGION  *Region;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (!IsListEmpty (&File->RegionToFlushLink)) {

+    // Free the entries from the Buffer List

+    RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);

+    do {

+      Region = (BOOTMON_FS_FILE_REGION*)RegionToFlushLink;

+

+      //

+      // Get next element of the list before deleting the region description

+      // that contain the LIST_ENTRY structure.

+      //

+      RegionToFlushLink = RemoveEntryList (RegionToFlushLink);

+

+      // Free the buffers

+      FreePool (Region->Buffer);

+      FreePool (Region);

+    } while (!IsListEmpty (&File->RegionToFlushLink));

+  }

+

+  // If (RegionCount is greater than 0) then the file already exists

+  if (File->HwDescription.RegionCount > 0) {

+    // Invalidate the last Block

+    Status = InvalidateImageDescription (File);

+    ASSERT_EFI_ERROR (Status);

+    if (EFI_ERROR (Status)) {

+      return  EFI_WARN_DELETE_FAILURE;

+    }

+  }

+

+  // Remove the entry from the list

+  RemoveEntryList (&File->Link);

+  FreePool (File->Info);

+  FreePool (File);

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsReadWrite.c b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsReadWrite.c
new file mode 100644
index 0000000..f8124e9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsReadWrite.c
@@ -0,0 +1,259 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#include <Protocol/SimpleFileSystem.h>

+#include <Library/UefiLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/DebugLib.h>

+

+#include "BootMonFsInternal.h"

+

+/**

+  Read data from an open file.

+

+  @param[in]      This        A pointer to the EFI_FILE_PROTOCOL instance that

+                              is the file handle to read data from.

+  @param[in out]  BufferSize  On input, the size of the Buffer. On output, the

+                              amount of data returned in Buffer. In both cases,

+                              the size is measured in bytes.

+  @param[out]     Buffer      The buffer into which the data is read.

+

+  @retval  EFI_SUCCESS            The data was read.

+  @retval  EFI_DEVICE_ERROR       On entry, the current file position is

+                                  beyond the end of the file, or the device

+                                  reported an error while performing the read

+                                  operation.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsReadFile (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN OUT UINTN          *BufferSize,

+  OUT VOID              *Buffer

+  )

+{

+  BOOTMON_FS_INSTANCE   *Instance;

+  BOOTMON_FS_FILE       *File;

+  EFI_DISK_IO_PROTOCOL  *DiskIo;

+  EFI_BLOCK_IO_MEDIA    *Media;

+  UINT64                FileStart;

+  EFI_STATUS            Status;

+  UINTN                 RemainingFileSize;

+

+  if ((This == NULL)       ||

+      (BufferSize == NULL) ||

+      (Buffer == NULL)        ) {

+    return EFI_INVALID_PARAMETER;

+  }

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Ensure the file has been written in Flash before reading it.

+  // This keeps the code simple and avoids having to manage a non-flushed file.

+  BootMonFsFlushFile (This);

+

+  Instance  = File->Instance;

+  DiskIo    = Instance->DiskIo;

+  Media     = Instance->Media;

+  FileStart = (Media->LowestAlignedLba + File->HwDescription.BlockStart) * Media->BlockSize;

+

+  if (File->Position >= File->Info->FileSize) {

+    // The entire file has been read or the position has been

+    // set past the end of the file.

+    *BufferSize = 0;

+    if (File->Position > File->Info->FileSize) {

+      return EFI_DEVICE_ERROR;

+    } else {

+      return EFI_SUCCESS;

+    }

+  }

+

+  // This driver assumes that the entire file is in region 0.

+  RemainingFileSize = File->Info->FileSize - File->Position;

+

+  // If read would go past end of file, truncate the read

+  if (*BufferSize > RemainingFileSize) {

+    *BufferSize = RemainingFileSize;

+  }

+

+  Status = DiskIo->ReadDisk (

+                    DiskIo,

+                    Media->MediaId,

+                    FileStart + File->Position,

+                    *BufferSize,

+                    Buffer

+                    );

+  if (EFI_ERROR (Status)) {

+    *BufferSize = 0;

+  }

+

+  File->Position += *BufferSize;

+

+  return Status;

+}

+

+/**

+  Write data to an open file.

+

+  The data is not written to the flash yet. It will be written when the file

+  will be either read, closed or flushed.

+

+  @param[in]      This        A pointer to the EFI_FILE_PROTOCOL instance that

+                              is the file handle to write data to.

+  @param[in out]  BufferSize  On input, the size of the Buffer. On output, the

+                              size of the data actually written. In both cases,

+                              the size is measured in bytes.

+  @param[in]      Buffer      The buffer of data to write.

+

+  @retval  EFI_SUCCESS            The data was written.

+  @retval  EFI_ACCESS_DENIED      The file was opened read only.

+  @retval  EFI_OUT_OF_RESOURCES   Unable to allocate the buffer to store the

+                                  data to write.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsWriteFile (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN OUT UINTN          *BufferSize,

+  IN VOID               *Buffer

+  )

+{

+  BOOTMON_FS_FILE         *File;

+  BOOTMON_FS_FILE_REGION  *Region;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (File->OpenMode == EFI_FILE_MODE_READ) {

+    return EFI_ACCESS_DENIED;

+  }

+

+  // Allocate and initialize the memory region

+  Region = (BOOTMON_FS_FILE_REGION*)AllocateZeroPool (sizeof (BOOTMON_FS_FILE_REGION));

+  if (Region == NULL) {

+    *BufferSize = 0;

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  Region->Buffer = AllocateCopyPool (*BufferSize, Buffer);

+  if (Region->Buffer == NULL) {

+    *BufferSize = 0;

+    FreePool (Region);

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  Region->Size   = *BufferSize;

+  Region->Offset = File->Position;

+

+  InsertTailList (&File->RegionToFlushLink, &Region->Link);

+

+  File->Position += *BufferSize;

+

+  if (File->Position > File->Info->FileSize) {

+    File->Info->FileSize = File->Position;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Set a file's current position.

+

+  @param[in]  This      A pointer to the EFI_FILE_PROTOCOL instance that is

+                        the file handle to set the requested position on.

+  @param[in]  Position  The byte position from the start of the file to set.

+

+  @retval  EFI_SUCCESS            The position was set.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsSetPosition (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN UINT64             Position

+  )

+{

+  BOOTMON_FS_FILE  *File;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  //

+  // UEFI Spec section 12.5:

+  // "Seeking to position 0xFFFFFFFFFFFFFFFF causes the current position to

+  // be set to the end of the file."

+  //

+  if (Position == 0xFFFFFFFFFFFFFFFF) {

+    Position = File->Info->FileSize;

+  }

+

+  File->Position = Position;

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Return a file's current position.

+

+  @param[in]   This      A pointer to the EFI_FILE_PROTOCOL instance that is

+                         the file handle to get the current position on.

+  @param[out]  Position  The address to return the file's current position value.

+

+  @retval  EFI_SUCCESS            The position was returned.

+  @retval  EFI_INVALID_PARAMETER  At least one of the parameters is invalid.

+

+**/

+EFIAPI

+EFI_STATUS

+BootMonFsGetPosition (

+  IN  EFI_FILE_PROTOCOL *This,

+  OUT UINT64            *Position

+  )

+{

+  BOOTMON_FS_FILE         *File;

+

+  if (This == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+  File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);

+  if (File->Info == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (Position == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *Position = File->Position;

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsUnsupported.c b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsUnsupported.c
new file mode 100644
index 0000000..4ecc4ea
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsUnsupported.c
@@ -0,0 +1,37 @@
+/** @file

+*

+*  Copyright (c) 2012-2014, ARM 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.

+*

+**/

+

+#include "BootMonFsInternal.h"

+

+EFIAPI

+EFI_STATUS

+BootMonFsSetPositionUnsupported (

+  IN EFI_FILE_PROTOCOL  *This,

+  IN UINT64             Position

+  )

+{

+  ASSERT(0);

+  return EFI_UNSUPPORTED;

+}

+

+EFIAPI

+EFI_STATUS

+BootMonFsGetPositionUnsupported (

+  IN EFI_FILE_PROTOCOL  *This,

+  OUT UINT64            *Position

+  )

+{

+  ASSERT(0);

+  return EFI_UNSUPPORTED;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/ArmTrustzone.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/ArmTrustzone.h
new file mode 100644
index 0000000..78e98aa
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/ArmTrustzone.h
@@ -0,0 +1,88 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#ifndef __ARM_TRUSTZONE_H__

+#define __ARM_TRUSTZONE_H__

+

+#include <Uefi.h>

+

+// Setup TZ Protection Controller

+#define TZPC_DECPROT_0  0

+#define TZPC_DECPROT_1  1

+#define TZPC_DECPROT_2  2

+#define TZPC_DECPROT_MAX  2

+

+/**

+    FIXME: Need documentation

+**/

+EFI_STATUS

+TZPCSetDecProtBits (

+  IN  UINTN TzpcBase,

+  IN  UINTN TzpcId,

+  IN  UINTN Bits

+  );

+

+/**

+    FIXME: Need documentation

+**/

+EFI_STATUS

+TZPCClearDecProtBits (

+  IN  UINTN TzpcBase,

+  IN  UINTN TzpcId,

+  IN  UINTN Bits

+  );

+

+// Setup TZ Address Space Controller

+#define TZASC_REGION_ENABLED        1

+#define TZASC_REGION_DISABLED       0

+#define TZASC_REGION_SIZE_32KB      0xE

+#define TZASC_REGION_SIZE_64KB      0xF

+#define TZASC_REGION_SIZE_128KB     0x10

+#define TZASC_REGION_SIZE_256KB     0x11

+#define TZASC_REGION_SIZE_512KB     0x12

+#define TZASC_REGION_SIZE_1MB       0x13

+#define TZASC_REGION_SIZE_2MB       0x14

+#define TZASC_REGION_SIZE_4MB       0x15

+#define TZASC_REGION_SIZE_8MB       0x16

+#define TZASC_REGION_SIZE_16MB      0x17

+#define TZASC_REGION_SIZE_32MB      0x18

+#define TZASC_REGION_SIZE_64MB      0x19

+#define TZASC_REGION_SIZE_128MB     0x1A

+#define TZASC_REGION_SIZE_256MB     0x1B

+#define TZASC_REGION_SIZE_512MB     0x1C

+#define TZASC_REGION_SIZE_1GB       0x1D

+#define TZASC_REGION_SIZE_2GB       0x1E

+#define TZASC_REGION_SIZE_4GB       0x1F

+#define TZASC_REGION_SECURITY_SR    (1 << 3)

+#define TZASC_REGION_SECURITY_SW    (1 << 2)

+#define TZASC_REGION_SECURITY_SRW   (TZASC_REGION_SECURITY_SR|TZASC_REGION_SECURITY_SW)

+#define TZASC_REGION_SECURITY_NSR   (1 << 1)

+#define TZASC_REGION_SECURITY_NSW   1

+#define TZASC_REGION_SECURITY_NSRW  (TZASC_REGION_SECURITY_NSR|TZASC_REGION_SECURITY_NSW)

+

+/**

+    FIXME: Need documentation

+**/

+EFI_STATUS

+TZASCSetRegion (

+  IN  INTN  TzascBase,

+  IN  UINTN RegionId,

+  IN  UINTN Enabled,

+  IN  UINTN LowAddress,

+  IN  UINTN HighAddress,

+  IN  UINTN Size,

+  IN  UINTN Security

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/HdLcd.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/HdLcd.h
new file mode 100644
index 0000000..6df97a9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/HdLcd.h
@@ -0,0 +1,89 @@
+/** @file  HDLcd.h

+

+ Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+

+ 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 _HDLCD_H_

+#define _HDLCD_H_

+

+//

+// HDLCD Controller Register Offsets

+//

+

+#define HDLCD_REG_VERSION                 ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x000)

+#define HDLCD_REG_INT_RAWSTAT             ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x010)

+#define HDLCD_REG_INT_CLEAR               ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x014)

+#define HDLCD_REG_INT_MASK                ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x018)

+#define HDLCD_REG_INT_STATUS              ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x01C)

+#define HDLCD_REG_FB_BASE                 ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x100)

+#define HDLCD_REG_FB_LINE_LENGTH          ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x104)

+#define HDLCD_REG_FB_LINE_COUNT           ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x108)

+#define HDLCD_REG_FB_LINE_PITCH           ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x10C)

+#define HDLCD_REG_BUS_OPTIONS             ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x110)

+#define HDLCD_REG_V_SYNC                  ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x200)

+#define HDLCD_REG_V_BACK_PORCH            ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x204)

+#define HDLCD_REG_V_DATA                  ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x208)

+#define HDLCD_REG_V_FRONT_PORCH           ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x20C)

+#define HDLCD_REG_H_SYNC                  ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x210)

+#define HDLCD_REG_H_BACK_PORCH            ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x214)

+#define HDLCD_REG_H_DATA                  ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x218)

+#define HDLCD_REG_H_FRONT_PORCH           ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x21C)

+#define HDLCD_REG_POLARITIES              ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x220)

+#define HDLCD_REG_COMMAND                 ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x230)

+#define HDLCD_REG_PIXEL_FORMAT            ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x240)

+#define HDLCD_REG_RED_SELECT              ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x244)

+#define HDLCD_REG_GREEN_SELECT            ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x248)

+#define HDLCD_REG_BLUE_SELECT             ((UINTN)PcdGet32 (PcdArmHdLcdBase) + 0x24C)

+

+

+//

+// HDLCD Values of registers

+//

+

+// HDLCD Interrupt mask, clear and status register

+#define HDLCD_DMA_END                     BIT0    /* DMA has finished reading a frame */

+#define HDLCD_BUS_ERROR                   BIT1    /* DMA bus error */

+#define HDLCD_SYNC                        BIT2    /* Vertical sync */

+#define HDLCD_UNDERRUN                    BIT3    /* No Data available while DATAEN active */

+

+// CLCD_CONTROL Control register

+#define HDLCD_DISABLE                     0

+#define HDLCD_ENABLE                      BIT0

+

+// Bus Options

+#define HDLCD_BURST_1                     BIT0

+#define HDLCD_BURST_2                     BIT1

+#define HDLCD_BURST_4                     BIT2

+#define HDLCD_BURST_8                     BIT3

+#define HDLCD_BURST_16                    BIT4

+

+// Polarities - HIGH

+#define HDLCD_VSYNC_HIGH                  BIT0

+#define HDLCD_HSYNC_HIGH                  BIT1

+#define HDLCD_DATEN_HIGH                  BIT2

+#define HDLCD_DATA_HIGH                   BIT3

+#define HDLCD_PXCLK_HIGH                  BIT4

+// Polarities - LOW (for completion and for ease of understanding the hardware settings)

+#define HDLCD_VSYNC_LOW                   0

+#define HDLCD_HSYNC_LOW                   0

+#define HDLCD_DATEN_LOW                   0

+#define HDLCD_DATA_LOW                    0

+#define HDLCD_PXCLK_LOW                   0

+

+// Pixel Format

+#define HDLCD_LITTLE_ENDIAN              (0 << 31)

+#define HDLCD_BIG_ENDIAN                 (1 << 31)

+

+// Number of bytes per pixel

+#define HDLCD_4BYTES_PER_PIXEL           ((4 - 1) << 3)

+

+#endif /* _HDLCD_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL011Uart.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL011Uart.h
new file mode 100644
index 0000000..2fe796f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL011Uart.h
@@ -0,0 +1,231 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#ifndef __PL011_UART_H__

+#define __PL011_UART_H__

+

+#include <Uefi.h>

+#include <Protocol/SerialIo.h>

+

+// PL011 Registers

+#define UARTDR                    0x000

+#define UARTRSR                   0x004

+#define UARTECR                   0x004

+#define UARTFR                    0x018

+#define UARTILPR                  0x020

+#define UARTIBRD                  0x024

+#define UARTFBRD                  0x028

+#define UARTLCR_H                 0x02C

+#define UARTCR                    0x030

+#define UARTIFLS                  0x034

+#define UARTIMSC                  0x038

+#define UARTRIS                   0x03C

+#define UARTMIS                   0x040

+#define UARTICR                   0x044

+#define UARTDMACR                 0x048

+

+#define UARTPID0                  0xFE0

+#define UARTPID1                  0xFE4

+#define UARTPID2                  0xFE8

+#define UARTPID3                  0xFEC

+

+// Data status bits

+#define UART_DATA_ERROR_MASK      0x0F00

+

+// Status reg bits

+#define UART_STATUS_ERROR_MASK    0x0F

+

+// Flag reg bits

+#define PL011_UARTFR_RI           (1 << 8)  // Ring indicator

+#define PL011_UARTFR_TXFE         (1 << 7)  // Transmit FIFO empty

+#define PL011_UARTFR_RXFF         (1 << 6)  // Receive  FIFO full

+#define PL011_UARTFR_TXFF         (1 << 5)  // Transmit FIFO full

+#define PL011_UARTFR_RXFE         (1 << 4)  // Receive  FIFO empty

+#define PL011_UARTFR_BUSY         (1 << 3)  // UART busy

+#define PL011_UARTFR_DCD          (1 << 2)  // Data carrier detect

+#define PL011_UARTFR_DSR          (1 << 1)  // Data set ready

+#define PL011_UARTFR_CTS          (1 << 0)  // Clear to send

+

+// Flag reg bits - alternative names

+#define UART_TX_EMPTY_FLAG_MASK   PL011_UARTFR_TXFE

+#define UART_RX_FULL_FLAG_MASK    PL011_UARTFR_RXFF

+#define UART_TX_FULL_FLAG_MASK    PL011_UARTFR_TXFF

+#define UART_RX_EMPTY_FLAG_MASK   PL011_UARTFR_RXFE

+#define UART_BUSY_FLAG_MASK       PL011_UARTFR_BUSY

+

+// Control reg bits

+#define PL011_UARTCR_CTSEN        (1 << 15) // CTS hardware flow control enable

+#define PL011_UARTCR_RTSEN        (1 << 14) // RTS hardware flow control enable

+#define PL011_UARTCR_RTS          (1 << 11) // Request to send

+#define PL011_UARTCR_DTR          (1 << 10) // Data transmit ready.

+#define PL011_UARTCR_RXE          (1 << 9)  // Receive enable

+#define PL011_UARTCR_TXE          (1 << 8)  // Transmit enable

+#define PL011_UARTCR_LBE          (1 << 7)  // Loopback enable

+#define PL011_UARTCR_UARTEN       (1 << 0)  // UART Enable

+

+// Line Control Register Bits

+#define PL011_UARTLCR_H_SPS       (1 << 7)  // Stick parity select

+#define PL011_UARTLCR_H_WLEN_8    (3 << 5)

+#define PL011_UARTLCR_H_WLEN_7    (2 << 5)

+#define PL011_UARTLCR_H_WLEN_6    (1 << 5)

+#define PL011_UARTLCR_H_WLEN_5    (0 << 5)

+#define PL011_UARTLCR_H_FEN       (1 << 4)  // FIFOs Enable

+#define PL011_UARTLCR_H_STP2      (1 << 3)  // Two stop bits select

+#define PL011_UARTLCR_H_EPS       (1 << 2)  // Even parity select

+#define PL011_UARTLCR_H_PEN       (1 << 1)  // Parity Enable

+#define PL011_UARTLCR_H_BRK       (1 << 0)  // Send break

+

+#define PL011_UARTPID2_VER(X)     (((X) >> 4) & 0xF)

+#define PL011_VER_R1P4            0x2

+

+/*

+

+  Programmed hardware of Serial port.

+

+  @return    Always return EFI_UNSUPPORTED.

+

+**/

+RETURN_STATUS

+EFIAPI

+PL011UartInitializePort (

+  IN OUT UINTN               UartBase,

+  IN OUT UINT64              *BaudRate,

+  IN OUT UINT32              *ReceiveFifoDepth,

+  IN OUT EFI_PARITY_TYPE     *Parity,

+  IN OUT UINT8               *DataBits,

+  IN OUT EFI_STOP_BITS_TYPE  *StopBits

+  );

+

+/**

+

+  Assert or deassert the control signals on a serial port.

+  The following control signals are set according their bit settings :

+  . Request to Send

+  . Data Terminal Ready

+

+  @param[in]  UartBase  UART registers base address

+  @param[in]  Control   The following bits are taken into account :

+                        . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the

+                          "Request To Send" control signal if this bit is

+                          equal to one/zero.

+                        . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert

+                          the "Data Terminal Ready" control signal if this

+                          bit is equal to one/zero.

+                        . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable

+                          the hardware loopback if this bit is equal to

+                          one/zero.

+                        . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.

+                        . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/

+                          disable the hardware flow control based on CTS (Clear

+                          To Send) and RTS (Ready To Send) control signals.

+

+  @retval  RETURN_SUCCESS      The new control bits were set on the serial device.

+  @retval  RETURN_UNSUPPORTED  The serial device does not support this operation.

+

+**/

+RETURN_STATUS

+EFIAPI

+PL011UartSetControl (

+  IN UINTN   UartBase,

+  IN UINT32  Control

+  );

+

+/**

+

+  Retrieve the status of the control bits on a serial device.

+

+  @param[in]   UartBase  UART registers base address

+  @param[out]  Control   Status of the control bits on a serial device :

+

+                         . EFI_SERIAL_DATA_CLEAR_TO_SEND, EFI_SERIAL_DATA_SET_READY,

+                           EFI_SERIAL_RING_INDICATE, EFI_SERIAL_CARRIER_DETECT,

+                           EFI_SERIAL_REQUEST_TO_SEND, EFI_SERIAL_DATA_TERMINAL_READY

+                           are all related to the DTE (Data Terminal Equipment) and

+                           DCE (Data Communication Equipment) modes of operation of

+                           the serial device.

+                         . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the receive

+                           buffer is empty, 0 otherwise.

+                         . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the transmit

+                           buffer is empty, 0 otherwise.

+                         . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if the

+                           hardware loopback is enabled (the ouput feeds the receive

+                           buffer), 0 otherwise.

+                         . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if a

+                           loopback is accomplished by software, 0 otherwise.

+                         . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to one if the

+                           hardware flow control based on CTS (Clear To Send) and RTS

+                           (Ready To Send) control signals is enabled, 0 otherwise.

+

+

+  @retval RETURN_SUCCESS  The control bits were read from the serial device.

+

+**/

+RETURN_STATUS

+EFIAPI

+PL011UartGetControl (

+  IN UINTN     UartBase,

+  OUT UINT32  *Control

+  );

+

+/**

+  Write data to serial device.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Write data failed.

+  @retval !0               Actual number of bytes written to serial device.

+

+**/

+UINTN

+EFIAPI

+PL011UartWrite (

+  IN  UINTN       UartBase,

+  IN  UINT8       *Buffer,

+  IN  UINTN       NumberOfBytes

+  );

+

+/**

+  Read data from serial device and save the data in buffer.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Read data failed.

+  @retval !0               Actual number of bytes read from serial device.

+

+**/

+UINTN

+EFIAPI

+PL011UartRead (

+  IN  UINTN       UartBase,

+  OUT UINT8       *Buffer,

+  IN  UINTN       NumberOfBytes

+  );

+

+/**

+  Check to see if any data is available to be read from the debug device.

+

+  @retval EFI_SUCCESS       At least one byte of data is available to be read

+  @retval EFI_NOT_READY     No data is available to be read

+  @retval EFI_DEVICE_ERROR  The serial device is not functioning properly

+

+**/

+BOOLEAN

+EFIAPI

+PL011UartPoll (

+  IN  UINTN       UartBase

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h
new file mode 100644
index 0000000..76fbd0e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL031RealTimeClock.h
@@ -0,0 +1,56 @@
+/** @file

+*

+*  Copyright (c) 2011 - 2014, ARM 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.

+*

+**/

+

+

+#ifndef __PL031_REAL_TIME_CLOCK_H__

+#define __PL031_REAL_TIME_CLOCK_H__

+

+// PL031 Registers

+#define PL031_RTC_DR_DATA_REGISTER                      0x000

+#define PL031_RTC_MR_MATCH_REGISTER                     0x004

+#define PL031_RTC_LR_LOAD_REGISTER                      0x008

+#define PL031_RTC_CR_CONTROL_REGISTER                   0x00C

+#define PL031_RTC_IMSC_IRQ_MASK_SET_CLEAR_REGISTER      0x010

+#define PL031_RTC_RIS_RAW_IRQ_STATUS_REGISTER           0x014

+#define PL031_RTC_MIS_MASKED_IRQ_STATUS_REGISTER        0x018

+#define PL031_RTC_ICR_IRQ_CLEAR_REGISTER                0x01C

+#define PL031_RTC_PERIPH_ID0                            0xFE0

+#define PL031_RTC_PERIPH_ID1                            0xFE4

+#define PL031_RTC_PERIPH_ID2                            0xFE8

+#define PL031_RTC_PERIPH_ID3                            0xFEC

+#define PL031_RTC_PCELL_ID0                             0xFF0

+#define PL031_RTC_PCELL_ID1                             0xFF4

+#define PL031_RTC_PCELL_ID2                             0xFF8

+#define PL031_RTC_PCELL_ID3                             0xFFC

+

+// PL031 Values

+#define PL031_RTC_ENABLED                               0x00000001

+#define PL031_SET_IRQ_MASK                              0x00000001

+#define PL031_IRQ_TRIGGERED                             0x00000001

+#define PL031_CLEAR_IRQ                                 0x00000001

+

+#define PL031_COUNTS_PER_SECOND                         1

+

+// Define EPOCH (1970-JANUARY-01) in the Julian Date representation

+#define EPOCH_JULIAN_DATE                               2440588

+

+// Seconds per unit

+#define SEC_PER_MIN                                     ((UINTN)    60)

+#define SEC_PER_HOUR                                    ((UINTN)  3600)

+#define SEC_PER_DAY                                     ((UINTN) 86400)

+

+#define SEC_PER_MONTH                                   ((UINTN)  2,592,000)

+#define SEC_PER_YEAR                                    ((UINTN) 31,536,000)

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL061Gpio.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL061Gpio.h
new file mode 100644
index 0000000..356428a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL061Gpio.h
@@ -0,0 +1,49 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+

+#ifndef __PL061_GPIO_H__

+#define __PL061_GPIO_H__

+

+#include <Protocol/EmbeddedGpio.h>

+

+// PL061 GPIO Registers

+#define PL061_GPIO_DATA_REG             0x000

+#define PL061_GPIO_DIR_REG              0x400

+#define PL061_GPIO_IS_REG               0x404

+#define PL061_GPIO_IBE_REG              0x408

+#define PL061_GPIO_IEV_REG              0x40C

+#define PL061_GPIO_IE_REG               0x410

+#define PL061_GPIO_RIS_REG              0x414

+#define PL061_GPIO_MIS_REG              0x410

+#define PL061_GPIO_IC_REG               0x41C

+#define PL061_GPIO_AFSEL_REG            0x420

+

+#define PL061_GPIO_PERIPH_ID0           0xFE0

+#define PL061_GPIO_PERIPH_ID1           0xFE4

+#define PL061_GPIO_PERIPH_ID2           0xFE8

+#define PL061_GPIO_PERIPH_ID3           0xFEC

+

+#define PL061_GPIO_PCELL_ID0            0xFF0

+#define PL061_GPIO_PCELL_ID1            0xFF4

+#define PL061_GPIO_PCELL_ID2            0xFF8

+#define PL061_GPIO_PCELL_ID3            0xFFC

+

+

+#define PL061_GPIO_PINS                 8

+

+// All bits low except one bit high, native bit length

+#define GPIO_PIN_MASK(Pin)              (1UL << ((UINTN)(Pin)))

+

+#endif  // __PL061_GPIO_H__

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL111Lcd.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL111Lcd.h
new file mode 100644
index 0000000..8c1c29d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL111Lcd.h
@@ -0,0 +1,140 @@
+/** @file  PL111Lcd.h

+

+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>

+ 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 _PL111LCD_H__

+#define _PL111LCD_H__

+

+/**********************************************************************

+ *

+ *  This header file contains all the bits of the PL111 that are

+ *  platform independent.

+ *

+ **********************************************************************/

+

+// Controller Register Offsets

+#define PL111_REG_LCD_TIMING_0            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x000)

+#define PL111_REG_LCD_TIMING_1            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x004)

+#define PL111_REG_LCD_TIMING_2            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x008)

+#define PL111_REG_LCD_TIMING_3            ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x00C)

+#define PL111_REG_LCD_UP_BASE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x010)

+#define PL111_REG_LCD_LP_BASE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x014)

+#define PL111_REG_LCD_CONTROL             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x018)

+#define PL111_REG_LCD_IMSC                ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x01C)

+#define PL111_REG_LCD_RIS                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x020)

+#define PL111_REG_LCD_MIS                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x024)

+#define PL111_REG_LCD_ICR                 ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x028)

+#define PL111_REG_LCD_UP_CURR             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x02C)

+#define PL111_REG_LCD_LP_CURR             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x030)

+#define PL111_REG_LCD_PALETTE             ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0x200)

+

+// Identification Register Offsets

+#define PL111_REG_CLCD_PERIPH_ID_0        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE0)

+#define PL111_REG_CLCD_PERIPH_ID_1        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE4)

+#define PL111_REG_CLCD_PERIPH_ID_2        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFE8)

+#define PL111_REG_CLCD_PERIPH_ID_3        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFEC)

+#define PL111_REG_CLCD_P_CELL_ID_0        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF0)

+#define PL111_REG_CLCD_P_CELL_ID_1        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF4)

+#define PL111_REG_CLCD_P_CELL_ID_2        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFF8)

+#define PL111_REG_CLCD_P_CELL_ID_3        ((UINTN)PcdGet32 (PcdPL111LcdBase) + 0xFFC)

+

+/**********************************************************************/

+

+// Register components (register bits)

+

+// This should make life easier to program specific settings in the different registers

+// by simplifying the setting up of the individual bits of each register

+// and then assembling the final register value.

+

+/**********************************************************************/

+

+// Register: PL111_REG_LCD_TIMING_0

+#define HOR_AXIS_PANEL(hbp,hfp,hsw,hor_res) (UINT32)(((UINT32)(hbp) << 24) | ((UINT32)(hfp) << 16) | ((UINT32)(hsw) << 8) | (((UINT32)((hor_res)/16)-1) << 2))

+

+// Register: PL111_REG_LCD_TIMING_1

+#define VER_AXIS_PANEL(vbp,vfp,vsw,ver_res) (UINT32)(((UINT32)(vbp) << 24) | ((UINT32)(vfp) << 16) | ((UINT32)(vsw) << 10) | ((ver_res)-1))

+

+// Register: PL111_REG_LCD_TIMING_2

+#define PL111_BIT_SHIFT_PCD_HI            27

+#define PL111_BIT_SHIFT_BCD               26

+#define PL111_BIT_SHIFT_CPL               16

+#define PL111_BIT_SHIFT_IOE               14

+#define PL111_BIT_SHIFT_IPC               13

+#define PL111_BIT_SHIFT_IHS               12

+#define PL111_BIT_SHIFT_IVS               11

+#define PL111_BIT_SHIFT_ACB               6

+#define PL111_BIT_SHIFT_CLKSEL            5

+#define PL111_BIT_SHIFT_PCD_LO            0

+

+#define PL111_BCD                         (1 << 26)

+#define PL111_IPC                         (1 << 13)

+#define PL111_IHS                         (1 << 12)

+#define PL111_IVS                         (1 << 11)

+

+#define CLK_SIG_POLARITY(hor_res)         (UINT32)(PL111_BCD | PL111_IPC | PL111_IHS | PL111_IVS | (((hor_res)-1) << 16))

+

+// Register: PL111_REG_LCD_TIMING_3

+#define PL111_BIT_SHIFT_LEE               16

+#define PL111_BIT_SHIFT_LED               0

+

+#define PL111_CTRL_WATERMARK              (1 << 16)

+#define PL111_CTRL_LCD_V_COMP             (1 << 12)

+#define PL111_CTRL_LCD_PWR                (1 << 11)

+#define PL111_CTRL_BEPO                   (1 << 10)

+#define PL111_CTRL_BEBO                   (1 << 9)

+#define PL111_CTRL_BGR                    (1 << 8)

+#define PL111_CTRL_LCD_DUAL               (1 << 7)

+#define PL111_CTRL_LCD_MONO_8             (1 << 6)

+#define PL111_CTRL_LCD_TFT                (1 << 5)

+#define PL111_CTRL_LCD_BW                 (1 << 4)

+#define PL111_CTRL_LCD_1BPP               (0 << 1)

+#define PL111_CTRL_LCD_2BPP               (1 << 1)

+#define PL111_CTRL_LCD_4BPP               (2 << 1)

+#define PL111_CTRL_LCD_8BPP               (3 << 1)

+#define PL111_CTRL_LCD_16BPP              (4 << 1)

+#define PL111_CTRL_LCD_24BPP              (5 << 1)

+#define PL111_CTRL_LCD_16BPP_565          (6 << 1)

+#define PL111_CTRL_LCD_12BPP_444          (7 << 1)

+#define PL111_CTRL_LCD_BPP(Bpp)           ((Bpp) << 1)

+#define PL111_CTRL_LCD_EN                 1

+

+/**********************************************************************/

+

+// Register: PL111_REG_LCD_TIMING_0

+#define PL111_LCD_TIMING_0_HBP(hbp)       (((hbp) & 0xFF) << 24)

+#define PL111_LCD_TIMING_0_HFP(hfp)       (((hfp) & 0xFF) << 16)

+#define PL111_LCD_TIMING_0_HSW(hsw)       (((hsw) & 0xFF) << 8)

+#define PL111_LCD_TIMING_0_PPL(ppl)       (((hsw) & 0x3F) << 2)

+

+// Register: PL111_REG_LCD_TIMING_1

+#define PL111_LCD_TIMING_1_VBP(vbp)       (((vbp) & 0xFF) << 24)

+#define PL111_LCD_TIMING_1_VFP(vfp)       (((vfp) & 0xFF) << 16)

+#define PL111_LCD_TIMING_1_VSW(vsw)       (((vsw) & 0x3F) << 10)

+#define PL111_LCD_TIMING_1_LPP(lpp)        ((lpp) & 0xFC)

+

+// Register: PL111_REG_LCD_TIMING_2

+#define PL111_BIT_MASK_PCD_HI             0xF8000000

+#define PL111_BIT_MASK_BCD                0x04000000

+#define PL111_BIT_MASK_CPL                0x03FF0000

+#define PL111_BIT_MASK_IOE                0x00004000

+#define PL111_BIT_MASK_IPC                0x00002000

+#define PL111_BIT_MASK_IHS                0x00001000

+#define PL111_BIT_MASK_IVS                0x00000800

+#define PL111_BIT_MASK_ACB                0x000007C0

+#define PL111_BIT_MASK_CLKSEL             0x00000020

+#define PL111_BIT_MASK_PCD_LO             0x0000001F

+

+// Register: PL111_REG_LCD_TIMING_3

+#define PL111_BIT_MASK_LEE                0x00010000

+#define PL111_BIT_MASK_LED                0x0000007F

+

+#endif /* _PL111LCD_H__ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL301Axi.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL301Axi.h
new file mode 100644
index 0000000..ae94183
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL301Axi.h
@@ -0,0 +1,21 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef PL301AXI_H_

+#define PL301AXI_H_

+

+VOID PL301AxiInit(UINTN FAxiBase);

+

+

+#endif /* PL301AXI_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL310L2Cache.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL310L2Cache.h
new file mode 100644
index 0000000..a610998
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL310L2Cache.h
@@ -0,0 +1,79 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef L2CACHELIB_H_

+#define L2CACHELIB_H_

+

+#define L2X0_CACHEID            0x000

+#define L2X0_CTRL               0x100

+#define L2X0_AUXCTRL            0x104

+#define L230_TAG_LATENCY        0x108

+#define L230_DATA_LATENCY       0x10C

+#define L2X0_INTCLEAR           0x220

+#define L2X0_CACHE_SYNC         0x730

+#define L2X0_INVWAY             0x77C

+#define L2X0_CLEAN_WAY          0x7BC

+#define L2X0_PFCTRL             0xF60

+#define L2X0_PWRCTRL            0xF80

+

+#define L2X0_CACHEID_IMPLEMENTER_ARM        0x41

+#define L2X0_CACHEID_PARTNUM_PL310          0x03

+

+#define L2X0_CTRL_ENABLED                   0x1

+#define L2X0_CTRL_DISABLED                  0x0

+

+#define L2X0_AUXCTRL_EXCLUSIVE              (1 << 12)

+#define L2X0_AUXCTRL_ASSOCIATIVITY          (1 << 16)

+#define L2X0_AUXCTRL_WAYSIZE_MASK           (3 << 17)

+#define L2X0_AUXCTRL_WAYSIZE_16KB           (1 << 17)

+#define L2X0_AUXCTRL_WAYSIZE_32KB           (2 << 17)

+#define L2X0_AUXCTRL_WAYSIZE_64KB           (3 << 17)

+#define L2X0_AUXCTRL_WAYSIZE_128KB          (4 << 17)

+#define L2X0_AUXCTRL_WAYSIZE_256KB          (5 << 17)

+#define L2X0_AUXCTRL_WAYSIZE_512KB          (6 << 17)

+#define L2X0_AUXCTRL_EM                     (1 << 20)

+#define L2X0_AUXCTRL_SHARED_OVERRIDE        (1 << 22)

+#define L2x0_AUXCTRL_AW_AWCACHE             (0 << 23)

+#define L2x0_AUXCTRL_AW_NOALLOC             (1 << 23)

+#define L2x0_AUXCTRL_AW_OVERRIDE            (2 << 23)

+#define L2X0_AUXCTRL_SBO                    (1 << 25)

+#define L2X0_AUXCTRL_NSAC                   (1 << 27)

+#define L2x0_AUXCTRL_DPREFETCH              (1 << 28)

+#define L2x0_AUXCTRL_IPREFETCH              (1 << 29)

+#define L2x0_AUXCTRL_EARLY_BRESP            (1 << 30)

+

+#define L2x0_LATENCY_1_CYCLE                 0

+#define L2x0_LATENCY_2_CYCLES                1

+#define L2x0_LATENCY_3_CYCLES                2

+#define L2x0_LATENCY_4_CYCLES                3

+#define L2x0_LATENCY_5_CYCLES                4

+#define L2x0_LATENCY_6_CYCLES                5

+#define L2x0_LATENCY_7_CYCLES                6

+#define L2x0_LATENCY_8_CYCLES                7

+

+#define PL310_LATENCIES(Write,Read,Setup)      (((Write) << 8) | ((Read) << 4) | (Setup))

+#define PL310_TAG_LATENCIES(Write,Read,Setup)  PL310_LATENCIES(Write,Read,Setup)

+#define PL310_DATA_LATENCIES(Write,Read,Setup) PL310_LATENCIES(Write,Read,Setup)

+

+VOID

+L2x0CacheInit (

+  IN  UINTN   L2x0Base,

+  IN  UINT32  L2x0TagLatencies,

+  IN  UINT32  L2x0DataLatencies,

+  IN  UINT32  L2x0AuxValue,

+  IN  UINT32  L2x0AuxMask,

+  IN  BOOLEAN CacheEnabled

+  );

+

+#endif /* L2CACHELIB_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL341Dmc.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL341Dmc.h
new file mode 100644
index 0000000..caba8f4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL341Dmc.h
@@ -0,0 +1,336 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef _PL341DMC_H_

+#define _PL341DMC_H_

+

+

+typedef struct  {

+    UINTN   HasQos;        // has QoS registers

+    UINTN   MaxChip;       // number of memory chips accessible

+    BOOLEAN IsUserCfg;

+    UINT32  User0Cfg;

+    UINT32  User2Cfg;

+    UINT32  RefreshPeriod;

+    UINT32  CasLatency;

+    UINT32  WriteLatency;

+    UINT32  t_mrd;

+    UINT32  t_ras;

+    UINT32  t_rc;

+    UINT32  t_rcd;

+    UINT32  t_rfc;

+    UINT32  t_rp;

+    UINT32  t_rrd;

+    UINT32  t_wr;

+    UINT32  t_wtr;

+    UINT32  t_xp;

+    UINT32  t_xsr;

+    UINT32  t_esr;

+    UINT32  MemoryCfg;

+    UINT32  MemoryCfg2;

+    UINT32  MemoryCfg3;

+    UINT32  ChipCfg0;

+    UINT32  ChipCfg1;

+    UINT32  ChipCfg2;

+    UINT32  ChipCfg3;

+    UINT32  t_faw;

+    UINT32  t_data_en;

+    UINT32  t_wdata_en;

+    UINT32  ModeReg;

+    UINT32  ExtModeReg;

+} PL341_DMC_CONFIG;

+

+/* Memory config bit fields */

+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_9      0x1

+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_10     0x2

+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_11     0x3

+#define DMC_MEMORY_CONFIG_COLUMN_ADDRESS_12     0x4

+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_11        (0x0 << 3)

+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_12        (0x1 << 3)

+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_13        (0x2 << 3)

+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_14        (0x3 << 3)

+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_15        (0x4 << 3)

+#define DMC_MEMORY_CONFIG_ROW_ADDRESS_16        (0x5 << 3)

+#define DMC_MEMORY_CONFIG_BURST_2               (0x1 << 15)

+#define DMC_MEMORY_CONFIG_BURST_4               (0x2 << 15)

+#define DMC_MEMORY_CONFIG_BURST_8               (0x3 << 15)

+#define DMC_MEMORY_CONFIG_BURST_16              (0x4 << 15)

+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_1    (0x0 << 21)

+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_2    (0x1 << 21)

+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_3    (0x2 << 21)

+#define DMC_MEMORY_CONFIG_ACTIVE_CHIP_4    (0x3 << 21)

+

+#define DMC_MEMORY_CFG2_CLK_ASYNC    (0x0 << 0)

+#define DMC_MEMORY_CFG2_CLK_SYNC    (0x1 << 0)

+#define DMC_MEMORY_CFG2_DQM_INIT    (0x1 << 2)

+#define DMC_MEMORY_CFG2_CKE_INIT    (0x1 << 3)

+#define DMC_MEMORY_CFG2_BANK_BITS_2    (0x0 << 4)

+#define DMC_MEMORY_CFG2_BANK_BITS_3    (0x3 << 4)

+#define DMC_MEMORY_CFG2_MEM_WIDTH_16    (0x0 << 6)

+#define DMC_MEMORY_CFG2_MEM_WIDTH_32    (0x1 << 6)

+#define DMC_MEMORY_CFG2_MEM_WIDTH_64    (0x2 << 6)

+#define DMC_MEMORY_CFG2_MEM_WIDTH_RESERVED  (0x3 << 6)

+

+//

+// DMC Configuration Register Map

+//

+#define DMC_STATUS_REG              0x00

+#define DMC_COMMAND_REG             0x04

+#define DMC_DIRECT_CMD_REG          0x08

+#define DMC_MEMORY_CONFIG_REG       0x0C

+#define DMC_REFRESH_PRD_REG         0x10

+#define DMC_CAS_LATENCY_REG         0x14

+#define DMC_WRITE_LATENCY_REG       0x18

+#define DMC_T_MRD_REG               0x1C

+#define DMC_T_RAS_REG               0x20

+#define DMC_T_RC_REG                0x24

+#define DMC_T_RCD_REG               0x28

+#define DMC_T_RFC_REG               0x2C

+#define DMC_T_RP_REG                0x30

+#define DMC_T_RRD_REG               0x34

+#define DMC_T_WR_REG                0x38

+#define DMC_T_WTR_REG               0x3C

+#define DMC_T_XP_REG                0x40

+#define DMC_T_XSR_REG               0x44

+#define DMC_T_ESR_REG               0x48

+#define DMC_MEMORY_CFG2_REG         0x4C

+#define DMC_MEMORY_CFG3_REG         0x50

+#define DMC_T_FAW_REG               0x54

+#define DMC_T_RDATA_EN              0x5C        /* DFI read data enable register */

+#define DMC_T_WRLAT_DIFF            0x60        /* DFI write data enable register */

+

+// Returns the state of the memory controller:

+#define DMC_STATUS_CONFIG       0x0

+#define DMC_STATUS_READY        0x1

+#define DMC_STATUS_PAUSED       0x2

+#define DMC_STATUS_LOWPOWER     0x3

+

+// Changes the state of the memory controller:

+#define DMC_COMMAND_GO              0x0

+#define DMC_COMMAND_SLEEP           0x1

+#define DMC_COMMAND_WAKEUP          0x2

+#define DMC_COMMAND_PAUSE           0x3

+#define DMC_COMMAND_CONFIGURE       0x4

+#define DMC_COMMAND_ACTIVEPAUSE     0x7

+

+// Determines the command required

+#define DMC_DIRECT_CMD_MEMCMD_PRECHARGEALL      0x0

+#define DMC_DIRECT_CMD_MEMCMD_AUTOREFRESH       (0x1 << 18)

+#define DMC_DIRECT_CMD_MEMCMD_MODEREG           (0x2 << 18)

+#define DMC_DIRECT_CMD_MEMCMD_EXTMODEREG        (0x2 << 18)

+#define DMC_DIRECT_CMD_MEMCMD_NOP               (0x3 << 18)

+#define DMC_DIRECT_CMD_MEMCMD_DPD               (0x1 << 22)

+#define DMC_DIRECT_CMD_BANKADDR(n)              ((n & 0x3) << 16)

+#define DMC_DIRECT_CMD_CHIP_ADDR(n)             ((n & 0x3) << 20)

+

+

+//

+// AXI ID configuration register map

+//

+#define DMC_ID_0_CFG_REG            0x100

+#define DMC_ID_1_CFG_REG            0x104

+#define DMC_ID_2_CFG_REG            0x108

+#define DMC_ID_3_CFG_REG            0x10C

+#define DMC_ID_4_CFG_REG            0x110

+#define DMC_ID_5_CFG_REG            0x114

+#define DMC_ID_6_CFG_REG            0x118

+#define DMC_ID_7_CFG_REG            0x11C

+#define DMC_ID_8_CFG_REG            0x120

+#define DMC_ID_9_CFG_REG            0x124

+#define DMC_ID_10_CFG_REG           0x128

+#define DMC_ID_11_CFG_REG           0x12C

+#define DMC_ID_12_CFG_REG           0x130

+#define DMC_ID_13_CFG_REG           0x134

+#define DMC_ID_14_CFG_REG           0x138

+#define DMC_ID_15_CFG_REG           0x13C

+

+// Set the QoS

+#define DMC_ID_CFG_QOS_DISABLE      0

+#define DMC_ID_CFG_QOS_ENABLE       1

+#define DMC_ID_CFG_QOS_MIN          2

+

+

+//

+// Chip configuration register map

+//

+#define DMC_CHIP_0_CFG_REG          0x200

+#define DMC_CHIP_1_CFG_REG          0x204

+#define DMC_CHIP_2_CFG_REG          0x208

+#define DMC_CHIP_3_CFG_REG          0x20C

+

+//

+// User Defined Pins

+//

+#define DMC_USER_STATUS_REG         0x300

+#define DMC_USER_0_CFG_REG          0x304

+#define DMC_USER_1_CFG_REG          0x308

+#define DMC_FEATURE_CRTL_REG        0x30C

+#define DMC_USER_2_CFG_REG          0x310

+

+

+//

+// PHY Register Settings

+//

+#define PHY_PTM_DFI_CLK_RANGE       0xE00  // DDR2 PHY PTM register offset

+#define PHY_PTM_IOTERM              0xE04

+#define PHY_PTM_PLL_EN              0xe0c

+#define PHY_PTM_PLL_RANGE           0xe18

+#define PHY_PTM_FEEBACK_DIV         0xe1c

+#define PHY_PTM_RCLK_DIV            0xe20

+#define PHY_PTM_LOCK_STATUS         0xe28

+#define PHY_PTM_INIT_DONE           0xe34

+#define PHY_PTM_ADDCOM_IOSTR_OFF    0xec8

+#define PHY_PTM_SQU_TRAINING        0xee8

+#define PHY_PTM_SQU_STAT            0xeec

+

+// ==============================================================================

+// PIPD 40G DDR2/DDR3 PHY Register definitions

+//

+// Offsets from APB Base Address

+// ==============================================================================

+#define PHY_BYTE0_OFFSET            0x000

+#define PHY_BYTE1_OFFSET            0x200

+#define PHY_BYTE2_OFFSET            0x400

+#define PHY_BYTE3_OFFSET            0x600

+

+#define PHY_BYTE0_COARSE_SQADJ_INIT 0x064  ;// Coarse squelch adjust

+#define PHY_BYTE1_COARSE_SQADJ_INIT 0x264  ;// Coarse squelch adjust

+#define PHY_BYTE2_COARSE_SQADJ_INIT 0x464  ;// Coarse squelch adjust

+#define PHY_BYTE3_COARSE_SQADJ_INIT 0x664  ;// Coarse squelch adjust

+

+#define PHY_BYTE0_IOSTR_OFFSET      0x004

+#define PHY_BYTE1_IOSTR_OFFSET      0x204

+#define PHY_BYTE2_IOSTR_OFFSET      0x404

+#define PHY_BYTE3_IOSTR_OFFSET      0x604

+

+

+;//--------------------------------------------------------------------------

+

+// DFI Clock ranges:

+

+#define PHY_PTM_DFI_CLK_RANGE_200MHz            0x0

+#define PHY_PTM_DFI_CLK_RANGE_201_267MHz        0x1

+#define PHY_PTM_DFI_CLK_RANGE_268_333MHz        0x2

+#define PHY_PTM_DFI_CLK_RANGE_334_400MHz        0x3

+#define PHY_PTM_DFI_CLK_RANGE_401_533MHz        0x4

+#define PHY_PTM_DFI_CLK_RANGE_534_667MHz        0x5

+#define PHY_PTM_DFI_CLK_RANGE_668_800MHz        0x6

+

+

+

+#define  PHY_PTM_DFI_CLK_RANGE_VAL              PHY_PTM_DFI_CLK_RANGE_334_400MHz

+

+//--------------------------------------------------------------------------

+

+

+// PLL Range

+

+#define PHY_PTM_PLL_RANGE_200_400MHz            0x0     // b0 = frequency >= 200 MHz and < 400 MHz

+#define PHY_PTM_PLL_RANGE_400_800MHz            0x1     // b1 = frequency >= 400 MHz.

+#define PHY_PTM_FEEBACK_DIV_200_400MHz          0x0     // b0 = frequency >= 200 MHz and < 400 MHz

+#define PHY_PTM_FEEBACK_DIV_400_800MHz          0x1     // b1 = frequency >= 400 MHz.

+#define PHY_PTM_REFCLK_DIV_200_400MHz           0x0

+#define PHY_PTM_REFCLK_DIV_400_800MHz           0x1

+

+#define TC_UIOLHNC_MASK                         0x000003C0

+#define TC_UIOLHNC_SHIFT                        0x6

+#define TC_UIOLHPC_MASK                         0x0000003F

+#define TC_UIOLHPC_SHIFT                        0x2

+#define TC_UIOHOCT_MASK                         0x2

+#define TC_UIOHOCT_SHIFT                        0x1

+#define TC_UIOHSTOP_SHIFT                       0x0

+#define TC_UIOLHXC_VALUE                        0x4

+

+#define PHY_PTM_SQU_TRAINING_ENABLE             0x1

+#define PHY_PTM_SQU_TRAINING_DISABLE            0x0

+

+

+//--------------------------------------

+// JEDEC DDR2 Device Register definitions and settings

+//--------------------------------------

+#define DDR_MODESET_SHFT                        14

+#define DDR_MODESET_MR                          0x0  ;// Mode register

+#define DDR_MODESET_EMR                         0x1  ;// Extended Mode register

+#define DDR_MODESET_EMR2                        0x2

+#define DDR_MODESET_EMR3                        0x3

+

+//

+// Extended Mode Register settings

+//

+#define DDR_EMR_OCD_MASK                        0x0000380

+#define DDR_EMR_OCD_SHIFT                       0x7

+#define DDR_EMR_RTT_MASK                        0x00000044                  // DDR2 Device RTT (ODT) settings

+#define DDR_EMR_RTT_SHIFT                       0x2

+#define DDR_EMR_ODS_MASK                        0x00000002                  // DDR2 Output Drive Strength

+#define DDR_EMR_ODS_SHIFT                       0x0001

+

+// Termination Values:

+#define DDR_EMR_RTT_50R                         0x00000044                  // DDR2 50 Ohm termination

+#define DDR_EMR_RTT_75R                         0x00000004                  // DDR2 75 Ohm termination

+#define DDR_EMR_RTT_150                         0x00000040                  // DDR2 150 Ohm termination

+

+// Output Drive Strength Values:

+#define DDR_EMR_ODS_FULL                        0x0                         // DDR2 Full Drive Strength

+#define DDR_EMR_ODS_HALF                        0x1                         // DDR2 Half Drive Strength

+

+// OCD values

+#define DDR_EMR_OCD_DEFAULT                     0x7

+#define DDR_EMR_OCD_NS                          0x0

+

+#define DDR_EMR_ODS_VAL                         DDR_EMR_ODS_FULL

+

+#define DDR_SDRAM_START_ADDR                    0x10000000

+

+

+// ----------------------------------------

+// PHY IOTERM values

+// ----------------------------------------

+#define PHY_PTM_IOTERM_OFF                      0x0

+#define PHY_PTM_IOTERM_150R                     0x1

+#define PHY_PTM_IOTERM_75R                      0x2

+#define PHY_PTM_IOTERM_50R                      0x3

+

+#define PHY_BYTE_IOSTR_60OHM                    0x0

+#define PHY_BYTE_IOSTR_40OHM                    0x1

+#define PHY_BYTE_IOSTR_30OHM                    0x2

+#define PHY_BYTE_IOSTR_30AOHM                   0x3

+

+#define DDR2_MR_BURST_LENGTH_4     (2)

+#define DDR2_MR_BURST_LENGTH_8     (3)

+#define DDR2_MR_DLL_RESET          (1 << 8)

+#define DDR2_MR_CAS_LATENCY_4      (4 << 4)

+#define DDR2_MR_CAS_LATENCY_5      (5 << 4)

+#define DDR2_MR_CAS_LATENCY_6      (6 << 4)

+#define DDR2_MR_WR_CYCLES_2        (1 << 9)

+#define DDR2_MR_WR_CYCLES_3        (2 << 9)

+#define DDR2_MR_WR_CYCLES_4        (3 << 9)

+#define DDR2_MR_WR_CYCLES_5        (4 << 9)

+#define DDR2_MR_WR_CYCLES_6        (5 << 9)

+

+

+VOID

+PL341DmcInit (

+  IN  UINTN             DmcBase,

+  IN  PL341_DMC_CONFIG* DmcConfig

+  );

+

+VOID PL341DmcPhyInit (

+  IN UINTN   DmcPhyBase

+  );

+

+VOID PL341DmcTrainPHY (

+  IN UINTN   DmcPhyBase

+  );

+

+#endif /* _PL341DMC_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL35xSmc.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL35xSmc.h
new file mode 100644
index 0000000..750f508
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/PL35xSmc.h
@@ -0,0 +1,75 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#ifndef PL35xSMC_H_

+#define PL35xSMC_H_

+

+#define PL350_SMC_DIRECT_CMD_OFFSET   0x10

+#define PL350_SMC_SET_CYCLES_OFFSET   0x14

+#define PL350_SMC_SET_OPMODE_OFFSET   0x18

+#define PL350_SMC_REFRESH_0_OFFSET    0x20

+#define PL350_SMC_REFRESH_1_OFFSET    0x24

+

+#define PL350_SMC_DIRECT_CMD_ADDR(addr)                 ((addr) & 0xFFFFF)

+#define PL350_SMC_DIRECT_CMD_ADDR_SET_CRE               (1 << 20)

+#define PL350_SMC_DIRECT_CMD_ADDR_CMD_MODE_UPDATE       (3 << 21)

+#define PL350_SMC_DIRECT_CMD_ADDR_CMD_UPDATE            (2 << 21)

+#define PL350_SMC_DIRECT_CMD_ADDR_CMD_MODE              (1 << 21)

+#define PL350_SMC_DIRECT_CMD_ADDR_CMD_UPDATE_AXI        (0 << 21)

+#define PL350_SMC_DIRECT_CMD_ADDR_CS_INTERF(interf,chip) (((interf) << 25) | ((chip) << 23))

+#define PL350_SMC_DIRECT_CMD_ADDR_CS(ChipSelect)        (((ChipSelect) & 0x7) << 23)

+

+#define PL350_SMC_SET_OPMODE_MEM_WIDTH_8                (0 << 0)

+#define PL350_SMC_SET_OPMODE_MEM_WIDTH_16               (1 << 0)

+#define PL350_SMC_SET_OPMODE_MEM_WIDTH_32               (2 << 0)

+#define PL350_SMC_SET_OPMODE_SET_RD_SYNC                (1 << 2)

+#define PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_1      (0 << 3)

+#define PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_4      (1 << 3)

+#define PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_8      (2 << 3)

+#define PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_16     (3 << 3)

+#define PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_32     (4 << 3)

+#define PL350_SMC_SET_OPMODE_SET_RD_BURST_LENGTH_CONT   (5 << 3)

+#define PL350_SMC_SET_OPMODE_SET_WR_SYNC                (1 << 6)

+#define PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_1      (0 << 7)

+#define PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_4      (1 << 7)

+#define PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_8      (2 << 7)

+#define PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_16     (3 << 7)

+#define PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_32     (4 << 7)

+#define PL350_SMC_SET_OPMODE_SET_WR_BURST_LENGTH_CONT   (5 << 7)

+#define PL350_SMC_SET_OPMODE_SET_BAA                    (1 << 10)

+#define PL350_SMC_SET_OPMODE_SET_ADV                    (1 << 11)

+#define PL350_SMC_SET_OPMODE_SET_BLS                    (1 << 12)

+#define PL350_SMC_SET_OPMODE_SET_BURST_ALIGN_ANY        (0 << 13)

+#define PL350_SMC_SET_OPMODE_SET_BURST_ALIGN_32         (1 << 13)

+#define PL350_SMC_SET_OPMODE_SET_BURST_ALIGN_64         (2 << 13)

+#define PL350_SMC_SET_OPMODE_SET_BURST_ALIGN_128        (3 << 13)

+#define PL350_SMC_SET_OPMODE_SET_BURST_ALIGN_256        (4 << 13)

+

+#define PL350_SMC_SET_CYCLE_NAND_T_RC(t)                (((t) & 0xF) << 0)

+#define PL350_SMC_SET_CYCLE_NAND_T_WC(t)                (((t) & 0xF) << 4)

+#define PL350_SMC_SET_CYCLE_NAND_T_REA(t)              (((t) & 0x7) << 8)

+#define PL350_SMC_SET_CYCLE_NAND_T_WP(t)                (((t) & 0x7) << 11)

+#define PL350_SMC_SET_CYCLE_NAND_T_CLR(t)                (((t) & 0x7) << 14)

+#define PL350_SMC_SET_CYCLE_NAND_T_AR(t)                (((t) & 0x7) << 17)

+#define PL350_SMC_SET_CYCLE_NAND_T_RR(t)                (((t) & 0x7) << 20)

+

+#define PL350_SMC_SET_CYCLE_SRAM_T_RC(t)                (((t) & 0xF) << 0)

+#define PL350_SMC_SET_CYCLE_SRAM_T_WC(t)                (((t) & 0xF) << 4)

+#define PL350_SMC_SET_CYCLE_SRAM_T_CEOE(t)              (((t) & 0x7) << 8)

+#define PL350_SMC_SET_CYCLE_SRAM_T_WP(t)                (((t) & 0x7) << 11)

+#define PL350_SMC_SET_CYCLE_SRAM_T_PC(t)                (((t) & 0x7) << 14)

+#define PL350_SMC_SET_CYCLE_SRAM_T_TR(t)                (((t) & 0x7) << 17)

+#define PL350_SMC_SET_CYCLE_SRAM_WE_TIME                (1 << 20)

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/SP804Timer.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/SP804Timer.h
new file mode 100644
index 0000000..904b13c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/SP804Timer.h
@@ -0,0 +1,57 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+

+#ifndef _SP804_TIMER_H__

+#define _SP804_TIMER_H__

+

+// SP804 Timer constants

+// Note: The SP804 Timer module comprises two timers, Timer_0 and Timer_1

+//       These timers are identical and all their registers have an offset of 0x20

+//       i.e. SP804_TIMER_0_LOAD_REG = 0x00 and SP804_TIMER_1_LOAD_REG = 0x20

+//       Therefore, define all registers only once and adjust the base addresses by 0x20

+#define SP804_TIMER_LOAD_REG            0x00

+#define SP804_TIMER_CURRENT_REG         0x04

+#define SP804_TIMER_CONTROL_REG         0x08

+#define SP804_TIMER_INT_CLR_REG         0x0C

+#define SP804_TIMER_RAW_INT_STS_REG     0x10

+#define SP804_TIMER_MSK_INT_STS_REG     0x14

+#define SP804_TIMER_BG_LOAD_REG         0x18

+

+// Timer control register bit definitions

+#define SP804_TIMER_CTRL_ONESHOT        BIT0

+#define SP804_TIMER_CTRL_32BIT          BIT1

+#define SP804_TIMER_CTRL_PRESCALE_MASK  (BIT3|BIT2)

+#define SP804_PRESCALE_DIV_1            0

+#define SP804_PRESCALE_DIV_16           BIT2

+#define SP804_PRESCALE_DIV_256          BIT3

+#define SP804_TIMER_CTRL_INT_ENABLE     BIT5

+#define SP804_TIMER_CTRL_PERIODIC       BIT6

+#define SP804_TIMER_CTRL_ENABLE         BIT7

+

+// Other SP804 Timer definitions

+#define SP804_MAX_TICKS                 0xFFFFFFFF

+

+// SP810 System Controller constants

+#define SP810_SYS_CTRL_REG              0x00

+#define SP810_SYS_CTRL_TIMER0_TIMCLK    BIT15 // 0=REFCLK, 1=TIMCLK

+#define SP810_SYS_CTRL_TIMER0_EN        BIT16

+#define SP810_SYS_CTRL_TIMER1_TIMCLK    BIT17 // 0=REFCLK, 1=TIMCLK

+#define SP810_SYS_CTRL_TIMER1_EN        BIT18

+#define SP810_SYS_CTRL_TIMER2_TIMCLK    BIT19 // 0=REFCLK, 1=TIMCLK

+#define SP810_SYS_CTRL_TIMER2_EN        BIT20

+#define SP810_SYS_CTRL_TIMER3_TIMCLK    BIT21 // 0=REFCLK, 1=TIMCLK

+#define SP810_SYS_CTRL_TIMER3_EN        BIT22

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/SP805Watchdog.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/SP805Watchdog.h
new file mode 100644
index 0000000..4d5e145
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Drivers/SP805Watchdog.h
@@ -0,0 +1,48 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+

+#ifndef __SP805_WATCHDOG_H__

+#define __SP805_WATCHDOG_H__

+

+// SP805 Watchdog Registers

+#define SP805_WDOG_LOAD_REG             ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x000)

+#define SP805_WDOG_CURRENT_REG          ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x004)

+#define SP805_WDOG_CONTROL_REG          ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x008)

+#define SP805_WDOG_INT_CLR_REG          ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x00C)

+#define SP805_WDOG_RAW_INT_STS_REG      ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x010)

+#define SP805_WDOG_MSK_INT_STS_REG      ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x014)

+#define SP805_WDOG_LOCK_REG             ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xC00)

+

+#define SP805_WDOG_PERIPH_ID0           ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE0)

+#define SP805_WDOG_PERIPH_ID1           ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE4)

+#define SP805_WDOG_PERIPH_ID2           ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE8)

+#define SP805_WDOG_PERIPH_ID3           ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFEC)

+

+#define SP805_WDOG_PCELL_ID0            ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF0)

+#define SP805_WDOG_PCELL_ID1            ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF4)

+#define SP805_WDOG_PCELL_ID2            ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF8)

+#define SP805_WDOG_PCELL_ID3            ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFFC)

+

+// Timer control register bit definitions

+#define SP805_WDOG_CTRL_INTEN           BIT0

+#define SP805_WDOG_CTRL_RESEN           BIT1

+#define SP805_WDOG_RAW_INT_STS_WDOGRIS  BIT0

+#define SP805_WDOG_MSK_INT_STS_WDOGMIS  BIT0

+

+#define SP805_WDOG_LOCK_IS_UNLOCKED     0x00000000

+#define SP805_WDOG_LOCK_IS_LOCKED       0x00000001

+#define SP805_WDOG_SPECIAL_UNLOCK_CODE  0x1ACCE551

+

+#endif  // __SP805_WATCHDOG_H__

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/ArmGlobalVariableHob.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/ArmGlobalVariableHob.h
new file mode 100644
index 0000000..844090b
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/ArmGlobalVariableHob.h
@@ -0,0 +1,51 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#ifndef __ARM_GLOBAL_VARIABLE_GUID_H__

+#define __ARM_GLOBAL_VARIABLE_GUID_H__

+

+#include <Pi/PiBootMode.h>

+#include <Pi/PiHob.h>

+

+#define ARM_HOB_GLOBAL_VARIABLE_GUID  \

+  { 0xc3253c90, 0xa24f, 0x4599, { 0xa6, 0x64, 0x1f, 0x88, 0x13, 0x77, 0x8f, 0xc9} };

+

+extern EFI_GUID gArmGlobalVariableGuid;

+

+///

+/// Describes all memory ranges used during the HOB producer

+/// phase that exist outside the HOB list. This HOB type

+/// describes how memory is used, not the physical attributes of memory.

+///

+typedef struct {

+  ///

+  /// The Guid HOB header. Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION

+  ///                 and  Header.Name    = gArmGlobalVariableGuid

+  ///

+  EFI_HOB_GUID_TYPE            Header;

+

+  ///

+  /// The base address of memory allocated by this HOB. Type

+  /// EFI_PHYSICAL_ADDRESS is defined in AllocatePages() in the UEFI 2.0

+  /// specification.

+  ///

+  EFI_PHYSICAL_ADDRESS        GlobalVariableBase;

+

+  ///

+  /// The length in bytes of memory allocated by this HOB.

+  ///

+  UINT32                      GlobalVariableSize;

+} ARM_HOB_GLOBAL_VARIABLE;

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/ArmPlatformEvents.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/ArmPlatformEvents.h
new file mode 100644
index 0000000..9027bc3
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/ArmPlatformEvents.h
@@ -0,0 +1,23 @@
+/** @file

+*

+*  Copyright (c) 2015, ARM 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.

+*

+**/

+

+#ifndef __ARM_PLATFORM_EVENTS_H__

+#define __ARM_PLATFORM_EVENTS_H__

+

+#define ARM_PLATFORM_UPDATE_FDT_EVENT_GUID \

+  { 0xaffe115b, 0x8589, 0x456d, { 0xba, 0xb5, 0x8f, 0x2e, 0xda, 0x53, 0xae, 0xb7 } }

+

+extern EFI_GUID gArmPlatformUpdateFdtEventGuid;

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/BootMonFsFileInfo.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/BootMonFsFileInfo.h
new file mode 100644
index 0000000..c4d805c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Guid/BootMonFsFileInfo.h
@@ -0,0 +1,47 @@
+/** @file

+*

+*  Copyright (c) 2014, ARM Ltd. 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 __BOOTMON_FS_FILE_INFO_H__

+#define __BOOTMON_FS_FILE_INFO_H__

+

+#define BOOTMON_FS_FILE_INFO_ID \

+  { \

+    0x41e26b9c, 0xada6, 0x45b3, {0x80, 0x8e, 0x23, 0x57, 0xa3, 0x5b, 0x60, 0xd6 } \

+  }

+

+// From BootMonFS header file

+#define BOOTMONFS_IMAGE_DESCRIPTION_REGION_MAX 4

+

+typedef struct {

+  // The size of the structure.

+  UINT64    Size;

+

+  // Subset of properties stored in the file meta-data.

+  UINT32  EntryPoint;

+  UINT32  RegionCount;

+  struct {

+    UINT32 LoadAddress;

+    UINT32 Size;

+    UINT32 Offset;

+    UINT32 Checksum;

+  } Region[BOOTMONFS_IMAGE_DESCRIPTION_REGION_MAX];

+

+} BOOTMON_FS_FILE_INFO;

+

+#define SIZE_OF_BOOTMON_FS_FILE_INFO \

+  OFFSET_OF (BOOTMON_FS_FILE_INFO, Region[BOOTMONFS_IMAGE_DESCRIPTION_REGION_MAX - 1].Checksum)

+

+extern EFI_GUID gArmBootMonFsFileInfoGuid;

+

+#endif // __BOOTMON_FS_FILE_INFO_H__

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h
new file mode 100644
index 0000000..b1a080c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h
@@ -0,0 +1,38 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#ifndef __ARM_PLATFORM_GLOBAL_VARIABLE_LIB_H_

+#define __ARM_PLATFORM_GLOBAL_VARIABLE_LIB_H_

+

+VOID

+ArmPlatformGetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  );

+

+VOID

+ArmPlatformSetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  );

+

+VOID*

+ArmPlatformGetGlobalVariableAddress (

+  IN  UINTN     VariableOffset

+  );

+

+#endif

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformLib.h
new file mode 100644
index 0000000..77561a3
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformLib.h
@@ -0,0 +1,169 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#ifndef _ARMPLATFORMLIB_H_

+#define _ARMPLATFORMLIB_H_

+

+//

+// The package level header files this module uses

+//

+#include <PiPei.h>

+//

+// The protocols, PPI and GUID defintions for this module

+//

+#include <Ppi/MasterBootMode.h>

+#include <Ppi/BootInRecoveryMode.h>

+

+#include <Library/ArmLib.h>

+

+/**

+  This structure is used to describe a region of the EFI memory map

+

+  Every EFI regions of the system memory described by their physical start address and their size

+  can have different attributes. Some regions can be tested and other untested.

+

+**/

+typedef struct {

+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute;

+  EFI_PHYSICAL_ADDRESS         PhysicalStart;

+  UINT64                       NumberOfBytes;

+} ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR;

+

+/**

+  Return the core position from the value of its MpId register

+

+  This function returns the core position from the position 0 in the processor.

+  This function might be called from assembler before any stack is set.

+

+  @return   Return the core position

+

+**/

+UINTN

+ArmPlatformGetCorePosition (

+  IN UINTN MpId

+  );

+

+/**

+  Return a non-zero value if the callee is the primary core

+

+  This function returns a non-zero value if the callee is the primary core.

+  The primary core is the core responsible to initialize the hardware and run UEFI.

+  This function might be called from assembler before any stack is set.

+

+  @return   Return a non-zero value if the callee is the primary core.

+

+**/

+UINTN

+ArmPlatformIsPrimaryCore (

+  IN UINTN MpId

+  );

+

+/**

+  Return the MpId of the primary core

+

+  This function returns the MpId of the primary core.

+  This function might be called from assembler before any stack is set.

+

+  @return   Return the MpId of the primary core

+

+**/

+UINTN

+ArmPlatformGetPrimaryCoreMpId (

+  VOID

+  );

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+  @return   Return the current Boot Mode of the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  );

+

+/**

+  First platform specific function to be called in the PEI phase

+

+  This function is actually the first function called by the PrePi

+  or PrePeiCore modules. It allows to retrieve arguments passed to

+  the UEFI firmware through the CPU registers.

+

+  This function might be written into assembler as no stack are set

+  when the function is invoked.

+

+**/

+VOID

+ArmPlatformPeiBootAction (

+  VOID

+  );

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  );

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  );

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  OUT ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  );

+

+/**

+  Return the Platform specific PPIs

+

+  This function exposes the Platform Specific PPIs. They can be used by any PrePi modules or passed

+  to the PeiCore by PrePeiCore.

+

+  @param[out]   PpiListSize         Size in Bytes of the Platform PPI List

+  @param[out]   PpiList             Platform PPI List

+

+**/

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformSecLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformSecLib.h
new file mode 100644
index 0000000..cb3148e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformSecLib.h
@@ -0,0 +1,88 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#ifndef _ARMPLATFORMSECLIB_H_

+#define _ARMPLATFORMSECLIB_H_

+

+#define ARM_SEC_BOOT_MASK                 ~0

+#define ARM_SEC_COLD_BOOT                 (1 << 0)

+#define ARM_SEC_SECONDARY_COLD_BOOT       (1 << 1)

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+VOID

+ArmPlatformSecBootMemoryInit (

+  VOID

+  );

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+VOID

+ArmPlatformSecBootAction (

+  VOID

+  );

+

+/**

+  Initialize controllers that must setup at the early stage

+

+  Some peripherals must be initialized in Secure World.

+  For example: Some L2 controller, interconnect, clock, DMC, etc

+

+**/

+RETURN_STATUS

+ArmPlatformSecInitialize (

+  IN  UINTN                     MpId

+  );

+

+/**

+  Call before jumping to Normal World

+

+  This function allows the firmware platform to do extra actions before

+  jumping to the Normal World

+

+**/

+VOID

+ArmPlatformSecExtraAction (

+  IN  UINTN         MpId,

+  OUT UINTN*        JumpAddress

+  );

+

+/**

+  Initialize the Secure peripherals and memory regions

+

+  If Trustzone is supported by your platform then this function makes the required initialization

+  of the secure peripherals and memory regions.

+

+**/

+VOID

+ArmPlatformSecTrustzoneInit (

+  IN  UINTN                     MpId

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformSysConfigLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformSysConfigLib.h
new file mode 100644
index 0000000..39a0cc7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmPlatformSysConfigLib.h
@@ -0,0 +1,63 @@
+/** @file  ArmPlatformSysConfigLib.h

+

+  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+

+  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 __ARM_PLATFORM_SYS_CONFIG_H__

+#define __ARM_PLATFORM_SYS_CONFIG_H__

+

+#include <Base.h>

+

+/* This header file makes it easier to access the System Configuration Registers

+ * in the ARM Versatile Express motherboard.

+ */

+

+//

+// Typedef

+//

+typedef UINT32  SYS_CONFIG_FUNCTION;

+

+//

+// Functions

+//

+RETURN_STATUS

+ArmPlatformSysConfigInitialize (

+  VOID

+  );

+

+RETURN_STATUS

+ArmPlatformSysConfigGet (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  OUT UINT32*               Value

+  );

+

+RETURN_STATUS

+ArmPlatformSysConfigGetValues (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINTN                 Size,

+  OUT UINT32*               Values

+  );

+

+RETURN_STATUS

+ArmPlatformSysConfigSet (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINT32                Value

+  );

+

+RETURN_STATUS

+ArmPlatformSysConfigSetDevice (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINT32                Device,

+  IN  UINT32                Value

+  );

+

+#endif /* __SYS_CFG_REGISTERS_H__ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmShellCmdLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmShellCmdLib.h
new file mode 100644
index 0000000..eb31cd4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmShellCmdLib.h
@@ -0,0 +1,57 @@
+/** @file

+*

+*  Definitions for the Dynamic Shell command library

+*

+*  Copyright (C) 2014, ARM Ltd

+*

+*  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 _ARM_SHELL_CMD_LIB_H_

+#define _ARM_SHELL_CMD_LIB_H_

+

+/**

+

+  Initialize and Install EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL for RunAxf command.

+

+  @param[in] ImageHandle        Handle the protocol should be attached to.

+

+  @retval EFI_SUCCESS           The command has been installed successfully.

+

+  @retval EFI_UNSUPPORTED       Help for the command failed to initialise.

+

+  @return                       Status code returned by InstallProtocolInterface

+                                Boot Service function.

+

+**/

+EFI_STATUS

+ShellDynCmdRunAxfInstall (

+  IN EFI_HANDLE             ImageHandle

+  );

+

+/**

+

+  Uninstall the RunAxf Command

+

+  @param[in] ImageHandle  Handle of the device where the protocol should have

+                          been installed.

+

+  @retval EFI_SUCCESS     The device has been un-initialized successfully.

+

+  @return                 Status code returned by UninstallProtocolInterface

+                          Boot Service function.

+

+**/

+EFI_STATUS

+ShellDynCmdRunAxfUninstall (

+  IN EFI_HANDLE             ImageHandle

+  );

+

+#endif // _ARM_SHELL_CMD_LIB_H_

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmTrustedMonitorLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmTrustedMonitorLib.h
new file mode 100644
index 0000000..5368697
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/ArmTrustedMonitorLib.h
@@ -0,0 +1,24 @@
+/** @file

+*  Main file supporting the Monitor World on ARM PLatforms

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef __ARM_TRUSTED_MONITOR_LIB_H_

+#define __ARM_TRUSTED_MONITOR_LIB_H_

+

+VOID

+ArmSecureMonitorWorldInitialize (

+  VOID

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/LcdPlatformLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/LcdPlatformLib.h
new file mode 100644
index 0000000..b9bdf47
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/LcdPlatformLib.h
@@ -0,0 +1,221 @@
+/** @file

+

+ Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>

+ 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 __LCDPLATFORMLIB_H

+#define __LCDPLATFORMLIB_H

+

+#include <Protocol/GraphicsOutput.h>

+

+#define LCD_VRAM_SIZE                     SIZE_8MB

+

+//

+// Modes definitions

+//

+#define VGA                               0

+#define SVGA                              1

+#define XGA                               2

+#define SXGA                              3

+#define WSXGA                             4

+#define UXGA                              5

+#define HD                                6

+

+//

+// VGA Mode: 640 x 480

+//

+#define VGA_H_RES_PIXELS                  640

+#define VGA_V_RES_PIXELS                  480

+#define VGA_OSC_FREQUENCY                 23750000  /* 0x016A6570 */

+

+#define VGA_H_SYNC                        ( 80 - 1)

+#define VGA_H_FRONT_PORCH                 ( 16 - 1)

+#define VGA_H_BACK_PORCH                  ( 64 - 1)

+

+#define VGA_V_SYNC                        (  4 - 1)

+#define VGA_V_FRONT_PORCH                 (  3 - 1)

+#define VGA_V_BACK_PORCH                  ( 13 - 1)

+

+//

+// SVGA Mode: 800 x 600

+//

+#define SVGA_H_RES_PIXELS                 800

+#define SVGA_V_RES_PIXELS                 600

+#define SVGA_OSC_FREQUENCY                38250000  /* 0x0247A610 */

+

+#define SVGA_H_SYNC                       ( 80 - 1)

+#define SVGA_H_FRONT_PORCH                ( 32 - 1)

+#define SVGA_H_BACK_PORCH                 (112 - 1)

+

+#define SVGA_V_SYNC                       (  4 - 1)

+#define SVGA_V_FRONT_PORCH                (  3 - 1)

+#define SVGA_V_BACK_PORCH                 ( 17 - 1)

+

+//

+// XGA Mode: 1024 x 768

+//

+#define XGA_H_RES_PIXELS                  1024

+#define XGA_V_RES_PIXELS                  768

+#define XGA_OSC_FREQUENCY                 63500000  /* 0x03C8EEE0 */

+

+#define XGA_H_SYNC                        (104 - 1)

+#define XGA_H_FRONT_PORCH                 ( 48 - 1)

+#define XGA_H_BACK_PORCH                  (152 - 1)

+

+#define XGA_V_SYNC                        (  4 - 1)

+#define XGA_V_FRONT_PORCH                 (  3 - 1)

+#define XGA_V_BACK_PORCH                  ( 23 - 1)

+

+//

+// SXGA Mode: 1280 x 1024

+//

+#define SXGA_H_RES_PIXELS                 1280

+#define SXGA_V_RES_PIXELS                 1024

+#define SXGA_OSC_FREQUENCY                109000000  /* 0x067F3540 */

+

+#define SXGA_H_SYNC                       (136 - 1)

+#define SXGA_H_FRONT_PORCH                ( 80 - 1)

+#define SXGA_H_BACK_PORCH                 (216 - 1)

+

+#define SXGA_V_SYNC                       (  7 - 1)

+#define SXGA_V_FRONT_PORCH                (  3 - 1)

+#define SXGA_V_BACK_PORCH                 ( 29 - 1)

+

+//

+// WSXGA+ Mode: 1680 x 1050

+//

+#define WSXGA_H_RES_PIXELS                1680

+#define WSXGA_V_RES_PIXELS                1050

+#define WSXGA_OSC_FREQUENCY               147000000  /* 0x08C30AC0 */

+

+#define WSXGA_H_SYNC                      (170 - 1)

+#define WSXGA_H_FRONT_PORCH               (104 - 1)

+#define WSXGA_H_BACK_PORCH                (274 - 1)

+

+#define WSXGA_V_SYNC                      (  5 - 1)

+#define WSXGA_V_FRONT_PORCH               (  4 - 1)

+#define WSXGA_V_BACK_PORCH                ( 41 - 1)

+

+//

+// UXGA Mode: 1600 x 1200

+//

+#define UXGA_H_RES_PIXELS                 1600

+#define UXGA_V_RES_PIXELS                 1200

+#define UXGA_OSC_FREQUENCY                161000000  /* 0x0998AA40 */

+

+#define UXGA_H_SYNC                       (168 - 1)

+#define UXGA_H_FRONT_PORCH                (112 - 1)

+#define UXGA_H_BACK_PORCH                 (280 - 1)

+

+#define UXGA_V_SYNC                       (  4 - 1)

+#define UXGA_V_FRONT_PORCH                (  3 - 1)

+#define UXGA_V_BACK_PORCH                 ( 38 - 1)

+

+//

+// HD Mode: 1920 x 1080

+//

+#define HD_H_RES_PIXELS                   1920

+#define HD_V_RES_PIXELS                   1080

+#define HD_OSC_FREQUENCY                  165000000  /* 0x09D5B340 */

+

+#define HD_H_SYNC                         ( 79 - 1)

+#define HD_H_FRONT_PORCH                  (128 - 1)

+#define HD_H_BACK_PORCH                   (328 - 1)

+

+#define HD_V_SYNC                         (  5 - 1)

+#define HD_V_FRONT_PORCH                  (  3 - 1)

+#define HD_V_BACK_PORCH                   ( 32 - 1)

+

+//

+// Colour Masks

+//

+

+#define LCD_24BPP_RED_MASK              0x00FF0000

+#define LCD_24BPP_GREEN_MASK            0x0000FF00

+#define LCD_24BPP_BLUE_MASK             0x000000FF

+#define LCD_24BPP_RESERVED_MASK         0xFF000000

+

+#define LCD_16BPP_555_RED_MASK          0x00007C00

+#define LCD_16BPP_555_GREEN_MASK        0x000003E0

+#define LCD_16BPP_555_BLUE_MASK         0x0000001F

+#define LCD_16BPP_555_RESERVED_MASK     0x00000000

+

+#define LCD_16BPP_565_RED_MASK          0x0000F800

+#define LCD_16BPP_565_GREEN_MASK        0x000007E0

+#define LCD_16BPP_565_BLUE_MASK         0x0000001F

+#define LCD_16BPP_565_RESERVED_MASK     0x00008000

+

+#define LCD_12BPP_444_RED_MASK          0x00000F00

+#define LCD_12BPP_444_GREEN_MASK        0x000000F0

+#define LCD_12BPP_444_BLUE_MASK         0x0000000F

+#define LCD_12BPP_444_RESERVED_MASK     0x0000F000

+

+

+// The enumeration indexes maps the PL111 LcdBpp values used in the LCD Control Register

+typedef enum {

+  LCD_BITS_PER_PIXEL_1 = 0,

+  LCD_BITS_PER_PIXEL_2,

+  LCD_BITS_PER_PIXEL_4,

+  LCD_BITS_PER_PIXEL_8,

+  LCD_BITS_PER_PIXEL_16_555,

+  LCD_BITS_PER_PIXEL_24,

+  LCD_BITS_PER_PIXEL_16_565,

+  LCD_BITS_PER_PIXEL_12_444

+} LCD_BPP;

+

+

+EFI_STATUS

+LcdPlatformInitializeDisplay (

+  IN EFI_HANDLE   Handle

+  );

+

+EFI_STATUS

+LcdPlatformGetVram (

+  OUT EFI_PHYSICAL_ADDRESS*                 VramBaseAddress,

+  OUT UINTN*                                VramSize

+  );

+

+UINT32

+LcdPlatformGetMaxMode (

+  VOID

+  );

+

+EFI_STATUS

+LcdPlatformSetMode (

+  IN UINT32                                 ModeNumber

+  );

+

+EFI_STATUS

+LcdPlatformQueryMode (

+  IN  UINT32                                ModeNumber,

+  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info

+  );

+

+EFI_STATUS

+LcdPlatformGetTimings (

+  IN  UINT32                              ModeNumber,

+  OUT UINT32*                             HRes,

+  OUT UINT32*                             HSync,

+  OUT UINT32*                             HBackPorch,

+  OUT UINT32*                             HFrontPorch,

+  OUT UINT32*                             VRes,

+  OUT UINT32*                             VSync,

+  OUT UINT32*                             VBackPorch,

+  OUT UINT32*                             VFrontPorch

+  );

+

+EFI_STATUS

+LcdPlatformGetBpp (

+  IN  UINT32                                ModeNumber,

+  OUT LCD_BPP*                              Bpp

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/NorFlashPlatformLib.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/NorFlashPlatformLib.h
new file mode 100644
index 0000000..e9e1c06
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Library/NorFlashPlatformLib.h
@@ -0,0 +1,37 @@
+/** @file

+

+ Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+

+ 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 _NORFLASHPLATFORMLIB_H_

+#define _NORFLASHPLATFORMLIB_H_

+

+typedef struct {

+  UINTN       DeviceBaseAddress;    // Start address of the Device Base Address (DBA)

+  UINTN       RegionBaseAddress;    // Start address of one single region

+  UINTN       Size;

+  UINTN       BlockSize;

+  EFI_GUID    Guid;

+} NOR_FLASH_DESCRIPTION;

+

+EFI_STATUS

+NorFlashPlatformInitialization (

+  VOID

+  );

+

+EFI_STATUS

+NorFlashPlatformGetDevices (

+  OUT NOR_FLASH_DESCRIPTION   **NorFlashDescriptions,

+  OUT UINT32                  *Count

+  );

+

+#endif /* _NORFLASHPLATFORMLIB_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Include/Ppi/ArmGlobalVariable.h b/uefi/linaro-edk2/ArmPlatformPkg/Include/Ppi/ArmGlobalVariable.h
new file mode 100644
index 0000000..8a29b83
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Include/Ppi/ArmGlobalVariable.h
@@ -0,0 +1,55 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#ifndef __ARM_GLOBAL_VARIABLE_H__

+#define __ARM_GLOBAL_VARIABLE_H__

+

+#define ARM_GLOBAL_VARIABLE_PPI_GUID  \

+  { 0xab1c1816, 0xd542, 0x4e6f, {0x9b, 0x1e, 0x8e, 0xcd, 0x92, 0x53, 0xe2, 0xe7} }

+

+

+/**

+  This service of the EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI that migrates temporary RAM into

+  permanent memory.

+

+  @param PeiServices            Pointer to the PEI Services Table.

+  @param TemporaryMemoryBase    Source Address in temporary memory from which the SEC or PEIM will copy the

+                                Temporary RAM contents.

+  @param PermanentMemoryBase    Destination Address in permanent memory into which the SEC or PEIM will copy the

+                                Temporary RAM contents.

+  @param CopySize               Amount of memory to migrate from temporary to permanent memory.

+

+  @retval EFI_SUCCESS           The data was successfully returned.

+  @retval EFI_INVALID_PARAMETER PermanentMemoryBase + CopySize > TemporaryMemoryBase when

+                                TemporaryMemoryBase > PermanentMemoryBase.

+

+**/

+typedef

+EFI_STATUS

+(EFIAPI * ARM_GLOBAL_VARIABLE_GET_MEMORY) (

+  OUT EFI_PHYSICAL_ADDRESS    *GlobalVariableBase

+);

+

+///

+/// This service abstracts the ability to migrate contents of the platform early memory store.

+/// Note: The name EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI is different from the current PI 1.2 spec.

+///       This PPI was optional.

+///

+typedef struct {

+  ARM_GLOBAL_VARIABLE_GET_MEMORY   GetGlobalVariableMemory;

+} ARM_GLOBAL_VARIABLE_PPI;

+

+extern EFI_GUID gArmGlobalVariablePpiGuid;

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c
new file mode 100644
index 0000000..511d0f6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c
@@ -0,0 +1,76 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <PiDxe.h>

+#include <Library/ArmPlatformGlobalVariableLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/PcdLib.h>

+

+#include <Guid/ArmGlobalVariableHob.h>

+

+UINTN  mGlobalVariableBase = 0;

+

+RETURN_STATUS

+EFIAPI

+ArmPlatformGlobalVariableConstructor (

+  VOID

+  )

+{

+  ARM_HOB_GLOBAL_VARIABLE  *Hob;

+

+  Hob = GetFirstGuidHob (&gArmGlobalVariableGuid);

+  ASSERT (Hob != NULL);

+

+  mGlobalVariableBase = Hob->GlobalVariableBase;

+

+  return EFI_SUCCESS;

+}

+

+VOID

+ArmPlatformGetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  if (mGlobalVariableBase == 0) {

+    ArmPlatformGlobalVariableConstructor ();

+  }

+

+  CopyMem (Variable, (VOID*)(mGlobalVariableBase + VariableOffset), VariableSize);

+}

+

+VOID

+ArmPlatformSetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  if (mGlobalVariableBase == 0) {

+    ArmPlatformGlobalVariableConstructor ();

+  }

+

+  CopyMem ((VOID*)(mGlobalVariableBase + VariableOffset), Variable, VariableSize);

+}

+

+VOID*

+ArmPlatformGetGlobalVariableAddress (

+  IN  UINTN     VariableOffset

+  )

+{

+  return (VOID*)(mGlobalVariableBase + VariableOffset);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf
new file mode 100644
index 0000000..e90d6a5
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf
@@ -0,0 +1,44 @@
+#/** @file

+# Timer library implementation

+#

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = DxeArmPlatformGlobalVariableLib

+  FILE_GUID                      = 53fa3cc3-23b7-4ec2-9bfa-30257d7e1135

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib

+

+  CONSTRUCTOR                    = ArmPlatformGlobalVariableConstructor

+

+[Sources.common]

+  DxeArmPlatformGlobalVariableLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  HobLib

+

+[Guids]

+  gArmGlobalVariableGuid

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c
new file mode 100644
index 0000000..2ffbdbe
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c
@@ -0,0 +1,84 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <Uefi.h>

+#include <Library/ArmPlatformGlobalVariableLib.h>

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/PcdLib.h>

+#include <Library/DebugLib.h>

+

+// Declared by ArmPlatformPkg/PrePi Module

+extern UINTN mGlobalVariableBase;

+

+VOID

+ArmPlatformGetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));

+

+  GlobalVariableBase = PcdGet64 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);

+

+  if (VariableSize == 4) {

+    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));

+  } else if (VariableSize == 8) {

+    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));

+  } else {

+    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);

+  }

+}

+

+VOID

+ArmPlatformSetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));

+

+  GlobalVariableBase = PcdGet64 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);

+

+  if (VariableSize == 4) {

+    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);

+  } else if (VariableSize == 8) {

+    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);

+  } else {

+    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);

+  }

+}

+

+VOID*

+ArmPlatformGetGlobalVariableAddress (

+  IN  UINTN     VariableOffset

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));

+

+  GlobalVariableBase = PcdGet64 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);

+

+  return (VOID*)(GlobalVariableBase + VariableOffset);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf
new file mode 100644
index 0000000..09995e1
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.inf
@@ -0,0 +1,40 @@
+#/** @file

+# ArmPlatformGlobalVariableLib library implementation

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PeiArmPlatformGlobalVariableLib

+  FILE_GUID                      = 3e03daf2-b7b4-45f7-80b2-12aba043391f

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib

+

+[Sources.common]

+  PeiArmPlatformGlobalVariableLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  PcdLib

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c
new file mode 100644
index 0000000..41af183
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c
@@ -0,0 +1,105 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <Uefi.h>

+#include <Library/ArmPlatformGlobalVariableLib.h>

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/PcdLib.h>

+#include <Library/DebugLib.h>

+

+#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) || \

+                  ((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))

+

+// Declared by ArmPlatformPkg/PrePi Module

+extern UINTN mGlobalVariableBase;

+

+VOID

+ArmPlatformGetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));

+

+  if (IS_XIP()) {

+    // In Case of XIP, we expect the Primary Stack at the top of the System Memory

+    // The size must be 64bit aligned to allow 64bit variable to be aligned

+    GlobalVariableBase = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);

+  } else {

+    GlobalVariableBase = mGlobalVariableBase;

+  }

+

+  if (VariableSize == 4) {

+    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));

+  } else if (VariableSize == 8) {

+    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));

+  } else {

+    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);

+  }

+}

+

+VOID

+ArmPlatformSetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));

+

+  if (IS_XIP()) {

+    // In Case of XIP, we expect the Primary Stack at the top of the System Memory

+    // The size must be 64bit aligned to allow 64bit variable to be aligned

+    GlobalVariableBase = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);

+  } else {

+    GlobalVariableBase = mGlobalVariableBase;

+  }

+

+  if (VariableSize == 4) {

+    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);

+  } else if (VariableSize == 8) {

+    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);

+  } else {

+    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);

+  }

+}

+

+VOID*

+ArmPlatformGetGlobalVariableAddress (

+  IN  UINTN     VariableOffset

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));

+

+  if (IS_XIP()) {

+    // In Case of XIP, we expect the Primary Stack at the top of the System Memory

+    // The size must be 64bit aligned to allow 64bit variable to be aligned

+    GlobalVariableBase = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);

+  } else {

+    GlobalVariableBase = mGlobalVariableBase;

+  }

+

+  return (VOID*)(GlobalVariableBase + VariableOffset);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf
new file mode 100644
index 0000000..596f559
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.inf
@@ -0,0 +1,46 @@
+#/** @file

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PrePiArmPlatformGlobalVariableLib

+  FILE_GUID                      = 44d59470-e5e6-4811-af00-33bb573a804b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib

+

+[Sources.common]

+  PrePiArmPlatformGlobalVariableLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  ArmPkg/ArmPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  PcdLib

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

+

+[Pcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c
new file mode 100644
index 0000000..aa8d892
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c
@@ -0,0 +1,81 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <Uefi.h>

+#include <Library/ArmPlatformGlobalVariableLib.h>

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/PcdLib.h>

+#include <Library/DebugLib.h>

+

+VOID

+ArmPlatformGetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));

+

+  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);

+

+  if (VariableSize == 4) {

+    *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));

+  } else if (VariableSize == 8) {

+    *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));

+  } else {

+    CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);

+  }

+}

+

+VOID

+ArmPlatformSetGlobalVariable (

+  IN  UINTN     VariableOffset,

+  IN  UINTN     VariableSize,

+  OUT VOID*     Variable

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));

+

+  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);

+

+  if (VariableSize == 4) {

+    WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);

+  } else if (VariableSize == 8) {

+    WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);

+  } else {

+    CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);

+  }

+}

+

+VOID*

+ArmPlatformGetGlobalVariableAddress (

+  IN  UINTN     VariableOffset

+  )

+{

+  UINTN  GlobalVariableBase;

+

+  // Ensure the Global Variable Size have been initialized

+  ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));

+

+  GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);

+

+  return (VOID*)(GlobalVariableBase + VariableOffset);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf
new file mode 100644
index 0000000..d64cbaf
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.inf
@@ -0,0 +1,39 @@
+#/** @file

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = SecArmPlatformGlobalVariableLib

+  FILE_GUID                      = e01f4944-df86-488b-b89b-79e7a53a3a5d

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformGlobalVariableLib

+

+[Sources.common]

+  SecArmPlatformGlobalVariableLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  PcdLib

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdSecGlobalVariableSize

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/AArch64/ArmPlatformHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/AArch64/ArmPlatformHelper.S
new file mode 100644
index 0000000..8c099b4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/AArch64/ArmPlatformHelper.S
@@ -0,0 +1,65 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLibV8.h>

+#include <Library/ArmLib.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  ret

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+// With this function: CorePos = (ClusterId * 4) + CoreId

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   x1, x0, #ARM_CORE_MASK

+  and   x0, x0, #ARM_CLUSTER_MASK

+  add   x0, x1, x0, LSR #6

+  ret

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x0)

+  ldrh  w0, [x0]

+  ret

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, x1)

+  ldrh  w1, [x1]

+  and   x0, x0, x1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, x1)

+  ldrh  w1, [x1]

+  cmp   w0, w1

+  mov   x0, #1

+  mov   x1, #0

+  csel  x0, x0, x1, eq

+  ret

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/Arm/ArmPlatformHelper.S b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/Arm/ArmPlatformHelper.S
new file mode 100644
index 0000000..e52ea5a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/Arm/ArmPlatformHelper.S
@@ -0,0 +1,63 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+.text

+.align 2

+

+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)

+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)

+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)

+

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)

+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)

+

+ASM_PFX(ArmPlatformPeiBootAction):

+  bx    lr

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformGetCorePosition):

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr   r0, [r0]

+  bx    lr

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ASM_PFX(ArmPlatformIsPrimaryCore):

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/Arm/ArmPlatformHelper.asm b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/Arm/ArmPlatformHelper.asm
new file mode 100644
index 0000000..95704c1
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/Arm/ArmPlatformHelper.asm
@@ -0,0 +1,72 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Library/ArmLib.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformPeiBootAction

+  EXPORT  ArmPlatformGetCorePosition

+  EXPORT  ArmPlatformGetPrimaryCoreMpId

+  EXPORT  ArmPlatformIsPrimaryCore

+

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCore

+  IMPORT  _gPcd_FixedAtBuild_PcdArmPrimaryCoreMask

+

+  PRESERVE8

+  AREA    ArmPlatformNullHelper, CODE, READONLY

+

+ArmPlatformPeiBootAction FUNCTION

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetCorePosition (

+//  IN UINTN MpId

+//  );

+ArmPlatformGetCorePosition FUNCTION

+  and   r1, r0, #ARM_CORE_MASK

+  and   r0, r0, #ARM_CLUSTER_MASK

+  add   r0, r1, r0, LSR #7

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformGetPrimaryCoreMpId (

+//  VOID

+//  );

+ArmPlatformGetPrimaryCoreMpId FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)

+  ldr   r0, [r0]

+  bx    lr

+  ENDFUNC

+

+//UINTN

+//ArmPlatformIsPrimaryCore (

+//  IN UINTN MpId

+//  );

+ArmPlatformIsPrimaryCore FUNCTION

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)

+  ldr   r1, [r1]

+  and   r0, r0, r1

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r1)

+  ldr   r1, [r1]

+  cmp   r0, r1

+  moveq r0, #1

+  movne r0, #0

+  bx    lr

+  ENDFUNC

+

+  END

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.c
new file mode 100644
index 0000000..0cc1e4a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.c
@@ -0,0 +1,164 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <Library/ArmLib.h>

+#include <Library/ArmPlatformLib.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+

+ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {

+  {

+    // Cluster 0, Core 0

+    0x0, 0x0,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 1

+    0x0, 0x1,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 2

+    0x0, 0x2,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (UINT64)0xFFFFFFFF

+  },

+  {

+    // Cluster 0, Core 3

+    0x0, 0x3,

+

+    // MP Core MailBox Set/Get/Clear Addresses and Clear Value

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (EFI_PHYSICAL_ADDRESS)0,

+    (UINT64)0xFFFFFFFF

+  }

+};

+

+// This function should be better located into TimerLib implementation

+RETURN_STATUS

+EFIAPI

+TimerConstructor (

+  VOID

+  )

+{

+  return EFI_SUCCESS;

+}

+

+/**

+  Return the current Boot Mode

+

+  This function returns the boot reason on the platform

+

+**/

+EFI_BOOT_MODE

+ArmPlatformGetBootMode (

+  VOID

+  )

+{

+  return BOOT_WITH_FULL_CONFIGURATION;

+}

+

+/**

+  Initialize controllers that must setup in the normal world

+

+  This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei

+  in the PEI phase.

+

+**/

+RETURN_STATUS

+ArmPlatformInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  //TODO: Implement me

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Initialize the system (or sometimes called permanent) memory

+

+  This memory is generally represented by the DRAM.

+

+**/

+VOID

+ArmPlatformInitializeSystemMemory (

+  VOID

+  )

+{

+  //TODO: Implement me

+}

+

+EFI_STATUS

+PrePeiCoreGetMpCoreInfo (

+  OUT UINTN                   *CoreCount,

+  OUT ARM_CORE_INFO           **ArmCoreTable

+  )

+{

+  if (ArmIsMpCore()) {

+    *CoreCount    = sizeof(mArmPlatformNullMpCoreInfoTable) / sizeof(ARM_CORE_INFO);

+    *ArmCoreTable = mArmPlatformNullMpCoreInfoTable;

+    return EFI_SUCCESS;

+  } else {

+    return EFI_UNSUPPORTED;

+  }

+}

+

+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore

+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;

+ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };

+

+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &mArmMpCoreInfoPpiGuid,

+    &mMpCoreInfoPpi

+  }

+};

+

+VOID

+ArmPlatformGetPlatformPpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  if (ArmIsMpCore()) {

+    *PpiListSize = sizeof(gPlatformPpiTable);

+    *PpiList = gPlatformPpiTable;

+  } else {

+    *PpiListSize = 0;

+    *PpiList = NULL;

+  }

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf
new file mode 100644
index 0000000..4517ad5
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf
@@ -0,0 +1,48 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformLibNull

+  FILE_GUID                      = cb494bad-23ff-427e-8608-d7e138d3363b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  DebugLib

+

+[Sources.common]

+  ArmPlatformLibNull.c

+  ArmPlatformLibNullMem.c

+

+[Sources.Arm]

+  Arm/ArmPlatformHelper.S    | GCC

+  Arm/ArmPlatformHelper.asm  | RVCT

+

+[Sources.AArch64]

+  AArch64/ArmPlatformHelper.S

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c
new file mode 100644
index 0000000..45a64c6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c
@@ -0,0 +1,34 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+

+/**

+  Return the Virtual Memory Map of your platform

+

+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.

+

+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-

+                                    Virtual Memory mapping. This array must be ended by a zero-filled

+                                    entry

+

+**/

+VOID

+ArmPlatformGetVirtualMemoryMap (

+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap

+  )

+{

+  ASSERT(0);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullSec.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullSec.inf
new file mode 100644
index 0000000..3cd5fd8
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullSec.inf
@@ -0,0 +1,47 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformLibNull

+  FILE_GUID                      = cb494bad-23ff-427e-8608-d7e138d3363b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  DebugLib

+

+[Sources.common]

+  ArmPlatformLibNull.c

+

+[Sources.Arm]

+  Arm/ArmPlatformHelper.S    | GCC

+  Arm/ArmPlatformHelper.asm  | RVCT

+

+[Sources.AArch64]

+  AArch64/ArmPlatformHelper.S

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask

+  gArmTokenSpaceGuid.PcdArmPrimaryCore

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/AArch64/ArmPlatformLibNullBoot.S b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/AArch64/ArmPlatformLibNullBoot.S
new file mode 100644
index 0000000..0bfb947
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/AArch64/ArmPlatformLibNullBoot.S
@@ -0,0 +1,61 @@
+//

+//  Copyright (c) 2011 - 2013, ARM 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.

+//

+//

+

+#include <Base.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformSecBootAction)

+GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit)

+GCC_ASM_EXPORT(ArmSecMpCoreSecondariesWrite)

+GCC_ASM_EXPORT(ArmSecMpCoreSecondariesRead)

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ASM_PFX(ArmPlatformSecBootAction):

+  ret

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ASM_PFX(ArmPlatformSecBootMemoryInit):

+  // The SMC does not need to be initialized for RTSM

+  ret

+

+/* Write the flag register used to start Secondary cores */

+ASM_PFX(ArmSecMpCoreSecondariesWrite):

+  // Write to the CPU Mailbox

+  ret

+

+

+/* Read the flag register used to start Secondary cores */

+ASM_PFX(ArmSecMpCoreSecondariesRead):

+  // Return the value from the CPU Mailbox

+  mov x0, #0

+  ret

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/Arm/ArmPlatformLibNullBoot.S b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/Arm/ArmPlatformLibNullBoot.S
new file mode 100644
index 0000000..a00fac4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/Arm/ArmPlatformLibNullBoot.S
@@ -0,0 +1,47 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <Base.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformSecBootAction)

+GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit)

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ASM_PFX(ArmPlatformSecBootAction):

+  bx   lr

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ASM_PFX(ArmPlatformSecBootMemoryInit):

+  // The SMC does not need to be initialized for RTSM

+  bx    lr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/Arm/ArmPlatformLibNullBoot.asm b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/Arm/ArmPlatformLibNullBoot.asm
new file mode 100644
index 0000000..ead0868
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/Arm/ArmPlatformLibNullBoot.asm
@@ -0,0 +1,49 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+#include <Base.h>

+#include <AutoGen.h>

+

+  EXPORT  ArmPlatformSecBootAction

+  EXPORT  ArmPlatformSecBootMemoryInit

+

+  PRESERVE8

+  AREA    ArmPlatformSecLibBoot, CODE, READONLY

+

+/**

+  Call at the beginning of the platform boot up

+

+  This function allows the firmware platform to do extra actions at the early

+  stage of the platform power up.

+

+  Note: This function must be implemented in assembler as there is no stack set up yet

+

+**/

+ArmPlatformSecBootAction

+  bx    lr

+

+/**

+  Initialize the memory where the initial stacks will reside

+

+  This memory can contain the initial stacks (Secure and Secure Monitor stacks).

+  In some platform, this region is already initialized and the implementation of this function can

+  do nothing. This memory can also represent the Secure RAM.

+  This function is called before the satck has been set up. Its implementation must ensure the stack

+  pointer is not used (probably required to use assembly language)

+

+**/

+ArmPlatformSecBootMemoryInit

+  // The SMC does not need to be initialized for RTSM

+  bx    lr

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.c
new file mode 100644
index 0000000..0e5529f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.c
@@ -0,0 +1,74 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+/**

+  Initialize the Secure peripherals and memory regions

+

+  If Trustzone is supported by your platform then this function makes the required initialization

+  of the secure peripherals and memory regions.

+

+**/

+VOID

+ArmPlatformSecTrustzoneInit (

+  IN  UINTN                     MpId

+  )

+{

+  // Secondary cores might have to set the Secure SGIs into the GICD_IGROUPR0

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return;

+  }

+

+  ASSERT(FALSE);

+}

+

+/**

+  Initialize controllers that must setup at the early stage

+

+  Some peripherals must be initialized in Secure World.

+  For example, some L2x0 requires to be initialized in Secure World

+

+**/

+RETURN_STATUS

+ArmPlatformSecInitialize (

+  IN  UINTN                     MpId

+  )

+{

+  // If it is not the primary core then there is nothing to do

+  if (!ArmPlatformIsPrimaryCore (MpId)) {

+    return RETURN_SUCCESS;

+  }

+

+  // Do nothing yet

+  return RETURN_SUCCESS;

+}

+

+/**

+  Call before jumping to Normal World

+

+  This function allows the firmware platform to do extra actions before

+  jumping to the Normal World

+

+**/

+VOID

+ArmPlatformSecExtraAction (

+  IN  UINTN         MpId,

+  OUT UINTN*        JumpAddress

+  )

+{

+  *JumpAddress = PcdGet64 (PcdFvBaseAddress);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.inf
new file mode 100644
index 0000000..0e3f54a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSecLibNull/ArmPlatformLibNullSec.inf
@@ -0,0 +1,44 @@
+#/* @file

+#  Copyright (c) 2011-2014, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformLibSecNull

+  FILE_GUID                      = a2cf63c6-d44f-4cd0-8af6-722a0138c021

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSecLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  DebugLib

+

+[Sources.common]

+  ArmPlatformLibNullSec.c

+

+[Sources.ARM]

+  Arm/ArmPlatformLibNullBoot.asm     | RVCT

+  Arm/ArmPlatformLibNullBoot.S       | GCC

+

+[Sources.AARCH64]

+  AArch64/ArmPlatformLibNullBoot.S

+

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S
new file mode 100644
index 0000000..485017f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S
@@ -0,0 +1,129 @@
+//

+//  Copyright (c) 2012-2014, ARM 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.

+//

+//

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformStackSet)

+GCC_ASM_EXPORT(ArmPlatformStackSetPrimary)

+GCC_ASM_EXPORT(ArmPlatformStackSetSecondary)

+

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmPlatformGetCorePosition)

+GCC_ASM_IMPORT(ArmPlatformGetPrimaryCoreMpId)

+

+GCC_ASM_IMPORT(gPcd_FixedAtBuild_PcdCoreCount)

+

+//VOID

+//ArmPlatformStackSet (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ASM_PFX(ArmPlatformStackSet):

+  // Save parameters

+  mov   x6, x3

+  mov   x5, x2

+  mov   x4, x1

+  mov   x3, x0

+

+  // Save the Link register

+  mov   x7, x30

+

+  // Identify Stack

+  mov   x0, x1

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+  cmp   x0, #1

+

+  // Restore parameters

+  mov   x0, x3

+  mov   x1, x4

+  mov   x2, x5

+  mov   x3, x6

+

+  // Restore the Link register

+  mov   x30, x7

+

+  // Should be ASM_PFX(ArmPlatformStackSetPrimary) but generate linker error 'unsupported ELF EM_AARCH64'

+  b.eq  ArmPlatformStackSetPrimaryL

+  // Should be ASM_PFX(ArmPlatformStackSetSecondary) but generate linker error 'unsupported ELF EM_AARCH64'

+  b.ne  ArmPlatformStackSetSecondaryL

+

+//VOID

+//ArmPlatformStackSetPrimary (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ArmPlatformStackSetPrimaryL:

+ASM_PFX(ArmPlatformStackSetPrimary):

+  // Save the Link register

+  mov   x4, x30

+

+  // Add stack of primary stack to StackBase

+  add   x0, x0, x2

+

+  // Compute SecondaryCoresCount * SecondaryCoreStackSize

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdCoreCount, x1)

+  ldr   w1, [x1]

+  sub   x1, x1, #1

+  mul   x3, x3, x1

+

+  // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))

+  add   sp, x0, x3

+

+  br    x4

+

+//VOID

+//ArmPlatformStackSetSecondary (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ArmPlatformStackSetSecondaryL:

+ASM_PFX(ArmPlatformStackSetSecondary):

+  // Save the Link register

+  mov   x4, x30

+  mov   sp, x0

+

+  // Get Core Position

+  mov   x0, x1

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+  mov   x5, x0

+

+  // Get Primary Core Position

+  bl    ASM_PFX(ArmPlatformGetPrimaryCoreMpId)

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+

+  // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)

+  cmp   x5, x0

+  b.ls  1f

+  // Decrement the position if after the primary core

+  sub   x5, x5, #1

+1:

+  add   x5, x5, #1

+

+  // Compute top of the secondary stack

+  mul   x3, x3, x5

+

+  // Set stack

+  add   sp, sp, x3

+

+  br    x4

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.S b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.S
new file mode 100644
index 0000000..96e9259
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.S
@@ -0,0 +1,121 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(ArmPlatformStackSet)

+GCC_ASM_EXPORT(ArmPlatformStackSetPrimary)

+GCC_ASM_EXPORT(ArmPlatformStackSetSecondary)

+

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmPlatformGetCorePosition)

+GCC_ASM_IMPORT(ArmPlatformGetPrimaryCoreMpId)

+

+GCC_ASM_IMPORT(gPcd_FixedAtBuild_PcdCoreCount)

+

+//VOID

+//ArmPlatformStackSet (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ASM_PFX(ArmPlatformStackSet):

+  // Save parameters

+  mov   r6, r3

+  mov   r5, r2

+  mov   r4, r1

+  mov   r3, r0

+

+  // Save the Link register

+  mov   r7, lr

+

+  // Identify Stack

+  mov   r0, r1

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+  cmp   r0, #1

+

+  // Restore parameters

+  mov   r0, r3

+  mov   r1, r4

+  mov   r2, r5

+  mov   r3, r6

+

+  // Restore the Link register

+  mov   lr, r7

+

+  beq   ASM_PFX(ArmPlatformStackSetPrimary)

+  bne   ASM_PFX(ArmPlatformStackSetSecondary)

+

+//VOID

+//ArmPlatformStackSetPrimary (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ASM_PFX(ArmPlatformStackSetPrimary):

+  mov   r4, lr

+

+  // Add stack of primary stack to StackBase

+  add   r0, r0, r2

+

+  // Compute SecondaryCoresCount * SecondaryCoreStackSize

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdCoreCount, r1)

+  ldr   r1, [r1]

+  sub   r1, #1

+  mul   r3, r3, r1

+

+  // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))

+  add   sp, r0, r3

+

+  bx    r4

+

+//VOID

+//ArmPlatformStackSetSecondary (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ASM_PFX(ArmPlatformStackSetSecondary):

+  mov   r4, lr

+  mov   sp, r0

+

+  // Get Core Position

+  mov   r0, r1

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+  mov   r5, r0

+

+  // Get Primary Core Position

+  bl    ASM_PFX(ArmPlatformGetPrimaryCoreMpId)

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+

+  // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)

+  cmp   r5, r0

+  subhi r5, r5, #1

+  add   r5, r5, #1

+

+  // Compute top of the secondary stack

+  mul   r3, r3, r5

+

+  // Set stack

+  add   sp, sp, r3

+

+  bx r4

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.asm b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.asm
new file mode 100644
index 0000000..99218cd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.asm
@@ -0,0 +1,127 @@
+//

+//  Copyright (c) 2012-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  EXPORT  ArmPlatformStackSet

+  EXPORT  ArmPlatformStackSetPrimary

+  EXPORT  ArmPlatformStackSetSecondary

+

+  IMPORT  ArmPlatformIsPrimaryCore

+  IMPORT  ArmPlatformGetCorePosition

+  IMPORT  ArmPlatformGetPrimaryCoreMpId

+

+  IMPORT  _gPcd_FixedAtBuild_PcdCoreCount

+

+  PRESERVE8

+  AREA    ArmPlatformStackLib, CODE, READONLY

+

+//VOID

+//ArmPlatformStackSet (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ArmPlatformStackSet FUNCTION

+  // Save parameters

+  mov   r6, r3

+  mov   r5, r2

+  mov   r4, r1

+  mov   r3, r0

+

+  // Save the Link register

+  mov   r7, lr

+

+  // Identify Stack

+  mov   r0, r1

+  bl    ArmPlatformIsPrimaryCore

+  cmp   r0, #1

+

+  // Restore parameters

+  mov   r0, r3

+  mov   r1, r4

+  mov   r2, r5

+  mov   r3, r6

+

+  // Restore the Link register

+  mov   lr, r7

+

+  beq   ArmPlatformStackSetPrimary

+  bne   ArmPlatformStackSetSecondary

+  ENDFUNC

+

+//VOID

+//ArmPlatformStackSetPrimary (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ArmPlatformStackSetPrimary FUNCTION

+  mov   r4, lr

+

+  // Add stack of primary stack to StackBase

+  add   r0, r0, r2

+

+  // Compute SecondaryCoresCount * SecondaryCoreStackSize

+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdCoreCount, r1)

+  ldr   r1, [r1]

+  sub   r1, #1

+  mul   r3, r3, r1

+

+  // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))

+  add   sp, r0, r3

+

+  bx    r4

+  ENDFUNC

+

+//VOID

+//ArmPlatformStackSetSecondary (

+//  IN UINTN StackBase,

+//  IN UINTN MpId,

+//  IN UINTN PrimaryStackSize,

+//  IN UINTN SecondaryStackSize

+//  );

+ArmPlatformStackSetSecondary FUNCTION

+  mov   r4, lr

+  mov   sp, r0

+

+  // Get Core Position

+  mov   r0, r1

+  bl ArmPlatformGetCorePosition

+  mov   r5, r0

+

+  // Get Primary Core Position

+  bl ArmPlatformGetPrimaryCoreMpId

+  bl ArmPlatformGetCorePosition

+

+  // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)

+  cmp   r5, r0

+  subhi r5, r5, #1

+  add   r5, r5, #1

+

+  // Compute top of the secondary stack

+  mul   r3, r3, r5

+

+  // Set stack

+  add   sp, sp, r3

+

+  bx r4

+  ENDFUNC

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf
new file mode 100644
index 0000000..16a2917
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf
@@ -0,0 +1,40 @@
+#/* @file

+#

+#  Copyright (c) 2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformStackLib

+  FILE_GUID                      = 5e2e44af-53c1-44c2-a801-9c149f3d6ba0

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformStackLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[Sources.ARM]

+  Arm/ArmPlatformStackLib.asm     | RVCT

+  Arm/ArmPlatformStackLib.S       | GCC

+

+[Sources.AARCH64]

+  AArch64/ArmPlatformStackLib.S

+

+[LibraryClasses]

+  ArmPlatformLib

+

+[FixedPcd]

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.c
new file mode 100644
index 0000000..a7199e6
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.c
@@ -0,0 +1,85 @@
+/** @file

+

+  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+

+  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 <Base.h>

+

+#include <Library/ArmPlatformSysConfigLib.h>

+

+

+RETURN_STATUS

+ArmPlatformSysConfigInitialize (

+  VOID

+  )

+{

+  return RETURN_SUCCESS;

+}

+

+/***************************************

+ * GENERAL FUNCTION: AccessSysCfgRegister

+ * Interacts with

+ *    SYS_CFGSTAT

+ *    SYS_CFGDATA

+ *    SYS_CFGCTRL

+ * for setting and for reading out values

+ ***************************************/

+RETURN_STATUS

+AccessSysCfgRegister (

+  IN     UINT32   ReadWrite,

+  IN     UINT32   Function,

+  IN     UINT32   Site,

+  IN     UINT32   Position,

+  IN     UINT32   Device,

+  IN OUT UINT32*  Data

+  )

+{

+  return RETURN_UNSUPPORTED;

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigGet (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  OUT UINT32*               Value

+  )

+{

+  return RETURN_UNSUPPORTED;

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigGetValues (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINTN                 Size,

+  OUT UINT32*               Values

+  )

+{

+  return RETURN_UNSUPPORTED;

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigSet (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINT32                Value

+  )

+{

+  return RETURN_UNSUPPORTED;

+}

+

+RETURN_STATUS

+ArmPlatformSysConfigSetDevice (

+  IN  SYS_CONFIG_FUNCTION   Function,

+  IN  UINT32                Device,

+  IN  UINT32                Value

+  )

+{

+  return RETURN_UNSUPPORTED;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf
new file mode 100644
index 0000000..f379d72
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmPlatformSysConfigLibNull/ArmPlatformSysConfigLibNull.inf
@@ -0,0 +1,28 @@
+#/** @file

+#

+#  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmPlatformSysConfigLibNull

+  FILE_GUID                      = b2a191a9-9bac-4c83-a2f3-d5f6e71efd03

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSysConfigLib

+

+[Sources.common]

+  ArmPlatformSysConfigLibNull.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.c
new file mode 100644
index 0000000..67bbb9e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.c
@@ -0,0 +1,95 @@
+/** @file

+*

+*  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+*

+*  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 <Uefi.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiLib.h>

+#include <Library/ArmShellCmdLib.h>

+

+#include "ArmShellCmdRunAxf.h"

+

+EFI_HANDLE gRunAxfHiiHandle = NULL;

+

+#define RUNAXF_HII_GUID \

+  { \

+  0xf5a6413b, 0x78d5, 0x448e, { 0xa2, 0x15, 0x22, 0x82, 0x8e, 0xbc, 0x61, 0x61 } \

+  }

+

+EFI_GUID gRunAxfHiiGuid = RUNAXF_HII_GUID;

+

+static EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mShellDynCmdProtocolRunAxf = {

+    L"runaxf",                             // *CommandName

+    ShellDynCmdRunAxfHandler,              // Handler

+    ShellDynCmdRunAxfGetHelp               // GetHelp

+};

+

+EFI_STATUS

+ShellDynCmdRunAxfInstall (

+  IN EFI_HANDLE             ImageHandle

+  )

+{

+  EFI_STATUS Status;

+

+  // Register our shell command

+  Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle,

+                 &gEfiShellDynamicCommandProtocolGuid,

+                 &mShellDynCmdProtocolRunAxf,

+                 NULL);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Load the manual page for our command

+  //

+  // 3rd parameter 'HII strings array' must be name of .uni strings file

+  // followed by 'Strings', e.g. mycommands.uni must be specified as

+  // 'mycommandsStrings' because the build Autogen process defines this as a

+  // string array for the strings in your .uni file.  Examine your Build folder

+  // under your package's DEBUG folder and you will find it defined in a

+  // xxxStrDefs.h file.

+  //

+  gRunAxfHiiHandle = HiiAddPackages (&gRunAxfHiiGuid, ImageHandle,

+                                     ArmShellCmdRunAxfStrings, NULL);

+  if (gRunAxfHiiHandle == NULL) {

+    return EFI_UNSUPPORTED;

+  }

+

+  return EFI_SUCCESS;

+}

+

+

+EFI_STATUS

+ShellDynCmdRunAxfUninstall (

+  IN EFI_HANDLE             ImageHandle

+  )

+{

+

+  EFI_STATUS Status;

+

+  if (gRunAxfHiiHandle != NULL) {

+    HiiRemovePackages (gRunAxfHiiHandle);

+  }

+

+  Status = gBS->UninstallMultipleProtocolInterfaces (ImageHandle,

+                 &gEfiShellDynamicCommandProtocolGuid,

+                 &mShellDynCmdProtocolRunAxf,

+                 NULL);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.h b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.h
new file mode 100644
index 0000000..8599961
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.h
@@ -0,0 +1,85 @@
+/** @file

+*

+*  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+*

+*  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 __ARM_SHELL_CMD_RUNAXF__

+#define __ARM_SHELL_CMD_RUNAXF__

+

+#include <ShellBase.h>

+

+#include <Protocol/EfiShell.h>

+#include <Protocol/EfiShellDynamicCommand.h>

+

+#include <Library/HiiLib.h>

+#include <Library/ShellLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+

+extern EFI_GUID      gRunAxfHiiGuid;

+extern EFI_HANDLE    gRunAxfHiiHandle;

+extern EFI_HANDLE    gRunAxfImageHandle;

+

+// List of data segments to load to memory from AXF/ELF file.

+typedef struct {

+  LIST_ENTRY  Link;       // This attribute must be the first entry of this

+                          // structure (to avoid pointer computation)

+  UINTN       MemOffset;  // Where the data should go, Dest

+  UINTN       FileOffset; // Where the data is from, Src

+  BOOLEAN     Zeroes;     // A section of Zeroes. Like .bss in ELF

+  UINTN       Length;     // Number of bytes.

+} RUNAXF_LOAD_LIST;

+

+

+/**

+  This is the shell command handler function pointer callback type. This

+  function handles the command when it is invoked in the shell.

+

+  @param[in] This             The instance of the

+                              EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.

+  @param[in] SystemTable      The pointer to the system table.

+  @param[in] ShellParameters  The parameters associated with the command.

+  @param[in] Shell            The instance of the shell protocol used in the

+                              context of processing this command.

+

+  @return EFI_SUCCESS         The operation was successful.

+  @return other               The operation failed.

+**/

+SHELL_STATUS

+EFIAPI

+ShellDynCmdRunAxfHandler (

+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL    *This,

+  IN EFI_SYSTEM_TABLE                      *SystemTable,

+  IN EFI_SHELL_PARAMETERS_PROTOCOL         *ShellParameters,

+  IN EFI_SHELL_PROTOCOL                    *Shell

+  );

+

+

+/**

+  This is the command help handler function pointer callback type. This

+  function is responsible for displaying help information for the associated

+  command.

+

+  @param[in] This             The instance of the

+                              EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.

+  @param[in] Language         The pointer to the language string to use.

+

+  @return string              Pool allocated help string, must be freed by

+                              caller.

+**/

+CHAR16*

+EFIAPI

+ShellDynCmdRunAxfGetHelp (

+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL    *This,

+  IN CONST CHAR8                           *Language

+  );

+

+#endif //__ARM_SHELL_CMD_RUNAXF__

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.inf
new file mode 100644
index 0000000..7d15f69
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.inf
@@ -0,0 +1,54 @@
+## @file

+#

+#  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010006

+  BASE_NAME                      = ArmShellCmdRunAxf

+  FILE_GUID                      = 1f78349d-7fba-4686-8098-fa017eda35fb

+  MODULE_TYPE                    = UEFI_APPLICATION

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmShellCmdRunAxfLib

+

+[Sources.common]

+  ArmShellCmdRunAxf.c

+  ArmShellCmdRunAxf.uni

+  RunAxf.c

+  BootMonFsLoader.h

+  BootMonFsLoader.c

+  ElfLoader.h

+  ElfLoader.c

+  # ELF definitions taken from BaseTools

+  elf32.h

+  elf64.h

+  elf_common.h

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  MdePkg/MdePkg.dec

+  ShellPkg/ShellPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  BaseLib

+  DebugLib

+  HiiLib

+  ShellLib

+

+[Protocols]

+  gEfiShellDynamicCommandProtocolGuid

+

+[Guids]

+  gArmBootMonFsFileInfoGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.uni b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.uni
new file mode 100644
index 0000000..33cc734
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ArmShellCmdRunAxf.uni
Binary files differ
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/BootMonFsLoader.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/BootMonFsLoader.c
new file mode 100644
index 0000000..0bce037
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/BootMonFsLoader.c
@@ -0,0 +1,154 @@
+/** @file

+*

+*  Copyright (c) 2014, ARM Ltd. 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 <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiLib.h>

+

+#include <Guid/BootMonFsFileInfo.h>

+#include <Protocol/SimpleFileSystem.h> // EFI_FILE_HANDLE

+

+#include "ArmShellCmdRunAxf.h"

+#include "BootMonFsLoader.h"

+

+/**

+  Check that loading the file is supported.

+

+  Not all information is checked, only the properties that matters to us in

+  our simplified loader.

+

+  BootMonFS file properties is not in a file header but in the file-system

+  metadata, so we need to pass a handle to the file to allow access to the

+  information.

+

+  @param[in] FileHandle  Handle of the file to check.

+

+  @retval EFI_SUCCESS on success.

+  @retval EFI_INVALID_PARAMETER if the header is invalid.

+  @retval EFI_UNSUPPORTED if the file type/platform is not supported.

+**/

+EFI_STATUS

+BootMonFsCheckFile (

+  IN  CONST EFI_FILE_HANDLE  FileHandle

+  )

+{

+  EFI_STATUS           Status;

+  BOOTMON_FS_FILE_INFO Info;

+  UINTN                InfoSize;

+  UINTN                Index;

+

+  ASSERT (FileHandle != NULL);

+

+  // Try to load the file information as BootMonFS executable.

+  InfoSize = sizeof (Info);

+  // Get BootMon File info and see if it gives us what we need to load the file.

+  Status = FileHandle->GetInfo (FileHandle, &gArmBootMonFsFileInfoGuid,

+                               &InfoSize, &Info);

+

+  if (!EFI_ERROR (Status)) {

+    // Check the values return to see if they look reasonable.

+    // Do we have a good entrypoint and at least one good load region?

+    // We assume here that we cannot load to address 0x0.

+    if ((Info.Size == 0) || (Info.EntryPoint == 0) || (Info.RegionCount == 0) ||

+        (Info.RegionCount > BOOTMONFS_IMAGE_DESCRIPTION_REGION_MAX)) {

+      // The file does not seem to be of the right type.

+      Status = EFI_UNSUPPORTED;

+    } else {

+      // Check load regions. We just check for valid numbers, we dont do the

+      // checksums. Info.Offset can be zero if it loads from the start of the

+      // file.

+      for (Index = 0; Index < Info.RegionCount; Index++) {

+        if ((Info.Region[Index].LoadAddress == 0) || (Info.Region[Index].Size == 0)) {

+          Status = EFI_UNSUPPORTED;

+          break;

+        }

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Load a binary file from BootMonFS.

+

+  @param[in]  FileHandle    Handle of the file to load.

+

+  @param[in]  FileData      Address  of the file data in memory.

+

+  @param[out] EntryPoint    Will be filled with the ELF entry point address.

+

+  @param[out] ImageSize     Will be filled with the file size in memory. This

+                            will effectively be equal to the sum of the load

+                            region sizes.

+

+  This function assumes the file is valid and supported as checked with

+  BootMonFsCheckFile().

+

+  @retval EFI_SUCCESS on success.

+  @retval EFI_INVALID_PARAMETER if the file is invalid.

+**/

+EFI_STATUS

+BootMonFsLoadFile (

+  IN  CONST EFI_FILE_HANDLE   FileHandle,

+  IN  CONST VOID             *FileData,

+  OUT VOID                  **EntryPoint,

+  OUT LIST_ENTRY             *LoadList

+  )

+{

+  EFI_STATUS            Status;

+  BOOTMON_FS_FILE_INFO  Info;

+  UINTN                 InfoSize;

+  UINTN                 Index;

+  UINTN                 ImageSize;

+  RUNAXF_LOAD_LIST     *LoadNode;

+

+  ASSERT (FileHandle != NULL);

+  ASSERT (FileData   != NULL);

+  ASSERT (EntryPoint != NULL);

+  ASSERT (LoadList   != NULL);

+

+  ImageSize = 0;

+

+  InfoSize = sizeof (Info);

+  Status = FileHandle->GetInfo (FileHandle, &gArmBootMonFsFileInfoGuid,

+                               &InfoSize, &Info);

+

+  if (!EFI_ERROR (Status)) {

+    *EntryPoint = (VOID*)((UINTN)Info.EntryPoint);

+    // Load all the regions to run-time memory

+    for (Index = 0; Index < Info.RegionCount; Index++) {

+      LoadNode = AllocateRuntimeZeroPool (sizeof (RUNAXF_LOAD_LIST));

+      if (LoadNode == NULL) {

+        Status = EFI_OUT_OF_RESOURCES;

+        break;

+      }

+

+      LoadNode->MemOffset  = (UINTN)Info.Region[Index].LoadAddress;

+      LoadNode->FileOffset = (UINTN)FileData + Info.Region[Index].Offset;

+      LoadNode->Length     = (UINTN)Info.Region[Index].Size;

+      InsertTailList (LoadList, &LoadNode->Link);

+

+      ImageSize += LoadNode->Length;

+    }

+  }

+

+  if ((!EFI_ERROR (Status)) && (ImageSize == 0)) {

+    Status = EFI_INVALID_PARAMETER;

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/BootMonFsLoader.h b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/BootMonFsLoader.h
new file mode 100644
index 0000000..de3c0ad
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/BootMonFsLoader.h
@@ -0,0 +1,66 @@
+/** @file

+*

+*  Copyright (c) 2014, ARM Ltd. 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 __BOOTMONFS_LOADER_H__

+#define __BOOTMONFS_LOADER_H__

+

+/**

+  Check that loading the file is supported.

+

+  Not all information is checked, only the properties that matters to us in

+  our simplified loader.

+

+  BootMonFS file properties is not in a file header but in the file-system

+  metadata, so we need to pass a handle to the file to allow access to the

+  information.

+

+  @param[in] FileHandle  Handle of the file to check.

+

+  @retval EFI_SUCCESS on success.

+  @retval EFI_INVALID_PARAMETER if the header is invalid.

+  @retval EFI_UNSUPPORTED if the file type/platform is not supported.

+**/

+EFI_STATUS

+BootMonFsCheckFile (

+  IN  CONST EFI_FILE_HANDLE  FileHandle

+  );

+

+/**

+  Load a binary file from BootMonFS.

+

+  @param[in]  FileHandle    Handle of the file to load.

+

+  @param[in]  FileData      Address  of the file data in memory.

+

+  @param[out] EntryPoint    Will be filled with the ELF entry point address.

+

+  @param[out] ImageSize     Will be filled with the file size in memory. This

+                            will effectively be equal to the sum of the load

+                            region sizes.

+

+  This function assumes the file is valid and supported as checked with

+  BootMonFsCheckFile().

+

+  @retval EFI_SUCCESS on success.

+  @retval EFI_INVALID_PARAMETER if the file is invalid.

+**/

+EFI_STATUS

+BootMonFsLoadFile (

+  IN  CONST EFI_FILE_HANDLE   FileHandle,

+  IN  CONST VOID             *FileData,

+  OUT VOID                  **EntryPoint,

+  OUT LIST_ENTRY             *LoadList

+  );

+

+#endif // __BOOTMONFS_LOADER_H__

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ElfLoader.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ElfLoader.c
new file mode 100644
index 0000000..6bb0d22
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ElfLoader.c
@@ -0,0 +1,340 @@
+/** @file

+*

+*  Copyright (c) 2014, ARM 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.

+*

+**/

+

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiLib.h>

+

+#include "ArmShellCmdRunAxf.h"

+#include "ElfLoader.h"

+#include "elf_common.h"

+#include "elf32.h"

+#include "elf64.h"

+

+

+// Put the functions the #ifdef. We only use the appropriate one for the platform.

+// This prevents 'defined but not used' compiler warning.

+#ifdef MDE_CPU_ARM

+STATIC

+BOOLEAN

+IsArmElf (

+  IN  CONST VOID *Buf

+  )

+{

+  Elf32_Ehdr *Hdr = (Elf32_Ehdr*)Buf;

+

+  if (Hdr->e_ident[EI_CLASS] != ELFCLASS32) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFWRONGCLASS_32), gRunAxfHiiHandle);

+    return FALSE;

+  }

+

+  if (Hdr->e_machine != EM_ARM) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFWRONGMACH_32), gRunAxfHiiHandle);

+    return FALSE;

+  }

+

+  // We don't currently check endianness of ELF data (hdr->e_ident[EI_DATA])

+

+  return TRUE;

+}

+#elif defined(MDE_CPU_AARCH64)

+STATIC

+BOOLEAN

+IsAarch64Elf (

+  IN  CONST VOID *Buf

+  )

+{

+  Elf64_Ehdr *Hdr = (Elf64_Ehdr*)Buf;

+

+  if (Hdr->e_ident[EI_CLASS] != ELFCLASS64) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFWRONGCLASS_64), gRunAxfHiiHandle);

+    return FALSE;

+  }

+

+  if (Hdr->e_machine != EM_AARCH64) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFWRONGMACH_64), gRunAxfHiiHandle);

+    return FALSE;

+  }

+

+  // We don't currently check endianness of ELF data (hdr->e_ident[EI_DATA])

+

+  return TRUE;

+}

+#endif // MDE_CPU_ARM , MDE_CPU_AARCH64

+

+

+/**

+ Support checking 32 and 64bit as the header could be valid, we might just

+ not support loading it.

+**/

+STATIC

+EFI_STATUS

+ElfCheckHeader (

+  IN  CONST VOID *Buf

+  )

+{

+  Elf32_Ehdr *Hdr32 = (Elf32_Ehdr*)Buf;

+

+  if (!IS_ELF (*Hdr32)) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFMAGIC), gRunAxfHiiHandle);

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (Hdr32->e_type != ET_EXEC) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFNOTEXEC), gRunAxfHiiHandle);

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (Hdr32->e_ident[EI_CLASS] == ELFCLASS32) {

+    if ((Hdr32->e_phoff == 0) || (Hdr32->e_phentsize == 0) || (Hdr32->e_phnum == 0)) {

+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFNOPROG), gRunAxfHiiHandle);

+      return EFI_INVALID_PARAMETER;

+    }

+

+    if (Hdr32->e_flags != 0) {

+      DEBUG ((EFI_D_INFO, "Warning: Wrong processor-specific flags, expected 0.\n"));

+    }

+

+    DEBUG ((EFI_D_INFO, "Entry point addr: 0x%lx\n", Hdr32->e_entry));

+    DEBUG ((EFI_D_INFO, "Start of program headers: 0x%lx\n", Hdr32->e_phoff));

+    DEBUG ((EFI_D_INFO, "Size of 1 program header: %d\n", Hdr32->e_phentsize));

+    DEBUG ((EFI_D_INFO, "Number of program headers: %d\n", Hdr32->e_phnum));

+  } else if (Hdr32->e_ident[EI_CLASS] == ELFCLASS64) {

+      Elf64_Ehdr *Hdr64 = (Elf64_Ehdr*)Buf;

+

+    if ((Hdr64->e_phoff == 0) || (Hdr64->e_phentsize == 0) || (Hdr64->e_phnum == 0)) {

+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFNOPROG), gRunAxfHiiHandle);

+      return EFI_INVALID_PARAMETER;

+    }

+

+    if (Hdr64->e_flags != 0) {

+      DEBUG ((EFI_D_INFO, "Warning: Wrong processor-specific flags, expected 0.\n"));

+    }

+

+    DEBUG ((EFI_D_INFO, "Entry point addr: 0x%lx\n", Hdr64->e_entry));

+    DEBUG ((EFI_D_INFO, "Start of program headers: 0x%lx\n", Hdr64->e_phoff));

+    DEBUG ((EFI_D_INFO, "Size of 1 program header: %d\n", Hdr64->e_phentsize));

+    DEBUG ((EFI_D_INFO, "Number of program headers: %d\n", Hdr64->e_phnum));

+  } else {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFWRONGCLASS), gRunAxfHiiHandle);

+    return EFI_INVALID_PARAMETER;

+  }

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+ Load an ELF segment into memory.

+

+ This function assumes the ELF file is valid.

+ This function is meant to be called for PT_LOAD type segments only.

+**/

+STATIC

+EFI_STATUS

+ElfLoadSegment (

+  IN  CONST VOID  *ElfImage,

+  IN  CONST VOID  *PHdr,

+  IN  LIST_ENTRY  *LoadList

+  )

+{

+  VOID             *FileSegment;

+  VOID             *MemSegment;

+  UINTN             ExtraZeroes;

+  UINTN             ExtraZeroesCount;

+  RUNAXF_LOAD_LIST *LoadNode;

+

+#ifdef MDE_CPU_ARM

+  Elf32_Phdr  *ProgramHdr;

+  ProgramHdr = (Elf32_Phdr *)PHdr;

+#elif defined(MDE_CPU_AARCH64)

+  Elf64_Phdr  *ProgramHdr;

+  ProgramHdr = (Elf64_Phdr *)PHdr;

+#endif

+

+  ASSERT (ElfImage != NULL);

+  ASSERT (ProgramHdr != NULL);

+

+  FileSegment = (VOID *)((UINTN)ElfImage + ProgramHdr->p_offset);

+  MemSegment = (VOID *)ProgramHdr->p_vaddr;

+

+  // If the segment's memory size p_memsz is larger than the file size p_filesz,

+  // the "extra" bytes are defined to hold the value 0 and to follow the

+  // segment's initialised area.

+  // This is typically the case for the .bss segment.

+  // The file size may not be larger than the memory size.

+  if (ProgramHdr->p_filesz > ProgramHdr->p_memsz) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFBADFORMAT), gRunAxfHiiHandle);

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Load the segment in memory.

+  if (ProgramHdr->p_filesz != 0) {

+    DEBUG ((EFI_D_INFO, "Loading segment from 0x%lx to 0x%lx (size = %ld)\n",

+                 FileSegment, MemSegment, ProgramHdr->p_filesz));

+

+    LoadNode = AllocateRuntimeZeroPool (sizeof (RUNAXF_LOAD_LIST));

+    if (LoadNode == NULL) {

+      return EFI_OUT_OF_RESOURCES;

+    }

+    LoadNode->MemOffset  = (UINTN)MemSegment;

+    LoadNode->FileOffset = (UINTN)FileSegment;

+    LoadNode->Length     = (UINTN)ProgramHdr->p_filesz;

+    InsertTailList (LoadList, &LoadNode->Link);

+  }

+

+  ExtraZeroes = ((UINTN)MemSegment + ProgramHdr->p_filesz);

+  ExtraZeroesCount = ProgramHdr->p_memsz - ProgramHdr->p_filesz;

+  DEBUG ((EFI_D_INFO, "Completing segment with %d zero bytes.\n", ExtraZeroesCount));

+  if (ExtraZeroesCount > 0) {

+    // Extra Node to add the Zeroes.

+    LoadNode = AllocateRuntimeZeroPool (sizeof (RUNAXF_LOAD_LIST));

+    if (LoadNode == NULL) {

+      return EFI_OUT_OF_RESOURCES;

+    }

+    LoadNode->MemOffset  = (UINTN)ExtraZeroes;

+    LoadNode->Zeroes     = TRUE;

+    LoadNode->Length     = ExtraZeroesCount;

+    InsertTailList (LoadList, &LoadNode->Link);

+  }

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+ Check that the ELF File Header is valid and Machine type supported.

+

+ Not all information is checked in the ELF header, only the stuff that

+ matters to us in our simplified ELF loader.

+

+ @param[in] ElfImage  Address of the ELF file to check.

+

+ @retval EFI_SUCCESS on success.

+ @retval EFI_INVALID_PARAMETER if the header is invalid.

+ @retval EFI_UNSUPPORTED if the file type/platform is not supported.

+**/

+EFI_STATUS

+ElfCheckFile (

+  IN  CONST VOID *ElfImage

+  )

+{

+  EFI_STATUS Status;

+

+  ASSERT (ElfImage != NULL);

+

+  // Check that the ELF header is valid.

+  Status = ElfCheckHeader (ElfImage);

+  if (EFI_ERROR(Status)) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFBADHEADER), gRunAxfHiiHandle);

+    return EFI_INVALID_PARAMETER;

+  }

+

+#ifdef MDE_CPU_ARM

+  if (IsArmElf (ElfImage)) {

+    return EFI_SUCCESS;

+  }

+#elif defined(MDE_CPU_AARCH64)

+  if (IsAarch64Elf (ElfImage)) {

+    return EFI_SUCCESS;

+  }

+#endif

+

+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_BAD_ARCH), gRunAxfHiiHandle);

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  Load a ELF file.

+

+  @param[in] ElfImage       Address of the ELF file in memory.

+

+  @param[out] EntryPoint    Will be filled with the ELF entry point address.

+

+  @param[out] ImageSize     Will be filled with the ELF size in memory. This will

+                            effectively be equal to the sum of the segments sizes.

+

+  This functon assumes the header is valid and supported as checked with

+  ElfCheckFile().

+

+  @retval EFI_SUCCESS on success.

+  @retval EFI_INVALID_PARAMETER if the ELF file is invalid.

+**/

+EFI_STATUS

+ElfLoadFile (

+  IN  CONST VOID   *ElfImage,

+  OUT VOID        **EntryPoint,

+  OUT LIST_ENTRY   *LoadList

+  )

+{

+  EFI_STATUS    Status;

+  UINT8        *ProgramHdr;

+  UINTN         Index;

+  UINTN         ImageSize;

+

+#ifdef MDE_CPU_ARM

+  Elf32_Ehdr   *ElfHdr;

+  Elf32_Phdr   *ProgramHdrPtr;

+

+  ElfHdr = (Elf32_Ehdr*)ElfImage;

+#elif defined(MDE_CPU_AARCH64)

+  Elf64_Ehdr   *ElfHdr;

+  Elf64_Phdr   *ProgramHdrPtr;

+

+  ElfHdr = (Elf64_Ehdr*)ElfImage;

+#endif

+

+  ASSERT (ElfImage   != NULL);

+  ASSERT (EntryPoint != NULL);

+  ASSERT (LoadList   != NULL);

+

+  ProgramHdr = (UINT8*)ElfImage + ElfHdr->e_phoff;

+  DEBUG ((EFI_D_INFO, "ELF program header entry : 0x%lx\n", ProgramHdr));

+

+  ImageSize = 0;

+

+  // Load every loadable ELF segment into memory.

+  for (Index = 0; Index < ElfHdr->e_phnum; ++Index) {

+

+#ifdef MDE_CPU_ARM

+    ProgramHdrPtr = (Elf32_Phdr*)ProgramHdr;

+#elif defined(MDE_CPU_AARCH64)

+    ProgramHdrPtr = (Elf64_Phdr*)ProgramHdr;

+#endif

+

+    // Only consider PT_LOAD type segments, ignore others.

+    if (ProgramHdrPtr->p_type == PT_LOAD) {

+      Status = ElfLoadSegment (ElfImage, (VOID *)ProgramHdrPtr, LoadList);

+      if (EFI_ERROR (Status)) {

+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFFAILSEG), gRunAxfHiiHandle);

+        return EFI_INVALID_PARAMETER;

+      }

+      ImageSize += ProgramHdrPtr->p_memsz;

+    }

+    ProgramHdr += ElfHdr->e_phentsize;

+  }

+

+  if (ImageSize == 0) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_ELFNOSEG), gRunAxfHiiHandle);

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Return the entry point specified in the ELF header.

+  *EntryPoint = (void*)ElfHdr->e_entry;

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ElfLoader.h b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ElfLoader.h
new file mode 100644
index 0000000..7020a6c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/ElfLoader.h
@@ -0,0 +1,64 @@
+/** @file

+*

+*  Copyright (c) 2014, ARM 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.

+*

+**/

+

+#ifndef ELF_LOADER_H

+#define ELF_LOADER_H

+

+/**

+  Check that the ELF File Header is valid and Machine type supported.

+

+  Not all information is checked in the ELF header, only the stuff that

+  matters to us in our simplified ELF loader.

+

+  @param[in] ElfImage  Address of the ELF file to check.

+

+  @retval EFI_SUCCESS on success.

+  @retval EFI_INVALID_PARAMETER if the header is invalid.

+  @retval EFI_UNSUPPORTED if the file type/platform is not supported.

+**/

+EFI_STATUS

+ElfCheckFile (

+  IN  CONST VOID *ElfImage

+  );

+

+

+/**

+  Load a ELF file.

+

+  @param[in]  ElfImage      Address of the ELF file in memory.

+

+  @param[out] EntryPoint    Will be filled with the ELF entry point address.

+

+  @param[out] ImageSize     Will be filled with the ELF size in memory. This will

+                            effectively be equal to the sum of the segments sizes.

+

+  This function assumes the header is valid and supported as checked with

+  ElfCheckFile().

+

+  NOTE:

+   - We don't currently take the segment permissions into account (indicated by

+     the program headers). It can be used to allocate pages with the right

+     read/write/exec permissions.

+

+  @retval EFI_SUCCESS on success.

+  @retval EFI_INVALID_PARAMETER if the ELF file is invalid.

+**/

+EFI_STATUS

+ElfLoadFile (

+  IN  CONST VOID   *ElfImage,

+  OUT VOID        **EntryPoint,

+  OUT LIST_ENTRY   *LoadList

+  );

+

+#endif // ELF_LOADER_H

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/RunAxf.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/RunAxf.c
new file mode 100644
index 0000000..e8576af
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/RunAxf.c
@@ -0,0 +1,395 @@
+/** @file

+*

+*  Shell command for launching AXF files.

+*

+*  Copyright (c) 2014, ARM 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.

+*

+**/

+

+#include <Guid/GlobalVariable.h>

+#include <Library/PrintLib.h>

+#include <Library/HandleParsingLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/DebugLib.h>

+

+#include <Library/ArmLib.h>

+

+#include "ArmShellCmdRunAxf.h"

+#include "ElfLoader.h"

+#include "BootMonFsLoader.h"

+

+// Provide arguments to AXF?

+typedef VOID (*ELF_ENTRYPOINT)(UINTN arg0, UINTN arg1,

+                               UINTN arg2, UINTN arg3);

+

+

+STATIC

+EFI_STATUS

+ShutdownUefiBootServices (

+  VOID

+  )

+{

+  EFI_STATUS              Status;

+  UINTN                   MemoryMapSize;

+  EFI_MEMORY_DESCRIPTOR   *MemoryMap;

+  UINTN                   MapKey;

+  UINTN                   DescriptorSize;

+  UINT32                  DescriptorVersion;

+  UINTN                   Pages;

+

+  MemoryMap = NULL;

+  MemoryMapSize = 0;

+  Pages = 0;

+

+  do {

+    Status = gBS->GetMemoryMap (

+                    &MemoryMapSize,

+                    MemoryMap,

+                    &MapKey,

+                    &DescriptorSize,

+                    &DescriptorVersion

+                    );

+    if (Status == EFI_BUFFER_TOO_SMALL) {

+

+      Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;

+      MemoryMap = AllocatePages (Pages);

+

+      //

+      // Get System MemoryMap

+      //

+      Status = gBS->GetMemoryMap (

+                      &MemoryMapSize,

+                      MemoryMap,

+                      &MapKey,

+                      &DescriptorSize,

+                      &DescriptorVersion

+                      );

+    }

+

+    // Don't do anything between the GetMemoryMap() and ExitBootServices()

+    if (!EFI_ERROR (Status)) {

+      Status = gBS->ExitBootServices (gImageHandle, MapKey);

+      if (EFI_ERROR (Status)) {

+        FreePages (MemoryMap, Pages);

+        MemoryMap = NULL;

+        MemoryMapSize = 0;

+      }

+    }

+  } while (EFI_ERROR (Status));

+

+  return Status;

+}

+

+

+STATIC

+EFI_STATUS

+PreparePlatformHardware (

+  VOID

+  )

+{

+  //Note: Interrupts will be disabled by the GIC driver when ExitBootServices() will be called.

+

+  // Clean before Disable else the Stack gets corrupted with old data.

+  ArmCleanDataCache ();

+  ArmDisableDataCache ();

+  // Invalidate all the entries that might have snuck in.

+  ArmInvalidateDataCache ();

+

+  // Disable and invalidate the instruction cache

+  ArmDisableInstructionCache ();

+  ArmInvalidateInstructionCache ();

+

+  // Turn off MMU

+  ArmDisableMmu();

+

+  return EFI_SUCCESS;

+}

+

+// Process arguments to pass to AXF?

+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {

+  {NULL, TypeMax}

+};

+

+

+/**

+  This is the shell command handler function pointer callback type. This

+  function handles the command when it is invoked in the shell.

+

+  @param[in] This             The instance of the

+                              EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.

+  @param[in] SystemTable      The pointer to the system table.

+  @param[in] ShellParameters  The parameters associated with the command.

+  @param[in] Shell            The instance of the shell protocol used in the

+                              context of processing this command.

+

+  @return EFI_SUCCESS         The operation was successful.

+  @return other               The operation failed.

+**/

+SHELL_STATUS

+EFIAPI

+ShellDynCmdRunAxfHandler (

+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL    *This,

+  IN EFI_SYSTEM_TABLE                      *SystemTable,

+  IN EFI_SHELL_PARAMETERS_PROTOCOL         *ShellParameters,

+  IN EFI_SHELL_PROTOCOL                    *Shell

+  )

+{

+  LIST_ENTRY        *ParamPackage;

+  EFI_STATUS         Status;

+  SHELL_STATUS       ShellStatus;

+  SHELL_FILE_HANDLE  FileHandle;

+  ELF_ENTRYPOINT     StartElf;

+  CONST CHAR16      *FileName;

+  EFI_FILE_INFO     *Info;

+  UINTN              FileSize;

+  VOID              *FileData;

+  VOID              *Entrypoint;

+  LIST_ENTRY         LoadList;

+  LIST_ENTRY        *Node;

+  LIST_ENTRY        *NextNode;

+  RUNAXF_LOAD_LIST  *LoadNode;

+  CHAR16            *TmpFileName;

+  CHAR16            *TmpChar16;

+

+

+  ShellStatus = SHELL_SUCCESS;

+  FileHandle = NULL;

+  FileData = NULL;

+  InitializeListHead (&LoadList);

+

+  // Only install if they are not there yet? First time or every time?

+  // These can change if the shell exits and start again.

+  Status = gBS->InstallMultipleProtocolInterfaces (&gImageHandle,

+                &gEfiShellProtocolGuid, Shell,

+                &gEfiShellParametersProtocolGuid, ShellParameters,

+                NULL);

+

+  if (EFI_ERROR (Status)) {

+    return SHELL_DEVICE_ERROR;

+  }

+

+  // Update the protocols for the application library

+  Status = ShellInitialize ();

+  ASSERT_EFI_ERROR (Status);

+  // Add support to load AXF with optipnal args?

+

+  //

+  // Process Command Line arguments

+  //

+  Status = ShellCommandLineParse (ParamList, &ParamPackage, NULL, TRUE);

+  if (EFI_ERROR (Status)) {

+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_INVALID_ARG), gRunAxfHiiHandle);

+    ShellStatus = SHELL_INVALID_PARAMETER;

+  } else {

+    //

+    // Check for "-?"

+    //

+    if ((ShellCommandLineGetFlag (ParamPackage, L"-?")) ||

+        (ShellCommandLineGetRawValue (ParamPackage, 1) == NULL)) {

+      //

+      // We didn't get a file to load

+      //

+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_INVALID_ARG), gRunAxfHiiHandle);

+      ShellStatus = SHELL_INVALID_PARAMETER;

+    } else {

+      // For the moment we assume we only ever get one file to load with no arguments.

+      FileName = ShellCommandLineGetRawValue (ParamPackage, 1);

+      Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);

+      if (EFI_ERROR (Status)) {

+        // BootMonFS supports file extensions, but they are stripped by default

+        // when the NOR is programmed.

+        // Remove the file extension and try to open again.

+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_FILE_NOT_FOUND),

+                         gRunAxfHiiHandle, FileName);

+        // Go through the filename and remove file extension. Preserve the

+        // original name.

+        TmpFileName = AllocateCopyPool (StrSize (FileName), (VOID *)FileName);

+        if (TmpFileName != NULL) {

+          TmpChar16 = StrStr (TmpFileName, L".");

+          if (TmpChar16 != NULL) {

+            *TmpChar16 = '\0';

+            DEBUG((EFI_D_ERROR, "Trying to open file: %s\n", TmpFileName));

+            Status = ShellOpenFileByName (TmpFileName, &FileHandle,

+                                          EFI_FILE_MODE_READ, 0);

+          }

+          FreePool (TmpFileName);

+        }

+        // Do we now have an open file after trying again?

+        if (EFI_ERROR (Status)) {

+          ShellStatus = SHELL_INVALID_PARAMETER;

+          FileHandle = NULL;

+        }

+      }

+

+      if (FileHandle != NULL) {

+        Info = ShellGetFileInfo (FileHandle);

+        FileSize = (UINTN) Info->FileSize;

+        FreePool (Info);

+

+        //

+        // Allocate buffer to read file. 'Runtime' so we can access it after

+        // ExitBootServices().

+        //

+        FileData = AllocateRuntimeZeroPool (FileSize);

+        if (FileData == NULL) {

+          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_NO_MEM), gRunAxfHiiHandle);

+          ShellStatus = SHELL_OUT_OF_RESOURCES;

+        } else {

+          //

+          // Read file into Buffer

+          //

+          Status = ShellReadFile (FileHandle, &FileSize, FileData);

+          if (EFI_ERROR (Status)) {

+            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_READ_FAIL), gRunAxfHiiHandle);

+            SHELL_FREE_NON_NULL (FileData);

+            FileData = NULL;

+            ShellStatus = SHELL_DEVICE_ERROR;

+          }

+        }

+      }

+    }

+

+    //

+    // Free the command line package

+    //

+    ShellCommandLineFreeVarList (ParamPackage);

+  }

+

+  // We have a file in memory. Try to work out if we can use it.

+  // It can either be in ELF format or BootMonFS format.

+  if (FileData != NULL) {

+    // Do some validation on the file before we try to load it. The file can

+    // either be an proper ELF file or one processed by the FlashLoader.

+    // Since the data might need to go to various locations in memory we cannot

+    // load the data directly while UEFI is running. We use the file loaders to

+    // populate a linked list of data and load addresses. This is processed and

+    // data copied to where it needs to go after calling ExitBootServices. At

+    // that stage we've reached the point of no return, so overwriting UEFI code

+    // does not make a difference.

+    Status = ElfCheckFile (FileData);

+    if (!EFI_ERROR (Status)) {

+      // Load program into memory

+      Status = ElfLoadFile ((VOID*)FileData, &Entrypoint, &LoadList);

+    } else {

+      // Try to see if it is a BootMonFs executable

+      Status = BootMonFsCheckFile ((EFI_FILE_HANDLE)FileHandle);

+      if (!EFI_ERROR (Status)) {

+        // Load program into memory

+        Status = BootMonFsLoadFile ((EFI_FILE_HANDLE)FileHandle,

+                                    (VOID*)FileData, &Entrypoint, &LoadList);

+      } else {

+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RUNAXF_BAD_FILE),

+                         gRunAxfHiiHandle);

+        SHELL_FREE_NON_NULL (FileData);

+        ShellStatus = SHELL_UNSUPPORTED;

+      }

+    }

+  }

+

+  // Program load list created.

+  // Shutdown UEFI, copy and jump to code.

+  if (!IsListEmpty (&LoadList) && !EFI_ERROR (Status)) {

+    // Exit boot services here. This means we cannot return and cannot assume to

+    // have access to UEFI functions.

+    Status = ShutdownUefiBootServices ();

+    if (EFI_ERROR (Status)) {

+      DEBUG ((EFI_D_ERROR,"Can not shutdown UEFI boot services. Status=0x%X\n",

+              Status));

+    } else {

+      // Process linked list. Copy data to Memory.

+      Node = GetFirstNode (&LoadList);

+      while (!IsNull (&LoadList, Node)) {

+        LoadNode = (RUNAXF_LOAD_LIST *)Node;

+        // Do we have data to copy or do we need to set Zeroes (.bss)?

+        if (LoadNode->Zeroes) {

+          ZeroMem ((VOID*)LoadNode->MemOffset, LoadNode->Length);

+        } else {

+          CopyMem ((VOID *)LoadNode->MemOffset, (VOID *)LoadNode->FileOffset,

+                   LoadNode->Length);

+        }

+        Node = GetNextNode (&LoadList, Node);

+      }

+

+      //

+      // Switch off interrupts, caches, mmu, etc

+      //

+      Status = PreparePlatformHardware ();

+      ASSERT_EFI_ERROR (Status);

+

+      StartElf = (ELF_ENTRYPOINT)Entrypoint;

+      StartElf (0,0,0,0);

+

+      // We should never get here.. But if we do, spin..

+      ASSERT (FALSE);

+      while (1);

+    }

+  }

+

+  // Free file related information as we are returning to UEFI.

+  Node = GetFirstNode (&LoadList);

+  while (!IsNull (&LoadList, Node)) {

+    NextNode = RemoveEntryList (Node);

+    FreePool (Node);

+    Node = NextNode;

+  }

+  SHELL_FREE_NON_NULL (FileData);

+  if (FileHandle != NULL) {

+    ShellCloseFile (&FileHandle);

+  }

+

+  // Uninstall protocols as we don't know if they will change.

+  // If the shell exits and come in again these mappings may be different

+  // and cause a crash.

+  Status = gBS->UninstallMultipleProtocolInterfaces (gImageHandle,

+                &gEfiShellProtocolGuid, Shell,

+                &gEfiShellParametersProtocolGuid, ShellParameters,

+                NULL);

+

+  if (EFI_ERROR (Status) && ShellStatus == SHELL_SUCCESS) {

+    ShellStatus = SHELL_DEVICE_ERROR;

+  }

+

+  return ShellStatus;

+}

+

+

+/**

+  This is the command help handler function pointer callback type. This

+  function is responsible for displaying help information for the associated

+  command.

+

+  @param[in] This             The instance of the

+                              EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.

+  @param[in] Language         The pointer to the language string to use.

+

+  @return string              Pool allocated help string, must be freed by

+                              caller.

+**/

+CHAR16*

+EFIAPI

+ShellDynCmdRunAxfGetHelp (

+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL    *This,

+  IN CONST CHAR8                           *Language

+  )

+{

+  CHAR16 *HelpText;

+

+  ASSERT (gRunAxfHiiHandle != NULL);

+

+  // This allocates memory. The caller is responsoible to free.

+  HelpText = HiiGetString (gRunAxfHiiHandle, STRING_TOKEN (STR_GET_HELP_RUNAXF),

+                           Language);

+

+  return HelpText;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf32.h b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf32.h
new file mode 100644
index 0000000..3951444
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf32.h
@@ -0,0 +1,258 @@
+/** @file

+Ported ELF include files from FreeBSD

+

+Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>

+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.

+

+

+**/

+/*-

+ * Copyright (c) 1996-1998 John D. Polstra.

+ * All rights reserved.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions

+ * are met:

+ * 1. Redistributions of source code must retain the above copyright

+ *    notice, this list of conditions and the following disclaimer.

+ * 2. Redistributions in binary form must reproduce the above copyright

+ *    notice, this list of conditions and the following disclaimer in the

+ *    documentation and/or other materials provided with the distribution.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND

+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE

+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE

+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS

+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT

+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

+ * SUCH DAMAGE.

+ *

+ * $FreeBSD: src/sys/sys/elf32.h,v 1.8.14.2 2007/12/03 21:30:36 marius Exp $

+ */

+

+#ifndef _SYS_ELF32_H_

+#define _SYS_ELF32_H_ 1

+

+

+/*

+ * ELF definitions common to all 32-bit architectures.

+ */

+

+typedef UINT32  Elf32_Addr;

+typedef UINT16  Elf32_Half;

+typedef UINT32  Elf32_Off;

+typedef INT32   Elf32_Sword;

+typedef UINT32  Elf32_Word;

+typedef UINT64  Elf32_Lword;

+

+typedef Elf32_Word      Elf32_Hashelt;

+

+/* Non-standard class-dependent datatype used for abstraction. */

+typedef Elf32_Word      Elf32_Size;

+typedef Elf32_Sword     Elf32_Ssize;

+

+/*

+ * ELF header.

+ */

+

+typedef struct {

+  unsigned char   e_ident[EI_NIDENT]; /* File identification. */

+  Elf32_Half      e_type;             /* File type. */

+  Elf32_Half      e_machine;          /* Machine architecture. */

+  Elf32_Word      e_version;          /* ELF format version. */

+  Elf32_Addr      e_entry;            /* Entry point. */

+  Elf32_Off       e_phoff;            /* Program header file offset. */

+  Elf32_Off       e_shoff;            /* Section header file offset. */

+  Elf32_Word      e_flags;            /* Architecture-specific flags. */

+  Elf32_Half      e_ehsize;           /* Size of ELF header in bytes. */

+  Elf32_Half      e_phentsize;        /* Size of program header entry. */

+  Elf32_Half      e_phnum;            /* Number of program header entries. */

+  Elf32_Half      e_shentsize;        /* Size of section header entry. */

+  Elf32_Half      e_shnum;            /* Number of section header entries. */

+  Elf32_Half      e_shstrndx;         /* Section name strings section. */

+} Elf32_Ehdr;

+

+/*

+ * Section header.

+ */

+

+typedef struct {

+  Elf32_Word      sh_name;        /* Section name (index into the

+                                     section header string table). */

+  Elf32_Word      sh_type;        /* Section type. */

+  Elf32_Word      sh_flags;       /* Section flags. */

+  Elf32_Addr      sh_addr;        /* Address in memory image. */

+  Elf32_Off       sh_offset;      /* Offset in file. */

+  Elf32_Word      sh_size;        /* Size in bytes. */

+  Elf32_Word      sh_link;        /* Index of a related section. */

+  Elf32_Word      sh_info;        /* Depends on section type. */

+  Elf32_Word      sh_addralign;   /* Alignment in bytes. */

+  Elf32_Word      sh_entsize;     /* Size of each entry in section. */

+} Elf32_Shdr;

+

+/*

+ * Program header.

+ */

+

+typedef struct {

+  Elf32_Word      p_type;         /* Entry type. */

+  Elf32_Off       p_offset;       /* File offset of contents. */

+  Elf32_Addr      p_vaddr;        /* Virtual address in memory image. */

+  Elf32_Addr      p_paddr;        /* Physical address (not used). */

+  Elf32_Word      p_filesz;       /* Size of contents in file. */

+  Elf32_Word      p_memsz;        /* Size of contents in memory. */

+  Elf32_Word      p_flags;        /* Access permission flags. */

+  Elf32_Word      p_align;        /* Alignment in memory and file. */

+} Elf32_Phdr;

+

+/*

+ * Dynamic structure.  The ".dynamic" section contains an array of them.

+ */

+

+typedef struct {

+  Elf32_Sword     d_tag;          /* Entry type. */

+  union {

+    Elf32_Word      d_val;  /* Integer value. */

+    Elf32_Addr      d_ptr;  /* Address value. */

+  } d_un;

+} Elf32_Dyn;

+

+/*

+ * Relocation entries.

+ */

+

+/* Relocations that don't need an addend field. */

+typedef struct {

+  Elf32_Addr      r_offset;       /* Location to be relocated. */

+  Elf32_Word      r_info;         /* Relocation type and symbol index. */

+} Elf32_Rel;

+

+/* Relocations that need an addend field. */

+typedef struct {

+  Elf32_Addr      r_offset;       /* Location to be relocated. */

+  Elf32_Word      r_info;         /* Relocation type and symbol index. */

+  Elf32_Sword     r_addend;       /* Addend. */

+} Elf32_Rela;

+

+/* Macros for accessing the fields of r_info. */

+#define ELF32_R_SYM(info)       ((info) >> 8)

+#define ELF32_R_TYPE(info)      ((unsigned char)(info))

+

+/* Macro for constructing r_info from field values. */

+#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))

+

+/*

+ *      Note entry header

+ */

+typedef Elf_Note Elf32_Nhdr;

+

+/*

+ *      Move entry

+ */

+typedef struct {

+  Elf32_Lword     m_value;        /* symbol value */

+  Elf32_Word      m_info;         /* size + index */

+  Elf32_Word      m_poffset;      /* symbol offset */

+  Elf32_Half      m_repeat;       /* repeat count */

+  Elf32_Half      m_stride;       /* stride info */

+} Elf32_Move;

+

+/*

+ *      The macros compose and decompose values for Move.r_info

+ *

+ *      sym = ELF32_M_SYM(M.m_info)

+ *      size = ELF32_M_SIZE(M.m_info)

+ *      M.m_info = ELF32_M_INFO(sym, size)

+ */

+#define ELF32_M_SYM(info)       ((info)>>8)

+#define ELF32_M_SIZE(info)      ((unsigned char)(info))

+#define ELF32_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))

+

+/*

+ *      Hardware/Software capabilities entry

+ */

+typedef struct {

+  Elf32_Word      c_tag;          /* how to interpret value */

+  union {

+    Elf32_Word      c_val;

+    Elf32_Addr      c_ptr;

+  } c_un;

+} Elf32_Cap;

+

+/*

+ * Symbol table entries.

+ */

+

+typedef struct {

+  Elf32_Word      st_name;        /* String table index of name. */

+  Elf32_Addr      st_value;       /* Symbol value. */

+  Elf32_Word      st_size;        /* Size of associated object. */

+  unsigned char   st_info;        /* Type and binding information. */

+  unsigned char   st_other;       /* Reserved (not used). */

+  Elf32_Half      st_shndx;       /* Section index of symbol. */

+} Elf32_Sym;

+

+/* Macros for accessing the fields of st_info. */

+#define ELF32_ST_BIND(info)             ((info) >> 4)

+#define ELF32_ST_TYPE(info)             ((info) & 0xf)

+

+/* Macro for constructing st_info from field values. */

+#define ELF32_ST_INFO(bind, type)       (((bind) << 4) + ((type) & 0xf))

+

+/* Macro for accessing the fields of st_other. */

+#define ELF32_ST_VISIBILITY(oth)        ((oth) & 0x3)

+

+/* Structures used by Sun & GNU symbol versioning. */

+typedef struct

+{

+  Elf32_Half      vd_version;

+  Elf32_Half      vd_flags;

+  Elf32_Half      vd_ndx;

+  Elf32_Half      vd_cnt;

+  Elf32_Word      vd_hash;

+  Elf32_Word      vd_aux;

+  Elf32_Word      vd_next;

+} Elf32_Verdef;

+

+typedef struct

+{

+  Elf32_Word      vda_name;

+  Elf32_Word      vda_next;

+} Elf32_Verdaux;

+

+typedef struct

+{

+  Elf32_Half      vn_version;

+  Elf32_Half      vn_cnt;

+  Elf32_Word      vn_file;

+  Elf32_Word      vn_aux;

+  Elf32_Word      vn_next;

+} Elf32_Verneed;

+

+typedef struct

+{

+  Elf32_Word      vna_hash;

+  Elf32_Half      vna_flags;

+  Elf32_Half      vna_other;

+  Elf32_Word      vna_name;

+  Elf32_Word      vna_next;

+} Elf32_Vernaux;

+

+typedef Elf32_Half Elf32_Versym;

+

+typedef struct {

+  Elf32_Half      si_boundto;     /* direct bindings - symbol bound to */

+  Elf32_Half      si_flags;       /* per symbol flags */

+} Elf32_Syminfo;

+

+#endif /* !_SYS_ELF32_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf64.h b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf64.h
new file mode 100644
index 0000000..1cfe0c9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf64.h
@@ -0,0 +1,260 @@
+/** @file

+Ported ELF include files from FreeBSD

+

+Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>

+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.

+

+**/

+/*-

+ * Copyright (c) 1996-1998 John D. Polstra.

+ * All rights reserved.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions

+ * are met:

+ * 1. Redistributions of source code must retain the above copyright

+ *    notice, this list of conditions and the following disclaimer.

+ * 2. Redistributions in binary form must reproduce the above copyright

+ *    notice, this list of conditions and the following disclaimer in the

+ *    documentation and/or other materials provided with the distribution.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND

+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE

+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE

+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS

+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT

+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

+ * SUCH DAMAGE.

+ *

+ * $FreeBSD: src/sys/sys/elf64.h,v 1.10.14.2 2007/12/03 21:30:36 marius Exp $

+ */

+

+#ifndef _SYS_ELF64_H_

+#define _SYS_ELF64_H_ 1

+

+

+/*

+ * ELF definitions common to all 64-bit architectures.

+ */

+

+typedef UINT64  Elf64_Addr;

+typedef UINT16  Elf64_Half;

+typedef UINT64  Elf64_Off;

+typedef INT32   Elf64_Sword;

+typedef INT64   Elf64_Sxword;

+typedef UINT32  Elf64_Word;

+typedef UINT64  Elf64_Lword;

+typedef UINT64  Elf64_Xword;

+

+/*

+ * Types of dynamic symbol hash table bucket and chain elements.

+ *

+ * This is inconsistent among 64 bit architectures, so a machine dependent

+ * typedef is required.

+ */

+

+typedef Elf64_Word      Elf64_Hashelt;

+

+/* Non-standard class-dependent datatype used for abstraction. */

+typedef Elf64_Xword     Elf64_Size;

+typedef Elf64_Sxword    Elf64_Ssize;

+

+/*

+ * ELF header.

+ */

+

+typedef struct {

+  unsigned char   e_ident[EI_NIDENT]; /* File identification. */

+  Elf64_Half      e_type;             /* File type. */

+  Elf64_Half      e_machine;          /* Machine architecture. */

+  Elf64_Word      e_version;          /* ELF format version. */

+  Elf64_Addr      e_entry;            /* Entry point. */

+  Elf64_Off       e_phoff;            /* Program header file offset. */

+  Elf64_Off       e_shoff;            /* Section header file offset. */

+  Elf64_Word      e_flags;            /* Architecture-specific flags. */

+  Elf64_Half      e_ehsize;           /* Size of ELF header in bytes. */

+  Elf64_Half      e_phentsize;        /* Size of program header entry. */

+  Elf64_Half      e_phnum;            /* Number of program header entries. */

+  Elf64_Half      e_shentsize;        /* Size of section header entry. */

+  Elf64_Half      e_shnum;            /* Number of section header entries. */

+  Elf64_Half      e_shstrndx;         /* Section name strings section. */

+} Elf64_Ehdr;

+

+/*

+ * Section header.

+ */

+

+typedef struct {

+  Elf64_Word      sh_name;        /* Section name (index into the

+                                     section header string table). */

+  Elf64_Word      sh_type;        /* Section type. */

+  Elf64_Xword     sh_flags;       /* Section flags. */

+  Elf64_Addr      sh_addr;        /* Address in memory image. */

+  Elf64_Off       sh_offset;      /* Offset in file. */

+  Elf64_Xword     sh_size;        /* Size in bytes. */

+  Elf64_Word      sh_link;        /* Index of a related section. */

+  Elf64_Word      sh_info;        /* Depends on section type. */

+  Elf64_Xword     sh_addralign;   /* Alignment in bytes. */

+  Elf64_Xword     sh_entsize;     /* Size of each entry in section. */

+} Elf64_Shdr;

+

+/*

+ * Program header.

+ */

+

+typedef struct {

+  Elf64_Word      p_type;         /* Entry type. */

+  Elf64_Word      p_flags;        /* Access permission flags. */

+  Elf64_Off       p_offset;       /* File offset of contents. */

+  Elf64_Addr      p_vaddr;        /* Virtual address in memory image. */

+  Elf64_Addr      p_paddr;        /* Physical address (not used). */

+  Elf64_Xword     p_filesz;       /* Size of contents in file. */

+  Elf64_Xword     p_memsz;        /* Size of contents in memory. */

+  Elf64_Xword     p_align;        /* Alignment in memory and file. */

+} Elf64_Phdr;

+

+/*

+ * Dynamic structure.  The ".dynamic" section contains an array of them.

+ */

+

+typedef struct {

+  Elf64_Sxword    d_tag;          /* Entry type. */

+  union {

+    Elf64_Xword     d_val;  /* Integer value. */

+    Elf64_Addr      d_ptr;  /* Address value. */

+  } d_un;

+} Elf64_Dyn;

+

+/*

+ * Relocation entries.

+ */

+

+/* Relocations that don't need an addend field. */

+typedef struct {

+  Elf64_Addr      r_offset;       /* Location to be relocated. */

+  Elf64_Xword     r_info;         /* Relocation type and symbol index. */

+} Elf64_Rel;

+

+/* Relocations that need an addend field. */

+typedef struct {

+  Elf64_Addr      r_offset;       /* Location to be relocated. */

+  Elf64_Xword     r_info;         /* Relocation type and symbol index. */

+  Elf64_Sxword    r_addend;       /* Addend. */

+} Elf64_Rela;

+

+/* Macros for accessing the fields of r_info. */

+#define ELF64_R_SYM(info)       ((info) >> 32)

+#define ELF64_R_TYPE(info)      ((info) & 0xffffffffL)

+

+/* Macro for constructing r_info from field values. */

+#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL))

+

+#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40)

+#define ELF64_R_TYPE_ID(info)   (((Elf64_Xword)(info)<<56)>>56)

+#define ELF64_R_TYPE_INFO(data, type)   \

+                (((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))

+

+/*

+ *      Note entry header

+ */

+typedef Elf_Note Elf64_Nhdr;

+

+/*

+ *      Move entry

+ */

+typedef struct {

+  Elf64_Lword     m_value;        /* symbol value */

+  Elf64_Xword     m_info;         /* size + index */

+  Elf64_Xword     m_poffset;      /* symbol offset */

+  Elf64_Half      m_repeat;       /* repeat count */

+  Elf64_Half      m_stride;       /* stride info */

+} Elf64_Move;

+

+#define ELF64_M_SYM(info)       ((info)>>8)

+#define ELF64_M_SIZE(info)      ((unsigned char)(info))

+#define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))

+

+/*

+ *      Hardware/Software capabilities entry

+ */

+typedef struct {

+  Elf64_Xword     c_tag;          /* how to interpret value */

+  union {

+    Elf64_Xword     c_val;

+    Elf64_Addr      c_ptr;

+  } c_un;

+} Elf64_Cap;

+

+/*

+ * Symbol table entries.

+ */

+

+typedef struct {

+  Elf64_Word      st_name;        /* String table index of name. */

+  unsigned char   st_info;        /* Type and binding information. */

+  unsigned char   st_other;       /* Reserved (not used). */

+  Elf64_Half      st_shndx;       /* Section index of symbol. */

+  Elf64_Addr      st_value;       /* Symbol value. */

+  Elf64_Xword     st_size;        /* Size of associated object. */

+} Elf64_Sym;

+

+/* Macros for accessing the fields of st_info. */

+#define ELF64_ST_BIND(info)             ((info) >> 4)

+#define ELF64_ST_TYPE(info)             ((info) & 0xf)

+

+/* Macro for constructing st_info from field values. */

+#define ELF64_ST_INFO(bind, type)       (((bind) << 4) + ((type) & 0xf))

+

+/* Macro for accessing the fields of st_other. */

+#define ELF64_ST_VISIBILITY(oth)        ((oth) & 0x3)

+

+/* Structures used by Sun & GNU-style symbol versioning. */

+typedef struct {

+  Elf64_Half      vd_version;

+  Elf64_Half      vd_flags;

+  Elf64_Half      vd_ndx;

+  Elf64_Half      vd_cnt;

+  Elf64_Word      vd_hash;

+  Elf64_Word      vd_aux;

+  Elf64_Word      vd_next;

+} Elf64_Verdef;

+

+typedef struct {

+  Elf64_Word      vda_name;

+  Elf64_Word      vda_next;

+} Elf64_Verdaux;

+

+typedef struct {

+  Elf64_Half      vn_version;

+  Elf64_Half      vn_cnt;

+  Elf64_Word      vn_file;

+  Elf64_Word      vn_aux;

+  Elf64_Word      vn_next;

+} Elf64_Verneed;

+

+typedef struct {

+  Elf64_Word      vna_hash;

+  Elf64_Half      vna_flags;

+  Elf64_Half      vna_other;

+  Elf64_Word      vna_name;

+  Elf64_Word      vna_next;

+} Elf64_Vernaux;

+

+typedef Elf64_Half Elf64_Versym;

+

+typedef struct {

+  Elf64_Half      si_boundto;     /* direct bindings - symbol bound to */

+  Elf64_Half      si_flags;       /* per symbol flags */

+} Elf64_Syminfo;

+

+#endif /* !_SYS_ELF64_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf_common.h b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf_common.h
new file mode 100644
index 0000000..ed3cedc
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmShellCmdRunAxf/elf_common.h
@@ -0,0 +1,1059 @@
+/** @file

+Ported ELF include files from FreeBSD

+

+Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>

+Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>

+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.

+

+

+**/

+/*-

+ * Copyright (c) 1998 John D. Polstra.

+ * All rights reserved.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions

+ * are met:

+ * 1. Redistributions of source code must retain the above copyright

+ *    notice, this list of conditions and the following disclaimer.

+ * 2. Redistributions in binary form must reproduce the above copyright

+ *    notice, this list of conditions and the following disclaimer in the

+ *    documentation and/or other materials provided with the distribution.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND

+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE

+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE

+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS

+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT

+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

+ * SUCH DAMAGE.

+ *

+ * $FreeBSD: src/sys/sys/elf_common.h,v 1.15.8.2 2007/12/03 21:30:36 marius Exp $

+ */

+

+#ifndef _SYS_ELF_COMMON_H_

+#define _SYS_ELF_COMMON_H_ 1

+

+/*

+ * ELF definitions that are independent of architecture or word size.

+ */

+

+/*

+ * Note header.  The ".note" section contains an array of notes.  Each

+ * begins with this header, aligned to a word boundary.  Immediately

+ * following the note header is n_namesz bytes of name, padded to the

+ * next word boundary.  Then comes n_descsz bytes of descriptor, again

+ * padded to a word boundary.  The values of n_namesz and n_descsz do

+ * not include the padding.

+ */

+

+typedef struct {

+        UINT32  n_namesz;       /* Length of name. */

+        UINT32  n_descsz;       /* Length of descriptor. */

+        UINT32  n_type;         /* Type of this note. */

+} Elf_Note;

+

+/* Indexes into the e_ident array.  Keep synced with

+   http://www.sco.com/developers/gabi/latest/ch4.eheader.html */

+#define EI_MAG0         0       /* Magic number, byte 0. */

+#define EI_MAG1         1       /* Magic number, byte 1. */

+#define EI_MAG2         2       /* Magic number, byte 2. */

+#define EI_MAG3         3       /* Magic number, byte 3. */

+#define EI_CLASS        4       /* Class of machine. */

+#define EI_DATA         5       /* Data format. */

+#define EI_VERSION      6       /* ELF format version. */

+#define EI_OSABI        7       /* Operating system / ABI identification */

+#define EI_ABIVERSION   8       /* ABI version */

+#define OLD_EI_BRAND    8       /* Start of architecture identification. */

+#define EI_PAD          9       /* Start of padding (per SVR4 ABI). */

+#define EI_NIDENT       16      /* Size of e_ident array. */

+

+/* Values for the magic number bytes. */

+#define ELFMAG0         0x7f

+#define ELFMAG1         'E'

+#define ELFMAG2         'L'

+#define ELFMAG3         'F'

+#define ELFMAG          "\177ELF"       /* magic string */

+#define SELFMAG         4               /* magic string size */

+

+/* Values for e_ident[EI_VERSION] and e_version. */

+#define EV_NONE         0

+#define EV_CURRENT      1

+

+/* Values for e_ident[EI_CLASS]. */

+#define ELFCLASSNONE    0       /* Unknown class. */

+#define ELFCLASS32      1       /* 32-bit architecture. */

+#define ELFCLASS64      2       /* 64-bit architecture. */

+

+/* Values for e_ident[EI_DATA]. */

+#define ELFDATANONE     0       /* Unknown data format. */

+#define ELFDATA2LSB     1       /* 2's complement little-endian. */

+#define ELFDATA2MSB     2       /* 2's complement big-endian. */

+

+/* Values for e_ident[EI_OSABI]. */

+#define ELFOSABI_NONE           0       /* UNIX System V ABI */

+#define ELFOSABI_HPUX           1       /* HP-UX operating system */

+#define ELFOSABI_NETBSD         2       /* NetBSD */

+#define ELFOSABI_LINUX          3       /* GNU/Linux */

+#define ELFOSABI_HURD           4       /* GNU/Hurd */

+#define ELFOSABI_86OPEN         5       /* 86Open common IA32 ABI */

+#define ELFOSABI_SOLARIS        6       /* Solaris */

+#define ELFOSABI_AIX            7       /* AIX */

+#define ELFOSABI_IRIX           8       /* IRIX */

+#define ELFOSABI_FREEBSD        9       /* FreeBSD */

+#define ELFOSABI_TRU64          10      /* TRU64 UNIX */

+#define ELFOSABI_MODESTO        11      /* Novell Modesto */

+#define ELFOSABI_OPENBSD        12      /* OpenBSD */

+#define ELFOSABI_OPENVMS        13      /* Open VMS */

+#define ELFOSABI_NSK            14      /* HP Non-Stop Kernel */

+#define ELFOSABI_ARM            97      /* ARM */

+#define ELFOSABI_STANDALONE     255     /* Standalone (embedded) application */

+

+#define ELFOSABI_SYSV           ELFOSABI_NONE   /* symbol used in old spec */

+#define ELFOSABI_MONTEREY       ELFOSABI_AIX    /* Monterey */

+

+/* e_ident */

+#define IS_ELF(ehdr)    ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \

+                         (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \

+                         (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \

+                         (ehdr).e_ident[EI_MAG3] == ELFMAG3)

+

+/* Values for e_type. */

+#define ET_NONE         0       /* Unknown type. */

+#define ET_REL          1       /* Relocatable. */

+#define ET_EXEC         2       /* Executable. */

+#define ET_DYN          3       /* Shared object. */

+#define ET_CORE         4       /* Core file. */

+#define ET_LOOS         0xfe00  /* First operating system specific. */

+#define ET_HIOS         0xfeff  /* Last operating system-specific. */

+#define ET_LOPROC       0xff00  /* First processor-specific. */

+#define ET_HIPROC       0xffff  /* Last processor-specific. */

+

+/* Values for e_machine. */

+#define EM_NONE         0       /* Unknown machine. */

+#define EM_M32          1       /* AT&T WE32100. */

+#define EM_SPARC        2       /* Sun SPARC. */

+#define EM_386          3       /* Intel i386. */

+#define EM_68K          4       /* Motorola 68000. */

+#define EM_88K          5       /* Motorola 88000. */

+#define EM_860          7       /* Intel i860. */

+#define EM_MIPS         8       /* MIPS R3000 Big-Endian only. */

+#define EM_S370         9       /* IBM System/370. */

+#define EM_MIPS_RS3_LE  10      /* MIPS R3000 Little-Endian. */

+#define EM_PARISC       15      /* HP PA-RISC. */

+#define EM_VPP500       17      /* Fujitsu VPP500. */

+#define EM_SPARC32PLUS  18      /* SPARC v8plus. */

+#define EM_960          19      /* Intel 80960. */

+#define EM_PPC          20      /* PowerPC 32-bit. */

+#define EM_PPC64        21      /* PowerPC 64-bit. */

+#define EM_S390         22      /* IBM System/390. */

+#define EM_V800         36      /* NEC V800. */

+#define EM_FR20         37      /* Fujitsu FR20. */

+#define EM_RH32         38      /* TRW RH-32. */

+#define EM_RCE          39      /* Motorola RCE. */

+#define EM_ARM          40      /* ARM. */

+#define EM_SH           42      /* Hitachi SH. */

+#define EM_SPARCV9      43      /* SPARC v9 64-bit. */

+#define EM_TRICORE      44      /* Siemens TriCore embedded processor. */

+#define EM_ARC          45      /* Argonaut RISC Core. */

+#define EM_H8_300       46      /* Hitachi H8/300. */

+#define EM_H8_300H      47      /* Hitachi H8/300H. */

+#define EM_H8S          48      /* Hitachi H8S. */

+#define EM_H8_500       49      /* Hitachi H8/500. */

+#define EM_IA_64        50      /* Intel IA-64 Processor. */

+#define EM_MIPS_X       51      /* Stanford MIPS-X. */

+#define EM_COLDFIRE     52      /* Motorola ColdFire. */

+#define EM_68HC12       53      /* Motorola M68HC12. */

+#define EM_MMA          54      /* Fujitsu MMA. */

+#define EM_PCP          55      /* Siemens PCP. */

+#define EM_NCPU         56      /* Sony nCPU. */

+#define EM_NDR1         57      /* Denso NDR1 microprocessor. */

+#define EM_STARCORE     58      /* Motorola Star*Core processor. */

+#define EM_ME16         59      /* Toyota ME16 processor. */

+#define EM_ST100        60      /* STMicroelectronics ST100 processor. */

+#define EM_TINYJ        61      /* Advanced Logic Corp. TinyJ processor. */

+#define EM_X86_64       62      /* Advanced Micro Devices x86-64 */

+#define EM_AMD64        EM_X86_64 /* Advanced Micro Devices x86-64 (compat) */

+#define EM_AARCH64      183     /* ARM 64bit Architecture */

+

+/* Non-standard or deprecated. */

+#define EM_486          6       /* Intel i486. */

+#define EM_MIPS_RS4_BE  10      /* MIPS R4000 Big-Endian */

+#define EM_ALPHA_STD    41      /* Digital Alpha (standard value). */

+#define EM_ALPHA        0x9026  /* Alpha (written in the absence of an ABI) */

+

+/* Special section indexes. */

+#define SHN_UNDEF            0          /* Undefined, missing, irrelevant. */

+#define SHN_LORESERVE   0xff00          /* First of reserved range. */

+#define SHN_LOPROC      0xff00          /* First processor-specific. */

+#define SHN_HIPROC      0xff1f          /* Last processor-specific. */

+#define SHN_LOOS        0xff20          /* First operating system-specific. */

+#define SHN_HIOS        0xff3f          /* Last operating system-specific. */

+#define SHN_ABS         0xfff1          /* Absolute values. */

+#define SHN_COMMON      0xfff2          /* Common data. */

+#define SHN_XINDEX      0xffff          /* Escape -- index stored elsewhere. */

+#define SHN_HIRESERVE   0xffff          /* Last of reserved range. */

+

+/* sh_type */

+#define SHT_NULL                0       /* inactive */

+#define SHT_PROGBITS            1       /* program defined information */

+#define SHT_SYMTAB              2       /* symbol table section */

+#define SHT_STRTAB              3       /* string table section */

+#define SHT_RELA                4       /* relocation section with addends */

+#define SHT_HASH                5       /* symbol hash table section */

+#define SHT_DYNAMIC             6       /* dynamic section */

+#define SHT_NOTE                7       /* note section */

+#define SHT_NOBITS              8       /* no space section */

+#define SHT_REL                 9       /* relocation section - no addends */

+#define SHT_SHLIB               10      /* reserved - purpose unknown */

+#define SHT_DYNSYM              11      /* dynamic symbol table section */

+#define SHT_INIT_ARRAY          14      /* Initialization function pointers. */

+#define SHT_FINI_ARRAY          15      /* Termination function pointers. */

+#define SHT_PREINIT_ARRAY       16      /* Pre-initialization function ptrs. */

+#define SHT_GROUP               17      /* Section group. */

+#define SHT_SYMTAB_SHNDX        18      /* Section indexes (see SHN_XINDEX). */

+#define SHT_LOOS                0x60000000      /* First of OS specific semantics */

+#define SHT_LOSUNW              0x6ffffff4

+#define SHT_SUNW_dof            0x6ffffff4

+#define SHT_SUNW_cap            0x6ffffff5

+#define SHT_SUNW_SIGNATURE      0x6ffffff6

+#define SHT_SUNW_ANNOTATE       0x6ffffff7

+#define SHT_SUNW_DEBUGSTR       0x6ffffff8

+#define SHT_SUNW_DEBUG          0x6ffffff9

+#define SHT_SUNW_move           0x6ffffffa

+#define SHT_SUNW_COMDAT         0x6ffffffb

+#define SHT_SUNW_syminfo        0x6ffffffc

+#define SHT_SUNW_verdef         0x6ffffffd

+#define SHT_GNU_verdef          0x6ffffffd      /* Symbol versions provided */

+#define SHT_SUNW_verneed        0x6ffffffe

+#define SHT_GNU_verneed         0x6ffffffe      /* Symbol versions required */

+#define SHT_SUNW_versym         0x6fffffff

+#define SHT_GNU_versym          0x6fffffff      /* Symbol version table */

+#define SHT_HISUNW              0x6fffffff

+#define SHT_HIOS                0x6fffffff      /* Last of OS specific semantics */

+#define SHT_LOPROC              0x70000000      /* reserved range for processor */

+#define SHT_AMD64_UNWIND        0x70000001      /* unwind information */

+#define SHT_HIPROC              0x7fffffff      /* specific section header types */

+#define SHT_LOUSER              0x80000000      /* reserved range for application */

+#define SHT_HIUSER              0xffffffff      /* specific indexes */

+

+/* Flags for sh_flags. */

+#define SHF_WRITE               0x1     /* Section contains writable data. */

+#define SHF_ALLOC               0x2     /* Section occupies memory. */

+#define SHF_EXECINSTR           0x4     /* Section contains instructions. */

+#define SHF_MERGE               0x10    /* Section may be merged. */

+#define SHF_STRINGS             0x20    /* Section contains strings. */

+#define SHF_INFO_LINK           0x40    /* sh_info holds section index. */

+#define SHF_LINK_ORDER          0x80    /* Special ordering requirements. */

+#define SHF_OS_NONCONFORMING    0x100   /* OS-specific processing required. */

+#define SHF_GROUP               0x200   /* Member of section group. */

+#define SHF_TLS                 0x400   /* Section contains TLS data. */

+#define SHF_MASKOS      0x0ff00000      /* OS-specific semantics. */

+#define SHF_MASKPROC    0xf0000000      /* Processor-specific semantics. */

+

+/* Values for p_type. */

+#define PT_NULL         0       /* Unused entry. */

+#define PT_LOAD         1       /* Loadable segment. */

+#define PT_DYNAMIC      2       /* Dynamic linking information segment. */

+#define PT_INTERP       3       /* Pathname of interpreter. */

+#define PT_NOTE         4       /* Auxiliary information. */

+#define PT_SHLIB        5       /* Reserved (not used). */

+#define PT_PHDR         6       /* Location of program header itself. */

+#define PT_TLS          7       /* Thread local storage segment */

+#define PT_LOOS         0x60000000      /* First OS-specific. */

+#define PT_SUNW_UNWIND  0x6464e550      /* amd64 UNWIND program header */

+#define PT_GNU_EH_FRAME 0x6474e550

+#define PT_LOSUNW       0x6ffffffa

+#define PT_SUNWBSS      0x6ffffffa      /* Sun Specific segment */

+#define PT_SUNWSTACK    0x6ffffffb      /* describes the stack segment */

+#define PT_SUNWDTRACE   0x6ffffffc      /* private */

+#define PT_SUNWCAP      0x6ffffffd      /* hard/soft capabilities segment */

+#define PT_HISUNW       0x6fffffff

+#define PT_HIOS         0x6fffffff      /* Last OS-specific. */

+#define PT_LOPROC       0x70000000      /* First processor-specific type. */

+#define PT_HIPROC       0x7fffffff      /* Last processor-specific type. */

+

+/* Values for p_flags. */

+#define PF_X            0x1             /* Executable. */

+#define PF_W            0x2             /* Writable. */

+#define PF_R            0x4             /* Readable. */

+#define PF_MASKOS       0x0ff00000      /* Operating system-specific. */

+#define PF_MASKPROC     0xf0000000      /* Processor-specific. */

+

+/* Extended program header index. */

+#define PN_XNUM         0xffff

+

+/* Values for d_tag. */

+#define DT_NULL         0       /* Terminating entry. */

+#define DT_NEEDED       1       /* String table offset of a needed shared

+                                   library. */

+#define DT_PLTRELSZ     2       /* Total size in bytes of PLT relocations. */

+#define DT_PLTGOT       3       /* Processor-dependent address. */

+#define DT_HASH         4       /* Address of symbol hash table. */

+#define DT_STRTAB       5       /* Address of string table. */

+#define DT_SYMTAB       6       /* Address of symbol table. */

+#define DT_RELA         7       /* Address of ElfNN_Rela relocations. */

+#define DT_RELASZ       8       /* Total size of ElfNN_Rela relocations. */

+#define DT_RELAENT      9       /* Size of each ElfNN_Rela relocation entry. */

+#define DT_STRSZ        10      /* Size of string table. */

+#define DT_SYMENT       11      /* Size of each symbol table entry. */

+#define DT_INIT         12      /* Address of initialization function. */

+#define DT_FINI         13      /* Address of finalization function. */

+#define DT_SONAME       14      /* String table offset of shared object

+                                   name. */

+#define DT_RPATH        15      /* String table offset of library path. [sup] */

+#define DT_SYMBOLIC     16      /* Indicates "symbolic" linking. [sup] */

+#define DT_REL          17      /* Address of ElfNN_Rel relocations. */

+#define DT_RELSZ        18      /* Total size of ElfNN_Rel relocations. */

+#define DT_RELENT       19      /* Size of each ElfNN_Rel relocation. */

+#define DT_PLTREL       20      /* Type of relocation used for PLT. */

+#define DT_DEBUG        21      /* Reserved (not used). */

+#define DT_TEXTREL      22      /* Indicates there may be relocations in

+                                   non-writable segments. [sup] */

+#define DT_JMPREL       23      /* Address of PLT relocations. */

+#define DT_BIND_NOW     24      /* [sup] */

+#define DT_INIT_ARRAY   25      /* Address of the array of pointers to

+                                   initialization functions */

+#define DT_FINI_ARRAY   26      /* Address of the array of pointers to

+                                   termination functions */

+#define DT_INIT_ARRAYSZ 27      /* Size in bytes of the array of

+                                   initialization functions. */

+#define DT_FINI_ARRAYSZ 28      /* Size in bytes of the array of

+                                   terminationfunctions. */

+#define DT_RUNPATH      29      /* String table offset of a null-terminated

+                                   library search path string. */

+#define DT_FLAGS        30      /* Object specific flag values. */

+#define DT_ENCODING     32      /* Values greater than or equal to DT_ENCODING

+                                   and less than DT_LOOS follow the rules for

+                                   the interpretation of the d_un union

+                                   as follows: even == 'd_ptr', even == 'd_val'

+                                   or none */

+#define DT_PREINIT_ARRAY   32   /* Address of the array of pointers to

+                                   pre-initialization functions. */

+#define DT_PREINIT_ARRAYSZ 33   /* Size in bytes of the array of

+                                   pre-initialization functions. */

+#define DT_MAXPOSTAGS      34   /* number of positive tags */

+#define DT_LOOS            0x6000000d      /* First OS-specific */

+#define DT_SUNW_AUXILIARY  0x6000000d      /* symbol auxiliary name */

+#define DT_SUNW_RTLDINF    0x6000000e      /* ld.so.1 info (private) */

+#define DT_SUNW_FILTER     0x6000000f      /* symbol filter name */

+#define DT_SUNW_CAP        0x60000010      /* hardware/software */

+#define DT_HIOS            0x6ffff000      /* Last OS-specific */

+

+/*

+ * DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the

+ * Dyn.d_un.d_val field of the Elf*_Dyn structure.

+ */

+#define DT_VALRNGLO     0x6ffffd00

+#define DT_CHECKSUM     0x6ffffdf8      /* elf checksum */

+#define DT_PLTPADSZ     0x6ffffdf9      /* pltpadding size */

+#define DT_MOVEENT      0x6ffffdfa      /* move table entry size */

+#define DT_MOVESZ       0x6ffffdfb      /* move table size */

+#define DT_FEATURE_1    0x6ffffdfc      /* feature holder */

+#define DT_POSFLAG_1    0x6ffffdfd      /* flags for DT_* entries, effecting */

+                                        /*      the following DT_* entry. */

+                                        /*      See DF_P1_* definitions */

+#define DT_SYMINSZ      0x6ffffdfe      /* syminfo table size (in bytes) */

+#define DT_SYMINENT     0x6ffffdff      /* syminfo entry size (in bytes) */

+#define DT_VALRNGHI     0x6ffffdff

+

+/*

+ * DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the

+ * Dyn.d_un.d_ptr field of the Elf*_Dyn structure.

+ *

+ * If any adjustment is made to the ELF object after it has been

+ * built, these entries will need to be adjusted.

+ */

+#define DT_ADDRRNGLO    0x6ffffe00

+#define DT_CONFIG       0x6ffffefa      /* configuration information */

+#define DT_DEPAUDIT     0x6ffffefb      /* dependency auditing */

+#define DT_AUDIT        0x6ffffefc      /* object auditing */

+#define DT_PLTPAD       0x6ffffefd      /* pltpadding (sparcv9) */

+#define DT_MOVETAB      0x6ffffefe      /* move table */

+#define DT_SYMINFO      0x6ffffeff      /* syminfo table */

+#define DT_ADDRRNGHI    0x6ffffeff

+

+#define DT_VERSYM       0x6ffffff0      /* Address of versym section. */

+#define DT_RELACOUNT    0x6ffffff9      /* number of RELATIVE relocations */

+#define DT_RELCOUNT     0x6ffffffa      /* number of RELATIVE relocations */

+#define DT_FLAGS_1      0x6ffffffb      /* state flags - see DF_1_* defs */

+#define DT_VERDEF       0x6ffffffc      /* Address of verdef section. */

+#define DT_VERDEFNUM    0x6ffffffd      /* Number of elems in verdef section */

+#define DT_VERNEED      0x6ffffffe      /* Address of verneed section. */

+#define DT_VERNEEDNUM   0x6fffffff      /* Number of elems in verneed section */

+

+#define DT_LOPROC       0x70000000      /* First processor-specific type. */

+#define DT_DEPRECATED_SPARC_REGISTER    0x7000001

+#define DT_AUXILIARY    0x7ffffffd      /* shared library auxiliary name */

+#define DT_USED         0x7ffffffe      /* ignored - same as needed */

+#define DT_FILTER       0x7fffffff      /* shared library filter name */

+#define DT_HIPROC       0x7fffffff      /* Last processor-specific type. */

+

+/* Values for DT_FLAGS */

+#define DF_ORIGIN       0x0001  /* Indicates that the object being loaded may

+                                   make reference to the $ORIGIN substitution

+                                   string */

+#define DF_SYMBOLIC     0x0002  /* Indicates "symbolic" linking. */

+#define DF_TEXTREL      0x0004  /* Indicates there may be relocations in

+                                   non-writable segments. */

+#define DF_BIND_NOW     0x0008  /* Indicates that the dynamic linker should

+                                   process all relocations for the object

+                                   containing this entry before transferring

+                                   control to the program. */

+#define DF_STATIC_TLS   0x0010  /* Indicates that the shared object or

+                                   executable contains code using a static

+                                   thread-local storage scheme. */

+

+/* Values for n_type.  Used in core files. */

+#define NT_PRSTATUS     1       /* Process status. */

+#define NT_FPREGSET     2       /* Floating point registers. */

+#define NT_PRPSINFO     3       /* Process state info. */

+

+/* Symbol Binding - ELFNN_ST_BIND - st_info */

+#define STB_LOCAL       0       /* Local symbol */

+#define STB_GLOBAL      1       /* Global symbol */

+#define STB_WEAK        2       /* like global - lower precedence */

+#define STB_LOOS        10      /* Reserved range for operating system */

+#define STB_HIOS        12      /*   specific semantics. */

+#define STB_LOPROC      13      /* reserved range for processor */

+#define STB_HIPROC      15      /*   specific semantics. */

+

+/* Symbol type - ELFNN_ST_TYPE - st_info */

+#define STT_NOTYPE      0       /* Unspecified type. */

+#define STT_OBJECT      1       /* Data object. */

+#define STT_FUNC        2       /* Function. */

+#define STT_SECTION     3       /* Section. */

+#define STT_FILE        4       /* Source file. */

+#define STT_COMMON      5       /* Uninitialized common block. */

+#define STT_TLS         6       /* TLS object. */

+#define STT_NUM         7

+#define STT_LOOS        10      /* Reserved range for operating system */

+#define STT_HIOS        12      /*   specific semantics. */

+#define STT_LOPROC      13      /* reserved range for processor */

+#define STT_HIPROC      15      /*   specific semantics. */

+

+/* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */

+#define STV_DEFAULT     0x0     /* Default visibility (see binding). */

+#define STV_INTERNAL    0x1     /* Special meaning in relocatable objects. */

+#define STV_HIDDEN      0x2     /* Not visible. */

+#define STV_PROTECTED   0x3     /* Visible but not preemptible. */

+

+/* Special symbol table indexes. */

+#define STN_UNDEF       0       /* Undefined symbol index. */

+

+/* Symbol versioning flags. */

+#define VER_DEF_CURRENT 1

+#define VER_DEF_IDX(x)  VER_NDX(x)

+

+#define VER_FLG_BASE    0x01

+#define VER_FLG_WEAK    0x02

+

+#define VER_NEED_CURRENT        1

+#define VER_NEED_WEAK   (1u << 15)

+#define VER_NEED_HIDDEN VER_NDX_HIDDEN

+#define VER_NEED_IDX(x) VER_NDX(x)

+

+#define VER_NDX_LOCAL   0

+#define VER_NDX_GLOBAL  1

+#define VER_NDX_GIVEN   2

+

+#define VER_NDX_HIDDEN  (1u << 15)

+#define VER_NDX(x)      ((x) & ~(1u << 15))

+

+#define CA_SUNW_NULL    0

+#define CA_SUNW_HW_1    1               /* first hardware capabilities entry */

+#define CA_SUNW_SF_1    2               /* first software capabilities entry */

+

+/*

+ * Syminfo flag values

+ */

+#define SYMINFO_FLG_DIRECT      0x0001  /* symbol ref has direct association */

+                                        /*      to object containing defn. */

+#define SYMINFO_FLG_PASSTHRU    0x0002  /* ignored - see SYMINFO_FLG_FILTER */

+#define SYMINFO_FLG_COPY        0x0004  /* symbol is a copy-reloc */

+#define SYMINFO_FLG_LAZYLOAD    0x0008  /* object containing defn should be */

+                                        /*      lazily-loaded */

+#define SYMINFO_FLG_DIRECTBIND  0x0010  /* ref should be bound directly to */

+                                        /*      object containing defn. */

+#define SYMINFO_FLG_NOEXTDIRECT 0x0020  /* don't let an external reference */

+                                        /*      directly bind to this symbol */

+#define SYMINFO_FLG_FILTER      0x0002  /* symbol ref is associated to a */

+#define SYMINFO_FLG_AUXILIARY   0x0040  /*      standard or auxiliary filter */

+

+/*

+ * Syminfo.si_boundto values.

+ */

+#define SYMINFO_BT_SELF         0xffff  /* symbol bound to self */

+#define SYMINFO_BT_PARENT       0xfffe  /* symbol bound to parent */

+#define SYMINFO_BT_NONE         0xfffd  /* no special symbol binding */

+#define SYMINFO_BT_EXTERN       0xfffc  /* symbol defined as external */

+#define SYMINFO_BT_LOWRESERVE   0xff00  /* beginning of reserved entries */

+

+/*

+ * Syminfo version values.

+ */

+#define SYMINFO_NONE            0       /* Syminfo version */

+#define SYMINFO_CURRENT         1

+#define SYMINFO_NUM             2

+

+/*

+ * Relocation types.

+ *

+ * All machine architectures are defined here to allow tools on one to

+ * handle others.

+ */

+

+#define R_386_NONE              0       /* No relocation. */

+#define R_386_32                1       /* Add symbol value. */

+#define R_386_PC32              2       /* Add PC-relative symbol value. */

+#define R_386_GOT32             3       /* Add PC-relative GOT offset. */

+#define R_386_PLT32             4       /* Add PC-relative PLT offset. */

+#define R_386_COPY              5       /* Copy data from shared object. */

+#define R_386_GLOB_DAT          6       /* Set GOT entry to data address. */

+#define R_386_JMP_SLOT          7       /* Set GOT entry to code address. */

+#define R_386_RELATIVE          8       /* Add load address of shared object. */

+#define R_386_GOTOFF            9       /* Add GOT-relative symbol address. */

+#define R_386_GOTPC             10      /* Add PC-relative GOT table address. */

+#define R_386_TLS_TPOFF         14      /* Negative offset in static TLS block */

+#define R_386_TLS_IE            15      /* Absolute address of GOT for -ve static TLS */

+#define R_386_TLS_GOTIE         16      /* GOT entry for negative static TLS block */

+#define R_386_TLS_LE            17      /* Negative offset relative to static TLS */

+#define R_386_TLS_GD            18      /* 32 bit offset to GOT (index,off) pair */

+#define R_386_TLS_LDM           19      /* 32 bit offset to GOT (index,zero) pair */

+#define R_386_TLS_GD_32         24      /* 32 bit offset to GOT (index,off) pair */

+#define R_386_TLS_GD_PUSH       25      /* pushl instruction for Sun ABI GD sequence */

+#define R_386_TLS_GD_CALL       26      /* call instruction for Sun ABI GD sequence */

+#define R_386_TLS_GD_POP        27      /* popl instruction for Sun ABI GD sequence */

+#define R_386_TLS_LDM_32        28      /* 32 bit offset to GOT (index,zero) pair */

+#define R_386_TLS_LDM_PUSH      29      /* pushl instruction for Sun ABI LD sequence */

+#define R_386_TLS_LDM_CALL      30      /* call instruction for Sun ABI LD sequence */

+#define R_386_TLS_LDM_POP       31      /* popl instruction for Sun ABI LD sequence */

+#define R_386_TLS_LDO_32        32      /* 32 bit offset from start of TLS block */

+#define R_386_TLS_IE_32         33      /* 32 bit offset to GOT static TLS offset entry */

+#define R_386_TLS_LE_32         34      /* 32 bit offset within static TLS block */

+#define R_386_TLS_DTPMOD32      35      /* GOT entry containing TLS index */

+#define R_386_TLS_DTPOFF32      36      /* GOT entry containing TLS offset */

+#define R_386_TLS_TPOFF32       37      /* GOT entry of -ve static TLS offset */

+

+/* Null relocation */

+#define R_AARCH64_NONE                          256     /* No relocation */

+/* Static AArch64 relocations */

+ /* Static data relocations */

+#define R_AARCH64_ABS64                         257     /* S + A */

+#define R_AARCH64_ABS32                         258     /* S + A */

+#define R_AARCH64_ABS16                         259     /* S + A */

+#define R_AARCH64_PREL64                        260     /* S + A - P */

+#define R_AARCH64_PREL32                        261     /* S + A - P */

+#define R_AARCH64_PREL16                        262     /* S + A - P */

+ /* Group relocations to create a 16, 32, 48, or 64 bit unsigned data value or address inline */

+#define R_AARCH64_MOVW_UABS_G0                  263     /* S + A */

+#define R_AARCH64_MOVW_UABS_G0_NC               264     /* S + A */

+#define R_AARCH64_MOVW_UABS_G1                  265     /* S + A */

+#define R_AARCH64_MOVW_UABS_G1_NC               266     /* S + A */

+#define R_AARCH64_MOVW_UABS_G2                  267     /* S + A */

+#define R_AARCH64_MOVW_UABS_G2_NC               268     /* S + A */

+#define R_AARCH64_MOVW_UABS_G3                  269     /* S + A */

+ /* Group relocations to create a 16, 32, 48, or 64 bit signed data or offset value inline */

+#define R_AARCH64_MOVW_SABS_G0                  270     /* S + A */

+#define R_AARCH64_MOVW_SABS_G1                  271     /* S + A */

+#define R_AARCH64_MOVW_SABS_G2                  272     /* S + A */

+ /* Relocations to generate 19, 21 and 33 bit PC-relative addresses */

+#define R_AARCH64_LD_PREL_LO19                  273     /* S + A - P */

+#define R_AARCH64_ADR_PREL_LO21                 274     /* S + A - P */

+#define R_AARCH64_ADR_PREL_PG_HI21              275     /* Page(S+A) - Page(P) */

+#define R_AARCH64_ADR_PREL_PG_HI21_NC           276     /* Page(S+A) - Page(P) */

+#define R_AARCH64_ADD_ABS_LO12_NC               277     /* S + A */

+#define R_AARCH64_LDST8_ABS_LO12_NC             278     /* S + A */

+#define R_AARCH64_LDST16_ABS_LO12_NC            284     /* S + A */

+#define R_AARCH64_LDST32_ABS_LO12_NC            285     /* S + A */

+#define R_AARCH64_LDST64_ABS_LO12_NC            286     /* S + A */

+#define R_AARCH64_LDST128_ABS_LO12_NC           299     /* S + A */

+ /* Relocations for control-flow instructions - all offsets are a multiple of 4 */

+#define R_AARCH64_TSTBR14                       279     /* S+A-P */

+#define R_AARCH64_CONDBR19                      280     /* S+A-P */

+#define R_AARCH64_JUMP26                        282     /* S+A-P */

+#define R_AARCH64_CALL26                        283     /* S+A-P */

+ /* Group relocations to create a 16, 32, 48, or 64 bit PC-relative offset inline */

+#define R_AARCH64_MOVW_PREL_G0                  287     /* S+A-P */

+#define R_AARCH64_MOVW_PREL_G0_NC               288     /* S+A-P */

+#define R_AARCH64_MOVW_PREL_G1                  289     /* S+A-P */

+#define R_AARCH64_MOVW_PREL_G1_NC               290     /* S+A-P */

+#define R_AARCH64_MOVW_PREL_G2                  291     /* S+A-P */

+#define R_AARCH64_MOVW_PREL_G2_NC               292     /* S+A-P */

+#define R_AARCH64_MOVW_PREL_G3                  293     /* S+A-P */

+ /* Group relocations to create a 16, 32, 48, or 64 bit GOT-relative offsets inline */

+#define R_AARCH64_MOVW_GOTOFF_G0                300     /* G(S)-GOT */

+#define R_AARCH64_MOVW_GOTOFF_G0_NC             301     /* G(S)-GOT */

+#define R_AARCH64_MOVW_GOTOFF_G1                302     /* G(S)-GOT */

+#define R_AARCH64_MOVW_GOTOFF_G1_NC             303     /* G(S)-GOT */

+#define R_AARCH64_MOVW_GOTOFF_G2                304     /* G(S)-GOT */

+#define R_AARCH64_MOVW_GOTOFF_G2_NC             305     /* G(S)-GOT */

+#define R_AARCH64_MOVW_GOTOFF_G3                306     /* G(S)-GOT */

+ /*  GOT-relative data relocations */

+#define R_AARCH64_GOTREL64                      307     /* S+A-GOT */

+#define R_AARCH64_GOTREL32                      308     /* S+A-GOT */

+ /* GOT-relative instruction relocations */

+#define R_AARCH64_GOT_LD_PREL19                 309     /* G(S)-P */

+#define R_AARCH64_LD64_GOTOFF_LO15              310     /* G(S)-GOT */

+#define R_AARCH64_ADR_GOT_PAGE                  311     /* Page(G(S))-Page(P) */

+#define R_AARCH64_LD64_GOT_LO12_NC              312     /* G(S) */

+#define R_AARCH64_LD64_GOTPAGE_LO15             313     /* G(S)-Page(GOT) */

+/* Relocations for thread-local storage */

+ /* General Dynamic TLS relocations */

+#define R_AARCH64_TLSGD_ADR_PREL21              512     /* G(TLSIDX(S+A)) - P */

+#define R_AARCH64_TLSGD_ADR_PAGE21              513     /* Page(G(TLSIDX(S+A))) - Page(P) */

+#define R_AARCH64_TLSGD_ADD_LO12_NC             514     /* G(TLSIDX(S+A)) */

+#define R_AARCH64_TLSGD_MOVW_G1                 515     /* G(TLSIDX(S+A)) - GOT */

+#define R_AARCH64_TLSGD_MOVW_G0_NC              516     /* G(TLSIDX(S+A)) - GOT */

+ /* Local Dynamic TLS relocations */

+#define R_AARCH64_TLSLD_ADR_PREL21              517     /* G(LDM(S))) - P */

+#define R_AARCH64_TLSLD_ADR_PAGE21              518     /* Page(G(LDM(S)))-Page(P) */

+#define R_AARCH64_TLSLD_ADD_LO12_NC             519     /* G(LDM(S)) */

+#define R_AARCH64_TLSLD_MOVW_G1                 520     /* G(LDM(S)) - GOT */

+#define R_AARCH64_TLSLD_MOVW_G0_NC              521     /* G(LDM(S)) - GOT */

+#define R_AARCH64_TLSLD_LD_PREL19               522     /* G(LDM(S)) - P */

+#define R_AARCH64_TLSLD_MOVW_DTPREL_G2          523     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_MOVW_DTPREL_G1          524     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC       525     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_MOVW_DTPREL_G0          526     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC       527     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_ADD_DTPREL_HI12         528     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_ADD_DTPREL_LO12         529     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC      530     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12       531     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC    532     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12      533     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC   534     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12      535     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC   536     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12      537     /* DTPREL(S+A) */

+#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC   538     /* DTPREL(S+A) */

+ /* Initial Exec TLS relocations */

+#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1        539     /* G(TPREL(S+A)) - GOT */

+#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC     540     /* G(TPREL(S+A)) - GOT */

+#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21     541     /* Page(G(TPREL(S+A))) - Page(P) */

+#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC   542     /* G(TPREL(S+A)) */

+#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19      543     /* G(TPREL(S+A)) - P */

+ /* Local Exec TLS relocations */

+#define R_AARCH64_TLSLE_MOVW_TPREL_G2           544     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_MOVW_TPREL_G1           545     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC        546     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_MOVW_TPREL_G0           547     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC        548     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_ADD_TPREL_HI12          549     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_ADD_TPREL_LO12          550     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC       551     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST8_TPREL_LO12        552     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC     553     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST16_TPREL_LO12       554     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC    555     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST32_TPREL_LO12       556     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC    557     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST64_TPREL_LO12       558     /* TPREL(S+A) */

+#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC    559     /* TPREL(S+A) */

+/* Dynamic relocations */

+ /* Dynamic relocations */

+#define R_AARCH64_COPY                          1024

+#define R_AARCH64_GLOB_DAT                      1025    /* S + A */

+#define R_AARCH64_JUMP_SLOT                     1026    /* S + A */

+#define R_AARCH64_RELATIVE                      1027    /* Delta(S) + A , Delta(P) + A */

+#define R_AARCH64_TLS_DTPREL64                  1028    /* DTPREL(S+A) */

+#define R_AARCH64_TLS_DTPMOD64                  1029    /* LDM(S) */

+#define R_AARCH64_TLS_TPREL64                   1030    /* TPREL(S+A) */

+#define R_AARCH64_TLS_DTPREL32                  1031    /* DTPREL(S+A) */

+#define R_AARCH64_TLS_DTPMOD32                  1032    /* LDM(S) */

+#define R_AARCH64_TLS_TPREL32                   1033    /* DTPREL(S+A) */

+

+#define R_ALPHA_NONE            0       /* No reloc */

+#define R_ALPHA_REFLONG         1       /* Direct 32 bit */

+#define R_ALPHA_REFQUAD         2       /* Direct 64 bit */

+#define R_ALPHA_GPREL32         3       /* GP relative 32 bit */

+#define R_ALPHA_LITERAL         4       /* GP relative 16 bit w/optimization */

+#define R_ALPHA_LITUSE          5       /* Optimization hint for LITERAL */

+#define R_ALPHA_GPDISP          6       /* Add displacement to GP */

+#define R_ALPHA_BRADDR          7       /* PC+4 relative 23 bit shifted */

+#define R_ALPHA_HINT            8       /* PC+4 relative 16 bit shifted */

+#define R_ALPHA_SREL16          9       /* PC relative 16 bit */

+#define R_ALPHA_SREL32          10      /* PC relative 32 bit */

+#define R_ALPHA_SREL64          11      /* PC relative 64 bit */

+#define R_ALPHA_OP_PUSH         12      /* OP stack push */

+#define R_ALPHA_OP_STORE        13      /* OP stack pop and store */

+#define R_ALPHA_OP_PSUB         14      /* OP stack subtract */

+#define R_ALPHA_OP_PRSHIFT      15      /* OP stack right shift */

+#define R_ALPHA_GPVALUE         16

+#define R_ALPHA_GPRELHIGH       17

+#define R_ALPHA_GPRELLOW        18

+#define R_ALPHA_IMMED_GP_16     19

+#define R_ALPHA_IMMED_GP_HI32   20

+#define R_ALPHA_IMMED_SCN_HI32  21

+#define R_ALPHA_IMMED_BR_HI32   22

+#define R_ALPHA_IMMED_LO32      23

+#define R_ALPHA_COPY            24      /* Copy symbol at runtime */

+#define R_ALPHA_GLOB_DAT        25      /* Create GOT entry */

+#define R_ALPHA_JMP_SLOT        26      /* Create PLT entry */

+#define R_ALPHA_RELATIVE        27      /* Adjust by program base */

+

+#define R_ARM_NONE              0       /* No relocation. */

+#define R_ARM_PC24              1

+#define R_ARM_ABS32             2

+#define R_ARM_REL32             3

+#define R_ARM_PC13              4

+#define R_ARM_ABS16             5

+#define R_ARM_ABS12             6

+#define R_ARM_THM_ABS5          7

+#define R_ARM_ABS8              8

+#define R_ARM_SBREL32           9

+#define R_ARM_THM_PC22          10

+#define R_ARM_THM_PC8           11

+#define R_ARM_AMP_VCALL9        12

+#define R_ARM_SWI24             13

+#define R_ARM_THM_SWI8          14

+#define R_ARM_XPC25             15

+#define R_ARM_THM_XPC22         16

+#define R_ARM_COPY              20      /* Copy data from shared object. */

+#define R_ARM_GLOB_DAT          21      /* Set GOT entry to data address. */

+#define R_ARM_JUMP_SLOT         22      /* Set GOT entry to code address. */

+#define R_ARM_RELATIVE          23      /* Add load address of shared object. */

+#define R_ARM_GOTOFF            24      /* Add GOT-relative symbol address. */

+#define R_ARM_GOTPC             25      /* Add PC-relative GOT table address. */

+#define R_ARM_GOT32             26      /* Add PC-relative GOT offset. */

+#define R_ARM_PLT32             27      /* Add PC-relative PLT offset. */

+#define R_ARM_CALL              28

+#define R_ARM_JMP24             29

+#define R_ARM_MOVW_ABS_NC       43

+#define R_ARM_MOVT_ABS          44

+#define R_ARM_THM_MOVW_ABS_NC   47

+#define R_ARM_THM_MOVT_ABS      48

+

+// Block of PC-relative relocations added to work around gcc putting

+// object relocations in static executables.

+#define R_ARM_THM_JUMP24        30

+#define R_ARM_PREL31            42

+#define R_ARM_MOVW_PREL_NC      45

+#define R_ARM_MOVT_PREL         46

+#define R_ARM_THM_MOVW_PREL_NC  49

+#define R_ARM_THM_MOVT_PREL     50

+#define R_ARM_THM_JMP6          52

+#define R_ARM_THM_ALU_PREL_11_0 53

+#define R_ARM_THM_PC12          54

+#define R_ARM_REL32_NOI         56

+#define R_ARM_ALU_PC_G0_NC      57

+#define R_ARM_ALU_PC_G0         58

+#define R_ARM_ALU_PC_G1_NC      59

+#define R_ARM_ALU_PC_G1         60

+#define R_ARM_ALU_PC_G2         61

+#define R_ARM_LDR_PC_G1         62

+#define R_ARM_LDR_PC_G2         63

+#define R_ARM_LDRS_PC_G0        64

+#define R_ARM_LDRS_PC_G1        65

+#define R_ARM_LDRS_PC_G2        66

+#define R_ARM_LDC_PC_G0         67

+#define R_ARM_LDC_PC_G1         68

+#define R_ARM_LDC_PC_G2         69

+#define R_ARM_GOT_PREL          96

+#define R_ARM_THM_JUMP11        102

+#define R_ARM_THM_JUMP8         103

+#define R_ARM_TLS_GD32          104

+#define R_ARM_TLS_LDM32         105

+#define R_ARM_TLS_IE32          107

+

+#define R_ARM_THM_JUMP19        51

+#define R_ARM_GNU_VTENTRY       100

+#define R_ARM_GNU_VTINHERIT     101

+#define R_ARM_RSBREL32          250

+#define R_ARM_THM_RPC22         251

+#define R_ARM_RREL32            252

+#define R_ARM_RABS32            253

+#define R_ARM_RPC24             254

+#define R_ARM_RBASE             255

+

+

+

+/*      Name                    Value      Field        Calculation */

+#define R_IA_64_NONE            0       /* None */

+#define R_IA_64_IMM14           0x21    /* immediate14  S + A */

+#define R_IA_64_IMM22           0x22    /* immediate22  S + A */

+#define R_IA_64_IMM64           0x23    /* immediate64  S + A */

+#define R_IA_64_DIR32MSB        0x24    /* word32 MSB   S + A */

+#define R_IA_64_DIR32LSB        0x25    /* word32 LSB   S + A */

+#define R_IA_64_DIR64MSB        0x26    /* word64 MSB   S + A */

+#define R_IA_64_DIR64LSB        0x27    /* word64 LSB   S + A */

+#define R_IA_64_GPREL22         0x2a    /* immediate22  @gprel(S + A) */

+#define R_IA_64_GPREL64I        0x2b    /* immediate64  @gprel(S + A) */

+#define R_IA_64_GPREL32MSB      0x2c    /* word32 MSB   @gprel(S + A) */

+#define R_IA_64_GPREL32LSB      0x2d    /* word32 LSB   @gprel(S + A) */

+#define R_IA_64_GPREL64MSB      0x2e    /* word64 MSB   @gprel(S + A) */

+#define R_IA_64_GPREL64LSB      0x2f    /* word64 LSB   @gprel(S + A) */

+#define R_IA_64_LTOFF22         0x32    /* immediate22  @ltoff(S + A) */

+#define R_IA_64_LTOFF64I        0x33    /* immediate64  @ltoff(S + A) */

+#define R_IA_64_PLTOFF22        0x3a    /* immediate22  @pltoff(S + A) */

+#define R_IA_64_PLTOFF64I       0x3b    /* immediate64  @pltoff(S + A) */

+#define R_IA_64_PLTOFF64MSB     0x3e    /* word64 MSB   @pltoff(S + A) */

+#define R_IA_64_PLTOFF64LSB     0x3f    /* word64 LSB   @pltoff(S + A) */

+#define R_IA_64_FPTR64I         0x43    /* immediate64  @fptr(S + A) */

+#define R_IA_64_FPTR32MSB       0x44    /* word32 MSB   @fptr(S + A) */

+#define R_IA_64_FPTR32LSB       0x45    /* word32 LSB   @fptr(S + A) */

+#define R_IA_64_FPTR64MSB       0x46    /* word64 MSB   @fptr(S + A) */

+#define R_IA_64_FPTR64LSB       0x47    /* word64 LSB   @fptr(S + A) */

+#define R_IA_64_PCREL60B        0x48    /* immediate60 form1 S + A - P */

+#define R_IA_64_PCREL21B        0x49    /* immediate21 form1 S + A - P */

+#define R_IA_64_PCREL21M        0x4a    /* immediate21 form2 S + A - P */

+#define R_IA_64_PCREL21F        0x4b    /* immediate21 form3 S + A - P */

+#define R_IA_64_PCREL32MSB      0x4c    /* word32 MSB   S + A - P */

+#define R_IA_64_PCREL32LSB      0x4d    /* word32 LSB   S + A - P */

+#define R_IA_64_PCREL64MSB      0x4e    /* word64 MSB   S + A - P */

+#define R_IA_64_PCREL64LSB      0x4f    /* word64 LSB   S + A - P */

+#define R_IA_64_LTOFF_FPTR22    0x52    /* immediate22  @ltoff(@fptr(S + A)) */

+#define R_IA_64_LTOFF_FPTR64I   0x53    /* immediate64  @ltoff(@fptr(S + A)) */

+#define R_IA_64_LTOFF_FPTR32MSB 0x54    /* word32 MSB   @ltoff(@fptr(S + A)) */

+#define R_IA_64_LTOFF_FPTR32LSB 0x55    /* word32 LSB   @ltoff(@fptr(S + A)) */

+#define R_IA_64_LTOFF_FPTR64MSB 0x56    /* word64 MSB   @ltoff(@fptr(S + A)) */

+#define R_IA_64_LTOFF_FPTR64LSB 0x57    /* word64 LSB   @ltoff(@fptr(S + A)) */

+#define R_IA_64_SEGREL32MSB     0x5c    /* word32 MSB   @segrel(S + A) */

+#define R_IA_64_SEGREL32LSB     0x5d    /* word32 LSB   @segrel(S + A) */

+#define R_IA_64_SEGREL64MSB     0x5e    /* word64 MSB   @segrel(S + A) */

+#define R_IA_64_SEGREL64LSB     0x5f    /* word64 LSB   @segrel(S + A) */

+#define R_IA_64_SECREL32MSB     0x64    /* word32 MSB   @secrel(S + A) */

+#define R_IA_64_SECREL32LSB     0x65    /* word32 LSB   @secrel(S + A) */

+#define R_IA_64_SECREL64MSB     0x66    /* word64 MSB   @secrel(S + A) */

+#define R_IA_64_SECREL64LSB     0x67    /* word64 LSB   @secrel(S + A) */

+#define R_IA_64_REL32MSB        0x6c    /* word32 MSB   BD + A */

+#define R_IA_64_REL32LSB        0x6d    /* word32 LSB   BD + A */

+#define R_IA_64_REL64MSB        0x6e    /* word64 MSB   BD + A */

+#define R_IA_64_REL64LSB        0x6f    /* word64 LSB   BD + A */

+#define R_IA_64_LTV32MSB        0x74    /* word32 MSB   S + A */

+#define R_IA_64_LTV32LSB        0x75    /* word32 LSB   S + A */

+#define R_IA_64_LTV64MSB        0x76    /* word64 MSB   S + A */

+#define R_IA_64_LTV64LSB        0x77    /* word64 LSB   S + A */

+#define R_IA_64_PCREL21BI       0x79    /* immediate21 form1 S + A - P */

+#define R_IA_64_PCREL22         0x7a    /* immediate22  S + A - P */

+#define R_IA_64_PCREL64I        0x7b    /* immediate64  S + A - P */

+#define R_IA_64_IPLTMSB         0x80    /* function descriptor MSB special */

+#define R_IA_64_IPLTLSB         0x81    /* function descriptor LSB speciaal */

+#define R_IA_64_SUB             0x85    /* immediate64  A - S */

+#define R_IA_64_LTOFF22X        0x86    /* immediate22  special */

+#define R_IA_64_LDXMOV          0x87    /* immediate22  special */

+#define R_IA_64_TPREL14         0x91    /* imm14        @tprel(S + A) */

+#define R_IA_64_TPREL22         0x92    /* imm22        @tprel(S + A) */

+#define R_IA_64_TPREL64I        0x93    /* imm64        @tprel(S + A) */

+#define R_IA_64_TPREL64MSB      0x96    /* word64 MSB   @tprel(S + A) */

+#define R_IA_64_TPREL64LSB      0x97    /* word64 LSB   @tprel(S + A) */

+#define R_IA_64_LTOFF_TPREL22   0x9a    /* imm22        @ltoff(@tprel(S+A)) */

+#define R_IA_64_DTPMOD64MSB     0xa6    /* word64 MSB   @dtpmod(S + A) */

+#define R_IA_64_DTPMOD64LSB     0xa7    /* word64 LSB   @dtpmod(S + A) */

+#define R_IA_64_LTOFF_DTPMOD22  0xaa    /* imm22        @ltoff(@dtpmod(S+A)) */

+#define R_IA_64_DTPREL14        0xb1    /* imm14        @dtprel(S + A) */

+#define R_IA_64_DTPREL22        0xb2    /* imm22        @dtprel(S + A) */

+#define R_IA_64_DTPREL64I       0xb3    /* imm64        @dtprel(S + A) */

+#define R_IA_64_DTPREL32MSB     0xb4    /* word32 MSB   @dtprel(S + A) */

+#define R_IA_64_DTPREL32LSB     0xb5    /* word32 LSB   @dtprel(S + A) */

+#define R_IA_64_DTPREL64MSB     0xb6    /* word64 MSB   @dtprel(S + A) */

+#define R_IA_64_DTPREL64LSB     0xb7    /* word64 LSB   @dtprel(S + A) */

+#define R_IA_64_LTOFF_DTPREL22  0xba    /* imm22        @ltoff(@dtprel(S+A)) */

+

+#define R_PPC_NONE              0       /* No relocation. */

+#define R_PPC_ADDR32            1

+#define R_PPC_ADDR24            2

+#define R_PPC_ADDR16            3

+#define R_PPC_ADDR16_LO         4

+#define R_PPC_ADDR16_HI         5

+#define R_PPC_ADDR16_HA         6

+#define R_PPC_ADDR14            7

+#define R_PPC_ADDR14_BRTAKEN    8

+#define R_PPC_ADDR14_BRNTAKEN   9

+#define R_PPC_REL24             10

+#define R_PPC_REL14             11

+#define R_PPC_REL14_BRTAKEN     12

+#define R_PPC_REL14_BRNTAKEN    13

+#define R_PPC_GOT16             14

+#define R_PPC_GOT16_LO          15

+#define R_PPC_GOT16_HI          16

+#define R_PPC_GOT16_HA          17

+#define R_PPC_PLTREL24          18

+#define R_PPC_COPY              19

+#define R_PPC_GLOB_DAT          20

+#define R_PPC_JMP_SLOT          21

+#define R_PPC_RELATIVE          22

+#define R_PPC_LOCAL24PC         23

+#define R_PPC_UADDR32           24

+#define R_PPC_UADDR16           25

+#define R_PPC_REL32             26

+#define R_PPC_PLT32             27

+#define R_PPC_PLTREL32          28

+#define R_PPC_PLT16_LO          29

+#define R_PPC_PLT16_HI          30

+#define R_PPC_PLT16_HA          31

+#define R_PPC_SDAREL16          32

+#define R_PPC_SECTOFF           33

+#define R_PPC_SECTOFF_LO        34

+#define R_PPC_SECTOFF_HI        35

+#define R_PPC_SECTOFF_HA        36

+

+/*

+ * TLS relocations

+ */

+#define R_PPC_TLS               67

+#define R_PPC_DTPMOD32          68

+#define R_PPC_TPREL16           69

+#define R_PPC_TPREL16_LO        70

+#define R_PPC_TPREL16_HI        71

+#define R_PPC_TPREL16_HA        72

+#define R_PPC_TPREL32           73

+#define R_PPC_DTPREL16          74

+#define R_PPC_DTPREL16_LO       75

+#define R_PPC_DTPREL16_HI       76

+#define R_PPC_DTPREL16_HA       77

+#define R_PPC_DTPREL32          78

+#define R_PPC_GOT_TLSGD16       79

+#define R_PPC_GOT_TLSGD16_LO    80

+#define R_PPC_GOT_TLSGD16_HI    81

+#define R_PPC_GOT_TLSGD16_HA    82

+#define R_PPC_GOT_TLSLD16       83

+#define R_PPC_GOT_TLSLD16_LO    84

+#define R_PPC_GOT_TLSLD16_HI    85

+#define R_PPC_GOT_TLSLD16_HA    86

+#define R_PPC_GOT_TPREL16       87

+#define R_PPC_GOT_TPREL16_LO    88

+#define R_PPC_GOT_TPREL16_HI    89

+#define R_PPC_GOT_TPREL16_HA    90

+

+/*

+ * The remaining relocs are from the Embedded ELF ABI, and are not in the

+ *  SVR4 ELF ABI.

+ */

+

+#define R_PPC_EMB_NADDR32       101

+#define R_PPC_EMB_NADDR16       102

+#define R_PPC_EMB_NADDR16_LO    103

+#define R_PPC_EMB_NADDR16_HI    104

+#define R_PPC_EMB_NADDR16_HA    105

+#define R_PPC_EMB_SDAI16        106

+#define R_PPC_EMB_SDA2I16       107

+#define R_PPC_EMB_SDA2REL       108

+#define R_PPC_EMB_SDA21         109

+#define R_PPC_EMB_MRKREF        110

+#define R_PPC_EMB_RELSEC16      111

+#define R_PPC_EMB_RELST_LO      112

+#define R_PPC_EMB_RELST_HI      113

+#define R_PPC_EMB_RELST_HA      114

+#define R_PPC_EMB_BIT_FLD       115

+#define R_PPC_EMB_RELSDA        116

+

+#define R_SPARC_NONE            0

+#define R_SPARC_8               1

+#define R_SPARC_16              2

+#define R_SPARC_32              3

+#define R_SPARC_DISP8           4

+#define R_SPARC_DISP16          5

+#define R_SPARC_DISP32          6

+#define R_SPARC_WDISP30         7

+#define R_SPARC_WDISP22         8

+#define R_SPARC_HI22            9

+#define R_SPARC_22              10

+#define R_SPARC_13              11

+#define R_SPARC_LO10            12

+#define R_SPARC_GOT10           13

+#define R_SPARC_GOT13           14

+#define R_SPARC_GOT22           15

+#define R_SPARC_PC10            16

+#define R_SPARC_PC22            17

+#define R_SPARC_WPLT30          18

+#define R_SPARC_COPY            19

+#define R_SPARC_GLOB_DAT        20

+#define R_SPARC_JMP_SLOT        21

+#define R_SPARC_RELATIVE        22

+#define R_SPARC_UA32            23

+#define R_SPARC_PLT32           24

+#define R_SPARC_HIPLT22         25

+#define R_SPARC_LOPLT10         26

+#define R_SPARC_PCPLT32         27

+#define R_SPARC_PCPLT22         28

+#define R_SPARC_PCPLT10         29

+#define R_SPARC_10              30

+#define R_SPARC_11              31

+#define R_SPARC_64              32

+#define R_SPARC_OLO10           33

+#define R_SPARC_HH22            34

+#define R_SPARC_HM10            35

+#define R_SPARC_LM22            36

+#define R_SPARC_PC_HH22         37

+#define R_SPARC_PC_HM10         38

+#define R_SPARC_PC_LM22         39

+#define R_SPARC_WDISP16         40

+#define R_SPARC_WDISP19         41

+#define R_SPARC_GLOB_JMP        42

+#define R_SPARC_7               43

+#define R_SPARC_5               44

+#define R_SPARC_6               45

+#define R_SPARC_DISP64          46

+#define R_SPARC_PLT64           47

+#define R_SPARC_HIX22           48

+#define R_SPARC_LOX10           49

+#define R_SPARC_H44             50

+#define R_SPARC_M44             51

+#define R_SPARC_L44             52

+#define R_SPARC_REGISTER        53

+#define R_SPARC_UA64            54

+#define R_SPARC_UA16            55

+#define R_SPARC_TLS_GD_HI22     56

+#define R_SPARC_TLS_GD_LO10     57

+#define R_SPARC_TLS_GD_ADD      58

+#define R_SPARC_TLS_GD_CALL     59

+#define R_SPARC_TLS_LDM_HI22    60

+#define R_SPARC_TLS_LDM_LO10    61

+#define R_SPARC_TLS_LDM_ADD     62

+#define R_SPARC_TLS_LDM_CALL    63

+#define R_SPARC_TLS_LDO_HIX22   64

+#define R_SPARC_TLS_LDO_LOX10   65

+#define R_SPARC_TLS_LDO_ADD     66

+#define R_SPARC_TLS_IE_HI22     67

+#define R_SPARC_TLS_IE_LO10     68

+#define R_SPARC_TLS_IE_LD       69

+#define R_SPARC_TLS_IE_LDX      70

+#define R_SPARC_TLS_IE_ADD      71

+#define R_SPARC_TLS_LE_HIX22    72

+#define R_SPARC_TLS_LE_LOX10    73

+#define R_SPARC_TLS_DTPMOD32    74

+#define R_SPARC_TLS_DTPMOD64    75

+#define R_SPARC_TLS_DTPOFF32    76

+#define R_SPARC_TLS_DTPOFF64    77

+#define R_SPARC_TLS_TPOFF32     78

+#define R_SPARC_TLS_TPOFF64     79

+

+#define R_X86_64_NONE           0       /* No relocation. */

+#define R_X86_64_64             1       /* Add 64 bit symbol value. */

+#define R_X86_64_PC32           2       /* PC-relative 32 bit signed sym value. */

+#define R_X86_64_GOT32          3       /* PC-relative 32 bit GOT offset. */

+#define R_X86_64_PLT32          4       /* PC-relative 32 bit PLT offset. */

+#define R_X86_64_COPY           5       /* Copy data from shared object. */

+#define R_X86_64_GLOB_DAT       6       /* Set GOT entry to data address. */

+#define R_X86_64_JMP_SLOT       7       /* Set GOT entry to code address. */

+#define R_X86_64_RELATIVE       8       /* Add load address of shared object. */

+#define R_X86_64_GOTPCREL       9       /* Add 32 bit signed pcrel offset to GOT. */

+#define R_X86_64_32             10      /* Add 32 bit zero extended symbol value */

+#define R_X86_64_32S            11      /* Add 32 bit sign extended symbol value */

+#define R_X86_64_16             12      /* Add 16 bit zero extended symbol value */

+#define R_X86_64_PC16           13      /* Add 16 bit signed extended pc relative symbol value */

+#define R_X86_64_8              14      /* Add 8 bit zero extended symbol value */

+#define R_X86_64_PC8            15      /* Add 8 bit signed extended pc relative symbol value */

+#define R_X86_64_DTPMOD64       16      /* ID of module containing symbol */

+#define R_X86_64_DTPOFF64       17      /* Offset in TLS block */

+#define R_X86_64_TPOFF64        18      /* Offset in static TLS block */

+#define R_X86_64_TLSGD          19      /* PC relative offset to GD GOT entry */

+#define R_X86_64_TLSLD          20      /* PC relative offset to LD GOT entry */

+#define R_X86_64_DTPOFF32       21      /* Offset in TLS block */

+#define R_X86_64_GOTTPOFF       22      /* PC relative offset to IE GOT entry */

+#define R_X86_64_TPOFF32        23      /* Offset in static TLS block */

+

+

+#endif /* !_SYS_ELF_COMMON_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/AArch64/ArmTrustedMonitorLibNull.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/AArch64/ArmTrustedMonitorLibNull.c
new file mode 100644
index 0000000..72c62d7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/AArch64/ArmTrustedMonitorLibNull.c
@@ -0,0 +1,24 @@
+/** @file

+*  Main file supporting the Monitor World on ARM PLatforms

+*

+*  Copyright (c) 2012-2013, ARM 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.

+*

+**/

+

+VOID

+ArmSecureMonitorWorldInitialize (

+  VOID

+  )

+{

+  // Do not touch the EL3 Exception Vector Table Register.

+  // The default default DebugAgentLib could have already set its own vector

+  // into EL3 to catch abort exceptions.

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/ArmTrustedMonitorLibNull.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/ArmTrustedMonitorLibNull.c
new file mode 100644
index 0000000..1f950d7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/ArmTrustedMonitorLibNull.c
@@ -0,0 +1,38 @@
+/** @file

+*  Main file supporting the Monitor World on ARM PLatforms

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include <Library/ArmLib.h>

+#include <Library/ArmTrustedMonitorLib.h>

+#include <Library/DebugLib.h>

+

+#define IS_ALIGNED(Address, Align) (((UINTN)Address & (Align-1)) == 0)

+

+VOID

+MonitorVectorTable (

+  VOID

+  );

+

+VOID

+ArmSecureMonitorWorldInitialize (

+  VOID

+  )

+{

+  // Ensure the Monitor Table is 32bit aligned

+  ASSERT (((UINTN)&MonitorVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0);

+

+  // Write the Monitor Mode Vector Table Address

+  ArmWriteMVBar ((UINTN) &MonitorVectorTable);

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/MonitorTable.S b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/MonitorTable.S
new file mode 100644
index 0000000..3e75bee
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/MonitorTable.S
@@ -0,0 +1,41 @@
+//

+//  Copyright (c) 2011, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <AutoGen.h>

+#include <Library/PcdLib.h>

+

+.text

+.align 5

+

+GCC_ASM_EXPORT(MonitorVectorTable)

+

+ASM_PFX(MonitorVectorTable):

+

+_MonitorResetEntry:

+  b   _MonitorResetEntry

+_MonitorUndefinedEntry:

+  b   _MonitorUndefinedEntry

+_MonitorSmcEntry:

+  b   _MonitorSmcEntry

+_MonitorPrefetchEntry:

+  b   _MonitorPrefetchEntry

+_MonitorDataAbortEntry:

+  b   _MonitorDataAbortEntry

+_MonitorReservedEntry:

+  b   _MonitorReservedEntry

+_MonitorIrqEntry:

+  b   _MonitorIrqEntry

+_MonitorFiqEntry:

+  b   _MonitorFiqEntry

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/MonitorTable.asm b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/MonitorTable.asm
new file mode 100644
index 0000000..f4f515d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/Arm/MonitorTable.asm
@@ -0,0 +1,40 @@
+//

+//  Copyright (c) 2011, ARM 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.

+//

+//

+

+#include <Library/PcdLib.h>

+

+    EXPORT  MonitorVectorTable

+

+    PRESERVE8

+    AREA    MonitoVectorTableArea, CODE, READONLY, CODEALIGN, ALIGN=5

+

+MonitorVectorTable

+

+_MonitorResetEntry

+  b   _MonitorResetEntry

+_MonitorUndefinedEntry

+  b   _MonitorUndefinedEntry

+_MonitorSmcEntry

+  b   _MonitorSmcEntry

+_MonitorPrefetchEntry

+  b   _MonitorPrefetchEntry

+_MonitorDataAbortEntry

+  b   _MonitorDataAbortEntry

+_MonitorReservedEntry

+  b   _MonitorReservedEntry

+_MonitorIrqEntry

+  b   _MonitorIrqEntry

+_MonitorFiqEntry

+  b   _MonitorFiqEntry

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf
new file mode 100644
index 0000000..505d2ec
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf
@@ -0,0 +1,40 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmTrustedMonitorLibNull

+  FILE_GUID                      = c4b50eb2-ed16-4283-a5b0-a7341c3f997b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmTrustedMonitorLib

+

+[Sources.ARM]

+  Arm/ArmTrustedMonitorLibNull.c

+  Arm/MonitorTable.asm     | RVCT

+  Arm/MonitorTable.S       | GCC

+

+[Sources.AARCH64]

+  AArch64/ArmTrustedMonitorLibNull.c

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

+

+[LibraryClasses]

+  ArmLib

+  BaseLib

+  DebugLib

+  PcdLib

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.c
new file mode 100755
index 0000000..a452e38
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.c
@@ -0,0 +1,121 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <PiPei.h>

+

+#include <Library/ArmLib.h>

+#include <Library/ArmGicLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/ArmPlatformSecLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+#include <Library/PrintLib.h>

+#include <Library/SerialPortLib.h>

+

+// When the firmware is built as not Standalone, the secondary cores need to wait the firmware

+// entirely written into DRAM. It is the firmware from DRAM which will wake up the secondary cores.

+VOID

+NonSecureWaitForFirmware (

+  VOID

+  )

+{

+  VOID (*SecondaryStart)(VOID);

+  UINTN AcknowledgeInterrupt;

+  UINTN InterruptId;

+

+  // The secondary cores will execute the firmware once wake from WFI.

+  SecondaryStart = (VOID (*)())(UINTN)PcdGet64 (PcdFvBaseAddress);

+

+  ArmCallWFI ();

+

+  // Acknowledge the interrupt and send End of Interrupt signal.

+  AcknowledgeInterrupt = ArmGicAcknowledgeInterrupt (PcdGet32 (PcdGicInterruptInterfaceBase), &InterruptId);

+  // Check if it is a valid interrupt ID

+  if (InterruptId < ArmGicGetMaxNumInterrupts (PcdGet32 (PcdGicDistributorBase))) {

+    // Got a valid SGI number hence signal End of Interrupt

+    ArmGicEndOfInterrupt (PcdGet32 (PcdGicInterruptInterfaceBase), AcknowledgeInterrupt);

+  }

+

+  // Jump to secondary core entry point.

+  SecondaryStart ();

+

+  // PEI Core should always load and never return

+  ASSERT (FALSE);

+}

+

+/**

+  Call before jumping to Normal World

+

+  This function allows the firmware platform to do extra actions before

+  jumping to the Normal World

+

+**/

+VOID

+ArmPlatformSecExtraAction (

+  IN  UINTN         MpId,

+  OUT UINTN*        JumpAddress

+  )

+{

+  CHAR8           Buffer[100];

+  UINTN           CharCount;

+  UINTN*          StartAddress;

+

+  if (FeaturePcdGet (PcdStandalone) == FALSE) {

+

+    //

+    // Warning: This code assumes the DRAM has already been initialized by ArmPlatformSecLib

+    //

+

+    if (ArmPlatformIsPrimaryCore (MpId)) {

+      StartAddress = (UINTN*)(UINTN)PcdGet64 (PcdFvBaseAddress);

+

+      // Patch the DRAM to make an infinite loop at the start address

+      *StartAddress = 0xEAFFFFFE; // opcode for while(1)

+

+      CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Waiting for firmware at 0x%08X ...\n\r",StartAddress);

+      SerialPortWrite ((UINT8 *) Buffer, CharCount);

+

+      *JumpAddress = PcdGet64 (PcdFvBaseAddress);

+    } else {

+      // When the primary core is stopped by the hardware debugger to copy the firmware

+      // into DRAM. The secondary cores are still running. As soon as the first bytes of

+      // the firmware are written into DRAM, the secondary cores will start to execute the

+      // code even if the firmware is not entirely written into the memory.

+      // That's why the secondary cores need to be parked in WFI and wake up once the

+      // firmware is ready.

+

+      *JumpAddress = (UINTN)NonSecureWaitForFirmware;

+    }

+  } else if (FeaturePcdGet (PcdSystemMemoryInitializeInSec)) {

+

+    //

+    // Warning: This code assumes the DRAM has already been initialized by ArmPlatformSecLib

+    //

+

+    if (ArmPlatformIsPrimaryCore (MpId)) {

+      // Signal the secondary cores they can jump to PEI phase

+      ArmGicSendSgiTo (PcdGet32 (PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));

+

+      // To enter into Non Secure state, we need to make a return from exception

+      *JumpAddress = PcdGet64 (PcdFvBaseAddress);

+    } else {

+      // We wait for the primary core to finish to initialize the System Memory. Otherwise the secondary

+      // cores would make crash the system by setting their stacks in DRAM before the primary core has not

+      // finished to initialize the system memory.

+      *JumpAddress = (UINTN)NonSecureWaitForFirmware;

+    }

+  } else {

+    *JumpAddress = PcdGet64 (PcdFvBaseAddress);

+  }

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf
new file mode 100755
index 0000000..b058f36
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/DebugSecExtraActionLib/DebugSecExtraActionLib.inf
@@ -0,0 +1,54 @@
+#/* @file

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = DebugSecExtraActionLib

+  FILE_GUID                      = 8fff7a60-a6f8-11e0-990a-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = ArmPlatformSecExtraActionLib

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+#  VALID_ARCHITECTURES           = ARM

+#

+

+[Sources.common]

+  DebugSecExtraActionLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmPlatformLib

+  DebugLib

+  PcdLib

+  ArmGicLib

+  PrintLib

+  SerialPortLib

+

+[FeaturePcd]

+  gArmPlatformTokenSpaceGuid.PcdStandalone

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+

+  gArmTokenSpaceGuid.PcdGicDistributorBase

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase

+  gArmTokenSpaceGuid.PcdGicSgiIntId

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/AArch64/EblCmdMmu.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/AArch64/EblCmdMmu.c
new file mode 100644
index 0000000..1692675
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/AArch64/EblCmdMmu.c
@@ -0,0 +1,33 @@
+/** @file

+*

+*  Copyright (c) 2011 - 2013, ARM 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.

+*

+**/

+

+#include <PiDxe.h>

+#include <Library/UefiLib.h>

+#include <Library/ArmLib.h>

+#include <Chipset/AArch64.h>

+#include <Library/CacheMaintenanceLib.h>

+#include <Library/EblCmdLib.h>

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+

+EFI_STATUS

+EblDumpMmu (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  AsciiPrint ("\nNot supported on this platform.\n");

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/Arm/EblCmdMmu.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/Arm/EblCmdMmu.c
new file mode 100644
index 0000000..fe9d3ea
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/Arm/EblCmdMmu.c
@@ -0,0 +1,370 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include <PiDxe.h>

+#include <Library/UefiLib.h>

+#include <Library/ArmLib.h>

+#include <Chipset/ArmV7.h>

+#include <Library/CacheMaintenanceLib.h>

+#include <Library/EblCmdLib.h>

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+

+#define GET_TT_ATTRIBUTES(TTEntry)  ((TTEntry) & ~(TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK))

+#define GET_TT_PAGE_ATTRIBUTES(TTEntry)  ((TTEntry) & 0xFFF)

+#define GET_TT_LARGEPAGE_ATTRIBUTES(TTEntry)  ((TTEntry) & 0xFFFF)

+

+// Section

+#define TT_DESCRIPTOR_SECTION_STRONGLY_ORDER   (TT_DESCRIPTOR_SECTION_TYPE_SECTION    | \

+                                                TT_DESCRIPTOR_SECTION_NG_GLOBAL       | \

+                                                TT_DESCRIPTOR_SECTION_S_NOT_SHARED    | \

+                                                TT_DESCRIPTOR_SECTION_DOMAIN(0)       | \

+                                                TT_DESCRIPTOR_SECTION_AP_RW_RW        | \

+                                                TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED)

+

+// Small Page

+#define TT_DESCRIPTOR_PAGE_STRONGLY_ORDER      (TT_DESCRIPTOR_PAGE_TYPE_PAGE          | \

+                                                TT_DESCRIPTOR_PAGE_NG_GLOBAL          | \

+                                                TT_DESCRIPTOR_PAGE_S_NOT_SHARED       | \

+                                                TT_DESCRIPTOR_PAGE_AP_RW_RW           | \

+                                                TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED)

+

+// Large Page

+#define TT_DESCRIPTOR_LARGEPAGE_WRITE_BACK     (TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE     | \

+                                                TT_DESCRIPTOR_PAGE_NG_GLOBAL          | \

+                                                TT_DESCRIPTOR_PAGE_S_NOT_SHARED       | \

+                                                TT_DESCRIPTOR_PAGE_AP_RW_RW           | \

+                                                TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC)

+#define TT_DESCRIPTOR_LARGEPAGE_WRITE_THROUGH  (TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE     | \

+                                                TT_DESCRIPTOR_PAGE_NG_GLOBAL          | \

+                                                TT_DESCRIPTOR_PAGE_S_NOT_SHARED       | \

+                                                TT_DESCRIPTOR_PAGE_AP_RW_RW           | \

+                                                TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)

+#define TT_DESCRIPTOR_LARGEPAGE_DEVICE         (TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE     | \

+                                                TT_DESCRIPTOR_PAGE_NG_GLOBAL          | \

+                                                TT_DESCRIPTOR_PAGE_S_NOT_SHARED       | \

+                                                TT_DESCRIPTOR_PAGE_AP_RW_RW           | \

+                                                TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE)

+#define TT_DESCRIPTOR_LARGEPAGE_UNCACHED       (TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE     | \

+                                                TT_DESCRIPTOR_PAGE_NG_GLOBAL          | \

+                                                TT_DESCRIPTOR_PAGE_S_NOT_SHARED       | \

+                                                TT_DESCRIPTOR_PAGE_AP_RW_RW           | \

+                                                TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE)

+

+

+typedef enum { Level0, Level1,Level2 } MMU_LEVEL;

+

+typedef struct {

+  MMU_LEVEL   Level;

+  UINT32      Value;

+  UINT32      Index;

+  UINT32*     Table;

+} MMU_ENTRY;

+

+MMU_ENTRY

+MmuEntryCreate (

+  IN MMU_LEVEL Level,

+  IN UINT32* Table,

+  IN UINT32 Index

+  )

+{

+  MMU_ENTRY Entry;

+  Entry.Level = Level;

+  Entry.Value = Table[Index];

+  Entry.Table = Table;

+  Entry.Index = Index;

+  return Entry;

+}

+

+UINT32

+MmuEntryIsValidAddress (

+  IN MMU_LEVEL Level,

+  IN UINT32 Entry

+  )

+{

+  if (Level == Level0) {

+    return 0;

+  } else if (Level == Level1) {

+    if ((Entry & 0x3) == 0) {           // Ignored

+      return 0;

+    } else if ((Entry & 0x3) == 2) {    // Section Type

+      return 1;

+    } else {                            // Page Type

+      return 0;

+    }

+  } else if (Level == Level2){

+    if ((Entry & 0x3) == 0) {           // Ignored

+      return 0;

+    } else {                            // Page Type

+      return 1;

+    }

+  } else {

+    DEBUG((EFI_D_ERROR,"MmuEntryIsValidAddress: Level:%d Entry:0x%X\n",(UINT32)Level,(UINT32)Entry));

+    ASSERT(0);

+    return 0;

+  }

+}

+

+UINT32

+MmuEntryGetAddress (

+  IN MMU_ENTRY Entry

+  )

+{

+  if (Entry.Level == Level1) {

+    if ((Entry.Value & 0x3) == 0) {

+      return 0;

+    } else if ((Entry.Value & 0x3) == 2) {    // Section Type

+      return Entry.Value & TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK;

+    } else if ((Entry.Value & 0x3) == 1) {    // Level2 Table

+      MMU_ENTRY Level2Entry = MmuEntryCreate (Level2,(UINT32*)(Entry.Value & 0xFFFFC000),0);

+      return MmuEntryGetAddress (Level2Entry);

+    } else {                                  // Page Type

+      return 0;

+    }

+  } else if (Entry.Level == Level2) {

+    if ((Entry.Value & 0x3) == 0) {           // Ignored

+      return 0;

+    } else if ((Entry.Value & 0x3) == 1) {    // Large Page

+      return Entry.Value & 0xFFFF0000;

+    } else if ((Entry.Value & 0x2) == 2) {    // Small Page

+      return Entry.Value & 0xFFFFF000;

+    } else {

+      return 0;

+    }

+  } else {

+    ASSERT(0);

+    return 0;

+  }

+}

+

+UINT32

+MmuEntryGetSize (

+  IN MMU_ENTRY Entry

+  )

+{

+  if (Entry.Level == Level1) {

+    if ((Entry.Value & 0x3) == 0) {

+      return 0;

+    } else if ((Entry.Value & 0x3) == 2) {

+      if (Entry.Value & (1 << 18))

+        return 16*SIZE_1MB;

+      else

+        return SIZE_1MB;

+    } else if ((Entry.Value & 0x3) == 1) {      // Level2 Table split 1MB section

+      return SIZE_1MB;

+    } else {

+      DEBUG((EFI_D_ERROR, "MmuEntryGetSize: Value:0x%X",Entry.Value));

+      ASSERT(0);

+      return 0;

+    }

+  } else if (Entry.Level == Level2) {

+    if ((Entry.Value & 0x3) == 0) {           // Ignored

+      return 0;

+    } else if ((Entry.Value & 0x3) == 1) {    // Large Page

+      return SIZE_64KB;

+    } else if ((Entry.Value & 0x2) == 2) {    // Small Page

+      return SIZE_4KB;

+    } else {

+      ASSERT(0);

+      return 0;

+    }

+  } else {

+    ASSERT(0);

+    return 0;

+  }

+}

+

+CONST CHAR8*

+MmuEntryGetAttributesName (

+  IN MMU_ENTRY Entry

+  )

+{

+  UINT32 Value;

+

+  if (Entry.Level == Level1) {

+    Value = GET_TT_ATTRIBUTES(Entry.Value) | TT_DESCRIPTOR_SECTION_NS_MASK;

+    if (Value == TT_DESCRIPTOR_SECTION_WRITE_BACK(0))

+      return "TT_DESCRIPTOR_SECTION_WRITE_BACK";

+    else if (Value == TT_DESCRIPTOR_SECTION_WRITE_THROUGH(0))

+      return "TT_DESCRIPTOR_SECTION_WRITE_THROUGH";

+    else if (Value == TT_DESCRIPTOR_SECTION_DEVICE(0))

+      return "TT_DESCRIPTOR_SECTION_DEVICE";

+    else if (Value == TT_DESCRIPTOR_SECTION_UNCACHED(0))

+      return "TT_DESCRIPTOR_SECTION_UNCACHED";

+    else if (Value == TT_DESCRIPTOR_SECTION_STRONGLY_ORDER)

+      return "TT_DESCRIPTOR_SECTION_STRONGLY_ORDERED";

+    else {

+      return "SectionUnknown";

+    }

+  } else if ((Entry.Level == Level2) && ((Entry.Value & 0x2) == 2)) { //Small Page

+    Value = GET_TT_PAGE_ATTRIBUTES(Entry.Value);

+    if (Value == TT_DESCRIPTOR_PAGE_WRITE_BACK)

+      return "TT_DESCRIPTOR_PAGE_WRITE_BACK";

+    else if (Value == TT_DESCRIPTOR_PAGE_WRITE_THROUGH)

+      return "TT_DESCRIPTOR_PAGE_WRITE_THROUGH";

+    else if (Value == TT_DESCRIPTOR_PAGE_DEVICE)

+      return "TT_DESCRIPTOR_PAGE_DEVICE";

+    else if (Value == TT_DESCRIPTOR_PAGE_UNCACHED)

+      return "TT_DESCRIPTOR_PAGE_UNCACHED";

+    else if (Value == TT_DESCRIPTOR_PAGE_STRONGLY_ORDER)

+      return "TT_DESCRIPTOR_PAGE_STRONGLY_ORDERED";

+    else {

+      return "PageUnknown";

+    }

+  } else if ((Entry.Level == Level2) && ((Entry.Value & 0x3) == 1)) { //Large Page

+    Value = GET_TT_LARGEPAGE_ATTRIBUTES(Entry.Value);

+    if (Value == TT_DESCRIPTOR_LARGEPAGE_WRITE_BACK)

+      return "TT_DESCRIPTOR_LARGEPAGE_WRITE_BACK";

+    else if (Value == TT_DESCRIPTOR_LARGEPAGE_WRITE_THROUGH)

+      return "TT_DESCRIPTOR_LARGEPAGE_WRITE_THROUGH";

+    else if (Value == TT_DESCRIPTOR_LARGEPAGE_DEVICE)

+      return "TT_DESCRIPTOR_LARGEPAGE_DEVICE";

+    else if (Value == TT_DESCRIPTOR_LARGEPAGE_UNCACHED)

+      return "TT_DESCRIPTOR_LARGEPAGE_UNCACHED";

+    else {

+      return "LargePageUnknown";

+    }

+  } else {

+    ASSERT(0);

+    return "";

+  }

+}

+

+UINT32

+MmuEntryGetAttributes (

+  IN MMU_ENTRY Entry

+  )

+{

+  if (Entry.Level == Level1) {

+    if ((Entry.Value & 0x3) == 0) {

+      return 0;

+    } else if ((Entry.Value & 0x3) == 2) {

+      return GET_TT_ATTRIBUTES(Entry.Value);

+    } else {

+      return 0;

+    }

+  } else if ((Entry.Level == Level2) && ((Entry.Value & 0x2) == 2)) { //Small Page

+    if (GET_TT_PAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_PAGE_WRITE_BACK)

+      return TT_DESCRIPTOR_SECTION_WRITE_BACK(0);

+    else if (GET_TT_PAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_PAGE_WRITE_THROUGH)

+      return TT_DESCRIPTOR_SECTION_WRITE_THROUGH(0);

+    else if (GET_TT_PAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_PAGE_DEVICE)

+      return TT_DESCRIPTOR_SECTION_DEVICE(0);

+    else if (GET_TT_PAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_PAGE_UNCACHED)

+      return TT_DESCRIPTOR_SECTION_UNCACHED(0);

+    else if (GET_TT_PAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_PAGE_STRONGLY_ORDER)

+      return TT_DESCRIPTOR_SECTION_STRONGLY_ORDER;

+    else {

+      return 0;

+    }

+  } else if ((Entry.Level == Level2) && ((Entry.Value & 0x3) == 1)) { //Large Page

+    if (GET_TT_LARGEPAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_LARGEPAGE_WRITE_BACK)

+      return TT_DESCRIPTOR_SECTION_WRITE_BACK(0);

+    else if (GET_TT_LARGEPAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_LARGEPAGE_WRITE_THROUGH)

+      return TT_DESCRIPTOR_SECTION_WRITE_THROUGH(0);

+    else if (GET_TT_LARGEPAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_LARGEPAGE_DEVICE)

+      return TT_DESCRIPTOR_SECTION_DEVICE(0);

+    else if (GET_TT_LARGEPAGE_ATTRIBUTES(Entry.Value) == TT_DESCRIPTOR_LARGEPAGE_UNCACHED)

+      return TT_DESCRIPTOR_SECTION_UNCACHED(0);

+    else {

+      return 0;

+    }

+  } else {

+    return 0;

+  }

+}

+

+

+MMU_ENTRY

+DumpMmuLevel (

+  IN MMU_LEVEL Level,

+  IN UINT32* Table,

+  IN MMU_ENTRY PreviousEntry

+  )

+{

+  UINT32      Index = 0, Count;

+  MMU_ENTRY   LastEntry, Entry;

+

+  ASSERT((Level == Level1) || (Level == Level2));

+

+  if (Level == Level1)    Count = 4096;

+  else                    Count = 256;

+

+  // At Level1, we will get into this function because PreviousEntry is not valid

+  if (!MmuEntryIsValidAddress((MMU_LEVEL)(Level-1),PreviousEntry.Value)) {

+      // Find the first valid address

+      for (; (Index < Count) && (!MmuEntryIsValidAddress(Level,Table[Index])); Index++);

+

+      LastEntry = MmuEntryCreate(Level,Table,Index);

+      Index++;

+  } else {

+    LastEntry = PreviousEntry;

+  }

+

+  for (; Index < Count; Index++) {

+    Entry = MmuEntryCreate(Level,Table,Index);

+    if ((Level == Level1) && ((Entry.Value & 0x3) == 1)) {       // We have got a Level2 table redirection

+      LastEntry = DumpMmuLevel(Level2,(UINT32*)(Entry.Value & 0xFFFFFC00),LastEntry);

+    } else if (!MmuEntryIsValidAddress(Level,Table[Index])) {

+      if (MmuEntryIsValidAddress(LastEntry.Level,LastEntry.Value)) {

+          AsciiPrint("0x%08X-0x%08X\t%a\n",

+              MmuEntryGetAddress(LastEntry),MmuEntryGetAddress(PreviousEntry)+MmuEntryGetSize(PreviousEntry)-1,

+              MmuEntryGetAttributesName(LastEntry));

+      }

+      LastEntry = Entry;

+    } else {

+      if (MmuEntryGetAttributes(LastEntry) != MmuEntryGetAttributes(Entry)) {

+          if (MmuEntryIsValidAddress(Level,LastEntry.Value)) {

+            AsciiPrint("0x%08X-0x%08X\t%a\n",

+                      MmuEntryGetAddress(LastEntry),MmuEntryGetAddress(PreviousEntry)+MmuEntryGetSize(PreviousEntry)-1,

+                      MmuEntryGetAttributesName(LastEntry));

+          }

+          LastEntry = Entry;

+      } else {

+        ASSERT(LastEntry.Value != 0);

+      }

+    }

+    PreviousEntry = Entry;

+  }

+

+  if ((Level == Level1) && (LastEntry.Index != Index) && MmuEntryIsValidAddress(Level,LastEntry.Value)) {

+    AsciiPrint("0x%08X-0x%08X\t%a\n",

+                  MmuEntryGetAddress(LastEntry),MmuEntryGetAddress(PreviousEntry)+MmuEntryGetSize(PreviousEntry)-1,

+                  MmuEntryGetAttributesName(LastEntry));

+  }

+

+  return LastEntry;

+}

+

+

+EFI_STATUS

+EblDumpMmu (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  UINT32  *TTEntry;

+  MMU_ENTRY NoEntry;

+

+  TTEntry = ArmGetTTBR0BaseAddress();

+

+  AsciiPrint ("\nTranslation Table:0x%X\n",TTEntry);

+  AsciiPrint ("Address Range\t\tAttributes\n");

+  AsciiPrint ("____________________________________________________\n");

+

+  NoEntry.Level = (MMU_LEVEL)200;

+  DumpMmuLevel(Level1,TTEntry,NoEntry);

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c
new file mode 100644
index 0000000..dcd7c41
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdFdt.c
@@ -0,0 +1,218 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include <Base.h>

+#include <Uefi.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/BdsLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+#include <Library/PrintLib.h>

+#include <Library/UefiLib.h>

+#include <Library/UefiApplicationEntryPoint.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+

+#include <Protocol/DevicePathFromText.h>

+

+#include <Guid/ArmGlobalVariableHob.h>

+

+#include <libfdt.h>

+

+#define ALIGN(x, a)     (((x) + ((a) - 1)) & ~((a) - 1))

+#define PALIGN(p, a)    ((void *)(ALIGN((unsigned long)(p), (a))))

+#define GET_CELL(p)     (p += 4, *((const uint32_t *)(p-4)))

+

+STATIC

+UINTN

+IsPrintableString (

+  IN CONST VOID* data,

+  IN UINTN len

+  )

+{

+  CONST CHAR8 *s = data;

+  CONST CHAR8 *ss;

+

+  // Zero length is not

+  if (len == 0) {

+    return 0;

+  }

+

+  // Must terminate with zero

+  if (s[len - 1] != '\0') {

+    return 0;

+  }

+

+  ss = s;

+  while (*s/* && isprint(*s)*/) {

+    s++;

+  }

+

+  // Not zero, or not done yet

+  if (*s != '\0' || (s + 1 - ss) < len) {

+    return 0;

+  }

+

+  return 1;

+}

+

+STATIC

+VOID

+PrintData (

+  IN CONST CHAR8* data,

+  IN UINTN len

+  )

+{

+  UINTN i;

+  CONST CHAR8 *p = data;

+

+  // No data, don't print

+  if (len == 0)

+    return;

+

+  if (IsPrintableString (data, len)) {

+    Print(L" = \"%a\"", (const char *)data);

+  } else if ((len % 4) == 0) {

+    Print(L" = <");

+    for (i = 0; i < len; i += 4) {

+      Print(L"0x%08x%a", fdt32_to_cpu(GET_CELL(p)),i < (len - 4) ? " " : "");

+    }

+    Print(L">");

+  } else {

+    Print(L" = [");

+    for (i = 0; i < len; i++)

+      Print(L"%02x%a", *p++, i < len - 1 ? " " : "");

+    Print(L"]");

+  }

+}

+

+VOID

+DumpFdt (

+  IN VOID*                FdtBlob

+  )

+{

+  struct fdt_header *bph;

+  UINT32 off_dt;

+  UINT32 off_str;

+  CONST CHAR8* p_struct;

+  CONST CHAR8* p_strings;

+  CONST CHAR8* p;

+  CONST CHAR8* s;

+  CONST CHAR8* t;

+  UINT32 tag;

+  UINTN sz;

+  UINTN depth;

+  UINTN shift;

+  UINT32 version;

+

+  depth = 0;

+  shift = 4;

+

+  bph = FdtBlob;

+  off_dt = fdt32_to_cpu(bph->off_dt_struct);

+  off_str = fdt32_to_cpu(bph->off_dt_strings);

+  p_struct = (CONST CHAR8*)FdtBlob + off_dt;

+  p_strings = (CONST CHAR8*)FdtBlob + off_str;

+  version = fdt32_to_cpu(bph->version);

+

+  p = p_struct;

+  while ((tag = fdt32_to_cpu(GET_CELL(p))) != FDT_END) {

+

+    if (tag == FDT_BEGIN_NODE) {

+      s = p;

+      p = PALIGN(p + strlen(s) + 1, 4);

+

+      if (*s == '\0')

+              s = "/";

+

+      Print(L"%*s%a {\n", depth * shift, L" ", s);

+

+      depth++;

+      continue;

+    }

+

+    if (tag == FDT_END_NODE) {

+      depth--;

+

+      Print(L"%*s};\n", depth * shift, L" ");

+      continue;

+    }

+

+    if (tag == FDT_NOP) {

+      Print(L"%*s// [NOP]\n", depth * shift, L" ");

+      continue;

+    }

+

+    if (tag != FDT_PROP) {

+      Print(L"%*s ** Unknown tag 0x%08x\n", depth * shift, L" ", tag);

+      break;

+    }

+    sz = fdt32_to_cpu(GET_CELL(p));

+    s = p_strings + fdt32_to_cpu(GET_CELL(p));

+    if (version < 16 && sz >= 8)

+            p = PALIGN(p, 8);

+    t = p;

+

+    p = PALIGN(p + sz, 4);

+

+    Print(L"%*s%a", depth * shift, L" ", s);

+    PrintData(t, sz);

+    Print(L";\n");

+  }

+}

+

+EFI_STATUS

+EblDumpFdt (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  EFI_STATUS           Status;

+  EFI_DEVICE_PATH*     FdtDevicePath;

+  EFI_PHYSICAL_ADDRESS FdtBlob;

+  UINTN                FdtBlobSize;

+  UINTN                Ret;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;

+

+  // If no FDT file is passed to the argument then get the one from the platform

+  if (Argc < 2) {

+    Status = GetEnvironmentVariable (L"Fdt", &gArmGlobalVariableGuid, NULL, NULL, (VOID**)&FdtDevicePath);

+    if (Status == EFI_NOT_FOUND) {

+      // No set yet, get the Default Device Path

+      Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+      ASSERT_EFI_ERROR(Status);

+      FdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtDevicePath));

+    }

+  } else {

+    return EFI_NOT_FOUND;

+  }

+

+  Status = BdsLoadImage (FdtDevicePath, AllocateAnyPages, &FdtBlob, &FdtBlobSize);

+  if (EFI_ERROR(Status)) {

+    Print (L"ERROR: Did not find the Fdt Blob.\n");

+    return Status;

+  }

+

+  Ret = fdt_check_header((CONST VOID*)(UINTN)FdtBlob);

+  if (Ret != 0) {

+    Print (L"ERROR: Device Tree header not valid (err:%d)\n",Ret);

+    return Status;

+  }

+

+  DumpFdt ((VOID*)(UINTN)FdtBlob);

+

+  FreePool (FdtDevicePath);

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c
new file mode 100644
index 0000000..8999910
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c
@@ -0,0 +1,456 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include <PiDxe.h>

+#include <Library/ArmLib.h>

+#include <Library/CacheMaintenanceLib.h>

+#include <Library/EblCmdLib.h>

+#include <Library/BaseLib.h>

+#include <Library/DxeServicesTableLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/UefiLib.h>

+#include <Library/PcdLib.h>

+#include <Library/EfiFileLib.h>

+#include <Library/ArmDisassemblerLib.h>

+#include <Library/PeCoffGetEntryPointLib.h>

+#include <Library/PerformanceLib.h>

+#include <Library/TimerLib.h>

+#include <Library/BdsLib.h>

+

+#include <Guid/DebugImageInfoTable.h>

+

+#include <Protocol/DebugSupport.h>

+#include <Protocol/LoadedImage.h>

+#include <Protocol/DevicePathToText.h>

+

+EFI_STATUS

+EblDumpMmu (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  );

+

+EFI_STATUS

+EblDumpFdt (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  );

+

+/**

+  Simple arm disassembler via a library

+

+  Argv[0] - symboltable

+  Argv[1] - Optional qoted format string

+  Argv[2] - Optional flag

+

+  @param  Argc   Number of command arguments in Argv

+  @param  Argv   Array of strings that represent the parsed command line.

+                 Argv[0] is the command name

+

+  @return EFI_SUCCESS

+

+**/

+EFI_STATUS

+EblSymbolTable (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  EFI_STATUS                        Status;

+  EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugImageTableHeader = NULL;

+  EFI_DEBUG_IMAGE_INFO              *DebugTable;

+  UINTN                             Entry;

+  CHAR8                             *Format;

+  CHAR8                             *Pdb;

+  UINT32                            PeCoffSizeOfHeaders;

+  UINT32                            ImageBase;

+  BOOLEAN                           Elf;

+

+  // Need to add lots of error checking on the passed in string

+  // Default string is for RealView debugger

+#if (__ARMCC_VERSION < 500000)

+  Format = (Argc > 1) ? Argv[1] : "load /a /ni /np %a &0x%x";

+#else

+  Format = (Argc > 1) ? Argv[1] : "add-symbol-file %a 0x%x";

+#endif

+  Elf = (Argc > 2) ? FALSE : TRUE;

+

+  Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugImageTableHeader);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  DebugTable = DebugImageTableHeader->EfiDebugImageInfoTable;

+  if (DebugTable == NULL) {

+    return EFI_SUCCESS;

+  }

+

+  for (Entry = 0; Entry < DebugImageTableHeader->TableSize; Entry++, DebugTable++) {

+    if (DebugTable->NormalImage != NULL) {

+      if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {

+        ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;

+        PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageBase);

+        Pdb = PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);

+        if (Pdb != NULL) {

+          if (Elf) {

+            // ELF and Mach-O images don't include the header so the linked address does not include header

+            ImageBase += PeCoffSizeOfHeaders;

+          }

+          AsciiPrint (Format, Pdb, ImageBase);

+          AsciiPrint ("\n");

+        } else {

+        }

+      }

+    }

+  }

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+  Simple arm disassembler via a library

+

+  Argv[0] - disasm

+  Argv[1] - Address to start disassembling from

+  ARgv[2] - Number of instructions to disassembly (optional)

+

+  @param  Argc   Number of command arguments in Argv

+  @param  Argv   Array of strings that represent the parsed command line.

+                 Argv[0] is the command name

+

+  @return EFI_SUCCESS

+

+**/

+EFI_STATUS

+EblDisassembler (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  UINT8   *Ptr, *CurrentAddress;

+  UINT32  Address;

+  UINT32  Count;

+  CHAR8   Buffer[80];

+  UINT32  ItBlock;

+

+  if (Argc < 2) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Address = AsciiStrHexToUintn (Argv[1]);

+  Count   = (Argc > 2) ? (UINT32)AsciiStrHexToUintn (Argv[2]) : 20;

+

+  Ptr = (UINT8 *)(UINTN)Address;

+  ItBlock = 0;

+  do {

+    CurrentAddress = Ptr;

+    DisassembleInstruction (&Ptr, TRUE, TRUE, &ItBlock, Buffer, sizeof (Buffer));

+    AsciiPrint ("0x%08x: %a\n", CurrentAddress, Buffer);

+  } while (Count-- > 0);

+

+

+  return EFI_SUCCESS;

+}

+

+

+CHAR8 *

+ImageHandleToPdbFileName (

+  IN  EFI_HANDLE    Handle

+  )

+{

+  EFI_STATUS                  Status;

+  EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage;

+  CHAR8                       *Pdb;

+  CHAR8                       *StripLeading;

+

+  Status = gBS->HandleProtocol (Handle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage);

+  if (EFI_ERROR (Status)) {

+    return "";

+  }

+

+  Pdb = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);

+  StripLeading = AsciiStrStr (Pdb, "\\ARM\\");

+  if (StripLeading == NULL) {

+    StripLeading = AsciiStrStr (Pdb, "/ARM/");

+    if (StripLeading == NULL) {

+      return Pdb;

+    }

+  }

+  // Hopefully we hacked off the unneeded part

+  return (StripLeading + 5);

+}

+

+

+STATIC CHAR8 *mTokenList[] = {

+  /*"SEC",*/

+  "PEI",

+  "DXE",

+  /*"BDS",*/

+  NULL

+};

+

+/**

+  Simple arm disassembler via a library

+

+  Argv[0] - disasm

+  Argv[1] - Address to start disassembling from

+  ARgv[2] - Number of instructions to disassembly (optional)

+

+  @param  Argc   Number of command arguments in Argv

+  @param  Argv   Array of strings that represent the parsed command line.

+                 Argv[0] is the command name

+

+  @return EFI_SUCCESS

+

+**/

+EFI_STATUS

+EblPerformance (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  UINTN       Key;

+  CONST VOID  *Handle;

+  CONST CHAR8 *Token, *Module;

+  UINT64      Start, Stop, TimeStamp;

+  UINT64      Delta, TicksPerSecond, Milliseconds, Microseconds;

+  UINTN       Index;

+  BOOLEAN     CountUp;

+

+  TicksPerSecond = GetPerformanceCounterProperties (&Start, &Stop);

+  if (Start < Stop) {

+    CountUp = TRUE;

+  } else {

+    CountUp = FALSE;

+  }

+

+  Key       = 0;

+  do {

+    Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);

+    if (Key != 0) {

+      if (AsciiStriCmp ("StartImage:", Token) == 0) {

+        if (Stop == 0) {

+          // The entry for EBL is still running so the stop time will be zero. Skip it

+          AsciiPrint ("   running     %a\n", ImageHandleToPdbFileName ((EFI_HANDLE)Handle));

+        } else {

+          Delta =  CountUp?(Stop - Start):(Start - Stop);

+          Microseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000000), TicksPerSecond, NULL);

+          AsciiPrint ("%10ld us  %a\n", Microseconds, ImageHandleToPdbFileName ((EFI_HANDLE)Handle));

+        }

+      }

+    }

+  } while (Key != 0);

+

+  AsciiPrint ("\n");

+

+  TimeStamp = 0;

+  Key       = 0;

+  do {

+    Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);

+    if (Key != 0) {

+      for (Index = 0; mTokenList[Index] != NULL; Index++) {

+        if (AsciiStriCmp (mTokenList[Index], Token) == 0) {

+          Delta =  CountUp?(Stop - Start):(Start - Stop);

+          TimeStamp += Delta;

+          Milliseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000), TicksPerSecond, NULL);

+          AsciiPrint ("%6a %6ld ms\n", Token, Milliseconds);

+          break;

+        }

+      }

+    }

+  } while (Key != 0);

+

+  AsciiPrint ("Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));

+

+  return EFI_SUCCESS;

+}

+

+#define EFI_MEMORY_PORT_IO  0x4000000000000000ULL

+

+EFI_STATUS

+EblDumpGcd (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  EFI_STATUS                        Status;

+  UINTN                           NumberOfDescriptors;

+  UINTN i;

+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;

+  EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;

+

+  Status = gDS->GetMemorySpaceMap(&NumberOfDescriptors,&MemorySpaceMap);

+  if (EFI_ERROR (Status)) {

+      return Status;

+  }

+  AsciiPrint ("    Address Range       Image     Device   Attributes\n");

+  AsciiPrint ("__________________________________________________________\n");

+  for (i=0; i < NumberOfDescriptors; i++) {

+    AsciiPrint ("MEM %016lx - %016lx",(UINT64)MemorySpaceMap[i].BaseAddress,MemorySpaceMap[i].BaseAddress+MemorySpaceMap[i].Length-1);

+    AsciiPrint (" %08x %08x",MemorySpaceMap[i].ImageHandle,MemorySpaceMap[i].DeviceHandle);

+

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_RUNTIME)

+        AsciiPrint (" RUNTIME");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_PORT_IO)

+        AsciiPrint (" PORT_IO");

+

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_UC)

+        AsciiPrint (" MEM_UC");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WC)

+        AsciiPrint (" MEM_WC");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WT)

+        AsciiPrint (" MEM_WT");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WB)

+        AsciiPrint (" MEM_WB");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_UCE)

+        AsciiPrint (" MEM_UCE");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WP)

+        AsciiPrint (" MEM_WP");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_RP)

+        AsciiPrint (" MEM_RP");

+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_XP)

+        AsciiPrint (" MEM_XP");

+

+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeNonExistent)

+        AsciiPrint (" TYPE_NONEXISTENT");

+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeReserved)

+        AsciiPrint (" TYPE_RESERVED");

+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeSystemMemory)

+        AsciiPrint (" TYPE_SYSMEM");

+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeMemoryMappedIo)

+        AsciiPrint (" TYPE_MEMMAP");

+

+    AsciiPrint ("\n");

+  }

+

+  FreePool (MemorySpaceMap);

+

+  Status = gDS->GetIoSpaceMap(&NumberOfDescriptors,&IoSpaceMap);

+  if (EFI_ERROR (Status)) {

+      return Status;

+  }

+  for (i=0; i < NumberOfDescriptors; i++) {

+    AsciiPrint ("IO  %08lx - %08lx",IoSpaceMap[i].BaseAddress,IoSpaceMap[i].BaseAddress+IoSpaceMap[i].Length);

+    AsciiPrint ("\t%08x %08x",IoSpaceMap[i].ImageHandle,IoSpaceMap[i].DeviceHandle);

+

+    if (IoSpaceMap[i].GcdIoType & EfiGcdMemoryTypeNonExistent)

+        AsciiPrint (" TYPE_NONEXISTENT");

+    if (IoSpaceMap[i].GcdIoType & EfiGcdMemoryTypeReserved)

+        AsciiPrint (" TYPE_RESERVED");

+    if (IoSpaceMap[i].GcdIoType & EfiGcdIoTypeIo)

+        AsciiPrint (" TYPE_IO");

+

+    AsciiPrint ("\n");

+  }

+

+  FreePool (IoSpaceMap);

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+EblDevicePaths (

+  IN UINTN  Argc,

+  IN CHAR8  **Argv

+  )

+{

+  EFI_STATUS Status;

+  UINTN                              HandleCount;

+  EFI_HANDLE                         *HandleBuffer;

+  UINTN                              Index;

+  CHAR16*                            String;

+  EFI_DEVICE_PATH_PROTOCOL*          DevicePathProtocol;

+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL*  DevicePathToTextProtocol;

+

+  BdsConnectAllDrivers();

+

+  Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+  if (EFI_ERROR (Status)) {

+    AsciiPrint ("Did not find the DevicePathToTextProtocol.\n");

+    return EFI_SUCCESS;

+  }

+

+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiDevicePathProtocolGuid, NULL, &HandleCount, &HandleBuffer);

+  if (EFI_ERROR (Status)) {

+    AsciiPrint ("No device path found\n");

+    return EFI_SUCCESS;

+  }

+

+  for (Index = 0; Index < HandleCount; Index++) {

+    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);

+    String = DevicePathToTextProtocol->ConvertDevicePathToText(DevicePathProtocol,TRUE,TRUE);

+    Print (L"[0x%X] %s\n",(UINTN)HandleBuffer[Index], String);

+  }

+

+  return EFI_SUCCESS;

+}

+

+GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] =

+{

+  {

+    "disasm address [count]",

+    " disassemble count instructions",

+    NULL,

+    EblDisassembler

+  },

+  {

+    "performance",

+    " Display boot performance info",

+    NULL,

+    EblPerformance

+  },

+  {

+    "symboltable [\"format string\"] [PECOFF]",

+    " show symbol table commands for debugger",

+    NULL,

+    EblSymbolTable

+  },

+  {

+    "dumpgcd",

+    " dump Global Coherency Domain",

+    NULL,

+    EblDumpGcd

+  },

+  {

+    "dumpmmu",

+    " dump MMU Table",

+    NULL,

+    EblDumpMmu

+  },

+  {

+    "devicepaths",

+    " list all the Device Paths",

+    NULL,

+    EblDevicePaths

+  },

+  {

+    "dumpfdt",

+    " dump the current fdt or the one defined in the arguments",

+    NULL,

+    EblDumpFdt

+  }

+};

+

+

+VOID

+EblInitializeExternalCmd (

+  VOID

+  )

+{

+  EblAddCommands (mLibCmdTemplate, sizeof (mLibCmdTemplate)/sizeof (EBL_COMMAND_TABLE));

+  return;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
new file mode 100644
index 0000000..5506c77
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.inf
@@ -0,0 +1,66 @@
+#/** @file

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmPlatformEblCmdLib

+  FILE_GUID                      = 6085e1ca-0d2d-4ba4-9872-c59b36ffd6ad

+  MODULE_TYPE                    = UEFI_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = EblCmdLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER

+

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC

+#

+

+[Sources.common]

+  EblCmdLib.c

+  EblCmdFdt.c

+

+[Sources.ARM]

+  Arm/EblCmdMmu.c

+

+[Sources.AARCH64]

+  AArch64/EblCmdMmu.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  ArmLib

+  DebugLib

+  ArmDisassemblerLib

+  PerformanceLib

+  TimerLib

+  BdsLib

+  FdtLib

+

+[Protocols]

+  gEfiDebugSupportProtocolGuid

+  gEfiLoadedImageProtocolGuid

+  gEfiDevicePathToTextProtocolGuid

+

+[Guids]

+  gEfiDebugImageInfoTableGuid

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdFdtDevicePath

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/L2X0CacheLibNull/L2X0Cache.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/L2X0CacheLibNull/L2X0Cache.c
new file mode 100644
index 0000000..3f7fd30
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/L2X0CacheLibNull/L2X0Cache.c
@@ -0,0 +1,30 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <Uefi.h>

+#include <Drivers/PL310L2Cache.h>

+

+// Initialize L2X0 Cache Controller

+VOID

+L2x0CacheInit (

+  IN  UINTN   L2x0Base,

+  IN  UINT32  L2x0TagLatencies,

+  IN  UINT32  L2x0DataLatencies,

+  IN  UINT32  L2x0AuxValue,

+  IN  UINT32  L2x0AuxMask,

+  IN  BOOLEAN CacheEnabled

+  )

+{

+    //No implementation

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/L2X0CacheLibNull/L2X0CacheLibNull.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/L2X0CacheLibNull/L2X0CacheLibNull.inf
new file mode 100755
index 0000000..1bced4d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/L2X0CacheLibNull/L2X0CacheLibNull.inf
@@ -0,0 +1,27 @@
+#/* @file

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = L2X0CacheLibNull

+  FILE_GUID                      = 9c76c900-1e8c-11e0-8766-0002a5d5c51b

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = L2X0CacheLib

+

+[Sources]

+  L2X0Cache.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.c
new file mode 100644
index 0000000..44fe78f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.c
@@ -0,0 +1,137 @@
+/** @file

+  Serial I/O Port library functions with no library constructor/destructor

+

+  Copyright (c) 2012-2014, ARM Ltd. All rights reserved.<BR>

+

+  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 <Base.h>

+

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+#include <Library/SerialPortExtLib.h>

+

+#include <Drivers/PL011Uart.h>

+

+/**

+  Set new attributes to PL011.

+

+  @param  BaudRate                The baud rate of the serial device. If the baud rate is not supported,

+                                  the speed will be reduced down to the nearest supported one and the

+                                  variable's value will be updated accordingly.

+  @param  ReceiveFifoDepth        The number of characters the device will buffer on input. If the specified

+                                  value is not supported, the variable's value will be reduced down to the

+                                  nearest supported one.

+  @param  Timeout                 If applicable, the number of microseconds the device will wait

+                                  before timing out a Read or a Write operation.

+  @param  Parity                  If applicable, this is the EFI_PARITY_TYPE that is computed or checked

+                                  as each character is transmitted or received. If the device does not

+                                  support parity, the value is the default parity value.

+  @param  DataBits                The number of data bits in each character

+  @param  StopBits                If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character.

+                                  If the device does not support stop bits, the value is the default stop

+                                  bit value.

+

+  @retval EFI_SUCCESS             All attributes were set correctly on the serial device.

+  @retval EFI_INVALID_PARAMETERS  One or more of the attributes has an unsupported value.

+

+**/

+RETURN_STATUS

+EFIAPI

+SerialPortSetAttributes (

+  IN OUT UINT64              *BaudRate,

+  IN OUT UINT32              *ReceiveFifoDepth,

+  IN OUT UINT32              *Timeout,

+  IN OUT EFI_PARITY_TYPE     *Parity,

+  IN OUT UINT8               *DataBits,

+  IN OUT EFI_STOP_BITS_TYPE  *StopBits

+  )

+{

+  return PL011UartInitializePort (

+        (UINTN)PcdGet64 (PcdSerialRegisterBase),

+        BaudRate,

+        ReceiveFifoDepth,

+        Parity,

+        DataBits,

+        StopBits);

+}

+

+/**

+

+  Assert or deassert the control signals on a serial port.

+  The following control signals are set according their bit settings :

+  . Request to Send

+  . Data Terminal Ready

+

+  @param[in]  Control  The following bits are taken into account :

+                       . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the

+                         "Request To Send" control signal if this bit is

+                         equal to one/zero.

+                       . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert

+                         the "Data Terminal Ready" control signal if this

+                         bit is equal to one/zero.

+                       . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable

+                         the hardware loopback if this bit is equal to

+                         one/zero.

+                       . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.

+                       . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/

+                         disable the hardware flow control based on CTS (Clear

+                         To Send) and RTS (Ready To Send) control signals.

+

+  @retval  RETURN_SUCCESS      The new control bits were set on the serial device.

+  @retval  RETURN_UNSUPPORTED  The serial device does not support this operation.

+

+**/

+RETURN_STATUS

+EFIAPI

+SerialPortSetControl (

+  IN UINT32  Control

+  )

+{

+  return PL011UartSetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);

+}

+

+/**

+

+  Retrieve the status of the control bits on a serial device.

+

+  @param[out]  Control  Status of the control bits on a serial device :

+

+                        . EFI_SERIAL_DATA_CLEAR_TO_SEND, EFI_SERIAL_DATA_SET_READY,

+                          EFI_SERIAL_RING_INDICATE, EFI_SERIAL_CARRIER_DETECT,

+                          EFI_SERIAL_REQUEST_TO_SEND, EFI_SERIAL_DATA_TERMINAL_READY

+                          are all related to the DTE (Data Terminal Equipment) and

+                          DCE (Data Communication Equipment) modes of operation of

+                          the serial device.

+                        . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the receive

+                          buffer is empty, 0 otherwise.

+                        . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the transmit

+                          buffer is empty, 0 otherwise.

+                        . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if the

+                          hardware loopback is enabled (the ouput feeds the receive

+                          buffer), 0 otherwise.

+                        . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if a

+                          loopback is accomplished by software, 0 otherwise.

+                        . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to one if the

+                          hardware flow control based on CTS (Clear To Send) and RTS

+                          (Ready To Send) control signals is enabled, 0 otherwise.

+

+  @retval RETURN_SUCCESS  The control bits were read from the serial device.

+

+**/

+RETURN_STATUS

+EFIAPI

+SerialPortGetControl (

+  OUT UINT32  *Control

+  )

+{

+  return PL011UartGetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.inf
new file mode 100644
index 0000000..723cc97
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortExtLib.inf
@@ -0,0 +1,43 @@
+#/** @file

+#

+#  Component description file for PL011SerialPortLib module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PL011SerialPortExtLib

+  FILE_GUID                      = 2be281f1-c506-4558-bd98-d6930e6de9d6

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = SerialPortExtLib

+

+[Sources.common]

+  PL011SerialPortExtLib.c

+

+[LibraryClasses]

+  PL011UartLib

+  PcdLib

+

+[Packages]

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[Pcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
new file mode 100644
index 0000000..d4f7fc9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
@@ -0,0 +1,113 @@
+/** @file

+  Serial I/O Port library functions with no library constructor/destructor

+

+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>

+

+  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 <Base.h>

+

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+#include <Library/SerialPortLib.h>

+#include <Library/SerialPortExtLib.h>

+

+#include <Drivers/PL011Uart.h>

+

+

+/**

+

+  Programmed hardware of Serial port.

+

+  @return    Always return RETURN_UNSUPPORTED.

+

+**/

+RETURN_STATUS

+EFIAPI

+SerialPortInitialize (

+  VOID

+  )

+{

+  UINT64              BaudRate;

+  UINT32              ReceiveFifoDepth;

+  EFI_PARITY_TYPE     Parity;

+  UINT8               DataBits;

+  EFI_STOP_BITS_TYPE  StopBits;

+

+  BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);

+  ReceiveFifoDepth = 0; // Use the default value for Fifo depth

+  Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);

+  DataBits = PcdGet8 (PcdUartDefaultDataBits);

+  StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits);

+

+  return PL011UartInitializePort (

+      (UINTN)PcdGet64 (PcdSerialRegisterBase),

+      &BaudRate, &ReceiveFifoDepth, &Parity, &DataBits, &StopBits);

+}

+

+/**

+  Write data to serial device.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Write data failed.

+  @retval !0               Actual number of bytes written to serial device.

+

+**/

+UINTN

+EFIAPI

+SerialPortWrite (

+  IN UINT8     *Buffer,

+  IN UINTN     NumberOfBytes

+  )

+{

+  return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);

+}

+

+/**

+  Read data from serial device and save the data in buffer.

+

+  @param  Buffer           Point of data buffer which need to be written.

+  @param  NumberOfBytes    Number of output bytes which are cached in Buffer.

+

+  @retval 0                Read data failed.

+  @retval !0               Actual number of bytes read from serial device.

+

+**/

+UINTN

+EFIAPI

+SerialPortRead (

+  OUT UINT8     *Buffer,

+  IN  UINTN     NumberOfBytes

+)

+{

+  return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);

+}

+

+/**

+  Check to see if any data is available to be read from the debug device.

+

+  @retval EFI_SUCCESS       At least one byte of data is available to be read

+  @retval EFI_NOT_READY     No data is available to be read

+  @retval EFI_DEVICE_ERROR  The serial device is not functioning properly

+

+**/

+BOOLEAN

+EFIAPI

+SerialPortPoll (

+  VOID

+  )

+{

+  return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf
new file mode 100644
index 0000000..3a950d0
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf
@@ -0,0 +1,43 @@
+#/** @file

+#

+#  Component description file for PL011SerialPortLib module

+#

+#  Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PL011SerialPortLib

+  FILE_GUID                      = 8ecefc8f-a2c4-4091-b80f-20f7aeb0567f

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = SerialPortLib

+

+[Sources.common]

+  PL011SerialPortLib.c

+

+[LibraryClasses]

+  PL011UartLib

+  PcdLib

+

+[Packages]

+  EmbeddedPkg/EmbeddedPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[Pcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c
new file mode 100644
index 0000000..52ba489
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c
@@ -0,0 +1,684 @@
+/** @file

+  Implement EFI RealTimeClock runtime services via RTC Lib.

+

+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+

+  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 <Uefi.h>

+#include <PiDxe.h>

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/UefiLib.h>

+#include <Library/IoLib.h>

+#include <Library/RealTimeClockLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PcdLib.h>

+#include <Library/ArmPlatformSysConfigLib.h>

+#include <Library/DxeServicesTableLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+#include <Library/UefiRuntimeLib.h>

+

+#include <Protocol/RealTimeClock.h>

+

+#include <Guid/GlobalVariable.h>

+#include <Guid/EventGroup.h>

+

+#include <Drivers/PL031RealTimeClock.h>

+

+#include <ArmPlatform.h>

+

+STATIC CONST CHAR16           mTimeZoneVariableName[] = L"PL031RtcTimeZone";

+STATIC CONST CHAR16           mDaylightVariableName[] = L"PL031RtcDaylight";

+STATIC BOOLEAN                mPL031Initialized = FALSE;

+STATIC EFI_EVENT              mRtcVirtualAddrChangeEvent;

+STATIC UINTN                  mPL031RtcBase;

+STATIC EFI_RUNTIME_SERVICES   *mRT;

+

+EFI_STATUS

+IdentifyPL031 (

+  VOID

+  )

+{

+  EFI_STATUS    Status;

+

+  // Check if this is a PrimeCell Peripheral

+  if (  (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID0) != 0x0D)

+      || (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID1) != 0xF0)

+      || (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID2) != 0x05)

+      || (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID3) != 0xB1)) {

+    Status = EFI_NOT_FOUND;

+    goto EXIT;

+  }

+

+  // Check if this PrimeCell Peripheral is the PL031 Real Time Clock

+  if (  (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID0) != 0x31)

+      || (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID1) != 0x10)

+      || ((MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID2) & 0xF) != 0x04)

+      || (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID3) != 0x00)) {

+    Status = EFI_NOT_FOUND;

+    goto EXIT;

+  }

+

+  Status = EFI_SUCCESS;

+

+  EXIT:

+  return Status;

+}

+

+EFI_STATUS

+InitializePL031 (

+  VOID

+  )

+{

+  EFI_STATUS    Status;

+

+  // Prepare the hardware

+  Status = IdentifyPL031();

+  if (EFI_ERROR (Status)) {

+    goto EXIT;

+  }

+

+  // Ensure interrupts are masked. We do not want RTC interrupts in UEFI

+  if ((MmioRead32 (mPL031RtcBase + PL031_RTC_IMSC_IRQ_MASK_SET_CLEAR_REGISTER) & PL031_SET_IRQ_MASK) != PL031_SET_IRQ_MASK) {

+    MmioOr32 (mPL031RtcBase + PL031_RTC_IMSC_IRQ_MASK_SET_CLEAR_REGISTER, PL031_SET_IRQ_MASK);

+  }

+

+  // Clear any existing interrupts

+  if ((MmioRead32 (mPL031RtcBase + PL031_RTC_RIS_RAW_IRQ_STATUS_REGISTER) & PL031_IRQ_TRIGGERED) == PL031_IRQ_TRIGGERED) {

+    MmioOr32 (mPL031RtcBase + PL031_RTC_ICR_IRQ_CLEAR_REGISTER, PL031_CLEAR_IRQ);

+  }

+

+  // Start the clock counter

+  if ((MmioRead32 (mPL031RtcBase + PL031_RTC_CR_CONTROL_REGISTER) & PL031_RTC_ENABLED) != PL031_RTC_ENABLED) {

+    MmioOr32 (mPL031RtcBase + PL031_RTC_CR_CONTROL_REGISTER, PL031_RTC_ENABLED);

+  }

+

+  mPL031Initialized = TRUE;

+

+  EXIT:

+  return Status;

+}

+

+/**

+  Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME

+ **/

+VOID

+EpochToEfiTime (

+  IN  UINTN     EpochSeconds,

+  OUT EFI_TIME  *Time

+  )

+{

+  UINTN         a;

+  UINTN         b;

+  UINTN         c;

+  UINTN         d;

+  UINTN         g;

+  UINTN         j;

+  UINTN         m;

+  UINTN         y;

+  UINTN         da;

+  UINTN         db;

+  UINTN         dc;

+  UINTN         dg;

+  UINTN         hh;

+  UINTN         mm;

+  UINTN         ss;

+  UINTN         J;

+

+  J  = (EpochSeconds / 86400) + 2440588;

+  j  = J + 32044;

+  g  = j / 146097;

+  dg = j % 146097;

+  c  = (((dg / 36524) + 1) * 3) / 4;

+  dc = dg - (c * 36524);

+  b  = dc / 1461;

+  db = dc % 1461;

+  a  = (((db / 365) + 1) * 3) / 4;

+  da = db - (a * 365);

+  y  = (g * 400) + (c * 100) + (b * 4) + a;

+  m  = (((da * 5) + 308) / 153) - 2;

+  d  = da - (((m + 4) * 153) / 5) + 122;

+

+  Time->Year  = y - 4800 + ((m + 2) / 12);

+  Time->Month = ((m + 2) % 12) + 1;

+  Time->Day   = d + 1;

+

+  ss = EpochSeconds % 60;

+  a  = (EpochSeconds - ss) / 60;

+  mm = a % 60;

+  b = (a - mm) / 60;

+  hh = b % 24;

+

+  Time->Hour        = hh;

+  Time->Minute      = mm;

+  Time->Second      = ss;

+  Time->Nanosecond  = 0;

+

+}

+

+/**

+  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)

+ **/

+UINTN

+EfiTimeToEpoch (

+  IN  EFI_TIME  *Time

+  )

+{

+  UINTN a;

+  UINTN y;

+  UINTN m;

+  UINTN JulianDate;  // Absolute Julian Date representation of the supplied Time

+  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY

+  UINTN EpochSeconds;

+

+  a = (14 - Time->Month) / 12 ;

+  y = Time->Year + 4800 - a;

+  m = Time->Month + (12*a) - 3;

+

+  JulianDate = Time->Day + ((153*m + 2)/5) + (365*y) + (y/4) - (y/100) + (y/400) - 32045;

+

+  ASSERT (JulianDate >= EPOCH_JULIAN_DATE);

+  EpochDays = JulianDate - EPOCH_JULIAN_DATE;

+

+  EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;

+

+  return EpochSeconds;

+}

+

+BOOLEAN

+IsLeapYear (

+  IN EFI_TIME   *Time

+  )

+{

+  if (Time->Year % 4 == 0) {

+    if (Time->Year % 100 == 0) {

+      if (Time->Year % 400 == 0) {

+        return TRUE;

+      } else {

+        return FALSE;

+      }

+    } else {

+      return TRUE;

+    }

+  } else {

+    return FALSE;

+  }

+}

+

+BOOLEAN

+DayValid (

+  IN  EFI_TIME  *Time

+  )

+{

+  STATIC CONST INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

+

+  if (Time->Day < 1 ||

+      Time->Day > DayOfMonth[Time->Month - 1] ||

+      (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))

+     ) {

+    return FALSE;

+  }

+

+  return TRUE;

+}

+

+/**

+  Returns the current time and date information, and the time-keeping capabilities

+  of the hardware platform.

+

+  @param  Time                   A pointer to storage to receive a snapshot of the current time.

+  @param  Capabilities           An optional pointer to a buffer to receive the real time clock

+                                 device's capabilities.

+

+  @retval EFI_SUCCESS            The operation completed successfully.

+  @retval EFI_INVALID_PARAMETER  Time is NULL.

+  @retval EFI_DEVICE_ERROR       The time could not be retrieved due to hardware error.

+  @retval EFI_SECURITY_VIOLATION The time could not be retrieved due to an authentication failure.

+

+**/

+EFI_STATUS

+EFIAPI

+LibGetTime (

+  OUT EFI_TIME                *Time,

+  OUT EFI_TIME_CAPABILITIES   *Capabilities

+  )

+{

+  EFI_STATUS  Status = EFI_SUCCESS;

+  UINT32      EpochSeconds;

+  INT16       TimeZone;

+  UINT8       Daylight;

+  UINTN       Size;

+

+  // Initialize the hardware if not already done

+  if (!mPL031Initialized) {

+    Status = InitializePL031 ();

+    if (EFI_ERROR (Status)) {

+      goto EXIT;

+    }

+  }

+

+  // Snapshot the time as early in the function call as possible

+  // On some platforms we may have access to a battery backed up hardware clock.

+  // If such RTC exists try to use it first.

+  Status = ArmPlatformSysConfigGet (SYS_CFG_RTC, &EpochSeconds);

+  if (Status == EFI_UNSUPPORTED) {

+    // Battery backed up hardware RTC does not exist, revert to PL031

+    EpochSeconds = MmioRead32 (mPL031RtcBase + PL031_RTC_DR_DATA_REGISTER);

+    Status = EFI_SUCCESS;

+  } else if (EFI_ERROR (Status)) {

+    // Battery backed up hardware RTC exists but could not be read due to error. Abort.

+    goto EXIT;

+  } else {

+    // Battery backed up hardware RTC exists and we read the time correctly from it.

+    // Now sync the PL031 to the new time.

+    MmioWrite32 (mPL031RtcBase + PL031_RTC_LR_LOAD_REGISTER, EpochSeconds);

+  }

+

+  // Ensure Time is a valid pointer

+  if (Time == NULL) {

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+  }

+

+  // Get the current time zone information from non-volatile storage

+  Size = sizeof (TimeZone);

+  Status = mRT->GetVariable (

+                  (CHAR16 *)mTimeZoneVariableName,

+                  &gEfiCallerIdGuid,

+                  NULL,

+                  &Size,

+                  (VOID *)&TimeZone

+                  );

+

+  if (EFI_ERROR (Status)) {

+    ASSERT(Status != EFI_INVALID_PARAMETER);

+    ASSERT(Status != EFI_BUFFER_TOO_SMALL);

+

+    if (Status != EFI_NOT_FOUND)

+      goto EXIT;

+

+    // The time zone variable does not exist in non-volatile storage, so create it.

+    Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;

+    // Store it

+    Status = mRT->SetVariable (

+                    (CHAR16 *)mTimeZoneVariableName,

+                    &gEfiCallerIdGuid,

+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+                    Size,

+                    (VOID *)&(Time->TimeZone)

+                    );

+    if (EFI_ERROR (Status)) {

+      DEBUG ((

+        EFI_D_ERROR,

+        "LibGetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",

+        mTimeZoneVariableName,

+        Status

+        ));

+      goto EXIT;

+    }

+  } else {

+    // Got the time zone

+    Time->TimeZone = TimeZone;

+

+    // Check TimeZone bounds:   -1440 to 1440 or 2047

+    if (((Time->TimeZone < -1440) || (Time->TimeZone > 1440))

+        && (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE)) {

+      Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;

+    }

+

+    // Adjust for the correct time zone

+    if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {

+      EpochSeconds += Time->TimeZone * SEC_PER_MIN;

+    }

+  }

+

+  // Get the current daylight information from non-volatile storage

+  Size = sizeof (Daylight);

+  Status = mRT->GetVariable (

+                  (CHAR16 *)mDaylightVariableName,

+                  &gEfiCallerIdGuid,

+                  NULL,

+                  &Size,

+                  (VOID *)&Daylight

+                  );

+

+  if (EFI_ERROR (Status)) {

+    ASSERT(Status != EFI_INVALID_PARAMETER);

+    ASSERT(Status != EFI_BUFFER_TOO_SMALL);

+

+    if (Status != EFI_NOT_FOUND)

+      goto EXIT;

+

+    // The daylight variable does not exist in non-volatile storage, so create it.

+    Time->Daylight = 0;

+    // Store it

+    Status = mRT->SetVariable (

+                    (CHAR16 *)mDaylightVariableName,

+                    &gEfiCallerIdGuid,

+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+                    Size,

+                    (VOID *)&(Time->Daylight)

+                    );

+    if (EFI_ERROR (Status)) {

+      DEBUG ((

+        EFI_D_ERROR,

+        "LibGetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",

+        mDaylightVariableName,

+        Status

+        ));

+      goto EXIT;

+    }

+  } else {

+    // Got the daylight information

+    Time->Daylight = Daylight;

+

+    // Adjust for the correct period

+    if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {

+      // Convert to adjusted time, i.e. spring forwards one hour

+      EpochSeconds += SEC_PER_HOUR;

+    }

+  }

+

+  // Convert from internal 32-bit time to UEFI time

+  EpochToEfiTime (EpochSeconds, Time);

+

+  // Update the Capabilities info

+  if (Capabilities != NULL) {

+    // PL031 runs at frequency 1Hz

+    Capabilities->Resolution  = PL031_COUNTS_PER_SECOND;

+    // Accuracy in ppm multiplied by 1,000,000, e.g. for 50ppm set 50,000,000

+    Capabilities->Accuracy    = (UINT32)PcdGet32 (PcdPL031RtcPpmAccuracy);

+    // FALSE: Setting the time does not clear the values below the resolution level

+    Capabilities->SetsToZero  = FALSE;

+  }

+

+  EXIT:

+  return Status;

+}

+

+

+/**

+  Sets the current local time and date information.

+

+  @param  Time                  A pointer to the current time.

+

+  @retval EFI_SUCCESS           The operation completed successfully.

+  @retval EFI_INVALID_PARAMETER A time field is out of range.

+  @retval EFI_DEVICE_ERROR      The time could not be set due due to hardware error.

+

+**/

+EFI_STATUS

+EFIAPI

+LibSetTime (

+  IN  EFI_TIME                *Time

+  )

+{

+  EFI_STATUS  Status;

+  UINTN       EpochSeconds;

+

+  // Check the input parameters are within the range specified by UEFI

+  if ((Time->Year   < 1900) ||

+       (Time->Year   > 9999) ||

+       (Time->Month  < 1   ) ||

+       (Time->Month  > 12  ) ||

+       (!DayValid (Time)    ) ||

+       (Time->Hour   > 23  ) ||

+       (Time->Minute > 59  ) ||

+       (Time->Second > 59  ) ||

+       (Time->Nanosecond > 999999999) ||

+       (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||

+       (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))

+    ) {

+    Status = EFI_INVALID_PARAMETER;

+    goto EXIT;

+  }

+

+  // Because the PL031 is a 32-bit counter counting seconds,

+  // the maximum time span is just over 136 years.

+  // Time is stored in Unix Epoch format, so it starts in 1970,

+  // Therefore it can not exceed the year 2106.

+  if ((Time->Year < 1970) || (Time->Year >= 2106)) {

+    Status = EFI_UNSUPPORTED;

+    goto EXIT;

+  }

+

+  // Initialize the hardware if not already done

+  if (!mPL031Initialized) {

+    Status = InitializePL031 ();

+    if (EFI_ERROR (Status)) {

+      goto EXIT;

+    }

+  }

+

+  EpochSeconds = EfiTimeToEpoch (Time);

+

+  // Adjust for the correct time zone, i.e. convert to UTC time zone

+  if (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) {

+    EpochSeconds -= Time->TimeZone * SEC_PER_MIN;

+  }

+

+  // TODO: Automatic Daylight activation

+

+  // Adjust for the correct period

+  if ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) {

+    // Convert to un-adjusted time, i.e. fall back one hour

+    EpochSeconds -= SEC_PER_HOUR;

+  }

+

+  // On some platforms we may have access to a battery backed up hardware clock.

+  //

+  // If such RTC exists then it must be updated first, before the PL031,

+  // to minimise any time drift. This is important because the battery backed-up

+  // RTC maintains the master time for the platform across reboots.

+  //

+  // If such RTC does not exist then the following function returns UNSUPPORTED.

+  Status = ArmPlatformSysConfigSet (SYS_CFG_RTC, EpochSeconds);

+  if ((EFI_ERROR (Status)) && (Status != EFI_UNSUPPORTED)){

+    // Any status message except SUCCESS and UNSUPPORTED indicates a hardware failure.

+    goto EXIT;

+  }

+

+

+  // Set the PL031

+  MmioWrite32 (mPL031RtcBase + PL031_RTC_LR_LOAD_REGISTER, EpochSeconds);

+

+  // The accesses to Variable Services can be very slow, because we may be writing to Flash.

+  // Do this after having set the RTC.

+

+  // Save the current time zone information into non-volatile storage

+  Status = mRT->SetVariable (

+                  (CHAR16 *)mTimeZoneVariableName,

+                  &gEfiCallerIdGuid,

+                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+                  sizeof (Time->TimeZone),

+                  (VOID *)&(Time->TimeZone)

+                  );

+  if (EFI_ERROR (Status)) {

+      DEBUG ((

+        EFI_D_ERROR,

+        "LibSetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",

+        mTimeZoneVariableName,

+        Status

+        ));

+    goto EXIT;

+  }

+

+  // Save the current daylight information into non-volatile storage

+  Status = mRT->SetVariable (

+                  (CHAR16 *)mDaylightVariableName,

+                  &gEfiCallerIdGuid,

+                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+                  sizeof(Time->Daylight),

+                  (VOID *)&(Time->Daylight)

+                  );

+  if (EFI_ERROR (Status)) {

+    DEBUG ((

+      EFI_D_ERROR,

+      "LibSetTime: Failed to save %s variable to non-volatile storage, Status = %r\n",

+      mDaylightVariableName,

+      Status

+      ));

+    goto EXIT;

+  }

+

+  EXIT:

+  return Status;

+}

+

+

+/**

+  Returns the current wakeup alarm clock setting.

+

+  @param  Enabled               Indicates if the alarm is currently enabled or disabled.

+  @param  Pending               Indicates if the alarm signal is pending and requires acknowledgement.

+  @param  Time                  The current alarm setting.

+

+  @retval EFI_SUCCESS           The alarm settings were returned.

+  @retval EFI_INVALID_PARAMETER Any parameter is NULL.

+  @retval EFI_DEVICE_ERROR      The wakeup time could not be retrieved due to a hardware error.

+

+**/

+EFI_STATUS

+EFIAPI

+LibGetWakeupTime (

+  OUT BOOLEAN     *Enabled,

+  OUT BOOLEAN     *Pending,

+  OUT EFI_TIME    *Time

+  )

+{

+  // Not a required feature

+  return EFI_UNSUPPORTED;

+}

+

+

+/**

+  Sets the system wakeup alarm clock time.

+

+  @param  Enabled               Enable or disable the wakeup alarm.

+  @param  Time                  If Enable is TRUE, the time to set the wakeup alarm for.

+

+  @retval EFI_SUCCESS           If Enable is TRUE, then the wakeup alarm was enabled. If

+                                Enable is FALSE, then the wakeup alarm was disabled.

+  @retval EFI_INVALID_PARAMETER A time field is out of range.

+  @retval EFI_DEVICE_ERROR      The wakeup time could not be set due to a hardware error.

+  @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.

+

+**/

+EFI_STATUS

+EFIAPI

+LibSetWakeupTime (

+  IN BOOLEAN      Enabled,

+  OUT EFI_TIME    *Time

+  )

+{

+  // Not a required feature

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Fixup internal data so that EFI can be call in virtual mode.

+  Call the passed in Child Notify event and convert any pointers in

+  lib to virtual mode.

+

+  @param[in]    Event   The Event that is being processed

+  @param[in]    Context Event Context

+**/

+VOID

+EFIAPI

+LibRtcVirtualNotifyEvent (

+  IN EFI_EVENT        Event,

+  IN VOID             *Context

+  )

+{

+  //

+  // Only needed if you are going to support the OS calling RTC functions in virtual mode.

+  // You will need to call EfiConvertPointer (). To convert any stored physical addresses

+  // to virtual address. After the OS transitions to calling in virtual mode, all future

+  // runtime calls will be made in virtual mode.

+  //

+  EfiConvertPointer (0x0, (VOID**)&mPL031RtcBase);

+  EfiConvertPointer (0x0, (VOID**)&mRT);

+  return;

+}

+

+/**

+  This is the declaration of an EFI image entry point. This can be the entry point to an application

+  written to this specification, an EFI boot service driver, or an EFI runtime driver.

+

+  @param  ImageHandle           Handle that identifies the loaded image.

+  @param  SystemTable           System Table for this image.

+

+  @retval EFI_SUCCESS           The operation completed successfully.

+

+**/

+EFI_STATUS

+EFIAPI

+LibRtcInitialize (

+  IN EFI_HANDLE                            ImageHandle,

+  IN EFI_SYSTEM_TABLE                      *SystemTable

+  )

+{

+  EFI_STATUS    Status;

+  EFI_HANDLE    Handle;

+

+  // Initialize RTC Base Address

+  mPL031RtcBase = PcdGet32 (PcdPL031RtcBase);

+

+  // Declare the controller as EFI_MEMORY_RUNTIME

+  Status = gDS->AddMemorySpace (

+                  EfiGcdMemoryTypeMemoryMappedIo,

+                  mPL031RtcBase, SIZE_4KB,

+                  EFI_MEMORY_UC | EFI_MEMORY_RUNTIME

+                  );

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  Status = gDS->SetMemorySpaceAttributes (mPL031RtcBase, SIZE_4KB, EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  // Setup the setters and getters

+  gRT->GetTime       = LibGetTime;

+  gRT->SetTime       = LibSetTime;

+  gRT->GetWakeupTime = LibGetWakeupTime;

+  gRT->SetWakeupTime = LibSetWakeupTime;

+

+  mRT = gRT;

+

+  // Install the protocol

+  Handle = NULL;

+  Status = gBS->InstallMultipleProtocolInterfaces (

+                  &Handle,

+                  &gEfiRealTimeClockArchProtocolGuid,  NULL,

+                  NULL

+                 );

+  ASSERT_EFI_ERROR (Status);

+

+  //

+  // Register for the virtual address change event

+  //

+  Status = gBS->CreateEventEx (

+                  EVT_NOTIFY_SIGNAL,

+                  TPL_NOTIFY,

+                  LibRtcVirtualNotifyEvent,

+                  NULL,

+                  &gEfiEventVirtualAddressChangeGuid,

+                  &mRtcVirtualAddrChangeEvent

+                  );

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
new file mode 100644
index 0000000..3a98fc7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
@@ -0,0 +1,46 @@
+#/** @file

+#

+# Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>

+# Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PL031RealTimeClockLib

+  FILE_GUID                      = 470DFB96-E205-4515-A75E-2E60F853E79D

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = RealTimeClockLib

+

+[Sources.common]

+  PL031RealTimeClockLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  IoLib

+  UefiLib

+  DebugLib

+  PcdLib

+  ArmPlatformSysConfigLib

+  DxeServicesTableLib

+  UefiRuntimeLib

+

+[Guids]

+  gEfiEventVirtualAddressChangeGuid

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase

+  gArmPlatformTokenSpaceGuid.PcdPL031RtcPpmAccuracy

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c
new file mode 100644
index 0000000..5c241fa
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointer.c
@@ -0,0 +1,91 @@
+/** @file

+  PEI Services Table Pointer Library.

+

+  This library is used for PEIM which does executed from flash device directly but

+  executed in memory.

+

+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>

+  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 <PiPei.h>

+#include <Library/ArmPlatformGlobalVariableLib.h>

+#include <Library/PeiServicesTablePointerLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+/**

+  Caches a pointer PEI Services Table.

+

+  Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer

+  in a platform specific manner.

+

+  If PeiServicesTablePointer is NULL, then ASSERT().

+

+  @param    PeiServicesTablePointer   The address of PeiServices pointer.

+**/

+VOID

+EFIAPI

+SetPeiServicesTablePointer (

+  IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer

+  )

+{

+  ASSERT (PeiServicesTablePointer != NULL);

+

+  ArmPlatformSetGlobalVariable (PcdGet32 (PcdPeiServicePtrGlobalOffset), sizeof(EFI_PEI_SERVICES **), &PeiServicesTablePointer);

+}

+

+/**

+  Retrieves the cached value of the PEI Services Table pointer.

+

+  Returns the cached value of the PEI Services Table pointer in a CPU specific manner

+  as specified in the CPU binding section of the Platform Initialization Pre-EFI

+  Initialization Core Interface Specification.

+

+  If the cached PEI Services Table pointer is NULL, then ASSERT().

+

+  @return  The pointer to PeiServices.

+

+**/

+CONST EFI_PEI_SERVICES**

+EFIAPI

+GetPeiServicesTablePointer (

+  VOID

+  )

+{

+  EFI_PEI_SERVICES **PeiServicesTablePointer;

+

+  ArmPlatformGetGlobalVariable (PcdGet32 (PcdPeiServicePtrGlobalOffset), sizeof(EFI_PEI_SERVICES **), &PeiServicesTablePointer);

+

+  return (CONST EFI_PEI_SERVICES**)PeiServicesTablePointer;

+}

+

+/**

+  Perform CPU specific actions required to migrate the PEI Services Table

+  pointer from temporary RAM to permanent RAM.

+

+  For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes

+  immediately preceding the Interrupt Descriptor Table (IDT) in memory.

+  For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes

+  immediately preceding the Interrupt Descriptor Table (IDT) in memory.

+  For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in

+  a dedicated CPU register.  This means that there is no memory storage

+  associated with storing the PEI Services Table pointer, so no additional

+  migration actions are required for Itanium or ARM CPUs.

+

+**/

+VOID

+EFIAPI

+MigratePeiServicesTablePointer (

+  VOID

+  )

+{

+  return;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
new file mode 100644
index 0000000..307cec8
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
@@ -0,0 +1,44 @@
+## @file

+# Instance of PEI Services Table Pointer Library using global variable for the table pointer.

+#

+# PEI Services Table Pointer Library implementation that retrieves a pointer to the

+#  PEI Services Table from a global variable. Not available to modules that execute from

+#  read-only memory.

+#

+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PeiServicesTablePointerLib

+  FILE_GUID                      = 1c747f6b-0a58-49ae-8ea3-0327a4fa10e3

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PeiServicesTablePointerLib|PEIM PEI_CORE SEC

+

+#

+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC (EBC is for build only)

+#

+

+[Sources]

+  PeiServicesTablePointer.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmPlatformGlobalVariableLib

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdPeiServicePtrGlobalOffset

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
new file mode 100644
index 0000000..c07fc0f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
@@ -0,0 +1,376 @@
+/** @file

+

+Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+

+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 "IntelBdsPlatform.h"

+

+///

+/// Predefined platform default time out value

+///

+UINT16                      gPlatformBootTimeOutDefault;

+

+EFI_STATUS

+EFIAPI

+PlatformIntelBdsConstructor (

+  IN EFI_HANDLE        ImageHandle,

+  IN EFI_SYSTEM_TABLE  *SystemTable

+  )

+{

+  gPlatformBootTimeOutDefault = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);

+  return EFI_SUCCESS;

+}

+

+//

+// BDS Platform Functions

+//

+/**

+  Platform Bds init. Include the platform firmware vendor, revision

+  and so crc check.

+

+**/

+VOID

+EFIAPI

+PlatformBdsInit (

+  VOID

+  )

+{

+}

+

+STATIC

+EFI_STATUS

+GetConsoleDevicePathFromVariable (

+  IN  CHAR16*             ConsoleVarName,

+  IN  CHAR16*             DefaultConsolePaths,

+  OUT EFI_DEVICE_PATH**   DevicePaths

+  )

+{

+  EFI_STATUS                Status;

+  UINTN                     Size;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;

+  CHAR16*                   DevicePathStr;

+  CHAR16*                   NextDevicePathStr;

+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;

+

+  Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);

+  if (EFI_ERROR(Status)) {

+    // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)

+    if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {

+      *DevicePaths = NULL;

+      return EFI_SUCCESS;

+    }

+

+    Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);

+    ASSERT_EFI_ERROR(Status);

+

+    DevicePathInstances = NULL;

+

+    // Extract the Device Path instances from the multi-device path string

+    while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {

+      NextDevicePathStr = StrStr (DefaultConsolePaths, L";");

+      if (NextDevicePathStr == NULL) {

+        DevicePathStr = DefaultConsolePaths;

+        DefaultConsolePaths = NULL;

+      } else {

+        DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof(CHAR16), DefaultConsolePaths);

+        *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';

+        DefaultConsolePaths = NextDevicePathStr;

+        if (DefaultConsolePaths[0] == L';') {

+          DefaultConsolePaths++;

+        }

+      }

+

+      DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);

+      ASSERT(DevicePathInstance != NULL);

+      DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);

+

+      if (NextDevicePathStr != NULL) {

+        FreePool (DevicePathStr);

+      }

+      FreePool (DevicePathInstance);

+    }

+

+    // Set the environment variable with this device path multi-instances

+    Size = GetDevicePathSize (DevicePathInstances);

+    if (Size > 0) {

+      gRT->SetVariable (

+          ConsoleVarName,

+          &gEfiGlobalVariableGuid,

+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,

+          Size,

+          DevicePathInstances

+          );

+    } else {

+      Status = EFI_INVALID_PARAMETER;

+    }

+  }

+

+  if (!EFI_ERROR(Status)) {

+    *DevicePaths = DevicePathInstances;

+  }

+  return Status;

+}

+

+STATIC

+EFI_STATUS

+InitializeConsolePipe (

+  IN EFI_DEVICE_PATH    *ConsoleDevicePaths,

+  IN EFI_GUID           *Protocol,

+  OUT EFI_HANDLE        *Handle,

+  OUT VOID*             *Interface

+  )

+{

+  EFI_STATUS                Status;

+  UINTN                     Size;

+  UINTN                     NoHandles;

+  EFI_HANDLE                *Buffer;

+  EFI_DEVICE_PATH_PROTOCOL* DevicePath;

+

+  // Connect all the Device Path Consoles

+  while (ConsoleDevicePaths != NULL) {

+    DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);

+

+    Status = BdsConnectDevicePath (DevicePath, Handle, NULL);

+    DEBUG_CODE_BEGIN();

+      if (EFI_ERROR(Status)) {

+        // We convert back to the text representation of the device Path

+        EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;

+        CHAR16* DevicePathTxt;

+        EFI_STATUS Status;

+

+        Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);

+        if (!EFI_ERROR(Status)) {

+          DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);

+

+          DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));

+

+          FreePool (DevicePathTxt);

+        }

+      }

+    DEBUG_CODE_END();

+

+    // If the console splitter driver is not supported by the platform then use the first Device Path

+    // instance for the console interface.

+    if (!EFI_ERROR(Status) && (*Interface == NULL)) {

+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);

+    }

+  }

+

+  // No Device Path has been defined for this console interface. We take the first protocol implementation

+  if (*Interface == NULL) {

+    Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);

+    if (EFI_ERROR (Status)) {

+      BdsConnectAllDrivers ();

+      Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);

+    }

+

+    if (!EFI_ERROR(Status)) {

+      *Handle = Buffer[0];

+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);

+      ASSERT_EFI_ERROR (Status);

+    }

+    FreePool (Buffer);

+  } else {

+    Status = EFI_SUCCESS;

+  }

+

+  return Status;

+}

+

+/**

+  Connect the predefined platform default console device. Always try to find

+  and enable the vga device if have.

+

+  @param PlatformConsole          Predefined platform default console device array.

+

+  @retval EFI_SUCCESS             Success connect at least one ConIn and ConOut

+                                  device, there must have one ConOut device is

+                                  active vga device.

+  @return Return the status of BdsLibConnectAllDefaultConsoles ()

+

+**/

+EFI_STATUS

+PlatformBdsConnectConsole (

+  VOID

+  )

+{

+  EFI_STATUS                Status;

+  EFI_DEVICE_PATH*          ConOutDevicePaths;

+  EFI_DEVICE_PATH*          ConInDevicePaths;

+  EFI_DEVICE_PATH*          ConErrDevicePaths;

+

+  // By getting the Console Device Paths from the environment variables before initializing the console pipe, we

+  // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface

+  // of newly installed console drivers

+  Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+  Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+  Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);

+  ASSERT_EFI_ERROR (Status);

+

+  // Initialize the Consoles

+  Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);

+  ASSERT_EFI_ERROR (Status);

+  Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);

+  ASSERT_EFI_ERROR (Status);

+  Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);

+  if (EFI_ERROR(Status)) {

+    // In case of error, we reuse the console output for the error output

+    gST->StandardErrorHandle = gST->ConsoleOutHandle;

+    gST->StdErr = gST->ConOut;

+  }

+

+  return Status;

+}

+

+/**

+  Connect with predefined platform connect sequence,

+  the OEM/IBV can customize with their own connect sequence.

+**/

+VOID

+PlatformBdsConnectSequence (

+  VOID

+  )

+{

+}

+

+/**

+  Load the predefined driver option, OEM/IBV can customize this

+  to load their own drivers

+

+  @param BdsDriverLists  - The header of the driver option link list.

+

+**/

+VOID

+PlatformBdsGetDriverOption (

+  IN OUT LIST_ENTRY              *BdsDriverLists

+  )

+{

+}

+

+/**

+  Perform the platform diagnostic, such like test memory. OEM/IBV also

+  can customize this function to support specific platform diagnostic.

+

+  @param MemoryTestLevel  The memory test intensive level

+  @param QuietBoot        Indicate if need to enable the quiet boot

+  @param BaseMemoryTest   A pointer to BdsMemoryTest()

+

+**/

+VOID

+PlatformBdsDiagnostics (

+  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,

+  IN BOOLEAN                     QuietBoot,

+  IN BASEM_MEMORY_TEST           BaseMemoryTest

+  )

+{

+}

+

+/**

+  The function will execute with as the platform policy, current policy

+  is driven by boot mode. IBV/OEM can customize this code for their specific

+  policy action.

+

+  @param  DriverOptionList        The header of the driver option link list

+  @param  BootOptionList          The header of the boot option link list

+  @param  ProcessCapsules         A pointer to ProcessCapsules()

+  @param  BaseMemoryTest          A pointer to BaseMemoryTest()

+

+**/

+VOID

+EFIAPI

+PlatformBdsPolicyBehavior (

+  IN LIST_ENTRY                      *DriverOptionList,

+  IN LIST_ENTRY                      *BootOptionList,

+  IN PROCESS_CAPSULES                ProcessCapsules,

+  IN BASEM_MEMORY_TEST               BaseMemoryTest

+  )

+{

+  EFI_STATUS Status;

+

+  Status = PlatformBdsConnectConsole ();

+  ASSERT_EFI_ERROR (Status);

+}

+

+/**

+  Hook point after a boot attempt succeeds. We don't expect a boot option to

+  return, so the UEFI 2.0 specification defines that you will default to an

+  interactive mode and stop processing the BootOrder list in this case. This

+  is also a platform implementation and can be customized by IBV/OEM.

+

+  @param  Option                  Pointer to Boot Option that succeeded to boot.

+

+**/

+VOID

+EFIAPI

+PlatformBdsBootSuccess (

+  IN  BDS_COMMON_OPTION *Option

+  )

+{

+}

+

+/**

+  Hook point after a boot attempt fails.

+

+  @param  Option                  Pointer to Boot Option that failed to boot.

+  @param  Status                  Status returned from failed boot.

+  @param  ExitData                Exit data returned from failed boot.

+  @param  ExitDataSize            Exit data size returned from failed boot.

+

+**/

+VOID

+EFIAPI

+PlatformBdsBootFail (

+  IN  BDS_COMMON_OPTION  *Option,

+  IN  EFI_STATUS         Status,

+  IN  CHAR16             *ExitData,

+  IN  UINTN              ExitDataSize

+  )

+{

+}

+

+/**

+  This function locks platform flash that is not allowed to be updated during normal boot path.

+  The flash layout is platform specific.

+**/

+VOID

+EFIAPI

+PlatformBdsLockNonUpdatableFlash (

+  VOID

+  )

+{

+  return;

+}

+

+

+/**

+  Lock the ConsoleIn device in system table. All key

+  presses will be ignored until the Password is typed in. The only way to

+  disable the password is to type it in to a ConIn device.

+

+  @param  Password        Password used to lock ConIn device.

+

+  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.

+  @retval EFI_UNSUPPORTED Password not found

+

+**/

+EFI_STATUS

+EFIAPI

+LockKeyboards (

+  IN  CHAR16    *Password

+  )

+{

+    return EFI_UNSUPPORTED;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.h b/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.h
new file mode 100644
index 0000000..a244ac9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.h
@@ -0,0 +1,35 @@
+/** @file

+  Head file for BDS Platform specific code

+

+Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>

+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 _INTEL_BDS_PLATFORM_H_

+#define _INTEL_BDS_PLATFORM_H_

+

+#include <Protocol/DevicePathFromText.h>

+#include <Protocol/DevicePathToText.h>

+

+#include <Library/BaseMemoryLib.h>

+#include <Library/BdsLib.h>

+#include <Library/DebugLib.h>

+#include <Library/DevicePathLib.h>

+#include <Library/UefiBootServicesTableLib.h>

+#include <Library/UefiRuntimeServicesTableLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/BaseLib.h>

+#include <Library/PcdLib.h>

+#include <Library/GenericBdsLib.h>

+#include <Library/PlatformBdsLib.h>

+

+#include <Guid/GlobalVariable.h>

+

+#endif // _INTEL_BDS_PLATFORM_H

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf
new file mode 100644
index 0000000..235589a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PlatformIntelBdsLib/PlatformIntelBdsLib.inf
@@ -0,0 +1,65 @@
+## @file

+#  Implementation for PlatformBdsLib library class interfaces.

+#  using ARM Platform framework.

+#

+#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>

+#  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = PlatformIntelBdsLib

+  FILE_GUID                      = 67780d14-60eb-4894-ab7c-eed6af427f9f

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PlatformBdsLib|DXE_DRIVER

+  CONSTRUCTOR                    = PlatformIntelBdsConstructor

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+#  VALID_ARCHITECTURES           = ARM AARCH64

+#

+

+[Sources]

+  IntelBdsPlatform.c

+  IntelBdsPlatform.h

+

+[Packages]

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec

+

+[LibraryClasses]

+  BaseLib

+  BaseMemoryLib

+  BdsLib

+  DebugLib

+  DevicePathLib

+  MemoryAllocationLib

+  UefiBootServicesTableLib

+  PcdLib

+  GenericBdsLib

+

+[Guids]

+  gArmGlobalVariableGuid

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths

+  gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths

+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformBootTimeOut

+

+[Protocols]

+  gEfiDevicePathFromTextProtocolGuid

+  gEfiDevicePathToTextProtocolGuid

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c
new file mode 100755
index 0000000..8932e10
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointer.c
@@ -0,0 +1,60 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <PiPei.h>

+#include <Library/ArmPlatformGlobalVariableLib.h>

+#include <Library/PrePiHobListPointerLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+/**

+  Returns the pointer to the HOB list.

+

+  This function returns the pointer to first HOB in the list.

+

+  @return The pointer to the HOB list.

+

+**/

+VOID *

+EFIAPI

+PrePeiGetHobList (

+  VOID

+  )

+{

+  VOID* HobList;

+

+  ArmPlatformGetGlobalVariable (PcdGet32 (PcdHobListPtrGlobalOffset), sizeof(VOID*), &HobList);

+

+  return HobList;

+}

+

+

+

+/**

+  Updates the pointer to the HOB list.

+

+  @param  HobList       Hob list pointer to store

+

+**/

+EFI_STATUS

+EFIAPI

+PrePeiSetHobList (

+  IN  VOID      *HobList

+  )

+{

+  ArmPlatformSetGlobalVariable (PcdGet32 (PcdHobListPtrGlobalOffset), sizeof(VOID*), &HobList);

+

+  return EFI_SUCCESS;

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
new file mode 100755
index 0000000..16b201e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
@@ -0,0 +1,35 @@
+#/** @file

+#

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PrePiHobListPointerLib

+  FILE_GUID                      = d751d880-5ee2-11e0-b93e-0002a5d5c51b

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PrePiHobListPointerLib

+

+[Sources]

+  PrePiHobListPointer.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+

+[LibraryClasses]

+  ArmPlatformGlobalVariableLib

+

+[FixedPcd.common]

+  gArmPlatformTokenSpaceGuid.PcdHobListPtrGlobalOffset

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c b/uefi/linaro-edk2/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c
new file mode 100644
index 0000000..16798e9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c
@@ -0,0 +1,256 @@
+/** @file

+

+  Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>

+  Copyright (c) 2011 - 2014, ARM 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.

+

+**/

+

+#include <Base.h>

+

+#include <Library/BaseLib.h>

+#include <Library/TimerLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+#include <Library/IoLib.h>

+#include <Drivers/SP804Timer.h>

+

+#define SP804_TIMER_METRONOME_BASE    ((UINTN)PcdGet32 (PcdSP804TimerMetronomeBase))

+#define SP804_TIMER_PERFORMANCE_BASE  ((UINTN)PcdGet32 (PcdSP804TimerPerformanceBase))

+

+// Setup SP810's Timer2 for managing delay functions. And Timer3 for Performance counter

+// Note: ArmVE's Timer0 and Timer1 are used by TimerDxe.

+RETURN_STATUS

+EFIAPI

+TimerConstructor (

+  VOID

+  )

+{

+  // Check if the Metronome Timer is already initialized

+  if ((MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) == 0) {

+    // Configure the Metronome Timer for free running operation, 32 bits, no prescaler, and interrupt disabled

+    MmioWrite32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1);

+

+    // Start the Metronome Timer ticking

+    MmioOr32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);

+  }

+

+  // Check if the Performance Timer is already initialized

+  if ((MmioRead32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG) & SP804_TIMER_CTRL_ENABLE) == 0) {

+    // Configure the Performance timer for free running operation, 32 bits, no prescaler, interrupt disabled

+    MmioWrite32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1);

+

+    // Start the Performance Timer ticking

+    MmioOr32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);

+  }

+

+  return RETURN_SUCCESS;

+}

+

+/**

+  Stalls the CPU for at least the given number of microseconds.

+

+  Stalls the CPU for the number of microseconds specified by MicroSeconds.

+  The hardware timer is 32 bits.

+  The maximum possible delay is (0xFFFFFFFF / TimerFrequencyMHz), i.e. ([32bits] / FreqInMHz)

+  For example:

+  +----------------+------------+----------+----------+

+  | TimerFrequency |  MaxDelay  | MaxDelay | MaxDelay |

+  |     (MHz)      |    (us)    |   (s)    |  (min)   |

+  +----------------+------------+----------+----------+

+  |        1       | 0xFFFFFFFF |   4294   |   71.5   |

+  |        5       | 0x33333333 |    859   |   14.3   |

+  |       10       | 0x19999999 |    429   |    7.2   |

+  |       50       | 0x051EB851 |     86   |    1.4   |

+  +----------------+------------+----------+----------+

+  If it becomes necessary to support higher delays, then consider using the

+  real time clock.

+

+  During this delay, the cpu is not yielded to any other process, with one exception:

+  events that are triggered off a timer and which execute at a higher TPL than

+  this function. These events may call MicroSecondDelay (or NanoSecondDelay) to

+  fulfil their own needs.

+  Therefore, this function must be re-entrant, as it may be interrupted and re-started.

+

+  @param  MicroSeconds  The minimum number of microseconds to delay.

+

+  @return The value of MicroSeconds inputted.

+

+**/

+UINTN

+EFIAPI

+MicroSecondDelay (

+  IN  UINTN MicroSeconds

+  )

+{

+  UINT64    DelayTicks64;         // Convert from microseconds to timer ticks, more bits to detect over-range conditions.

+  UINTN     DelayTicks;           // Convert from microseconds to timer ticks, native size for general calculations.

+  UINTN     StartTicks;           // Timer value snapshot at the start of the delay

+  UINTN     TargetTicks;          // Timer value to signal the end of the delay

+  UINTN     CurrentTicks;         // Current value of the 64-bit timer value at any given moment

+

+  // If we snapshot the timer at the start of the delay function then we minimise unaccounted overheads.

+  StartTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);

+

+  // We are operating at the limit of 32bits. For the range checking work in 64 bits to avoid overflows.

+  DelayTicks64 = MultU64x32((UINT64)MicroSeconds, PcdGet32(PcdSP804TimerFrequencyInMHz));

+

+  // We are limited to 32 bits.

+  // If the specified delay is exactly equal to the max range of the timer,

+  // then the start will be equal to the stop plus one timer overflow (wrap-around).

+  // To avoid having to check for that, reduce the maximum acceptable range by 1 tick,

+  // i.e. reject delays equal or greater than the max range of the timer.

+  if (DelayTicks64 >= (UINT64)SP804_MAX_TICKS) {

+    DEBUG((EFI_D_ERROR,"MicroSecondDelay: ERROR: MicroSeconds=%d exceed SP804 count range. Max MicroSeconds=%d\n",

+      MicroSeconds,

+      ((UINTN)SP804_MAX_TICKS/PcdGet32(PcdSP804TimerFrequencyInMHz))));

+  }

+  ASSERT(DelayTicks64 < (UINT64)SP804_MAX_TICKS);

+

+  // From now on do calculations only in native bit size.

+  DelayTicks = (UINTN)DelayTicks64;

+

+  // Calculate the target value of the timer.

+

+  //Note: SP804 timer is counting down

+  if (StartTicks >= DelayTicks) {

+    // In this case we do not expect a wrap-around of the timer to occur.

+    // CurrentTicks must be less than StartTicks and higher than TargetTicks.

+    // If this is not the case, then the delay has been reached and may even have been exceeded if this

+    // function was suspended by a higher priority interrupt.

+

+    TargetTicks = StartTicks - DelayTicks;

+

+    do {

+      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);

+    } while ((CurrentTicks > TargetTicks) && (CurrentTicks <= StartTicks));

+

+  } else {

+    // In this case TargetTicks is larger than StartTicks.

+    // This means we expect a wrap-around of the timer to occur and we must wait for it.

+    // Before the wrap-around, CurrentTicks must be less than StartTicks and less than TargetTicks.

+    // After the wrap-around, CurrentTicks must be larger than StartTicks and larger than TargetTicks.

+    // If this is not the case, then the delay has been reached and may even have been exceeded if this

+    // function was suspended by a higher priority interrupt.

+

+    // The order of operations is essential to avoid arithmetic overflow problems

+    TargetTicks = ((UINTN)SP804_MAX_TICKS - DelayTicks) + StartTicks;

+

+    // First wait for the wrap-around to occur

+    do {

+      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);

+    } while (CurrentTicks <= StartTicks);

+

+    // Then wait for the target

+    do {

+      CurrentTicks = MmioRead32 (SP804_TIMER_METRONOME_BASE + SP804_TIMER_CURRENT_REG);

+    } while (CurrentTicks > TargetTicks);

+  }

+

+  return MicroSeconds;

+}

+

+/**

+  Stalls the CPU for at least the given number of nanoseconds.

+

+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.

+

+  When the timer frequency is 1MHz, each tick corresponds to 1 microsecond.

+  Therefore, the nanosecond delay will be rounded up to the nearest 1 microsecond.

+

+  @param  NanoSeconds The minimum number of nanoseconds to delay.

+

+  @return The value of NanoSeconds inputted.

+

+**/

+UINTN

+EFIAPI

+NanoSecondDelay (

+  IN  UINTN NanoSeconds

+  )

+{

+  UINTN  MicroSeconds;

+

+  // Round up to 1us Tick Number

+  MicroSeconds = NanoSeconds / 1000;

+  MicroSeconds += ((NanoSeconds % 1000) == 0) ? 0 : 1;

+

+  MicroSecondDelay (MicroSeconds);

+

+  return NanoSeconds;

+}

+

+/**

+  Retrieves the current value of a 64-bit free running performance counter.

+

+  The counter can either count up by 1 or count down by 1. If the physical

+  performance counter counts by a larger increment, then the counter values

+  must be translated. The properties of the counter can be retrieved from

+  GetPerformanceCounterProperties().

+

+  @return The current value of the free running performance counter.

+

+**/

+UINT64

+EFIAPI

+GetPerformanceCounter (

+  VOID

+  )

+{

+  // Free running 64-bit/32-bit counter is needed here.

+  // Don't think we need this to boot, just to do performance profile

+  UINT64 Value;

+  Value = MmioRead32 (SP804_TIMER_PERFORMANCE_BASE + SP804_TIMER_CURRENT_REG);

+  return Value;

+}

+

+

+/**

+  Retrieves the 64-bit frequency in Hz and the range of performance counter

+  values.

+

+  If StartValue is not NULL, then the value that the performance counter starts

+  with immediately after is it rolls over is returned in StartValue. If

+  EndValue is not NULL, then the value that the performance counter end with

+  immediately before it rolls over is returned in EndValue. The 64-bit

+  frequency of the performance counter in Hz is always returned. If StartValue

+  is less than EndValue, then the performance counter counts up. If StartValue

+  is greater than EndValue, then the performance counter counts down. For

+  example, a 64-bit free running counter that counts up would have a StartValue

+  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter

+  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.

+

+  @param  StartValue  The value the performance counter starts with when it

+                      rolls over.

+  @param  EndValue    The value that the performance counter ends with before

+                      it rolls over.

+

+  @return The frequency in Hz.

+

+**/

+UINT64

+EFIAPI

+GetPerformanceCounterProperties (

+  OUT UINT64  *StartValue,  OPTIONAL

+  OUT UINT64  *EndValue     OPTIONAL

+  )

+{

+  if (StartValue != NULL) {

+    // Timer starts with the reload value

+    *StartValue = 0xFFFFFFFF;

+  }

+

+  if (EndValue != NULL) {

+    // Timer counts down to 0x0

+    *EndValue = (UINT64)0ULL;

+  }

+

+  return PcdGet64 (PcdEmbeddedPerformanceCounterFrequencyInHz);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf
new file mode 100644
index 0000000..fb5cc18
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf
@@ -0,0 +1,44 @@
+#/** @file

+# Timer library implementation

+#

+#

+#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = SP804TimerLib

+  FILE_GUID                      = 09cefa99-0d07-487f-a651-fb44f094b1c7

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = TimerLib

+

+  CONSTRUCTOR                    = TimerConstructor

+

+[Sources.common]

+  SP804TimerLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  IoLib

+  BaseLib

+

+[Pcd]

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerFrequencyInMHz

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerPerformanceBase

+  gArmPlatformTokenSpaceGuid.PcdSP804TimerMetronomeBase

+  gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/License.txt b/uefi/linaro-edk2/ArmPlatformPkg/License.txt
new file mode 100755
index 0000000..e827fe5
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/License.txt
@@ -0,0 +1,25 @@
+Copyright (c) 2011-2012, ARM Limited. All rights reserved.

+

+Redistribution and use in source and binary forms, with or without

+modification, are permitted provided that the following conditions

+are met:

+

+* Redistributions of source code must retain the above copyright

+  notice, this list of conditions and the following disclaimer.

+* Redistributions in binary form must reproduce the above copyright

+  notice, this list of conditions and the following disclaimer in

+  the documentation and/or other materials provided with the

+  distribution.

+

+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS

+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE

+COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER

+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT

+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN

+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE

+POSSIBILITY OF SUCH DAMAGE.

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
new file mode 100755
index 0000000..577b288
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
@@ -0,0 +1,174 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <PiPei.h>

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/PcdLib.h>

+

+VOID

+BuildMemoryTypeInformationHob (

+  VOID

+  );

+

+VOID

+InitMmu (

+  VOID

+  )

+{

+  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable;

+  VOID                          *TranslationTableBase;

+  UINTN                         TranslationTableSize;

+  RETURN_STATUS                 Status;

+

+  // Get Virtual Memory Map from the Platform Library

+  ArmPlatformGetVirtualMemoryMap (&MemoryTable);

+

+  //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in

+  //      DRAM (even at the top of DRAM as it is the first permanent memory allocation)

+  Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);

+  if (EFI_ERROR (Status)) {

+    DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));

+  }

+}

+

+/*++

+

+Routine Description:

+

+

+

+Arguments:

+

+  FileHandle  - Handle of the file being invoked.

+  PeiServices - Describes the list of possible PEI Services.

+

+Returns:

+

+  Status -  EFI_SUCCESS if the boot mode could be set

+

+--*/

+EFI_STATUS

+EFIAPI

+MemoryPeim (

+  IN EFI_PHYSICAL_ADDRESS               UefiMemoryBase,

+  IN UINT64                             UefiMemorySize

+  )

+{

+  EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;

+  UINT64                      ResourceLength;

+  EFI_PEI_HOB_POINTERS        NextHob;

+  EFI_PHYSICAL_ADDRESS        FdTop;

+  EFI_PHYSICAL_ADDRESS        SystemMemoryTop;

+  EFI_PHYSICAL_ADDRESS        ResourceTop;

+  BOOLEAN                     Found;

+

+  // Ensure PcdSystemMemorySize has been set

+  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);

+

+  //

+  // Now, the permanent memory has been installed, we can call AllocatePages()

+  //

+  ResourceAttributes = (

+      EFI_RESOURCE_ATTRIBUTE_PRESENT |

+      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |

+      EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |

+      EFI_RESOURCE_ATTRIBUTE_TESTED

+  );

+

+  // Reserved the memory space occupied by the firmware volume

+  BuildResourceDescriptorHob (

+      EFI_RESOURCE_SYSTEM_MEMORY,

+      ResourceAttributes,

+      PcdGet64 (PcdSystemMemoryBase),

+      PcdGet64 (PcdSystemMemorySize)

+  );

+

+  SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize);

+  FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize);

+

+  // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE

+  // core to overwrite this area we must mark the region with the attribute non-present

+  if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) {

+    Found = FALSE;

+

+    // Search for System Memory Hob that contains the firmware

+    NextHob.Raw = GetHobList ();

+    while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {

+      if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&

+          (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) &&

+          (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength))

+      {

+        ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute;

+        ResourceLength = NextHob.ResourceDescriptor->ResourceLength;

+        ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength;

+

+        if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) {

+          if (SystemMemoryTop == FdTop) {

+            NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT;

+          } else {

+            // Create the System Memory HOB for the firmware with the non-present attribute

+            BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,

+                                        ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,

+                                        PcdGet64 (PcdFdBaseAddress),

+                                        PcdGet32 (PcdFdSize));

+

+            // Top of the FD is system memory available for UEFI

+            NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize);

+            NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize);

+          }

+        } else {

+          // Create the System Memory HOB for the firmware with the non-present attribute

+          BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,

+                                      ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,

+                                      PcdGet64 (PcdFdBaseAddress),

+                                      PcdGet32 (PcdFdSize));

+

+          // Update the HOB

+          NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart;

+

+          // If there is some memory available on the top of the FD then create a HOB

+          if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) {

+            // Create the System Memory HOB for the remaining region (top of the FD)

+            BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,

+                                        ResourceAttributes,

+                                        FdTop,

+                                        ResourceTop - FdTop);

+          }

+        }

+        Found = TRUE;

+        break;

+      }

+      NextHob.Raw = GET_NEXT_HOB (NextHob);

+    }

+

+    ASSERT(Found);

+  }

+

+  // Build Memory Allocation Hob

+  InitMmu ();

+

+  if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {

+    // Optional feature that helps prevent EFI memory map fragmentation.

+    BuildMemoryTypeInformationHob ();

+  }

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
new file mode 100755
index 0000000..1e5b93e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
@@ -0,0 +1,66 @@
+#/** @file

+#

+#  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmMemoryInitPeiLib

+  FILE_GUID                      = 55ddb6e0-70b5-11e0-b33e-0002a5d5c51b

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PlatformPeiLib

+

+[Sources]

+  MemoryInitPeiLib.c

+

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  HobLib

+  ArmLib

+  ArmPlatformLib

+

+[Guids]

+  gEfiMemoryTypeInformationGuid

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize

+

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData

+

+[Pcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c
new file mode 100755
index 0000000..bc1ab2f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c
@@ -0,0 +1,154 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <PiPei.h>

+

+//

+// The protocols, PPI and GUID defintions for this module

+//

+#include <Ppi/MasterBootMode.h>

+#include <Ppi/BootInRecoveryMode.h>

+#include <Guid/MemoryTypeInformation.h>

+//

+// The Library classes this module consumes

+//

+#include <Library/ArmPlatformLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/PeimEntryPoint.h>

+#include <Library/PeiServicesLib.h>

+#include <Library/PcdLib.h>

+

+EFI_STATUS

+EFIAPI

+MemoryPeim (

+  IN EFI_PHYSICAL_ADDRESS               UefiMemoryBase,

+  IN UINT64                             UefiMemorySize

+  );

+

+// May want to put this into a library so you only need the PCD settings if you are using the feature?

+VOID

+BuildMemoryTypeInformationHob (

+  VOID

+  )

+{

+  EFI_MEMORY_TYPE_INFORMATION   Info[10];

+

+  Info[0].Type          = EfiACPIReclaimMemory;

+  Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);

+  Info[1].Type          = EfiACPIMemoryNVS;

+  Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);

+  Info[2].Type          = EfiReservedMemoryType;

+  Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);

+  Info[3].Type          = EfiRuntimeServicesData;

+  Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);

+  Info[4].Type          = EfiRuntimeServicesCode;

+  Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);

+  Info[5].Type          = EfiBootServicesCode;

+  Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode);

+  Info[6].Type          = EfiBootServicesData;

+  Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData);

+  Info[7].Type          = EfiLoaderCode;

+  Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);

+  Info[8].Type          = EfiLoaderData;

+  Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);

+

+  // Terminator for the list

+  Info[9].Type          = EfiMaxMemoryType;

+  Info[9].NumberOfPages = 0;

+

+  BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));

+}

+

+/*++

+

+Routine Description:

+

+

+

+Arguments:

+

+  FileHandle  - Handle of the file being invoked.

+  PeiServices - Describes the list of possible PEI Services.

+

+Returns:

+

+  Status -  EFI_SUCCESS if the boot mode could be set

+

+--*/

+EFI_STATUS

+EFIAPI

+InitializeMemory (

+  IN       EFI_PEI_FILE_HANDLE  FileHandle,

+  IN CONST EFI_PEI_SERVICES     **PeiServices

+  )

+{

+  EFI_STATUS                            Status;

+  UINTN                                 SystemMemoryBase;

+  UINTN                                 SystemMemoryTop;

+  UINTN                                 FdBase;

+  UINTN                                 FdTop;

+  UINTN                                 UefiMemoryBase;

+

+  DEBUG ((EFI_D_ERROR, "Memory Init PEIM Loaded\n"));

+

+  //

+  // Initialize the System Memory (DRAM)

+  //

+  if (!FeaturePcdGet (PcdSystemMemoryInitializeInSec)) {

+    // In case the DRAM has not been initialized by the secure firmware

+    ArmPlatformInitializeSystemMemory ();

+  }

+

+  // Ensure PcdSystemMemorySize has been set

+  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);

+

+  SystemMemoryBase = (UINTN)PcdGet64 (PcdSystemMemoryBase);

+  SystemMemoryTop = SystemMemoryBase + (UINTN)PcdGet64 (PcdSystemMemorySize);

+  FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress);

+  FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize);

+

+  //

+  // Declare the UEFI memory to PEI

+  //

+

+  // In case the firmware has been shadowed in the System Memory

+  if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) {

+    // Check if there is enough space between the top of the system memory and the top of the

+    // firmware to place the UEFI memory (for PEI & DXE phases)

+    if (SystemMemoryTop - FdTop >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) {

+      UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);

+    } else {

+      // Check there is enough space for the UEFI memory

+      ASSERT (SystemMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) <= FdBase);

+

+      UefiMemoryBase = FdBase - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);

+    }

+  } else {

+    // Check the Firmware does not overlapped with the system memory

+    ASSERT ((FdBase < SystemMemoryBase) || (FdBase >= SystemMemoryTop));

+    ASSERT ((FdTop <= SystemMemoryBase) || (FdTop > SystemMemoryTop));

+

+    UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);

+  }

+

+  Status = PeiServicesInstallPeiMemory (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));

+  ASSERT_EFI_ERROR (Status);

+

+  // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)

+  Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));

+  ASSERT_EFI_ERROR (Status);

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf
new file mode 100755
index 0000000..6374b63
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf
@@ -0,0 +1,75 @@
+#/** @file

+#

+#  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+#  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                    = 0x00010005

+  BASE_NAME                      = MemoryInit

+  FILE_GUID                      = c61ef796-b50d-4f98-9f78-4f6f79d800d5

+  MODULE_TYPE                    = PEIM

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = InitializeMemory

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC ARM

+#

+

+[Sources]

+  MemoryInitPeim.c

+  MemoryInitPeiLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  PeimEntryPoint

+  DebugLib

+  HobLib

+  ArmLib

+  ArmPlatformLib

+

+[Guids]

+  gEfiMemoryTypeInformationGuid

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize

+

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData

+

+[Pcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+

+[Depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeiLib.c b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeiLib.c
new file mode 100755
index 0000000..a27b168
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeiLib.c
@@ -0,0 +1,30 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <PiPei.h>

+

+#include <Library/ArmPlatformLib.h>

+#include <Library/HobLib.h>

+#include <Library/PcdLib.h>

+

+EFI_STATUS

+EFIAPI

+PlatformPeim (

+  VOID

+  )

+{

+  BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));

+

+  return EFI_SUCCESS;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
new file mode 100755
index 0000000..314789d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
@@ -0,0 +1,53 @@
+#/** @file

+#

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformPeiLib

+  FILE_GUID                      = 49d37060-70b5-11e0-aa2d-0002a5d5c51b

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = PlatformPeiLib

+

+[Sources]

+  PlatformPeiLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  DebugLib

+  HobLib

+  ArmPlatformLib

+

+[Ppis]

+  gEfiPeiMasterBootModePpiGuid                  # PPI ALWAYS_PRODUCED

+  gEfiPeiBootInRecoveryModePpiGuid              # PPI SOMETIMES_PRODUCED

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdFvSize

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize

+

+[depex]

+  TRUE

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeim.c b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeim.c
new file mode 100755
index 0000000..ca33ae5
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeim.c
@@ -0,0 +1,138 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include <PiPei.h>

+

+//

+// The protocols, PPI and GUID defintions for this module

+//

+#include <Ppi/ArmGlobalVariable.h>

+#include <Ppi/MasterBootMode.h>

+#include <Ppi/BootInRecoveryMode.h>

+#include <Ppi/GuidedSectionExtraction.h>

+//

+// The Library classes this module consumes

+//

+#include <Library/ArmPlatformLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DebugLib.h>

+#include <Library/HobLib.h>

+#include <Library/PeimEntryPoint.h>

+#include <Library/PeiServicesLib.h>

+#include <Library/PcdLib.h>

+

+#include <Guid/ArmGlobalVariableHob.h>

+

+EFI_STATUS

+EFIAPI

+InitializePlatformPeim (

+  IN       EFI_PEI_FILE_HANDLE  FileHandle,

+  IN CONST EFI_PEI_SERVICES     **PeiServices

+  );

+

+EFI_STATUS

+EFIAPI

+PlatformPeim (

+  VOID

+  );

+

+//

+// Module globals

+//

+EFI_PEI_PPI_DESCRIPTOR  mPpiListBootMode = {

+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),

+  &gEfiPeiMasterBootModePpiGuid,

+  NULL

+};

+

+EFI_PEI_PPI_DESCRIPTOR  mPpiListRecoveryBootMode = {

+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),

+  &gEfiPeiBootInRecoveryModePpiGuid,

+  NULL

+};

+

+VOID

+EFIAPI

+BuildGlobalVariableHob (

+  IN EFI_PHYSICAL_ADDRESS         GlobalVariableBase,

+  IN UINT32                       GlobalVariableSize

+  )

+{

+  EFI_STATUS                Status;

+  ARM_HOB_GLOBAL_VARIABLE   *Hob;

+

+  Status = PeiServicesCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE), (VOID**)&Hob);

+  if (!EFI_ERROR(Status)) {

+    CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);

+    Hob->GlobalVariableBase = GlobalVariableBase;

+    Hob->GlobalVariableSize = GlobalVariableSize;

+  }

+}

+

+/*++

+

+Routine Description:

+

+

+

+Arguments:

+

+  FileHandle  - Handle of the file being invoked.

+  PeiServices - Describes the list of possible PEI Services.

+

+Returns:

+

+  Status -  EFI_SUCCESS if the boot mode could be set

+

+--*/

+EFI_STATUS

+EFIAPI

+InitializePlatformPeim (

+  IN       EFI_PEI_FILE_HANDLE  FileHandle,

+  IN CONST EFI_PEI_SERVICES     **PeiServices

+  )

+{

+  EFI_STATUS                    Status;

+  UINTN                         BootMode;

+  ARM_GLOBAL_VARIABLE_PPI       *ArmGlobalVariablePpi;

+  EFI_PHYSICAL_ADDRESS          GlobalVariableBase;

+

+  DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));

+

+  PlatformPeim ();

+

+  Status = PeiServicesLocatePpi (&gArmGlobalVariablePpiGuid, 0, NULL, (VOID**)&ArmGlobalVariablePpi);

+  if (!EFI_ERROR(Status)) {

+    Status = ArmGlobalVariablePpi->GetGlobalVariableMemory (&GlobalVariableBase);

+

+    if (!EFI_ERROR(Status)) {

+      // Declare the Global Variable HOB

+      BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));

+    }

+  }

+

+  BootMode  = ArmPlatformGetBootMode ();

+  Status    = (**PeiServices).SetBootMode (PeiServices, (UINT8) BootMode);

+  ASSERT_EFI_ERROR (Status);

+

+  Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListBootMode);

+  ASSERT_EFI_ERROR (Status);

+

+  if (BootMode == BOOT_IN_RECOVERY_MODE) {

+    Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListRecoveryBootMode);

+    ASSERT_EFI_ERROR (Status);

+  }

+

+  return Status;

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeim.inf b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeim.inf
new file mode 100755
index 0000000..3822b09
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PlatformPei/PlatformPeim.inf
@@ -0,0 +1,69 @@
+#/** @file

+#

+#  Copyright (c) 2011-2012, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PlatformPei

+  FILE_GUID                      = 2ad0fc59-2314-4bf3-8633-13fa22a624a0

+  MODULE_TYPE                    = PEIM

+  VERSION_STRING                 = 1.0

+

+  ENTRY_POINT                    = InitializePlatformPeim

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC ARM

+#

+

+[Sources]

+  PlatformPeim.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  PeimEntryPoint

+  DebugLib

+  HobLib

+  ArmPlatformLib

+  PlatformPeiLib

+

+[Ppis]

+  gEfiPeiMasterBootModePpiGuid                  # PPI ALWAYS_PRODUCED

+  gEfiPeiBootInRecoveryModePpiGuid              # PPI SOMETIMES_PRODUCED

+  gArmGlobalVariablePpiGuid

+

+[Guids]

+  gArmGlobalVariableGuid

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdFvSize

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize

+

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

+

+[Depex]

+  TRUE

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/ArchPrePeiCore.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/ArchPrePeiCore.c
new file mode 100644
index 0000000..e1842f2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/ArchPrePeiCore.c
@@ -0,0 +1,52 @@
+/** @file

+*  Main file supporting the transition to PEI Core in Normal World for Versatile Express

+*

+*  Copyright (c) 2012-2013, ARM 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.

+*

+**/

+

+#include <Library/PrintLib.h>

+#include <Library/SerialPortLib.h>

+

+#include "PrePeiCore.h"

+

+VOID

+PeiCommonExceptionEntry (

+  IN UINT32 Entry,

+  IN UINTN LR

+  )

+{

+  CHAR8           Buffer[100];

+  UINTN           CharCount;

+

+  switch (Entry) {

+  case EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Synchronous Exception at 0x%X\n\r", LR);

+    break;

+  case EXCEPT_AARCH64_IRQ:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r", LR);

+    break;

+  case EXCEPT_AARCH64_FIQ:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r", LR);

+    break;

+  case EXCEPT_AARCH64_SERROR:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SError/Abort Exception at 0x%X\n\r", LR);

+    break;

+  default:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r", LR);

+    break;

+  }

+

+  SerialPortWrite ((UINT8 *) Buffer, CharCount);

+

+  while(1);

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/Exception.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/Exception.S
new file mode 100644
index 0000000..cdc8d92
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/Exception.S
@@ -0,0 +1,81 @@
+#

+#  Copyright (c) 2011-2014, ARM 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.

+#

+#

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <AutoGen.h>

+

+.text

+.align 11

+

+GCC_ASM_EXPORT(PeiVectorTable)

+

+//============================================================

+//Default Exception Handlers

+//============================================================

+

+ASM_PFX(PeiVectorTable):

+

+

+#define TO_HANDLER                                              \

+   EL1_OR_EL2(x1)                                               \

+1: mrs  x1, elr_el1    /* EL1 Exception Link Register */       ;\

+   b    3f                                                     ;\

+2: mrs  x1, elr_el2    /* EL2 Exception Link Register */       ;\

+3: bl   ASM_PFX(PeiCommonExceptionEntry)                       ;

+

+

+//

+// Default Exception handlers: There is no plan to return from any of these exceptions.

+// No context saving at all.

+//

+

+.align 7

+_DefaultSyncExceptHandler_t:

+  mov  x0, #EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS

+  TO_HANDLER

+

+.align 7

+_DefaultIrq_t:

+  mov  x0, #EXCEPT_AARCH64_IRQ

+  TO_HANDLER

+

+.align 7

+_DefaultFiq_t:

+  mov  x0, #EXCEPT_AARCH64_FIQ

+  TO_HANDLER

+

+.align 7

+_DefaultSError_t:

+  mov  x0, #EXCEPT_AARCH64_SERROR

+  TO_HANDLER

+

+.align 7

+_DefaultSyncExceptHandler_h:

+  mov  x0, #EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS

+  TO_HANDLER

+

+.align 7

+_DefaultIrq_h:

+  mov  x0, #EXCEPT_AARCH64_IRQ

+  TO_HANDLER

+

+.align 7

+_DefaultFiq_h:

+  mov  x0, #EXCEPT_AARCH64_FIQ

+  TO_HANDLER

+

+.align 7

+_DefaultSError_h:

+  mov  x0, #EXCEPT_AARCH64_SERROR

+  TO_HANDLER

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/Helper.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/Helper.S
new file mode 100644
index 0000000..8e23b03
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/Helper.S
@@ -0,0 +1,48 @@
+#========================================================================================

+#  Copyright (c) 2011-2013, ARM 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.

+#

+#=======================================================================================

+

+#include <AsmMacroIoLibV8.h>

+#include <Chipset/AArch64.h>

+

+#start of the code section

+.text

+.align 3

+

+GCC_ASM_EXPORT(SetupExceptionLevel1)

+GCC_ASM_EXPORT(SetupExceptionLevel2)

+

+// Setup EL1 while in EL1

+ASM_PFX(SetupExceptionLevel1):

+   mov  x5, x30                   // Save LR

+

+   mov  x0, #CPACR_CP_FULL_ACCESS

+   bl   ASM_PFX(ArmWriteCpacr)    // Disable copro traps to EL1

+

+   ret  x5

+

+// Setup EL2 while in EL2

+ASM_PFX(SetupExceptionLevel2):

+   msr     sctlr_el2, xzr

+   mrs     x0, hcr_el2            // Read EL2 Hypervisor configuration Register

+

+   // Send all interrupts to their respective Exception levels for EL2

+   orr     x0, x0, #(1 << 3)      // Enable EL2 FIQ

+   orr     x0, x0, #(1 << 4)      // Enable EL2 IRQ

+   orr     x0, x0, #(1 << 5)      // Enable EL2 SError and Abort

+   msr     hcr_el2, x0            // Write back our settings

+

+   msr     cptr_el2, xzr          // Disable copro traps to EL2

+

+   ret

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/PrePeiCoreEntryPoint.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/PrePeiCoreEntryPoint.S
new file mode 100644
index 0000000..b84190c
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/PrePeiCoreEntryPoint.S
@@ -0,0 +1,110 @@
+//

+//  Copyright (c) 2011-2014, ARM 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.

+//

+//

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_IMPORT(CEntryPoint)

+GCC_ASM_IMPORT(ArmPlatformGetCorePosition)

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmReadMpidr)

+GCC_ASM_IMPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(_ModuleEntryPoint)

+

+StartupAddr: .8byte CEntryPoint

+

+ASM_PFX(_ModuleEntryPoint):

+  // Do early platform specific actions

+  bl    ASM_PFX(ArmPlatformPeiBootAction)

+

+// NOTE: We could be booting from EL3, EL2 or EL1. Need to correctly detect

+//       and configure the system accordingly. EL2 is default if possible.

+// If we started in EL3 we need to switch and run at EL2.

+// If we are running at EL2 stay in EL2

+// If we are starting at EL1 stay in EL1.

+

+// If started at EL3 Sec is run and switches to EL2 before jumping to PEI.

+// If started at EL1 or EL2 Sec jumps directly to PEI without making any

+// changes.

+

+// Which EL are we running at? Every EL needs some level of setup...

+// We should not run this code in EL3

+  EL1_OR_EL2(x0)

+1:bl    ASM_PFX(SetupExceptionLevel1)

+  b     ASM_PFX(MainEntryPoint)

+2:bl    ASM_PFX(SetupExceptionLevel2)

+  b     ASM_PFX(MainEntryPoint)

+

+ASM_PFX(MainEntryPoint):

+  // Identify CPU ID

+  bl    ASM_PFX(ArmReadMpidr)

+  // Keep a copy of the MpId register value

+  mov   x5, x0

+

+  // Is it the Primary Core ?

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresStackBase), x1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)

+  add   x1, x1, x2

+

+  // x0 is equal to 1 if I am the primary core

+  cmp   x0, #1

+  b.eq   _SetupPrimaryCoreStack

+

+_SetupSecondaryCoreStack:

+  // x1 contains the base of the secondary stacks

+

+  // Get the Core Position

+  mov   x6, x1      // Save base of the secondary stacks

+  mov   x0, x5

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+  // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack

+  add   x0, x0, #1

+

+  // StackOffset = CorePos * StackSize

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x2)

+  mul   x0, x0, x2

+  // SP = StackBase + StackOffset

+  add   sp, x6, x0

+

+_PrepareArguments:

+  // The PEI Core Entry Point has been computed by GenFV and stored in the second entry of the Reset Vector

+  LoadConstantToReg (FixedPcdGet64(PcdFvBaseAddress), x2)

+  add   x2, x2, #8

+  ldr   x1, [x2]

+

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   x3, StartupAddr

+

+  // Jump to PrePeiCore C code

+  //    x0 = mp_id

+  //    x1 = pei_core_address

+  mov   x0, x5

+  blr   x3

+

+_SetupPrimaryCoreStack:

+  // x1 contains the top of the primary stack

+  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), x2)

+

+  // The reserved space for global variable must be 16-bytes aligned for pushing

+  // 128-bit variable on the stack

+  SetPrimaryStack (x1, x2, x3, x4)

+  b     _PrepareArguments

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/SwitchStack.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/SwitchStack.S
new file mode 100644
index 0000000..8d83510
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/AArch64/SwitchStack.S
@@ -0,0 +1,43 @@
+#------------------------------------------------------------------------------

+#

+# Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>

+# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+# Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>

+#

+# 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.

+#

+#------------------------------------------------------------------------------

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(SecSwitchStack)

+

+

+

+#/**

+#  This allows the caller to switch the stack and return

+#

+# @param      StackDelta     Signed amount by which to modify the stack pointer

+#

+# @return     Nothing. Goes to the Entry Point passing in the new parameters

+#

+#**/

+#VOID

+#EFIAPI

+#SecSwitchStack (

+#  VOID  *StackDelta

+#  )#

+#

+ASM_PFX(SecSwitchStack):

+    mov   x1, sp

+    add   x1, x0, x1

+    mov   sp, x1

+    ret

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/ArchPrePeiCore.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/ArchPrePeiCore.c
new file mode 100644
index 0000000..6a25039
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/ArchPrePeiCore.c
@@ -0,0 +1,62 @@
+/** @file

+*  Main file supporting the transition to PEI Core in Normal World for Versatile Express

+*

+*  Copyright (c) 2012, ARM 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.

+*

+**/

+

+#include <Library/PrintLib.h>

+#include <Library/SerialPortLib.h>

+

+#include "PrePeiCore.h"

+

+VOID

+PeiCommonExceptionEntry (

+  IN UINT32 Entry,

+  IN UINTN LR

+  )

+{

+  CHAR8           Buffer[100];

+  UINTN           CharCount;

+

+  switch (Entry) {

+  case 0:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);

+    break;

+  case 1:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);

+    break;

+  case 2:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);

+    break;

+  case 3:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);

+    break;

+  case 4:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);

+    break;

+  case 5:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);

+    break;

+  case 6:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);

+    break;

+  case 7:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);

+    break;

+  default:

+    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);

+    break;

+  }

+  SerialPortWrite ((UINT8 *) Buffer, CharCount);

+  while(1);

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/Exception.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/Exception.S
new file mode 100644
index 0000000..afd284a
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/Exception.S
@@ -0,0 +1,102 @@
+//

+//  Copyright (c) 2011, ARM 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.

+#

+#

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <AutoGen.h>

+

+#start of the code section

+.text

+.align 5

+

+# IMPORT

+GCC_ASM_IMPORT(PeiCommonExceptionEntry)

+

+# EXPORT

+GCC_ASM_EXPORT(PeiVectorTable)

+

+//============================================================

+//Default Exception Handlers

+//============================================================

+

+

+ASM_PFX(PeiVectorTable):

+  b _DefaultResetHandler

+  b _DefaultUndefined

+  b _DefaultSWI

+  b _DefaultPrefetchAbort

+  b _DefaultDataAbort

+  b _DefaultReserved

+  b _DefaultIrq

+  b _DefaultFiq

+

+//

+// Default Exception handlers: There is no plan to return from any of these exceptions.

+// No context saving at all.

+//

+_DefaultResetHandler:

+  mov  r1, lr

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #0

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

+_DefaultUndefined:

+  sub  r1, LR, #4

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #1

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

+_DefaultSWI:

+  sub  r1, LR, #4

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #2

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

+_DefaultPrefetchAbort:

+  sub  r1, LR, #4

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #3

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

+_DefaultDataAbort:

+  sub  r1, LR, #8

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #4

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

+_DefaultReserved:

+  mov  r1, lr

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #5

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

+_DefaultIrq:

+  sub  r1, LR, #4

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #6

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

+_DefaultFiq:

+  sub  r1, LR, #4

+  # Switch to SVC for common stack

+  cps  #0x13

+  mov  r0, #7

+  blx  ASM_PFX(PeiCommonExceptionEntry)

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/Exception.asm b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/Exception.asm
new file mode 100644
index 0000000..de438f9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/Exception.asm
@@ -0,0 +1,91 @@
+//

+//  Copyright (c) 2011, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <AutoGen.h>

+

+  IMPORT  PeiCommonExceptionEntry

+  EXPORT  PeiVectorTable

+

+  PRESERVE8

+  AREA    PrePeiCoreException, CODE, READONLY, CODEALIGN, ALIGN=5

+

+//============================================================

+//Default Exception Handlers

+//============================================================

+

+

+PeiVectorTable

+  b _DefaultResetHandler

+  b _DefaultUndefined

+  b _DefaultSWI

+  b _DefaultPrefetchAbort

+  b _DefaultDataAbort

+  b _DefaultReserved

+  b _DefaultIrq

+  b _DefaultFiq

+

+//

+// Default Exception handlers: There is no plan to return from any of these exceptions.

+// No context saving at all.

+//

+_DefaultResetHandler

+   mov  r1, lr

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #0

+   blx   PeiCommonExceptionEntry

+

+_DefaultUndefined

+   sub  r1, LR, #4

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #1

+   blx   PeiCommonExceptionEntry

+

+_DefaultSWI

+   sub  r1, LR, #4

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #2

+   blx   PeiCommonExceptionEntry

+

+_DefaultPrefetchAbort

+   sub  r1, LR, #4

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #3

+   blx   PeiCommonExceptionEntry

+

+_DefaultDataAbort

+   sub  r1, LR, #8

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #4

+   blx   PeiCommonExceptionEntry

+

+_DefaultReserved

+   mov  r1, lr

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #5

+   blx   PeiCommonExceptionEntry

+

+_DefaultIrq

+   sub  r1, LR, #4

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #6

+   blx   PeiCommonExceptionEntry

+

+_DefaultFiq

+   sub  r1, LR, #4

+   cps       #0x13                     ; Switch to SVC for common stack

+   mov  r0, #7

+   blx   PeiCommonExceptionEntry

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/PrePeiCoreEntryPoint.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/PrePeiCoreEntryPoint.S
new file mode 100644
index 0000000..a6f19af
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/PrePeiCoreEntryPoint.S
@@ -0,0 +1,94 @@
+//

+//  Copyright (c) 2011-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_IMPORT(CEntryPoint)

+GCC_ASM_IMPORT(ArmPlatformGetCorePosition)

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmReadMpidr)

+GCC_ASM_IMPORT(ArmPlatformPeiBootAction)

+GCC_ASM_EXPORT(_ModuleEntryPoint)

+

+StartupAddr: .word    CEntryPoint

+

+ASM_PFX(_ModuleEntryPoint):

+  // Do early platform specific actions

+  bl    ASM_PFX(ArmPlatformPeiBootAction)

+

+  // Identify CPU ID

+  bl    ASM_PFX(ArmReadMpidr)

+  // Keep a copy of the MpId register value

+  mov   r5, r0

+

+  // Is it the Primary Core ?

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresStackBase), r1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)

+  add   r1, r1, r2

+

+  // r0 is equal to 1 if I am the primary core

+  cmp   r0, #1

+  beq   _SetupPrimaryCoreStack

+

+_SetupSecondaryCoreStack:

+  // r1 contains the base of the secondary stacks

+

+  // Get the Core Position

+  mov   r6, r1      // Save base of the secondary stacks

+  mov   r0, r5

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+  // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack

+  add   r0, r0, #1

+

+  // StackOffset = CorePos * StackSize

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r2)

+  mul   r0, r0, r2

+  // SP = StackBase + StackOffset

+  add   sp, r6, r0

+

+_PrepareArguments:

+  // The PEI Core Entry Point has been computed by GenFV and stored in the second entry of the Reset Vector

+  LoadConstantToReg (FixedPcdGet32(PcdFvBaseAddress), r2)

+  add   r2, r2, #4

+  ldr   r1, [r2]

+

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   r3, StartupAddr

+

+  // Jump to PrePeiCore C code

+  //    r0 = mp_id

+  //    r1 = pei_core_address

+  mov   r0, r5

+  blx   r3

+

+_SetupPrimaryCoreStack:

+  // r1 contains the top of the primary stack

+  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)

+

+  // The reserved space for global variable must be 8-bytes aligned for pushing

+  // 64-bit variable on the stack

+  SetPrimaryStack (r1, r2, r3)

+  b     _PrepareArguments

+

+_NeverReturn:

+  b _NeverReturn

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/PrePeiCoreEntryPoint.asm b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/PrePeiCoreEntryPoint.asm
new file mode 100644
index 0000000..edf479f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/PrePeiCoreEntryPoint.asm
@@ -0,0 +1,98 @@
+//

+//  Copyright (c) 2011-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  IMPORT  CEntryPoint

+  IMPORT  ArmPlatformGetCorePosition

+  IMPORT  ArmPlatformIsPrimaryCore

+  IMPORT  ArmReadMpidr

+  IMPORT  ArmPlatformPeiBootAction

+  EXPORT  _ModuleEntryPoint

+

+  PRESERVE8

+  AREA    PrePeiCoreEntryPoint, CODE, READONLY

+

+StartupAddr        DCD      CEntryPoint

+

+_ModuleEntryPoint

+  // Do early platform specific actions

+  bl    ArmPlatformPeiBootAction

+

+  // Identify CPU ID

+  bl    ArmReadMpidr

+  // Keep a copy of the MpId register value

+  mov   r5, r0

+

+  // Is it the Primary Core ?

+  bl    ArmPlatformIsPrimaryCore

+

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresStackBase), r1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)

+  add   r1, r1, r2

+

+  // r0 is equal to 1 if I am the primary core

+  cmp   r0, #1

+  beq   _SetupPrimaryCoreStack

+

+_SetupSecondaryCoreStack

+  // r1 contains the base of the secondary stacks

+

+  // Get the Core Position

+  mov   r6, r1      // Save base of the secondary stacks

+  mov   r0, r5

+  bl    ArmPlatformGetCorePosition

+  // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack

+  add   r0, r0, #1

+

+  // StackOffset = CorePos * StackSize

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r2)

+  mul   r0, r0, r2

+  // SP = StackBase + StackOffset

+  add   sp, r6, r0

+

+_PrepareArguments

+  // The PEI Core Entry Point has been computed by GenFV and stored in the second entry of the Reset Vector

+  LoadConstantToReg (FixedPcdGet32(PcdFvBaseAddress), r2)

+  add   r2, r2, #4

+  ldr   r1, [r2]

+

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   r3, StartupAddr

+

+  // Jump to PrePeiCore C code

+  //    r0 = mp_id

+  //    r1 = pei_core_address

+  mov   r0, r5

+  blx   r3

+

+_SetupPrimaryCoreStack

+  // r1 contains the top of the primary stack

+  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)

+

+  // The reserved space for global variable must be 8-bytes aligned for pushing

+  // 64-bit variable on the stack

+  SetPrimaryStack (r1, r2, r3)

+  b     _PrepareArguments

+

+_NeverReturn

+  b _NeverReturn

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/SwitchStack.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/SwitchStack.S
new file mode 100644
index 0000000..509dc20
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/SwitchStack.S
@@ -0,0 +1,43 @@
+#------------------------------------------------------------------------------

+#

+# Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>

+# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+# 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.

+#

+#------------------------------------------------------------------------------

+

+.text

+.align 3

+

+GCC_ASM_EXPORT(SecSwitchStack)

+

+

+

+#/**

+#  This allows the caller to switch the stack and return

+#

+# @param      StackDelta     Signed amount by which to modify the stack pointer

+#

+# @return     Nothing. Goes to the Entry Point passing in the new parameters

+#

+#**/

+#VOID

+#EFIAPI

+#SecSwitchStack (

+#  VOID  *StackDelta

+#  )#

+#

+ASM_PFX(SecSwitchStack):

+    mov   R1, R13

+    add   R1, R0, R1

+    mov   R13, R1

+    bx    LR

+

+

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/SwitchStack.asm b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/SwitchStack.asm
new file mode 100644
index 0000000..cb1308f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/Arm/SwitchStack.asm
@@ -0,0 +1,38 @@
+;------------------------------------------------------------------------------

+;

+; Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>

+; Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>

+; 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.

+;

+;------------------------------------------------------------------------------

+

+    EXPORT SecSwitchStack

+

+    AREA   Switch_Stack, CODE, READONLY

+

+;/**

+;  This allows the caller to switch the stack and return

+;

+; @param      StackDelta     Signed amount by which to modify the stack pointer

+;

+; @return     Nothing. Goes to the Entry Point passing in the new parameters

+;

+;**/

+;VOID

+;EFIAPI

+;SecSwitchStack (

+;  VOID  *StackDelta

+;  );

+;

+SecSwitchStack

+    MOV   R1, SP

+    ADD   R1, R0, R1

+    MOV   SP, R1

+    BX    LR

+    END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/MainMPCore.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/MainMPCore.c
new file mode 100644
index 0000000..a86f739
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/MainMPCore.c
@@ -0,0 +1,158 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/ArmGicLib.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+#include "PrePeiCore.h"

+

+/*

+ * This is the main function for secondary cores. They loop around until a non Null value is written to

+ * SYS_FLAGS register.The SYS_FLAGS register is platform specific.

+ * Note:The secondary cores, while executing secondary_main, assumes that:

+ *      : SGI 0 is configured as Non-secure interrupt

+ *      : Priority Mask is configured to allow SGI 0

+ *      : Interrupt Distributor and CPU interfaces are enabled

+ *

+ */

+VOID

+EFIAPI

+SecondaryMain (

+  IN UINTN MpId

+  )

+{

+  EFI_STATUS              Status;

+  UINTN                   PpiListSize;

+  UINTN                   PpiListCount;

+  EFI_PEI_PPI_DESCRIPTOR  *PpiList;

+  ARM_MP_CORE_INFO_PPI    *ArmMpCoreInfoPpi;

+  UINTN                   Index;

+  UINTN                   ArmCoreCount;

+  ARM_CORE_INFO           *ArmCoreInfoTable;

+  UINT32                  ClusterId;

+  UINT32                  CoreId;

+  VOID                    (*SecondaryStart)(VOID);

+  UINTN                   SecondaryEntryAddr;

+  UINTN                   AcknowledgeInterrupt;

+  UINTN                   InterruptId;

+

+  ClusterId = GET_CLUSTER_ID(MpId);

+  CoreId    = GET_CORE_ID(MpId);

+

+  // Get the gArmMpCoreInfoPpiGuid

+  PpiListSize = 0;

+  ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);

+  PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);

+  for (Index = 0; Index < PpiListCount; Index++, PpiList++) {

+    if (CompareGuid (PpiList->Guid, &gArmMpCoreInfoPpiGuid) == TRUE) {

+      break;

+    }

+  }

+

+  // On MP Core Platform we must implement the ARM MP Core Info PPI

+  ASSERT (Index != PpiListCount);

+

+  ArmMpCoreInfoPpi = PpiList->Ppi;

+  ArmCoreCount = 0;

+  Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);

+  ASSERT_EFI_ERROR (Status);

+

+  // Find the core in the ArmCoreTable

+  for (Index = 0; Index < ArmCoreCount; Index++) {

+    if ((ArmCoreInfoTable[Index].ClusterId == ClusterId) && (ArmCoreInfoTable[Index].CoreId == CoreId)) {

+      break;

+    }

+  }

+

+  // The ARM Core Info Table must define every core

+  ASSERT (Index != ArmCoreCount);

+

+  // Clear Secondary cores MailBox

+  MmioWrite32 (ArmCoreInfoTable[Index].MailboxClearAddress, ArmCoreInfoTable[Index].MailboxClearValue);

+

+  do {

+    ArmCallWFI ();

+

+    // Read the Mailbox

+    SecondaryEntryAddr = MmioRead32 (ArmCoreInfoTable[Index].MailboxGetAddress);

+

+    // Acknowledge the interrupt and send End of Interrupt signal.

+    AcknowledgeInterrupt = ArmGicAcknowledgeInterrupt (PcdGet32 (PcdGicInterruptInterfaceBase), &InterruptId);

+    // Check if it is a valid interrupt ID

+    if (InterruptId < ArmGicGetMaxNumInterrupts (PcdGet32 (PcdGicDistributorBase))) {

+      // Got a valid SGI number hence signal End of Interrupt

+      ArmGicEndOfInterrupt (PcdGet32 (PcdGicInterruptInterfaceBase), AcknowledgeInterrupt);

+    }

+  } while (SecondaryEntryAddr == 0);

+

+  // Jump to secondary core entry point.

+  SecondaryStart = (VOID (*)())SecondaryEntryAddr;

+  SecondaryStart();

+

+  // The secondaries shouldn't reach here

+  ASSERT(FALSE);

+}

+

+VOID

+EFIAPI

+PrimaryMain (

+  IN  EFI_PEI_CORE_ENTRY_POINT  PeiCoreEntryPoint

+  )

+{

+  EFI_SEC_PEI_HAND_OFF        SecCoreData;

+  UINTN                       PpiListSize;

+  EFI_PEI_PPI_DESCRIPTOR      *PpiList;

+  UINTN                       TemporaryRamBase;

+  UINTN                       TemporaryRamSize;

+

+  CreatePpiList (&PpiListSize, &PpiList);

+

+  // Enable the GIC Distributor

+  ArmGicEnableDistributor (PcdGet32(PcdGicDistributorBase));

+

+  // If ArmVe has not been built as Standalone then we need to wake up the secondary cores

+  if (FeaturePcdGet (PcdSendSgiToBringUpSecondaryCores)) {

+    // Sending SGI to all the Secondary CPU interfaces

+    ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));

+  }

+

+  // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at

+  // the base of the primary core stack

+  PpiListSize = ALIGN_VALUE(PpiListSize, 0x4);

+  TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;

+  TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;

+

+  // Make sure the size is 8-byte aligned. Once divided by 2, the size should be 4-byte aligned

+  // to ensure the stack pointer is 4-byte aligned.

+  TemporaryRamSize = TemporaryRamSize - (TemporaryRamSize & (0x8-1));

+

+  //

+  // Bind this information into the SEC hand-off state

+  // Note: this must be in sync with the stuff in the asm file

+  // Note also:  HOBs (pei temp ram) MUST be above stack

+  //

+  SecCoreData.DataSize               = sizeof(EFI_SEC_PEI_HAND_OFF);

+  SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);

+  SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);

+  SecCoreData.TemporaryRamBase       = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)

+  SecCoreData.TemporaryRamSize       = TemporaryRamSize;

+  SecCoreData.PeiTemporaryRamBase    = SecCoreData.TemporaryRamBase;

+  SecCoreData.PeiTemporaryRamSize    = SecCoreData.TemporaryRamSize / 2;

+  SecCoreData.StackBase              = (VOID *)ALIGN_VALUE((UINTN)(SecCoreData.TemporaryRamBase) + SecCoreData.PeiTemporaryRamSize, 0x4);

+  SecCoreData.StackSize              = (TemporaryRamBase + TemporaryRamSize) - (UINTN)SecCoreData.StackBase;

+

+  // Jump to PEI core entry point

+  PeiCoreEntryPoint (&SecCoreData, PpiList);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/MainUniCore.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/MainUniCore.c
new file mode 100644
index 0000000..6317f17
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/MainUniCore.c
@@ -0,0 +1,67 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#include "PrePeiCore.h"

+

+VOID

+EFIAPI

+SecondaryMain (

+  IN UINTN MpId

+  )

+{

+  ASSERT(FALSE);

+}

+

+VOID

+EFIAPI

+PrimaryMain (

+  IN  EFI_PEI_CORE_ENTRY_POINT  PeiCoreEntryPoint

+  )

+{

+  EFI_SEC_PEI_HAND_OFF        SecCoreData;

+  UINTN                       PpiListSize;

+  EFI_PEI_PPI_DESCRIPTOR      *PpiList;

+  UINTN                       TemporaryRamBase;

+  UINTN                       TemporaryRamSize;

+

+  CreatePpiList (&PpiListSize, &PpiList);

+

+  // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at

+  // the base of the primary core stack

+  PpiListSize = ALIGN_VALUE(PpiListSize, 0x4);

+  TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;

+  TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;

+

+  // Make sure the size is 8-byte aligned. Once divided by 2, the size should be 4-byte aligned

+  // to ensure the stack pointer is 4-byte aligned.

+  TemporaryRamSize = TemporaryRamSize - (TemporaryRamSize & (0x8-1));

+

+  //

+  // Bind this information into the SEC hand-off state

+  // Note: this must be in sync with the stuff in the asm file

+  // Note also:  HOBs (pei temp ram) MUST be above stack

+  //

+  SecCoreData.DataSize               = sizeof(EFI_SEC_PEI_HAND_OFF);

+  SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);

+  SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);

+  SecCoreData.TemporaryRamBase       = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)

+  SecCoreData.TemporaryRamSize       = TemporaryRamSize;

+  SecCoreData.PeiTemporaryRamBase    = SecCoreData.TemporaryRamBase;

+  SecCoreData.PeiTemporaryRamSize    = SecCoreData.TemporaryRamSize / 2;

+  SecCoreData.StackBase              = (VOID *)ALIGN_VALUE((UINTN)(SecCoreData.TemporaryRamBase) + SecCoreData.PeiTemporaryRamSize, 0x4);

+  SecCoreData.StackSize              = (TemporaryRamBase + TemporaryRamSize) - (UINTN)SecCoreData.StackBase;

+

+  // Jump to PEI core entry point

+  (PeiCoreEntryPoint)(&SecCoreData, PpiList);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCore.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCore.c
new file mode 100644
index 0000000..43ae40d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCore.c
@@ -0,0 +1,163 @@
+/** @file

+*  Main file supporting the transition to PEI Core in Normal World for Versatile Express

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/BaseLib.h>

+#include <Library/DebugAgentLib.h>

+#include <Library/ArmLib.h>

+

+#include <Ppi/ArmGlobalVariable.h>

+

+#include "PrePeiCore.h"

+

+EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI   mTemporaryRamSupportPpi = { PrePeiCoreTemporaryRamSupport };

+ARM_GLOBAL_VARIABLE_PPI             mGlobalVariablePpi = { PrePeiCoreGetGlobalVariableMemory };

+

+EFI_PEI_PPI_DESCRIPTOR      gCommonPpiTable[] = {

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &gEfiTemporaryRamSupportPpiGuid,

+    &mTemporaryRamSupportPpi

+  },

+  {

+    EFI_PEI_PPI_DESCRIPTOR_PPI,

+    &gArmGlobalVariablePpiGuid,

+    &mGlobalVariablePpi

+  }

+};

+

+VOID

+CreatePpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  )

+{

+  EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;

+  UINTN                   PlatformPpiListSize;

+  UINTN                   ListBase;

+  EFI_PEI_PPI_DESCRIPTOR *LastPpi;

+

+  // Get the Platform PPIs

+  PlatformPpiListSize = 0;

+  ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);

+

+  // Copy the Common and Platform PPis in Temporrary Memory

+  ListBase = PcdGet64 (PcdCPUCoresStackBase);

+  CopyMem ((VOID*)ListBase, gCommonPpiTable, sizeof(gCommonPpiTable));

+  CopyMem ((VOID*)(ListBase + sizeof(gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);

+

+  // Set the Terminate flag on the last PPI entry

+  LastPpi = (EFI_PEI_PPI_DESCRIPTOR*)ListBase + ((sizeof(gCommonPpiTable) + PlatformPpiListSize) / sizeof(EFI_PEI_PPI_DESCRIPTOR)) - 1;

+  LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;

+

+  *PpiList     = (EFI_PEI_PPI_DESCRIPTOR*)ListBase;

+  *PpiListSize = sizeof(gCommonPpiTable) + PlatformPpiListSize;

+}

+

+VOID

+CEntryPoint (

+  IN  UINTN                     MpId,

+  IN  EFI_PEI_CORE_ENTRY_POINT  PeiCoreEntryPoint

+  )

+{

+  // Data Cache enabled on Primary core when MMU is enabled.

+  ArmDisableDataCache ();

+  // Invalidate Data cache

+  ArmInvalidateDataCache ();

+  // Invalidate instruction cache

+  ArmInvalidateInstructionCache ();

+  // Enable Instruction Caches on all cores.

+  ArmEnableInstructionCache ();

+

+  //

+  // Note: Doesn't have to Enable CPU interface in non-secure world,

+  // as Non-secure interface is already enabled in Secure world.

+  //

+

+  // Write VBAR - The Exception Vector table must be aligned to its requirement

+  // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure

+  // 'Align=4K' is defined into your FDF for this module.

+  ASSERT (((UINTN)PeiVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0);

+  ArmWriteVBar ((UINTN)PeiVectorTable);

+

+  //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.

+

+  // If not primary Jump to Secondary Main

+  if (ArmPlatformIsPrimaryCore (MpId)) {

+    // Initialize the Debug Agent for Source Level Debugging

+    InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);

+    SaveAndSetDebugTimerInterrupt (TRUE);

+

+    // Initialize the platform specific controllers

+    ArmPlatformInitialize (MpId);

+

+    // Goto primary Main.

+    PrimaryMain (PeiCoreEntryPoint);

+  } else {

+    SecondaryMain (MpId);

+  }

+

+  // PEI Core should always load and never return

+  ASSERT (FALSE);

+}

+

+EFI_STATUS

+EFIAPI

+PrePeiCoreTemporaryRamSupport (

+  IN CONST EFI_PEI_SERVICES   **PeiServices,

+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,

+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,

+  IN UINTN                    CopySize

+  )

+{

+  VOID                             *OldHeap;

+  VOID                             *NewHeap;

+  VOID                             *OldStack;

+  VOID                             *NewStack;

+

+  OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;

+  NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));

+

+  OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));

+  NewStack = (VOID*)(UINTN)PermanentMemoryBase;

+

+  //

+  // Migrate the temporary memory stack to permanent memory stack.

+  //

+  CopyMem (NewStack, OldStack, CopySize >> 1);

+

+  //

+  // Migrate the temporary memory heap to permanent memory heap.

+  //

+  CopyMem (NewHeap, OldHeap, CopySize >> 1);

+

+  SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);

+

+  return EFI_SUCCESS;

+}

+

+EFI_STATUS

+PrePeiCoreGetGlobalVariableMemory (

+  OUT EFI_PHYSICAL_ADDRESS    *GlobalVariableBase

+  )

+{

+  ASSERT (GlobalVariableBase != NULL);

+

+  *GlobalVariableBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) +

+                        (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) -

+                        (UINTN)PcdGet32 (PcdPeiGlobalVariableSize);

+

+  return EFI_SUCCESS;

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCore.h b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCore.h
new file mode 100644
index 0000000..20684e2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCore.h
@@ -0,0 +1,83 @@
+/** @file

+*  Main file supporting the transition to PEI Core in Normal World for Versatile Express

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+#ifndef __PREPEICORE_H_

+#define __PREPEICORE_H_

+

+#include <Library/ArmLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/PcdLib.h>

+

+#include <PiPei.h>

+#include <Ppi/TemporaryRamSupport.h>

+

+VOID

+CreatePpiList (

+  OUT UINTN                   *PpiListSize,

+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList

+  );

+

+EFI_STATUS

+EFIAPI

+PrePeiCoreTemporaryRamSupport (

+  IN CONST EFI_PEI_SERVICES   **PeiServices,

+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,

+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,

+  IN UINTN                    CopySize

+  );

+

+EFI_STATUS

+PrePeiCoreGetGlobalVariableMemory (

+  OUT EFI_PHYSICAL_ADDRESS    *GlobalVariableBase

+  );

+

+VOID

+SecSwitchStack (

+  INTN    StackDelta

+  );

+

+// Vector Table for Pei Phase

+VOID  PeiVectorTable (VOID);

+

+VOID

+EFIAPI

+PrimaryMain (

+  IN  EFI_PEI_CORE_ENTRY_POINT  PeiCoreEntryPoint

+  );

+

+/*

+ * This is the main function for secondary cores. They loop around until a non Null value is written to

+ * SYS_FLAGS register.The SYS_FLAGS register is platform specific.

+ * Note:The secondary cores, while executing secondary_main, assumes that:

+ *      : SGI 0 is configured as Non-secure interrupt

+ *      : Priority Mask is configured to allow SGI 0

+ *      : Interrupt Distributor and CPU interfaces are enabled

+ *

+ */

+VOID

+EFIAPI

+SecondaryMain (

+  IN UINTN MpId

+  );

+

+VOID

+PeiCommonExceptionEntry (

+  IN UINT32 Entry,

+  IN UINTN LR

+  );

+

+#endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf
new file mode 100644
index 0000000..5ba0231
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCoreMPCore.inf
@@ -0,0 +1,80 @@
+#/** @file

+#  Pre PeiCore - Hand-off to PEI Core in Normal World

+#

+#  Copyright (c) 2011-2014, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformPrePeiCore

+  FILE_GUID                      = 469fc080-aec1-11df-927c-0002a5d5c51b

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+

+[Sources.common]

+  MainMPCore.c

+  PrePeiCore.c

+

+[Sources.ARM]

+  Arm/ArchPrePeiCore.c

+  Arm/PrePeiCoreEntryPoint.asm | RVCT

+  Arm/PrePeiCoreEntryPoint.S   | GCC

+  Arm/SwitchStack.asm      | RVCT

+  Arm/SwitchStack.S        | GCC

+  Arm/Exception.asm        | RVCT

+  Arm/Exception.S          | GCC

+

+[Sources.AARCH64]

+  AArch64/ArchPrePeiCore.c

+  AArch64/PrePeiCoreEntryPoint.S

+  AArch64/SwitchStack.S

+  AArch64/Exception.S

+  AArch64/Helper.S

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  ArmPlatformLib

+  BaseLib

+  DebugLib

+  DebugAgentLib

+  IoLib

+  ArmGicLib

+  PrintLib

+  SerialPortLib

+

+[Ppis]

+  gEfiTemporaryRamSupportPpiGuid

+  gArmGlobalVariablePpiGuid

+  gArmMpCoreInfoPpiGuid

+

+[FeaturePcd]

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdFvSize

+

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize

+

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

+

+  gArmTokenSpaceGuid.PcdGicDistributorBase

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase

+  gArmTokenSpaceGuid.PcdGicSgiIntId

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf
new file mode 100644
index 0000000..d677f15
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf
@@ -0,0 +1,74 @@
+#/** @file

+#  Pre PeiCore - Hand-off to PEI Core in Normal World

+#

+#  Copyright (c) 2011, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformPrePeiCore

+  FILE_GUID                      = 469fc080-aec1-11df-927c-0002a5d5c51b

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+

+[Sources.common]

+  PrePeiCore.c

+  MainUniCore.c

+

+[Sources.ARM]

+  Arm/ArchPrePeiCore.c

+  Arm/PrePeiCoreEntryPoint.asm | RVCT

+  Arm/PrePeiCoreEntryPoint.S   | GCC

+  Arm/SwitchStack.asm      | RVCT

+  Arm/SwitchStack.S        | GCC

+  Arm/Exception.asm        | RVCT

+  Arm/Exception.S          | GCC

+

+[Sources.AARCH64]

+  AArch64/ArchPrePeiCore.c

+  AArch64/PrePeiCoreEntryPoint.S

+  AArch64/SwitchStack.S

+  AArch64/Exception.S

+  AArch64/Helper.S

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmLib

+  ArmPlatformLib

+  BaseLib

+  DebugLib

+  DebugAgentLib

+  IoLib

+  PrintLib

+  SerialPortLib

+

+[Ppis]

+  gEfiTemporaryRamSupportPpiGuid

+  gArmGlobalVariablePpiGuid

+

+[FeaturePcd]

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores

+

+[FixedPcd]

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdFvSize

+

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize

+

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/AArch64/ArchPrePi.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/AArch64/ArchPrePi.c
new file mode 100644
index 0000000..2179861
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/AArch64/ArchPrePi.c
@@ -0,0 +1,33 @@
+/** @file

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#include "PrePi.h"

+

+#include <Chipset/AArch64.h>

+

+VOID

+ArchInitialize (

+  VOID

+  )

+{

+  // Enable Floating Point

+  if (FixedPcdGet32 (PcdVFPEnabled)) {

+    ArmEnableVFP ();

+  }

+

+  if (ArmReadCurrentEL () == AARCH64_EL2) {

+    // Trap General Exceptions. All exceptions that would be routed to EL1 are routed to EL2

+    ArmWriteHcr (ARM_HCR_TGE);

+  }

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
new file mode 100644
index 0000000..fcea949
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
@@ -0,0 +1,146 @@
+//

+//  Copyright (c) 2011-2013, ARM 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.

+//

+//

+

+#include <AsmMacroIoLibV8.h>

+#include <Base.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+.text

+.align 3

+

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmReadMpidr)

+GCC_ASM_IMPORT(ArmPlatformPeiBootAction)

+GCC_ASM_IMPORT(ArmPlatformStackSet)

+GCC_ASM_EXPORT(_ModuleEntryPoint)

+

+StartupAddr:        .8byte ASM_PFX(CEntryPoint)

+

+ASM_PFX(_ModuleEntryPoint):

+  // Do early platform specific actions

+  bl    ASM_PFX(ArmPlatformPeiBootAction)

+

+  // Get ID of this CPU in Multicore system

+  bl    ASM_PFX(ArmReadMpidr)

+  // Keep a copy of the MpId register value

+  mov   x10, x0

+

+_SetSVCMode:

+// Check if we can install the stack at the top of the System Memory or if we need

+// to install the stacks at the bottom of the Firmware Device (case the FD is located

+// at the top of the DRAM)

+_SetupStackPosition:

+  // Compute Top of System Memory

+  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), x1)

+  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), x2)

+  sub   x2, x2, #1

+  add   x1, x1, x2      // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize

+

+  // Calculate Top of the Firmware Device

+  LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2)

+  LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3)

+  sub   x3, x3, #1

+  add   x3, x3, x2      // x3 = FdTop = PcdFdBaseAddress + PcdFdSize

+

+  // UEFI Memory Size (stacks are allocated in this region)

+  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4)

+

+  //

+  // Reserve the memory for the UEFI region (contain stacks on its top)

+  //

+

+  // Calculate how much space there is between the top of the Firmware and the Top of the System Memory

+  subs  x0, x1, x3   // x0 = SystemMemoryTop - FdTop

+  b.mi  _SetupStack  // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM

+  cmp   x0, x4

+  b.ge  _SetupStack

+

+  // Case the top of stacks is the FdBaseAddress

+  mov   x1, x2

+

+_SetupStack:

+  // x1 contains the top of the stack (and the UEFI Memory)

+

+  // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment

+  // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the

+  // top of the memory space)

+  adds  x11, x1, #1

+  b.cs  _SetupOverflowStack

+

+_SetupAlignedStack:

+  mov   x1, x11

+  b     _GetBaseUefiMemory

+

+_SetupOverflowStack:

+  // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE

+  // aligned (4KB)

+  LoadConstantToReg (EFI_PAGE_MASK, x11)

+  and   x11, x11, x1

+  sub   x1, x1, x11

+

+_GetBaseUefiMemory:

+  // Calculate the Base of the UEFI Memory

+  sub   x11, x1, x4

+

+_GetStackBase:

+  // r1 = The top of the Mpcore Stacks

+  // Stack for the primary core = PrimaryCoreStack

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)

+  sub   x12, x1, x2

+

+  // Stack for the secondary core = Number of Cores - 1

+  LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0)

+  sub   x0, x0, #1

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)

+  mul   x1, x1, x0

+  sub   x12, x12, x1

+

+  // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)

+  mov   x0, x12

+  mov   x1, x10

+  //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3)

+  bl    ASM_PFX(ArmPlatformStackSet)

+

+  // Is it the Primary Core ?

+  mov   x0, x10

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+  cmp   x0, #1

+  bne   _PrepareArguments

+

+_ReserveGlobalVariable:

+  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), x0)

+  // InitializePrimaryStack($GlobalVariableSize, $Tmp1, $Tmp2)

+  InitializePrimaryStack(x0, x1, x2)

+

+_PrepareArguments:

+  mov   x0, x10

+  mov   x1, x11

+  mov   x2, x12

+  mov   x3, sp

+

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   x4, StartupAddr

+

+  // Jump to PrePiCore C code

+  //    x0 = MpId

+  //    x1 = UefiMemoryBase

+  //    x2 = StacksBase

+  //    x3 = GlobalVariableBase

+  blr   x4

+

+_NeverReturn:

+  b _NeverReturn

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ArchPrePi.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ArchPrePi.c
new file mode 100644
index 0000000..075eb89
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ArchPrePi.c
@@ -0,0 +1,29 @@
+/** @file

+*

+*  Copyright (c) 2011 - 2013, ARM 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.

+*

+**/

+

+#include "PrePi.h"

+

+VOID

+ArchInitialize (

+  VOID

+  )

+{

+  // Enable program flow prediction, if supported.

+  ArmEnableBranchPrediction ();

+

+  if (FixedPcdGet32 (PcdVFPEnabled)) {

+    ArmEnableVFP ();

+  }

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S
new file mode 100644
index 0000000..f00960f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S
@@ -0,0 +1,155 @@
+//

+//  Copyright (c) 2011-2014, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+#include <Chipset/ArmV7.h>

+

+.text

+.align 3

+

+GCC_ASM_IMPORT(CEntryPoint)

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmReadMpidr)

+GCC_ASM_IMPORT(ArmPlatformPeiBootAction)

+GCC_ASM_IMPORT(ArmPlatformStackSet)

+GCC_ASM_EXPORT(_ModuleEntryPoint)

+

+StartupAddr: .word    CEntryPoint

+

+

+ASM_PFX(_ModuleEntryPoint):

+  // Do early platform specific actions

+  bl    ASM_PFX(ArmPlatformPeiBootAction)

+

+  // Get ID of this CPU in Multicore system

+  bl    ASM_PFX(ArmReadMpidr)

+  // Keep a copy of the MpId register value

+  mov   r8, r0

+

+_SetSVCMode:

+  // Enter SVC mode, Disable FIQ and IRQ

+  mov     r1, #(CPSR_MODE_SVC | CPSR_IRQ | CPSR_FIQ)

+  msr     CPSR_c, r1

+

+// Check if we can install the stack at the top of the System Memory or if we need

+// to install the stacks at the bottom of the Firmware Device (case the FD is located

+// at the top of the DRAM)

+_SetupStackPosition:

+  // Compute Top of System Memory

+  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), r1)

+  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), r2)

+  sub   r2, r2, #1

+  add   r1, r1, r2      // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize

+

+  // Calculate Top of the Firmware Device

+  LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)

+  LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)

+  sub   r3, r3, #1

+  add   r3, r3, r2      // r3 = FdTop = PcdFdBaseAddress + PcdFdSize

+

+  // UEFI Memory Size (stacks are allocated in this region)

+  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)

+

+  //

+  // Reserve the memory for the UEFI region (contain stacks on its top)

+  //

+

+  // Calculate how much space there is between the top of the Firmware and the Top of the System Memory

+  subs  r0, r1, r3      // r0 = SystemMemoryTop - FdTop

+  bmi   _SetupStack     // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM

+  cmp   r0, r4

+  bge   _SetupStack

+

+  // Case the top of stacks is the FdBaseAddress

+  mov   r1, r2

+

+_SetupStack:

+  // r1 contains the top of the stack (and the UEFI Memory)

+

+  // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment

+  // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the

+  // top of the memory space)

+  adds  r9, r1, #1

+  bcs   _SetupOverflowStack

+

+_SetupAlignedStack:

+  mov   r1, r9

+  b     _GetBaseUefiMemory

+

+_SetupOverflowStack:

+  // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE

+  // aligned (4KB)

+  LoadConstantToReg (EFI_PAGE_MASK, r9)

+  and   r9, r9, r1

+  sub   r1, r1, r9

+

+_GetBaseUefiMemory:

+  // Calculate the Base of the UEFI Memory

+  sub   r9, r1, r4

+

+_GetStackBase:

+  // r1 = The top of the Mpcore Stacks

+  // Stack for the primary core = PrimaryCoreStack

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)

+  sub   r10, r1, r2

+

+  // Stack for the secondary core = Number of Cores - 1

+  LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)

+  sub   r0, r0, #1

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)

+  mul   r1, r1, r0

+  sub   r10, r10, r1

+

+  // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)

+  mov   r0, r10

+  mov   r1, r8

+  //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)

+  bl    ASM_PFX(ArmPlatformStackSet)

+

+  // Is it the Primary Core ?

+  mov   r0, r8

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+  cmp   r0, #1

+  bne   _PrepareArguments

+

+_ReserveGlobalVariable:

+  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r0)

+  // InitializePrimaryStack($GlobalVariableSize, $Tmp1)

+  InitializePrimaryStack(r0, r1)

+

+_PrepareArguments:

+  mov   r0, r8

+  mov   r1, r9

+  mov   r2, r10

+  mov   r3, sp

+

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   r4, StartupAddr

+

+  // Jump to PrePiCore C code

+  //    r0 = MpId

+  //    r1 = UefiMemoryBase

+  //    r2 = StacksBase

+  //    r3 = GlobalVariableBase

+  blx   r4

+

+_NeverReturn:

+  b _NeverReturn

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm
new file mode 100644
index 0000000..cbb3a08
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.asm
@@ -0,0 +1,158 @@
+//

+//  Copyright (c) 2011-2014, ARM 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.

+//

+//

+

+#include <AsmMacroIoLib.h>

+#include <Base.h>

+#include <Library/PcdLib.h>

+#include <AutoGen.h>

+

+#include <Chipset/ArmV7.h>

+

+  INCLUDE AsmMacroIoLib.inc

+

+  IMPORT  CEntryPoint

+  IMPORT  ArmPlatformIsPrimaryCore

+  IMPORT  ArmReadMpidr

+  IMPORT  ArmPlatformPeiBootAction

+  IMPORT  ArmPlatformStackSet

+

+  EXPORT  _ModuleEntryPoint

+

+  PRESERVE8

+  AREA    PrePiCoreEntryPoint, CODE, READONLY

+

+StartupAddr        DCD      CEntryPoint

+

+_ModuleEntryPoint

+  // Do early platform specific actions

+  bl    ArmPlatformPeiBootAction

+

+  // Get ID of this CPU in Multicore system

+  bl    ArmReadMpidr

+  // Keep a copy of the MpId register value

+  mov   r8, r0

+

+_SetSVCMode

+  // Enter SVC mode, Disable FIQ and IRQ

+  mov     r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)

+  msr     CPSR_c, r1

+

+// Check if we can install the stack at the top of the System Memory or if we need

+// to install the stacks at the bottom of the Firmware Device (case the FD is located

+// at the top of the DRAM)

+_SetupStackPosition

+  // Compute Top of System Memory

+  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), r1)

+  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), r2)

+  sub   r2, r2, #1

+  add   r1, r1, r2      // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize

+

+  // Calculate Top of the Firmware Device

+  LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)

+  LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)

+  sub   r3, r3, #1

+  add   r3, r3, r2      // r3 = FdTop = PcdFdBaseAddress + PcdFdSize

+

+  // UEFI Memory Size (stacks are allocated in this region)

+  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)

+

+  //

+  // Reserve the memory for the UEFI region (contain stacks on its top)

+  //

+

+  // Calculate how much space there is between the top of the Firmware and the Top of the System Memory

+  subs  r0, r1, r3      // r0 = SystemMemoryTop - FdTop

+  bmi   _SetupStack     // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM

+  cmp   r0, r4

+  bge   _SetupStack

+

+  // Case the top of stacks is the FdBaseAddress

+  mov   r1, r2

+

+_SetupStack

+  // r1 contains the top of the stack (and the UEFI Memory)

+

+  // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment

+  // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the

+  // top of the memory space)

+  adds  r9, r1, #1

+  bcs   _SetupOverflowStack

+

+_SetupAlignedStack

+  mov   r1, r9

+  b     _GetBaseUefiMemory

+

+_SetupOverflowStack

+  // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE

+  // aligned (4KB)

+  LoadConstantToReg (EFI_PAGE_MASK, r9)

+  and   r9, r9, r1

+  sub   r1, r1, r9

+

+_GetBaseUefiMemory

+  // Calculate the Base of the UEFI Memory

+  sub   r9, r1, r4

+

+_GetStackBase

+  // r1 = The top of the Mpcore Stacks

+  // Stack for the primary core = PrimaryCoreStack

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)

+  sub   r10, r1, r2

+

+  // Stack for the secondary core = Number of Cores - 1

+  LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)

+  sub   r0, r0, #1

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)

+  mul   r1, r1, r0

+  sub   r10, r10, r1

+

+  // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)

+  mov   r0, r10

+  mov   r1, r8

+  //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)

+  bl    ArmPlatformStackSet

+

+  // Is it the Primary Core ?

+  mov   r0, r8

+  bl    ArmPlatformIsPrimaryCore

+  cmp   r0, #1

+  bne   _PrepareArguments

+

+_ReserveGlobalVariable

+  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r0)

+  // InitializePrimaryStack($GlobalVariableSize, $Tmp1)

+  InitializePrimaryStack r0, r1

+

+_PrepareArguments

+  mov   r0, r8

+  mov   r1, r9

+  mov   r2, r10

+  mov   r3, sp

+

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   r4, StartupAddr

+

+  // Jump to PrePiCore C code

+  //    r0 = MpId

+  //    r1 = UefiMemoryBase

+  //    r2 = StacksBase

+  //    r3 = GlobalVariableBase

+  blx   r4

+

+_NeverReturn

+  b _NeverReturn

+

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/LzmaDecompress.h b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/LzmaDecompress.h
new file mode 100644
index 0000000..a79ff34
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/LzmaDecompress.h
@@ -0,0 +1,103 @@
+/** @file

+  LZMA Decompress Library header file

+

+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>

+  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 __LZMA_DECOMPRESS_H___

+#define __LZMA_DECOMPRESS_H___

+

+/**

+  Examines a GUIDed section and returns the size of the decoded buffer and the

+  size of an scratch buffer required to actually decode the data in a GUIDed section.

+

+  Examines a GUIDed section specified by InputSection.

+  If GUID for InputSection does not match the GUID that this handler supports,

+  then RETURN_UNSUPPORTED is returned.

+  If the required information can not be retrieved from InputSection,

+  then RETURN_INVALID_PARAMETER is returned.

+  If the GUID of InputSection does match the GUID that this handler supports,

+  then the size required to hold the decoded buffer is returned in OututBufferSize,

+  the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field

+  from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.

+

+  If InputSection is NULL, then ASSERT().

+  If OutputBufferSize is NULL, then ASSERT().

+  If ScratchBufferSize is NULL, then ASSERT().

+  If SectionAttribute is NULL, then ASSERT().

+

+

+  @param[in]  InputSection       A pointer to a GUIDed section of an FFS formatted file.

+  @param[out] OutputBufferSize   A pointer to the size, in bytes, of an output buffer required

+                                 if the buffer specified by InputSection were decoded.

+  @param[out] ScratchBufferSize  A pointer to the size, in bytes, required as scratch space

+                                 if the buffer specified by InputSection were decoded.

+  @param[out] SectionAttribute   A pointer to the attributes of the GUIDed section. See the Attributes

+                                 field of EFI_GUID_DEFINED_SECTION in the PI Specification.

+

+  @retval  RETURN_SUCCESS            The information about InputSection was returned.

+  @retval  RETURN_UNSUPPORTED        The section specified by InputSection does not match the GUID this handler supports.

+  @retval  RETURN_INVALID_PARAMETER  The information can not be retrieved from the section specified by InputSection.

+

+**/

+RETURN_STATUS

+EFIAPI

+LzmaGuidedSectionGetInfo (

+  IN  CONST VOID  *InputSection,

+  OUT UINT32      *OutputBufferSize,

+  OUT UINT32      *ScratchBufferSize,

+  OUT UINT16      *SectionAttribute

+  );

+

+/**

+  Decompress a LZAM compressed GUIDed section into a caller allocated output buffer.

+

+  Decodes the GUIDed section specified by InputSection.

+  If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.

+  If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.

+  If the GUID of InputSection does match the GUID that this handler supports, then InputSection

+  is decoded into the buffer specified by OutputBuffer and the authentication status of this

+  decode operation is returned in AuthenticationStatus.  If the decoded buffer is identical to the

+  data in InputSection, then OutputBuffer is set to point at the data in InputSection.  Otherwise,

+  the decoded data will be placed in caller allocated buffer specified by OutputBuffer.

+

+  If InputSection is NULL, then ASSERT().

+  If OutputBuffer is NULL, then ASSERT().

+  If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().

+  If AuthenticationStatus is NULL, then ASSERT().

+

+

+  @param[in]  InputSection  A pointer to a GUIDed section of an FFS formatted file.

+  @param[out] OutputBuffer  A pointer to a buffer that contains the result of a decode operation.

+  @param[out] ScratchBuffer A caller allocated buffer that may be required by this function

+                            as a scratch buffer to perform the decode operation.

+  @param[out] AuthenticationStatus

+                            A pointer to the authentication status of the decoded output buffer.

+                            See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI

+                            section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must

+                            never be set by this handler.

+

+  @retval  RETURN_SUCCESS            The buffer specified by InputSection was decoded.

+  @retval  RETURN_UNSUPPORTED        The section specified by InputSection does not match the GUID this handler supports.

+  @retval  RETURN_INVALID_PARAMETER  The section specified by InputSection can not be decoded.

+

+**/

+RETURN_STATUS

+EFIAPI

+LzmaGuidedSectionExtraction (

+  IN CONST  VOID    *InputSection,

+  OUT       VOID    **OutputBuffer,

+  OUT       VOID    *ScratchBuffer,        OPTIONAL

+  OUT       UINT32  *AuthenticationStatus

+  );

+

+#endif // __LZMADECOMPRESS_H__

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/MainMPCore.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/MainMPCore.c
new file mode 100644
index 0000000..bf81373
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/MainMPCore.c
@@ -0,0 +1,106 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include "PrePi.h"

+

+#include <Library/ArmGicLib.h>

+

+#include <Ppi/ArmMpCoreInfo.h>

+

+VOID

+PrimaryMain (

+  IN  UINTN                     UefiMemoryBase,

+  IN  UINTN                     StacksBase,

+  IN  UINTN                     GlobalVariableBase,

+  IN  UINT64                    StartTimeStamp

+  )

+{

+  // Enable the GIC Distributor

+  ArmGicEnableDistributor(PcdGet32(PcdGicDistributorBase));

+

+  // In some cases, the secondary cores are waiting for an SGI from the next stage boot loader to resume their initialization

+  if (!FixedPcdGet32(PcdSendSgiToBringUpSecondaryCores)) {

+    // Sending SGI to all the Secondary CPU interfaces

+    ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));

+  }

+

+  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);

+

+  // We must never return

+  ASSERT(FALSE);

+}

+

+VOID

+SecondaryMain (

+  IN  UINTN                     MpId

+  )

+{

+  EFI_STATUS              Status;

+  ARM_MP_CORE_INFO_PPI    *ArmMpCoreInfoPpi;

+  UINTN                   Index;

+  UINTN                   ArmCoreCount;

+  ARM_CORE_INFO           *ArmCoreInfoTable;

+  UINT32                  ClusterId;

+  UINT32                  CoreId;

+  VOID                    (*SecondaryStart)(VOID);

+  UINTN                   SecondaryEntryAddr;

+  UINTN                   AcknowledgeInterrupt;

+  UINTN                   InterruptId;

+

+  ClusterId = GET_CLUSTER_ID(MpId);

+  CoreId    = GET_CORE_ID(MpId);

+

+  // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)

+  Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);

+  ASSERT_EFI_ERROR (Status);

+

+  ArmCoreCount = 0;

+  Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);

+  ASSERT_EFI_ERROR (Status);

+

+  // Find the core in the ArmCoreTable

+  for (Index = 0; Index < ArmCoreCount; Index++) {

+    if ((ArmCoreInfoTable[Index].ClusterId == ClusterId) && (ArmCoreInfoTable[Index].CoreId == CoreId)) {

+      break;

+    }

+  }

+

+  // The ARM Core Info Table must define every core

+  ASSERT (Index != ArmCoreCount);

+

+  // Clear Secondary cores MailBox

+  MmioWrite32 (ArmCoreInfoTable[Index].MailboxClearAddress, ArmCoreInfoTable[Index].MailboxClearValue);

+

+  do {

+    ArmCallWFI ();

+

+    // Read the Mailbox

+    SecondaryEntryAddr = MmioRead32 (ArmCoreInfoTable[Index].MailboxGetAddress);

+

+    // Acknowledge the interrupt and send End of Interrupt signal.

+    AcknowledgeInterrupt = ArmGicAcknowledgeInterrupt (PcdGet32 (PcdGicInterruptInterfaceBase), &InterruptId);

+    // Check if it is a valid interrupt ID

+    if (InterruptId < ArmGicGetMaxNumInterrupts (PcdGet32 (PcdGicDistributorBase))) {

+      // Got a valid SGI number hence signal End of Interrupt

+      ArmGicEndOfInterrupt (PcdGet32 (PcdGicInterruptInterfaceBase), AcknowledgeInterrupt);

+    }

+  } while (SecondaryEntryAddr == 0);

+

+  // Jump to secondary core entry point.

+  SecondaryStart = (VOID (*)())SecondaryEntryAddr;

+  SecondaryStart();

+

+  // The secondaries shouldn't reach here

+  ASSERT(FALSE);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/MainUniCore.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/MainUniCore.c
new file mode 100644
index 0000000..43588a5
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/MainUniCore.c
@@ -0,0 +1,44 @@
+/** @file

+*

+*  Copyright (c) 2011, ARM 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.

+*

+**/

+

+#include "PrePi.h"

+

+VOID

+PrimaryMain (

+  IN  UINTN                     UefiMemoryBase,

+  IN  UINTN                     StacksBase,

+  IN  UINTN                     GlobalVariableBase,

+  IN  UINT64                    StartTimeStamp

+  )

+{

+  DEBUG_CODE_BEGIN();

+    // On MPCore system, PeiMpCore.inf should be used instead of PeiUniCore.inf

+    ASSERT(ArmIsMpCore() == 0);

+  DEBUG_CODE_END();

+

+  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);

+

+  // We must never return

+  ASSERT(FALSE);

+}

+

+VOID

+SecondaryMain (

+  IN  UINTN                     MpId

+  )

+{

+  // We must never get into this function on UniCore system

+  ASSERT(FALSE);

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PeiMPCore.inf b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PeiMPCore.inf
new file mode 100755
index 0000000..ad996c5
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PeiMPCore.inf
@@ -0,0 +1,114 @@
+#/** @file

+#

+#  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmPlatformPrePiMPCore

+  FILE_GUID                      = d959e387-7b91-452c-90e0-a1dbac90ddb8

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+

+[Sources]

+  PrePi.c

+  MainMPCore.c

+

+[Sources.ARM]

+  Arm/ArchPrePi.c

+  Arm/ModuleEntryPoint.S   | GCC

+  Arm/ModuleEntryPoint.asm | RVCT

+

+[Sources.AArch64]

+  AArch64/ArchPrePi.c

+  AArch64/ModuleEntryPoint.S

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  DebugAgentLib

+  ArmLib

+  ArmGicLib

+  IoLib

+  TimerLib

+  SerialPortLib

+  ExtractGuidedSectionLib

+  LzmaDecompressLib

+  PeCoffGetEntryPointLib

+  DebugAgentLib

+  PrePiLib

+  ArmPlatformLib

+  ArmPlatformStackLib

+  MemoryAllocationLib

+  HobLib

+  PrePiHobListPointerLib

+  PlatformPeiLib

+  MemoryInitPeiLib

+

+[Ppis]

+  gArmMpCoreInfoPpiGuid

+

+[Guids]

+  gArmGlobalVariableGuid

+  gArmMpCoreInfoGuid

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores

+

+[FixedPcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString

+

+  gArmTokenSpaceGuid.PcdVFPEnabled

+

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdFvSize

+

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize

+

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

+

+  gArmTokenSpaceGuid.PcdGicDistributorBase

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase

+  gArmTokenSpaceGuid.PcdGicSgiIntId

+

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize

+

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PeiUniCore.inf b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PeiUniCore.inf
new file mode 100755
index 0000000..f892573
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PeiUniCore.inf
@@ -0,0 +1,110 @@
+#/** @file

+#

+#  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>

+#

+#  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                    = 0x00010005

+  BASE_NAME                      = ArmPlatformPrePiUniCore

+  FILE_GUID                      = d959e387-7b91-452c-90e0-a1dbac90ddb8

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+

+[Sources]

+  PrePi.c

+  MainUniCore.c

+

+[Sources.ARM]

+  Arm/ArchPrePi.c

+  Arm/ModuleEntryPoint.S   | GCC

+  Arm/ModuleEntryPoint.asm | RVCT

+

+[Sources.AArch64]

+  AArch64/ArchPrePi.c

+  AArch64/ModuleEntryPoint.S

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  DebugAgentLib

+  ArmLib

+  IoLib

+  TimerLib

+  SerialPortLib

+  ExtractGuidedSectionLib

+  LzmaDecompressLib

+  PeCoffGetEntryPointLib

+  DebugAgentLib

+  PrePiLib

+  ArmPlatformLib

+  ArmPlatformStackLib

+  MemoryAllocationLib

+  HobLib

+  PrePiHobListPointerLib

+  PlatformPeiLib

+  MemoryInitPeiLib

+

+[Ppis]

+  gArmMpCoreInfoPpiGuid

+

+[Guids]

+  gArmGlobalVariableGuid

+  gArmMpCoreInfoGuid

+

+[FeaturePcd]

+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob

+  gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores

+

+[FixedPcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString

+

+  gArmTokenSpaceGuid.PcdVFPEnabled

+

+  gArmTokenSpaceGuid.PcdFdBaseAddress

+  gArmTokenSpaceGuid.PcdFdSize

+

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+  gArmTokenSpaceGuid.PcdFvSize

+

+  gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize

+

+  gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize

+

+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize

+

+  gArmPlatformTokenSpaceGuid.PcdCoreCount

+

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize

+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize

+

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode

+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData

+

+[Pcd]

+  gArmTokenSpaceGuid.PcdSystemMemoryBase

+  gArmTokenSpaceGuid.PcdSystemMemorySize

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PrePi.c b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PrePi.c
new file mode 100755
index 0000000..9a5e067
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PrePi.c
@@ -0,0 +1,260 @@
+/** @file

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <PiPei.h>

+

+#include <Library/DebugAgentLib.h>

+#include <Library/PrePiLib.h>

+#include <Library/PrintLib.h>

+#include <Library/PeCoffGetEntryPointLib.h>

+#include <Library/PrePiHobListPointerLib.h>

+#include <Library/TimerLib.h>

+#include <Library/PerformanceLib.h>

+

+#include <Ppi/GuidedSectionExtraction.h>

+#include <Ppi/ArmMpCoreInfo.h>

+#include <Guid/LzmaDecompress.h>

+#include <Guid/ArmGlobalVariableHob.h>

+

+#include "PrePi.h"

+#include "LzmaDecompress.h"

+

+#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \

+                  ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))

+

+// Not used when PrePi in run in XIP mode

+UINTN mGlobalVariableBase = 0;

+

+EFI_STATUS

+EFIAPI

+ExtractGuidedSectionLibConstructor (

+  VOID

+  );

+

+EFI_STATUS

+EFIAPI

+LzmaDecompressLibConstructor (

+  VOID

+  );

+

+VOID

+EFIAPI

+BuildGlobalVariableHob (

+  IN EFI_PHYSICAL_ADDRESS         GlobalVariableBase,

+  IN UINT32                       GlobalVariableSize

+  )

+{

+  ARM_HOB_GLOBAL_VARIABLE  *Hob;

+

+  Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));

+  ASSERT(Hob != NULL);

+

+  CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);

+  Hob->GlobalVariableBase = GlobalVariableBase;

+  Hob->GlobalVariableSize = GlobalVariableSize;

+}

+

+EFI_STATUS

+GetPlatformPpi (

+  IN  EFI_GUID  *PpiGuid,

+  OUT VOID      **Ppi

+  )

+{

+  UINTN                   PpiListSize;

+  UINTN                   PpiListCount;

+  EFI_PEI_PPI_DESCRIPTOR  *PpiList;

+  UINTN                   Index;

+

+  PpiListSize = 0;

+  ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);

+  PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);

+  for (Index = 0; Index < PpiListCount; Index++, PpiList++) {

+    if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {

+      *Ppi = PpiList->Ppi;

+      return EFI_SUCCESS;

+    }

+  }

+

+  return EFI_NOT_FOUND;

+}

+

+VOID

+PrePiMain (

+  IN  UINTN                     UefiMemoryBase,

+  IN  UINTN                     StacksBase,

+  IN  UINTN                     GlobalVariableBase,

+  IN  UINT64                    StartTimeStamp

+  )

+{

+  EFI_HOB_HANDOFF_INFO_TABLE*   HobList;

+  ARM_MP_CORE_INFO_PPI*         ArmMpCoreInfoPpi;

+  UINTN                         ArmCoreCount;

+  ARM_CORE_INFO*                ArmCoreInfoTable;

+  EFI_STATUS                    Status;

+  CHAR8                         Buffer[100];

+  UINTN                         CharCount;

+  UINTN                         StacksSize;

+

+  // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)

+  ASSERT (IS_XIP() ||

+          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&

+           ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize)))));

+

+  // Initialize the architecture specific bits

+  ArchInitialize ();

+

+  // Initialize the Serial Port

+  SerialPortInitialize ();

+  CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",

+    (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);

+  SerialPortWrite ((UINT8 *) Buffer, CharCount);

+

+  // Initialize the Debug Agent for Source Level Debugging

+  InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);

+  SaveAndSetDebugTimerInterrupt (TRUE);

+

+  // Declare the PI/UEFI memory region

+  HobList = HobConstructor (

+    (VOID*)UefiMemoryBase,

+    FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),

+    (VOID*)UefiMemoryBase,

+    (VOID*)StacksBase  // The top of the UEFI Memory is reserved for the stacks

+    );

+  PrePeiSetHobList (HobList);

+

+  // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)

+  Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));

+  ASSERT_EFI_ERROR (Status);

+

+  // Create the Stacks HOB (reserve the memory for all stacks)

+  if (ArmIsMpCore ()) {

+    StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) +

+                 ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize));

+  } else {

+    StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);

+  }

+  BuildStackHob (StacksBase, StacksSize);

+

+  // Declare the Global Variable HOB

+  BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));

+

+  //TODO: Call CpuPei as a library

+  BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));

+

+  if (ArmIsMpCore ()) {

+    // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid

+    Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);

+

+    // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)

+    ASSERT_EFI_ERROR (Status);

+

+    // Build the MP Core Info Table

+    ArmCoreCount = 0;

+    Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);

+    if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) {

+      // Build MPCore Info HOB

+      BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);

+    }

+  }

+

+  // Set the Boot Mode

+  SetBootMode (ArmPlatformGetBootMode ());

+

+  // Initialize Platform HOBs (CpuHob and FvHob)

+  Status = PlatformPeim ();

+  ASSERT_EFI_ERROR (Status);

+

+  // Now, the HOB List has been initialized, we can register performance information

+  PERF_START (NULL, "PEI", NULL, StartTimeStamp);

+

+  // SEC phase needs to run library constructors by hand.

+  ExtractGuidedSectionLibConstructor ();

+  LzmaDecompressLibConstructor ();

+

+  // Build HOBs to pass up our version of stuff the DXE Core needs to save space

+  BuildPeCoffLoaderHob ();

+  BuildExtractSectionHob (

+    &gLzmaCustomDecompressGuid,

+    LzmaGuidedSectionGetInfo,

+    LzmaGuidedSectionExtraction

+    );

+

+  // Assume the FV that contains the SEC (our code) also contains a compressed FV.

+  Status = DecompressFirstFv ();

+  ASSERT_EFI_ERROR (Status);

+

+  // Load the DXE Core and transfer control to it

+  Status = LoadDxeCoreFromFv (NULL, 0);

+  ASSERT_EFI_ERROR (Status);

+}

+

+VOID

+CEntryPoint (

+  IN  UINTN                     MpId,

+  IN  UINTN                     UefiMemoryBase,

+  IN  UINTN                     StacksBase,

+  IN  UINTN                     GlobalVariableBase

+  )

+{

+  UINT64   StartTimeStamp;

+

+  ASSERT(!ArmIsMpCore() || (PcdGet32 (PcdCoreCount) > 1));

+

+  // Initialize the platform specific controllers

+  ArmPlatformInitialize (MpId);

+

+  if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) {

+    // Initialize the Timer Library to setup the Timer HW controller

+    TimerConstructor ();

+    // We cannot call yet the PerformanceLib because the HOB List has not been initialized

+    StartTimeStamp = GetPerformanceCounter ();

+  } else {

+    StartTimeStamp = 0;

+  }

+

+  // Data Cache enabled on Primary core when MMU is enabled.

+  ArmDisableDataCache ();

+  // Invalidate Data cache

+  ArmInvalidateDataCache ();

+  // Invalidate instruction cache

+  ArmInvalidateInstructionCache ();

+  // Enable Instruction Caches on all cores.

+  ArmEnableInstructionCache ();

+

+  // Define the Global Variable region when we are not running in XIP

+  if (!IS_XIP()) {

+    if (ArmPlatformIsPrimaryCore (MpId)) {

+      mGlobalVariableBase = GlobalVariableBase;

+      if (ArmIsMpCore()) {

+        // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)

+        ArmCallSEV ();

+      }

+    } else {

+      // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)

+      ArmCallWFE ();

+    }

+  }

+

+  // If not primary Jump to Secondary Main

+  if (ArmPlatformIsPrimaryCore (MpId)) {

+    // Goto primary Main.

+    PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);

+  } else {

+    SecondaryMain (MpId);

+  }

+

+  // DXE Core should always load and never return

+  ASSERT (FALSE);

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PrePi.h b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PrePi.h
new file mode 100644
index 0000000..e67795f
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/PrePi/PrePi.h
@@ -0,0 +1,90 @@
+/** @file

+*

+*  Copyright (c) 2011-2012, ARM 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.

+*

+**/

+

+#ifndef _PREPI_H_

+#define _PREPI_H_

+

+#include <PiPei.h>

+

+#include <Library/PcdLib.h>

+#include <Library/ArmLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/DebugLib.h>

+#include <Library/IoLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/HobLib.h>

+#include <Library/SerialPortLib.h>

+#include <Library/ArmPlatformLib.h>

+

+#define SerialPrint(txt)  SerialPortWrite (txt, AsciiStrLen(txt)+1);

+

+RETURN_STATUS

+EFIAPI

+TimerConstructor (

+  VOID

+  );

+

+VOID

+PrePiMain (

+  IN  UINTN                     UefiMemoryBase,

+  IN  UINTN                     StacksBase,

+  IN  UINTN                     GlobalVariableBase,

+  IN  UINT64                    StartTimeStamp

+  );

+

+EFI_STATUS

+EFIAPI

+MemoryPeim (

+  IN EFI_PHYSICAL_ADDRESS       UefiMemoryBase,

+  IN UINT64                     UefiMemorySize

+  );

+

+EFI_STATUS

+EFIAPI

+PlatformPeim (

+  VOID

+  );

+

+VOID

+PrimaryMain (

+  IN  UINTN                     UefiMemoryBase,

+  IN  UINTN                     StacksBase,

+  IN  UINTN                     GlobalVariableBase,

+  IN  UINT64                    StartTimeStamp

+  );

+

+VOID

+SecondaryMain (

+  IN  UINTN                     MpId

+  );

+

+// Either implemented by PrePiLib or by MemoryInitPei

+VOID

+BuildMemoryTypeInformationHob (

+  VOID

+  );

+

+EFI_STATUS

+GetPlatformPpi (

+  IN  EFI_GUID  *PpiGuid,

+  OUT VOID      **Ppi

+  );

+

+// Initialize the Architecture specific controllers

+VOID

+ArchInitialize (

+  VOID

+  );

+

+#endif /* _PREPI_H_ */

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/build_report.py b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/build_report.py
new file mode 100644
index 0000000..effaf1d
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/build_report.py
@@ -0,0 +1,54 @@
+#

+#  Copyright (c) 2011-2012, ARM 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.

+#

+

+import re

+

+class BuildReport:

+    PCDs = {}

+

+    def parse_platform_summary(self, file):

+        pass

+

+    def parse_pcd_report(self, report_file):

+        pcd_reg = re.compile(" (\*P|\*F|\*M|  ) (\w+)(\ +)\: (.*) \((\w+)\) = (.*)\n")

+

+        for line in report_file.xreadlines():

+            stripped_line = line.strip()

+            if re.match("\<=+\>", stripped_line):

+                return

+            elif re.match("g.*Guid", stripped_line):

+                guid = stripped_line

+                self.PCDs[guid] = {}

+            else:

+                m = pcd_reg.match(line)

+                if m:

+                    self.PCDs[guid][m.group(2)] = (m.group(6).strip(),m.group(5))

+

+    def parse_firmware_device(self, file):

+        pass

+

+    def parse_module_summary(self, file):

+        #print "Module Summary"

+        pass

+

+    CONST_SECTION_HEADERS = [('Platform Summary', parse_platform_summary),

+                             ('Platform Configuration Database Report',parse_pcd_report),

+                             ('Firmware Device (FD)',parse_firmware_device),

+                             ('Module Summary',parse_module_summary)]

+

+    def __init__(self, filename = 'report.log'):

+        report_file = open(filename, 'r')

+        for line in report_file.xreadlines():

+            for section_header in BuildReport.CONST_SECTION_HEADERS:

+                if line.strip() == section_header[0]:

+                    section_header[1](self, report_file)

+        #print self.PCDs

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py
new file mode 100644
index 0000000..280b6b4
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py
@@ -0,0 +1,102 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+

+from arm_ds.debugger_v1 import Debugger

+from arm_ds.debugger_v1 import DebugException

+

+import re, sys, getopt

+

+import edk2_debugger

+

+# Reload external classes

+reload(edk2_debugger)

+

+def usage():

+    print "-v,--verbose"

+    print "-a,--all: Load all symbols"

+    print "-l,--report=: Filename for the EDK2 report log"

+    print "-m,--sysmem=(base,size): System Memory region"

+    print "-f,--fv=(base,size): Firmware region"

+    print "-r,--rom=(base,size): ROM region"

+

+verbose = False

+load_all = False

+report_file = None

+regions = []

+opts,args = getopt.getopt(sys.argv[1:], "hvar:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv="])

+if (opts is None) or (not opts):

+    report_file = '../../../report.log'

+else:

+    region_reg = re.compile("\((.*),(.*)\)")

+    base_reg = re.compile("(.*)")

+

+    for o,a in opts:

+        region_type = None

+        regex = None

+        m = None

+        if o in ("-h","--help"):

+            usage()

+            sys.exit()

+        elif o in ("-v","--verbose"):

+            verbose = True

+        elif o in ("-a","--all"):

+            load_all = True

+        elif o in ("-l","--report"):

+            report_file = a

+        elif o in ("-m","--sysmem"):

+            region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_SYSMEM

+            regex = region_reg

+        elif o in ("-f","--fv"):

+            region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_FV

+            regex = region_reg

+        elif o in ("-r","--rom"):

+            region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_ROM

+            regex = region_reg

+        else:

+            assert False, "Unhandled option (%s)" % o

+

+        if region_type:

+            m = regex.match(a)

+            if m:

+                if regex.groups == 1:

+                    regions.append((region_type,int(m.group(1),0),0))

+                else:

+                    regions.append((region_type,int(m.group(1),0),int(m.group(2),0)))

+            else:

+                if regex.groups == 1:

+                    raise Exception('cmd_load_symbols', "Expect a base address")

+                else:

+                    raise Exception('cmd_load_symbols', "Expect a region format as (base,size)")

+

+# Debugger object for accessing the debugger

+debugger = Debugger()

+

+# Initialisation commands

+ec = debugger.getExecutionContext(0)

+ec.getExecutionService().stop()

+ec.getExecutionService().waitForStop()

+# in case the execution context reference is out of date

+ec = debugger.getExecutionContext(0)

+

+try:

+    armplatform_debugger = edk2_debugger.ArmPlatformDebugger(ec, report_file, regions, verbose)

+

+    if load_all:

+        armplatform_debugger.load_all_symbols()

+    else:

+        armplatform_debugger.load_current_symbols()

+except IOError, (ErrorNumber, ErrorMessage):

+    print "Error: %s" % ErrorMessage

+except Exception, (ErrorClass, ErrorMessage):

+    print "Error(%s): %s" % (ErrorClass, ErrorMessage)

+except DebugException, de:

+    print "DebugError: %s" % (de.getMessage())

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py
new file mode 100644
index 0000000..cb420af
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py
@@ -0,0 +1,231 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+

+import os

+

+import firmware_volume

+import build_report

+import system_table

+

+# Reload external classes

+reload(firmware_volume)

+reload(build_report)

+reload(system_table)

+

+def readMem32(executionContext, address):

+    bytes = executionContext.getMemoryService().read(address, 4, 32)

+    return struct.unpack('<I',bytes)[0]

+

+def dump_fv(ec, fv_base, fv_size):

+    fv = firmware_volume.FirmwareVolume(ec,

+                                        int(build.PCDs['gArmTokenSpaceGuid']['PcdFvBaseAddress'][0],16),

+                                        int(build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16))

+

+    ffs = fv.get_next_ffs()

+    while ffs != None:

+        print "# %s" % ffs

+

+        section = ffs.get_next_section()

+        while section != None:

+            print "\t%s" % section

+            try:

+                print "\t\t- %s" % section.get_debug_filepath()

+            except Exception:

+                pass

+            section = ffs.get_next_section(section)

+

+        ffs = fv.get_next_ffs(ffs)

+

+def dump_system_table(ec, mem_base, mem_size):

+    st = system_table.SystemTable(ec, mem_base, mem_size)

+

+    debug_info_table_base = st.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)

+

+    debug_info_table = system_table.DebugInfoTable(ec, debug_info_table_base)

+    debug_info_table.dump()

+

+def load_symbol_from_file(ec, filename, address, verbose = False):

+    if verbose:

+        print "Add symbols of %s at 0x%x" % (filename, address)

+

+    try:

+        ec.getImageService().addSymbols(filename, address)

+    except:

+        try:

+            # We could get an exception if the symbols are already loaded

+            ec.getImageService().unloadSymbols(filename)

+            ec.getImageService().addSymbols(filename, address)

+        except:

+            print "Warning: not possible to load symbols from %s at 0x%x" % (filename, address)

+

+def is_aarch64(ec):

+    success = True

+    try:

+        # Try to access a Aarch64 specific register

+        ec.getRegisterService().getValue('X0')

+    except:

+        success = False

+    return success

+

+class ArmPlatform:

+    def __init__(self, sysmembase=None, sysmemsize=None, fvs={}):

+        self.sysmembase = sysmembase

+        self.sysmemsize = sysmemsize

+        self.fvs = fvs

+

+class ArmPlatformDebugger:

+    system_table = None

+    firmware_volumes = {}

+

+    REGION_TYPE_SYSMEM = 1

+    REGION_TYPE_ROM    = 2

+    REGION_TYPE_FV     = 3

+

+    def __init__(self, ec, report_log, regions, verbose = False):

+        self.ec = ec

+        self.verbose = verbose

+        fvs = []

+        sysmem_base = None

+        sysmem_size = None

+

+        if report_log and os.path.isfile(report_log):

+            try:

+                self.build = build_report.BuildReport(report_log)

+            except IOError:

+                raise IOError(2, 'Report \'%s\' is not valid' % report_log)

+

+            # Generate list of supported Firmware Volumes

+            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16) != 0:

+                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdFvSize'][0],16)))

+            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdSecureFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvSize'][0],16) != 0:

+                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSecureFvSize'][0],16)))

+            if self.build.PCDs['gArmTokenSpaceGuid'].has_key('PcdHypFvSize') and int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvSize'][0],16) != 0:

+                fvs.append((int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvBaseAddress'][0],16),int(self.build.PCDs['gArmTokenSpaceGuid']['PcdHypFvSize'][0],16)))

+

+            sysmem_base = int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSystemMemoryBase'][0],16)

+            sysmem_size = int(self.build.PCDs['gArmTokenSpaceGuid']['PcdSystemMemorySize'][0],16)

+        else:

+            for region in regions:

+                if region[0] == ArmPlatformDebugger.REGION_TYPE_SYSMEM:

+                    sysmem_base = region[1]

+                    sysmem_size = region[2]

+                elif region[0] == ArmPlatformDebugger.REGION_TYPE_FV:

+                    fvs.append((region[1],region[2]))

+                elif region[0] == ArmPlatformDebugger.REGION_TYPE_ROM:

+                    for base in xrange(region[1], region[1] + region[2], 0x400000):

+                        signature = struct.unpack("cccc", self.ec.getMemoryService().read(base, 4, 32))

+                        if signature == FirmwareVolume.CONST_FV_SIGNATURE:

+                            fvs.append((base,0))

+                else:

+                    print "Region type '%d' Not Supported" % region[0]

+

+        self.platform = ArmPlatform(sysmem_base, sysmem_size, fvs)

+

+    def in_sysmem(self, addr):

+        return (self.platform.sysmembase is not None) and (self.platform.sysmembase <= addr) and (addr < self.platform.sysmembase + self.platform.sysmemsize)

+

+    def in_fv(self, addr):

+        return (self.get_fv_at(addr) != None)

+

+    def get_fv_at(self, addr):

+        for fv in self.platform.fvs:

+            if (fv[0] <= addr) and (addr < fv[0] + fv[1]):

+                return fv

+        return None

+

+    def load_current_symbols(self):

+        pc = int(self.ec.getRegisterService().getValue('PC')) & 0xFFFFFFFF

+        if self.in_fv(pc):

+            debug_infos = []

+

+            (fv_base, fv_size) = self.get_fv_at(pc)

+

+            if self.firmware_volumes.has_key(fv_base) == False:

+                self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size)

+

+            stack_frame = self.ec.getTopLevelStackFrame()

+            info = self.firmware_volumes[fv_base].load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF, self.verbose)

+            debug_infos.append(info)

+            while stack_frame.next() is not None:

+                stack_frame = stack_frame.next()

+

+                # Stack frame attached to 'PC'

+                pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF

+

+                # Check if the symbols for this stack frame have already been loaded

+                found = False

+                for debug_info in debug_infos:

+                    if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]):

+                        found = True

+                if found == False:

+                    info = self.firmware_volumes[fv_base].load_symbols_at(pc)

+                    debug_infos.append(info)

+

+            #self.firmware_volumes[fv_base].load_symbols_at(pc)

+        elif self.in_sysmem(pc):

+            debug_infos = []

+

+            if self.system_table is None:

+                # Find the System Table

+                self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize)

+

+                # Find the Debug Info Table

+                debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)

+                self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base)

+

+            stack_frame = self.ec.getTopLevelStackFrame()

+            info = self.debug_info_table.load_symbols_at(int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF, self.verbose)

+            debug_infos.append(info)

+            while stack_frame.next() is not None:

+                stack_frame = stack_frame.next()

+

+                # Stack frame attached to 'PC'

+                pc = int(stack_frame.getRegisterService().getValue('PC')) & 0xFFFFFFFF

+

+                # Check if the symbols for this stack frame have already been loaded

+                found = False

+                for debug_info in debug_infos:

+                    if (pc >= debug_info[0]) and (pc < debug_info[0] + debug_info[1]):

+                        found = True

+                if found == False:

+                    try:

+                        info = self.debug_info_table.load_symbols_at(pc)

+                        debug_infos.append(info)

+                    except:

+                        pass

+

+            #self.debug_info_table.load_symbols_at(pc)

+        else:

+            raise Exception('ArmPlatformDebugger', "Not supported region")

+

+    def load_all_symbols(self):

+        # Load all the XIP symbols attached to the Firmware Volume

+        for (fv_base, fv_size) in self.platform.fvs:

+            if self.firmware_volumes.has_key(fv_base) == False:

+                self.firmware_volumes[fv_base] = firmware_volume.FirmwareVolume(self.ec, fv_base, fv_size)

+            self.firmware_volumes[fv_base].load_all_symbols(self.verbose)

+

+        try:

+            # Load all symbols of module loaded into System Memory

+            if self.system_table is None:

+                # Find the System Table

+                self.system_table = system_table.SystemTable(self.ec, self.platform.sysmembase, self.platform.sysmemsize)

+

+

+                # Find the Debug Info Table

+                debug_info_table_base = self.system_table.get_configuration_table(system_table.DebugInfoTable.CONST_DEBUG_INFO_TABLE_GUID)

+                self.debug_info_table = system_table.DebugInfoTable(self.ec, debug_info_table_base)

+

+            self.debug_info_table.load_all_symbols(self.verbose)

+        except:

+            # Debugger exception could be excepted if DRAM has not been initialized or if we have not started to run from DRAM yet

+            print "Note: no symbols have been found in System Memory (possible cause: the UEFI permanent memory has been installed yet)"

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py
new file mode 100644
index 0000000..8e3a8ad
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py
@@ -0,0 +1,355 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+

+from arm_ds.debugger_v1 import DebugException

+

+import struct

+import string

+

+import edk2_debugger

+

+class EfiFileSection(object):

+    EFI_SECTION_PE32                  = 0x10

+    EFI_SECTION_PIC                   = 0x11

+    EFI_SECTION_TE                    = 0x12

+

+    EFI_IMAGE_DEBUG_TYPE_CODEVIEW     = 0x2

+

+    SIZEOF_EFI_FFS_FILE_HEADER        = 0x28

+

+    def __init__(self, ec, base):

+        self.base = base

+        self.ec = ec

+

+    def __str__(self):

+        return "FileSection(type:0x%X, size:0x%x)" % (self.get_type(), self.get_size())

+

+    def get_base(self):

+        return self.base

+

+    def get_type(self):

+        return struct.unpack("B", self.ec.getMemoryService().read(self.base + 0x3, 1, 8))[0]

+

+    def get_size(self):

+        return (struct.unpack("<I", self.ec.getMemoryService().read(self.base, 4, 32))[0] & 0x00ffffff)

+

+    def get_debug_filepath(self):

+        type = self.get_type()

+        if type == EfiFileSection.EFI_SECTION_TE:

+            section = EfiSectionTE(self, ec, self.base + 0x4)

+        elif type == EfiFileSection.EFI_SECTION_PE32:

+            section = EfiSectionPE32(self, ec, self.base + 0x4)

+        else:

+            raise Exception("EfiFileSection", "No debug section")

+        return section.get_debug_filepath()

+

+class EfiSectionTE:

+    SIZEOF_EFI_TE_IMAGE_HEADER        = 0x28

+    EFI_TE_IMAGE_SIGNATURE            = ('V','Z')

+

+    def __init__(self, ec, base_te):

+        self.ec = ec

+        self.base_te = int(base_te)

+        te_sig = struct.unpack("cc", self.ec.getMemoryService().read(self.base_te, 2, 32))

+        if te_sig != EfiSectionTE.EFI_TE_IMAGE_SIGNATURE:

+            raise Exception("EfiFileSectionTE","TE Signature incorrect")

+

+    def get_debug_filepath(self):

+        stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]

+        stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER

+

+        debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_te + 0x20)

+        if debug_dir_entry_rva == 0:

+            raise Exception("EfiFileSectionTE","No debug directory for image")

+        debug_dir_entry_rva -= stripped_size

+

+        debug_type = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0xC)

+        if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):

+            raise Exception("EfiFileSectionTE","Debug type is not dwarf")

+

+        debug_rva = self.ec.getMemoryService().readMemory32(self.base_te + debug_dir_entry_rva + 0x14)

+        debug_rva -= stripped_size

+

+        dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(self.base_te + debug_rva, 4, 32))

+        if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):

+            raise Exception("EfiFileSectionTE","Dwarf debug signature not found")

+

+        if dwarf_sig == 0x66727764:

+            filename = self.base_te + debug_rva + 0xc

+        else:

+            filename = self.base_te + debug_rva + 0x10

+        filename = struct.unpack("200s", self.ec.getMemoryService().read(filename, 200, 32))[0]

+        return filename[0:string.find(filename,'\0')]

+

+    def get_debug_elfbase(self):

+        stripped_size = struct.unpack("<H", self.ec.getMemoryService().read(self.base_te + 0x6, 2, 32))[0]

+        stripped_size -= EfiSectionTE.SIZEOF_EFI_TE_IMAGE_HEADER

+

+        base_of_code = self.ec.getMemoryService().readMemory32(self.base_te + 0xC)

+

+        return self.base_te + base_of_code - stripped_size

+

+class EfiSectionPE32:

+    def __init__(self, ec, base_pe32):

+        self.ec = ec

+        self.base_pe32 = base_pe32

+

+    def get_debug_filepath(self):

+        # Offset from dos hdr to PE file hdr

+        file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe32 + 0x3C)

+

+        # Offset to debug dir in PE hdrs

+        debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe32 + file_header_offset + 0xA8)

+        if debug_dir_entry_rva == 0:

+            raise Exception("EfiFileSectionPE32","No Debug Directory")

+

+        debug_type = self.ec.getMemoryService().readMemory32(self.base_pe32 + debug_dir_entry_rva + 0xC)

+        if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):

+            raise Exception("EfiFileSectionPE32","Debug type is not dwarf")

+

+

+        debug_rva = self.ec.getMemoryService().readMemory32(self.base_pe32 + debug_dir_entry_rva + 0x14)

+

+        dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(str(self.base_pe32 + debug_rva), 4, 32))

+        if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):

+            raise Exception("EfiFileSectionPE32","Dwarf debug signature not found")

+

+        if dwarf_sig == 0x66727764:

+            filename = self.base_pe32 + debug_rva + 0xc

+        else:

+            filename = self.base_pe32 + debug_rva + 0x10

+        filename = struct.unpack("200s", self.ec.getMemoryService().read(str(filename), 200, 32))[0]

+        return filename[0:string.find(filename,'\0')]

+

+    def get_debug_elfbase(self):

+        # Offset from dos hdr to PE file hdr

+        pe_file_header = self.base_pe32 + self.ec.getMemoryService().readMemory32(self.base_pe32 + 0x3C)

+

+        base_of_code = self.base_pe32 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x28)

+        base_of_data = self.base_pe32 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x2C)

+

+        if (base_of_code < base_of_data) and (base_of_code != 0):

+            return base_of_code

+        else:

+            return base_of_data

+

+class EfiSectionPE64:

+    def __init__(self, ec, base_pe64):

+        self.ec = ec

+        self.base_pe64 = base_pe64

+

+    def get_debug_filepath(self):

+        # Offset from dos hdr to PE file hdr (EFI_IMAGE_NT_HEADERS64)

+        #file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe64 + 0x3C)

+        file_header_offset = 0x0

+

+        # Offset to debug dir in PE hdrs

+        debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe64 + file_header_offset + 0x138)

+        if debug_dir_entry_rva == 0:

+            raise Exception("EfiFileSectionPE64","No Debug Directory")

+

+        debug_type = self.ec.getMemoryService().readMemory32(self.base_pe64 + debug_dir_entry_rva + 0xC)

+        if (debug_type != 0xdf) and (debug_type != EfiFileSection.EFI_IMAGE_DEBUG_TYPE_CODEVIEW):

+            raise Exception("EfiFileSectionPE64","Debug type is not dwarf")

+

+

+        debug_rva = self.ec.getMemoryService().readMemory32(self.base_pe64 + debug_dir_entry_rva + 0x14)

+

+        dwarf_sig = struct.unpack("cccc", self.ec.getMemoryService().read(str(self.base_pe64 + debug_rva), 4, 32))

+        if (dwarf_sig != 0x66727764) and (dwarf_sig != FirmwareFile.CONST_NB10_SIGNATURE):

+            raise Exception("EfiFileSectionPE64","Dwarf debug signature not found")

+

+        if dwarf_sig == 0x66727764:

+            filename = self.base_pe64 + debug_rva + 0xc

+        else:

+            filename = self.base_pe64 + debug_rva + 0x10

+        filename = struct.unpack("200s", self.ec.getMemoryService().read(str(filename), 200, 32))[0]

+        return filename[0:string.find(filename,'\0')]

+

+    def get_debug_elfbase(self):

+        # Offset from dos hdr to PE file hdr

+        pe_file_header = self.base_pe64 + self.ec.getMemoryService().readMemory32(self.base_pe64 + 0x3C)

+

+        base_of_code = self.base_pe64 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x28)

+        base_of_data = self.base_pe64 + self.ec.getMemoryService().readMemory32(pe_file_header + 0x2C)

+

+        if (base_of_code < base_of_data) and (base_of_code != 0):

+            return base_of_code

+        else:

+            return base_of_data

+

+class FirmwareFile:

+    EFI_FV_FILETYPE_RAW                   = 0x01

+    EFI_FV_FILETYPE_FREEFORM              = 0x02

+    EFI_FV_FILETYPE_SECURITY_CORE         = 0x03

+    EFI_FV_FILETYPE_PEI_CORE              = 0x04

+    EFI_FV_FILETYPE_DXE_CORE              = 0x05

+    EFI_FV_FILETYPE_PEIM                  = 0x06

+    EFI_FV_FILETYPE_DRIVER                = 0x07

+    EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER  = 0x08

+    EFI_FV_FILETYPE_APPLICATION           = 0x09

+    EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE = 0x0B

+    EFI_FV_FILETYPE_FFS_MIN               = 0xF0

+

+    CONST_NB10_SIGNATURE = ('N','B','1','0')

+

+    def __init__(self, fv, base, ec):

+        self.fv = fv

+        self.base = base

+        self.ec = ec

+

+    def __str__(self):

+        return "FFS(state:0x%x, type:0x%X, size:0x%x)" % (self.get_state(), self.get_type(), self.get_size())

+

+    def get_base(self):

+        return self.base

+

+    def get_size(self):

+        size = (self.ec.getMemoryService().readMemory32(self.base + 0x14) & 0x00ffffff)

+

+        # Occupied size is the size considering the alignment

+        return size + ((0x8 - (size & 0x7)) & 0x7)

+

+    def get_type(self):

+        return self.ec.getMemoryService().readMemory8(self.base + 0x12)

+

+    def get_state(self):

+        state = self.ec.getMemoryService().readMemory8(self.base + 0x17)

+

+        polarity = self.fv.get_polarity()

+        if polarity:

+            state = ~state

+

+        highest_bit = 0x80;

+        while (highest_bit != 0) and ((highest_bit & state) == 0):

+            highest_bit >>= 1

+

+        return highest_bit

+

+    def get_next_section(self, section=None):

+        if section == None:

+            if self.get_type() != FirmwareFile.EFI_FV_FILETYPE_FFS_MIN:

+                section_base = self.get_base() + 0x18;

+            else:

+                return None

+        else:

+            section_base = int(section.get_base() + section.get_size())

+

+            # Align to next 4 byte boundary

+            if (section_base & 0x3) != 0:

+                section_base = section_base + 0x4 - (section_base & 0x3)

+

+        if section_base < self.get_base() + self.get_size():

+            return EfiFileSection(self.ec, section_base)

+        else:

+            return None

+

+class FirmwareVolume:

+    CONST_FV_SIGNATURE = ('_','F','V','H')

+    EFI_FVB2_ERASE_POLARITY = 0x800

+

+    DebugInfos = []

+

+    def __init__(self, ec, fv_base, fv_size):

+        self.ec = ec

+        self.fv_base = fv_base

+        self.fv_size = fv_size

+

+        try:

+            signature = struct.unpack("cccc", self.ec.getMemoryService().read(fv_base + 0x28, 4, 32))

+        except DebugException:

+            raise Exception("FirmwareVolume", "Not possible to access the defined firmware volume at [0x%X,0x%X]. Could be the used build report does not correspond to your current debugging context." % (int(fv_base),int(fv_base+fv_size)))

+        if signature != FirmwareVolume.CONST_FV_SIGNATURE:

+            raise Exception("FirmwareVolume", "This is not a valid firmware volume")

+

+    def get_size(self):

+        return self.ec.getMemoryService().readMemory32(self.fv_base + 0x20)

+

+    def get_attributes(self):

+        return self.ec.getMemoryService().readMemory32(self.fv_base + 0x2C)

+

+    def get_polarity(self):

+        attributes = self.get_attributes()

+        if attributes & FirmwareVolume.EFI_FVB2_ERASE_POLARITY:

+            return 1

+        else:

+            return 0

+

+    def get_next_ffs(self, ffs=None):

+        if ffs == None:

+            # Get the offset of the first FFS file from the FV header

+            ffs_base = self.fv_base +  self.ec.getMemoryService().readMemory16(self.fv_base + 0x30)

+        else:

+            # Goto the next FFS file

+            ffs_base = int(ffs.get_base() + ffs.get_size())

+

+            # Align to next 8 byte boundary

+            if (ffs_base & 0x7) != 0:

+                ffs_base = ffs_base + 0x8 - (ffs_base & 0x7)

+

+        if ffs_base < self.fv_base + self.get_size():

+            return FirmwareFile(self, ffs_base, self.ec)

+        else:

+            return None

+

+    def get_debug_info(self):

+        self.DebugInfos = []

+

+        ffs = self.get_next_ffs()

+        while ffs != None:

+            section = ffs.get_next_section()

+            while section != None:

+                type = section.get_type()

+                if (type == EfiFileSection.EFI_SECTION_TE) or (type == EfiFileSection.EFI_SECTION_PE32):

+                    self.DebugInfos.append((section.get_base(), section.get_size(), section.get_type()))

+                section = ffs.get_next_section(section)

+            ffs = self.get_next_ffs(ffs)

+

+    def load_symbols_at(self, addr, verbose = False):

+        if self.DebugInfos == []:

+            self.get_debug_info()

+

+        for debug_info in self.DebugInfos:

+            if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):

+                if debug_info[2] == EfiFileSection.EFI_SECTION_TE:

+                    section = EfiSectionTE(self.ec, debug_info[0] + 0x4)

+                elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:

+                    section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)

+                else:

+                    raise Exception('FirmwareVolume','Section Type not supported')

+

+                try:

+                    edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)

+                except Exception, (ErrorClass, ErrorMessage):

+                    if verbose:

+                        print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)

+

+                return debug_info

+

+    def load_all_symbols(self, verbose = False):

+        if self.DebugInfos == []:

+            self.get_debug_info()

+

+        for debug_info in self.DebugInfos:

+            if debug_info[2] == EfiFileSection.EFI_SECTION_TE:

+                section = EfiSectionTE(self.ec, debug_info[0] + 0x4)

+            elif debug_info[2] == EfiFileSection.EFI_SECTION_PE32:

+                section = EfiSectionPE32(self.ec, debug_info[0] + 0x4)

+            else:

+                continue

+

+            try:

+                edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)

+            except Exception, (ErrorClass, ErrorMessage):

+                if verbose:

+                    print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/profile.py b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/profile.py
new file mode 100644
index 0000000..2e55993
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/profile.py
@@ -0,0 +1,334 @@
+#!/usr/bin/python
+
+#
+#  Copyright (c) 2014, ARM 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.
+#
+
+import getopt
+import operator
+import os
+import pickle
+import sys
+from sys import argv
+from cStringIO import StringIO
+
+modules = {}
+functions = {}
+functions_addr = {}
+
+def usage():
+	print "-t,--trace: Location of the Trace file"
+	print "-s,--symbols: Location of the symbols and modules"
+
+def get_address_from_string(address):
+	return int(address.strip("S:").strip("N:").strip("EL2:").strip("EL1:"), 16)
+
+def get_module_from_addr(modules, addr):
+	for key,value in modules.items():
+		if (value['start'] <= addr) and (addr <= value['end']):
+			return key
+	return None
+
+def add_cycles_to_function(functions, func_name, addr, cycles):
+	if func_name != "<Unknown>":
+		# Check if we are still in the previous function
+		if add_cycles_to_function.prev_func_name == func_name:
+			add_cycles_to_function.prev_entry['cycles'] += cycles
+			return (add_cycles_to_function.prev_func_name, add_cycles_to_function.prev_module_name)
+
+		if func_name in functions.keys():
+			for module_name, module_value in functions[func_name].iteritems():
+				if (module_value['start'] <= addr) and (addr < module_value['end']):
+					module_value['cycles'] += cycles
+
+					add_cycles_to_function.prev_func_name   = func_name
+					add_cycles_to_function.prev_module_name = module_name
+					add_cycles_to_function.prev_entry       = module_value
+					return (func_name, module_name)
+				elif (module_value['end'] == 0):
+					module_value['cycles'] += cycles
+
+					add_cycles_to_function.prev_func_name   = func_name
+					add_cycles_to_function.prev_module_name = module_name
+					add_cycles_to_function.prev_entry       = module_value
+					return (func_name, module_name)
+
+		# Workaround to fix the 'info func' limitation that does not expose the 'static' function
+		module_name = get_module_from_addr(modules, addr)
+		functions[func_name] = {}
+		functions[func_name][module_name] = {}
+		functions[func_name][module_name]['start']  = 0
+		functions[func_name][module_name]['end']    = 0
+		functions[func_name][module_name]['cycles'] = cycles
+		functions[func_name][module_name]['count']  = 0
+
+		add_cycles_to_function.prev_func_name   = func_name
+		add_cycles_to_function.prev_module_name = module_name
+		add_cycles_to_function.prev_entry       = functions[func_name][module_name]
+		return (func_name, module_name)
+	else:
+		# Check if we are still in the previous function
+		if (add_cycles_to_function.prev_entry is not None) and (add_cycles_to_function.prev_entry['start'] <= addr) and (addr < add_cycles_to_function.prev_entry['end']):
+			add_cycles_to_function.prev_entry['cycles'] += cycles
+			return (add_cycles_to_function.prev_func_name, add_cycles_to_function.prev_module_name)
+
+		# Generate the key for the given address
+		key = addr & ~0x0FFF
+
+		if key not in functions_addr.keys():
+			if 'Unknown' not in functions.keys():
+				functions['Unknown'] = {}
+			if 'Unknown' not in functions['Unknown'].keys():
+				functions['Unknown']['Unknown'] = {}
+				functions['Unknown']['Unknown']['cycles'] = 0
+				functions['Unknown']['Unknown']['count'] = 0
+			functions['Unknown']['Unknown']['cycles'] += cycles
+
+			add_cycles_to_function.prev_func_name = None
+			return None
+
+		for func_key, module in functions_addr[key].iteritems():
+			for module_key, module_value in module.iteritems():
+				if (module_value['start'] <= addr) and (addr < module_value['end']):
+					module_value['cycles'] += cycles
+
+					# In case o <Unknown> we prefer to fallback on the direct search
+					add_cycles_to_function.prev_func_name   = func_key
+					add_cycles_to_function.prev_module_name = module_key
+					add_cycles_to_function.prev_entry       = module_value
+					return (func_key, module_key)
+
+	print "Warning: Function %s @ 0x%x not found" % (func_name, addr)
+
+	add_cycles_to_function.prev_func_name = None
+	return None
+
+# Static variables for the previous function
+add_cycles_to_function.prev_func_name = None
+add_cycles_to_function.prev_entry     = None
+
+def trace_read():
+	global trace_process
+	line = trace.readline()
+	trace_process += len(line)
+	return line
+
+#
+# Parse arguments
+#
+trace_name = None
+symbols_file = None
+
+opts,args = getopt.getopt(sys.argv[1:], "ht:vs:v", ["help","trace=","symbols="])
+if (opts is None) or (not opts):
+	usage()
+	sys.exit()
+
+for o,a in opts:
+    if o in ("-h","--help"):
+        usage()
+        sys.exit()
+    elif o in ("-t","--trace"):
+        trace_name = a
+    elif o in ("-s","--symbols"):
+        symbols_file = a
+    else:
+        assert False, "Unhandled option (%s)" % o
+
+#
+# We try first to see if we run the script from DS-5
+#
+try:
+	from arm_ds.debugger_v1 import Debugger
+	from arm_ds.debugger_v1 import DebugException
+
+	# Debugger object for accessing the debugger
+	debugger = Debugger()
+
+	# Initialisation commands
+	ec = debugger.getExecutionContext(0)
+	ec.getExecutionService().stop()
+	ec.getExecutionService().waitForStop()
+	# in case the execution context reference is out of date
+	ec = debugger.getExecutionContext(0)
+
+	#
+	# Get the module name and their memory range
+	#
+	info_file = ec.executeDSCommand("info file")
+	info_file_str = StringIO(info_file)
+
+	line = info_file_str.readline().strip('\n')
+	while line != '':
+		if ("Symbols from" in line):
+			# Get the module name from the line 'Symbols from "/home/...."'
+			module_name = line.split("\"")[1].split("/")[-1]
+			modules[module_name] = {}
+
+			# Look for the text section
+			line = info_file_str.readline().strip('\n')
+			while (line != '') and ("Symbols from" not in line):
+				if ("ER_RO" in line):
+					modules[module_name]['start'] = get_address_from_string(line.split()[0])
+					modules[module_name]['end']   = get_address_from_string(line.split()[2])
+					line = info_file_str.readline().strip('\n')
+					break;
+				if (".text" in line):
+					modules[module_name]['start'] = get_address_from_string(line.split()[0])
+					modules[module_name]['end']   = get_address_from_string(line.split()[2])
+					line = info_file_str.readline().strip('\n')
+					break;
+				line = info_file_str.readline().strip('\n')
+		line = info_file_str.readline().strip('\n')
+
+	#
+	# Get the function name and their memory range
+	#
+	info_func = ec.executeDSCommand("info func")
+	info_func_str = StringIO(info_func)
+
+	# Skip the first line 'Low-level symbols ...'
+	line = info_func_str.readline().strip('\n')
+	func_prev = None
+	while line != '':
+		# We ignore all the functions after 'Functions in'
+		if ("Functions in " in line):
+			line = info_func_str.readline().strip('\n')
+			while line != '':
+				line = info_func_str.readline().strip('\n')
+			line = info_func_str.readline().strip('\n')
+			continue
+
+		if ("Low-level symbols" in line):
+			# We need to fixup the last function of the module
+			if func_prev is not None:
+				func_prev['end'] = modules[module_name]['end']
+				func_prev = None
+
+			line = info_func_str.readline().strip('\n')
+			continue
+
+		func_name = line.split()[1]
+		func_start = get_address_from_string(line.split()[0])
+		module_name = get_module_from_addr(modules, func_start)
+
+		if func_name not in functions.keys():
+			functions[func_name] = {}
+		functions[func_name][module_name] = {}
+		functions[func_name][module_name]['start'] = func_start
+		functions[func_name][module_name]['cycles'] = 0
+		functions[func_name][module_name]['count'] = 0
+
+		# Set the end address of the previous function
+		if func_prev is not None:
+			func_prev['end'] = func_start
+		func_prev = functions[func_name][module_name]
+
+		line = info_func_str.readline().strip('\n')
+
+	# Fixup the last function
+	func_prev['end'] = modules[module_name]['end']
+
+	if symbols_file is not None:
+		pickle.dump((modules, functions), open(symbols_file, "w"))
+except:
+	if symbols_file is None:
+		print "Error: Symbols file is required when run out of ARM DS-5"
+		sys.exit()
+
+	(modules, functions) = pickle.load(open(symbols_file, "r"))
+
+#
+# Build optimized table for the <Unknown> functions
+#
+functions_addr = {}
+for func_key, module in functions.iteritems():
+	for module_key, module_value in module.iteritems():
+		key = module_value['start'] & ~0x0FFF
+		if key not in functions_addr.keys():
+			functions_addr[key] = {}
+		if func_key not in functions_addr[key].keys():
+			functions_addr[key][func_key] = {}
+		functions_addr[key][func_key][module_key] = module_value
+
+#
+# Process the trace file
+#
+if trace_name is None:
+	sys.exit()
+
+trace = open(trace_name, "r")
+trace_size = os.path.getsize(trace_name)
+trace_process = 0
+
+# Get the column names from the first line
+columns = trace_read().split()
+column_addr     = columns.index('Address')
+column_cycles   = columns.index('Cycles')
+column_function = columns.index('Function')
+
+line = trace_read()
+i = 0
+prev_callee = None
+while line:
+	try:
+		func_name = line.split('\t')[column_function].strip()
+		address   = get_address_from_string(line.split('\t')[column_addr])
+		cycles    = int(line.split('\t')[column_cycles])
+		callee = add_cycles_to_function(functions, func_name, address, cycles)
+		if (prev_callee != None) and (prev_callee != callee):
+			functions[prev_callee[0]][prev_callee[1]]['count'] += 1
+		prev_callee = callee
+	except ValueError:
+		pass
+	line = trace_read()
+	if ((i % 1000000) == 0) and (i != 0):
+		percent = (trace_process * 100.00) / trace_size
+		print "Processing file ... (%.2f %%)" % (percent)
+	i = i + 1
+
+# Fixup the last callee
+functions[prev_callee[0]][prev_callee[1]]['count'] += 1
+
+#
+# Process results
+#
+functions_cycles     = {}
+all_functions_cycles = {}
+total_cycles         = 0
+
+for func_key, module in functions.iteritems():
+	for module_key, module_value in module.iteritems():
+		key = "%s/%s" % (module_key, func_key)
+		functions_cycles[key] = (module_value['cycles'], module_value['count'])
+		total_cycles += module_value['cycles']
+
+		if func_key not in all_functions_cycles.keys():
+			all_functions_cycles[func_key] = (module_value['cycles'], module_value['count'])
+		else:
+			all_functions_cycles[func_key] = tuple(map(sum, zip(all_functions_cycles[func_key], (module_value['cycles'], module_value['count']))))
+
+sorted_functions_cycles     = sorted(functions_cycles.iteritems(), key=operator.itemgetter(1), reverse = True)
+sorted_all_functions_cycles = sorted(all_functions_cycles.items(), key=operator.itemgetter(1), reverse = True)
+
+print
+print "----"
+for (key,value) in sorted_functions_cycles[:20]:
+	if value[0] != 0:
+		print "%s (cycles: %d - %d%%, count: %d)" % (key, value[0], (value[0] * 100) / total_cycles, value[1])
+	else:
+		break;
+print "----"
+for (key,value) in sorted_all_functions_cycles[:20]: 
+	if value[0] != 0:
+		print "%s (cycles: %d - %d%%, count: %d)" % (key, value[0], (value[0] * 100) / total_cycles, value[1])
+	else:
+		break;
diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/system_table.py b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/system_table.py
new file mode 100644
index 0000000..0a14f80
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Ds5/system_table.py
@@ -0,0 +1,177 @@
+#

+#  Copyright (c) 2011-2013, ARM 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.

+#

+

+from arm_ds.debugger_v1 import DebugException

+

+import struct

+

+import edk2_debugger

+import firmware_volume

+

+class DebugInfoTable:

+    CONST_DEBUG_INFO_TABLE_GUID = ( 0x49152E77L, 0x47641ADAL, 0xFE7AA2B7L, 0x8B5ED9FEL)

+

+    DebugInfos = []

+

+    def __init__(self, ec, debug_info_table_header_offset):

+        self.ec = ec

+        self.base = debug_info_table_header_offset

+

+    def get_debug_info(self):

+        # Get the information from EFI_DEBUG_IMAGE_INFO_TABLE_HEADER

+        count = self.ec.getMemoryService().readMemory32(self.base + 0x4)

+        if edk2_debugger.is_aarch64(self.ec):

+            debug_info_table_base = self.ec.getMemoryService().readMemory64(self.base + 0x8)

+        else:

+            debug_info_table_base = self.ec.getMemoryService().readMemory32(self.base + 0x8)

+

+        self.DebugInfos = []

+

+        for i in range(0, count):

+            # Get the address of the structure EFI_DEBUG_IMAGE_INFO

+            if edk2_debugger.is_aarch64(self.ec):

+                debug_info = self.ec.getMemoryService().readMemory64(debug_info_table_base + (i * 8))

+            else:

+                debug_info = self.ec.getMemoryService().readMemory32(debug_info_table_base + (i * 4))

+

+            if debug_info:

+                debug_info_type = self.ec.getMemoryService().readMemory32(debug_info)

+                # Normal Debug Info Type

+                if debug_info_type == 1:

+                    if edk2_debugger.is_aarch64(self.ec):

+                        # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL

+                        loaded_image_protocol = self.ec.getMemoryService().readMemory64(debug_info + 0x8)

+

+                        image_base = self.ec.getMemoryService().readMemory64(loaded_image_protocol + 0x40)

+                        image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x48)

+                    else:

+                        # Get the base address of the structure EFI_LOADED_IMAGE_PROTOCOL

+                        loaded_image_protocol = self.ec.getMemoryService().readMemory32(debug_info + 0x4)

+

+                        image_base = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x20)

+                        image_size = self.ec.getMemoryService().readMemory32(loaded_image_protocol + 0x28)

+

+                    self.DebugInfos.append((image_base,image_size))

+

+    # Return (base, size)

+    def load_symbols_at(self, addr, verbose = False):

+        if self.DebugInfos == []:

+            self.get_debug_info()

+

+        found = False

+        for debug_info in self.DebugInfos:

+            if (addr >= debug_info[0]) and (addr < debug_info[0] + debug_info[1]):

+                if edk2_debugger.is_aarch64(self.ec):

+                    section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])

+                else:

+                    section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])

+

+                try:

+                    edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)

+                except Exception, (ErrorClass, ErrorMessage):

+                    if verbose:

+                        print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)

+

+                found = True

+                return debug_info

+

+        if found == False:

+            raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr)

+

+    def load_all_symbols(self, verbose = False):

+        if self.DebugInfos == []:

+            self.get_debug_info()

+

+        for debug_info in self.DebugInfos:

+            if edk2_debugger.is_aarch64(self.ec):

+                section = firmware_volume.EfiSectionPE64(self.ec, debug_info[0])

+            else:

+                section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0])

+

+            try:

+                edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase(), verbose)

+            except Exception, (ErrorClass, ErrorMessage):

+                if verbose:

+                    print "Error while loading a symbol file (%s: %s)" % (ErrorClass, ErrorMessage)

+

+    def dump(self):

+        self.get_debug_info()

+        for debug_info in self.DebugInfos:

+            base_pe32 = debug_info[0]

+            if edk2_debugger.is_aarch64(self.ec):

+                section = firmware_volume.EfiSectionPE64(self.ec, base_pe32)

+            else:

+                section = firmware_volume.EfiSectionPE32(self.ec, base_pe32)

+            print section.get_debug_filepath()

+

+class SystemTable:

+    CONST_ST_SIGNATURE = ('I','B','I',' ','S','Y','S','T')

+

+    def __init__(self, ec, membase, memsize):

+        self.membase = membase

+        self.memsize = memsize

+        self.ec = ec

+

+        found = False

+

+        # Start from the top of the memory

+        offset = self.membase + self.memsize

+        # Align to highest 4MB boundary

+        offset = offset & ~0x3FFFFF

+        # We should not have a System Table at the top of the System Memory

+        offset = offset - 0x400000

+

+        # Start at top and look on 4MB boundaries for system table ptr structure

+        while offset > self.membase:

+            try:

+                signature = struct.unpack("cccccccc", self.ec.getMemoryService().read(str(offset), 8, 32))

+            except DebugException:

+                raise Exception('SystemTable','Fail to access System Memory. Ensure all the memory in the region [0x%x;0x%X] is accessible.' % (membase,membase+memsize))

+            if signature == SystemTable.CONST_ST_SIGNATURE:

+                found = True

+                if edk2_debugger.is_aarch64(self.ec):

+                    self.system_table_base = self.ec.getMemoryService().readMemory64(offset + 0x8)

+                else:

+                    self.system_table_base = self.ec.getMemoryService().readMemory32(offset + 0x8)

+                break

+            offset = offset - 0x400000

+

+        if not found:

+            raise Exception('SystemTable','System Table not found in System Memory [0x%x;0x%X]' % (membase,membase+memsize))

+

+    def get_configuration_table(self, conf_table_guid):

+        if edk2_debugger.is_aarch64(self.ec):

+            # Number of configuration Table entry

+            conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x68)

+

+            # Get location of the Configuration Table entries

+            conf_table_offset = self.ec.getMemoryService().readMemory64(self.system_table_base + 0x70)

+        else:

+            # Number of configuration Table entry

+            conf_table_entry_count = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x40)

+

+            # Get location of the Configuration Table entries

+            conf_table_offset = self.ec.getMemoryService().readMemory32(self.system_table_base + 0x44)

+

+        for i in range(0, conf_table_entry_count):

+            if edk2_debugger.is_aarch64(self.ec):

+                offset = conf_table_offset + (i * 0x18)

+            else:

+                offset = conf_table_offset + (i * 0x14)

+            guid = struct.unpack("<IIII", self.ec.getMemoryService().read(str(offset), 16, 32))

+            if guid == conf_table_guid:

+                if edk2_debugger.is_aarch64(self.ec):

+                    return self.ec.getMemoryService().readMemory64(offset + 0x10)

+                else:

+                    return self.ec.getMemoryService().readMemory32(offset + 0x10)

+

+        raise Exception('SystemTable','Configuration Table not found')

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Makefile b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Makefile
new file mode 100644
index 0000000..f933755
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Scripts/Makefile
@@ -0,0 +1,65 @@
+#/* @file

+#  Copyright (c) 2011-2014, ARM 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.             

+#

+#*/

+

+# Define the following variables to specify an alternative toolchain to the one located in your PATH:

+# - RVCT_TOOLS_PATH: for RVCT and RVCTLINUX toolchains

+# - ARMGCC_TOOLS_PATH: for ARMGCC toolchain

+# - ARMLINUXGCC_TOOLS_PATH: for ARMLINUXGCC

+

+EDK2_TOOLCHAIN ?= RVCTLINUX

+EDK2_ARCH ?= ARM

+EDK2_BUILD ?= DEBUG

+

+ifeq ($(EDK2_DSC),"")

+  $(error The Makfile macro 'EDK2_DSC' must be defined with an EDK2 DSC file.)

+endif

+

+ifeq ("$(OS)","Windows_NT")

+export WORKSPACE?=$(PWD)

+export EDK_TOOLS_PATH ?= $(WORKSPACE)\BaseTools

+endif

+

+SHELL := /bin/bash

+SILENT ?= @

+ECHO ?= echo

+MAKE ?= make -i -k

+RM ?= rm -f

+

+.PHONY: all clean

+

+EDK2_CONF = Conf/BuildEnv.sh Conf/build_rule.txt Conf/target.txt Conf/tools_def.txt

+

+all: $(EDK2_CONF)

+ifeq ("$(OS)","Windows_NT")

+	build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS)

+else

+	. ./edksetup.sh; build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS)

+endif

+

+$(EDK2_CONF):

+ifeq ("$(OS)","Windows_NT")

+	copy $(EDK_TOOLS_PATH)\Conf\build_rule.template Conf\build_rule.txt

+	copy $(EDK_TOOLS_PATH)\Conf\FrameworkDatabase.template Conf\FrameworkDatabase.txt

+	copy $(EDK_TOOLS_PATH)\Conf\target.template Conf\target.txt

+	copy $(EDK_TOOLS_PATH)\Conf\tools_def.template Conf\tools_def.txt

+else

+	. ./edksetup.sh; $(MAKE) -C BaseTools

+endif

+

+clean:

+ifeq ("$(OS)","Windows_NT")

+	build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS) cleanall

+else

+	. ./edksetup.sh; build -a $(EDK2_ARCH) -p $(EDK2_DSC) -t $(EDK2_TOOLCHAIN) -b $(EDK2_BUILD) $(EDK2_MACROS) cleanall; \

+	rm -Rf $(EDK2_CONF) Conf/.cache

+endif

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/Arch.c b/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/Arch.c
new file mode 100644
index 0000000..6e7d58e
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/Arch.c
@@ -0,0 +1,25 @@
+/** @file

+*

+*  Copyright (c) 2013, ARM 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.

+*

+**/

+

+#include <Chipset/AArch64.h>

+

+VOID

+EFIAPI

+ArmSecArchTrustzoneInit (

+  VOID

+  )

+{

+  // Do not trap any access to Floating Point and Advanced SIMD in EL3.

+  ArmWriteCptr (0);

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/Helper.S b/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/Helper.S
new file mode 100644
index 0000000..3b58e12
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/Helper.S
@@ -0,0 +1,93 @@
+#========================================================================================

+#  Copyright (c) 2011-2014, ARM 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.

+#

+#=======================================================================================

+

+#include <AsmMacroIoLibV8.h>

+#include <Chipset/AArch64.h>

+

+#start of the code section

+.text

+.align 3

+

+GCC_ASM_EXPORT(SwitchToNSExceptionLevel1)

+GCC_ASM_EXPORT(enter_monitor_mode)

+GCC_ASM_EXPORT(return_from_exception)

+GCC_ASM_EXPORT(copy_cpsr_into_spsr)

+GCC_ASM_EXPORT(set_non_secure_mode)

+

+// Switch from EL3 to NS-EL1

+ASM_PFX(SwitchToNSExceptionLevel1):

+   // Now setup our EL1. Controlled by EL2 config on Model

+   mrs     x0, hcr_el2            // Read EL2 Hypervisor configuration Register

+   orr     x0, x0, #(1 << 31)     // Set EL1 to be 64bit

+

+   // Send all interrupts to their respective Exception levels for EL2

+   and     x0, x0, #~(ARM_HCR_FMO | ARM_HCR_IMO | ARM_HCR_AMO) // Disable virtual FIQ, IRQ, SError and Abort

+   msr     hcr_el2, x0            // Write back our settings

+

+   msr     cptr_el2, xzr          // Disable copro traps to EL2

+

+   msr     sctlr_el2, xzr

+

+   // Enable architected timer access

+   mrs     x0, cnthctl_el2

+   orr     x0, x0, #3             // Enable EL1 access to timers

+   msr     cnthctl_el2, x0

+

+   mrs     x0, cntkctl_el1

+   orr     x0, x0, #3             // EL0 access to counters

+   msr     cntkctl_el1, x0

+

+   // Set ID regs

+   mrs     x0, midr_el1

+   mrs     x1, mpidr_el1

+   msr     vpidr_el2, x0

+   msr     vmpidr_el2, x1

+

+   ret

+

+

+// EL3 on AArch64 is Secure/monitor so this funtion is reduced vs ARMv7

+// we don't need a mode switch, just setup the Arguments and jump.

+// x0: Monitor World EntryPoint

+// x1: MpId

+// x2: SecBootMode

+// x3: Secure Monitor mode stack

+ASM_PFX(enter_monitor_mode):

+   mov     x4, x0                 // Swap EntryPoint and MpId registers

+   mov     x0, x1

+   mov     x1, x2

+   mov     x2, x3

+   br      x4

+

+// Put the address in correct ELR_ELx and do a eret.

+// We may need to do some config before we change to another Mode.

+ASM_PFX(return_from_exception):

+   msr     elr_el3, x0

+   eret

+

+// For AArch64 we need to construct the spsr we want from individual bits and pieces.

+ASM_PFX(copy_cpsr_into_spsr):

+   mrs     x0, CurrentEl  // Get the current exception level we  are running at.

+   mrs     x1, SPSel      // Which Stack are we using

+   orr     x0, x0, x1

+   mrs     x1, daif       // Which interrupts are enabled

+   orr     x0, x0, x1

+   msr     spsr_el3, x0   // Write to spsr

+   ret

+

+// Get this from platform file.

+ASM_PFX(set_non_secure_mode):

+   msr     spsr_el3, x0

+   ret

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/SecEntryPoint.S b/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/SecEntryPoint.S
new file mode 100644
index 0000000..3512ccd
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/AArch64/SecEntryPoint.S
@@ -0,0 +1,143 @@
+//

+//  Copyright (c) 2011-2014, ARM 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.

+//

+//

+

+#include <AutoGen.h>

+#include <AsmMacroIoLibV8.h>

+#include "SecInternal.h"

+

+.text

+.align 3

+

+GCC_ASM_IMPORT(CEntryPoint)

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmPlatformGetCorePosition)

+GCC_ASM_IMPORT(ArmPlatformSecBootAction)

+GCC_ASM_IMPORT(ArmPlatformSecBootMemoryInit)

+GCC_ASM_IMPORT(ArmDisableInterrupts)

+GCC_ASM_IMPORT(ArmDisableCachesAndMmu)

+GCC_ASM_IMPORT(ArmReadMpidr)

+GCC_ASM_IMPORT(ArmCallWFE)

+GCC_ASM_EXPORT(_ModuleEntryPoint)

+

+StartupAddr:        .8byte       ASM_PFX(CEntryPoint)

+

+ASM_PFX(_ModuleEntryPoint):

+

+// NOTE: We could be booting from EL3, EL2 or EL1. Need to correctly detect

+//       and configure the system accordingly. EL2 is default if possible.

+// If we started in EL3 we need to switch and run at EL2.

+// If we are running at EL2 stay in EL2

+// If we are starting at EL1 stay in EL1.

+

+// Sec only runs in EL3. Othewise we jump to PEI without changing anything.

+// If Sec runs we change to EL2 before switching to PEI.

+

+// Which EL are we running at? Every EL needs some level of setup...

+  EL1_OR_EL2_OR_EL3(x0)

+1:// If we are at EL1 or EL2 leave SEC for PEI.

+2:b     ASM_PFX(JumpToPEI)

+  // If we are at EL3 we need to configure it and switch to EL2

+3:b     ASM_PFX(MainEntryPoint)

+

+ASM_PFX(MainEntryPoint):

+  // First ensure all interrupts are disabled

+  bl    ASM_PFX(ArmDisableInterrupts)

+

+  // Ensure that the MMU and caches are off

+  bl    ASM_PFX(ArmDisableCachesAndMmu)

+

+  // By default, we are doing a cold boot

+  mov   x10, #ARM_SEC_COLD_BOOT

+

+  // Jump to Platform Specific Boot Action function

+  bl    ASM_PFX(ArmPlatformSecBootAction)

+

+_IdentifyCpu:

+  // Identify CPU ID

+  bl    ASM_PFX(ArmReadMpidr)

+  // Keep a copy of the MpId register value

+  mov   x5, x0

+

+  // Is it the Primary Core ?

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+  cmp   x0, #1

+  // Only the primary core initialize the memory (SMC)

+  b.eq  _InitMem

+

+_WaitInitMem:

+  // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized

+  // Otherwise we have to wait the Primary Core to finish the initialization

+  cmp   x10, #ARM_SEC_COLD_BOOT

+  b.ne  _SetupSecondaryCoreStack

+

+  // Wait for the primary core to initialize the initial memory (event: BOOT_MEM_INIT)

+  bl    ASM_PFX(ArmCallWFE)

+  // Now the Init Mem is initialized, we setup the secondary core stacks

+  b     _SetupSecondaryCoreStack

+

+_InitMem:

+  // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized

+  cmp   x10, #ARM_SEC_COLD_BOOT

+  b.ne  _SetupPrimaryCoreStack

+

+  // Initialize Init Boot Memory

+  bl    ASM_PFX(ArmPlatformSecBootMemoryInit)

+

+_SetupPrimaryCoreStack:

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), x1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), x2)

+  add   x1, x1, x2

+

+  LoadConstantToReg (FixedPcdGet32(PcdSecGlobalVariableSize), x2)

+

+  // The reserved space for global variable must be 8-bytes aligned for pushing

+  // 64-bit variable on the stack

+  SetPrimaryStack (x1, x2, x3, x4)

+  b     _PrepareArguments

+

+_SetupSecondaryCoreStack:

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), x1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), x2)

+  add   x6, x1, x2

+

+  // Get the Core Position

+  mov   x0, x5

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+  // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack

+  add   x0, x0, #1

+

+  // StackOffset = CorePos * StackSize

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecSecondaryStackSize), x2)

+  mul   x0, x0, x2

+  // SP = StackBase + StackOffset

+  add   sp, x6, x0

+

+_PrepareArguments:

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   x3, StartupAddr

+

+  // Jump to SEC C code

+  //    r0 = mp_id

+  //    r1 = Boot Mode

+  mov   x0, x5

+  mov   x1, x10

+  blr   x3

+

+  ret

+

+ASM_PFX(JumpToPEI):

+  LoadConstantToReg (FixedPcdGet32(PcdFvBaseAddress), x0)

+  blr   x0

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Arch.c b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Arch.c
new file mode 100644
index 0000000..85df081
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Arch.c
@@ -0,0 +1,25 @@
+/** @file

+*

+*  Copyright (c) 2013, ARM 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.

+*

+**/

+

+#include <Chipset/ArmV7.h>

+

+VOID

+EFIAPI

+ArmSecArchTrustzoneInit (

+  VOID

+  )

+{

+  // Write to CP15 Non-secure Access Control Register

+  ArmWriteNsacr (PcdGet32 (PcdArmNsacr));

+}

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Helper.S b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Helper.S
new file mode 100644
index 0000000..ac40102
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Helper.S
@@ -0,0 +1,84 @@
+#========================================================================================

+#  Copyright (c) 2011-2014, ARM 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.

+#

+#=======================================================================================

+

+#start of the code section

+.text

+.align 3

+

+GCC_ASM_EXPORT(return_from_exception)

+GCC_ASM_EXPORT(enter_monitor_mode)

+GCC_ASM_EXPORT(copy_cpsr_into_spsr)

+GCC_ASM_EXPORT(set_non_secure_mode)

+

+# r0: Monitor World EntryPoint

+# r1: MpId

+# r2: SecBootMode

+# r3: Secure Monitor mode stack

+ASM_PFX(enter_monitor_mode):

+    cmp     r3, #0                      @ If a Secure Monitor stack base has not been defined then use the Secure stack

+    moveq   r3, sp

+

+    mrs     r4, cpsr                    @ Save current mode (SVC) in r4

+    bic     r5, r4, #0x1f               @ Clear all mode bits

+    orr     r5, r5, #0x16               @ Set bits for Monitor mode

+    msr     cpsr_cxsf, r5               @ We are now in Monitor Mode

+

+    mov     sp, r3                      @ Set the stack of the Monitor Mode

+

+    mov     lr, r0                      @ Use the pass entrypoint as lr

+

+    msr     spsr_cxsf, r4               @ Use saved mode for the MOVS jump to the kernel

+

+    mov     r4, r0                      @ Swap EntryPoint and MpId registers

+    mov     r0, r1

+    mov     r1, r2

+    mov     r2, r3

+

+    bx      r4

+

+# We cannot use the instruction 'movs pc, lr' because the caller can be written either in ARM or Thumb2 assembler.

+# When we will jump into this function, we will set the CPSR flag to ARM assembler. By copying directly 'lr' into

+# 'pc'; we will not change the CPSR flag and it will crash.

+# The way to fix this limitation is to do the movs into the ARM assmbler code and then do a 'bx'.

+ASM_PFX(return_from_exception):

+    ldr     lr, returned_exception

+

+    #The following instruction breaks the code.

+    #movs    pc, lr

+    mrs     r2, cpsr

+    bic     r2, r2, #0x1f

+    orr     r2, r2, #0x13

+    msr     cpsr_c, r2

+

+returned_exception:                           @ We are now in non-secure state

+    bx      r0

+

+# Save the current Program Status Register (PSR) into the Saved PSR

+ASM_PFX(copy_cpsr_into_spsr):

+    mrs     r0, cpsr

+    msr     spsr_cxsf, r0

+    bx      lr

+

+# Set the Non Secure Mode

+ASM_PFX(set_non_secure_mode):

+    push    { r1 }

+    and     r0, r0, #0x1f     @ Keep only the mode bits

+    mrs     r1, spsr          @ Read the spsr

+    bic     r1, r1, #0x1f     @ Clear all mode bits

+    orr     r1, r1, r0

+    msr     spsr_cxsf, r1     @ write back spsr (may have caused a mode switch)

+    isb

+    pop     { r1 }

+    bx      lr                @ return (hopefully thumb-safe!)

+

+ASM_FUNCTION_REMOVE_IF_UNREFERENCED

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Helper.asm b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Helper.asm
new file mode 100644
index 0000000..8aa7d78
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/Helper.asm
@@ -0,0 +1,79 @@
+//

+//  Copyright (c) 2011-2012, ARM 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.

+//

+//

+

+    EXPORT  return_from_exception

+    EXPORT  enter_monitor_mode

+    EXPORT  copy_cpsr_into_spsr

+    EXPORT  set_non_secure_mode

+

+    AREA   Helper, CODE, READONLY

+

+// r0: Monitor World EntryPoint

+// r1: MpId

+// r2: SecBootMode

+// r3: Secure Monitor mode stack

+enter_monitor_mode FUNCTION

+    cmp     r3, #0                      // If a Secure Monitor stack base has not been defined then use the Secure stack

+    moveq   r3, sp

+

+    mrs     r4, cpsr                    // Save current mode (SVC) in r4

+    bic     r5, r4, #0x1f               // Clear all mode bits

+    orr     r5, r5, #0x16               // Set bits for Monitor mode

+    msr     cpsr_cxsf, r5               // We are now in Monitor Mode

+

+    mov     sp, r3                      // Set the stack of the Monitor Mode

+

+    mov     lr, r0                      // Use the pass entrypoint as lr

+

+    msr     spsr_cxsf, r4               // Use saved mode for the MOVS jump to the kernel

+

+    mov     r4, r0                      // Swap EntryPoint and MpId registers

+    mov     r0, r1

+    mov     r1, r2

+    mov     r2, r3

+

+    bx      r4

+    ENDFUNC

+

+// We cannot use the instruction 'movs pc, lr' because the caller can be written either in ARM or Thumb2 assembler.

+// When we will jump into this function, we will set the CPSR flag to ARM assembler. By copying directly 'lr' into

+// 'pc'; we will not change the CPSR flag and it will crash.

+// The way to fix this limitation is to do the movs into the ARM assmbler code and then do a 'bx'.

+return_from_exception

+    adr     lr, returned_exception

+    movs    pc, lr

+returned_exception                           // We are now in non-secure state

+    bx      r0

+

+// Save the current Program Status Register (PSR) into the Saved PSR

+copy_cpsr_into_spsr

+    mrs     r0, cpsr

+    msr     spsr_cxsf, r0

+    bx      lr

+

+// Set the Non Secure Mode

+set_non_secure_mode

+    push    { r1 }

+    and     r0, r0, #0x1f     // Keep only the mode bits

+    mrs     r1, spsr          // Read the spsr

+    bic     r1, r1, #0x1f     // Clear all mode bits

+    orr     r1, r1, r0

+    msr     spsr_cxsf, r1     // write back spsr (may have caused a mode switch)

+    isb

+    pop     { r1 }

+    bx      lr                // return (hopefully thumb-safe!)

+

+dead

+    B       dead

+

+    END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/SecEntryPoint.S b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/SecEntryPoint.S
new file mode 100644
index 0000000..51b91b9
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/SecEntryPoint.S
@@ -0,0 +1,122 @@
+//

+//  Copyright (c) 2011-2013, ARM 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.

+//

+//

+

+#include <AutoGen.h>

+#include <AsmMacroIoLib.h>

+#include "SecInternal.h"

+

+.text

+.align 3

+

+GCC_ASM_IMPORT(CEntryPoint)

+GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)

+GCC_ASM_IMPORT(ArmPlatformGetCorePosition)

+GCC_ASM_IMPORT(ArmPlatformSecBootAction)

+GCC_ASM_IMPORT(ArmPlatformSecBootMemoryInit)

+GCC_ASM_IMPORT(ArmDisableInterrupts)

+GCC_ASM_IMPORT(ArmDisableCachesAndMmu)

+GCC_ASM_IMPORT(ArmReadMpidr)

+GCC_ASM_IMPORT(ArmCallWFE)

+GCC_ASM_EXPORT(_ModuleEntryPoint)

+

+StartupAddr:        .word       ASM_PFX(CEntryPoint)

+

+ASM_PFX(_ModuleEntryPoint):

+  // First ensure all interrupts are disabled

+  bl    ASM_PFX(ArmDisableInterrupts)

+

+  // Ensure that the MMU and caches are off

+  bl    ASM_PFX(ArmDisableCachesAndMmu)

+

+  // By default, we are doing a cold boot

+  mov   r10, #ARM_SEC_COLD_BOOT

+

+  // Jump to Platform Specific Boot Action function

+  blx   ASM_PFX(ArmPlatformSecBootAction)

+

+_IdentifyCpu:

+  // Identify CPU ID

+  bl    ASM_PFX(ArmReadMpidr)

+  // Keep a copy of the MpId register value

+  mov   r9, r0

+

+  // Is it the Primary Core ?

+  bl    ASM_PFX(ArmPlatformIsPrimaryCore)

+  cmp   r0, #1

+  // Only the primary core initialize the memory (SMC)

+  beq   _InitMem

+

+_WaitInitMem:

+  // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized

+  // Otherwise we have to wait the Primary Core to finish the initialization

+  cmp   r10, #ARM_SEC_COLD_BOOT

+  bne   _SetupSecondaryCoreStack

+

+  // Wait for the primary core to initialize the initial memory (event: BOOT_MEM_INIT)

+  bl    ASM_PFX(ArmCallWFE)

+  // Now the Init Mem is initialized, we setup the secondary core stacks

+  b     _SetupSecondaryCoreStack

+

+_InitMem:

+  // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized

+  cmp   r10, #ARM_SEC_COLD_BOOT

+  bne   _SetupPrimaryCoreStack

+

+  // Initialize Init Boot Memory

+  bl    ASM_PFX(ArmPlatformSecBootMemoryInit)

+

+_SetupPrimaryCoreStack:

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)

+  add   r1, r1, r2

+

+  LoadConstantToReg (FixedPcdGet32(PcdSecGlobalVariableSize), r2)

+

+  // The reserved space for global variable must be 8-bytes aligned for pushing

+  // 64-bit variable on the stack

+  SetPrimaryStack (r1, r2, r3)

+  b     _PrepareArguments

+

+_SetupSecondaryCoreStack:

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)

+  add   r6, r1, r2

+

+  // Get the Core Position

+  mov   r0, r9

+  bl    ASM_PFX(ArmPlatformGetCorePosition)

+  // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack

+  add   r0, r0, #1

+

+  // StackOffset = CorePos * StackSize

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecSecondaryStackSize), r2)

+  mul   r0, r0, r2

+  // SP = StackBase + StackOffset

+  add   sp, r6, r0

+

+_PrepareArguments:

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   r3, StartupAddr

+

+  // Jump to SEC C code

+  //    r0 = mp_id

+  //    r1 = Boot Mode

+  mov   r0, r9

+  mov   r1, r10

+  blx   r3

+

+_NeverReturn:

+  b _NeverReturn

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/SecEntryPoint.asm b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/SecEntryPoint.asm
new file mode 100644
index 0000000..b30fab2
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Arm/SecEntryPoint.asm
@@ -0,0 +1,126 @@
+//

+//  Copyright (c) 2011-2013, ARM 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.

+//

+//

+

+#include <AutoGen.h>

+#include <AsmMacroIoLib.h>

+#include "SecInternal.h"

+

+  INCLUDE AsmMacroIoLib.inc

+

+  IMPORT  CEntryPoint

+  IMPORT  ArmPlatformIsPrimaryCore

+  IMPORT  ArmPlatformGetCorePosition

+  IMPORT  ArmPlatformSecBootAction

+  IMPORT  ArmPlatformSecBootMemoryInit

+  IMPORT  ArmDisableInterrupts

+  IMPORT  ArmDisableCachesAndMmu

+  IMPORT  ArmReadMpidr

+  IMPORT  ArmCallWFE

+  EXPORT  _ModuleEntryPoint

+

+  PRESERVE8

+  AREA    SecEntryPoint, CODE, READONLY

+

+StartupAddr        DCD      CEntryPoint

+

+_ModuleEntryPoint FUNCTION

+  // First ensure all interrupts are disabled

+  bl    ArmDisableInterrupts

+

+  // Ensure that the MMU and caches are off

+  bl    ArmDisableCachesAndMmu

+

+  // By default, we are doing a cold boot

+  mov   r10, #ARM_SEC_COLD_BOOT

+

+  // Jump to Platform Specific Boot Action function

+  blx   ArmPlatformSecBootAction

+

+_IdentifyCpu

+  // Identify CPU ID

+  bl    ArmReadMpidr

+  // Keep a copy of the MpId register value

+  mov   r9, r0

+

+  // Is it the Primary Core ?

+  bl    ArmPlatformIsPrimaryCore

+  cmp   r0, #1

+  // Only the primary core initialize the memory (SMC)

+  beq   _InitMem

+

+_WaitInitMem

+  // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized

+  // Otherwise we have to wait the Primary Core to finish the initialization

+  cmp   r10, #ARM_SEC_COLD_BOOT

+  bne   _SetupSecondaryCoreStack

+

+  // Wait for the primary core to initialize the initial memory (event: BOOT_MEM_INIT)

+  bl    ArmCallWFE

+  // Now the Init Mem is initialized, we setup the secondary core stacks

+  b     _SetupSecondaryCoreStack

+

+_InitMem

+  // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized

+  cmp   r10, #ARM_SEC_COLD_BOOT

+  bne   _SetupPrimaryCoreStack

+

+  // Initialize Init Boot Memory

+  bl    ArmPlatformSecBootMemoryInit

+

+_SetupPrimaryCoreStack

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)

+  add   r1, r1, r2

+

+  LoadConstantToReg (FixedPcdGet32(PcdSecGlobalVariableSize), r2)

+

+  // The reserved space for global variable must be 8-bytes aligned for pushing

+  // 64-bit variable on the stack

+  SetPrimaryStack (r1, r2, r3)

+  b     _PrepareArguments

+

+_SetupSecondaryCoreStack

+  // Get the top of the primary stacks (and the base of the secondary stacks)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)

+  add   r6, r1, r2

+

+  // Get the Core Position

+  mov   r0, r9

+  bl    ArmPlatformGetCorePosition

+  // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack

+  add   r0, r0, #1

+

+  // StackOffset = CorePos * StackSize

+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecSecondaryStackSize), r2)

+  mul   r0, r0, r2

+  // SP = StackBase + StackOffset

+  add   sp, r6, r0

+

+_PrepareArguments

+  // Move sec startup address into a data register

+  // Ensure we're jumping to FV version of the code (not boot remapped alias)

+  ldr   r3, StartupAddr

+

+  // Jump to SEC C code

+  //    r0 = mp_id

+  //    r1 = Boot Mode

+  mov   r0, r9

+  mov   r1, r10

+  blx   r3

+  ENDFUNC

+

+_NeverReturn

+  b _NeverReturn

+  END

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/Sec.c b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Sec.c
new file mode 100644
index 0000000..7127395
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Sec.c
@@ -0,0 +1,200 @@
+/** @file

+*  Main file supporting the SEC Phase on ARM Platforms

+*

+*  Copyright (c) 2011-2014, ARM 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.

+*

+**/

+

+#include <Library/ArmTrustedMonitorLib.h>

+#include <Library/DebugAgentLib.h>

+#include <Library/PrintLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/SerialPortLib.h>

+#include <Library/ArmGicLib.h>

+#include <Library/ArmPlatformLib.h>

+

+#include "SecInternal.h"

+

+#define SerialPrint(txt)  SerialPortWrite ((UINT8*)txt, AsciiStrLen(txt)+1);

+

+VOID

+CEntryPoint (

+  IN  UINTN                     MpId,

+  IN  UINTN                     SecBootMode

+  )

+{

+  CHAR8           Buffer[100];

+  UINTN           CharCount;

+  UINTN           JumpAddress;

+

+  // Invalidate the data cache. Doesn't have to do the Data cache clean.

+  ArmInvalidateDataCache ();

+

+  // Invalidate Instruction Cache

+  ArmInvalidateInstructionCache ();

+

+  // Invalidate I & D TLBs

+  ArmInvalidateTlb ();

+

+  // CPU specific settings

+  ArmCpuSetup (MpId);

+

+  // Enable Floating Point Coprocessor if supported by the platform

+  if (FixedPcdGet32 (PcdVFPEnabled)) {

+    ArmEnableVFP ();

+  }

+

+  // Initialize peripherals that must be done at the early stage

+  // Example: Some L2 controller, interconnect, clock, DMC, etc

+  ArmPlatformSecInitialize (MpId);

+

+  // Primary CPU clears out the SCU tag RAMs, secondaries wait

+  if (ArmPlatformIsPrimaryCore (MpId) && (SecBootMode == ARM_SEC_COLD_BOOT)) {

+    if (ArmIsMpCore()) {

+      // Signal for the initial memory is configured (event: BOOT_MEM_INIT)

+      ArmCallSEV ();

+    }

+

+    // SEC phase needs to run library constructors by hand. This assumes we are linked against the SerialLib

+    // In non SEC modules the init call is in autogenerated code.

+    SerialPortInitialize ();

+

+    // Start talking

+    if (FixedPcdGetBool (PcdTrustzoneSupport)) {

+      CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Secure firmware (version %s built at %a on %a)\n\r",

+          (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);

+    } else {

+      CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Boot firmware (version %s built at %a on %a)\n\r",

+          (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);

+    }

+    SerialPortWrite ((UINT8 *) Buffer, CharCount);

+

+    // Initialize the Debug Agent for Source Level Debugging

+    InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);

+    SaveAndSetDebugTimerInterrupt (TRUE);

+

+    // Enable the GIC distributor and CPU Interface

+    // - no other Interrupts are enabled,  doesn't have to worry about the priority.

+    // - all the cores are in secure state, use secure SGI's

+    ArmGicEnableDistributor (PcdGet32(PcdGicDistributorBase));

+    ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));

+  } else {

+    // Enable the GIC CPU Interface

+    ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));

+  }

+

+  // Enable Full Access to CoProcessors

+  ArmWriteCpacr (CPACR_CP_FULL_ACCESS);

+

+  // Test if Trustzone is supported on this platform

+  if (FixedPcdGetBool (PcdTrustzoneSupport)) {

+    if (ArmIsMpCore ()) {

+      // Setup SMP in Non Secure world

+      ArmCpuSetupSmpNonSecure (GET_CORE_ID(MpId));

+    }

+

+    // Either we use the Secure Stacks for Secure Monitor (in this case (Base == 0) && (Size == 0))

+    // Or we use separate Secure Monitor stacks (but (Base != 0) && (Size != 0))

+    ASSERT (((PcdGet32(PcdCPUCoresSecMonStackBase) == 0) && (PcdGet32(PcdCPUCoreSecMonStackSize) == 0)) ||

+            ((PcdGet32(PcdCPUCoresSecMonStackBase) != 0) && (PcdGet32(PcdCPUCoreSecMonStackSize) != 0)));

+

+    // Enter Monitor Mode

+    enter_monitor_mode (

+      (UINTN)TrustedWorldInitialization, MpId, SecBootMode,

+      (VOID*) (PcdGet32 (PcdCPUCoresSecMonStackBase) +

+          (PcdGet32 (PcdCPUCoreSecMonStackSize) * (ArmPlatformGetCorePosition (MpId) + 1)))

+      );

+  } else {

+    if (ArmPlatformIsPrimaryCore (MpId)) {

+      SerialPrint ("Trust Zone Configuration is disabled\n\r");

+    }

+

+    // With Trustzone support the transition from Sec to Normal world is done by return_from_exception().

+    // If we want to keep this function call we need to ensure the SVC's SPSR point to the same Program

+    // Status Register as the the current one (CPSR).

+    copy_cpsr_into_spsr ();

+

+    // Call the Platform specific function to execute additional actions if required

+    JumpAddress = PcdGet64 (PcdFvBaseAddress);

+    ArmPlatformSecExtraAction (MpId, &JumpAddress);

+

+    NonTrustedWorldTransition (MpId, JumpAddress);

+  }

+  ASSERT (0); // We must never return from the above function

+}

+

+VOID

+TrustedWorldInitialization (

+  IN  UINTN                     MpId,

+  IN  UINTN                     SecBootMode

+  )

+{

+  UINTN   JumpAddress;

+

+  //-------------------- Monitor Mode ---------------------

+

+  // Set up Monitor World (Vector Table, etc)

+  ArmSecureMonitorWorldInitialize ();

+

+  // Transfer the interrupt to Non-secure World

+  ArmGicSetupNonSecure (MpId, PcdGet32(PcdGicDistributorBase), PcdGet32(PcdGicInterruptInterfaceBase));

+

+  // Initialize platform specific security policy

+  ArmPlatformSecTrustzoneInit (MpId);

+

+  // Setup the Trustzone Chipsets

+  if (SecBootMode == ARM_SEC_COLD_BOOT) {

+    if (ArmPlatformIsPrimaryCore (MpId)) {

+      if (ArmIsMpCore()) {

+        // Signal the secondary core the Security settings is done (event: EVENT_SECURE_INIT)

+        ArmCallSEV ();

+      }

+    } else {

+      // The secondary cores need to wait until the Trustzone chipsets configuration is done

+      // before switching to Non Secure World

+

+      // Wait for the Primary Core to finish the initialization of the Secure World (event: EVENT_SECURE_INIT)

+      ArmCallWFE ();

+    }

+  }

+

+  // Call the Platform specific function to execute additional actions if required

+  JumpAddress = PcdGet64 (PcdFvBaseAddress);

+  ArmPlatformSecExtraAction (MpId, &JumpAddress);

+

+  // Initialize architecture specific security policy

+  ArmSecArchTrustzoneInit ();

+

+  // CP15 Secure Configuration Register

+  ArmWriteScr (PcdGet32 (PcdArmScr));

+

+  NonTrustedWorldTransition (MpId, JumpAddress);

+}

+

+VOID

+NonTrustedWorldTransition (

+  IN  UINTN                     MpId,

+  IN  UINTN                     JumpAddress

+  )

+{

+  // If PcdArmNonSecModeTransition is defined then set this specific mode to CPSR before the transition

+  // By not set, the mode for Non Secure World is SVC

+  if (PcdGet32 (PcdArmNonSecModeTransition) != 0) {

+    set_non_secure_mode ((ARM_PROCESSOR_MODE)PcdGet32 (PcdArmNonSecModeTransition));

+  }

+

+  return_from_exception (JumpAddress);

+  //-------------------- Non Secure Mode ---------------------

+

+  // PEI Core should always load and never return

+  ASSERT (FALSE);

+}

+

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/Sec.inf b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Sec.inf
new file mode 100644
index 0000000..27e64c7
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/Sec.inf
@@ -0,0 +1,84 @@
+#/** @file

+#  SEC - Reset vector code that jumps to C and starts the PEI phase

+#

+#  Copyright (c) 2011-2013, ARM 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]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = ArmPlatformSec

+  FILE_GUID                      = c536bbfe-c813-4e48-9f90-01fe1ecf9d54

+  MODULE_TYPE                    = SEC

+  VERSION_STRING                 = 1.0

+

+[Sources]

+  Sec.c

+

+[Sources.ARM]

+  Arm/Arch.c

+  Arm/Helper.asm           | RVCT

+  Arm/Helper.S             | GCC

+  Arm/SecEntryPoint.S      | GCC

+  Arm/SecEntryPoint.asm    | RVCT

+

+[Sources.AARCH64]

+  AArch64/Arch.c

+  AArch64/Helper.S

+  AArch64/SecEntryPoint.S

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+  ArmPkg/ArmPkg.dec

+  ArmPlatformPkg/ArmPlatformPkg.dec

+

+[LibraryClasses]

+  ArmCpuLib

+  ArmLib

+  ArmPlatformLib

+  ArmPlatformSecLib

+  ArmTrustedMonitorLib

+  BaseLib

+  DebugLib

+  DebugAgentLib

+  IoLib

+  ArmGicLib

+  PrintLib

+  SerialPortLib

+

+[FixedPcd.common]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString

+

+  gArmTokenSpaceGuid.PcdTrustzoneSupport

+  gArmTokenSpaceGuid.PcdVFPEnabled

+

+  gArmTokenSpaceGuid.PcdArmScr

+  gArmTokenSpaceGuid.PcdArmNonSecModeTransition

+

+  gArmTokenSpaceGuid.PcdSecureFvBaseAddress

+  gArmTokenSpaceGuid.PcdSecureFvSize

+

+  gArmTokenSpaceGuid.PcdFvBaseAddress

+

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecStackBase

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecPrimaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecSecondaryStackSize

+  gArmPlatformTokenSpaceGuid.PcdCPUCoresSecMonStackBase

+  gArmPlatformTokenSpaceGuid.PcdCPUCoreSecMonStackSize

+

+  gArmTokenSpaceGuid.PcdGicDistributorBase

+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase

+

+  gArmPlatformTokenSpaceGuid.PcdSecGlobalVariableSize

+

+[FixedPcd.ARM]

+  gArmTokenSpaceGuid.PcdArmNsacr

diff --git a/uefi/linaro-edk2/ArmPlatformPkg/Sec/SecInternal.h b/uefi/linaro-edk2/ArmPlatformPkg/Sec/SecInternal.h
new file mode 100644
index 0000000..1111237
--- /dev/null
+++ b/uefi/linaro-edk2/ArmPlatformPkg/Sec/SecInternal.h
@@ -0,0 +1,83 @@
+/** @file

+*  Main file supporting the SEC Phase on ARM PLatforms

+*

+*  Copyright (c) 2011-2013, ARM 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.

+*

+**/

+

+#ifndef __SEC_H__

+#define __SEC_H__

+

+#include <Base.h>

+#include <Library/ArmLib.h>

+#include <Library/ArmCpuLib.h>

+#include <Library/ArmPlatformLib.h>

+#include <Library/ArmPlatformSecLib.h>

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/PcdLib.h>

+

+#define IS_ALIGNED(Address, Align) (((UINTN)Address & (Align-1)) == 0)

+

+VOID

+TrustedWorldInitialization (

+  IN  UINTN                     MpId,

+  IN  UINTN                     SecBootMode

+  );

+

+VOID

+NonTrustedWorldTransition (

+  IN  UINTN                     MpId,

+  IN  UINTN                     JumpAddress

+  );

+

+VOID

+ArmSetupGicNonSecure (

+  IN  INTN                  GicDistributorBase,

+  IN  INTN                  GicInterruptInterfaceBase

+);

+

+VOID

+enter_monitor_mode (

+  IN UINTN                  MonitorEntryPoint,

+  IN UINTN                  MpId,

+  IN UINTN                  SecBootMode,

+  IN VOID*                  MonitorStackBase

+  );

+

+VOID

+return_from_exception (

+  IN UINTN                  NonSecureBase

+  );

+

+VOID

+copy_cpsr_into_spsr (

+  VOID

+  );

+

+VOID

+set_non_secure_mode (

+  IN ARM_PROCESSOR_MODE     Mode

+  );

+

+VOID

+SecCommonExceptionEntry (

+  IN UINT32 Entry,

+  IN UINTN  LR

+  );

+

+VOID

+EFIAPI

+ArmSecArchTrustzoneInit (

+  VOID

+  );

+

+#endif