diff options
Diffstat (limited to 'edk2/ArmPlatformPkg')
23 files changed, 1509 insertions, 337 deletions
diff --git a/edk2/ArmPlatformPkg/ArmPlatformPkg.dec b/edk2/ArmPlatformPkg/ArmPlatformPkg.dec index 3e2900ba3..07205273b 100644 --- a/edk2/ArmPlatformPkg/ArmPlatformPkg.dec +++ b/edk2/ArmPlatformPkg/ArmPlatformPkg.dec @@ -135,7 +135,8 @@ # - 2 = a Linux kernel with FDT support
gArmPlatformTokenSpaceGuid.PcdDefaultBootType|0|UINT32|0x00000010
gArmPlatformTokenSpaceGuid.PcdFdtDevicePath|L""|VOID*|0x00000011
-
+ gArmPlatformTokenSpaceGuid.PcdFdtLocalDevicePath|L""|VOID*|0x0000002E + ## 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
diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.dsc b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.dsc index 33ff82cc7..963243d8f 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.dsc +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.dsc @@ -30,7 +30,9 @@ BUILD_TARGETS = DEBUG|RELEASE
SKUID_IDENTIFIER = DEFAULT
FLASH_DEFINITION = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15-A7.fdf
+!ifndef $(EDK2_SKIP_PEICORE) DEFINE EDK2_SKIP_PEICORE=1
+!endif !include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc
@@ -125,8 +127,8 @@ # A7_0 = 0x100, GicCoreId = 2
# A7_1 = 0x101, GicCoreId = 3
# A7_2 = 0x102, GicCoreId = 4
- gArmTokenSpaceGuid.PcdArmPrimaryCore|0x100
- gArmTokenSpaceGuid.PcdGicPrimaryCoreId|2
+ gArmTokenSpaceGuid.PcdArmPrimaryCore|0
+ gArmTokenSpaceGuid.PcdGicPrimaryCoreId|0
!endif
#
diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15x2.dsc b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15x2.dsc index 59368e489..d785eb3d8 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15x2.dsc +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15x2.dsc @@ -30,6 +30,9 @@ BUILD_TARGETS = DEBUG|RELEASE SKUID_IDENTIFIER = DEFAULT FLASH_DEFINITION = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA15x2.fdf +!ifndef $(EDK2_ARMVE_STANDALONE) + DEFINE EDK2_ARMVE_STANDALONE=1 +!endif !include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc @@ -193,7 +196,7 @@ # # ARM Architectual Timer Frequency # - gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|60000000 + gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|600000000 ################################################################################ diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA5s.dsc b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA5s.dsc index 67756c063..a41680d23 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA5s.dsc +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA5s.dsc @@ -30,6 +30,9 @@ BUILD_TARGETS = DEBUG|RELEASE SKUID_IDENTIFIER = DEFAULT FLASH_DEFINITION = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA5s.fdf +!ifndef $(EDK2_ARMVE_STANDALONE) + DEFINE EDK2_ARMVE_STANDALONE=1 +!endif !include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc index b4040c28f..11eba89d9 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc @@ -30,6 +30,12 @@ BUILD_TARGETS = DEBUG|RELEASE
SKUID_IDENTIFIER = DEFAULT
FLASH_DEFINITION = ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.fdf
+!ifndef $(EDK2_ARMVE_STANDALONE) + DEFINE EDK2_ARMVE_STANDALONE=1 +!endif +!ifndef $(EDK2_ARMVE_SINGLE_BINARY) + DEFINE EDK2_ARMVE_SINGLE_BINARY=1 +!endif !include ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc
diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15x2/CTA15x2Boot.S b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15x2/CTA15x2Boot.S index f09d2cf1e..d865d6701 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15x2/CTA15x2Boot.S +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA15x2/CTA15x2Boot.S @@ -74,6 +74,23 @@ ASM_PFX(ArmPlatformSecBootMemoryInit): **/ smc_init: + // + // Disable loop buffer for A15 + // + MRC p15, 0, r2, c0, c0, 0 + MOV r1, r2, lsr #4 + LDR r0, =0xFFF + AND r1, r1, r0 + LDR r0, =0xC0F // See if A15 + CMP r1, r0 + BNE smc_init2 // Go if not + + MRC p15, 0, r1, c1, c0, 1 // Read Aux Ctrl Reg + ORR r1, r1, #(1 << 1) // Set Bit 1 + MCR p15, 0, r1, c1, c0, 1 // and write it back + +smc_init2: + LDR r0, = ARM_VE_SMC_CTRL_BASE LDR r2, = ARM_VE_SMB_PERIPH_BASE @@ -141,6 +158,13 @@ smc_init: LDR r1, = 0x03C00000 STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + // Set refresh period + LDR r1, = 0x1 + STR r1, [r0, #0x20] + + LDR r1, = 0x1 + STR r1, [r0, #0x24] + // page mode setup for VRAM LDR r0, = 0x00FFFFFC ADD r0, r0, r2 @@ -465,6 +489,15 @@ waitloop_14: LDR r3, =0 STR r3, [r2, #PHY_PTM_SQU_TRAINING] + // For Test Chip Change Program architected timer frequency + MRC p15, 0, r0, c0, c1, 1 // CPUID_EXT_PFR1 + LSR r0, r0, #16 + ANDS r0, r0, #1 // Check generic timer support + BEQ exit + LDR r0, = 600000000 // 600MHz timer frequency + MCR p15, 0, r0, c14, c0, 0 // CNTFRQ + +exit: bx lr // end of dmc_init diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressLib.inf b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressLib.inf index 129660417..c368456d2 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressLib.inf +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressLib.inf @@ -46,6 +46,3 @@ gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize gArmTokenSpaceGuid.PcdFvBaseAddress - - gArmTokenSpaceGuid.PcdArmPrimaryCoreMask - gArmTokenSpaceGuid.PcdArmPrimaryCore diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressSecLib.inf b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressSecLib.inf index f0521b95c..cec7bbe8a 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressSecLib.inf +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/ArmVExpressSecLib.inf @@ -48,6 +48,3 @@ [FixedPcd] gArmTokenSpaceGuid.PcdFvBaseAddress - - gArmTokenSpaceGuid.PcdArmPrimaryCoreMask - gArmTokenSpaceGuid.PcdArmPrimaryCore diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5s.c b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5s.c index 48934cc6d..227f9e62f 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5s.c +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5s.c @@ -51,39 +51,6 @@ ARM_CORE_INFO mVersatileExpressMpCoreInfoCTA5s[] = { }, }; -// DDR2 timings -PL341_DMC_CONFIG DDRTimings = { - .MaxChip = 1, - .IsUserCfg = FALSE, - .User0Cfg = 0x7C924924, - .User2Cfg = (TC_UIOLHXC_VALUE << TC_UIOLHNC_SHIFT) | (TC_UIOLHXC_VALUE << TC_UIOLHPC_SHIFT) | (0x1 << TC_UIOHOCT_SHIFT) | (0x1 << TC_UIOHSTOP_SHIFT), - .HasQos = FALSE, - .RefreshPeriod = 0x3D0, - .CasLatency = 0xA, - .WriteLatency = 0x3, - .t_mrd = 0x2, - .t_ras = 0xC, - .t_rc = 0xF, - .t_rcd = 0x104, - .t_rfc = 0x1022, - .t_rp = 0x104, - .t_rrd = 0x2, - .t_wr = 0x4, - .t_wtr = 0x2, - .t_xp = 0x2, - .t_xsr = 0xC8, - .t_esr = 0x4, - .MemoryCfg = DMC_MEMORY_CONFIG_ACTIVE_CHIP_1 | DMC_MEMORY_CONFIG_BURST_4 | - DMC_MEMORY_CONFIG_ROW_ADDRESS_14 | DMC_MEMORY_CONFIG_COLUMN_ADDRESS_10, - .MemoryCfg2 = DMC_MEMORY_CFG2_BANK_BITS_3 | DMC_MEMORY_CFG2_MEM_WIDTH_64, - .MemoryCfg3 = 0x00000001, - .ChipCfg0 = 0x000180C0, - .ChipCfg1 = 0x0000FF00, - .t_faw = 0x00000407, - .ModeReg = DDR2_MR_BURST_LENGTH_4 | DDR2_MR_CAS_LATENCY_5 | DDR2_MR_WR_CYCLES_3, - .ExtModeReg = 0x47, -}; - /** Return the current Boot Mode @@ -111,15 +78,11 @@ ArmPlatformGetBootMode ( in the PEI phase. **/ -RETURN_STATUS -ArmPlatformInitialize ( - IN UINTN MpId +VOID +ArmPlatformNormalInitialize ( + VOID ) { - if (!IS_PRIMARY_CORE(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 @@ -128,8 +91,6 @@ ArmPlatformInitialize ( 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; } /** @@ -143,7 +104,7 @@ ArmPlatformInitializeSystemMemory ( VOID ) { - PL341DmcInit(ARM_VE_DMC_BASE, &DDRTimings); + // Memory is initialised in CTA5sBoot.S } EFI_STATUS @@ -194,3 +155,16 @@ ArmPlatformSecTrustzoneInit ( { } + /** + This function is called by the ArmPlatformPkg/PrePi or ArmPlatformPkg/PlatformPei + in the PEI phase. + +**/ +RETURN_STATUS +ArmPlatformInitialize ( + IN UINTN MpId + ) +{ + return RETURN_SUCCESS; +} + diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5sBoot.S b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5sBoot.S index f90546ef2..62750bde2 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5sBoot.S +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA5s/CTA5sBoot.S @@ -15,6 +15,7 @@ #include <Base.h> #include <Library/ArmPlatformLib.h> #include <Drivers/PL35xSmc.h> +#include <Drivers/PL341Dmc.h> #include <ArmPlatform.h> #include <AutoGen.h> @@ -23,44 +24,8 @@ GCC_ASM_EXPORT(ArmPlatformSecBootAction) GCC_ASM_EXPORT(ArmPlatformInitializeBootMemory) -GCC_ASM_IMPORT(PL35xSmcInitialize) GCC_ASM_EXPORT(ArmPlatformSecBootMemoryInit) -// -// 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 @@ -84,7 +49,8 @@ ASM_PFX(ArmPlatformSecBootAction): **/ ASM_PFX(ArmPlatformInitializeBootMemory): - bx lr + bx lr + /** Initialize the memory where the initial stacks will reside @@ -97,43 +63,324 @@ ASM_PFX(ArmPlatformInitializeBootMemory): **/ 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 + mov r8, lr + bl smc_init + bl dmc_init + bx r8 + + +/** + Initialise the Static Memory Controller +**/ +smc_init: + + // + // Disable loop buffer for A15 + // + MRC p15, 0, r2, c0, c0, 0 + MOV r1, r2, lsr #4 + LDR r0, =0xFFF + AND r1, r1, r0 + LDR r0, =0xC0F // See if A15 + CMP r1, r0 + BNE smc_init2 // Go if not + + MRC p15, 0, r1, c1, c0, 1 // Read Aux Ctrl Reg + ORR r1, r1, #(1 << 1) // Set Bit 1 + MCR p15, 0, r1, c1, c0, 1 // and write it back + +smc_init2: + + LDR r0, = ARM_VE_SMC_CTRL_BASE + LDR r2, = ARM_VE_SMB_PERIPH_BASE + + // CS0 - NOR0 + LDR r1, = 0x0002393A + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000AAA + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x00400000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // CS1 - PSRAM + LDR r1, = 0x00027158 + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000802 + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x00C00000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // CS2 - usb, ethernet and vram + LDR r1, = 0x000CD2AA + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000046 + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x01400000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // CS3 - IOFPGA peripherals + LDR r1, = 0x00025156 + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000046 + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x01C00000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // CS4 - NOR1 + LDR r1, = 0x0002393A + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000AAA + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x02400000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // CS5 - unused + LDR r1, = 0x0002393A + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000AAA + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x02C00000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // CS6 - unused + LDR r1, = 0x0002393A + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000AAA + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x03400000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // CS7 - unused + LDR r1, = 0x0002393A + STR r1, [r0, #PL350_SMC_SET_CYCLES_OFFSET] + LDR r1, = 0x00000AAA + STR r1, [r0, #PL350_SMC_SET_OPMODE_OFFSET] + LDR r1, = 0x03C00000 + STR r1, [r0, #PL350_SMC_DIRECT_CMD_OFFSET] + + // Set refresh period + LDR r1, = 0x1 + STR r1, [r0, #0x20] + + LDR r1, = 0x1 + STR r1, [r0, #0x24] + + // page mode setup for VRAM + LDR r0, = 0x00FFFFFC + ADD r0, r0, r2 + + // read current state + LDR r1, [r0, #0] + LDR r1, [r0, #0] + LDR r1, = 0x00000000 + STR r1, [r0, #0] + LDR r1, [r0, #0] + + // enable page mode + LDR r1, [r0, #0] + LDR r1, [r0, #0] + LDR r1, = 0x00000000 + STR r1, [r0, #0] + LDR r1, = 0x00900090 + STR r1, [r0, #0] + + // confirm page mode enabled + LDR r1, [r0, #0] + LDR r1, [r0, #0] + LDR r1, = 0x00000000 + STR r1, [r0, #0] + LDR r1, [r0, #0] + + BX lr + // end of smc_init + + +/** + Initialise the PL341 Dynamic Memory Controller (DMC) + + On A15, the PHY needs to be locked before configuring the DMC. + After DMC config, the PHY needs to be trained +**/ +#define SCC_PHY_RESET_REG_OFFSET 0x04 + +dmc_init: + + LDR r0, = ARM_VE_DMC_BASE + LDR r1, = ARM_VE_BOARD_PERIPH_BASE + + // On entry:- + // r0 = base address of ssmc controller + // r1 = address of system registers + + // Initializes V2P_CA5 dynamic memory controller + + MOV r2, r1 + + // set config mode + MOV r1, #0x4 + STR r1, [r0, #DMC_COMMAND_REG] + + // initialise memory controlller + + // refresh period + LDR r1, =0x3D0 + STR r1, [r0, #DMC_REFRESH_PRD_REG] + + // cas latency + MOV r1, #0xA + STR r1, [r0, #DMC_CAS_LATENCY_REG] + + // write latency + MOV r1, #0x3 + STR r1, [r0, #DMC_WRITE_LATENCY_REG] + + // t_mrd + MOV r1, #0x2 + STR r1, [r0, #DMC_T_MRD_REG] + + // t_ras + MOV r1, #0x0C + STR r1, [r0, #DMC_T_RAS_REG] + + // t_rc + MOV r1, #0x0F + STR r1, [r0, #DMC_T_RC_REG] + + // t_rcd + LDR r1, =0x00000104 + STR r1, [r0,#DMC_T_RCD_REG] + + // t_rfc + LDR r1, =0x00001022 + STR r1, [r0, #DMC_T_RFC_REG] + + // t_rp + LDR r1, =0x00000104 + STR r1, [r0, #DMC_T_RP_REG] + + // t_rrd + MOV r1, #0x2 + STR r1, [r0, #DMC_T_RRD_REG] + + // t_wr + MOV r1, #0x4 + STR r1, [r0, #DMC_T_WR_REG] + + // t_wtr + MOV r1, #0x2 + STR r1, [r0, #DMC_T_WTR_REG] + + // t_xp + MOV r1, #0x2 + STR r1, [r0, #DMC_T_XP_REG] + + // t_xsr + MOV r1, #0xC8 + STR r1, [r0, #DMC_T_XSR_REG] + + // t_esr + MOV r1, #0x04 + STR r1, [r0, #DMC_T_ESR_REG] + + // t_faw + LDR r1, =0x00000407 + STR r1, [r0, #DMC_T_FAW_REG] + + // set memory config + LDR r1, =0x0001001A + STR r1, [r0, #DMC_MEMORY_CONFIG_REG] + + // set memory config 2 + LDR r1, =0x000000B0 + STR r1, [r0, #DMC_MEMORY_CFG2_REG] + + // initialise external memory chips + // set chip select for chip configuration + LDR r1, =0x000180C0 + STR r1, [r0, #DMC_CHIP_0_CFG_REG] + + // config memories + + // send nop + LDR r1, =0x000C0000 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // delay + MOV r1, #0 +B1: LDR r3, [r0, #DMC_STATUS_REG] // read status register + ADD r1, r1, #1 + CMP r1, #10 + BLT B1 + + // pre-charge all + MOV r1, #0x0 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // delay + MOV r1, #0 +B2: LDR r3, [r0, #DMC_STATUS_REG] // read status register + ADD r1, r1, #1 + CMP r1, #10 + BLT B2 + + // set extended mode register 2 + LDR r1, =0x000A8000 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // set extended mode register 3 + MOV r1, #0x000B0000 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // set extended mode register + LDR r1, =0x00094005 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // set mode register -DLL reset + LDR r1, =0x00080552 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // delay + MOV r1, #0 +B3: LDR r3, [r0, #DMC_STATUS_REG] // read status register + ADD r1, r1, #1 + CMP r1, #10 + BLT B3 + + // pre-charge all + MOV r1, #0x0 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // auto-refresh + MOV r1, #0x00040000 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // auto-refresh + MOV r1, #0x00040000 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // set mode register + LDR r1, =0x00080452 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // set extended mode register - Enable OCD defaults + LDR r1, =0x000943C5 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + // set extended mode register - OCD Exit + LDR r1, =0x00094047 + STR r1, [r0, #DMC_DIRECT_CMD_REG] + + //---------------------------------------- + // go command + MOV r1, #0x0 + STR r1, [r0, #DMC_COMMAND_REG] + // wait for ready +B4: LDR r1, [r0,#DMC_STATUS_REG] + TST r1,#1 + BEQ B4 + +exit: + bx lr + // end of dmc_init diff --git a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c index b7e7b3700..986044156 100644 --- a/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c +++ b/edk2/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4.c @@ -212,3 +212,11 @@ ArmPlatformGetPlatformPpiList ( *PpiList = gPlatformPpiTable; } +UINTN +ArmPlatformGetCorePosition ( + IN UINTN MpId + ) +{ + return 1; +} + diff --git a/edk2/ArmPlatformPkg/Bds/Bds.c b/edk2/ArmPlatformPkg/Bds/Bds.c index 11a76de90..fe463774e 100644 --- a/edk2/ArmPlatformPkg/Bds/Bds.c +++ b/edk2/ArmPlatformPkg/Bds/Bds.c @@ -223,8 +223,10 @@ DefineDefaultBootEntries ( ARM_BDS_LOADER_ARGUMENTS* BootArguments;
ARM_BDS_LOADER_TYPE BootType;
EFI_DEVICE_PATH* InitrdPath;
+ EFI_DEVICE_PATH* FdtLocalPath; UINTN CmdLineSize;
UINTN InitrdSize;
+ UINTN FdtLocalSize; //
// If Boot Order does not exist then create a default entry
@@ -262,17 +264,21 @@ DefineDefaultBootEntries ( if (BootDevicePath != NULL) {
BootType = (ARM_BDS_LOADER_TYPE)PcdGet32 (PcdDefaultBootType);
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) { CmdLineSize = AsciiStrSize ((CHAR8*)PcdGetPtr(PcdDefaultBootArgument));
InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));
InitrdSize = GetDevicePathSize (InitrdPath);
+ FdtLocalPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtLocalDevicePath)); + FdtLocalSize = GetDevicePathSize (FdtLocalPath); - BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);
+ BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize + FdtLocalSize); BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
BootArguments->LinuxArguments.InitrdSize = InitrdSize;
+ BootArguments->LinuxArguments.FdtLocalSize = FdtLocalSize; CopyMem ((VOID*)(BootArguments + 1), (CHAR8*)PcdGetPtr(PcdDefaultBootArgument), CmdLineSize);
CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
+ CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineSize + InitrdSize), FdtLocalPath, FdtLocalSize); } else {
BootArguments = NULL;
}
diff --git a/edk2/ArmPlatformPkg/Bds/Bds.inf b/edk2/ArmPlatformPkg/Bds/Bds.inf index 164e2ae52..f48879367 100644 --- a/edk2/ArmPlatformPkg/Bds/Bds.inf +++ b/edk2/ArmPlatformPkg/Bds/Bds.inf @@ -67,6 +67,7 @@ gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument gArmPlatformTokenSpaceGuid.PcdDefaultBootType gArmPlatformTokenSpaceGuid.PcdFdtDevicePath + gArmPlatformTokenSpaceGuid.PcdFdtLocalDevicePath gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths diff --git a/edk2/ArmPlatformPkg/Bds/BdsInternal.h b/edk2/ArmPlatformPkg/Bds/BdsInternal.h index 1307e2ae6..9bc8229d7 100644 --- a/edk2/ArmPlatformPkg/Bds/BdsInternal.h +++ b/edk2/ArmPlatformPkg/Bds/BdsInternal.h @@ -48,16 +48,19 @@ typedef enum {
BDS_LOADER_EFI_APPLICATION = 0,
BDS_LOADER_KERNEL_LINUX_ATAG,
- BDS_LOADER_KERNEL_LINUX_FDT,
+ BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT, + BDS_LOADER_KERNEL_LINUX_LOCAL_FDT, } ARM_BDS_LOADER_TYPE;
typedef struct {
UINT16 CmdLineSize;
UINT16 InitrdSize;
-
+ UINT16 FdtLocalSize; + // These following fields have variable length and are packed:
//CHAR8 *CmdLine;
//EFI_DEVICE_PATH_PROTOCOL *InitrdPathList;
+ //EFI_DEVICE_PATH_PROTOCOL *FdtLocalPathList; } ARM_BDS_LINUX_ARGUMENTS;
typedef union {
diff --git a/edk2/ArmPlatformPkg/Bds/BootMenu.c b/edk2/ArmPlatformPkg/Bds/BootMenu.c index 3f443fca8..eeea35cd0 100644 --- a/edk2/ArmPlatformPkg/Bds/BootMenu.c +++ b/edk2/ArmPlatformPkg/Bds/BootMenu.c @@ -125,9 +125,12 @@ BootMenuAddBootOption ( EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
EFI_DEVICE_PATH_PROTOCOL *InitrdPathNode;
EFI_DEVICE_PATH_PROTOCOL *InitrdPath;
+ EFI_DEVICE_PATH_PROTOCOL *FdtLocalPathNode; + EFI_DEVICE_PATH_PROTOCOL *FdtLocalPath; UINTN CmdLineSize;
BOOLEAN InitrdSupport;
UINTN InitrdSize;
+ UINTN FdtLocalSize; Attributes = 0;
SupportedBootDevice = NULL;
@@ -148,7 +151,7 @@ BootMenuAddBootOption ( // Append the Device Path node to the select device path
DevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNode);
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) { Print(L"Add an initrd: ");
Status = GetHIInputBoolean (&InitrdSupport);
if (EFI_ERROR(Status)) {
@@ -181,15 +184,36 @@ BootMenuAddBootOption ( goto FREE_DEVICE_PATH;
}
+ if (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) { + // Create the specific device path node + Status = SupportedBootDevice->Support->CreateDevicePathNode (L"local FDT", &FdtLocalPathNode, NULL, NULL); + 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 (FdtLocalPathNode != NULL) { + // Append the Device Path node to the select device path + FdtLocalPath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)FdtLocalPathNode); + } else { + FdtLocalPath = NULL; + } + } else { + FdtLocalPath = NULL; + } + CmdLineSize = AsciiStrSize (CmdLine);
InitrdSize = GetDevicePathSize (InitrdPath);
+ FdtLocalSize = GetDevicePathSize (FdtLocalPath); - BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);
+ BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize + FdtLocalSize); BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
BootArguments->LinuxArguments.InitrdSize = InitrdSize;
+ BootArguments->LinuxArguments.FdtLocalSize = FdtLocalSize; CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), CmdLine, CmdLineSize);
CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
+ CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize + InitrdSize), FdtLocalPath, FdtLocalSize); } else {
BootArguments = NULL;
}
@@ -264,7 +288,7 @@ BootMenuSelectBootOption ( Print(L"\t- %s\n",DevicePathTxt);
OptionalData = BdsLoadOption->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 ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) { Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);
}
@@ -356,14 +380,19 @@ BootMenuUpdateBootOption ( CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];
EFI_DEVICE_PATH *DevicePath;
EFI_DEVICE_PATH *TempInitrdPath;
+ EFI_DEVICE_PATH *TempFdtLocalPath; ARM_BDS_LOADER_TYPE BootType;
ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;
EFI_DEVICE_PATH *InitrdPathNode;
EFI_DEVICE_PATH *InitrdPath;
UINTN InitrdSize;
+ EFI_DEVICE_PATH *FdtLocalPathNode; + EFI_DEVICE_PATH *FdtLocalPath; + UINTN FdtLocalSize; UINTN CmdLineSize;
BOOLEAN InitrdSupport;
+ BOOLEAN FdtLocalSupport; Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, TRUE, &BootOptionEntry);
if (EFI_ERROR(Status)) {
@@ -387,7 +416,7 @@ BootMenuUpdateBootOption ( OptionalData = BootOption->OptionalData;
BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) { LinuxArguments = &OptionalData->Arguments.LinuxArguments;
CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);
@@ -451,13 +480,65 @@ BootMenuUpdateBootOption ( goto FREE_DEVICE_PATH;
}
+ FdtLocalSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->FdtLocalSize); + if (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) { + if (FdtLocalSize > 0) { + Print(L"Keep the local FDT: "); + } else { + Print(L"Add a local FDT: "); + } + Status = GetHIInputBoolean (&FdtLocalSupport); + if (EFI_ERROR(Status)) { + Status = EFI_ABORTED; + goto EXIT; + } + if (FdtLocalSupport && BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) { + if (FdtLocalSize > 0) { + // Case we update the FDT local device path + Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize + InitrdSize), L"local FDT", &FdtLocalPath, NULL, NULL); + if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string + Status = EFI_ABORTED; + goto EXIT; + } + FdtLocalSize = GetDevicePathSize (FdtLocalPath); + } else { + // Case we create the FdtLocal device path + + Status = DeviceSupport->CreateDevicePathNode (L"local FDT", &FdtLocalPathNode, NULL, NULL); + if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string + Status = EFI_ABORTED; + goto EXIT; + } + + if (FdtLocalPathNode != NULL) { + // Duplicate Linux kernel Device Path + TempFdtLocalPath = DuplicateDevicePath (BootOption->FilePathList); + // Replace Linux kernel Node by EndNode + SetDevicePathEndNode (GetLastDevicePathNode (TempFdtLocalPath)); + // Append the Device Path node to the select device path + FdtLocalPath = AppendDevicePathNode (TempFdtLocalPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)FdtLocalPathNode); + FreePool (TempFdtLocalPath); + FdtLocalSize = GetDevicePathSize (FdtLocalPath); + } else { + FdtLocalPath = NULL; + } + } + } else { + FdtLocalSize = 0; + } + } else { + FdtLocalSupport = FALSE; + } + CmdLineSize = AsciiStrSize (CmdLine);
- BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);
+ BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize + FdtLocalSize); BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
BootArguments->LinuxArguments.InitrdSize = InitrdSize;
+ BootArguments->LinuxArguments.FdtLocalSize = FdtLocalSize; CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);
CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
+ CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize + InitrdSize), FdtLocalPath, FdtLocalSize); } else {
BootArguments = NULL;
}
@@ -613,6 +694,9 @@ BootMenuMain ( UINTN Index;
UINTN BootMainEntryCount;
CHAR8 BootOptionSelectedStr[32]; + EFI_DEVICE_PATH_PROTOCOL* DefaultFdtDevicePath; + UINTN FdtDevicePathSize; + BootOption = NULL;
BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);
@@ -633,45 +717,94 @@ BootMenuMain ( 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);
- }
- Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));
+ CHAR16* DevicePathTxt; + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol; + ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData; + UINTN CmdLineSize; + UINTN InitrdSize; + 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_GLOBAL_FDT) || (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_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); }
- Print(L"\t- LoaderType: %d\n", LoaderType);
+ Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1)); }
- FreePool(DevicePathTxt);
- DEBUG_CODE_END();
+ + 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 data\n"); + break; + case BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT: + Print(L"\t- LoaderType: Linux kernel with global FDT\n"); + break; + case BDS_LOADER_KERNEL_LINUX_LOCAL_FDT: + if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.FdtLocalSize) > 0) { + CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize); + InitrdSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize); + DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ( + GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize + InitrdSize)), TRUE, TRUE); + Print(L"\t- FDT: %s\n", DevicePathTxt); + } else { + Print(L"\t- FDT: error, local FDT not specified, using global FDT\n"); + } + Print(L"\t- LoaderType: Linux kernel with Local FDT\n"); + break; + default: + Print(L"unknown\n"); + break; + } + } + FreePool(DevicePathTxt); OptionCount++;
}
BootOptionCount = OptionCount-1;
+ // Display the global FDT config + Print(L"-----------------------\n"); + { + EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol; + EFI_DEVICE_PATH_PROTOCOL* FdtDevicePath; + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol; + CHAR16* DevicePathTxt; + + // 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", DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath); + ASSERT_EFI_ERROR(Status); + + // Convert FdtDevicePath to text + Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol); + DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ( FdtDevicePath, TRUE, TRUE ); + Print(L"Global FDT Config\n\t- %s\n", DevicePathTxt); + } + // Display the hardcoded Boot entries
Print(L"-----------------------\n"); for (Index = 0; Index < BootMainEntryCount; Index++) {
diff --git a/edk2/ArmPlatformPkg/Bds/BootOption.c b/edk2/ArmPlatformPkg/Bds/BootOption.c index 289d36a50..df0a23223 100644 --- a/edk2/ArmPlatformPkg/Bds/BootOption.c +++ b/edk2/ArmPlatformPkg/Bds/BootOption.c @@ -32,6 +32,7 @@ BootOptionStart ( UINTN CmdLineSize;
UINTN InitrdSize;
EFI_DEVICE_PATH* Initrd;
+ UINTN FdtLocalSize; UINT16 LoadOptionIndexSize;
if (IS_ARM_BDS_BOOTENTRY (BootOption)) {
@@ -58,7 +59,7 @@ BootOptionStart ( Status = BdsBootLinuxAtag (BootOption->FilePathList,
Initrd, // Initrd
(CHAR8*)(LinuxArguments + 1)); // CmdLine
- } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT) {
+ } else if ((LoaderType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) { LinuxArguments = &(OptionalData->Arguments.LinuxArguments);
CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);
InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);
@@ -69,15 +70,25 @@ BootOptionStart ( 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", DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath);
- ASSERT_EFI_ERROR(Status);
+ if (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) { + FdtLocalSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->FdtLocalSize); +
+ if (FdtLocalSize > 0) { + FdtDevicePath = GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize + InitrdSize)); + } else { + FdtDevicePath = NULL; + } + } else { + // 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", DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath); + ASSERT_EFI_ERROR(Status); + } Status = BdsBootLinuxFdt (BootOption->FilePathList,
Initrd, // Initrd
@@ -157,6 +168,7 @@ BootOptionSetFields ( UINT16 FilePathListLength;
UINT8* EfiLoadOptionPtr;
UINT8* InitrdPathListPtr;
+ UINT8* FdtLocalPathListPtr; UINTN OptionalDataSize;
ARM_BDS_LINUX_ARGUMENTS* DestLinuxArguments;
ARM_BDS_LINUX_ARGUMENTS* SrcLinuxArguments;
@@ -168,8 +180,8 @@ BootOptionSetFields ( BootDescriptionSize = StrSize (BootDescription);
BootOptionalDataSize = sizeof(ARM_BDS_LOADER_OPTIONAL_DATA_HEADER);
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
- BootOptionalDataSize += sizeof(ARM_BDS_LINUX_ARGUMENTS) + BootArguments->LinuxArguments.CmdLineSize + BootArguments->LinuxArguments.InitrdSize;
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) { + BootOptionalDataSize += sizeof(ARM_BDS_LINUX_ARGUMENTS) + BootArguments->LinuxArguments.CmdLineSize + BootArguments->LinuxArguments.InitrdSize + BootArguments->LinuxArguments.FdtLocalSize; }
// Compute the size of the FilePath list
@@ -211,12 +223,13 @@ BootOptionSetFields ( OptionalDataSize = sizeof(ARM_BDS_LOADER_OPTIONAL_DATA_HEADER);
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) { SrcLinuxArguments = &(BootArguments->LinuxArguments);
DestLinuxArguments = &((ARM_BDS_LOADER_OPTIONAL_DATA*)EfiLoadOptionPtr)->Arguments.LinuxArguments;
WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->CmdLineSize), SrcLinuxArguments->CmdLineSize);
WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->InitrdSize), SrcLinuxArguments->InitrdSize);
+ WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->FdtLocalSize), SrcLinuxArguments->FdtLocalSize); OptionalDataSize += sizeof (ARM_BDS_LINUX_ARGUMENTS);
if (SrcLinuxArguments->CmdLineSize > 0) {
@@ -228,6 +241,11 @@ BootOptionSetFields ( InitrdPathListPtr = (UINT8*)((UINTN)(DestLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize);
CopyMem (InitrdPathListPtr, (VOID*)((UINTN)(SrcLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize), SrcLinuxArguments->InitrdSize);
}
+ + if (SrcLinuxArguments->FdtLocalSize > 0) { + FdtLocalPathListPtr = (UINT8*)((UINTN)(DestLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize + SrcLinuxArguments->InitrdSize); + CopyMem (FdtLocalPathListPtr, (VOID*)((UINTN)(SrcLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize + SrcLinuxArguments->InitrdSize), SrcLinuxArguments->FdtLocalSize); + } }
BootOption->OptionalDataSize = OptionalDataSize;
diff --git a/edk2/ArmPlatformPkg/Bds/BootOptionSupport.c b/edk2/ArmPlatformPkg/Bds/BootOptionSupport.c index fbdd5947d..897786f5a 100644 --- a/edk2/ArmPlatformPkg/Bds/BootOptionSupport.c +++ b/edk2/ArmPlatformPkg/Bds/BootOptionSupport.c @@ -233,7 +233,7 @@ BootDeviceGetType ( EFI_STATUS Status;
BOOLEAN IsEfiApp;
BOOLEAN IsBootLoader;
- BOOLEAN HasFDTSupport;
+ CHAR16 FDTType[16]; if (FileName == NULL) {
Print(L"Is an EFI Application? ");
@@ -258,16 +258,20 @@ BootDeviceGetType ( }
*BootType = BDS_LOADER_EFI_APPLICATION;
} else {
- Print(L"Has FDT support? ");
- Status = GetHIInputBoolean (&HasFDTSupport);
+ Print(L"Boot Type: [a] ATAGS, [g] Global FDT or [l] Local FDT? [a/g/l] "); + Status = GetHIInputStr (FDTType, 16); if (EFI_ERROR(Status)) {
return EFI_ABORTED;
}
- if (HasFDTSupport) {
- *BootType = BDS_LOADER_KERNEL_LINUX_FDT;
- } else {
+ if (StrCmp(FDTType, L"g") == 0) { + *BootType = BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT; + } else if (StrCmp(FDTType, L"l") == 0) { + *BootType = BDS_LOADER_KERNEL_LINUX_LOCAL_FDT; + } else if (StrCmp(FDTType, L"a") == 0) { *BootType = BDS_LOADER_KERNEL_LINUX_ATAG;
- }
+ } else { + return EFI_ABORTED; + } }
return EFI_SUCCESS;
diff --git a/edk2/ArmPlatformPkg/Documentation/patches/BaseTools-Pending-Patches.patch b/edk2/ArmPlatformPkg/Documentation/patches/BaseTools-Pending-Patches.patch index f7dceb62b..fd916602c 100755 --- a/edk2/ArmPlatformPkg/Documentation/patches/BaseTools-Pending-Patches.patch +++ b/edk2/ArmPlatformPkg/Documentation/patches/BaseTools-Pending-Patches.patch @@ -1,158 +1,93 @@ -From c23ebebbcd3ee992017d4aad70e523ea7252c884 Mon Sep 17 00:00:00 2001 -From: Olivier Martin <olivier.martin@arm.com> -Date: Tue, 6 Dec 2011 16:26:30 +0000 -Subject: [PATCH] BaseTools: Pending patches update - -Add patch: -- ARMLINUXGCC: Set the linked base address at 0x0 (0x8000 by default) ---- - BaseTools/Conf/tools_def.template | 2 +- - BaseTools/Source/C/GenFv/GenFv.c | 7 +--- - BaseTools/Source/C/GenFv/GenFvInternalLib.c | 48 +++++++++++--------------- - 3 files changed, 22 insertions(+), 35 deletions(-) - mode change 100644 => 100755 BaseTools/Conf/tools_def.template - -diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template -old mode 100644 -new mode 100755 -index ee7e23e..68caf86 ---- a/BaseTools/Conf/tools_def.template -+++ b/BaseTools/Conf/tools_def.template -@@ -4320,7 +4320,7 @@ RELEASE_ARMLINUXGCC_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) -mlittl - *_ARMLINUXGCC_ARM_VFRPP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -x c -E -P -DVFRCOMPILE --include $(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h
+Index: BaseTools/Conf/tools_def.template +=================================================================== +--- BaseTools/Conf/tools_def.template (revision 13864) ++++ BaseTools/Conf/tools_def.template (working copy) +@@ -2541,7 +2541,7 @@ + DEFINE GCC_IA32_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -m32 -malign-double -freorder-blocks -freorder-blocks-and-partition -O2 -mno-stack-arg-probe
+ DEFINE GCC_X64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mno-red-zone -Wno-address -mno-stack-arg-probe
+ DEFINE GCC_IPF_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -minline-int-divide-min-latency
+-DEFINE GCC_ARMGCC_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mword-relocations -mlittle-endian -mabi=aapcs -mapcs -fno-short-enums -save-temps -fsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer
++DEFINE GCC_ARMGCC_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mword-relocations -mlittle-endian -mabi=aapcs -mapcs -fno-short-enums -save-temps -fsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wno-address
+ DEFINE GCC_DLINK_FLAGS_COMMON = -nostdlib --pie
+ DEFINE GCC_IA32_X64_DLINK_COMMON = DEF(GCC_DLINK_FLAGS_COMMON) --gc-sections
+ DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
+@@ -4628,7 +4628,8 @@ + #
+ ####################################################################################
- *_ARMLINUXGCC_ARM_SLINK_FLAGS = -rc
--*_ARMLINUXGCC_ARM_DLINK_FLAGS = $(ARCHDLINK_FLAGS) --oformat=elf32-littlearm --emit-relocs -nostdlib -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
-+*_ARMLINUXGCC_ARM_DLINK_FLAGS = $(ARCHDLINK_FLAGS) -Ttext=0x0 --oformat=elf32-littlearm --emit-relocs -nostdlib -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
+-DEFINE RVCT_ALL_CC_FLAGS = --c90 -c --no_autoinline --asm --gnu --apcs /interwork --signed_chars --no_unaligned_access --split_sections --enum_is_int --preinclude AutoGen.h --diag_warning 167 --diag_style=ide
++DEFINE RVCT_ALL_ASM_FLAGS = --diag_suppress=1786 --diag_error=warning --apcs /interwork
++DEFINE RVCT_ALL_CC_FLAGS = --c90 -c --no_autoinline --asm --gnu --apcs /interwork --signed_chars --no_unaligned_access --split_sections --enum_is_int --preinclude AutoGen.h --diag_suppress=186 --diag_warning 167 --diag_error=warning --diag_style=ide
+ DEFINE RVCT_ALL_DLINK_FLAGS = --ro-base 0 --no_scanlib --reloc --no_exceptions --datacompressor off --strict --symbols --diag_style=ide
+
+ ####################################################################################
+@@ -4652,13 +4653,13 @@ + RELEASE_RVCT_ARM_DLINK_FLAGS = $(ARCHDLINK_FLAGS) DEF(RVCT_ALL_DLINK_FLAGS) --entry $(IMAGE_ENTRY_POINT) --map --list $(DEST_DIR_DEBUG)/$(BASE_NAME).map
- DEBUG_ARMLINUXGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -Wno-address -O0
- RELEASE_ARMLINUXGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -Wno-address -Wno-unused-but-set-variable
-diff --git a/BaseTools/Source/C/GenFv/GenFv.c b/BaseTools/Source/C/GenFv/GenFv.c -index fa86d00..27bd2af 100644 ---- a/BaseTools/Source/C/GenFv/GenFv.c -+++ b/BaseTools/Source/C/GenFv/GenFv.c -@@ -623,12 +623,7 @@ Returns: - );
- } else {
- VerboseMsg ("Create Fv image and its map file");
-- //
-- // Will take rebase action at below situation:
-- // 1. ForceRebase Flag specified to TRUE;
-- // 2. ForceRebase Flag not specified, BaseAddress greater than zero.
-- //
-- if (((mFvDataInfo.BaseAddress > 0) && (mFvDataInfo.ForceRebase == -1)) || (mFvDataInfo.ForceRebase == 1)) {
-+ if (mFvDataInfo.BaseAddressSet) {
- VerboseMsg ("FvImage Rebase Address is 0x%llX", (unsigned long long) mFvDataInfo.BaseAddress);
- }
- //
-diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c -index 684933f..aabba5b 100644 ---- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c -+++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c -@@ -506,6 +506,7 @@ Returns: - EFI_STATUS
- AddPadFile (
-+ IN FV_INFO *FvInfo,
- IN OUT MEMORY_FILE *FvImage,
- IN UINT32 DataAlignment,
- IN VOID *FvEnd,
-@@ -537,6 +538,8 @@ Returns: - {
- EFI_FFS_FILE_HEADER *PadFile;
- UINTN PadFileSize;
-+ UINTN PadFileOffset;
-+ UINTN ExtHeaderSize;
+-*_RVCT_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) --apcs /interwork
++*_RVCT_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_ASM_FLAGS)
+ *_RVCT_ARM_PP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E
+ *_RVCT_ARM_VFRPP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E -DVFRCOMPILE --preinclude $(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h
+ *_RVCT_ARM_MAKE_PATH = nmake /NOLOGO
+ *_RVCT_ARM_SLINK_FLAGS = --partial -o
+ DEBUG_RVCT_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_CC_FLAGS) -O1 -g
+-RELEASE_RVCT_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_CC_FLAGS) -O2
++RELEASE_RVCT_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) --diag_suppress=550 DEF(RVCT_ALL_CC_FLAGS) -O2
- //
- // Verify input parameters.
-@@ -559,32 +562,29 @@ Returns: - // This is the earliest possible valid offset (current plus pad file header
- // plus the next file header)
- //
-- PadFileSize = (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage + (sizeof (EFI_FFS_FILE_HEADER) * 2);
-+ // The padding is added into its own FFS file (which requires a header) added before the aligned file:
-+ // | ... FV data before AlignedFile ... | Pad File FFS Header | Padding | AlignedFile FFS Header (+ ExtHeader) | AlignedData
+ ##################
+ # ARM definitions
+@@ -4691,13 +4692,13 @@ + DEBUG_RVCTLINUX_ARM_DLINK_FLAGS = $(ARCHDLINK_FLAGS) DEF(RVCT_ALL_DLINK_FLAGS) --entry $(IMAGE_ENTRY_POINT) --map --list $(DEST_DIR_DEBUG)/$(BASE_NAME).map
+ RELEASE_RVCTLINUX_ARM_DLINK_FLAGS = $(ARCHDLINK_FLAGS) DEF(RVCT_ALL_DLINK_FLAGS) --entry $(IMAGE_ENTRY_POINT) --map --list $(DEST_DIR_DEBUG)/$(BASE_NAME).map
- //
-- // Add whatever it takes to get to the next aligned address
-+ // Calculate the Offset of the Pad File from the beginning of the FV file
- //
-- while ((PadFileSize % DataAlignment) != 0) {
-- PadFileSize++;
-- }
-- //
-- // Subtract the next file header size
-- //
-- PadFileSize -= sizeof (EFI_FFS_FILE_HEADER);
--
-- //
-- // Subtract the starting offset to get size
-- //
-- PadFileSize -= (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage;
-+ PadFileOffset = (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage;
-
- //
-- // Append extension header size
-+ // Get the size of the extension header if exists
- //
- if (ExtHeader != NULL) {
-- PadFileSize = PadFileSize + ExtHeader->ExtHeaderSize;
-+ ExtHeaderSize = ExtHeader->ExtHeaderSize;
-+ } else {
-+ ExtHeaderSize = 0;
- }
+-*_RVCTLINUX_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) --apcs /interwork
++*_RVCTLINUX_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_ASM_FLAGS)
+ *_RVCTLINUX_ARM_PP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E
+ *_RVCTLINUX_ARM_VFRPP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E -DVFRCOMPILE --preinclude $(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h
+ *_RVCTLINUX_ARM_MAKE_PATH = make
+ *_RVCTLINUX_ARM_SLINK_FLAGS = --partial -o
+ DEBUG_RVCTLINUX_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_CC_FLAGS) -O1 -g
+-RELEASE_RVCTLINUX_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_CC_FLAGS) -O2
++RELEASE_RVCTLINUX_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) --diag_suppress=550 DEF(RVCT_ALL_CC_FLAGS) -O2
- //
-+ // Calculate the Size of the Padding to ensure the alignment of the data of the Next file
-+ //
-+ PadFileSize = DataAlignment - ((FvInfo->BaseAddress + PadFileOffset + sizeof (EFI_FFS_FILE_HEADER) + ExtHeaderSize) & (DataAlignment - 1));
-+
-+ //
- // Verify that we have enough space for the file header
- //
- if (((UINTN) FvImage->CurrentFilePointer + PadFileSize) > (UINTN) FvEnd) {
-@@ -1115,7 +1115,7 @@ Returns: - //
- // Add pad file if necessary
- //
-- Status = AddPadFile (FvImage, 1 << CurrentFileAlignment, *VtfFileImage, NULL);
-+ Status = AddPadFile (FvInfo, FvImage, 1 << CurrentFileAlignment, *VtfFileImage, NULL);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 4002, "Resource", "FV space is full, could not add pad file for data alignment property.");
- free (FileBuffer);
-@@ -2304,7 +2304,7 @@ Returns: - //
- // Add FV Extended Header contents to the FV as a PAD file
- //
-- AddPadFile (&FvImageMemoryFile, 4, VtfFileImage, FvExtHeader);
-+ AddPadFile (&mFvDataInfo, &FvImageMemoryFile, 4, VtfFileImage, FvExtHeader);
+ ##################
+ # ARM definitions
+@@ -4739,13 +4740,13 @@ + DEBUG_RVCTCYGWIN_ARM_DLINK_FLAGS = "$(DLINKPATH_FLAG)" $(ARCHDLINK_FLAGS) DEF(RVCT_ALL_DLINK_FLAGS) --entry $(IMAGE_ENTRY_POINT) --map --list `cygpath -m $(DEST_DIR_DEBUG)/$(BASE_NAME).map`
+ RELEASE_RVCTCYGWIN_ARM_DLINK_FLAGS = "$(DLINKPATH_FLAG)" $(ARCHDLINK_FLAGS) DEF(RVCT_ALL_DLINK_FLAGS) --entry $(IMAGE_ENTRY_POINT) --map --list `cygpath -m $(DEST_DIR_DEBUG)/$(BASE_NAME).map`
+
+-*_RVCTCYGWIN_ARM_ASM_FLAGS = "$(ASMPATH_FLAG)" $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) --apcs /interwork
++*_RVCTCYGWIN_ARM_ASM_FLAGS = "$(ASMPATH_FLAG)" $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_ASM_FLAGS)
+ *_RVCTCYGWIN_ARM_PP_FLAGS = "$(CCPATH_FLAG)" $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E
+ *_RVCTCYGWIN_ARM_VFRPP_FLAGS = "$(CCPATH_FLAG)" $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E -DVFRCOMPILE --preinclude `cygpath -m $(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h`
+ *_RVCTCYGWIN_ARM_MAKE_PATH = make
+ *_RVCTCYGWIN_ARM_SLINK_FLAGS = "$(SLINKPATH_FLAG)" --partial -o
+ DEBUG_RVCTCYGWIN_ARM_CC_FLAGS = "$(CCPATH_FLAG)" $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_CC_FLAGS) -O1 -g
+-RELEASE_RVCTCYGWIN_ARM_CC_FLAGS = "$(CCPATH_FLAG)" $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(RVCT_ALL_CC_FLAGS) -O2
++RELEASE_RVCTCYGWIN_ARM_CC_FLAGS = "$(CCPATH_FLAG)" $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) --diag_suppress=550 DEF(RVCT_ALL_CC_FLAGS) -O2
- //
- // Fv Extension header change update Fv Header Check sum
-@@ -2825,20 +2825,12 @@ Returns: - PeFileBuffer = NULL;
+ ##################
+ # ARM definitions
+@@ -4813,8 +4814,8 @@ + *_ARMGCC_ARM_SLINK_FLAGS = -rc
+ *_ARMGCC_ARM_DLINK_FLAGS = $(ARCHDLINK_FLAGS) -Ttext=0x0 --oformat=elf32-littlearm --emit-relocs -nostdlib -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
- //
-- // Don't need to relocate image when BaseAddress is zero and no ForceRebase Flag specified.
-- //
-- if ((FvInfo->BaseAddress == 0) && (FvInfo->ForceRebase == -1)) {
-- return EFI_SUCCESS;
-- }
--
-- //
-- // If ForceRebase Flag specified to FALSE, will always not take rebase action.
-+ // Don't need to relocate image when BaseAddress is not set.
- //
-- if (FvInfo->ForceRebase == 0) {
-+ if (FvInfo->BaseAddressSet == FALSE) {
- return EFI_SUCCESS;
- }
+- DEBUG_ARMGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -combine -O0
+-RELEASE_ARMGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -combine -Wno-unused
++ DEBUG_ARMGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -O0
++RELEASE_ARMGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -Wno-unused
+
+ ####################################################################################
+ #
+@@ -4871,8 +4872,8 @@ + *_ARMLINUXGCC_ARM_SLINK_FLAGS = -rc
+ *_ARMLINUXGCC_ARM_DLINK_FLAGS = $(ARCHDLINK_FLAGS) -Ttext=0x0 --oformat=elf32-littlearm --emit-relocs -nostdlib -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
--
- XipBase = FvInfo->BaseAddress + XipOffset;
+- DEBUG_ARMLINUXGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -Wno-address -O0
+-RELEASE_ARMLINUXGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -Wno-address -Wno-unused-but-set-variable
++ DEBUG_ARMLINUXGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -fno-stack-protector -mno-unaligned-access -O0
++RELEASE_ARMLINUXGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARMGCC_CC_FLAGS) -fno-stack-protector -mno-unaligned-access -Wno-unused-but-set-variable
- //
--- -1.7.0.4 - + #################
+ # ASM 16 linker defintions
diff --git a/edk2/ArmPlatformPkg/Scripts/Ds5/build_report.py b/edk2/ArmPlatformPkg/Scripts/Ds5/build_report.py new file mode 100644 index 000000000..3805c0b43 --- /dev/null +++ b/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/edk2/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py b/edk2/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py new file mode 100644 index 000000000..424eb63cb --- /dev/null +++ b/edk2/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py @@ -0,0 +1,100 @@ +#
+# 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.
+#
+
+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 "-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"
+
+load_all = False
+report_file = None
+regions = []
+opts,args = getopt.getopt(sys.argv[1:], "har:vm:vr:vf:v", ["help","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 ("-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"
+
+ 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)
+
+armplatform_debugger = edk2_debugger.ArmPlatformDebugger(ec, report_file, regions)
+
+try:
+ armplatform_debugger = edk2_debugger.ArmPlatformDebugger(ec, report_file, regions)
+
+ 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/edk2/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py b/edk2/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py new file mode 100644 index 000000000..71e5a3ccd --- /dev/null +++ b/edk2/ArmPlatformPkg/Scripts/Ds5/edk2_debugger.py @@ -0,0 +1,217 @@ +# +# 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 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): + 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" % filename + pass + +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): + self.ec = ec + 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\' isnot 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) + 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) + 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.debug_info_table.load_symbols_at(pc) + debug_infos.append(info) + + #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() + + 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() + 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)" + pass diff --git a/edk2/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py b/edk2/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py new file mode 100644 index 000000000..c4e02ece2 --- /dev/null +++ b/edk2/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py @@ -0,0 +1,301 @@ +# +# 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. +# + +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 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): + 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') + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) + + return debug_info + + def load_all_symbols(self): + 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 + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) diff --git a/edk2/ArmPlatformPkg/Scripts/Ds5/system_table.py b/edk2/ArmPlatformPkg/Scripts/Ds5/system_table.py new file mode 100644 index 000000000..f489e466a --- /dev/null +++ b/edk2/ArmPlatformPkg/Scripts/Ds5/system_table.py @@ -0,0 +1,129 @@ +# +# 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. +# + +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): + count = self.ec.getMemoryService().readMemory32(self.base + 0x4) + 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 + 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: + # 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): + 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]): + section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0]) + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) + + found = True + return debug_info + + if found == False: + raise Exception('DebugInfoTable','No symbol found at 0x%x' % addr) + + def load_all_symbols(self): + if self.DebugInfos == []: + self.get_debug_info() + + for debug_info in self.DebugInfos: + section = firmware_volume.EfiSectionPE32(self.ec, debug_info[0]) + + edk2_debugger.load_symbol_from_file(self.ec, section.get_debug_filepath(), section.get_debug_elfbase()) + + def dump(self): + self.get_debug_info() + for debug_info in self.DebugInfos: + base_pe32 = debug_info[0] + 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 + 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): + # 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): + offset = conf_table_offset + (i * 0x14) + guid = struct.unpack("<IIII", self.ec.getMemoryService().read(str(offset), 16, 32)) + if guid == conf_table_guid: + return self.ec.getMemoryService().readMemory32(offset + 0x10) + + raise Exception('SystemTable','Configuration Table not found') |