Date   

[PATCH 3/4] MdeModulePkg/SdMmcPciHcDxe: Refactor data transfer completion

Albecki, Mateusz
 

This patch refactors the way in which the driver will check
the data transfer completion. Data transfer related
functionalities have been moved to separate function.

Cc: Hao A Wu <hao.a.wu@...>
Cc: Marcin Wojtas <mw@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Liming Gao <liming.gao@...>

Signed-off-by: Mateusz Albecki <mateusz.albecki@...>
---
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 181 ++++++++++++++---------
1 file changed, 112 insertions(+), 69 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index 3dfaae8542..480a1664ea 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -2447,6 +2447,112 @@ SdMmcCheckCommandComplete (
return EFI_NOT_READY;
}

+/**
+ Update the SDMA address on the SDMA buffer boundary interrupt.
+
+ @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
+ @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
+
+ @retval EFI_SUCCESS Updated SDMA buffer address.
+ @retval Others Failed to update SDMA buffer address.
+**/
+EFI_STATUS
+SdMmcUpdateSdmaAddress (
+ IN SD_MMC_HC_PRIVATE_DATA *Private,
+ IN SD_MMC_HC_TRB *Trb
+ )
+{
+ UINT64 SdmaAddr;
+ EFI_STATUS Status;
+
+ SdmaAddr = SD_MMC_SDMA_ROUND_UP ((UINTN)Trb->DataPhy, SD_MMC_SDMA_BOUNDARY);
+
+ if (Private->ControllerVersion[Trb->Slot] >= SD_MMC_HC_CTRL_VER_400) {
+ Status = SdMmcHcRwMmio (
+ Private->PciIo,
+ Trb->Slot,
+ SD_MMC_HC_ADMA_SYS_ADDR,
+ FALSE,
+ sizeof (UINT64),
+ &SdmaAddr
+ );
+ } else {
+ Status = SdMmcHcRwMmio (
+ Private->PciIo,
+ Trb->Slot,
+ SD_MMC_HC_SDMA_ADDR,
+ FALSE,
+ sizeof (UINT32),
+ &SdmaAddr
+ );
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Trb->DataPhy = (UINT64)(UINTN)SdmaAddr;
+ return EFI_SUCCESS;
+}
+
+/**
+ Checks if the data transfer completed and performs any actions
+ neccessary to continue the data transfer such as SDMA system
+ address fixup or PIO data transfer.
+
+ @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
+ @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
+ @param[in] IntStatus Snapshot of the normal interrupt status register.
+
+ @retval EFI_SUCCESS Data transfer completed successfully.
+ @retval EFI_NOT_READY Data transfer completion still pending.
+ @retval Others Data transfer failed to complete.
+**/
+EFI_STATUS
+SdMmcCheckDataTransfer (
+ IN SD_MMC_HC_PRIVATE_DATA *Private,
+ IN SD_MMC_HC_TRB *Trb,
+ IN UINT16 IntStatus
+ )
+{
+ UINT16 Data16;
+ EFI_STATUS Status;
+
+ if ((IntStatus & BIT1) != 0) {
+ Data16 = BIT1;
+ Status = SdMmcHcRwMmio (
+ Private->PciIo,
+ Trb->Slot,
+ SD_MMC_HC_NOR_INT_STS,
+ FALSE,
+ sizeof (Data16),
+ &Data16
+ );
+ return Status;
+ }
+
+ if ((Trb->Mode == SdMmcSdmaMode) && ((IntStatus & BIT3) != 0)) {
+ Data16 = BIT3;
+ Status = SdMmcHcRwMmio (
+ Private->PciIo,
+ Trb->Slot,
+ SD_MMC_HC_NOR_INT_STS,
+ FALSE,
+ sizeof (Data16),
+ &Data16
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Status = SdMmcUpdateSdmaAddress (Private, Trb);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ return EFI_NOT_READY;
+}
+
/**
Check the TRB execution result.

@@ -2467,7 +2573,6 @@ SdMmcCheckTrbResult (
EFI_STATUS Status;
EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet;
UINT16 IntStatus;
- UINT64 SdmaAddr;
UINT32 PioLength;

Packet = Trb->Packet;
@@ -2530,80 +2635,18 @@ SdMmcCheckTrbResult (
Status = SdMmcCheckCommandComplete (Private, Trb, IntStatus);
if (EFI_ERROR (Status)) {
goto Done;
- } else {
- //
- // If the command doesn't require data transfer skip the transfer
- // complete checking.
- //
- if ((Packet->SdMmcCmdBlk->CommandType != SdMmcCommandTypeAdtc) &&
- (Packet->SdMmcCmdBlk->ResponseType != SdMmcResponseTypeR1b) &&
- (Packet->SdMmcCmdBlk->ResponseType != SdMmcResponseTypeR5b)) {
- goto Done;
- }
}
}

- //
- // Check Transfer Complete bit is set or not.
- //
- if ((IntStatus & BIT1) == BIT1) {
- goto Done;
- }
-
- //
- // Check if DMA interrupt is signalled for the SDMA transfer.
- //
- if ((Trb->Mode == SdMmcSdmaMode) && ((IntStatus & BIT3) == BIT3)) {
- //
- // Clear DMA interrupt bit.
- //
- IntStatus = BIT3;
- Status = SdMmcHcRwMmio (
- Private->PciIo,
- Trb->Slot,
- SD_MMC_HC_NOR_INT_STS,
- FALSE,
- sizeof (IntStatus),
- &IntStatus
- );
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- //
- // Update SDMA Address register.
- //
- SdmaAddr = SD_MMC_SDMA_ROUND_UP ((UINTN)Trb->DataPhy, SD_MMC_SDMA_BOUNDARY);
-
- if (Private->ControllerVersion[Trb->Slot] >= SD_MMC_HC_CTRL_VER_400) {
- Status = SdMmcHcRwMmio (
- Private->PciIo,
- Trb->Slot,
- SD_MMC_HC_ADMA_SYS_ADDR,
- FALSE,
- sizeof (UINT64),
- &SdmaAddr
- );
- } else {
- Status = SdMmcHcRwMmio (
- Private->PciIo,
- Trb->Slot,
- SD_MMC_HC_SDMA_ADDR,
- FALSE,
- sizeof (UINT32),
- &SdmaAddr
- );
- }
-
- if (EFI_ERROR (Status)) {
- goto Done;
- }
- Trb->DataPhy = (UINT64)(UINTN)SdmaAddr;
+ if (Packet->SdMmcCmdBlk->CommandType == SdMmcCommandTypeAdtc ||
+ Packet->SdMmcCmdBlk->ResponseType == SdMmcResponseTypeR1b ||
+ Packet->SdMmcCmdBlk->ResponseType == SdMmcResponseTypeR5b) {
+ Status = SdMmcCheckDataTransfer (Private, Trb, IntStatus);
+ } else {
+ Status = EFI_SUCCESS;
}

-
- Status = EFI_NOT_READY;
Done:
-
if (Status != EFI_NOT_READY) {
SdMmcHcLedOnOff (Private->PciIo, Trb->Slot, FALSE);
if (EFI_ERROR (Status)) {
--
2.14.1.windows.1

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.


[PATCH 2/4] MdeModulePkg/SdMmcPciHcDxe: Read response on command completion

Albecki, Mateusz
 

SdMmcPciHcDxe driver used to read response only after
command and data transfer completed. According to SDHCI
specification response data is ready after the command
complete status is set by the host controller. Getting
the response data early will help debugging the cases
when command completed but data transfer timed out.

Cc: Hao A Wu <hao.a.wu@...>
Cc: Marcin Wojtas <mw@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Liming Gao <liming.gao@...>

Signed-off-by: Mateusz Albecki <mateusz.albecki@...>
---
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h | 1 +
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 201 +++++++++++++++------
2 files changed, 144 insertions(+), 58 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h
index 5bc3577ba2..15b7d12596 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h
@@ -153,6 +153,7 @@ typedef struct {

EFI_EVENT Event;
BOOLEAN Started;
+ BOOLEAN CommandComplete;
UINT64 Timeout;
UINT32 Retries;

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index 959645bf26..3dfaae8542 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -1708,6 +1708,7 @@ SdMmcPrintTrb (
DEBUG ((DebugLevel, "AdmaLengthMode: %d\n", Trb->AdmaLengthMode));
DEBUG ((DebugLevel, "Event: %d\n", Trb->Event));
DEBUG ((DebugLevel, "Started: %d\n", Trb->Started));
+ DEBUG ((DebugLevel, "CommandComplete: %d\n", Trb->CommandComplete));
DEBUG ((DebugLevel, "Timeout: %d\n", Trb->Timeout));
DEBUG ((DebugLevel, "Retries: %d\n", Trb->Retries));
DEBUG ((DebugLevel, "Adma32Desc: %X\n", Trb->Adma32Desc));
@@ -1758,6 +1759,7 @@ SdMmcCreateTrb (
Trb->Packet = Packet;
Trb->Event = Event;
Trb->Started = FALSE;
+ Trb->CommandComplete = FALSE;
Trb->Timeout = Packet->Timeout;
Trb->Retries = SD_MMC_TRB_RETRIES;
Trb->Private = Private;
@@ -2352,6 +2354,99 @@ SdMmcCheckAndRecoverErrors (
return ErrorStatus;
}

+/**
+ Reads the response data into the TRB buffer.
+ This function assumes that caller made sure that
+ command has completed.
+
+ @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
+ @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
+
+ @retval EFI_SUCCESS Response read successfully.
+ @retval Others Failed to get response.
+**/
+EFI_STATUS
+SdMmcGetResponse (
+ IN SD_MMC_HC_PRIVATE_DATA *Private,
+ IN SD_MMC_HC_TRB *Trb
+ )
+{
+ EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet;
+ UINT8 Index;
+ UINT32 Response[4];
+ EFI_STATUS Status;
+
+ Packet = Trb->Packet;
+
+ if (Packet->SdMmcCmdBlk->CommandType == SdMmcCommandTypeBc) {
+ return EFI_SUCCESS;
+ }
+
+ for (Index = 0; Index < 4; Index++) {
+ Status = SdMmcHcRwMmio (
+ Private->PciIo,
+ Trb->Slot,
+ SD_MMC_HC_RESPONSE + Index * 4,
+ TRUE,
+ sizeof (UINT32),
+ &Response[Index]
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+ CopyMem (Packet->SdMmcStatusBlk, Response, sizeof (Response));
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Checks if the command completed. If the command
+ completed it gets the response and records the
+ command completion in the TRB.
+
+ @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
+ @param[in] Trb The pointer to the SD_MMC_HC_TRB instance.
+ @param[in] IntStatus Snapshot of the normal interrupt status register.
+
+ @retval EFI_SUCCESS Command completed successfully.
+ @retval EFI_NOT_READY Command completion still pending.
+ @retval Others Command failed to complete.
+**/
+EFI_STATUS
+SdMmcCheckCommandComplete (
+ IN SD_MMC_HC_PRIVATE_DATA *Private,
+ IN SD_MMC_HC_TRB *Trb,
+ IN UINT16 IntStatus
+ )
+{
+ UINT16 Data16;
+ EFI_STATUS Status;
+
+ if ((IntStatus & BIT0) != 0) {
+ Data16 = BIT0;
+ Status = SdMmcHcRwMmio (
+ Private->PciIo,
+ Trb->Slot,
+ SD_MMC_HC_NOR_INT_STS,
+ FALSE,
+ sizeof (Data16),
+ &Data16
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Status = SdMmcGetResponse (Private, Trb);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Trb->CommandComplete = TRUE;
+ return EFI_SUCCESS;
+ }
+
+ return EFI_NOT_READY;
+}
+
/**
Check the TRB execution result.

@@ -2372,9 +2467,7 @@ SdMmcCheckTrbResult (
EFI_STATUS Status;
EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet;
UINT16 IntStatus;
- UINT32 Response[4];
UINT64 SdmaAddr;
- UINT8 Index;
UINT32 PioLength;

Packet = Trb->Packet;
@@ -2402,6 +2495,54 @@ SdMmcCheckTrbResult (
goto Done;
}

+ //
+ // Tuning commands are the only ones that do not generate command
+ // complete interrupt. Process them here before entering the code
+ // that waits for command completion.
+ //
+ if (((Private->Slot[Trb->Slot].CardType == EmmcCardType) &&
+ (Packet->SdMmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK)) ||
+ ((Private->Slot[Trb->Slot].CardType == SdCardType) &&
+ (Packet->SdMmcCmdBlk->CommandIndex == SD_SEND_TUNING_BLOCK))) {
+ //
+ // When performing tuning procedure (Execute Tuning is set to 1) through PIO mode,
+ // wait Buffer Read Ready bit of Normal Interrupt Status Register to be 1.
+ // Refer to SD Host Controller Simplified Specification 3.0 figure 2-29 for details.
+ //
+ if ((IntStatus & BIT5) == BIT5) {
+ //
+ // Clear Buffer Read Ready interrupt at first.
+ //
+ IntStatus = BIT5;
+ SdMmcHcRwMmio (Private->PciIo, Trb->Slot, SD_MMC_HC_NOR_INT_STS, FALSE, sizeof (IntStatus), &IntStatus);
+ //
+ // Read data out from Buffer Port register
+ //
+ for (PioLength = 0; PioLength < Trb->DataLen; PioLength += 4) {
+ SdMmcHcRwMmio (Private->PciIo, Trb->Slot, SD_MMC_HC_BUF_DAT_PORT, TRUE, 4, (UINT8*)Trb->Data + PioLength);
+ }
+ Status = EFI_SUCCESS;
+ goto Done;
+ }
+ }
+
+ if (!Trb->CommandComplete) {
+ Status = SdMmcCheckCommandComplete (Private, Trb, IntStatus);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ } else {
+ //
+ // If the command doesn't require data transfer skip the transfer
+ // complete checking.
+ //
+ if ((Packet->SdMmcCmdBlk->CommandType != SdMmcCommandTypeAdtc) &&
+ (Packet->SdMmcCmdBlk->ResponseType != SdMmcResponseTypeR1b) &&
+ (Packet->SdMmcCmdBlk->ResponseType != SdMmcResponseTypeR5b)) {
+ goto Done;
+ }
+ }
+ }
+
//
// Check Transfer Complete bit is set or not.
//
@@ -2459,65 +2600,9 @@ SdMmcCheckTrbResult (
Trb->DataPhy = (UINT64)(UINTN)SdmaAddr;
}

- if ((Packet->SdMmcCmdBlk->CommandType != SdMmcCommandTypeAdtc) &&
- (Packet->SdMmcCmdBlk->ResponseType != SdMmcResponseTypeR1b) &&
- (Packet->SdMmcCmdBlk->ResponseType != SdMmcResponseTypeR5b)) {
- if ((IntStatus & BIT0) == BIT0) {
- Status = EFI_SUCCESS;
- goto Done;
- }
- }
-
- if (((Private->Slot[Trb->Slot].CardType == EmmcCardType) &&
- (Packet->SdMmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK)) ||
- ((Private->Slot[Trb->Slot].CardType == SdCardType) &&
- (Packet->SdMmcCmdBlk->CommandIndex == SD_SEND_TUNING_BLOCK))) {
- //
- // When performing tuning procedure (Execute Tuning is set to 1) through PIO mode,
- // wait Buffer Read Ready bit of Normal Interrupt Status Register to be 1.
- // Refer to SD Host Controller Simplified Specification 3.0 figure 2-29 for details.
- //
- if ((IntStatus & BIT5) == BIT5) {
- //
- // Clear Buffer Read Ready interrupt at first.
- //
- IntStatus = BIT5;
- SdMmcHcRwMmio (Private->PciIo, Trb->Slot, SD_MMC_HC_NOR_INT_STS, FALSE, sizeof (IntStatus), &IntStatus);
- //
- // Read data out from Buffer Port register
- //
- for (PioLength = 0; PioLength < Trb->DataLen; PioLength += 4) {
- SdMmcHcRwMmio (Private->PciIo, Trb->Slot, SD_MMC_HC_BUF_DAT_PORT, TRUE, 4, (UINT8*)Trb->Data + PioLength);
- }
- Status = EFI_SUCCESS;
- goto Done;
- }
- }

Status = EFI_NOT_READY;
Done:
- //
- // Get response data when the cmd is executed successfully.
- //
- if (!EFI_ERROR (Status)) {
- if (Packet->SdMmcCmdBlk->CommandType != SdMmcCommandTypeBc) {
- for (Index = 0; Index < 4; Index++) {
- Status = SdMmcHcRwMmio (
- Private->PciIo,
- Trb->Slot,
- SD_MMC_HC_RESPONSE + Index * 4,
- TRUE,
- sizeof (UINT32),
- &Response[Index]
- );
- if (EFI_ERROR (Status)) {
- SdMmcHcLedOnOff (Private->PciIo, Trb->Slot, FALSE);
- return Status;
- }
- }
- CopyMem (Packet->SdMmcStatusBlk, Response, sizeof (Response));
- }
- }

if (Status != EFI_NOT_READY) {
SdMmcHcLedOnOff (Private->PciIo, Trb->Slot, FALSE);
--
2.14.1.windows.1

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.


[PATCH 1/4] MdeModulePkg/SdMmcPciHcDxe: Enhance driver traces

Albecki, Mateusz
 

To allow for easier debug of failing commands we
have added a capability to print TRB and command
packet when we start execution of the TRB(on
DEBUG_VERBOSE level) and when the TRB failed to
execute correctly(on DEBUG_ERROR level). Additionally
we will also print error interrupt status and interrupt
status register on failed SD command.

Cc: Hao A Wu <hao.a.wu@...>
Cc: Marcin Wojtas <mw@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Liming Gao <liming.gao@...>

Signed-off-by: Mateusz Albecki <mateusz.albecki@...>
---
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 87 ++++++++++++++++++++++++
1 file changed, 87 insertions(+)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index b05c818462..959645bf26 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -1643,6 +1643,82 @@ BuildAdmaDescTable (
return EFI_SUCCESS;
}

+/**
+ Prints the contents of the command packet to the debug port.
+
+ @param[in] DebugLevel Debug level at which the packet should be printed.
+ @param[in] Packet Pointer to packet to print.
+**/
+VOID
+SdMmcPrintPacket (
+ IN UINT32 DebugLevel,
+ IN EFI_SD_MMC_PASS_THRU_COMMAND_PACKET *Packet
+ )
+{
+ if (Packet == NULL) {
+ return;
+ }
+
+ DEBUG ((DebugLevel, "Printing EFI_SD_MMC_PASS_THRU_COMMAND_PACKET\n"));
+ if (Packet->SdMmcCmdBlk != NULL) {
+ DEBUG ((DebugLevel, "Command index: %d, argument: %X\n", Packet->SdMmcCmdBlk->CommandIndex, Packet->SdMmcCmdBlk->CommandArgument));
+ DEBUG ((DebugLevel, "Command type: %d, response type: %d\n", Packet->SdMmcCmdBlk->CommandType, Packet->SdMmcCmdBlk->ResponseType));
+ }
+ if (Packet->SdMmcStatusBlk != NULL) {
+ DEBUG ((DebugLevel, "Response 0: %X, 1: %X, 2: %X, 3: %X\n",
+ Packet->SdMmcStatusBlk->Resp0,
+ Packet->SdMmcStatusBlk->Resp1,
+ Packet->SdMmcStatusBlk->Resp2,
+ Packet->SdMmcStatusBlk->Resp3
+ ));
+ }
+ DEBUG ((DebugLevel, "Timeout: %d\n", Packet->Timeout));
+ DEBUG ((DebugLevel, "InDataBuffer: %X\n", Packet->InDataBuffer));
+ DEBUG ((DebugLevel, "OutDataBuffer: %X\n", Packet->OutDataBuffer));
+ DEBUG ((DebugLevel, "InTransferLength: %d\n", Packet->InTransferLength));
+ DEBUG ((DebugLevel, "OutTransferLength: %d\n", Packet->OutTransferLength));
+ DEBUG ((DebugLevel, "TransactionStatus: %r\n", Packet->TransactionStatus));
+}
+
+/**
+ Prints the contents of the TRB to the debug port.
+
+ @param[in] DebugLevel Debug level at which the TRB should be printed.
+ @param[in] Trb Pointer to the TRB structure.
+**/
+VOID
+SdMmcPrintTrb (
+ IN UINT32 DebugLevel,
+ IN SD_MMC_HC_TRB *Trb
+ )
+{
+ if (Trb == NULL) {
+ return;
+ }
+
+ DEBUG ((DebugLevel, "Printing SD_MMC_HC_TRB\n"));
+ DEBUG ((DebugLevel, "Slot: %d\n", Trb->Slot));
+ DEBUG ((DebugLevel, "BlockSize: %d\n", Trb->BlockSize));
+ DEBUG ((DebugLevel, "Data: %X\n", Trb->Data));
+ DEBUG ((DebugLevel, "DataLen: %d\n", Trb->DataLen));
+ DEBUG ((DebugLevel, "Read: %d\n", Trb->Read));
+ DEBUG ((DebugLevel, "DataPhy: %X\n", Trb->DataPhy));
+ DEBUG ((DebugLevel, "DataMap: %X\n", Trb->DataMap));
+ DEBUG ((DebugLevel, "Mode: %d\n", Trb->Mode));
+ DEBUG ((DebugLevel, "AdmaLengthMode: %d\n", Trb->AdmaLengthMode));
+ DEBUG ((DebugLevel, "Event: %d\n", Trb->Event));
+ DEBUG ((DebugLevel, "Started: %d\n", Trb->Started));
+ DEBUG ((DebugLevel, "Timeout: %d\n", Trb->Timeout));
+ DEBUG ((DebugLevel, "Retries: %d\n", Trb->Retries));
+ DEBUG ((DebugLevel, "Adma32Desc: %X\n", Trb->Adma32Desc));
+ DEBUG ((DebugLevel, "Adma64V3Desc: %X\n", Trb->Adma64V3Desc));
+ DEBUG ((DebugLevel, "Adma64V4Desc: %X\n", Trb->Adma64V4Desc));
+ DEBUG ((DebugLevel, "AdmaMap: %X\n", Trb->AdmaMap));
+ DEBUG ((DebugLevel, "AdmaPages: %X\n", Trb->AdmaPages));
+
+ SdMmcPrintPacket (DebugLevel, Trb->Packet);
+}
+
/**
Create a new TRB for the SD/MMC cmd request.

@@ -1963,6 +2039,9 @@ SdMmcExecTrb (
UINT64 AdmaAddr;
BOOLEAN AddressingMode64;

+ DEBUG ((DEBUG_VERBOSE, "Starting TRB execution\n"));
+ SdMmcPrintTrb (DEBUG_VERBOSE, Trb);
+
AddressingMode64 = FALSE;

Packet = Trb->Packet;
@@ -2235,6 +2314,10 @@ SdMmcCheckAndRecoverErrors (
return Status;
}

+ DEBUG ((DEBUG_ERROR, "Error reported by SDHCI\n"));
+ DEBUG ((DEBUG_ERROR, "Interrupt status = %X\n", IntStatus));
+ DEBUG ((DEBUG_ERROR, "Error interrupt status = %X\n", ErrIntStatus));
+
//
// If the data timeout error is reported
// but data transfer is signaled as completed we
@@ -2438,6 +2521,10 @@ Done:

if (Status != EFI_NOT_READY) {
SdMmcHcLedOnOff (Private->PciIo, Trb->Slot, FALSE);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "TRB failed with %r\n", Status));
+ SdMmcPrintTrb (DEBUG_ERROR, Trb);
+ }
}

return Status;
--
2.14.1.windows.1

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.


[PATCH 0/4] MdeModulePkg/SdMmcPciHcDxe: Refactor command processing

Albecki, Mateusz
 

This patch series aims to refactor command processing to achieve following

1. Trace the failing TRB packets to see what commands are failing and for what reasons
2. Get the response data even if data transfer timed out to allow easier debugging
3. Fix the PIO mode which is currently completely broken.

Tests performed:
1. Each patch in the series has passed boot from eMMC with ADMAv3 data transfer mode
2. SDMA based boot has been tested with the full patch series
3. PIO based boot has been tested with the full patch series
4. PIO based data transfer has been additionally tested by creating and modyfing a file in EFI shell

All tests were performed with eMMC in HS400 @200MHz clock frequency.

For easier review & integration patch has been pushed here:
Whole series: https://github.com/malbecki/edk2/tree/emmc_transfer_refactor
Whole series + SDMA force code(test 3): https://github.com/malbecki/edk2/tree/emmc_transfer_refactor_force_sdma
Whole series + PIO force code(test 4): https://github.com/malbecki/edk2/tree/emmc_transfer_refactor_force_pio

Cc: Hao A Wu <hao.a.wu@...>
Cc: Marcin Wojtas <mw@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Liming Gao <liming.gao@...>


Mateusz Albecki (4):
MdeModulePkg/SdMmcPciHcDxe: Enhance driver traces
MdeModulePkg/SdMmcPciHcDxe: Read response on command completion
MdeModulePkg/SdMmcPciHcDxe: Refactor data transfer completion
MdeModulePkg/SdMmcPciHcDxe: Fix PIO transfer mode

MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h | 4 +
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 502 ++++++++++++++++-----
2 files changed, 398 insertions(+), 108 deletions(-)

--
2.14.1.windows.1

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.


[PATCH] BaseTools: Enhance call stack unwindability for CLANGPDB x64 binary

Steven Shi
 

From: Steven <steven.shi@...>

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2487

The call stack unwindability of the COFF X64 binary requires
the binary to remain the pdata and xdata sections.
Details see the MSVC X64 calling convertion doc in below link:
https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention

Current build options discard or zero the data in pdata and xdata
sections which cause the debugger cannot correctly unwind the
X64 binary call stack in the runtime.
Enhance the build options to force emit the unwind tables and
keep the data of pdata and xdata sections correct in the binary.

Signed-off-by: Steven Shi <steven.shi@...>
Cc: Liming Gao <liming.gao@...>
Cc: Bob Feng <bob.c.feng@...>
---
BaseTools/Conf/tools_def.template | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index feee2bbf16..26294efe05 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -2759,7 +2759,7 @@ DEFINE CLANGPDB_IA32_TARGET = -target i686-unknown-windows
DEFINE CLANGPDB_X64_TARGET = -target x86_64-unknown-windows

DEFINE CLANGPDB_WARNING_OVERRIDES = -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-microsoft-enum-forward-reference
-DEFINE CLANGPDB_ALL_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) DEF(CLANGPDB_WARNING_OVERRIDES) -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -fno-asynchronous-unwind-tables -mno-implicit-float -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference -fms-compatibility -mno-stack-arg-probe
+DEFINE CLANGPDB_ALL_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) DEF(CLANGPDB_WARNING_OVERRIDES) -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -mno-implicit-float -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference -fms-compatibility -mno-stack-arg-probe

###########################
# CLANGPDB IA32 definitions
@@ -2817,18 +2817,20 @@ NOOPT_CLANGPDB_IA32_DLINK2_FLAGS =
*_CLANGPDB_X64_ASLPP_FLAGS = DEF(GCC_ASLPP_FLAGS) DEF(CLANGPDB_X64_TARGET)
*_CLANGPDB_X64_VFRPP_FLAGS = DEF(GCC_VFRPP_FLAGS) DEF(CLANGPDB_X64_TARGET)

-DEBUG_CLANGPDB_X64_CC_FLAGS = DEF(CLANGPDB_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -Oz -flto DEF(CLANGPDB_X64_TARGET) -gcodeview
-DEBUG_CLANGPDB_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DEBUG:GHASH /lldmap
+DEBUG_CLANGPDB_X64_CC_FLAGS = DEF(CLANGPDB_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -Oz -flto DEF(CLANGPDB_X64_TARGET) -gcodeview -funwind-tables
+DEBUG_CLANGPDB_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /Machine:X64 /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DEBUG:GHASH /lldmap
DEBUG_CLANGPDB_X64_DLINK2_FLAGS =
+DEBUG_CLANGPDB_X64_GENFW_FLAGS = --keepexceptiontable

-RELEASE_CLANGPDB_X64_CC_FLAGS = DEF(CLANGPDB_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -Oz -flto DEF(CLANGPDB_X64_TARGET)
+RELEASE_CLANGPDB_X64_CC_FLAGS = DEF(CLANGPDB_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -Oz -flto DEF(CLANGPDB_X64_TARGET) -fno-unwind-tables
RELEASE_CLANGPDB_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /MERGE:.rdata=.data /lldmap
RELEASE_CLANGPDB_X64_DLINK2_FLAGS =
+RELEASE_CLANGPDB_X64_GENFW_FLAGS =

-NOOPT_CLANGPDB_X64_CC_FLAGS = DEF(CLANGPDB_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -O0 DEF(CLANGPDB_X64_TARGET) -gcodeview
-NOOPT_CLANGPDB_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DEBUG:GHASH /lldmap
+NOOPT_CLANGPDB_X64_CC_FLAGS = DEF(CLANGPDB_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -O0 DEF(CLANGPDB_X64_TARGET) -gcodeview -funwind-tables
+NOOPT_CLANGPDB_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /Machine:X64 /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DEBUG:GHASH /lldmap
NOOPT_CLANGPDB_X64_DLINK2_FLAGS =
-
+NOOPT_CLANGPDB_X64_GENFW_FLAGS = --keepexceptiontable

#
#
--
2.16.1.windows.4


[edk2-platforms][PATCH 1/1] Platform/RPi4: Add ACPI entry for Genet network interface

Pete Batard
 

The Raspberry Pi 4 platforms uses a Broadcom Genet network interface, for
which we need ACPI entries in order to make it usable under Linux.

This patch adds these entries, including a max-dma-burst-size DSD attribute
aimed at simplifying support for Genet on distros that use older kernels,
such as Debian.

Note that we ran these settings through someone working for Broadcom, who
okayed the proposed values including ownership of max-dma-burst-size (which
we expect to also require for Device Tree usage on older kernels, hence the
requirement for a designated owner).

Signed-off-by: Pete Batard <pete@...>
---
Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl | 29 ++++++++++++++++++++
1 file changed, 29 insertions(+)

diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl b/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl
index b2f1d3439211..12c3967fa9e1 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl
@@ -267,6 +267,35 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
}
}

+ Device (ETH0)
+ {
+ Name (_HID, "BCM6E4E")
+ Name (_CID, "BCM6E4E")
+ Name (_UID, 0x0)
+ Name (_CCA, 0x0)
+ Method (_STA)
+ {
+ Return (0xf)
+ }
+ Method (_CRS, 0x0, Serialized)
+ {
+ Name (RBUF, ResourceTemplate ()
+ {
+ Memory32Fixed (ReadWrite, 0xfd580000, 0x10000, )
+ Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0xBD }
+ Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0xBE }
+ })
+ Return (RBUF)
+ }
+ Name (_DSD, Package () {
+ ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+ Package () {
+ Package () { "brcm,max-dma-burst-size", 0x08 },
+ Package () { "phy-mode", "rgmii" },
+ }
+ })
+ }
+
// Description: I2C
Device (I2C1)
{
--
2.21.0.windows.1


Re: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

Liming Gao
 

Pierre:
If so, this is not the error for other ACPI table. I suggest to print INFO message and directly return with success return value.

Thanks
Liming

-----Original Message-----
From: Pierre Gondois <Pierre.Gondois@...>
Sent: Monday, February 3, 2020 9:20 PM
To: devel@edk2.groups.io; Gao, Liming <liming.gao@...>
Cc: ard.biesheuvel@...; Feng, Bob C <bob.c.feng@...>; Sami Mujawar <Sami.Mujawar@...>; nd <nd@...>
Subject: RE: [edk2-devel] [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

Hello Liming,
Currently, the only ACPI tables which contain AML bytecode are the DSDT and SSDT tables. We don't need to generate a ".hex" file for
other ACPI tables or any other file since we would like to parse AML bytecode.
However this is only a safety check and this can be removed if desired.

Regards,
Pierre

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming Gao via Groups.Io
Sent: 03 February 2020 11:58
To: Pierre Gondois <Pierre.Gondois@...>; devel@edk2.groups.io
Cc: ard.biesheuvel@...; Feng, Bob C <bob.c.feng@...>; Sami Mujawar <Sami.Mujawar@...>; nd <nd@...>
Subject: Re: [edk2-devel] [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

Pierre:
Sorry for late response. I have one comment. Why only allows "DSDT" or "SSDT" in Signature?

Thanks
Liming
-----Original Message-----
From: Pierre Gondois <Pierre.Gondois@...>
Sent: Thursday, January 23, 2020 1:32 AM
To: Pierre Gondois <Pierre.Gondois@...>; devel@edk2.groups.io
Cc: ard.biesheuvel@...; Feng, Bob C <bob.c.feng@...>;
Gao, Liming <liming.gao@...>; Sami Mujawar
<Sami.Mujawar@...>; nd <nd@...>
Subject: RE: [PATCH v2 1/1] BaseTools: Script for converting .aml to
.hex

Hello everyone,
Do you have any input on the patch?

Regards,
Pierre

-----Original Message-----
From: PierreGondois <pierre.gondois@...>
Sent: 17 January 2020 17:18
To: devel@edk2.groups.io
Cc: Pierre Gondois <Pierre.Gondois@...>;
ard.biesheuvel@...; bob.c.feng@...; liming.gao@...;
Sami Mujawar <Sami.Mujawar@...>; nd <nd@...>
Subject: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

From: Pierre Gondois <pierre.gondois@...>

The "-tc" option of the iasl compiler allows to generate a .hex file containing a C array storing AML bytecode.

An online discussion suggested that this "-tc" option was specific to
the iasl compiler and it shouldn't be relied on. This conversation is available at:
https://edk2.groups.io/g/devel/topic/39786201#49659

A way to address this issue is to implement a compiler independent script that takes an AML file as input, and generates a .hex file.

This patch implements a Python script that converts an AML file to a .hex file, containing a C array storing AML bytecode.
This scipt has been tested with the AML output from the following compilers supported by the EDKII implementation:
* Intel ASL compiler
* Microsoft ASL compiler

Signed-off-by: Pierre Gondois <pierre.gondois@...>
---

The changes can be seen at
https://github.com/PierreARM/edk2/commits/718_asl_to_hex_script_conver
ter_2

Notes:
v2:
- Script converting AML to .hex file [Pierre]

BaseTools/BinWrappers/PosixLike/AmlToHex | 14 ++
BaseTools/BinWrappers/WindowsLike/AmlToHex.bat | 3 +
BaseTools/Conf/build_rule.template | 3 +
BaseTools/Source/Python/AmlToHex/AmlToHex.py | 155 ++++++++++++++++++++
4 files changed, 175 insertions(+)

diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex
b/BaseTools/BinWrappers/PosixLike/AmlToHex
new file mode 100755
index
0000000000000000000000000000000000000000..1dd28e966288f6ea4fc52d42e2dc
7b1f74226c23
--- /dev/null
+++ b/BaseTools/BinWrappers/PosixLike/AmlToHex
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+#python `dirname $0`/RunToolFromSource.py `basename $0` $*
+
+# If a ${PYTHON_COMMAND} command is available, use it in preference
+to python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then
+ python_exe=${PYTHON_COMMAND}
+fi
+
+full_cmd=${BASH_SOURCE:-$0} # see
+http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is
+not a good choice here dir=$(dirname "$full_cmd") exe=$(basename
+"$full_cmd")
+
+export PYTHONPATH="$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"}"
+exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@"
diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
new file mode 100644
index
0000000000000000000000000000000000000000..9616cd893bec9902451e6d8591f5
37cc408bd5e5
--- /dev/null
+++ b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
@@ -0,0 +1,3 @@
+@setlocal
+@set ToolName=%~n0%
+@%PYTHON_COMMAND%
+%BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
diff --git a/BaseTools/Conf/build_rule.template
b/BaseTools/Conf/build_rule.template
index
51748bc0655a5c656258a3007b4db6b2dc941ea0..0822b681fcd9f61c6508e6f93ffc
31fa70fd7059 100755
--- a/BaseTools/Conf/build_rule.template
+++ b/BaseTools/Conf/build_rule.template
@@ -1,6 +1,7 @@
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights
reserved.<BR> # Portions copyright (c) 2008 - 2010, Apple Inc. All
rights reserved.<BR>
+# Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent #

@@ -427,12 +428,14 @@
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) /I${s_path}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
+ -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml

<Command.GCC>
Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src}
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) -I${s_path}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
+ -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml

[C-Code-File.AcpiTable]
<InputFile>
diff --git a/BaseTools/Source/Python/AmlToHex/AmlToHex.py
b/BaseTools/Source/Python/AmlToHex/AmlToHex.py
new file mode 100644
index
0000000000000000000000000000000000000000..e8e7ace3a68532bc625afb1e7440
4c4e4b0205dd
--- /dev/null
+++ b/BaseTools/Source/Python/AmlToHex/AmlToHex.py
@@ -0,0 +1,155 @@
+## @file
+#
+# Convert an AML file to a .hex file containing the AML bytecode
+stored in a # C array.
+# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.hex".
+# "Tables\Dsdt.hex" will contain a C array named "dsdt_aml_code" that
+contains # the AML bytecode.
+#
+# Copyright (c) 2020, ARM Limited. All rights reserved.<BR> # #
+SPDX-License-Identifier: BSD-2-Clause-Patent #
+
+import argparse
+import Common.EdkLogger as EdkLogger
+from Common.BuildToolError import *
+import sys
+import os
+
+## Parse the command line arguments.
+#
+# @retval A argparse.NameSpace instance, containing parsed values.
+#
+def ParseArgs():
+ # Initialize the parser.
+ Parser = argparse.ArgumentParser(
+ description="Convert an AML file to a .hex file containing the AML " + \
+ "bytecode stored in a C array. By default, " + \
+ "\"Tables\\Dsdt.aml\" will generate" + \
+ "\"Tables\\Dsdt.hex\". \"Tables\\Dsdt.hex\" will " + \
+ "contain a C array named \"dsdt_aml_code\" that " + \
+ "contains the AML bytecode."
+ )
+
+ # Define the possible arguments.
+ Parser.add_argument(
+ dest="InputFile",
+ help="Path to an input AML file to generate a .hex file from."
+ )
+ Parser.add_argument(
+ "-o", "--out-dir", dest="OutDir",
+ help="Output directory where the .hex file will be generated. " + \
+ "Default is the input file's directory."
+ )
+
+ # Parse the input arguments.
+ Args = Parser.parse_args()
+ SplitInputName = ""
+
+ if not os.path.exists(Args.InputFile):
+ EdkLogger.error(__file__, FILE_OPEN_FAILURE,
+ ExtraData=Args.InputFile)
+ return
+ else:
+ with open(Args.InputFile, "rb") as fIn:
+ Signature = str(fIn.read(4))
+ if ("DSDT" not in Signature) and ("SSDT" not in Signature):
+ EdkLogger.error(__file__, PARAMETER_INVALID,
+ ExtraData=Args.InputFile,
+ Message="Error: Invalid file type. " + \
+ "File does not have a valid " + \
+ "DSDT or SSDT signature.")
+
+ # Get the basename of the input file.
+ SplitInputName = os.path.splitext(Args.InputFile)
+ BaseName = os.path.basename(SplitInputName[0])
+
+ # If no output directory is specified, output to the input directory.
+ if not Args.OutDir:
+ Args.OutputFile = os.path.join(
+ os.path.dirname(Args.InputFile),
+ BaseName + ".hex"
+ )
+ else:
+ if not os.path.exists(Args.OutDir):
+ os.mkdir(Args.OutDir)
+ Args.OutputFile = os.path.join(Args.OutDir, BaseName +
+ ".hex")
+
+ Args.BaseName = BaseName
+
+ return Args
+
+## Convert an AML file to a .hex file containing the AML bytecode
+stored # in a C array.
+#
+# @param InputFile Path to the input AML file.
+# @param OutputFile Path to the output .hex file to generate.
+# @param BaseName Base name of the input file.
+# This is also the name of the generated .hex file.
+#
+def AmlToHex(InputFile, OutputFile, BaseName):
+
+ MacroName = "__{}_HEX__".format(BaseName.upper())
+ ArrayName = BaseName.lower() + "_aml_code"
+
+ with open(InputFile, "rb") as fIn, open(OutputFile, "w") as fOut:
+ # Write header.
+ fOut.write("// This file has been generated from:\n" + \
+ "// \tPython script: " + \
+ os.path.abspath(__file__) + "\n" + \
+ "// \tInput AML file: " + \
+ os.path.abspath(InputFile) + "\n\n" + \
+ "#ifndef {}\n".format(MacroName) + \
+ "#define {}\n\n".format(MacroName)
+ )
+
+ # Write the array and its content.
+ fOut.write("unsigned char {}[] = {{\n ".format(ArrayName))
+ cnt = 0
+ byte = fIn.read(1)
+ while len(byte) != 0:
+ fOut.write("0x{0:02X}, ".format(ord(byte)))
+ cnt += 1
+ if (cnt % 8) == 0:
+ fOut.write("\n")
+ byte = fIn.read(1)
+ fOut.write("\n};\n")
+
+ # Write footer.
+ fOut.write("#endif // {}\n".format(MacroName))
+
+## Main method
+#
+# This method:
+# 1- Initialize an EdkLogger instance.
+# 2- Parses the input arguments.
+# 3- Converts an AML file to a .hex file containing the AML bytecode stored
+# in a C array.
+#
+# @retval 0 Success.
+# @retval 1 Error.
+#
+def Main():
+ # Initialize an EdkLogger instance.
+ EdkLogger.Initialize()
+
+ try:
+ # Parse the input arguments.
+ CommandArguments = ParseArgs()
+
+ # Convert an AML file to a .hex file containing the AML bytecode stored
+ # in a C array.
+ AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFile,
+ CommandArguments.BaseName)
+ except Exception as e:
+ print(e)
+ return 1
+
+ return 0
+
+if __name__ == '__main__':
+ r = Main()
+ # 0-127 is a safe return range, and 1 is a standard default error
+ if r < 0 or r > 127: r = 1
+ sys.exit(r)
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


Re: [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: Use %08x to print CacheControl Index

Laszlo Ersek
 

On 02/03/20 10:09, Zeng, Star wrote:
-----Original Message-----
From: Laszlo Ersek <lersek@...>
Sent: Monday, February 3, 2020 4:47 PM
To: Zeng, Star <star.zeng@...>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>; Ni, Ray <ray.ni@...>
Subject: Re: [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: Use %08x to print
CacheControl Index

Hello Star,

On 02/03/20 08:06, Star Zeng wrote:
Instead of %08lx, use %08x to print CacheControl Index as it is UINT32
type.

Cc: Eric Dong <eric.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Laszlo Ersek <lersek@...>
Signed-off-by: Star Zeng <star.zeng@...>
---
.../Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git
a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
index 0a4fcff033a3..1a02809b0e7c 100644
---
a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.
+++ c
@@ -465,7 +465,7 @@ DumpRegisterTableOnProcessor (
case CacheControl:
DEBUG ((
DebugPrintErrorLevel,
- "Processor: %04d: Index %04d, CACHE: %08lx, Bit Start: %02d,
Bit Length: %02d, Value: %016lx\r\n",
+ "Processor: %04d: Index %04d, CACHE: %08x, Bit Start: %02d,
+ Bit Length: %02d, Value: %016lx\r\n",
ProcessorNumber,
FeatureIndex,
RegisterTableEntry->Index,
if you are already touching this DEBUG invocation, can you please fix the
rest of the issues with the format string?

- ProcessorNumber is UINTN. If we know for sure it can be represented in a
UINT32, then it should be cast to UINT32 explicitly, and logged with "%04u".
(Otherwise, UINTN needs to be cast to UINT64, and logged with %lu or %lx.)

- Ditto for FeatureIndex.
%04u or %04d is not enough for UINT32 which needs %08x.
I thought the code is just taking assumption about their value should be not > 9999u. It is not a real issue.
I disagree. It's not about the field width / padding (4 vs. 8
characters), but the width of the data type. The parameter that's being
passed is a UINTN, which is UINT64 on X64. But the format specifier (%d,
%u, %x all alike) only expect a UINT32.

If we pass a UINT64 (in the form of a UINTN), then we should print it
with a UINT64 specifier (such as %lu or %lx).

Alternatively, if we know for sure that the value of the UINT64 in
question will fit in a UINT32, then we can use %u or %x for printing,
but then we need to truncate (cast) the data that's being passed in, to
UINT32.

My point is that the data size should be a match between what's passed
in and what is described with a format specifier. There is no format
specifier that directly matches UINTN, so you either need to cast UINTN
to UINT64 and use %lx, or cast UINTN to UINT32 and use %x.


This patch is to fix a real issue, without it, the print for ValidBitStart, ValidBitLength and Value will be wrong because the parameter for them are shifted for Index to fetch UINT64 value.
The patch is not wrong, it's just incomplete (given that we're modifying
a format string that mismatches the argument list in other places too).

ProcessorNumber and FeatureIndex are UINTNs, and they are being printed
with %d. Those are real issues too.

I found another real issue is MMIO : %08lx should be MMIO : %016lx as the code is on purpose to get UINT64 MMIO address.
Field width / padding are useful to get right, but getting the data
types to match is even more important.

Thanks
Laszlo

I prefer to just handle the real issue in this patch. How do you think? 😊


Re: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

PierreGondois
 

Hello Liming,
Currently, the only ACPI tables which contain AML bytecode are the DSDT and SSDT tables. We don't need to generate a ".hex" file for other ACPI tables or any other file since we would like to parse AML bytecode.
However this is only a safety check and this can be removed if desired.

Regards,
Pierre

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Liming Gao via Groups.Io
Sent: 03 February 2020 11:58
To: Pierre Gondois <Pierre.Gondois@...>; devel@edk2.groups.io
Cc: ard.biesheuvel@...; Feng, Bob C <bob.c.feng@...>; Sami Mujawar <Sami.Mujawar@...>; nd <nd@...>
Subject: Re: [edk2-devel] [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

Pierre:
Sorry for late response. I have one comment. Why only allows "DSDT" or "SSDT" in Signature?

Thanks
Liming
-----Original Message-----
From: Pierre Gondois <Pierre.Gondois@...>
Sent: Thursday, January 23, 2020 1:32 AM
To: Pierre Gondois <Pierre.Gondois@...>; devel@edk2.groups.io
Cc: ard.biesheuvel@...; Feng, Bob C <bob.c.feng@...>;
Gao, Liming <liming.gao@...>; Sami Mujawar
<Sami.Mujawar@...>; nd <nd@...>
Subject: RE: [PATCH v2 1/1] BaseTools: Script for converting .aml to
.hex

Hello everyone,
Do you have any input on the patch?

Regards,
Pierre

-----Original Message-----
From: PierreGondois <pierre.gondois@...>
Sent: 17 January 2020 17:18
To: devel@edk2.groups.io
Cc: Pierre Gondois <Pierre.Gondois@...>;
ard.biesheuvel@...; bob.c.feng@...; liming.gao@...;
Sami Mujawar <Sami.Mujawar@...>; nd <nd@...>
Subject: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

From: Pierre Gondois <pierre.gondois@...>

The "-tc" option of the iasl compiler allows to generate a .hex file containing a C array storing AML bytecode.

An online discussion suggested that this "-tc" option was specific to
the iasl compiler and it shouldn't be relied on. This conversation is available at:
https://edk2.groups.io/g/devel/topic/39786201#49659

A way to address this issue is to implement a compiler independent script that takes an AML file as input, and generates a .hex file.

This patch implements a Python script that converts an AML file to a .hex file, containing a C array storing AML bytecode.
This scipt has been tested with the AML output from the following compilers supported by the EDKII implementation:
* Intel ASL compiler
* Microsoft ASL compiler

Signed-off-by: Pierre Gondois <pierre.gondois@...>
---

The changes can be seen at
https://github.com/PierreARM/edk2/commits/718_asl_to_hex_script_conver
ter_2

Notes:
v2:
- Script converting AML to .hex file [Pierre]

BaseTools/BinWrappers/PosixLike/AmlToHex | 14 ++
BaseTools/BinWrappers/WindowsLike/AmlToHex.bat | 3 +
BaseTools/Conf/build_rule.template | 3 +
BaseTools/Source/Python/AmlToHex/AmlToHex.py | 155 ++++++++++++++++++++
4 files changed, 175 insertions(+)

diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex
b/BaseTools/BinWrappers/PosixLike/AmlToHex
new file mode 100755
index
0000000000000000000000000000000000000000..1dd28e966288f6ea4fc52d42e2dc
7b1f74226c23
--- /dev/null
+++ b/BaseTools/BinWrappers/PosixLike/AmlToHex
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+#python `dirname $0`/RunToolFromSource.py `basename $0` $*
+
+# If a ${PYTHON_COMMAND} command is available, use it in preference
+to python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then
+ python_exe=${PYTHON_COMMAND}
+fi
+
+full_cmd=${BASH_SOURCE:-$0} # see
+http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is
+not a good choice here dir=$(dirname "$full_cmd") exe=$(basename
+"$full_cmd")
+
+export PYTHONPATH="$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"}"
+exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@"
diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
new file mode 100644
index
0000000000000000000000000000000000000000..9616cd893bec9902451e6d8591f5
37cc408bd5e5
--- /dev/null
+++ b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
@@ -0,0 +1,3 @@
+@setlocal
+@set ToolName=%~n0%
+@%PYTHON_COMMAND%
+%BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
diff --git a/BaseTools/Conf/build_rule.template
b/BaseTools/Conf/build_rule.template
index
51748bc0655a5c656258a3007b4db6b2dc941ea0..0822b681fcd9f61c6508e6f93ffc
31fa70fd7059 100755
--- a/BaseTools/Conf/build_rule.template
+++ b/BaseTools/Conf/build_rule.template
@@ -1,6 +1,7 @@
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights
reserved.<BR> # Portions copyright (c) 2008 - 2010, Apple Inc. All
rights reserved.<BR>
+# Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent #

@@ -427,12 +428,14 @@
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) /I${s_path}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
+ -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml

<Command.GCC>
Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src}
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) -I${s_path}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst}
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
+ -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml

[C-Code-File.AcpiTable]
<InputFile>
diff --git a/BaseTools/Source/Python/AmlToHex/AmlToHex.py
b/BaseTools/Source/Python/AmlToHex/AmlToHex.py
new file mode 100644
index
0000000000000000000000000000000000000000..e8e7ace3a68532bc625afb1e7440
4c4e4b0205dd
--- /dev/null
+++ b/BaseTools/Source/Python/AmlToHex/AmlToHex.py
@@ -0,0 +1,155 @@
+## @file
+#
+# Convert an AML file to a .hex file containing the AML bytecode
+stored in a # C array.
+# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.hex".
+# "Tables\Dsdt.hex" will contain a C array named "dsdt_aml_code" that
+contains # the AML bytecode.
+#
+# Copyright (c) 2020, ARM Limited. All rights reserved.<BR> # #
+SPDX-License-Identifier: BSD-2-Clause-Patent #
+
+import argparse
+import Common.EdkLogger as EdkLogger
+from Common.BuildToolError import *
+import sys
+import os
+
+## Parse the command line arguments.
+#
+# @retval A argparse.NameSpace instance, containing parsed values.
+#
+def ParseArgs():
+ # Initialize the parser.
+ Parser = argparse.ArgumentParser(
+ description="Convert an AML file to a .hex file containing the AML " + \
+ "bytecode stored in a C array. By default, " + \
+ "\"Tables\\Dsdt.aml\" will generate" + \
+ "\"Tables\\Dsdt.hex\". \"Tables\\Dsdt.hex\" will " + \
+ "contain a C array named \"dsdt_aml_code\" that " + \
+ "contains the AML bytecode."
+ )
+
+ # Define the possible arguments.
+ Parser.add_argument(
+ dest="InputFile",
+ help="Path to an input AML file to generate a .hex file from."
+ )
+ Parser.add_argument(
+ "-o", "--out-dir", dest="OutDir",
+ help="Output directory where the .hex file will be generated. " + \
+ "Default is the input file's directory."
+ )
+
+ # Parse the input arguments.
+ Args = Parser.parse_args()
+ SplitInputName = ""
+
+ if not os.path.exists(Args.InputFile):
+ EdkLogger.error(__file__, FILE_OPEN_FAILURE,
+ ExtraData=Args.InputFile)
+ return
+ else:
+ with open(Args.InputFile, "rb") as fIn:
+ Signature = str(fIn.read(4))
+ if ("DSDT" not in Signature) and ("SSDT" not in Signature):
+ EdkLogger.error(__file__, PARAMETER_INVALID,
+ ExtraData=Args.InputFile,
+ Message="Error: Invalid file type. " + \
+ "File does not have a valid " + \
+ "DSDT or SSDT signature.")
+
+ # Get the basename of the input file.
+ SplitInputName = os.path.splitext(Args.InputFile)
+ BaseName = os.path.basename(SplitInputName[0])
+
+ # If no output directory is specified, output to the input directory.
+ if not Args.OutDir:
+ Args.OutputFile = os.path.join(
+ os.path.dirname(Args.InputFile),
+ BaseName + ".hex"
+ )
+ else:
+ if not os.path.exists(Args.OutDir):
+ os.mkdir(Args.OutDir)
+ Args.OutputFile = os.path.join(Args.OutDir, BaseName +
+ ".hex")
+
+ Args.BaseName = BaseName
+
+ return Args
+
+## Convert an AML file to a .hex file containing the AML bytecode
+stored # in a C array.
+#
+# @param InputFile Path to the input AML file.
+# @param OutputFile Path to the output .hex file to generate.
+# @param BaseName Base name of the input file.
+# This is also the name of the generated .hex file.
+#
+def AmlToHex(InputFile, OutputFile, BaseName):
+
+ MacroName = "__{}_HEX__".format(BaseName.upper())
+ ArrayName = BaseName.lower() + "_aml_code"
+
+ with open(InputFile, "rb") as fIn, open(OutputFile, "w") as fOut:
+ # Write header.
+ fOut.write("// This file has been generated from:\n" + \
+ "// \tPython script: " + \
+ os.path.abspath(__file__) + "\n" + \
+ "// \tInput AML file: " + \
+ os.path.abspath(InputFile) + "\n\n" + \
+ "#ifndef {}\n".format(MacroName) + \
+ "#define {}\n\n".format(MacroName)
+ )
+
+ # Write the array and its content.
+ fOut.write("unsigned char {}[] = {{\n ".format(ArrayName))
+ cnt = 0
+ byte = fIn.read(1)
+ while len(byte) != 0:
+ fOut.write("0x{0:02X}, ".format(ord(byte)))
+ cnt += 1
+ if (cnt % 8) == 0:
+ fOut.write("\n")
+ byte = fIn.read(1)
+ fOut.write("\n};\n")
+
+ # Write footer.
+ fOut.write("#endif // {}\n".format(MacroName))
+
+## Main method
+#
+# This method:
+# 1- Initialize an EdkLogger instance.
+# 2- Parses the input arguments.
+# 3- Converts an AML file to a .hex file containing the AML bytecode stored
+# in a C array.
+#
+# @retval 0 Success.
+# @retval 1 Error.
+#
+def Main():
+ # Initialize an EdkLogger instance.
+ EdkLogger.Initialize()
+
+ try:
+ # Parse the input arguments.
+ CommandArguments = ParseArgs()
+
+ # Convert an AML file to a .hex file containing the AML bytecode stored
+ # in a C array.
+ AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFile,
+ CommandArguments.BaseName)
+ except Exception as e:
+ print(e)
+ return 1
+
+ return 0
+
+if __name__ == '__main__':
+ r = Main()
+ # 0-127 is a safe return range, and 1 is a standard default error
+ if r < 0 or r > 127: r = 1
+ sys.exit(r)
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


Re: [PATCH 1/2] BaseTools: append -DNO_MSABI_VA_FUNCS option in CLANGPDB tool chain

Liming Gao
 

Reviewed-by: Liming Gao <liming.gao@...>

-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@...>
Sent: Monday, February 3, 2020 4:15 PM
To: devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@...>; Gao, Liming <liming.gao@...>
Subject: [PATCH 1/2] BaseTools: append -DNO_MSABI_VA_FUNCS option in CLANGPDB tool chain

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2415

For CLANGPDB tool chain and X64, use MS ABI version of GCC built-in macros for
variable argument lists to be align with CLANG38 tool chain.

Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <liming.gao@...>

Signed-off-by: Zhiguang Liu <zhiguang.liu@...>
---
BaseTools/Conf/tools_def.template | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index feee2bbf16..b29a823cfd 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -2759,7 +2759,7 @@ DEFINE CLANGPDB_IA32_TARGET = -target i686-unknown-windows
DEFINE CLANGPDB_X64_TARGET = -target x86_64-unknown-windows

DEFINE CLANGPDB_WARNING_OVERRIDES = -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-
out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-
microsoft-enum-forward-reference
-DEFINE CLANGPDB_ALL_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) DEF(CLANGPDB_WARNING_OVERRIDES) -fno-stack-protector -
mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -fno-
asynchronous-unwind-tables -mno-implicit-float -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -
funsigned-char -fno-ms-extensions -Wno-null-dereference -fms-compatibility -mno-stack-arg-probe
+DEFINE CLANGPDB_ALL_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) DEF(CLANGPDB_WARNING_OVERRIDES) -
DNO_MSABI_VA_FUNCS -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-
incompatible-library-redeclaration -fno-asynchronous-unwind-tables -mno-implicit-float -ftrap-
function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference -fms-
compatibility -mno-stack-arg-probe

###########################
# CLANGPDB IA32 definitions
--
2.16.2.windows.1


Re: [PATCH 2/2] MdePkg: Use the same VA function for both CLANGPDB and CLANG38

Liming Gao
 

Reviewed-by: Liming Gao <liming.gao@...>

-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@...>
Sent: Monday, February 3, 2020 4:15 PM
To: devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@...>; Gao, Liming <liming.gao@...>
Subject: [PATCH 2/2] MdePkg: Use the same VA function for both CLANGPDB and CLANG38

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2415

For CLANGPDB tool chain and X64, use MS ABI version of GCC built-in macros for
variable argument lists to be align with CLANG38 tool chain.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <liming.gao@...>

Signed-off-by: Zhiguang Liu <zhiguang.liu@...>
---
MdePkg/Include/Base.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index e0bcd0ae67..33211b96f7 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -623,7 +623,7 @@ typedef char* VA_LIST;

#elif defined(__GNUC__) || defined(__clang__)

-#if defined(MDE_CPU_X64) && !defined(NO_MSABI_VA_FUNCS) && !defined(__clang__)
+#if defined(MDE_CPU_X64) && !defined(NO_MSABI_VA_FUNCS)
//
// X64 only. Use MS ABI version of GCC built-in macros for variable argument lists.
//
--
2.16.2.windows.1


[edk2-platforms][PATCH v3 3/3] Platform/RPi4: Enable Broadcom Genet stub driver

Pete Batard
 

From: Jeremy Linton <lintonrjeremy@...>

This adds the required references to use the Genet stub driver in
order to dynamically populate the MAC address for OS consumption.

Signed-off-by: Pete Batard <pete@...>
---
Platform/RaspberryPi/RPi4/RPi4.dsc | 5 +++++
Platform/RaspberryPi/RPi4/RPi4.fdf | 1 +
2 files changed, 6 insertions(+)

diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc
index b3a114b6e0ed..bd3800c1d653 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
@@ -402,6 +402,7 @@ [PcdsFixedAtBuild.common]
gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x40000000
gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress|0xfc000000
gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0xfe000000
+ gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress|0xfd580000

# PCIe specific addresses
gBcm27xxTokenSpaceGuid.PcdBcm27xxPciRegBase|0xfd500000
@@ -648,6 +649,10 @@ [Components.common]
# Networking stack
#
!include NetworkPkg/Network.dsc.inc
+ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf {
+ <LibraryClasses>
+ NULL|Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf
+ }

#
# RNG
diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4/RPi4.fdf
index 2bcfdb3244f6..db393d47bcea 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.fdf
+++ b/Platform/RaspberryPi/RPi4/RPi4.fdf
@@ -269,6 +269,7 @@ [FV.FvMain]
# Networking stack
#
!include NetworkPkg/Network.fdf.inc
+ INF Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf

#
# RNG
--
2.21.0.windows.1


[edk2-platforms][PATCH v3 2/3] Platform/RPi: Add PlatformPcdLib to set the Genet MAC address

Pete Batard
 

The Genet driver stub used by the Raspberry Pi 4 platform is
designed to set the MAC address according to a PCD.

To be able to set that PCD at runtime, by using the Raspberry
Pi firmware interface, that has a dedicated call to retrieve
the MAC address, and satisfy driver dependencies in a generic
manner, we create a new PlatformPcdLib that can be referenced
by the Genet driver, to set the MAC PCD before use there.

While it is currently only tailored around MAC PCD population
for Genet, we do expect this PCD library to be extended in the
future, to provide additional PCD facilities for other drivers.

Signed-off-by: Pete Batard <pete@...>
---
Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c | 45 ++++++++++++++++++++
Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf | 43 +++++++++++++++++++
2 files changed, 88 insertions(+)

diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c
new file mode 100644
index 000000000000..e78518c81374
--- /dev/null
+++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c
@@ -0,0 +1,45 @@
+/** @file
+ *
+ * Copyright (c) 2020, Pete Batard <pete@...>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause-Patent
+ *
+ **/
+
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Protocol/RpiFirmware.h>
+
+EFI_STATUS
+EFIAPI
+PlatformPcdLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ UINT64 MacAddr;
+ RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
+
+ if (PcdGet64 (PcdBcmGenetMacAddress) == 0) {
+ Status = gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid, NULL,
+ (VOID**)&mFwProtocol);
+ ASSERT_EFI_ERROR(Status);
+
+ //
+ // Get the MAC address from the firmware
+ //
+ Status = mFwProtocol->GetMacAddress ((UINT8*) &MacAddr);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "%a: failed to retrieve MAC address\n", __FUNCTION__));
+ } else {
+ PcdSet64S (PcdBcmGenetMacAddress, MacAddr);
+ }
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf
new file mode 100644
index 000000000000..2a207d2b3e54
--- /dev/null
+++ b/Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf
@@ -0,0 +1,43 @@
+#/** @file
+#
+# Copyright (c) 2020, Pete Batard <pete@...>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x0001001A
+ BASE_NAME = PlatformPcdLib
+ FILE_GUID = 3B8409D7-D3C7-4006-823B-BFB184435363
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = NULL|DXE_DRIVER UEFI_APPLICATION
+ CONSTRUCTOR = PlatformPcdLibConstructor
+
+[Sources]
+ PlatformPcdLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ Platform/RaspberryPi/RaspberryPi.dec
+ Silicon/Broadcom/Drivers/Net/BcmNet.dec
+
+[LibraryClasses]
+ DebugLib
+ PcdLib
+ UefiLib
+ PrintLib
+
+[Protocols]
+ gRaspberryPiFirmwareProtocolGuid ## CONSUMES
+
+[Pcd]
+ gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress ## SOMETIMES_PRODUCES
+
+[FixedPcd]
+ gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress
+
+[Depex]
+ gRaspberryPiFirmwareProtocolGuid
--
2.21.0.windows.1


[edk2-platforms][PATCH v3 1/3] Silicon/Broadcom/Net: Add Genet stub driver to setup MAC

Pete Batard
 

From: Jeremy Linton <lintonrjeremy@...>

Add a stub for the Broadcom Genet network interface, that is used
by the Raspberry Pi 4 (and that may be used by other platforms).

For the time being, the stub only performs UMAC init, using a MAC
address PCD, as, even without a working network interface in UEFI
environment, it is desirable if the hardware can describe itself
for booting in an ACPI environment, rather than pass parameters via
DSDT/DSD .

Signed-off-by: Pete Batard <pete@...>
---
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 40 +++++++
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c | 114 ++++++++++++++++++++
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h | 20 ++++
Silicon/Broadcom/Drivers/Net/BcmNet.dec | 22 ++++
4 files changed, 196 insertions(+)

diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
new file mode 100644
index 000000000000..9e9301608f24
--- /dev/null
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
@@ -0,0 +1,40 @@
+## @file
+#
+# Copyright (c) 2020, Jeremy Linton All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001A
+ BASE_NAME = BcmGenetDxe
+ FILE_GUID = e2b1eaf3-50b7-4ae1-b79e-ec8020cb57ac
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 0.1
+ ENTRY_POINT = GenetEntryPoint
+
+[Sources]
+ Genet.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Broadcom/Drivers/Net/BcmNet.dec
+
+[LibraryClasses]
+ ArmLib
+ BaseLib
+ IoLib
+ UefiDriverEntryPoint
+ UefiLib
+
+[FixedPcd]
+ gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress
+
+[Pcd]
+ gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress
+
+[Depex]
+ TRUE
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c
new file mode 100644
index 000000000000..9f29bc0c0894
--- /dev/null
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c
@@ -0,0 +1,114 @@
+/** @file
+
+ Copyright (c) 2020, Jeremy Linton All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ This driver acts like a stub to set the Broadcom
+ Genet MAC address, until the actual network driver
+ is in place.
+
+**/
+
+#include <Library/ArmLib.h>
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Genet.h>
+#include <PiDxe.h>
+
+STATIC
+VOID
+RMWRegister (
+ UINT32 Offset,
+ UINT32 Mask,
+ UINT32 In
+ )
+{
+ EFI_PHYSICAL_ADDRESS Addr;
+ UINT32 Data;
+ UINT32 Shift;
+
+ Addr = GENET_BASE_ADDRESS + Offset;
+ Data = 0;
+ Shift = 1;
+ if (In) {
+ while (!(Mask & Shift))
+ Shift <<= 1;
+ Data = (MmioRead32 (Addr) & ~Mask) | ((In * Shift) & Mask);
+ } else {
+ Data = MmioRead32 (Addr) & ~Mask;
+ }
+
+ MmioWrite32 (Addr, Data);
+
+ ArmDataMemoryBarrier ();
+}
+
+STATIC
+VOID
+WdRegister (
+ UINT32 Offset,
+ UINT32 In
+ )
+{
+ EFI_PHYSICAL_ADDRESS Base = GENET_BASE_ADDRESS;
+
+ MmioWrite32 (Base + Offset, In);
+
+ ArmDataMemoryBarrier ();
+}
+
+STATIC
+VOID
+SetMacAddress (
+ UINT8* MacAddr
+)
+{
+ // Bring the UMAC out of reset
+ RMWRegister (GENET_SYS_RBUF_FLUSH_CTRL, 0x2, 1);
+ gBS->Stall (10);
+ RMWRegister (GENET_SYS_RBUF_FLUSH_CTRL, 0x2, 0);
+
+ // Update the MAC
+ DEBUG ((DEBUG_INFO, "Using MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
+ MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]));
+
+ WdRegister (GENET_UMAC_MAC0, (MacAddr[0] << 24) | (MacAddr[1] << 16) |
+ (MacAddr[2] << 8) | MacAddr[3]);
+ WdRegister (GENET_UMAC_MAC1, (MacAddr[4] << 8) | MacAddr[5]);
+
+}
+
+/**
+ The entry point of Genet UEFI Driver.
+
+ @param ImageHandle The image handle of the UEFI Driver.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The Driver or UEFI Driver exited normally.
+ @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
+ SystemTable->Hdr.Revision.
+
+**/
+EFI_STATUS
+EFIAPI
+GenetEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ UINT64 MacAddr;
+
+ // Read the MAC address
+ MacAddr = PcdGet64 (PcdBcmGenetMacAddress);
+
+ if (MacAddr != 0) {
+ SetMacAddress ((UINT8*)&MacAddr);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h
new file mode 100644
index 000000000000..4a3827c0e0d1
--- /dev/null
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h
@@ -0,0 +1,20 @@
+/** @file
+
+ Copyright (c) 2020, Pete Batard <pete@...>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef BCM_GENET_H__
+#define BCM_GENET_H__
+
+#include <Library/PcdLib.h>
+
+#define GENET_BASE_ADDRESS (FixedPcdGet64 (PcdBcmGenetRegistersAddress))
+
+#define GENET_SYS_RBUF_FLUSH_CTRL 0x0008
+#define GENET_UMAC_MAC0 0x080c
+#define GENET_UMAC_MAC1 0x0810
+
+#endif /* BCM_GENET_H__ */
diff --git a/Silicon/Broadcom/Drivers/Net/BcmNet.dec b/Silicon/Broadcom/Drivers/Net/BcmNet.dec
new file mode 100644
index 000000000000..2a8688cb09a7
--- /dev/null
+++ b/Silicon/Broadcom/Drivers/Net/BcmNet.dec
@@ -0,0 +1,22 @@
+## @file
+#
+# Copyright (c) 2020, Pete Batard <pete@...>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ DEC_SPECIFICATION = 0x0001001A
+ PACKAGE_NAME = BcmNetPkg
+ PACKAGE_GUID = 34E19823-D23A-41AB-9C09-ED1225B32DFF
+ PACKAGE_VERSION = 1.0
+
+[Guids]
+ gBcmNetTokenSpaceGuid = {0x12b97d70, 0x9149, 0x4c2f, {0x82, 0xd5, 0xad, 0xa9, 0x1e, 0x92, 0x75, 0xa1}}
+
+[PcdsFixedAtBuild]
+ gBcmNetTokenSpaceGuid.PcdBcmGenetRegistersAddress|0x0|UINT64|0x00000001
+
+[PcdsDynamic]
+ gBcmNetTokenSpaceGuid.PcdBcmGenetMacAddress|0x0|UINT64|0x00000002
--
2.21.0.windows.1


[edk2-platforms][PATCH v3 0/3] Platform/RPi4: Add Genet network driver stub

Pete Batard
 

Changes from v2:
* Remove #if (FixedPcdGet64 (PcdBcmGenetRegistersAddress) != 0) check

Jeremy Linton (2):
Silicon/Broadcom/Net: Add Genet stub driver to setup MAC
Platform/RPi4: Enable Broadcom Genet stub driver

Pete Batard (1):
Platform/RPi: Add PlatformPcdLib to set the Genet MAC address

Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c | 45 ++++++++
Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf | 43 ++++++++
Platform/RaspberryPi/RPi4/RPi4.dsc | 5 +
Platform/RaspberryPi/RPi4/RPi4.fdf | 1 +
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 40 +++++++
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c | 114 ++++++++++++++++++++
Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h | 20 ++++
Silicon/Broadcom/Drivers/Net/BcmNet.dec | 22 ++++
8 files changed, 290 insertions(+)
create mode 100644 Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.c
create mode 100644 Platform/RaspberryPi/Library/PlatformPcdLib/PlatformPcdLib.inf
create mode 100644 Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf
create mode 100644 Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.c
create mode 100644 Silicon/Broadcom/Drivers/Net/BcmGenetDxe/Genet.h
create mode 100644 Silicon/Broadcom/Drivers/Net/BcmNet.dec

--
2.21.0.windows.1


Re: [PATCH v1 1/1] BaseTools: Rationalise makefile generation

Liming Gao
 

Pierre:
Thanks for your contribution. Do you verify below configurations? And, how do you verify Windows host + GCC make?
1. Windows Host + VS nmake
2. Windows Host + GCC make
3. Linux Host + GCC make.

Thanks
Liming

-----Original Message-----
From: Pierre Gondois <Pierre.Gondois@...>
Sent: Thursday, January 23, 2020 1:37 AM
To: Pierre Gondois <Pierre.Gondois@...>; devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@...>; Gao, Liming <liming.gao@...>; Sami Mujawar <Sami.Mujawar@...>; nd
<nd@...>
Subject: RE: [PATCH v1 1/1] BaseTools: Rationalise makefile generation

Hello Bob and Liming,
Just to let you know, I created a Bugzilla here on the same topic: https://bugzilla.tianocore.org/show_bug.cgi?id=2481

Regards,
Pierre

-----Original Message-----
From: PierreGondois <pierre.gondois@...>
Sent: 13 January 2020 14:41
To: devel@edk2.groups.io
Cc: Pierre Gondois <Pierre.Gondois@...>; bob.c.feng@...; liming.gao@...; Sami Mujawar
<Sami.Mujawar@...>; pierre.gondois@...@arm.com
Subject: [PATCH v1 1/1] BaseTools: Rationalise makefile generation

From: Pierre Gondois <pierre.gondois@...>

The GenMake.py script tests the platform environment to determine the type of makefile that needs to be generated. If a Windows
build host is detected, the makefile generated is of Nmake type. Otherwise a GNUmake type is generated.

Furthermore, the <TARGET>_<TAGNAME>_<ARCH>_MAKE_PATH
option in tools_def.template defines the make tool to use.
E.g.: for VS2017 this is configured to use Nmake, cf.
*_VS2017_*_MAKE_PATH = DEF(VS2017_BIN_HOST)\nmake.exe while for GCC5 it is setup to use GNU make.
*_GCC5_*_MAKE_PATH = DEF(GCC_HOST_PREFIX)make

This prevents using the GCC compiler toolchain on a Windows build host.

To address this issue this patch introduces 2 factors to determine the generated makefile output.
1. Platform -> to determine shell commands used
in makefile.
2. MakeTool -> to determine the type of makefile
that needs to be generated.

Signed-off-by: Pierre Gondois <pierre.gondois@...>
Signed-off-by: Sami Mujawar <sami.mujawar@...>
---

The changes can be seen at https://github.com/PierreARM/edk2/tree/720_BaseTools_Rationalise_makefile_generation_v1

Notes:
v1:
- Rationalise makefile generation [Pierre]

BaseTools/Source/Python/AutoGen/GenMake.py | 122 ++++++++++----------
BaseTools/Source/Python/AutoGen/IncludesAutoGen.py | 34 +++---
BaseTools/Source/Python/build/build.py | 7 +-
3 files changed, 88 insertions(+), 75 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index fe94f9a4c232bb599a59563444c3985700c78ec6..640b562257f74a45b38b8c857dae4750f7c286e0 100755
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -2,6 +2,7 @@
# Create makefile for MS nmake and GNU make # # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent #

@@ -52,13 +53,6 @@ gIncludeMacroConversion = {
"EFI_PPI_DEPENDENCY" : gPpiDefinition,
}

-## default makefile type
-gMakeType = ""
-if sys.platform == "win32":
- gMakeType = "nmake"
-else:
- gMakeType = "gmake"
-

## BuildFile class
#
@@ -77,6 +71,13 @@ class BuildFile(object):
"gmake" : "GNUmakefile"
}

+ # Get Makefile name.
+ def getMakefileName(self):
+ if not self._FileType:
+ return _DEFAULT_FILE_NAME_
+ else:
+ return self._FILE_NAME_[self._FileType]
+
## Fixed header string for makefile
_MAKEFILE_HEADER = '''#
# DO NOT EDIT
@@ -106,7 +107,7 @@ class BuildFile(object):
# $(RD) remove dir command
#
_SHELL_CMD_ = {
- "nmake" : {
+ "win32" : {
"CP" : "copy /y",
"MV" : "move /y",
"RM" : "del /f /q",
@@ -114,7 +115,7 @@ class BuildFile(object):
"RD" : "rmdir /s /q",
},

- "gmake" : {
+ "posix" : {
"CP" : "cp -f",
"MV" : "mv -f",
"RM" : "rm -f",
@@ -125,35 +126,35 @@ class BuildFile(object):

## directory separator
_SEP_ = {
- "nmake" : "\\",
- "gmake" : "/"
+ "win32" : "\\",
+ "posix" : "/"
}

## directory creation template
_MD_TEMPLATE_ = {
- "nmake" : 'if not exist %(dir)s $(MD) %(dir)s',
- "gmake" : "$(MD) %(dir)s"
+ "win32" : 'if not exist %(dir)s $(MD) %(dir)s',
+ "posix" : "$(MD) %(dir)s"
}

## directory removal template
_RD_TEMPLATE_ = {
- "nmake" : 'if exist %(dir)s $(RD) %(dir)s',
- "gmake" : "$(RD) %(dir)s"
+ "win32" : 'if exist %(dir)s $(RD) %(dir)s',
+ "posix" : "$(RD) %(dir)s"
}
## cp if exist
_CP_TEMPLATE_ = {
- "nmake" : 'if exist %(Src)s $(CP) %(Src)s %(Dst)s',
- "gmake" : "test -f %(Src)s && $(CP) %(Src)s %(Dst)s"
+ "win32" : 'if exist %(Src)s $(CP) %(Src)s %(Dst)s',
+ "posix" : "test -f %(Src)s && $(CP) %(Src)s %(Dst)s"
}

_CD_TEMPLATE_ = {
- "nmake" : 'if exist %(dir)s cd %(dir)s',
- "gmake" : "test -e %(dir)s && cd %(dir)s"
+ "win32" : 'if exist %(dir)s cd %(dir)s',
+ "posix" : "test -e %(dir)s && cd %(dir)s"
}

_MAKE_TEMPLATE_ = {
- "nmake" : 'if exist %(file)s "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',
- "gmake" : 'test -e %(file)s && "$(MAKE)" $(MAKE_FLAGS) -f %(file)s'
+ "win32" : 'if exist %(file)s "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',
+ "posix" : 'test -e %(file)s && "$(MAKE)" $(MAKE_FLAGS) -f %(file)s'
}

_INCLUDE_CMD_ = {
@@ -169,22 +170,30 @@ class BuildFile(object):
#
def __init__(self, AutoGenObject):
self._AutoGenObject = AutoGenObject
- self._FileType = gMakeType

- ## Create build file
+ MakePath = AutoGenObject.BuildOption.get('MAKE', {}).get('PATH')
+ if not MakePath:
+ self._FileType = ""
+ elif "nmake" in MakePath:
+ self._FileType = "nmake"
+ else:
+ self._FileType = "gmake"
+
+ if sys.platform == "win32":
+ self._Platform = "win32"
+ else:
+ self._Platform = "posix"
+
+ ## Create build file.
#
- # @param FileType Type of build file. Only nmake and gmake are supported now.
+ # Only nmake and gmake are supported.
#
- # @retval TRUE The build file is created or re-created successfully
- # @retval FALSE The build file exists and is the same as the one to be generated
+ # @retval TRUE The build file is created or re-created successfully
+ # @retval FALSE The build file exists and is the same as the one to be generated
#
- def Generate(self, FileType=gMakeType):
- if FileType not in self._FILE_NAME_:
- EdkLogger.error("build", PARAMETER_INVALID, "Invalid build type [%s]" % FileType,
- ExtraData="[%s]" % str(self._AutoGenObject))
- self._FileType = FileType
+ def Generate(self):
FileContent = self._TEMPLATE_.Replace(self._TemplateDict)
- FileName = self._FILE_NAME_[FileType]
+ FileName = self.getMakefileName()
if not os.path.exists(os.path.join(self._AutoGenObject.MakeFileDir, "deps.txt")):
with open(os.path.join(self._AutoGenObject.MakeFileDir, "deps.txt"),"w+") as fd:
fd.write("")
@@ -200,7 +209,7 @@ class BuildFile(object):
# @retval list The directory creation command list
#
def GetCreateDirectoryCommand(self, DirList):
- return [self._MD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]
+ return [self._MD_TEMPLATE_[self._Platform] % {'dir':Dir} for
+ Dir in DirList]

## Return a list of directory removal command string
#
@@ -209,7 +218,7 @@ class BuildFile(object):
# @retval list The directory removal command list
#
def GetRemoveDirectoryCommand(self, DirList):
- return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]
+ return [self._RD_TEMPLATE_[self._Platform] % {'dir':Dir} for
+ Dir in DirList]

def PlaceMacro(self, Path, MacroDefinitions=None):
if Path.startswith("$("):
@@ -459,11 +468,8 @@ cleanlib:
# Compose a dict object containing information used to do replacement in template
@property
def _TemplateDict(self):
- if self._FileType not in self._SEP_:
- EdkLogger.error("build", PARAMETER_INVALID, "Invalid Makefile type [%s]" % self._FileType,
- ExtraData="[%s]" % str(self._AutoGenObject))
MyAgo = self._AutoGenObject
- Separator = self._SEP_[self._FileType]
+ Separator = self._SEP_[self._Platform]

# break build if no source files and binary files are found
if len(MyAgo.SourceFileList) == 0 and len(MyAgo.BinaryFileList) == 0:
@@ -625,10 +631,10 @@ cleanlib:

BcTargetList = []

- MakefileName = self._FILE_NAME_[self._FileType]
+ MakefileName = self.getMakefileName()
LibraryMakeCommandList = []
for D in self.LibraryBuildDirectoryList:
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join(D, MakefileName)}
+ Command = self._MAKE_TEMPLATE_[self._Platform] %
+ {"file":os.path.join(D, MakefileName)}
LibraryMakeCommandList.append(Command)

package_rel_dir = MyAgo.SourceDir @@ -680,8 +686,8 @@ cleanlib:
"separator" : Separator,
"module_tool_definitions" : ToolsDef,

- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),

"module_entry_point" : ModuleEntryPoint,
"image_entry_point" : ImageEntryPoint,
@@ -716,7 +722,7 @@ cleanlib:
self.ResultFileList.append(Dst)
if '%s :' %(Dst) not in self.BuildTargetList:
self.BuildTargetList.append("%s :" %(Dst))
- self.BuildTargetList.append('\t' + self._CP_TEMPLATE_[self._FileType] %{'Src': Src, 'Dst': Dst})
+ self.BuildTargetList.append('\t' +
+ self._CP_TEMPLATE_[self._Platform] %{'Src': Src, 'Dst': Dst})

FfsCmdList = Cmd[0]
for index, Str in enumerate(FfsCmdList):
@@ -1217,7 +1223,7 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
# Compose a dict object containing information used to do replacement in template
@property
def _TemplateDict(self):
- Separator = self._SEP_[self._FileType]
+ Separator = self._SEP_[self._Platform]
MyAgo = self._AutoGenObject
if self._FileType not in MyAgo.CustomMakefile:
EdkLogger.error('build', OPTION_NOT_SUPPORTED, "No custom makefile for %s" % self._FileType, @@ -1247,7 +1253,7 @@
${BEGIN}\t-@${create_directory_command}\n${END}\
ToolsDef.append("%s_%s = %s" % (Tool, Attr, MyAgo.BuildOption[Tool][Attr]))
ToolsDef.append("")

- MakefileName = self._FILE_NAME_[self._FileType]
+ MakefileName = self.getMakefileName()
MakefileTemplateDict = {
"makefile_header" : self._FILE_HEADER_[self._FileType],
"makefile_path" : os.path.join("$(MODULE_BUILD_DIR)", MakefileName),
@@ -1280,8 +1286,8 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
"separator" : Separator,
"module_tool_definitions" : ToolsDef,

- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),

"create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),
"custom_makefile_content" : CustomMakefile
@@ -1408,7 +1414,7 @@ cleanlib:
# Compose a dict object containing information used to do replacement in template
@property
def _TemplateDict(self):
- Separator = self._SEP_[self._FileType]
+ Separator = self._SEP_[self._Platform]

MyAgo = self._AutoGenObject
if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:
@@ -1419,13 +1425,13 @@ cleanlib:
self.ModuleBuildDirectoryList = self.GetModuleBuildDirectoryList()
self.LibraryBuildDirectoryList = self.GetLibraryBuildDirectoryList()

- MakefileName = self._FILE_NAME_[self._FileType]
+ MakefileName = self.getMakefileName()
LibraryMakefileList = []
LibraryMakeCommandList = []
for D in self.LibraryBuildDirectoryList:
D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})
Makefile = os.path.join(D, MakefileName)
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}
+ Command = self._MAKE_TEMPLATE_[self._Platform] %
+ {"file":Makefile}
LibraryMakefileList.append(Makefile)
LibraryMakeCommandList.append(Command)
self.LibraryMakeCommandList = LibraryMakeCommandList @@ -1435,7 +1441,7 @@ cleanlib:
for D in self.ModuleBuildDirectoryList:
D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})
Makefile = os.path.join(D, MakefileName)
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}
+ Command = self._MAKE_TEMPLATE_[self._Platform] %
+ {"file":Makefile}
ModuleMakefileList.append(Makefile)
ModuleMakeCommandList.append(Command)

@@ -1455,8 +1461,8 @@ cleanlib:

"toolchain_tag" : MyAgo.ToolChain,
"build_target" : MyAgo.BuildTarget,
- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),
"build_architecture_list" : MyAgo.Arch,
"architecture" : MyAgo.Arch,
"separator" : Separator,
@@ -1514,7 +1520,7 @@ class TopLevelMakefile(BuildFile):
# Compose a dict object containing information used to do replacement in template
@property
def _TemplateDict(self):
- Separator = self._SEP_[self._FileType]
+ Separator = self._SEP_[self._Platform]

# any platform autogen object is ok because we just need common information
MyAgo = self._AutoGenObject
@@ -1570,10 +1576,10 @@ class TopLevelMakefile(BuildFile):
else:
ExtraOption += " --pcd " + pcdname + '=' + pcd[3]

- MakefileName = self._FILE_NAME_[self._FileType]
+ MakefileName = self.getMakefileName()
SubBuildCommandList = []
for A in MyAgo.ArchList:
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}
+ Command = self._MAKE_TEMPLATE_[self._Platform] %
+ {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}
SubBuildCommandList.append(Command)

MakefileTemplateDict = {
@@ -1588,8 +1594,8 @@ class TopLevelMakefile(BuildFile):

"toolchain_tag" : MyAgo.ToolChain,
"build_target" : MyAgo.BuildTarget,
- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),
'arch' : list(MyAgo.ArchList),
"build_architecture_list" : ','.join(MyAgo.ArchList),
"separator" : Separator,
diff --git a/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py b/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py
index bb6e883d84ca6decc97514f95a35bd6db8714eed..c41dc33c4bcf33d30cf8bfc829718ed96923ff8f 100644
--- a/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/IncludesAutoGen.py
@@ -2,6 +2,7 @@
# Build cache intermediate result and state # # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # from Common.caching import cached_property @@ -12,20 +13,6 @@ from
Common.Misc import SaveFileOnChange, PathClass from Common.Misc import TemplateString import sys gIsFileMap = {} -if
sys.platform == "win32":
- _INCLUDE_DEPS_TEMPLATE = TemplateString('''
-${BEGIN}
-!IF EXIST(${deps_file})
-!INCLUDE ${deps_file}
-!ENDIF
-${END}
- ''')
-else:
- _INCLUDE_DEPS_TEMPLATE = TemplateString('''
-${BEGIN}
--include ${deps_file}
-${END}
- ''')

DEP_FILE_TAIL = "# Updated \n"

@@ -59,6 +46,25 @@ class IncludesAutoGen():

def CreateDepsInclude(self):
deps_file = {'deps_file':self.deps_files}
+
+ MakePath = self.module_autogen.BuildOption.get('MAKE', {}).get('PATH')
+ if not MakePath:
+ EdkLogger.error("build", PARAMETER_MISSING, Message="No Make path available.")
+ elif "nmake" in MakePath:
+ _INCLUDE_DEPS_TEMPLATE = TemplateString('''
+ ${BEGIN}
+ !IF EXIST(${deps_file})
+ !INCLUDE ${deps_file}
+ !ENDIF
+ ${END}
+ ''')
+ else:
+ _INCLUDE_DEPS_TEMPLATE = TemplateString('''
+ ${BEGIN}
+ -include ${deps_file}
+ ${END}
+ ''')
+
try:
deps_include_str = _INCLUDE_DEPS_TEMPLATE.Replace(deps_file)
except Exception as e:
diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py
index 34acdccbdbd00a3d10f9c6c42004f59a96ff0063..a2a4337b7524163049c77f99874ce1a7aa4c1644 100755
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -4,6 +4,7 @@
# Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR> # Copyright (c) 2007 - 2019, Intel Corporation. All rights
reserved.<BR> # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
+# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -1250,7 +1251,7 @@ class Build():
(AutoGenObject.BuildTarget, AutoGenObject.ToolChain, AutoGenObject.Arch),
ExtraData=str(AutoGenObject))

- makefile = GenMake.BuildFile(AutoGenObject)._FILE_NAME_[GenMake.gMakeType]
+ makefile = GenMake.BuildFile(AutoGenObject).getMakefileName()

# run
if Target == 'run':
@@ -2039,10 +2040,10 @@ class Build():
ModuleBuildDirectoryList = data_pipe.Get("ModuleBuildDirectoryList")

for m_build_dir in LibraryBuildDirectoryList:
- if not os.path.exists(os.path.join(m_build_dir,GenMake.BuildFile._FILE_NAME_[GenMake.gMakeType])):
+ if not os.path.exists(os.path.join(m_build_dir,GenMake.BuildFile.getMakefileName())):
return None
for m_build_dir in ModuleBuildDirectoryList:
- if not os.path.exists(os.path.join(m_build_dir,GenMake.BuildFile._FILE_NAME_[GenMake.gMakeType])):
+ if not os.path.exists(os.path.join(m_build_dir,GenMake.BuildFile.getMakefileName())):
return None
Wa = WorkSpaceInfo(
workspacedir,active_p,target,toolchain,archlist
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


Re: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

Liming Gao
 

Pierre:
Sorry for late response. I have one comment. Why only allows "DSDT" or "SSDT" in Signature?

Thanks
Liming

-----Original Message-----
From: Pierre Gondois <Pierre.Gondois@...>
Sent: Thursday, January 23, 2020 1:32 AM
To: Pierre Gondois <Pierre.Gondois@...>; devel@edk2.groups.io
Cc: ard.biesheuvel@...; Feng, Bob C <bob.c.feng@...>; Gao, Liming <liming.gao@...>; Sami Mujawar
<Sami.Mujawar@...>; nd <nd@...>
Subject: RE: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

Hello everyone,
Do you have any input on the patch?

Regards,
Pierre

-----Original Message-----
From: PierreGondois <pierre.gondois@...>
Sent: 17 January 2020 17:18
To: devel@edk2.groups.io
Cc: Pierre Gondois <Pierre.Gondois@...>; ard.biesheuvel@...; bob.c.feng@...; liming.gao@...; Sami
Mujawar <Sami.Mujawar@...>; nd <nd@...>
Subject: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex

From: Pierre Gondois <pierre.gondois@...>

The "-tc" option of the iasl compiler allows to generate a .hex file containing a C array storing AML bytecode.

An online discussion suggested that this "-tc" option was specific to the iasl compiler and it shouldn't be relied on. This conversation is
available at:
https://edk2.groups.io/g/devel/topic/39786201#49659

A way to address this issue is to implement a compiler independent script that takes an AML file as input, and generates a .hex file.

This patch implements a Python script that converts an AML file to a .hex file, containing a C array storing AML bytecode.
This scipt has been tested with the AML output from the following compilers supported by the EDKII implementation:
* Intel ASL compiler
* Microsoft ASL compiler

Signed-off-by: Pierre Gondois <pierre.gondois@...>
---

The changes can be seen at https://github.com/PierreARM/edk2/commits/718_asl_to_hex_script_converter_2

Notes:
v2:
- Script converting AML to .hex file [Pierre]

BaseTools/BinWrappers/PosixLike/AmlToHex | 14 ++
BaseTools/BinWrappers/WindowsLike/AmlToHex.bat | 3 +
BaseTools/Conf/build_rule.template | 3 +
BaseTools/Source/Python/AmlToHex/AmlToHex.py | 155 ++++++++++++++++++++
4 files changed, 175 insertions(+)

diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex b/BaseTools/BinWrappers/PosixLike/AmlToHex
new file mode 100755
index 0000000000000000000000000000000000000000..1dd28e966288f6ea4fc52d42e2dc7b1f74226c23
--- /dev/null
+++ b/BaseTools/BinWrappers/PosixLike/AmlToHex
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+#python `dirname $0`/RunToolFromSource.py `basename $0` $*
+
+# If a ${PYTHON_COMMAND} command is available, use it in preference to
+python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then
+ python_exe=${PYTHON_COMMAND}
+fi
+
+full_cmd=${BASH_SOURCE:-$0} # see
+http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is
+not a good choice here dir=$(dirname "$full_cmd") exe=$(basename
+"$full_cmd")
+
+export PYTHONPATH="$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"}"
+exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@"
diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
new file mode 100644
index 0000000000000000000000000000000000000000..9616cd893bec9902451e6d8591f537cc408bd5e5
--- /dev/null
+++ b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat
@@ -0,0 +1,3 @@
+@setlocal
+@set ToolName=%~n0%
+@%PYTHON_COMMAND%
+%BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template
index 51748bc0655a5c656258a3007b4db6b2dc941ea0..0822b681fcd9f61c6508e6f93ffc31fa70fd7059 100755
--- a/BaseTools/Conf/build_rule.template
+++ b/BaseTools/Conf/build_rule.template
@@ -1,6 +1,7 @@
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> # Portions copyright (c) 2008 - 2010, Apple Inc. All rights
reserved.<BR>
+# Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent #

@@ -427,12 +428,14 @@
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) /I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i >
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
+ -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml

<Command.GCC>
Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src}
"$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) -I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i >
$(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
"$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
+ -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml

[C-Code-File.AcpiTable]
<InputFile>
diff --git a/BaseTools/Source/Python/AmlToHex/AmlToHex.py b/BaseTools/Source/Python/AmlToHex/AmlToHex.py
new file mode 100644
index 0000000000000000000000000000000000000000..e8e7ace3a68532bc625afb1e74404c4e4b0205dd
--- /dev/null
+++ b/BaseTools/Source/Python/AmlToHex/AmlToHex.py
@@ -0,0 +1,155 @@
+## @file
+#
+# Convert an AML file to a .hex file containing the AML bytecode stored
+in a # C array.
+# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.hex".
+# "Tables\Dsdt.hex" will contain a C array named "dsdt_aml_code" that
+contains # the AML bytecode.
+#
+# Copyright (c) 2020, ARM Limited. All rights reserved.<BR> # #
+SPDX-License-Identifier: BSD-2-Clause-Patent #
+
+import argparse
+import Common.EdkLogger as EdkLogger
+from Common.BuildToolError import *
+import sys
+import os
+
+## Parse the command line arguments.
+#
+# @retval A argparse.NameSpace instance, containing parsed values.
+#
+def ParseArgs():
+ # Initialize the parser.
+ Parser = argparse.ArgumentParser(
+ description="Convert an AML file to a .hex file containing the AML " + \
+ "bytecode stored in a C array. By default, " + \
+ "\"Tables\\Dsdt.aml\" will generate" + \
+ "\"Tables\\Dsdt.hex\". \"Tables\\Dsdt.hex\" will " + \
+ "contain a C array named \"dsdt_aml_code\" that " + \
+ "contains the AML bytecode."
+ )
+
+ # Define the possible arguments.
+ Parser.add_argument(
+ dest="InputFile",
+ help="Path to an input AML file to generate a .hex file from."
+ )
+ Parser.add_argument(
+ "-o", "--out-dir", dest="OutDir",
+ help="Output directory where the .hex file will be generated. " + \
+ "Default is the input file's directory."
+ )
+
+ # Parse the input arguments.
+ Args = Parser.parse_args()
+ SplitInputName = ""
+
+ if not os.path.exists(Args.InputFile):
+ EdkLogger.error(__file__, FILE_OPEN_FAILURE,
+ ExtraData=Args.InputFile)
+ return
+ else:
+ with open(Args.InputFile, "rb") as fIn:
+ Signature = str(fIn.read(4))
+ if ("DSDT" not in Signature) and ("SSDT" not in Signature):
+ EdkLogger.error(__file__, PARAMETER_INVALID,
+ ExtraData=Args.InputFile,
+ Message="Error: Invalid file type. " + \
+ "File does not have a valid " + \
+ "DSDT or SSDT signature.")
+
+ # Get the basename of the input file.
+ SplitInputName = os.path.splitext(Args.InputFile)
+ BaseName = os.path.basename(SplitInputName[0])
+
+ # If no output directory is specified, output to the input directory.
+ if not Args.OutDir:
+ Args.OutputFile = os.path.join(
+ os.path.dirname(Args.InputFile),
+ BaseName + ".hex"
+ )
+ else:
+ if not os.path.exists(Args.OutDir):
+ os.mkdir(Args.OutDir)
+ Args.OutputFile = os.path.join(Args.OutDir, BaseName + ".hex")
+
+ Args.BaseName = BaseName
+
+ return Args
+
+## Convert an AML file to a .hex file containing the AML bytecode
+stored # in a C array.
+#
+# @param InputFile Path to the input AML file.
+# @param OutputFile Path to the output .hex file to generate.
+# @param BaseName Base name of the input file.
+# This is also the name of the generated .hex file.
+#
+def AmlToHex(InputFile, OutputFile, BaseName):
+
+ MacroName = "__{}_HEX__".format(BaseName.upper())
+ ArrayName = BaseName.lower() + "_aml_code"
+
+ with open(InputFile, "rb") as fIn, open(OutputFile, "w") as fOut:
+ # Write header.
+ fOut.write("// This file has been generated from:\n" + \
+ "// \tPython script: " + \
+ os.path.abspath(__file__) + "\n" + \
+ "// \tInput AML file: " + \
+ os.path.abspath(InputFile) + "\n\n" + \
+ "#ifndef {}\n".format(MacroName) + \
+ "#define {}\n\n".format(MacroName)
+ )
+
+ # Write the array and its content.
+ fOut.write("unsigned char {}[] = {{\n ".format(ArrayName))
+ cnt = 0
+ byte = fIn.read(1)
+ while len(byte) != 0:
+ fOut.write("0x{0:02X}, ".format(ord(byte)))
+ cnt += 1
+ if (cnt % 8) == 0:
+ fOut.write("\n")
+ byte = fIn.read(1)
+ fOut.write("\n};\n")
+
+ # Write footer.
+ fOut.write("#endif // {}\n".format(MacroName))
+
+## Main method
+#
+# This method:
+# 1- Initialize an EdkLogger instance.
+# 2- Parses the input arguments.
+# 3- Converts an AML file to a .hex file containing the AML bytecode stored
+# in a C array.
+#
+# @retval 0 Success.
+# @retval 1 Error.
+#
+def Main():
+ # Initialize an EdkLogger instance.
+ EdkLogger.Initialize()
+
+ try:
+ # Parse the input arguments.
+ CommandArguments = ParseArgs()
+
+ # Convert an AML file to a .hex file containing the AML bytecode stored
+ # in a C array.
+ AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFile,
+ CommandArguments.BaseName)
+ except Exception as e:
+ print(e)
+ return 1
+
+ return 0
+
+if __name__ == '__main__':
+ r = Main()
+ # 0-127 is a safe return range, and 1 is a standard default error
+ if r < 0 or r > 127: r = 1
+ sys.exit(r)
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


Re: [PATCH 0/1] Use _MSC_VER to determine MSVC compiler

Vitaly Cheptsov
 

Liming,

I believe it is reasonable to fix OpenSSL, but most likely it is faster to address EDK II code at first. In future we should still stick to _MSC_VER, but for now just ensuring that any toolchain by MSVC does not define _MSC_EXTENSIONS should work too.

I believe that -fms-compatibility option is not needed for CLANGPDB, as CLANGPDB is literally using clang, and that worked fine before in CLANG38 and XCODE5. We may still have to update some preprocessor conditions to include __clang__ near __GNUC__ if __GNUC__ is left undefined even when we remove -fms-compatibility, but that sounds fine for me.

We will investigate that on our own and submit a new patch, but help from other parties is strongly appreciated. We mostly use XCODE5 and are not well aware of other platforms.

Best wishes,
Vitaly

On Mon, Feb 3, 2020 at 11:00, Gao, Liming <liming.gao@...> wrote:
Vitaly:
This change will cause CryptoPkg openssl build failure, because OpensslLib.inf undefines _MSC_VER macro to make sure openssl source code be built in edk2 project without using MS VS functions.

Now, I have no good solution to fix this issue. One way is to use defined(_MSC_EXTENSIONS) && !defined(__clang__), another way is to investigate whether we can remove -fms-compatibility option in CLANGPDB.

Thanks
Liming
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Vitaly Cheptsov via Groups.Io
> Sent: Saturday, February 1, 2020 5:17 AM
> To: devel@edk2.groups.io
> Subject: [edk2-devel] [PATCH 0/1] Use _MSC_VER to determine MSVC compiler
>
> Patch details are explained in https://bugzilla.tianocore.org/show_bug.cgi?id=2397.
> We request this to be merged in edk2-stable202002.
>
> Vitaly Cheptsov (1):
> MdePkg: Use _MSC_VER to determine MSVC compiler
>
> MdePkg/Include/AArch64/ProcessorBind.h | 2 +-
> MdePkg/Include/Arm/ProcessorBind.h | 8 ++++----
> MdePkg/Include/Base.h | 10 +++++-----
> MdePkg/Include/Ia32/ProcessorBind.h | 6 +++---
> MdePkg/Include/X64/ProcessorBind.h | 6 +++---
> 5 files changed, 16 insertions(+), 16 deletions(-)
>
> --
> 2.21.1 (Apple Git-122.3)
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
>
> View/Reply Online (#53623): https://edk2.groups.io/g/devel/message/53623
> Mute This Topic: https://groups.io/mt/70882954/1759384
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [liming.gao@...]
> -=-=-=-=-=-=




Re: [PATCH v1] UefiCpuPkg/MpInitLib: Always get CPUID & PlatformID in MicrocodeDetect()

Laszlo Ersek
 

Hello Hao,

On 02/03/20 01:34, Hao A Wu wrote:
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2498

Commit fd30b00707 updated the logic in function MicrocodeDetect() that
will directly use the CPUID and PlatformID information from the 'CpuData'
field in the CPU_MP_DATA structure, instead of collecting these
information for each processor via AsmCpuid() and AsmReadMsr64() calls
respectively.

At that moment, this approach worked fine for APs. Since:
a) When the APs are waken up for the 1st time (1st MpInitLibInitialize()
entry at PEI phase), the function InitializeApData() will be called for
each AP and the CPUID and PlatformID information will be collected.

b) During the 2nd entry of MpInitLibInitialize() at DXE phase, when the
APs are waken up again, the function InitializeApData() will not be
called, which means the CPUID and PlatformID information will not be
collected. However, the below logics in MicrocodeDetect() function:

CurrentRevision = GetCurrentMicrocodeSignature ();
IsBspCallIn = (ProcessorNumber == (UINTN)CpuMpData->BspNumber) ? TRUE : FALSE;
if (CurrentRevision != 0 && !IsBspCallIn) {
//
// Skip loading microcode if it has been loaded successfully
//
return;
}

will ensure that the microcode detection and application will be
skipped due to the fact that such process has already been done in the
PEI phase.

But after commit 396e791059, which removes the above skip loading logic,
the CPUID and PlatformID information on APs will be used upon the 2nd
entry of the MpInitLibInitialize(). But since the CPUID and PlatformID
information has not been collected, it will bring issue to the microcode
detection process.

This commit will update the logic in MicrocodeDetect() back to always
collecting the CPUID and PlatformID information explicitly.

Cc: Eric Dong <eric.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Laszlo Ersek <lersek@...>
Cc: Siyuan Fu <siyuan.fu@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Signed-off-by: Hao A Wu <hao.a.wu@...>
---
UefiCpuPkg/Library/MpInitLib/Microcode.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
It seems like I haven't been involved in reviewing either commit
fd30b0070773 ("UefiCpuPkg/MpInitLib: Remove redundant microcode fields
in CPU_MP_DATA", 2020-01-02) or commit 396e791059f3 ("UefiCpuPkg: Always
load microcode patch on AP processor.", 2020-01-08), so I'd like to
defer on this patch to the other UefiCpuPkg reviewers.

Thanks!
Laszlo

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index b6675b9a60..67e214d463 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -93,6 +93,7 @@ MicrocodeDetect (
UINT32 InCompleteCheckSum32;
BOOLEAN CorrectMicrocode;
VOID *MicrocodeData;
+ MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr;
UINT32 ThreadId;
BOOLEAN IsBspCallIn;

@@ -115,8 +116,18 @@ MicrocodeDetect (
}

ExtendedTableLength = 0;
- Eax.Uint32 = CpuMpData->CpuData[ProcessorNumber].ProcessorSignature;
- PlatformId = CpuMpData->CpuData[ProcessorNumber].PlatformId;
+ //
+ // Here data of CPUID leafs have not been collected into context buffer, so
+ // GetProcessorCpuid() cannot be used here to retrieve CPUID data.
+ //
+ AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL);
+
+ //
+ // The index of platform information resides in bits 50:52 of MSR IA32_PLATFORM_ID
+ //
+ PlatformIdMsr.Uint64 = AsmReadMsr64 (MSR_IA32_PLATFORM_ID);
+ PlatformId = (UINT8) PlatformIdMsr.Bits.PlatformId;
+

//
// Check whether AP has same processor with BSP.


Re: [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: Use %08x to print CacheControl Index

Zeng, Star
 

-----Original Message-----
From: Laszlo Ersek <lersek@...>
Sent: Monday, February 3, 2020 4:47 PM
To: Zeng, Star <star.zeng@...>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>; Ni, Ray <ray.ni@...>
Subject: Re: [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: Use %08x to print
CacheControl Index

Hello Star,

On 02/03/20 08:06, Star Zeng wrote:
Instead of %08lx, use %08x to print CacheControl Index as it is UINT32
type.

Cc: Eric Dong <eric.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Laszlo Ersek <lersek@...>
Signed-off-by: Star Zeng <star.zeng@...>
---
.../Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git
a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
index 0a4fcff033a3..1a02809b0e7c 100644
---
a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.
+++ c
@@ -465,7 +465,7 @@ DumpRegisterTableOnProcessor (
case CacheControl:
DEBUG ((
DebugPrintErrorLevel,
- "Processor: %04d: Index %04d, CACHE: %08lx, Bit Start: %02d,
Bit Length: %02d, Value: %016lx\r\n",
+ "Processor: %04d: Index %04d, CACHE: %08x, Bit Start: %02d,
+ Bit Length: %02d, Value: %016lx\r\n",
ProcessorNumber,
FeatureIndex,
RegisterTableEntry->Index,
if you are already touching this DEBUG invocation, can you please fix the
rest of the issues with the format string?

- ProcessorNumber is UINTN. If we know for sure it can be represented in a
UINT32, then it should be cast to UINT32 explicitly, and logged with "%04u".
(Otherwise, UINTN needs to be cast to UINT64, and logged with %lu or %lx.)

- Ditto for FeatureIndex.
%04u or %04d is not enough for UINT32 which needs %08x.
I thought the code is just taking assumption about their value should be not > 9999u. It is not a real issue.

This patch is to fix a real issue, without it, the print for ValidBitStart, ValidBitLength and Value will be wrong because the parameter for them are shifted for Index to fetch UINT64 value.

I found another real issue is MMIO : %08lx should be MMIO : %016lx as the code is on purpose to get UINT64 MMIO address.

I prefer to just handle the real issue in this patch. How do you think? 😊


Thanks,
Star


The rest of the format specifications (including the now-fixed
CPU_REGISTER_TABLE_ENTRY.Index) are OK.

Thanks
Laszlo