summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format1
-rw-r--r--cmake/clang-format.cmake7
-rw-r--r--stage1/CMakeLists.txt2
-rw-r--r--stage1/init_hw.c100
-rw-r--r--stage1/main.c35
-rw-r--r--utils/ape2elf/CMakeLists.txt2
-rw-r--r--utils/ape2elf/main.cpp67
-rw-r--r--utils/apeconsole/CMakeLists.txt2
-rw-r--r--utils/apeconsole/main.cpp63
-rw-r--r--utils/bcmflash/CMakeLists.txt2
-rw-r--r--utils/bcmflash/main.cpp280
-rw-r--r--utils/bcmregtool/CMakeLists.txt2
-rw-r--r--utils/bcmregtool/apeloader/CMakeLists.txt9
-rw-r--r--utils/bcmregtool/apeloader/main.c6
-rw-r--r--utils/bcmregtool/main.cpp371
-rw-r--r--utils/bin2c/CMakeLists.txt2
-rw-r--r--utils/bin2c/main.cpp23
-rw-r--r--utils/elf2ape/CMakeLists.txt2
-rw-r--r--utils/elf2ape/main.cpp67
19 files changed, 431 insertions, 612 deletions
diff --git a/.clang-format b/.clang-format
index df83e01..84ebe7f 100644
--- a/.clang-format
+++ b/.clang-format
@@ -19,6 +19,7 @@ AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
+ AfterCaseLabel: true
AfterClass: false
AfterControlStatement: true
AfterEnum: true
diff --git a/cmake/clang-format.cmake b/cmake/clang-format.cmake
index d92b3fd..2036e03 100644
--- a/cmake/clang-format.cmake
+++ b/cmake/clang-format.cmake
@@ -70,8 +70,11 @@ else()
set(paths )
get_target_property(sources ${target} SOURCES)
foreach(source ${sources})
- get_source_file_property(path ${source} LOCATION)
- LIST(APPEND paths ${path})
+ get_source_file_property(type ${source} LANGUAGE)
+ IF("${type}" STREQUAL "C" OR "${type}" STREQUAL "CXX")
+ get_source_file_property(path ${source} LOCATION)
+ LIST(APPEND paths ${path})
+ ENDIF()
endforeach()
format_sources(${paths})
diff --git a/stage1/CMakeLists.txt b/stage1/CMakeLists.txt
index c189ddc..75b8e9d 100644
--- a/stage1/CMakeLists.txt
+++ b/stage1/CMakeLists.txt
@@ -68,3 +68,5 @@ target_link_libraries(sim-${PROJECT_NAME} simulator)
target_link_libraries(sim-${PROJECT_NAME} NVRam MII VPD APE printf)
install(TARGETS ${PROJECT_NAME} DESTINATION fw RESOURCE)
+
+format_target_sources(${PROJECT_NAME})
diff --git a/stage1/init_hw.c b/stage1/init_hw.c
index ecff40f..3fed509 100644
--- a/stage1/init_hw.c
+++ b/stage1/init_hw.c
@@ -44,8 +44,8 @@
#include "stage1.h"
-#include <MII.h>
#include <APE.h>
+#include <MII.h>
#if CXX_SIMULATOR
#include <APE_DEVICE.h>
#else
@@ -53,8 +53,8 @@
#endif
#include <bcm5719_GEN.h>
#include <bcm5719_RXMBUF.h>
-#include <bcm5719_TXMBUF.h>
#include <bcm5719_SDBCACHE.h>
+#include <bcm5719_TXMBUF.h>
#include <types.h>
#if CXX_SIMULATOR
@@ -67,8 +67,8 @@ void *memset(void *s, int c, size_t n)
// TODO: Use the memory window to set everything.
#else
// We assume things are aligned here...
- uint32_t* buffer = s;
- for(int i = 0; i < n/4; i++)
+ uint32_t *buffer = s;
+ for (int i = 0; i < n / 4; i++)
{
buffer[i] = c;
}
@@ -76,15 +76,15 @@ void *memset(void *s, int c, size_t n)
return s;
}
-void init_mii_function0(volatile DEVICE_t* device)
+void init_mii_function0(volatile DEVICE_t *device)
{
- if(0 == DEVICE.Status.bits.FunctionNumber)
+ if (0 == DEVICE.Status.bits.FunctionNumber)
{
reportStatus(STATUS_INIT_HW, 0xf1);
// MIIPORT 0 (0x8010):0x1A |= 0x4000
MII_selectBlock(device, 0, 0x8010);
- if(0x8010 == MII_getBlock(device, 0))
+ if (0x8010 == MII_getBlock(device, 0))
{
uint16_t r1Ah_value = MII_readRegister(device, 0, (mii_reg_t)0x1A);
r1Ah_value |= 0x4000;
@@ -134,7 +134,7 @@ void init_mii_function0(volatile DEVICE_t* device)
}
}
-void init_mii(volatile DEVICE_t* device)
+void init_mii(volatile DEVICE_t *device)
{
// MII init for all functions (MIIPORT determined by function/PHY type):
// Set MII_REG_CONTROL to AUTO_NEGOTIATION_ENABLE.
@@ -152,7 +152,7 @@ void __attribute__((noinline)) zero_bss(void)
extern uint32_t _fbss[];
extern uint32_t _ebss[];
- memset(_fbss, 0, (_ebss - _fbss) * 4);
+ memset(_fbss, 0, (_ebss - _fbss) * 4);
#endif
}
@@ -161,50 +161,49 @@ void early_init_hw(void)
zero_bss();
// Zero out ram - gencom, db cache, tx/rx mbuf, others in mem map
- memset((void*)&GEN, 0, REG_GEN_SIZE);
- memset((void*)&RXMBUF, 0, REG_RXMBUF_SIZE);
- memset((void*)&TXMBUF, 0, REG_TXMBUF_SIZE);
- memset((void*)&SDBCACHE, 0, REG_SDBCACHE_SIZE);
+ memset((void *)&GEN, 0, REG_GEN_SIZE);
+ memset((void *)&RXMBUF, 0, REG_RXMBUF_SIZE);
+ memset((void *)&TXMBUF, 0, REG_TXMBUF_SIZE);
+ memset((void *)&SDBCACHE, 0, REG_SDBCACHE_SIZE);
}
-
void init_mac(NVRAMContents_t *nvram)
{
int function = DEVICE.Status.bits.FunctionNumber;
uint32_t *mac0 = nvram->info.macAddr0;
uint32_t *my_mac = mac0; // default.
DEVICE.EmacMacAddresses0High.r32 = mac0[0];
- DEVICE.EmacMacAddresses0Low.r32 = mac0[1];
+ DEVICE.EmacMacAddresses0Low.r32 = mac0[1];
uint32_t *mac1 = nvram->info.macAddr1;
- if(1 == function)
+ if (1 == function)
{
my_mac = mac1;
}
DEVICE.EmacMacAddresses1High.r32 = mac1[0];
- DEVICE.EmacMacAddresses1Low.r32 = mac1[1];
+ DEVICE.EmacMacAddresses1Low.r32 = mac1[1];
uint32_t *mac2 = nvram->info2.macAddr2;
- if(2 == function)
+ if (2 == function)
{
my_mac = mac2;
}
DEVICE.EmacMacAddresses2High.r32 = mac2[0];
- DEVICE.EmacMacAddresses2Low.r32 = mac2[1];
+ DEVICE.EmacMacAddresses2Low.r32 = mac2[1];
uint32_t *mac3 = nvram->info2.macAddr3;
- if(3 == function)
+ if (3 == function)
{
my_mac = mac3;
}
DEVICE.EmacMacAddresses3High.r32 = mac3[0];
- DEVICE.EmacMacAddresses3Low.r32 = mac3[1];
+ DEVICE.EmacMacAddresses3Low.r32 = mac3[1];
// Store mac / serial number.
DEVICE.PciSerialNumberHigh.r32 = my_mac[0];
GEN.GenMacAddrHighMbox.r32 = my_mac[0];
- DEVICE.PciSerialNumberLow.r32 = my_mac[1];
+ DEVICE.PciSerialNumberLow.r32 = my_mac[1];
GEN.GenMacAddrLowMbox.r32 = my_mac[1];
}
@@ -212,13 +211,13 @@ uint32_t translate_power_budget(uint16_t raw)
{
RegDEVICEPciPowerBudget0_t translator;
translator.r32 = 0;
- if(raw)
+ if (raw)
{
- translator.bits.BasePower = (raw) & 0xFF;
+ translator.bits.BasePower = (raw)&0xFF;
translator.bits.DataScale = DEVICE_PCI_POWER_BUDGET_0_DATA_SCALE_0_1X;
- translator.bits.PMState = ((raw) & 0x0300) >> 8;
- translator.bits.Type = ((raw) & 0x1C00) >> 10;
- translator.bits.PowerRail = ((raw) & 0xE000) >> 13;
+ translator.bits.PMState = ((raw)&0x0300) >> 8;
+ translator.bits.Type = ((raw)&0x1C00) >> 10;
+ translator.bits.PowerRail = ((raw)&0xE000) >> 13;
}
return translator.r32;
@@ -228,7 +227,7 @@ void init_power(NVRAMContents_t *nvram)
{
// PCI power dissipated / consumed
DEVICE.PciPowerConsumptionInfo.r32 = nvram->info.powerConsumed;
- DEVICE.PciPowerDissipatedInfo.r32 = nvram->info.powerDissipated;
+ DEVICE.PciPowerDissipatedInfo.r32 = nvram->info.powerDissipated;
// Power Budget
uint32_t pb_raw0 = (nvram->info.powerBudget0) & 0xffff;
@@ -250,9 +249,9 @@ void init_power(NVRAMContents_t *nvram)
DEVICE.PciPowerBudget7.r32 = translate_power_budget(pb_raw7);
}
-uint16_t nvm_get_subsystem_device(volatile DEVICE_t *device, NVRAMContents_t* nvram)
+uint16_t nvm_get_subsystem_device(volatile DEVICE_t *device, NVRAMContents_t *nvram)
{
- switch(MII_getPhy(device))
+ switch (MII_getPhy(device))
{
/* SERDES */
case DEVICE_MII_COMMUNICATION_PHY_ADDRESS_SGMII_0:
@@ -280,7 +279,7 @@ uint16_t nvm_get_subsystem_device(volatile DEVICE_t *device, NVRAMContents_t* nv
}
}
-void init_pci(volatile DEVICE_t *device, NVRAMContents_t* nvram)
+void init_pci(volatile DEVICE_t *device, NVRAMContents_t *nvram)
{
// PCI Device / Vendor ID.
RegDEVICEPciVendorDeviceId_t vendor_device;
@@ -299,38 +298,38 @@ void init_pci(volatile DEVICE_t *device, NVRAMContents_t* nvram)
// RegDEVICEPciClassCodeRevision_t partially from REG_CHIP_ID
}
-void init_gen(NVRAMContents_t* nvram)
+void init_gen(NVRAMContents_t *nvram)
{
int function = DEVICE.Status.bits.FunctionNumber;
uint32_t cfg_feature;
uint32_t cfg_hw;
uint32_t cfg_hw2;
- switch(function)
+ switch (function)
{
default:
case 0:
cfg_feature = nvram->info.func0CfgFeature;
- cfg_hw = nvram->info.func0CfgHW;
- cfg_hw2 = nvram->info2.func0CfgHW2;
+ cfg_hw = nvram->info.func0CfgHW;
+ cfg_hw2 = nvram->info2.func0CfgHW2;
break;
case 1:
cfg_feature = nvram->info.func1CfgFeature;
- cfg_hw = nvram->info.func1CfgHW;
- cfg_hw2 = nvram->info2.func1CfgHW2;
+ cfg_hw = nvram->info.func1CfgHW;
+ cfg_hw2 = nvram->info2.func1CfgHW2;
break;
case 2:
cfg_feature = nvram->info2.func2CfgFeature;
- cfg_hw = nvram->info2.func2CfgHW;
- cfg_hw2 = nvram->info2.func2CfgHW2;
+ cfg_hw = nvram->info2.func2CfgHW;
+ cfg_hw2 = nvram->info2.func2CfgHW2;
break;
case 3:
cfg_feature = nvram->info2.func3CfgFeature;
- cfg_hw = nvram->info2.func3CfgHW;
- cfg_hw2 = nvram->info2.func3CfgHW2;
+ cfg_hw = nvram->info2.func3CfgHW;
+ cfg_hw2 = nvram->info2.func3CfgHW2;
break;
}
@@ -341,7 +340,7 @@ void init_gen(NVRAMContents_t* nvram)
GEN.GenCfg5.r32 = nvram->info2.cfg5;
}
-void load_nvm_config(volatile DEVICE_t* device, NVRAMContents_t *nvram)
+void load_nvm_config(volatile DEVICE_t *device, NVRAMContents_t *nvram)
{
// Load information from NVM, set various registers + mem
@@ -351,7 +350,6 @@ void load_nvm_config(volatile DEVICE_t* device, NVRAMContents_t *nvram)
// firmware revision
// mfrDate
-
// Power
init_power(nvram);
@@ -361,7 +359,7 @@ void load_nvm_config(volatile DEVICE_t* device, NVRAMContents_t *nvram)
init_gen(nvram);
}
-void init_hw(volatile DEVICE_t* device, NVRAMContents_t *nvram)
+void init_hw(volatile DEVICE_t *device, NVRAMContents_t *nvram)
{
reportStatus(STATUS_INIT_HW, 0);
// Misc regs init
@@ -388,12 +386,12 @@ void init_hw(volatile DEVICE_t* device, NVRAMContents_t *nvram)
// Unknown stuff involving REG 0x6530, REG 0x65F4, depends on config, TODO
// Value from Talos:0x6530z 0x6530 -> 0x00000000, 0x65F4 -> 0x00000109.
-
// REG_LSO_NONLSO_BD_READ_DMA_CORRUPTION_ENABLE_CONTROL: Set BD and NonLSO
// fields to 4K.
RegDEVICELsoNonlsoBdReadDmaCorruptionEnableControl_t reglso = DEVICE.LsoNonlsoBdReadDmaCorruptionEnableControl;
reglso.bits.PCIRequestBurstLengthforBDRDMAEngine = DEVICE_LSO_NONLSO_BD_READ_DMA_CORRUPTION_ENABLE_CONTROL_PCI_REQUEST_BURST_LENGTH_FOR_BD_RDMA_ENGINE_4K;
- reglso.bits.PCIRequestBurstLengthforNonLSORDMAEngine = DEVICE_LSO_NONLSO_BD_READ_DMA_CORRUPTION_ENABLE_CONTROL_PCI_REQUEST_BURST_LENGTH_FOR_NONLSO_RDMA_ENGINE_4K;
+ reglso.bits.PCIRequestBurstLengthforNonLSORDMAEngine =
+ DEVICE_LSO_NONLSO_BD_READ_DMA_CORRUPTION_ENABLE_CONTROL_PCI_REQUEST_BURST_LENGTH_FOR_NONLSO_RDMA_ENGINE_4K;
DEVICE.LsoNonlsoBdReadDmaCorruptionEnableControl = reglso;
// Disable ECC.
@@ -456,7 +454,6 @@ void init_hw(volatile DEVICE_t* device, NVRAMContents_t *nvram)
init_mii(device);
APE_releaseLock();
-
RegDEVICEBufferManagerMode_t bmm;
bmm.r32 = 0;
bmm.bits.Enable = 1;
@@ -464,7 +461,6 @@ void init_hw(volatile DEVICE_t* device, NVRAMContents_t *nvram)
bmm.bits.ResetRXMBUFPointer = 1;
DEVICE.BufferManagerMode = bmm;
-
// Set REG_MISCELLANEOUS_LOCAL_CONTROL to AUTO_SEEPROM_ACCESS|GPIO_2_OUTPUT_ENABLE.
DEVICE.MiscellaneousLocalControl.bits.AutoSEEPROMAccess = 1;
DEVICE.MiscellaneousLocalControl.bits.GPIO2OutputEnable = 1;
@@ -472,7 +468,7 @@ void init_hw(volatile DEVICE_t* device, NVRAMContents_t *nvram)
// Setup link-aware power mode.
// The following must be performed while holding REG_MUTEX_{REQUEST,GRANT}; use bit 4.
DEVICE.MutexRequest.r32 |= (1 << 4);
- while(0 == (DEVICE.MutexGrant.r32 & (1 << 4)))
+ while (0 == (DEVICE.MutexGrant.r32 & (1 << 4)))
{
// Wait for grant.
}
@@ -482,17 +478,17 @@ void init_hw(volatile DEVICE_t* device, NVRAMContents_t *nvram)
lapmcp.r32 = 0;
lapmcp.bits.MACClockSwitch = DEVICE_LINK_AWARE_POWER_MODE_CLOCK_POLICY_MAC_CLOCK_SWITCH_6_25MHZ;
DEVICE.LinkAwarePowerModeClockPolicy = lapmcp;
- // Set REG_CPMU_CONTROL to zero or more of LINK_AWARE_POWER_MODE_ENABLE, LINK_IDLE_POWER_MODE_ENABLE, LINK_SPEED_POWER_MODE_ENABLE as desired (see NVM CfgFeature).
+ // Set REG_CPMU_CONTROL to zero or more of LINK_AWARE_POWER_MODE_ENABLE, LINK_IDLE_POWER_MODE_ENABLE, LINK_SPEED_POWER_MODE_ENABLE as desired (see NVM
+ // CfgFeature).
RegDEVICECpmuControl_t cpmu_control;
cpmu_control.r32 = 0;
- cpmu_control.bits.LinkIdlePowerModeEnable = GEN.GenCfgFeature.bits.LinkIdle;
+ cpmu_control.bits.LinkIdlePowerModeEnable = GEN.GenCfgFeature.bits.LinkIdle;
cpmu_control.bits.LinkAwarePowerModeEnable = GEN.GenCfgFeature.bits.LinkAwarePowerMode;
cpmu_control.bits.LinkSpeedPowerModeEnable = GEN.GenCfgFeature.bits.LinkSpeedPowerMode;
DEVICE.CpmuControl = cpmu_control;
// Release grant.
DEVICE.MutexGrant.r32 = (1 << 4);
-
// Mask REG_CLOCK_SPEED_OVERRIDE_POLICY__MAC_CLOCK_SPEED_OVERRIDE_ENABLE.
DEVICE.ClockSpeedOverridePolicy.bits.MACClockSpeedOverrideEnabled = 0;
diff --git a/stage1/main.c b/stage1/main.c
index d7bb4c7..f0ac7d3 100644
--- a/stage1/main.c
+++ b/stage1/main.c
@@ -50,9 +50,7 @@
#define crc_swap(__x__) (__x__) /* No swapping needed on the host */
#else
#define be32toh(__x__) (__x__)
-#define crc_swap(__x__) \
- ((((__x__)&0x000000FF) << 24) | (((__x__)&0x0000FF00) << 8) | \
- (((__x__)&0x00FF0000) >> 8) | (((__x__)&0xFF000000) >> 24))
+#define crc_swap(__x__) ((((__x__)&0x000000FF) << 24) | (((__x__)&0x0000FF00) << 8) | (((__x__)&0x00FF0000) >> 8) | (((__x__)&0xFF000000) >> 24))
#endif
#include <APE.h>
#include <NVRam.h>
@@ -87,22 +85,20 @@ void init_once(void)
void handle_printf()
{
- uint32_t buffer_size = sizeof(SHM.RcpuPrintfBuffer)/sizeof(SHM.RcpuPrintfBuffer[0]) * sizeof(uint32_t);
+ uint32_t buffer_size = sizeof(SHM.RcpuPrintfBuffer) / sizeof(SHM.RcpuPrintfBuffer[0]) * sizeof(uint32_t);
- if (SHM.RcpuWritePointer.r32 > buffer_size ||
- SHM.RcpuReadPointer.r32 > buffer_size ||
- SHM.RcpuHostReadPointer.r32 > buffer_size)
+ if (SHM.RcpuWritePointer.r32 > buffer_size || SHM.RcpuReadPointer.r32 > buffer_size || SHM.RcpuHostReadPointer.r32 > buffer_size)
{
// Print buffer has not been initialized. Exit out.
return;
}
- for(;;)
+ for (;;)
{
uint32_t cached_pointer = SHM.RcpuReadPointer.r32;
- if(cached_pointer != SHM.RcpuWritePointer.r32)
+ if (cached_pointer != SHM.RcpuWritePointer.r32)
{
- if(cached_pointer >= buffer_size)
+ if (cached_pointer >= buffer_size)
{
cached_pointer = 0;
}
@@ -116,10 +112,8 @@ void handle_printf()
SHM.RcpuReadPointer.r32 = ++cached_pointer;
}
}
-
}
-
int main()
{
#if CXX_SIMULATOR
@@ -128,10 +122,9 @@ int main()
reportStatus(STATUS_MAIN, 0);
- if(0 == DEVICE.Status.bits.FunctionNumber)
+ if (0 == DEVICE.Status.bits.FunctionNumber)
{
- em100_puts("RX Firmware v"
- STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH) "\n");
+ em100_puts("RX Firmware v" STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH) "\n");
}
#if !CXX_SIMULATOR
@@ -141,12 +134,11 @@ int main()
reportStatus(STATUS_MAIN, 1);
- if(SHM.RcpuSegSig.bits.Sig != SHM_RCPU_SEG_SIG_SIG_RCPU_MAGIC)
+ if (SHM.RcpuSegSig.bits.Sig != SHM_RCPU_SEG_SIG_SIG_RCPU_MAGIC)
{
init_once();
}
-
// Read out the NVM configuration.
NVRam_acquireLock();
NVRam_enable();
@@ -163,7 +155,6 @@ int main()
// init_hw(&DEVICE, &gNVMContents);
#endif
-
SHM.RcpuInitCount.r32 = SHM.RcpuInitCount.r32 + 1;
// Send configuration information to APE SHM.
@@ -175,7 +166,6 @@ int main()
SHM.RcpuCpmuStatus.bits.Status = (DEVICE.Status.r32 & 0xFFFF0000) >> 16;
SHM.RcpuCpmuStatus.bits.Address = SHM_RCPU_CPMU_STATUS_ADDRESS_ADDRESS;
-
// Mark it as valid.
SHM.RcpuSegSig.bits.Sig = SHM_RCPU_SEG_SIG_SIG_RCPU_MAGIC;
@@ -214,11 +204,10 @@ int main()
}
}
-
#else
- if(0 == DEVICE.Status.bits.FunctionNumber)
+ if (0 == DEVICE.Status.bits.FunctionNumber)
{
- for(;;)
+ for (;;)
{
// Handle printf from the APE.
handle_printf();
@@ -230,7 +219,7 @@ int main()
mode.r32 = 0;
mode.bits.Halt = 1;
- for(;;)
+ for (;;)
{
// Halt the CPU since we aren't doing anything.
// DEVICE.RxRiscMode.r32 = mode.r32;;
diff --git a/utils/ape2elf/CMakeLists.txt b/utils/ape2elf/CMakeLists.txt
index 069d184..e272628 100644
--- a/utils/ape2elf/CMakeLists.txt
+++ b/utils/ape2elf/CMakeLists.txt
@@ -54,4 +54,6 @@ include_directories(elfio)
simulator_add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE NVRam VPD simulator OptParse Compress elfio)
+format_target_sources(${PROJECT_NAME})
+
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/utils/ape2elf/main.cpp b/utils/ape2elf/main.cpp
index 3ce51f3..0fe1cd5 100644
--- a/utils/ape2elf/main.cpp
+++ b/utils/ape2elf/main.cpp
@@ -45,16 +45,16 @@
#include <Compress.h>
#include <NVRam.h>
#include <OptionParser.h>
+#include <arpa/inet.h>
#include <bcm5719_eeprom.h>
#include <elfio/elfio.hpp>
-#include <arpa/inet.h>
-#define ENTRYPOINT_SYMBOL "__start"
-#define VERSION_MAJOR_SYMBOL "VERSION_MAJOR"
-#define VERSION_MINOR_SYMBOL "VERSION_MINOR"
-#define VERSION_PATCH_SYMBOL "VERSION_PATCH"
-#define STACK_END_SYMBOL "_estack"
-#define THUMB_CODE_SYMBOL "$t"
+#define ENTRYPOINT_SYMBOL "__start"
+#define VERSION_MAJOR_SYMBOL "VERSION_MAJOR"
+#define VERSION_MINOR_SYMBOL "VERSION_MINOR"
+#define VERSION_PATCH_SYMBOL "VERSION_PATCH"
+#define STACK_END_SYMBOL "_estack"
+#define THUMB_CODE_SYMBOL "$t"
using namespace std;
using namespace ELFIO;
@@ -63,23 +63,18 @@ using optparse::OptionParser;
#define MAX_SIZE (1024u * 256u) /* 256KB - max NVRAM */
int main(int argc, char const *argv[])
{
- union {
- uint8_t bytes[MAX_SIZE];
- uint32_t words[MAX_SIZE / 4];
+ union
+ {
+ uint8_t bytes[MAX_SIZE];
+ uint32_t words[MAX_SIZE / 4];
APEHeader_t header;
} ape;
OptionParser parser = OptionParser().description("BCM APE to elf Utility");
- parser.add_option("-i", "--input")
- .dest("input")
- .help("Read from the input ape binary")
- .metavar("FILE");
+ parser.add_option("-i", "--input").dest("input").help("Read from the input ape binary").metavar("FILE");
- parser.add_option("-o", "--output")
- .dest("output")
- .help("Save to the specified output elf file")
- .metavar("FILE");
+ parser.add_option("-o", "--output").dest("output").help("Save to the specified output elf file").metavar("FILE");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
@@ -149,7 +144,7 @@ int main(int argc, char const *argv[])
printf("Magic: 0x%08X\n", ape.header.magic);
printf("UNK0: 0x%08X\n", ape.header.unk0);
- char name[sizeof(ape.header.name) + 1] = {0};
+ char name[sizeof(ape.header.name) + 1] = { 0 };
strncpy(name, (char *)ape.header.name, sizeof(ape.header.name));
printf("Name: %s\n", name);
printf("Version: 0x%08X (%d.%d.%d)\n", ape.header.version, version_major, version_minor, version_patch);
@@ -189,8 +184,7 @@ int main(int argc, char const *argv[])
{
printf(" crc32\n");
}
- printf(" %s\n",
- section->flags & APE_SECTION_FLAG_CODE ? "code" : "data");
+ printf(" %s\n", section->flags & APE_SECTION_FLAG_CODE ? "code" : "data");
if (section->flags & APE_SECTION_FLAG_UNK0)
{
printf(" unknown\n");
@@ -207,8 +201,7 @@ int main(int argc, char const *argv[])
inBufferSize = section->compressedSize;
outBufferPtr = (uint8_t *)malloc(section->decompressedSize);
outBufferSize = section->decompressedSize;
- out_length =
- decompress(outBufferPtr, outBufferSize, inBufferPtr, inBufferSize);
+ out_length = decompress(outBufferPtr, outBufferSize, inBufferPtr, inBufferSize);
calculated_crc = NVRam_crc(outBufferPtr, outBufferSize, 0);
printf("out_length: 0x%08zX\n", out_length);
printf("out CRC: 0x%08X\n", calculated_crc);
@@ -225,8 +218,7 @@ int main(int argc, char const *argv[])
bss_seg->set_align(0x4);
// Add data section into data segment
- bss_seg->add_section_index(bss_sec->get_index(),
- bss_sec->get_addr_align());
+ bss_seg->add_section_index(bss_sec->get_index(), bss_sec->get_addr_align());
}
else if (!(section->flags & APE_SECTION_FLAG_CODE))
{
@@ -238,8 +230,7 @@ int main(int argc, char const *argv[])
data_seg->set_align(0x4);
// Add data section into data segment
- data_seg->add_section_index(data_sec->get_index(),
- data_sec->get_addr_align());
+ data_seg->add_section_index(data_sec->get_index(), data_sec->get_addr_align());
}
else
{
@@ -251,8 +242,7 @@ int main(int argc, char const *argv[])
text_seg->set_align(0x4);
// Add code section into program segment
- text_seg->add_section_index(text_sec->get_index(),
- text_sec->get_addr_align());
+ text_seg->add_section_index(text_sec->get_index(), text_sec->get_addr_align());
}
}
@@ -287,24 +277,17 @@ int main(int argc, char const *argv[])
Elf32_Word _version_patch = stra.add_string(VERSION_PATCH_SYMBOL);
// Add symbol entry
- syma.add_symbol(_start, ape.header.entrypoint, 0, STB_GLOBAL, STT_FUNC,
- 0, text_sec->get_index());
-
- syma.add_symbol(_thumb, ape.header.entrypoint & 0xfffffffe, 0,
- STB_LOCAL, STT_OBJECT, 0, text_sec->get_index());
+ syma.add_symbol(_start, ape.header.entrypoint, 0, STB_GLOBAL, STT_FUNC, 0, text_sec->get_index());
- syma.add_symbol(_version_major, version_major, 0, STB_GLOBAL, STT_OBJECT,
- 0, text_sec->get_index());
- syma.add_symbol(_version_minor, version_minor, 0, STB_GLOBAL, STT_OBJECT,
- 0, text_sec->get_index());
- syma.add_symbol(_version_patch, version_patch, 0, STB_GLOBAL, STT_OBJECT,
- 0, text_sec->get_index());
+ syma.add_symbol(_thumb, ape.header.entrypoint & 0xfffffffe, 0, STB_LOCAL, STT_OBJECT, 0, text_sec->get_index());
+ syma.add_symbol(_version_major, version_major, 0, STB_GLOBAL, STT_OBJECT, 0, text_sec->get_index());
+ syma.add_symbol(_version_minor, version_minor, 0, STB_GLOBAL, STT_OBJECT, 0, text_sec->get_index());
+ syma.add_symbol(_version_patch, version_patch, 0, STB_GLOBAL, STT_OBJECT, 0, text_sec->get_index());
uint32_t *vectors = (uint32_t *)text_sec->get_data();
Elf32_Word index = stra.add_string(STACK_END_SYMBOL);
- syma.add_symbol(index, vectors[0], 0, STB_GLOBAL, STT_OBJECT, 0,
- data_sec->get_index());
+ syma.add_symbol(index, vectors[0], 0, STB_GLOBAL, STT_OBJECT, 0, data_sec->get_index());
// Create ELF file
writer.save(options["output"]);
diff --git a/utils/apeconsole/CMakeLists.txt b/utils/apeconsole/CMakeLists.txt
index 02ecdb6..50cf882 100644
--- a/utils/apeconsole/CMakeLists.txt
+++ b/utils/apeconsole/CMakeLists.txt
@@ -9,4 +9,6 @@ simulator_add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE APE )
target_link_libraries(${PROJECT_NAME} PRIVATE simulator OptParse elfio)
+format_target_sources(${PROJECT_NAME})
+
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/utils/apeconsole/main.cpp b/utils/apeconsole/main.cpp
index d0d11bd..64e672a 100644
--- a/utils/apeconsole/main.cpp
+++ b/utils/apeconsole/main.cpp
@@ -41,45 +41,51 @@
/// POSSIBILITY OF SUCH DAMAGE.
/// @endcond
////////////////////////////////////////////////////////////////////////////////
+#include "../NVRam/bcm5719_NVM.h"
#include "HAL.hpp"
+#include <APE.h>
+#include <APE_APE_PERI.h>
+#include <APE_NVIC.h>
+#include <OptionParser.h>
+#include <bcm5719_DEVICE.h>
+#include <bcm5719_SHM.h>
+#include <elfio/elfio.hpp>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
+#include <iostream>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <types.h>
#include <unistd.h>
-#include <OptionParser.h>
#include <vector>
-#include <string>
-#include <iostream>
-#include <APE.h>
-#include <bcm5719_SHM.h>
-#include <elfio/elfio.hpp>
-
-#include <types.h>
-#include <bcm5719_DEVICE.h>
-#include <APE_APE_PERI.h>
-#include <APE_NVIC.h>
-#include "../NVRam/bcm5719_NVM.h"
-
-#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
+#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
using namespace std;
using namespace ELFIO;
using optparse::OptionParser;
#ifdef __ppc64__
-#define BARRIER() do { asm volatile ("sync 0\neieio\n" ::: "memory"); } while(0)
+#define BARRIER() \
+ do \
+ { \
+ asm volatile("sync 0\neieio\n" ::: "memory"); \
+ } while (0)
#else
-#define BARRIER() do { asm volatile ("" ::: "memory"); } while(0)
+#define BARRIER() \
+ do \
+ { \
+ asm volatile("" ::: "memory"); \
+ } while (0)
#endif
int main(int argc, char const *argv[])
@@ -89,27 +95,24 @@ int main(int argc, char const *argv[])
parser.version(VERSION_STRING);
parser.add_option("-f", "--function")
- .dest("function")
- .type("int")
- .set_default("1")
- .metavar("FUNCTION")
- .help("Read registers from the specified pci function.");
+ .dest("function")
+ .type("int")
+ .set_default("1")
+ .metavar("FUNCTION")
+ .help("Read registers from the specified pci function.");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
-
- if(!initHAL(NULL, options.get("function")))
+ if (!initHAL(NULL, options.get("function")))
{
cerr << "Unable to locate pci device with function " << options["function"] << " for the debug console." << endl;
exit(-1);
}
- uint32_t buffer_size = sizeof(SHM.RcpuPrintfBuffer)/sizeof(SHM.RcpuPrintfBuffer[0]) * sizeof(uint32_t);
+ uint32_t buffer_size = sizeof(SHM.RcpuPrintfBuffer) / sizeof(SHM.RcpuPrintfBuffer[0]) * sizeof(uint32_t);
- if (SHM.RcpuWritePointer.r32 > buffer_size ||
- SHM.RcpuReadPointer.r32 > buffer_size ||
- SHM.RcpuHostReadPointer.r32 > buffer_size)
+ if (SHM.RcpuWritePointer.r32 > buffer_size || SHM.RcpuReadPointer.r32 > buffer_size || SHM.RcpuHostReadPointer.r32 > buffer_size)
{
// Print buffer has not been initialized or we are not function 0. Exit out.
cerr << "Unexpected value in SHM. exiting." << endl;
@@ -120,13 +123,13 @@ int main(int argc, char const *argv[])
exit(-1);
}
- for(;;)
+ for (;;)
{
BARRIER();
uint32_t cached_pointer = SHM.RcpuHostReadPointer.r32;
- if(cached_pointer != SHM.RcpuWritePointer.r32)
+ if (cached_pointer != SHM.RcpuWritePointer.r32)
{
- if(cached_pointer >= buffer_size)
+ if (cached_pointer >= buffer_size)
{
cached_pointer = 0;
}
diff --git a/utils/bcmflash/CMakeLists.txt b/utils/bcmflash/CMakeLists.txt
index e254365..38a98a8 100644
--- a/utils/bcmflash/CMakeLists.txt
+++ b/utils/bcmflash/CMakeLists.txt
@@ -8,4 +8,6 @@ set(SOURCES
simulator_add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE NVRam VPD simulator OptParse)
+format_target_sources(${PROJECT_NAME})
+
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/utils/bcmflash/main.cpp b/utils/bcmflash/main.cpp
index 553adfe..6e3f84e 100644
--- a/utils/bcmflash/main.cpp
+++ b/utils/bcmflash/main.cpp
@@ -42,43 +42,40 @@
/// @endcond
////////////////////////////////////////////////////////////////////////////////
+#include "../NVRam/bcm5719_NVM.h"
#include "HAL.hpp"
#include <NVRam.h>
+#include <OptionParser.h>
+#include <bcm5719_DEVICE.h>
#include <bcm5719_eeprom.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
+#include <fstream>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <OptionParser.h>
#include <vector>
-#include <string>
-#include <fstream>
-
-#include <bcm5719_DEVICE.h>
-#include "../NVRam/bcm5719_NVM.h"
-
-#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
+#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
using namespace std;
using optparse::OptionParser;
-
-bool save_to_file(const char* filename, void* buffer, size_t size)
+bool save_to_file(const char *filename, void *buffer, size_t size)
{
cout << "Writing to " << filename << "." << endl;
- FILE* out = fopen(filename, "w+");
- if(out)
+ FILE *out = fopen(filename, "w+");
+ if (out)
{
fwrite(buffer, size, 1, out);
fclose(out);
@@ -91,106 +88,84 @@ bool save_to_file(const char* filename, void* buffer, size_t size)
}
}
-#define NVRAM_SIZE (1024u * 256u) /* 256KB */
+#define NVRAM_SIZE (1024u * 256u) /* 256KB */
int main(int argc, char const *argv[])
{
bool extract = false;
- union {
- uint8_t bytes[NVRAM_SIZE];
- uint32_t words[NVRAM_SIZE/4];
+ union
+ {
+ uint8_t bytes[NVRAM_SIZE];
+ uint32_t words[NVRAM_SIZE / 4];
NVRAMContents_t contents;
} nvram;
uint32_t ape_length = 0;
- uint8_t* ape = NULL;
- uint32_t* ape_wd = NULL;
+ uint8_t *ape = NULL;
+ uint32_t *ape_wd = NULL;
- uint8_t* stage1 = NULL;
- uint32_t* stage1_wd = NULL;
+ uint8_t *stage1 = NULL;
+ uint32_t *stage1_wd = NULL;
OptionParser parser = OptionParser().description("BCM Flash Utility v" VERSION_STRING);
parser.version(VERSION_STRING);
parser.add_option("-t", "--target")
- .choices({"hardware", "file"})
- .dest("target")
- // .set_default("hardware")
- .help( "hardware: Use the attached physical device.\n"
- "file: Use the file specified with -i, --file\n");
+ .choices({ "hardware", "file" })
+ .dest("target")
+ // .set_default("hardware")
+ .help("hardware: Use the attached physical device.\n"
+ "file: Use the file specified with -i, --file\n");
parser.add_option("-f", "--function")
- .dest("function")
- .type("int")
- .set_default("1")
- .metavar("FUNCTION")
- .help("Read registers from the specified pci function.");
+ .dest("function")
+ .type("int")
+ .set_default("1")
+ .metavar("FUNCTION")
+ .help("Read registers from the specified pci function.");
parser.add_option("--nvm-recovery")
- .dest("recovery")
- .action("store_true")
- .set_default("0")
- .help("Recover form an incorrect NVM autodetection. Only valid with --target=hardware");
+ .dest("recovery")
+ .action("store_true")
+ .set_default("0")
+ .help("Recover form an incorrect NVM autodetection. Only valid with --target=hardware");
- parser.add_option("-i", "--file")
- .dest("filename")
- .help("Read from the specified file")
- .metavar("FILE");
+ parser.add_option("-i", "--file").dest("filename").help("Read from the specified file").metavar("FILE");
parser.add_option("-b", "--backup")
- .dest("backup")
- .metavar("TYPE")
- .help( "Backup the firmware to the specified file.\n"
- "binary: Save a raw binary copy of the firmware to firmware.fw.\n"
- "extract: Save each individual stage to <stage>.fw.\n");
-
- parser.add_option("-r", "restore")
- .dest("restore")
- .help("Update the target device to match the specified file.")
- .metavar("FILE");
-
-
- parser.add_option("-1", "--stage1")
- .dest("stage1")
- .help("Update the target with the specified stage1 image, if possible.")
- .metavar("STAGE1");
-
- parser.add_option("-a", "--ape")
- .dest("ape")
- .help("Update the target with the specified ape image, if possible.")
- .metavar("APE");
-
- parser.add_option("-u", "--unlock")
- .dest("unlock")
- .action("store_true")
- .set_default("0")
- .help("Clear all NVM locks.")
- .metavar("UNLOCK");
-
- parser.add_option("-q", "--quiet")
- .action("store_false")
- .dest("verbose")
- .set_default("1")
- .help("don't print status messages to stdout");
+ .dest("backup")
+ .metavar("TYPE")
+ .help("Backup the firmware to the specified file.\n"
+ "binary: Save a raw binary copy of the firmware to firmware.fw.\n"
+ "extract: Save each individual stage to <stage>.fw.\n");
+
+ parser.add_option("-r", "restore").dest("restore").help("Update the target device to match the specified file.").metavar("FILE");
+
+ parser.add_option("-1", "--stage1").dest("stage1").help("Update the target with the specified stage1 image, if possible.").metavar("STAGE1");
+
+ parser.add_option("-a", "--ape").dest("ape").help("Update the target with the specified ape image, if possible.").metavar("APE");
+
+ parser.add_option("-u", "--unlock").dest("unlock").action("store_true").set_default("0").help("Clear all NVM locks.").metavar("UNLOCK");
+
+ parser.add_option("-q", "--quiet").action("store_false").dest("verbose").set_default("1").help("don't print status messages to stdout");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
- if("file" == options["target"])
+ if ("file" == options["target"])
{
- if(!options.is_set("filename"))
+ if (!options.is_set("filename"))
{
cerr << "Please specify a file to use." << endl;
parser.print_help();
exit(-1);
}
-
fstream infile;
infile.open(options["filename"], fstream::in | fstream::binary);
- if(infile.is_open())
+ if (infile.is_open())
{
- infile.read((char*)nvram.bytes, NVRAM_SIZE);
+ infile.read((char *)nvram.bytes, NVRAM_SIZE);
infile.close();
}
@@ -200,9 +175,9 @@ int main(int argc, char const *argv[])
exit(-1);
}
}
- else if("hardware" == options["target"])
+ else if ("hardware" == options["target"])
{
- if(!initHAL(NULL, options.get("function")))
+ if (!initHAL(NULL, options.get("function")))
{
cerr << "Unable to locate pci device with function " << options["function"] << " for the debug console." << endl;
exit(-1);
@@ -210,7 +185,7 @@ int main(int argc, char const *argv[])
printf("ChipId: %x\n", (uint32_t)DEVICE.ChipId.r32);
- if(options.get("recovery"))
+ if (options.get("recovery"))
{
NVRam_acquireLock();
NVRam_disable();
@@ -233,8 +208,7 @@ int main(int argc, char const *argv[])
exit(0);
}
-
- if(options.get("unlock"))
+ if (options.get("unlock"))
{
NVM.SoftwareArbitration.bits.ReqClr0 = 1;
NVM.SoftwareArbitration.bits.ReqClr1 = 1;
@@ -242,7 +216,6 @@ int main(int argc, char const *argv[])
NVM.SoftwareArbitration.bits.ReqClr3 = 1;
}
-
NVRam_acquireLock();
NVRam_enable();
@@ -258,13 +231,13 @@ int main(int argc, char const *argv[])
exit(-1);
}
- if(options.is_set("restore"))
+ if (options.is_set("restore"))
{
fstream restoreFile;
restoreFile.open(options["restore"], fstream::in | fstream::binary);
- if(restoreFile.is_open())
+ if (restoreFile.is_open())
{
- restoreFile.read((char*)nvram.bytes, NVRAM_SIZE);
+ restoreFile.read((char *)nvram.bytes, NVRAM_SIZE);
restoreFile.close();
}
@@ -274,7 +247,7 @@ int main(int argc, char const *argv[])
exit(-1);
}
- if("hardware" == options["target"])
+ if ("hardware" == options["target"])
{
cout << "Restoring from " << options["restore"] << " to hardware." << endl;
NVRam_acquireLock();
@@ -294,18 +267,17 @@ int main(int argc, char const *argv[])
}
}
-
- if(options.is_set("backup"))
+ if (options.is_set("backup"))
{
- if("binary" == options["backup"])
+ if ("binary" == options["backup"])
{
// Save to file.
- if(!save_to_file("firmware.fw", nvram.bytes, NVRAM_SIZE))
+ if (!save_to_file("firmware.fw", nvram.bytes, NVRAM_SIZE))
{
exit(-1);
}
}
- else if ("extract" == options["backup"])
+ else if ("extract" == options["backup"])
{
extract = true;
}
@@ -318,7 +290,7 @@ int main(int argc, char const *argv[])
}
stage1 = &nvram.bytes[be32toh(nvram.contents.header.bootstrapOffset)];
- stage1_wd = &nvram.words[be32toh(nvram.contents.header.bootstrapOffset)/4];
+ stage1_wd = &nvram.words[be32toh(nvram.contents.header.bootstrapOffset) / 4];
size_t stage1_length = (be32toh(nvram.contents.header.bootstrapWords) * 4) - 4; // last word is CRC
uint32_t crc_word = stage1_length / 4;
@@ -326,48 +298,47 @@ int main(int argc, char const *argv[])
uint32_t expected_crc = be32toh(~NVRam_crc(stage1, stage1_length, 0xffffffff));
printf("=== stage1 ===\n");
printf("Magic: 0x%08X\n", be32toh(nvram.contents.header.magic));
- printf("Bootstrap Phys Addr: 0x%08X\n",
- be32toh(nvram.contents.header.bootstrapPhysAddr));
+ printf("Bootstrap Phys Addr: 0x%08X\n", be32toh(nvram.contents.header.bootstrapPhysAddr));
printf("Length (bytes): 0x%08zX\n", stage1_length);
printf("Offset: 0x%08lX\n", ((stage1_wd - nvram.words) * 4));
printf("Calculated CRC: 0x%08X\n", expected_crc);
printf("CRC: 0x%08X\n", be32toh(stage1_wd[crc_word]));
- if(be32toh(nvram.contents.header.magic) != BCM_NVRAM_MAGIC)
+ if (be32toh(nvram.contents.header.magic) != BCM_NVRAM_MAGIC)
{
fprintf(stderr, "Error: stage1 magic is invalid.\n");
exit(-1);
}
- if(be32toh(stage1_wd[crc_word]) != expected_crc)
+ if (be32toh(stage1_wd[crc_word]) != expected_crc)
{
fprintf(stderr, "Error: stage1 crc is invalid.\n");
// exit(-1);
}
- if(extract)
+ if (extract)
{
- if(!save_to_file("stage1.bin", stage1, stage1_length))
+ if (!save_to_file("stage1.bin", stage1, stage1_length))
{
exit(-1);
}
}
- if(options.is_set("stage1"))
+ if (options.is_set("stage1"))
{
- const char* stage1_file = options["stage1"].c_str();
+ const char *stage1_file = options["stage1"].c_str();
printf("Updating stage1 with contents of file %s\n", stage1_file);
fstream infile;
infile.open(stage1_file, fstream::in | fstream::binary | fstream::ate);
- if(infile.is_open())
+ if (infile.is_open())
{
uint32_t new_stage1_length = infile.tellg();
infile.seekg(0);
- if(new_stage1_length > stage1_length)
+ if (new_stage1_length > stage1_length)
{
cerr << "Length is longer than original, currently unable to update." << endl;
exit(-1);
@@ -375,10 +346,10 @@ int main(int argc, char const *argv[])
else
{
// Overwrite position
- infile.read((char*)stage1, new_stage1_length);
+ infile.read((char *)stage1, new_stage1_length);
infile.close();
- while(new_stage1_length < stage1_length)
+ while (new_stage1_length < stage1_length)
{
// erase remaining bytes.
stage1[new_stage1_length] = 0xFF;
@@ -395,16 +366,16 @@ int main(int argc, char const *argv[])
// TODO: update length (if changed);
- if("file" == options["target"])
+ if ("file" == options["target"])
{
// write update file.
- if(!save_to_file(options["filename"].c_str(), (char*)nvram.bytes, NVRAM_SIZE))
+ if (!save_to_file(options["filename"].c_str(), (char *)nvram.bytes, NVRAM_SIZE))
{
exit(-1);
}
}
- if("hardware" == options["target"])
+ if ("hardware" == options["target"])
{
NVRam_acquireLock();
@@ -426,35 +397,35 @@ int main(int argc, char const *argv[])
exit(0);
}
- uint32_t* stage2_wd = &stage1_wd[(crc_word + 1)]; // immediately after stage1 crc
- NVRAMStage2_t *stage2 = (NVRAMStage2_t*)stage2_wd;
+ uint32_t *stage2_wd = &stage1_wd[(crc_word + 1)]; // immediately after stage1 crc
+ NVRAMStage2_t *stage2 = (NVRAMStage2_t *)stage2_wd;
uint32_t stage2_length = be32toh(stage2->header.length); // second word is size (bytes).
- stage2_length -= 4; // length includes crc.
+ stage2_length -= 4; // length includes crc.
uint32_t stage2_crc_word = stage2_length / 4;
printf("=== stage2 ===\n");
printf("Magic: 0x%08X\n", be32toh(stage2->header.magic));
printf("Length (bytes): 0x%08X\n", stage2_length);
printf("Offset: 0x%08lX\n", ((stage2_wd - nvram.words) * 4));
- uint32_t stage2_expected_crc = be32toh(~NVRam_crc((uint8_t*)stage2->words, stage2_length, 0xffffffff));
+ uint32_t stage2_expected_crc = be32toh(~NVRam_crc((uint8_t *)stage2->words, stage2_length, 0xffffffff));
printf("Calculated CRC: 0x%08X\n", stage2_expected_crc);
printf("CRC: 0x%08X\n", be32toh(stage2->words[stage2_crc_word]));
- if(be32toh(stage2->header.magic) != BCM_NVRAM_MAGIC)
+ if (be32toh(stage2->header.magic) != BCM_NVRAM_MAGIC)
{
fprintf(stderr, "Error: stage2 magic is invalid.\n");
exit(-1);
}
- if(be32toh(stage2->words[stage2_crc_word]) != stage2_expected_crc)
+ if (be32toh(stage2->words[stage2_crc_word]) != stage2_expected_crc)
{
fprintf(stderr, "Error: stage2 crc is invalid.\n");
exit(-1);
}
- if(extract)
+ if (extract)
{
- if(!save_to_file("stage2.bin", stage2->words, stage2_length))
+ if (!save_to_file("stage2.bin", stage2->words, stage2_length))
{
exit(-1);
}
@@ -472,26 +443,24 @@ int main(int argc, char const *argv[])
uint32_t type = BCM_CODE_DIRECTORY_GET_TYPE(info);
printf("Code Address: 0x%08X\n", addr);
printf("Code Words: 0x%08X (%ld bytes)\n", length, length * sizeof(uint32_t));
- printf("Code Offset: 0x%08X\n",
- be32toh(nvram.contents.directory[i].directoryOffset));
+ printf("Code Offset: 0x%08X\n", be32toh(nvram.contents.directory[i].directoryOffset));
printf("Code CPU: 0x%02X\n", cpu);
printf("Code Type: 0x%02X\n", type);
printf("\n");
- if(BCM_CODE_DIRECTORY_ADDR_APE == addr &&
- BCM_CODE_DIRECTORY_CPU_APE == cpu) /* APE */
+ if (BCM_CODE_DIRECTORY_ADDR_APE == addr && BCM_CODE_DIRECTORY_CPU_APE == cpu) /* APE */
{
ape = &nvram.bytes[be32toh(nvram.contents.directory[i].directoryOffset)];
- ape_wd = &nvram.words[be32toh(nvram.contents.directory[i].directoryOffset)/4];
+ ape_wd = &nvram.words[be32toh(nvram.contents.directory[i].directoryOffset) / 4];
ape_length = length * sizeof(uint32_t);
}
- if(extract)
+ if (extract)
{
- uint8_t* cd_loc = &nvram.bytes[be32toh(nvram.contents.directory[i].directoryOffset)];
- char* cd_name = strdup("cdN.bin");
+ uint8_t *cd_loc = &nvram.bytes[be32toh(nvram.contents.directory[i].directoryOffset)];
+ char *cd_name = strdup("cdN.bin");
cd_name[2] = '0' + i;
- if(!save_to_file(cd_name, cd_loc, length * sizeof(uint32_t)))
+ if (!save_to_file(cd_name, cd_loc, length * sizeof(uint32_t)))
{
exit(-1);
}
@@ -500,25 +469,25 @@ int main(int argc, char const *argv[])
}
}
- if(options.is_set("ape"))
+ if (options.is_set("ape"))
{
- if(NULL == ape)
+ if (NULL == ape)
{
fprintf(stderr, "Original APE entry was not found in firmware header.");
exit(-1);
}
- const char* ape_file = options["ape"].c_str();
+ const char *ape_file = options["ape"].c_str();
printf("Updating ape with contents of file %s\n", ape_file);
fstream infile;
infile.open(ape_file, fstream::in | fstream::binary | fstream::ate);
- if(infile.is_open())
+ if (infile.is_open())
{
uint32_t new_ape_length = infile.tellg();
infile.seekg(0);
- if(new_ape_length > ape_length)
+ if (new_ape_length > ape_length)
{
cerr << "Length is longer than original, currently unable to update." << endl;
exit(-1);
@@ -526,7 +495,7 @@ int main(int argc, char const *argv[])
else
{
// Overwrite position
- infile.read((char*)ape, new_ape_length);
+ infile.read((char *)ape, new_ape_length);
infile.close();
#if 0
@@ -544,19 +513,19 @@ int main(int argc, char const *argv[])
// TODO: update length (if changed);
- if("file" == options["target"])
+ if ("file" == options["target"])
{
// write update file.
- if(!save_to_file(options["filename"].c_str(), (char*)nvram.bytes, NVRAM_SIZE))
+ if (!save_to_file(options["filename"].c_str(), (char *)nvram.bytes, NVRAM_SIZE))
{
exit(-1);
}
}
- if("hardware" == options["target"])
+ if ("hardware" == options["target"])
{
// Ensure everything is in the correct endianness.
- for(int i = 0; i < new_ape_length/4; i++)
+ for (int i = 0; i < new_ape_length / 4; i++)
{
ape_wd[i] = be32toh(ape_wd[i]);
}
@@ -581,23 +550,17 @@ int main(int argc, char const *argv[])
exit(0);
}
-
printf("\n=== Info ===\n");
- printf("Firmware Revision: 0x%04X\n",
- be16toh(nvram.contents.info.firmwareRevision));
+ printf("Firmware Revision: 0x%04X\n", be16toh(nvram.contents.info.firmwareRevision));
printf("Part Number: %s\n", nvram.contents.info.partNumber);
- printf("Part Revision: %c%c\n", nvram.contents.info.partRevision[0],
- nvram.contents.info.partRevision[1]);
+ printf("Part Revision: %c%c\n", nvram.contents.info.partRevision[0], nvram.contents.info.partRevision[1]);
printf("Vendor ID: 0x%04X\n", be16toh(nvram.contents.info.vendorID));
printf("Device ID: 0x%04X\n", be16toh(nvram.contents.info.deviceID));
- printf("Subsystem Vendor ID: 0x%04X\n",
- be16toh(nvram.contents.info.subsystemVendorID));
- printf("Subsystem Device ID: 0x%04X\n",
- be16toh(nvram.contents.info.subsystemDeviceID));
- printf("Subsystem ID: 0x%04X\n",
- be16toh(nvram.contents.info.subsystemDeviceID));
+ printf("Subsystem Vendor ID: 0x%04X\n", be16toh(nvram.contents.info.subsystemVendorID));
+ printf("Subsystem Device ID: 0x%04X\n", be16toh(nvram.contents.info.subsystemDeviceID));
+ printf("Subsystem ID: 0x%04X\n", be16toh(nvram.contents.info.subsystemDeviceID));
printf("Function 0S Subsystem ID 0x%04X\n", be16toh(nvram.contents.info2.pciSubsystemF0SERDES));
printf("Function 1S Subsystem ID 0x%04X\n", be16toh(nvram.contents.info2.pciSubsystemF1SERDES));
@@ -608,15 +571,12 @@ int main(int argc, char const *argv[])
printf("Function 2G Subsystem ID 0x%04X\n", be16toh(nvram.contents.info2.pciSubsystemF2GPHY));
printf("Function 3G Subsystem ID 0x%04X\n", be16toh(nvram.contents.info2.pciSubsystemF3GPHY));
-
printf("Shared Cfg: 0x%08X\n", be32toh(nvram.contents.info.cfgShared));
- printf("Power Dissipated: 0x%02X 0x%02X 0x%02X 0x%02X\n",
- nvram.contents.info.powerDissipatedD3, nvram.contents.info.powerDissipatedD2,
+ printf("Power Dissipated: 0x%02X 0x%02X 0x%02X 0x%02X\n", nvram.contents.info.powerDissipatedD3, nvram.contents.info.powerDissipatedD2,
nvram.contents.info.powerDissipatedD1, nvram.contents.info.powerDissipatedD0);
- printf("Power Consumed: 0x%02X 0x%02X 0x%02X 0x%02X\n",
- nvram.contents.info.powerConsumedD3, nvram.contents.info.powerConsumedD2,
+ printf("Power Consumed: 0x%02X 0x%02X 0x%02X 0x%02X\n", nvram.contents.info.powerConsumedD3, nvram.contents.info.powerConsumedD2,
nvram.contents.info.powerConsumedD1, nvram.contents.info.powerConsumedD0);
// Print out power budget (and translated values).
@@ -634,24 +594,23 @@ int main(int argc, char const *argv[])
printf("Power Budget2: 0x%04X%04X\n", pb_raw[5], pb_raw[4]);
printf("Power Budget3: 0x%04X%04X\n", pb_raw[7], pb_raw[6]);
- for(int i = 0; i < ARRAY_ELEMENTS(pb_raw); i++)
+ for (int i = 0; i < ARRAY_ELEMENTS(pb_raw); i++)
{
uint32_t raw = pb_raw[i];
RegDEVICEPciPowerBudget0_t pb0;
pb0.r32 = 0;
- if(raw)
+ if (raw)
{
pb0.bits.BasePower = raw & 0xFF;
pb0.bits.DataScale = DEVICE_PCI_POWER_BUDGET_0_DATA_SCALE_0_1X;
- pb0.bits.PMState = (raw & 0x0300) >> 8;
- pb0.bits.Type = (raw & 0x1C00) >> 10;
+ pb0.bits.PMState = (raw & 0x0300) >> 8;
+ pb0.bits.Type = (raw & 0x1C00) >> 10;
pb0.bits.PowerRail = (raw & 0xE000) >> 13;
}
printf("Translated Power Budget[%d]: 0x%08X\n", i, (uint32_t)pb0.r32);
}
-
printf("\n=== Port 0 ===\n");
printf("Subsystem ID: 0x%04X\n", be16toh(nvram.contents.info2.pciSubsystemF0GPHY));
printf("MAC: 0x%04X%08X\n", be32toh(nvram.contents.info.macAddr0[0]), be32toh(nvram.contents.info.macAddr0[1]));
@@ -684,8 +643,7 @@ int main(int argc, char const *argv[])
if (vpd_is_valid(nvram.contents.vpd.bytes, sizeof(nvram.contents.vpd)))
{
uint32_t vpd_len = sizeof(nvram.contents.vpd);
- printf("Identifier: %s\n",
- vpd_get_identifier(nvram.contents.vpd.bytes, &vpd_len));
+ printf("Identifier: %s\n", vpd_get_identifier(nvram.contents.vpd.bytes, &vpd_len));
uint8_t *resource;
int index = 0;
@@ -693,15 +651,13 @@ int main(int argc, char const *argv[])
{
vpd_len = sizeof(nvram.contents.vpd);
uint16_t name;
- resource = vpd_get_resource_by_index(nvram.contents.vpd.bytes, &vpd_len,
- &name, index);
+ resource = vpd_get_resource_by_index(nvram.contents.vpd.bytes, &vpd_len, &name, index);
if (resource)
{
char *data = (char *)malloc(vpd_len + 1);
memcpy(data, resource, vpd_len);
data[vpd_len] = 0;
- printf("[%c%c] %24s: %s\n", name & 0xff, name >> 8, vpd_get_field_name(name),
- data);
+ printf("[%c%c] %24s: %s\n", name & 0xff, name >> 8, vpd_get_field_name(name), data);
free(data);
}
index++;
diff --git a/utils/bcmregtool/CMakeLists.txt b/utils/bcmregtool/CMakeLists.txt
index db4907f..4cc2376 100644
--- a/utils/bcmregtool/CMakeLists.txt
+++ b/utils/bcmregtool/CMakeLists.txt
@@ -12,4 +12,6 @@ simulator_add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE NVRam VPD MII APE apeloader-binary NCSI Network)
target_link_libraries(${PROJECT_NAME} PRIVATE simulator OptParse elfio)
+format_target_sources(${PROJECT_NAME})
+
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/utils/bcmregtool/apeloader/CMakeLists.txt b/utils/bcmregtool/apeloader/CMakeLists.txt
index 629fb6e..84c8793 100644
--- a/utils/bcmregtool/apeloader/CMakeLists.txt
+++ b/utils/bcmregtool/apeloader/CMakeLists.txt
@@ -60,11 +60,4 @@ target_link_libraries(${PROJECT_NAME}
--defsym=VERSION_PATCH=${VERSION_PATCH})
target_compile_options(${PROJECT_NAME} PRIVATE -nodefaultlibs)
-
-# Simulator add_executable
-# simulator_add_executable(sim-${PROJECT_NAME}
- # init_hw.c
- # main.c)
-
-# target_link_libraries(sim-${PROJECT_NAME} simulator)
-# target_link_libraries(sim-${PROJECT_NAME} NVRam MII VPD APE)
+format_target_sources(${PROJECT_NAME})
diff --git a/utils/bcmregtool/apeloader/main.c b/utils/bcmregtool/apeloader/main.c
index 0fa12ca..95dcd4a 100644
--- a/utils/bcmregtool/apeloader/main.c
+++ b/utils/bcmregtool/apeloader/main.c
@@ -47,15 +47,14 @@
#include <APE_SHM2.h>
#include <APE_SHM3.h>
-void init_shm(volatile SHM_t* shm)
+void init_shm(volatile SHM_t *shm)
{
// Update shm->Sig to signal ready.
shm->SegSig.bits.Sig = SHM_SEG_SIG_SIG_LOADER;
shm->FwStatus.bits.Ready = 1;
-
}
-void handle_command(volatile SHM_t* shm)
+void handle_command(volatile SHM_t *shm)
{
uint32_t command = shm->LoaderCommand.bits.Command;
if (!command)
@@ -98,7 +97,6 @@ void handle_command(volatile SHM_t* shm)
shm->LoaderCommand.bits.Command = 0;
}
-
int __start()
{
init_shm(&SHM);
diff --git a/utils/bcmregtool/main.cpp b/utils/bcmregtool/main.cpp
index 37d7c6a..70a9adb 100644
--- a/utils/bcmregtool/main.cpp
+++ b/utils/bcmregtool/main.cpp
@@ -41,44 +41,42 @@
/// POSSIBILITY OF SUCH DAMAGE.
/// @endcond
////////////////////////////////////////////////////////////////////////////////
+#include "../NVRam/bcm5719_NVM.h"
#include "HAL.hpp"
-#include <NVRam.h>
+#include <APE.h>
+#include <APE_APE_PERI.h>
+#include <APE_DEVICE.h>
+#include <APE_NVIC.h>
#include <MII.h>
+#include <NVRam.h>
+#include <OptionParser.h>
+#include <bcm5719_APE.h>
+#include <bcm5719_GEN.h>
+#include <bcm5719_SHM.h>
+#include <bcm5719_SHM_CHANNEL0.h>
+#include <bcm5719_SHM_CHANNEL1.h>
#include <bcm5719_eeprom.h>
#include <dirent.h>
+#include <elfio/elfio.hpp>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
+#include <iostream>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <types.h>
#include <unistd.h>
-#include <OptionParser.h>
#include <vector>
-#include <string>
-#include <iostream>
-#include <bcm5719_GEN.h>
-#include <APE.h>
-#include <bcm5719_SHM.h>
-#include <bcm5719_SHM_CHANNEL0.h>
-#include <bcm5719_SHM_CHANNEL1.h>
-#include <elfio/elfio.hpp>
-#include <types.h>
-#include <APE_DEVICE.h>
-#include <bcm5719_APE.h>
-#include <APE_APE_PERI.h>
-#include <APE_NVIC.h>
-
-#include "../NVRam/bcm5719_NVM.h"
-
-#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
+#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
using namespace std;
using namespace ELFIO;
@@ -86,27 +84,26 @@ using optparse::OptionParser;
elfio gELFIOReader;
-const char* regnames[32] = {
- "$zero", /* Zero register - always 0 */
- "$at", /* Assembler register */
- "$v0", "$v1", /* Results */
- "$a0", "$a1", "$a2", "$a3", /* Aguments */
- "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", /* Temp, not saved */
- "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", /* Saved registers */
- "$t8", "$t9", /* Temp, not saved */
- "$k0", "$k1", /* Kernel / OS */
- "$gp", "$sp", "$fp", /* Pointers */
- "$ra", /* return address */
+const char *regnames[32] = {
+ "$zero", /* Zero register - always 0 */
+ "$at", /* Assembler register */
+ "$v0", "$v1", /* Results */
+ "$a0", "$a1", "$a2", "$a3", /* Aguments */
+ "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", /* Temp, not saved */
+ "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", /* Saved registers */
+ "$t8", "$t9", /* Temp, not saved */
+ "$k0", "$k1", /* Kernel / OS */
+ "$gp", "$sp", "$fp", /* Pointers */
+ "$ra", /* return address */
};
-
void boot_ape_loader()
{
extern unsigned char apeloader_bin[];
extern unsigned int apeloader_bin_len;
int function = DEVICE.Status.bits.FunctionNumber;
- int numWords = apeloader_bin_len/4;
+ int numWords = apeloader_bin_len / 4;
RegAPEMode_t mode;
mode.r32 = 0;
@@ -116,18 +113,16 @@ void boot_ape_loader()
// We hijack the complete SHM here.
-
// load file.
- for(int i = 0; i < numWords; i++)
+ for (int i = 0; i < numWords; i++)
{
- SHM.write(0x0B00 + i*4, ((uint32_t*)apeloader_bin)[i]);
+ SHM.write(0x0B00 + i * 4, ((uint32_t *)apeloader_bin)[i]);
}
-
// Mark fw as not read.
SHM.FwStatus.bits.Ready = 0;
// Start the file
- APE.GpioMessage.r32 = 0x60220B00|2 + (0x1000 * function);
+ APE.GpioMessage.r32 = 0x60220B00 | 2 + (0x1000 * function);
mode.bits.Halt = 0;
mode.bits.FastBoot = 1;
@@ -135,7 +130,8 @@ void boot_ape_loader()
APE.Mode = mode;
// Wait for ready.
- while(0 == SHM.FwStatus.bits.Ready);
+ while (0 == SHM.FwStatus.bits.Ready)
+ ;
}
uint32_t loader_read_mem(uint32_t addr)
@@ -144,7 +140,8 @@ uint32_t loader_read_mem(uint32_t addr)
SHM.LoaderCommand.bits.Command = SHM_LOADER_COMMAND_COMMAND_READ_MEM;
// Wait for command to be handled.
- while(0 != SHM.LoaderCommand.bits.Command);
+ while (0 != SHM.LoaderCommand.bits.Command)
+ ;
return (uint32_t)SHM.LoaderArg0.r32;
}
@@ -156,33 +153,35 @@ void loader_write_mem(uint32_t addr, uint32_t value)
SHM.LoaderCommand.bits.Command = SHM_LOADER_COMMAND_COMMAND_WRITE_MEM;
// Wait for command to be handled.
- while(0 != SHM.LoaderCommand.bits.Command);
+ while (0 != SHM.LoaderCommand.bits.Command)
+ ;
}
const string symbol_for_address(uint32_t address, uint32_t &offset)
{
Elf_Half sec_num = gELFIOReader.sections.size();
- for ( int i = 0; i < sec_num; ++i ) {
- section* psec = gELFIOReader.sections[i];
+ for (int i = 0; i < sec_num; ++i)
+ {
+ section *psec = gELFIOReader.sections[i];
// Check section type
- if ( psec->get_type() == SHT_SYMTAB ) {
- const symbol_section_accessor symbols( gELFIOReader, psec );
- for ( unsigned int j = 0; j < symbols.get_symbols_num(); ++j ) {
- std::string name;
- Elf64_Addr value;
- Elf_Xword size;
+ if (psec->get_type() == SHT_SYMTAB)
+ {
+ const symbol_section_accessor symbols(gELFIOReader, psec);
+ for (unsigned int j = 0; j < symbols.get_symbols_num(); ++j)
+ {
+ std::string name;
+ Elf64_Addr value;
+ Elf_Xword size;
unsigned char bind;
unsigned char type;
- Elf_Half section_index;
+ Elf_Half section_index;
unsigned char other;
// Read symbol properties
- if(symbols.get_symbol( j, name, value, size, bind,
- type, section_index, other ))
+ if (symbols.get_symbol(j, name, value, size, bind, type, section_index, other))
{
- if(value <= address &&
- value + size > address)
+ if (value <= address && value + size > address)
{
offset = address - value;
return name;
@@ -243,11 +242,11 @@ void print_context(void)
printf(" pc: 0x%08X (%s+%d) opcode: 0x%08X \n", pc, symbol.c_str(), sym_offset, opcode);
int numCols = 4;
int offset = 32 / numCols;
- for(int i = 0; i < ARRAY_ELEMENTS(r)/4; i++)
+ for (int i = 0; i < ARRAY_ELEMENTS(r) / 4; i++)
{
- for(int j = 0; j < numCols; j++)
+ for (int j = 0; j < numCols; j++)
{
- printf("$%d(%5s): 0x%08X ", i + j*offset, regnames[i + j*offset], r[i + j*offset]);
+ printf("$%d(%5s): 0x%08X ", i + j * offset, regnames[i + j * offset], r[i + j * offset]);
}
printf("\n");
}
@@ -273,7 +272,6 @@ void writeMemory(uint32_t rxAddr, uint32_t value)
// break if the ROM is different.
DEVICE.RxRiscProgramCounter.r32 = 0x40000038;
-
cout << "PC is now " << (uint32_t)DEVICE.RxRiscProgramCounter.r32 << endl;
uint32_t iw = DEVICE.RxRiscCurrentInstruction.r32;
if (iw != 0xADCF0000)
@@ -318,7 +316,7 @@ void step(void)
// Force a re-load of the next word.
uint32_t newPC = DEVICE.RxRiscProgramCounter.r32;
- if(oldPC + 4 != newPC)
+ if (oldPC + 4 != newPC)
{
// branched. Re-read PC to re-read opcode
DEVICE.RxRiscProgramCounter.r32 = DEVICE.RxRiscProgramCounter.r32;
@@ -331,175 +329,98 @@ int main(int argc, char const *argv[])
parser.version(VERSION_STRING);
- parser.add_option("--elf")
- .dest("debugfile")
- .metavar("DEBUG_FILE")
- .help("Elf file used for improved context decoding.");
+ parser.add_option("--elf").dest("debugfile").metavar("DEBUG_FILE").help("Elf file used for improved context decoding.");
parser.add_option("-f", "--function")
- .dest("function")
- .type("int")
- .set_default("0")
- .metavar("FUNCTION")
- .help("Read registers from the specified pci function.");
-
- parser.add_option("-s", "--step")
- .dest("step")
- .set_default("0")
- .action("store_true")
- .help("Single step the CPU.");
-
- parser.add_option("-t", "--stepto")
- .dest("stepto")
- .metavar("ADDR")
- .help("Single step the CPU.");
-
- parser.add_option("--halt")
- .dest("halt")
- .set_default("0")
- .action("store_true")
- .help("Halt the CPU.");
-
- parser.add_option("-pc", "--pc")
- .dest("pc")
- .help("Force the PC to the specified value.");
-
- parser.add_option("-c", "--context")
- .dest("context")
- .set_default("0")
- .action("store_true")
- .help("Print the current CPU context.");
-
- parser.add_option("-g", "--run")
- .dest("run")
- .set_default("0")
- .action("store_true")
- .help("Continue CPU execution.");
-
- parser.add_option("-i", "--info")
- .dest("info")
- .set_default("0")
- .action("store_true")
- .help("Print device information registers.");
-
- parser.add_option("-a", "--ape")
- .dest("ape")
- .set_default("0")
- .action("store_true")
- .help("Print ape information registers.");
-
- parser.add_option("-rx", "--rx")
- .dest("rx")
- .set_default("0")
- .action("store_true")
- .help("Print rx information registers.");
-
- parser.add_option("-tx", "--tx")
- .dest("tx")
- .set_default("0")
- .action("store_true")
- .help("Print tx information registers.");
-
- parser.add_option("-p", "--apeboot")
- .dest("apeboot")
- .metavar("APE_FILE")
- .help("File to boot on the APE.");
-
- parser.add_option("--apehalt")
- .dest("apehalt")
- .set_default("0")
- .action("store_true")
- .help("Halt the APE.");
-
- parser.add_option("-n", "--network")
- .dest("network")
- .set_default("0")
- .action("store_true")
- .help("Print network information / status.");
-
- parser.add_option("--nvm")
- .dest("nvm")
- .set_default("0")
- .action("store_true")
- .help("Print NVM registers");
-
- parser.add_option("--unlock")
- .dest("unlock")
- .set_default("0")
- .action("store_true")
- .help("Unlock NVM and APE registers");
-
- parser.add_option("-apereset", "--apereset")
- .dest("apereset")
- .set_default("0")
- .action("store_true")
- .help("File to boot on the APE.");
-
- parser.add_option("-reset", "--reset")
- .dest("reset")
- .set_default("0")
- .action("store_true")
- .help("File to boot on the APE.");
-
- parser.add_option("-m", "--mii")
- .dest("mii")
- .set_default("0")
- .action("store_true")
- .help("Print MII information registers.");
-
- parser.add_option("-d", "--dumpregs")
- .dest("dumpregs")
- .set_default("0")
- .action("store_true")
- .help("Dump main device and APE registers.");
+ .dest("function")
+ .type("int")
+ .set_default("0")
+ .metavar("FUNCTION")
+ .help("Read registers from the specified pci function.");
+
+ parser.add_option("-s", "--step").dest("step").set_default("0").action("store_true").help("Single step the CPU.");
+
+ parser.add_option("-t", "--stepto").dest("stepto").metavar("ADDR").help("Single step the CPU.");
+
+ parser.add_option("--halt").dest("halt").set_default("0").action("store_true").help("Halt the CPU.");
+
+ parser.add_option("-pc", "--pc").dest("pc").help("Force the PC to the specified value.");
+
+ parser.add_option("-c", "--context").dest("context").set_default("0").action("store_true").help("Print the current CPU context.");
+
+ parser.add_option("-g", "--run").dest("run").set_default("0").action("store_true").help("Continue CPU execution.");
+
+ parser.add_option("-i", "--info").dest("info").set_default("0").action("store_true").help("Print device information registers.");
+
+ parser.add_option("-a", "--ape").dest("ape").set_default("0").action("store_true").help("Print ape information registers.");
+
+ parser.add_option("-rx", "--rx").dest("rx").set_default("0").action("store_true").help("Print rx information registers.");
+
+ parser.add_option("-tx", "--tx").dest("tx").set_default("0").action("store_true").help("Print tx information registers.");
+
+ parser.add_option("-p", "--apeboot").dest("apeboot").metavar("APE_FILE").help("File to boot on the APE.");
+
+ parser.add_option("--apehalt").dest("apehalt").set_default("0").action("store_true").help("Halt the APE.");
+
+ parser.add_option("-n", "--network").dest("network").set_default("0").action("store_true").help("Print network information / status.");
+
+ parser.add_option("--nvm").dest("nvm").set_default("0").action("store_true").help("Print NVM registers");
+
+ parser.add_option("--unlock").dest("unlock").set_default("0").action("store_true").help("Unlock NVM and APE registers");
+
+ parser.add_option("-apereset", "--apereset").dest("apereset").set_default("0").action("store_true").help("File to boot on the APE.");
+
+ parser.add_option("-reset", "--reset").dest("reset").set_default("0").action("store_true").help("File to boot on the APE.");
+
+ parser.add_option("-m", "--mii").dest("mii").set_default("0").action("store_true").help("Print MII information registers.");
+
+ parser.add_option("-d", "--dumpregs").dest("dumpregs").set_default("0").action("store_true").help("Dump main device and APE registers.");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
-
- if(!initHAL(NULL, options.get("function")))
+ if (!initHAL(NULL, options.get("function")))
{
cerr << "Unable to locate pci device with function " << (int)options.get("function") << endl;
exit(-1);
}
- if(options.is_set("debugfile"))
+ if (options.is_set("debugfile"))
{
- if(!gELFIOReader.load(options["debugfile"]))
+ if (!gELFIOReader.load(options["debugfile"]))
{
cerr << "Unablt to read elf file " << options["debugfile"] << endl;
exit(-1);
}
}
- if(options.get("step"))
+ if (options.get("step"))
{
- do {
+ do
+ {
cout << "Stepping...\n";
step();
print_context();
- } while(DEVICE.RxRiscProgramCounter.r32 > 0x40000000);
+ } while (DEVICE.RxRiscProgramCounter.r32 > 0x40000000);
exit(0);
}
- if(options.is_set("stepto"))
+ if (options.is_set("stepto"))
{
uint32_t addr = stoi(options["stepto"], nullptr, 0);
- do {
+ do
+ {
cout << "Stepping...\n";
step();
print_context();
- } while(DEVICE.RxRiscProgramCounter.r32 != addr);
+ } while (DEVICE.RxRiscProgramCounter.r32 != addr);
exit(0);
-
}
-
-
- if(options.get("halt"))
+ if (options.get("halt"))
{
cout << "Halting...\n";
RegDEVICERxRiscMode_t mode;
@@ -511,7 +432,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.is_set("pc"))
+ if (options.is_set("pc"))
{
uint32_t pc = stoi(options["pc"], nullptr, 0);
cout << "Updating PC to " << std::hex << pc << endl;
@@ -525,13 +446,13 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("context"))
+ if (options.get("context"))
{
print_context();
exit(0);
}
- if(options.get("run"))
+ if (options.get("run"))
{
cout << "Running...\n";
RegDEVICERxRiscMode_t mode;
@@ -540,7 +461,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("mii"))
+ if (options.get("mii"))
{
uint8_t phy = MII_getPhy(&DEVICE);
@@ -548,7 +469,6 @@ int main(int argc, char const *argv[])
printf("MII PHY ID[high]: 0x%04X\n", MII_readRegister(&DEVICE, phy, (mii_reg_t)REG_MII_PHY_ID_HIGH));
printf("MII PHY ID[low]: 0x%04X\n", MII_readRegister(&DEVICE, phy, (mii_reg_t)REG_MII_PHY_ID_LOW));
-
RegMIIControl_t control;
control.r16 = MII_readRegister(&DEVICE, phy, (mii_reg_t)REG_MII_CONTROL);
control.print();
@@ -620,24 +540,25 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.is_set("apeboot"))
+ if (options.is_set("apeboot"))
{
boot_ape_loader();
int fileLength = 0;
int fileWords = 0;
- #define NVRAM_SIZE (1024u * 256u) /* 256KB */
+#define NVRAM_SIZE (1024u * 256u) /* 256KB */
- union {
- uint8_t bytes[NVRAM_SIZE];
- uint32_t words[NVRAM_SIZE/4];
+ union
+ {
+ uint8_t bytes[NVRAM_SIZE];
+ uint32_t words[NVRAM_SIZE / 4];
} ape;
string &file = options["apeboot"];
fstream infile;
infile.open(file, fstream::in | fstream::binary);
- if(infile.is_open())
+ if (infile.is_open())
{
// get length of file:
infile.seekg(0, infile.end);
@@ -646,7 +567,7 @@ int main(int argc, char const *argv[])
infile.seekg(0, infile.beg);
// Read in file
- infile.read((char*)ape.bytes, fileLength);
+ infile.read((char *)ape.bytes, fileLength);
infile.close();
}
@@ -656,33 +577,30 @@ int main(int argc, char const *argv[])
exit(-1);
}
- if(ape.words[0] == be32toh(APE_HEADER_MAGIC))
+ if (ape.words[0] == be32toh(APE_HEADER_MAGIC))
{
// The file is swapped... fix it.
- for(int i = 0; i < sizeof(ape)/sizeof(ape.words[0]); i++)
+ for (int i = 0; i < sizeof(ape) / sizeof(ape.words[0]); i++)
{
ape.words[i] = be32toh(ape.words[i]);
}
}
-
// load file.
- for(int i = 0; i < fileWords; i++)
+ for (int i = 0; i < fileWords; i++)
{
- uint32_t addr = 0x10D800 + i*4;
+ uint32_t addr = 0x10D800 + i * 4;
loader_write_mem(addr, ape.words[i]);
}
-
RegAPEMode_t mode;
mode.r32 = 0;
mode.bits.Halt = 1;
mode.bits.FastBoot = 1;
APE.Mode = mode;
-
// Set the payload address
- APE.GpioMessage.r32 = 0x10D800|2;
+ APE.GpioMessage.r32 = 0x10D800 | 2;
// Clear the signature.
SHM.SegSig.r32 = 0xBAD0C0DE;
@@ -696,7 +614,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("apereset"))
+ if (options.get("apereset"))
{
// Halt
@@ -715,7 +633,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("apehalt"))
+ if (options.get("apehalt"))
{
// Halt
RegAPEMode_t mode;
@@ -726,16 +644,14 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("reset"))
+ if (options.get("reset"))
{
DEVICE.MiscellaneousConfig.bits.GRCReset = 1;
exit(0);
}
-
-
- if(options.get("rx"))
+ if (options.get("rx"))
{
DEVICE.ReceiveMacMode.print();
DEVICE.EmacMode.print();
@@ -745,7 +661,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("tx"))
+ if (options.get("tx"))
{
DEVICE.GrcModeControl.print();
DEVICE.EmacMode.print();
@@ -757,7 +673,7 @@ int main(int argc, char const *argv[])
APE.TxToNetBufferRing0.print();
APE.TxToNetBufferReturn0.print();
APE.TxToNetDoorbellFunc0.print();
- if(APE.TxToNetDoorbellFunc0.bits.TXQueueFull)
+ if (APE.TxToNetDoorbellFunc0.bits.TXQueueFull)
{
fprintf(stderr, "TX Queue Full\n");
}
@@ -765,7 +681,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("ape"))
+ if (options.get("ape"))
{
APE.Mode.print();
APE.Status.print();
@@ -787,7 +703,6 @@ int main(int argc, char const *argv[])
printf("APE RCPU PCI Vendor/Device ID: 0x%08X\n", (uint32_t)SHM.RcpuPciVendorDeviceId.r32);
printf("APE RCPU PCI Subsystem ID: 0x%08X\n", (uint32_t)SHM.RcpuPciSubsystemId.r32);
-
DEVICE.PerfectMatch1High.print();
DEVICE.PerfectMatch1Low.print();
@@ -820,7 +735,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("dumpregs"))
+ if (options.get("dumpregs"))
{
DEVICE.print();
APE.print();
@@ -829,7 +744,7 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("unlock"))
+ if (options.get("unlock"))
{
NVRam_releaseAllLocks();
APE_releaseAllLocks();
@@ -841,14 +756,14 @@ int main(int argc, char const *argv[])
exit(0);
}
- if(options.get("nvm"))
+ if (options.get("nvm"))
{
NVM.print();
exit(0);
}
- if(options.get("network"))
+ if (options.get("network"))
{
RegMIIStatus_t stat;
@@ -857,7 +772,7 @@ int main(int argc, char const *argv[])
uint16_t status_value = MII_readRegister(&DEVICE, phy, (mii_reg_t)REG_MII_STATUS);
stat.r16 = status_value;
stat.print();
- if(stat.bits.ExtendedStatusSupported)
+ if (stat.bits.ExtendedStatusSupported)
{
RegMIIIeeeExtendedStatus_t ext_stat;
uint16_t ext_status_value = MII_readRegister(&DEVICE, phy, (mii_reg_t)REG_MII_IEEE_EXTENDED_STATUS);
@@ -870,8 +785,7 @@ int main(int argc, char const *argv[])
exit(0);
}
-
- if(options.get("info"))
+ if (options.get("info"))
{
GEN.GenDataSig.print();
GEN.GenFwMbox.print();
@@ -883,7 +797,6 @@ int main(int argc, char const *argv[])
DEVICE.PciClassCodeRevision.print();
DEVICE.Status.print();
-
// GenCfgFeature
// GenCfgHw
// GenCfgShared
diff --git a/utils/bin2c/CMakeLists.txt b/utils/bin2c/CMakeLists.txt
index bd4e965..ef931b5 100644
--- a/utils/bin2c/CMakeLists.txt
+++ b/utils/bin2c/CMakeLists.txt
@@ -53,4 +53,6 @@ simulator_add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE OptParse)
include_directories(${CMAKE_SOURCE_DIR}/include)
+format_target_sources(${PROJECT_NAME})
+
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/utils/bin2c/main.cpp b/utils/bin2c/main.cpp
index a8da108..0132139 100644
--- a/utils/bin2c/main.cpp
+++ b/utils/bin2c/main.cpp
@@ -49,13 +49,12 @@
#include <iomanip>
#include <types.h>
-#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
-
+#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
using namespace std;
using optparse::OptionParser;
-string& escape(std::string& str)
+string &escape(std::string &str)
{
std::replace(str.begin(), str.end(), ' ', '_'); // No spaces allowed
std::replace(str.begin(), str.end(), '-', '_'); // Replace -'s with _'s
@@ -65,17 +64,17 @@ string& escape(std::string& str)
std::replace(str.begin(), str.end(), '[', '_'); // Replace ['s with _'s
std::replace(str.begin(), str.end(), ']', '_'); // Replace ]'s with _'s
- while(str.find("—") != std::string::npos)
+ while (str.find("—") != std::string::npos)
{
str.replace(str.find("—"), strlen("—"), "_"); // Replace @'s with _AT_'s.
}
- while(str.find("@") != std::string::npos)
- {
+ while (str.find("@") != std::string::npos)
+ {
str.replace(str.find("@"), 1, "_AT_"); // Replace @'s with _AT_'s.
}
- while(str.find("/") != std::string::npos)
+ while (str.find("/") != std::string::npos)
{
str.replace(str.find("/"), 1, "_DIV_"); // Replace /'s with _DIV_'s.
}
@@ -91,15 +90,9 @@ int main(int argc, char const *argv[])
parser.version(VERSION_STRING);
- parser.add_option("-i", "--input")
- .dest("input")
- .help("Input binary file to convert")
- .metavar("INPUT");
+ parser.add_option("-i", "--input").dest("input").help("Input binary file to convert").metavar("INPUT");
- parser.add_option("-o", "--output")
- .dest("output")
- .help("Output header file")
- .metavar("OUTPUT");
+ parser.add_option("-o", "--output").dest("output").help("Output header file").metavar("OUTPUT");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
diff --git a/utils/elf2ape/CMakeLists.txt b/utils/elf2ape/CMakeLists.txt
index 0801380..deefdc3 100644
--- a/utils/elf2ape/CMakeLists.txt
+++ b/utils/elf2ape/CMakeLists.txt
@@ -52,4 +52,6 @@ set(SOURCES
simulator_add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE NVRam VPD simulator OptParse Compress elfio)
+format_target_sources(${PROJECT_NAME})
+
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/utils/elf2ape/main.cpp b/utils/elf2ape/main.cpp
index ce4e4fd..829b040 100644
--- a/utils/elf2ape/main.cpp
+++ b/utils/elf2ape/main.cpp
@@ -45,13 +45,12 @@
#include <Compress.h>
#include <NVRam.h>
#include <OptionParser.h>
+#include <arpa/inet.h>
#include <bcm5719_eeprom.h>
#include <elfio/elfio.hpp>
#include <types.h>
-#include <arpa/inet.h>
-
-#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
+#define VERSION_STRING STRINGIFY(VERSION_MAJOR) "." STRINGIFY(VERSION_MINOR) "." STRINGIFY(VERSION_PATCH)
using namespace ELFIO;
@@ -87,8 +86,7 @@ uint64_t get_symbol_value(const char *search, elfio &reader)
unsigned char other;
// Read symbol properties
- if(psyms->get_symbol(j, name, value, size, bind, type, section_index,
- other))
+ if (psyms->get_symbol(j, name, value, size, bind, type, section_index, other))
{
if (name == search)
{
@@ -126,7 +124,8 @@ int main(int argc, char const *argv[])
{
uint32_t byteOffset = 0;
int numSections = 0;
- union {
+ union
+ {
uint8_t bytes[MAX_SIZE];
uint32_t words[MAX_SIZE / 4];
APEHeader_t header;
@@ -136,21 +135,11 @@ int main(int argc, char const *argv[])
parser.version(VERSION_STRING);
- parser.add_option("-i", "--input")
- .dest("input")
- .help("Input elf file to convert")
- .metavar("FILE");
-
- parser.add_option("-o", "--output")
- .dest("output")
- .help("Output ape binary")
- .metavar("FILE");
+ parser.add_option("-i", "--input").dest("input").help("Input elf file to convert").metavar("FILE");
- parser.add_option("-n", "--name")
- .dest("name")
- .help("Output ape binary")
- .metavar("FILE");
+ parser.add_option("-o", "--output").dest("output").help("Output ape binary").metavar("FILE");
+ parser.add_option("-n", "--name").dest("name").help("Output ape binary").metavar("FILE");
optparse::Values options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
@@ -182,9 +171,7 @@ int main(int argc, char const *argv[])
// writer.set_machine( EM_ARM );
// Ensure that this is the correct elf type.
- if (reader.get_class() != ELFCLASS32 ||
- reader.get_encoding() != ELFDATA2LSB ||
- reader.get_machine() != EM_ARM || reader.get_type() != ET_EXEC)
+ if (reader.get_class() != ELFCLASS32 || reader.get_encoding() != ELFDATA2LSB || reader.get_machine() != EM_ARM || reader.get_type() != ET_EXEC)
{
printf("Only 32-bit little-endian arm binaries are supported\n");
return 1;
@@ -213,11 +200,8 @@ int main(int argc, char const *argv[])
for (int i = 0; i < seg_num; ++i)
{
const segment *pseg = reader.segments[i];
- std::cout << " [" << i << "] 0x" << std::hex << pseg->get_flags()
- << "\tVirt: 0x" << pseg->get_virtual_address()
- << "\tFileSize: 0x" << pseg->get_file_size() << "\tSize: 0x"
- << pseg->get_memory_size() << "\tFlags: 0x"
- << pseg->get_flags() << std::endl;
+ std::cout << " [" << i << "] 0x" << std::hex << pseg->get_flags() << "\tVirt: 0x" << pseg->get_virtual_address() << "\tFileSize: 0x"
+ << pseg->get_file_size() << "\tSize: 0x" << pseg->get_memory_size() << "\tFlags: 0x" << pseg->get_flags() << std::endl;
for (int j = 0; j < pseg->get_sections_num(); j++)
{
@@ -225,11 +209,8 @@ int main(int argc, char const *argv[])
section *psec = reader.sections[idx];
if (psec->get_flags() & SHF_ALLOC)
{
- std::cout << " [" << j << "] " << psec->get_name() << "\t"
- << psec->get_size() << "\tType: 0x"
- << psec->get_type() << "\tFlags: 0x"
- << psec->get_flags() << "\tAddr: 0x"
- << psec->get_address() << std::endl;
+ std::cout << " [" << j << "] " << psec->get_name() << "\t" << psec->get_size() << "\tType: 0x" << psec->get_type() << "\tFlags: 0x"
+ << psec->get_flags() << "\tAddr: 0x" << psec->get_address() << std::endl;
APESection_t *section = &ape.header.section[numSections++];
section->flags = 0;
@@ -238,11 +219,10 @@ int main(int argc, char const *argv[])
const char *data = psec->get_data();
if (data)
{
- uint32_t compressedSize =
- compress((uint8_t *)&ape.bytes[byteOffset],
- psec->get_size() * 2, // Output, compressed
- (const uint8_t *)data,
- psec->get_size()); // input, uncompressed
+ uint32_t compressedSize = compress((uint8_t *)&ape.bytes[byteOffset],
+ psec->get_size() * 2, // Output, compressed
+ (const uint8_t *)data,
+ psec->get_size()); // input, uncompressed
// ROund up to nearest word.
compressedSize = ((compressedSize + 3) / 4) * 4;
@@ -251,10 +231,8 @@ int main(int argc, char const *argv[])
// memcpy(&ape.bytes[byteOffset], compressed,
// section->compressedSize); byteOffset +=
// section->compressedSize;
- section->crc =
- NVRam_crc((const uint8_t *)data, psec->get_size(), 0);
- section->flags |= APE_SECTION_FLAG_CHECKSUM_IS_CRC32 |
- APE_SECTION_FLAG_COMPRESSED;
+ section->crc = NVRam_crc((const uint8_t *)data, psec->get_size(), 0);
+ section->flags |= APE_SECTION_FLAG_CHECKSUM_IS_CRC32 | APE_SECTION_FLAG_COMPRESSED;
}
else
{
@@ -279,7 +257,7 @@ int main(int argc, char const *argv[])
if (options.is_set("name"))
{
string name = options["name"];
- strncpy((char*)ape.header.name, name.c_str(), sizeof(ape.header.name));
+ strncpy((char *)ape.header.name, name.c_str(), sizeof(ape.header.name));
}
uint8_t version_major = get_symbol_value("VERSION_MAJOR", reader);
@@ -288,8 +266,7 @@ int main(int argc, char const *argv[])
ape.header.version = version_major << 24 | version_minor << 16 | htons(version_patch);
ape.header.entrypoint = get_symbol_value("__start", reader);
ape.header.unk1 = APE_HEADER_UNK1;
- ape.header.words =
- (sizeof(ape.header) + sizeof(APESection_t) * numSections) / 4;
+ ape.header.words = (sizeof(ape.header) + sizeof(APESection_t) * numSections) / 4;
ape.header.unk2 = APE_HEADER_UNK2;
ape.header.sections = numSections;
ape.header.crc = 0;
@@ -298,7 +275,7 @@ int main(int argc, char const *argv[])
printf("Magic: 0x%08X\n", ape.header.magic);
printf("UNK0: 0x%08X\n", ape.header.unk0);
- char name[sizeof(ape.header.name) + 1] = {0};
+ char name[sizeof(ape.header.name) + 1] = { 0 };
strncpy(name, (char *)ape.header.name, sizeof(ape.header.name));
printf("Name: %s\n", name);
printf("Version: 0x%08X (%d.%d.%d)\n", ape.header.version, version_major, version_minor, version_patch);
OpenPOWER on IntegriCloud