summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.jenkins.groovy1
-rw-r--r--cmake/config.cmake5
-rw-r--r--cmake/headers.cmake65
-rw-r--r--include/bcm5719-endian.h64
-rw-r--r--libs/NCSI/tests/tests.cpp2
-rw-r--r--libs/Network/CMakeLists.txt4
-rw-r--r--libs/Network/tx.c2
-rw-r--r--simulator/HAL.cpp1
-rw-r--r--stage1/init_hw.c2
-rw-r--r--stage1/main.c2
-rwxr-xr-xutils/bcmflash/CMakeLists.txt10
-rw-r--r--utils/bcmflash/create_header.c2
-rw-r--r--utils/bcmflash/main.cpp6
-rw-r--r--utils/bcmflash/nvm_blackbird.c119
-rw-r--r--utils/bcmflash/nvm_kh08p.c121
-rw-r--r--utils/bcmflash/nvm_talos2.c119
-rw-r--r--utils/bcmregtool/CMakeLists.txt2
-rw-r--r--utils/bcmregtool/main.cpp2
18 files changed, 325 insertions, 204 deletions
diff --git a/.jenkins.groovy b/.jenkins.groovy
index 97add3b..968f900 100644
--- a/.jenkins.groovy
+++ b/.jenkins.groovy
@@ -176,6 +176,7 @@ try
"fedora": { build('master', true, true, true, true) },
"ubuntu-18.04": { build('ubuntu-18.04', false, false, false, false) },
"ubuntu-20.04": { build('ubuntu-20.04', true, false, false, false) },
+ "freebsd-12": { build('freebsd-12', true, false, false, false) },
)
}
catch(e)
diff --git a/cmake/config.cmake b/cmake/config.cmake
index 8fc1e95..b22048c 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -2,7 +2,7 @@
###
### @file config.cmake
###
-### @project
+### @project
###
### @brief High level configuration
###
@@ -60,3 +60,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/arm.cmake)
# Settings for generating release packages
include(${CMAKE_CURRENT_LIST_DIR}/cpack.cmake)
+
+# Settings for ehader detection
+include(${CMAKE_CURRENT_LIST_DIR}/headers.cmake)
diff --git a/cmake/headers.cmake b/cmake/headers.cmake
new file mode 100644
index 0000000..0b8cd7c
--- /dev/null
+++ b/cmake/headers.cmake
@@ -0,0 +1,65 @@
+################################################################################
+###
+### @file headers.cmake
+###
+### @project
+###
+### @brief Header auto-detection
+###
+################################################################################
+###
+################################################################################
+###
+### @copyright Copyright (c) 2020, Evan Lojewski
+### @cond
+###
+### All rights reserved.
+###
+### Redistribution and use in source and binary forms, with or without
+### modification, are permitted provided that the following conditions are met:
+### 1. Redistributions of source code must retain the above copyright notice,
+### this list of conditions and the following disclaimer.
+### 2. Redistributions in binary form must reproduce the above copyright notice,
+### this list of conditions and the following disclaimer in the documentation
+### and/or other materials provided with the distribution.
+### 3. Neither the name of the copyright holder nor the
+### names of its contributors may be used to endorse or promote products
+### derived from this software without specific prior written permission.
+###
+################################################################################
+###
+### THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+### AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+### IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+### ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+### LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+### CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+### SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+### INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+### CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+### ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+### POSSIBILITY OF SUCH DAMAGE.
+### @endcond
+################################################################################
+
+# Import the CHECK_INCLUDE_FILES macros
+include(CheckIncludeFiles)
+CHECK_INCLUDE_FILES("endian.h" ENDIANNESS_CONFIG_HAVE_ENDIAN_H)
+CHECK_INCLUDE_FILES("sys/endian.h" ENDIANNESS_CONFIG_HAVE_SYS_ENDIAN_H)
+CHECK_INCLUDE_FILES("linux/ethtool.h" CONFIG_HAVE_LINUX_ETHTOOL_H)
+
+FUNCTION(ADD_ENDIANNESS_DEFINES TARGET)
+ IF(ENDIANNESS_CONFIG_HAVE_ENDIAN_H)
+ target_compile_definitions(${TARGET} PRIVATE "-DENDIANNESS_CONFIG_HAVE_ENDIAN_H=1")
+ ENDIF()
+
+ IF(ENDIANNESS_CONFIG_HAVE_SYS_ENDIAN_H)
+ target_compile_definitions(${TARGET} PRIVATE "-DENDIANNESS_CONFIG_HAVE_SYS_ENDIAN_H=1")
+ ENDIF()
+ENDFUNCTION()
+
+FUNCTION(ADD_ETHTOOL_DEFINES TARGET)
+ IF(CONFIG_HAVE_LINUX_ETHTOOL_H)
+ target_compile_definitions(${TARGET} PRIVATE "-DCONFIG_HAVE_LINUX_ETHTOOL_H=1")
+ ENDIF()
+ENDFUNCTION()
diff --git a/include/bcm5719-endian.h b/include/bcm5719-endian.h
new file mode 100644
index 0000000..a0cb312
--- /dev/null
+++ b/include/bcm5719-endian.h
@@ -0,0 +1,64 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// @file bcm5719-endian.h
+///
+/// @project Endianness wrapper header
+///
+/// @brief Type and macro definitions
+///
+////////////////////////////////////////////////////////////////////////////////
+///
+////////////////////////////////////////////////////////////////////////////////
+///
+/// @copyright Copyright (c) 2018-2020, Evan Lojewski
+/// @cond
+///
+/// All rights reserved.
+///
+/// Redistribution and use in source and binary forms, with or without
+/// modification, are permitted provided that the following conditions are met:
+/// 1. Redistributions of source code must retain the above copyright notice,
+/// this list of conditions and the following disclaimer.
+/// 2. Redistributions in binary form must reproduce the above copyright notice,
+/// this list of conditions and the following disclaimer in the documentation
+/// and/or other materials provided with the distribution.
+/// 3. Neither the name of the copyright holder nor the
+/// names of its contributors may be used to endorse or promote products
+/// derived from this software without specific prior written permission.
+///
+////////////////////////////////////////////////////////////////////////////////
+///
+/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+/// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+/// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+/// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+/// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+/// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+/// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+/// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+/// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+/// POSSIBILITY OF SUCH DAMAGE.
+/// @endcond
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef BCM5719_ENDIAN_H
+#define BCM5719_ENDIAN_H
+
+#if defined(ENDIANNESS_CONFIG_HAVE_ENDIAN_H)
+#include <endian.h>
+#elif defined(ENDIANNESS_CONFIG_HAVE_SYS_ENDIAN_H)
+#include <sys/endian.h>
+#endif
+
+#ifdef __LITTLE_ENDIAN__
+#define swap32(__x__) ((((__x__)&0x000000FF) << 24) | (((__x__)&0x0000FF00) << 8) | (((__x__)&0x00FF0000) >> 8) | (((__x__)&0xFF000000) >> 24))
+#define swap16(__x__) ((((__x__)&0x00FF) << 8) | (((__x__)&0xFF00) >> 8))
+#elif __BIG_ENDIAN__
+#define swap32(__x__) (__x__)
+#define swap16(__x__) (__x__)
+#else
+#error Unknown endianness
+#endif
+
+#endif /* !BCM5719_ENDIAN_H */
diff --git a/libs/NCSI/tests/tests.cpp b/libs/NCSI/tests/tests.cpp
index 1bae4fc..0f916b2 100644
--- a/libs/NCSI/tests/tests.cpp
+++ b/libs/NCSI/tests/tests.cpp
@@ -3,7 +3,7 @@
#include <APE_APE_PERI.h>
#include <Ethernet.h>
#include <NCSI.h>
-#include <endian.h>
+#include <bcm5719-endian.h>
uint32_t *gPacket;
uint32_t gPacketLen;
diff --git a/libs/Network/CMakeLists.txt b/libs/Network/CMakeLists.txt
index b0fb993..e3c488a 100644
--- a/libs/Network/CMakeLists.txt
+++ b/libs/Network/CMakeLists.txt
@@ -2,7 +2,7 @@
###
### @file libs/Network/CMakeLists.txt
###
-### @project
+### @project
###
### @brief Network CMake file
###
@@ -67,3 +67,5 @@ target_include_directories(${PROJECT_NAME}-arm PUBLIC include)
format_target_sources(${PROJECT_NAME})
# add_subdirectory(tests)
+
+ADD_ENDIANNESS_DEFINES(${PROJECT_NAME})
diff --git a/libs/Network/tx.c b/libs/Network/tx.c
index 5c89f51..67ceaf0 100644
--- a/libs/Network/tx.c
+++ b/libs/Network/tx.c
@@ -50,7 +50,7 @@
#include <types.h>
#ifdef CXX_SIMULATOR
-#include <endian.h>
+#include <bcm5719-endian.h>
#include <stdio.h>
#else
#include <printf.h>
diff --git a/simulator/HAL.cpp b/simulator/HAL.cpp
index 5f59681..9c0f29a 100644
--- a/simulator/HAL.cpp
+++ b/simulator/HAL.cpp
@@ -55,7 +55,6 @@
#include <bcm5719_GEN.h>
#include <dirent.h>
-#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
diff --git a/stage1/init_hw.c b/stage1/init_hw.c
index 3fed509..a40bc27 100644
--- a/stage1/init_hw.c
+++ b/stage1/init_hw.c
@@ -160,11 +160,13 @@ void early_init_hw(void)
{
zero_bss();
+#if !CXX_SIMULATOR
// 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);
+#endif
}
void init_mac(NVRAMContents_t *nvram)
diff --git a/stage1/main.c b/stage1/main.c
index 00b0e2b..d3e4046 100644
--- a/stage1/main.c
+++ b/stage1/main.c
@@ -186,10 +186,8 @@ int main()
em100_puts("\n");
}
-#if !CXX_SIMULATOR
// Perform early initialization
early_init_hw();
-#endif
reportStatus(STATUS_MAIN, 1);
diff --git a/utils/bcmflash/CMakeLists.txt b/utils/bcmflash/CMakeLists.txt
index 1839968..fd41194 100755
--- a/utils/bcmflash/CMakeLists.txt
+++ b/utils/bcmflash/CMakeLists.txt
@@ -7,7 +7,6 @@ set(SOURCES
fileio.cpp
bcmflash.h
- ethtool.c ethtool.h
# Support files for initializing the firmware header
create_header.c create_header.h
@@ -16,9 +15,18 @@ set(SOURCES
nvm_kh08p.c
)
+IF(CONFIG_HAVE_LINUX_ETHTOOL_H)
+ LIST(APPEND SOURCES
+ ethtool.c ethtool.h
+ )
+ENDIF()
+
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)
+
+ADD_ENDIANNESS_DEFINES(${PROJECT_NAME})
+ADD_ETHTOOL_DEFINES(${PROJECT_NAME})
diff --git a/utils/bcmflash/create_header.c b/utils/bcmflash/create_header.c
index 5983370..133c351 100644
--- a/utils/bcmflash/create_header.c
+++ b/utils/bcmflash/create_header.c
@@ -45,8 +45,8 @@
#include "create_header.h"
#include <NVRam.h>
+#include <bcm5719-endian.h>
#include <bcm5719_eeprom.h>
-#include <endian.h>
#include <string.h>
static struct
diff --git a/utils/bcmflash/main.cpp b/utils/bcmflash/main.cpp
index 32c5916..cacf81e 100644
--- a/utils/bcmflash/main.cpp
+++ b/utils/bcmflash/main.cpp
@@ -44,14 +44,16 @@
#include "bcmflash.h"
#include "create_header.h"
+#ifdef CONFIG_HAVE_LINUX_ETHTOOL_H
#include "ethtool.h"
+#endif
#include <../bcm5719_NVM.h>
#include <NVRam.h>
#include <OptionParser.h>
+#include <bcm5719-endian.h>
#include <bcm5719_DEVICE.h>
#include <bcm5719_eeprom.h>
-#include <endian.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@@ -94,6 +96,7 @@ storage_t gStorage[] = {
.write = bcmflash_nvram_write,
.size = bcmflash_nvram_size,
},
+#ifdef ENDIANNESS_CONFIG_HAVE_LINUX_ETHTOOL_H
{
.type = "eth",
.type_help = "Use the specified network interface (tg3 driver must be loaded).",
@@ -102,6 +105,7 @@ storage_t gStorage[] = {
.write = bcmflash_ethtool_write,
.size = bcmflash_ethtool_size,
},
+#endif
{
.type = "file",
.type_help = "Use the file specified.",
diff --git a/utils/bcmflash/nvm_blackbird.c b/utils/bcmflash/nvm_blackbird.c
index dcec68a..49befcb 100644
--- a/utils/bcmflash/nvm_blackbird.c
+++ b/utils/bcmflash/nvm_blackbird.c
@@ -44,24 +44,15 @@
#include "create_header.h"
+#include <bcm5719-endian.h>
#include <bcm5719_eeprom.h>
-#ifdef __LITTLE_ENDIAN__
-#define htobe32(__x__) ((((__x__)&0x000000FF) << 24) | (((__x__)&0x0000FF00) << 8) | (((__x__)&0x00FF0000) >> 8) | (((__x__)&0xFF000000) >> 24))
-#define htobe16(__x__) ((((__x__)&0x00FF) << 8) | (((__x__)&0xFF00) >> 8))
-#elif __BIG_ENDIAN__
-#define htobe32(__x__) (__x__)
-#define htobe16(__x__) (__x__)
-#else
-#error Unknown endianness
-#endif
-
NVRAMInfo2_t gBlackbirdNVRAMInfo2 = {
- .mfr2Unk = 0, // [200] 00 00 -- Unknown, probably unused.
- .mfr2Len = htobe16(sizeof(NVRAMInfo2_t)), // [202] 00 8C -- Length of manufacturing section 2.
- .UNKNOWN0 = 0, // [204] 00 00 00 00 -- Could be reserved.
+ .mfr2Unk = 0, // [200] 00 00 -- Unknown, probably unused.
+ .mfr2Len = swap16(sizeof(NVRAMInfo2_t)), // [202] 00 8C -- Length of manufacturing section 2.
+ .UNKNOWN0 = 0, // [204] 00 00 00 00 -- Could be reserved.
- .macAddr2 = { htobe32(0x1022), htobe32(0x33445562) },
+ .macAddr2 = { swap32(0x1022), swap32(0x33445562) },
.UNKNOWN1 = 0, // [210] 0
.UNKNOWN2 = 0, // [214] 0
@@ -70,55 +61,55 @@ NVRAMInfo2_t gBlackbirdNVRAMInfo2 = {
.UNKNOWN4 = 0, // [220] 0
.UNKNOWN5 = 0, // [224] 0
- .func3PXEVLAN = htobe16(0),
- .func2PXEVLAN = htobe16(0),
-
- .pciSubsystemF1GPHY = htobe16(0x1981),
- .pciSubsystemF0GPHY = htobe16(0x1981),
- .pciSubsystemF3GPHY = htobe16(0x1981),
- .pciSubsystemF2GPHY = htobe16(0x1981),
- .pciSubsystemF1SERDES = htobe16(0x1657),
- .pciSubsystemF0SERDES = htobe16(0x1657),
- .pciSubsystemF3SERDES = htobe16(0x1657),
- .pciSubsystemF2SERDES = htobe16(0x1657),
-
- .UNKNOWN7 = 0, // [23C] 0
- .UNKNOWN8 = 0, // [240] 0
- .UNKNOWN9 = 0, // [244] 0
- .UNKNOWN10 = 0, // [248] 0
- .UNKNOWN11 = 0, // [24C] 0
- .func2CfgFeature = htobe32(0xC5C00000), // 1 [250] C5 C0 00 00 - Function 2 GEN_CFG_1E4.
- .func2CfgHW = htobe32(0x00004014), // 1 [254] 00 00 40 14 - Function 2 GEN_CFG_2.
-
- .macAddr3 = { htobe32(0x1022), htobe32(0x33445563) },
-
- .func3CfgFeature = htobe32(0xC5C00000), // 1 [260] C5 C0 00 00 - Function 3 GEN_CFG_1E4.
- .func3CfgHW = htobe32(0x00004014), // 1 [264] 00 00 40 14 - Function 3 GEN_CFG_2.
- .UNKNOWN12 = 0, // [268] 0a
- .UNKNOWN13 = 0, // [26C] 0a
- .UNKNOWN14 = 0, // [270] 0a
- .UNKNOWN15 = 0, // [274] 0a
- .func0CfgHW2 = htobe32(0x00000040), // 1 [278] 00 00 00 40 - Function 0 GEN_CFG_2A8.a
- .func1CfgHW2 = htobe32(0x00000040), // 1 [27C] 00 00 00 40 - Function 1 GEN_CFG_2A8.a
- .func2CfgHW2 = htobe32(0x00000040), // 1 [280] 00 00 00 40 - Function 2 GEN_CFG_2A8.a
- .func3CfgHW2 = htobe32(0x00000040), // 1 [284] 00 00 00 40 - Function 3 GEN_CFG_2A8.a
- .mfr2CRC = 0, // [288] 1A AC 41 A6 // could be CRC
+ .func3PXEVLAN = swap16(0),
+ .func2PXEVLAN = swap16(0),
+
+ .pciSubsystemF1GPHY = swap16(0x1981),
+ .pciSubsystemF0GPHY = swap16(0x1981),
+ .pciSubsystemF3GPHY = swap16(0x1981),
+ .pciSubsystemF2GPHY = swap16(0x1981),
+ .pciSubsystemF1SERDES = swap16(0x1657),
+ .pciSubsystemF0SERDES = swap16(0x1657),
+ .pciSubsystemF3SERDES = swap16(0x1657),
+ .pciSubsystemF2SERDES = swap16(0x1657),
+
+ .UNKNOWN7 = 0, // [23C] 0
+ .UNKNOWN8 = 0, // [240] 0
+ .UNKNOWN9 = 0, // [244] 0
+ .UNKNOWN10 = 0, // [248] 0
+ .UNKNOWN11 = 0, // [24C] 0
+ .func2CfgFeature = swap32(0xC5C00000), // 1 [250] C5 C0 00 00 - Function 2 GEN_CFG_1E4.
+ .func2CfgHW = swap32(0x00004014), // 1 [254] 00 00 40 14 - Function 2 GEN_CFG_2.
+
+ .macAddr3 = { swap32(0x1022), swap32(0x33445563) },
+
+ .func3CfgFeature = swap32(0xC5C00000), // 1 [260] C5 C0 00 00 - Function 3 GEN_CFG_1E4.
+ .func3CfgHW = swap32(0x00004014), // 1 [264] 00 00 40 14 - Function 3 GEN_CFG_2.
+ .UNKNOWN12 = 0, // [268] 0a
+ .UNKNOWN13 = 0, // [26C] 0a
+ .UNKNOWN14 = 0, // [270] 0a
+ .UNKNOWN15 = 0, // [274] 0a
+ .func0CfgHW2 = swap32(0x00000040), // 1 [278] 00 00 00 40 - Function 0 GEN_CFG_2A8.a
+ .func1CfgHW2 = swap32(0x00000040), // 1 [27C] 00 00 00 40 - Function 1 GEN_CFG_2A8.a
+ .func2CfgHW2 = swap32(0x00000040), // 1 [280] 00 00 00 40 - Function 2 GEN_CFG_2A8.a
+ .func3CfgHW2 = swap32(0x00000040), // 1 [284] 00 00 00 40 - Function 3 GEN_CFG_2A8.a
+ .mfr2CRC = 0, // [288] 1A AC 41 A6 // could be CRC
};
NVRAMInfo_t gBlackbirdNVRAMInfo = {
- .macAddr0 = { htobe32(0x1022), htobe32(0x33445560) },
+ .macAddr0 = { swap32(0x1022), swap32(0x33445560) },
.partNumber = "BCM95719",
.partRevision = { 'A', '0' },
.firmwareRevision = 0, /* Placeholder*/
.mfrData = { 0 },
.func1PXEVLAN = 0,
.func0PXEVLAN = 0,
- .deviceID = htobe16(0x1657), /*< PCI Device ID. */
- .vendorID = htobe16(0x14E4), /*< PCI Vendor ID. */
- .subsystemDeviceID = htobe16(0x1657), /*< PCI Subsystem Device ID. */
- .subsystemVendorID = htobe16(0x14E4), /*< PCI Subsystem Vendor ID. */
+ .deviceID = swap16(0x1657), /*< PCI Device ID. */
+ .vendorID = swap16(0x14E4), /*< PCI Vendor ID. */
+ .subsystemDeviceID = swap16(0x1657), /*< PCI Subsystem Device ID. */
+ .subsystemVendorID = swap16(0x14E4), /*< PCI Subsystem Vendor ID. */
- .cpuClock = htobe16(66), /*< 66MHz, Legacy */
+ .cpuClock = swap16(66), /*< 66MHz, Legacy */
.SMBusAddr = 0,
.SMBusAddrBMC = 0,
@@ -136,23 +127,23 @@ NVRAMInfo_t gBlackbirdNVRAMInfo = {
.powerConsumedD2 = 0x00, /*< Power consumed in the D2 state. The NetXtreme II family does not support the D2 state. */
.powerConsumedD3 = 0x0A, /*< Power consumed in the D3 state. Note: The data scale is hard coded at 0.1. */
- .func0CfgFeature = htobe32(0xC5C00080),
- .func0CfgHW = htobe32(0x00004014),
+ .func0CfgFeature = swap32(0xC5C00080),
+ .func0CfgHW = swap32(0x00004014),
- .macAddr1 = { htobe32(0x1022), htobe32(0x33445561) },
- .func1CfgFeature = htobe32(0xC5C00000),
- .func1CfgHW = htobe32(0x00004014),
+ .macAddr1 = { swap32(0x1022), swap32(0x33445561) },
+ .func1CfgFeature = swap32(0xC5C00000),
+ .func1CfgHW = swap32(0x00004014),
- .cfgShared = htobe32(0x00C2AA38),
- .powerBudget0 = htobe32(0x2C163C2C),
- .powerBudget1 = htobe32(0x0000230A),
+ .cfgShared = swap32(0x00C2AA38),
+ .powerBudget0 = swap32(0x2C163C2C),
+ .powerBudget1 = swap32(0x0000230A),
.serworksUse = 0,
.func1SERDESOverride = 0,
.func0SERDESOverride = 0,
.tpmNVMSize = 0,
- .macNVMSize = htobe16(4),
- .powerBudget2 = htobe32(0x00000000),
- .powerBudget3 = htobe32(0x00000000),
+ .macNVMSize = swap16(4),
+ .powerBudget2 = swap32(0x00000000),
+ .powerBudget3 = swap32(0x00000000),
.mfrCRC = 0,
};
diff --git a/utils/bcmflash/nvm_kh08p.c b/utils/bcmflash/nvm_kh08p.c
index 3deb019..3ce4e7d 100644
--- a/utils/bcmflash/nvm_kh08p.c
+++ b/utils/bcmflash/nvm_kh08p.c
@@ -44,24 +44,15 @@
#include "create_header.h"
+#include <bcm5719-endian.h>
#include <bcm5719_eeprom.h>
-#ifdef __LITTLE_ENDIAN__
-#define htobe32(__x__) ((((__x__)&0x000000FF) << 24) | (((__x__)&0x0000FF00) << 8) | (((__x__)&0x00FF0000) >> 8) | (((__x__)&0xFF000000) >> 24))
-#define htobe16(__x__) ((((__x__)&0x00FF) << 8) | (((__x__)&0xFF00) >> 8))
-#elif __BIG_ENDIAN__
-#define htobe32(__x__) (__x__)
-#define htobe16(__x__) (__x__)
-#else
-#error Unknown endianness
-#endif
-
NVRAMInfo2_t gKH08PNVRAMInfo2 = {
- .mfr2Unk = 0, // [200] 00 00 -- Unknown, probably unused.
- .mfr2Len = htobe16(sizeof(NVRAMInfo2_t)), // [202] 00 8C -- Length of manufacturing section 2.
- .UNKNOWN0 = 0, // [204] 00 00 00 00 -- Could be reserved.
+ .mfr2Unk = 0, // [200] 00 00 -- Unknown, probably unused.
+ .mfr2Len = swap16(sizeof(NVRAMInfo2_t)), // [202] 00 8C -- Length of manufacturing section 2.
+ .UNKNOWN0 = 0, // [204] 00 00 00 00 -- Could be reserved.
- .macAddr2 = { htobe32(0x1022), htobe32(0x33445568) },
+ .macAddr2 = { swap32(0x1022), swap32(0x33445568) },
.UNKNOWN1 = 0, // [210] 0
.UNKNOWN2 = 0, // [214] 0
@@ -70,55 +61,55 @@ NVRAMInfo2_t gKH08PNVRAMInfo2 = {
.UNKNOWN4 = 0, // [220] 0
.UNKNOWN5 = 0, // [224] 0
- .func3PXEVLAN = htobe16(1),
- .func2PXEVLAN = htobe16(1),
-
- .pciSubsystemF1GPHY = htobe16(0x1904),
- .pciSubsystemF0GPHY = htobe16(0x1904),
- .pciSubsystemF3GPHY = htobe16(0x1904),
- .pciSubsystemF2GPHY = htobe16(0x1904),
- .pciSubsystemF1SERDES = htobe16(0x1657),
- .pciSubsystemF0SERDES = htobe16(0x1657),
- .pciSubsystemF3SERDES = htobe16(0x1657),
- .pciSubsystemF2SERDES = htobe16(0x1657),
-
- .UNKNOWN7 = 0, // [23C] 0
- .UNKNOWN8 = 0, // [240] 0
- .UNKNOWN9 = 0, // [244] 0
- .UNKNOWN10 = 0, // [248] 0
- .UNKNOWN11 = 0, // [24C] 0
- .func2CfgFeature = htobe32(0xCDB50202), // 1 [250] C5 C0 00 00 - Function 2 GEN_CFG_1E4.
- .func2CfgHW = htobe32(0x00006014), // 1 [254] 00 00 40 14 - Function 2 GEN_CFG_2.
-
- .macAddr3 = { htobe32(0x1022), htobe32(0x33445569) },
-
- .func3CfgFeature = htobe32(0xCDB50202), // 1 [260] C5 C0 00 00 - Function 3 GEN_CFG_1E4.
- .func3CfgHW = htobe32(0x00006014), // 1 [264] 00 00 40 14 - Function 3 GEN_CFG_2.
- .UNKNOWN12 = 0, // [268] 0a
- .UNKNOWN13 = 0, // [26C] 0a
- .UNKNOWN14 = 0, // [270] 0a
- .UNKNOWN15 = 0, // [274] 0a
- .func0CfgHW2 = htobe32(0x00000042),
- .func1CfgHW2 = htobe32(0x00000042),
- .func2CfgHW2 = htobe32(0x00000042),
- .func3CfgHW2 = htobe32(0x00000042),
+ .func3PXEVLAN = swap16(1),
+ .func2PXEVLAN = swap16(1),
+
+ .pciSubsystemF1GPHY = swap16(0x1904),
+ .pciSubsystemF0GPHY = swap16(0x1904),
+ .pciSubsystemF3GPHY = swap16(0x1904),
+ .pciSubsystemF2GPHY = swap16(0x1904),
+ .pciSubsystemF1SERDES = swap16(0x1657),
+ .pciSubsystemF0SERDES = swap16(0x1657),
+ .pciSubsystemF3SERDES = swap16(0x1657),
+ .pciSubsystemF2SERDES = swap16(0x1657),
+
+ .UNKNOWN7 = 0, // [23C] 0
+ .UNKNOWN8 = 0, // [240] 0
+ .UNKNOWN9 = 0, // [244] 0
+ .UNKNOWN10 = 0, // [248] 0
+ .UNKNOWN11 = 0, // [24C] 0
+ .func2CfgFeature = swap32(0xCDB50202), // 1 [250] C5 C0 00 00 - Function 2 GEN_CFG_1E4.
+ .func2CfgHW = swap32(0x00006014), // 1 [254] 00 00 40 14 - Function 2 GEN_CFG_2.
+
+ .macAddr3 = { swap32(0x1022), swap32(0x33445569) },
+
+ .func3CfgFeature = swap32(0xCDB50202), // 1 [260] C5 C0 00 00 - Function 3 GEN_CFG_1E4.
+ .func3CfgHW = swap32(0x00006014), // 1 [264] 00 00 40 14 - Function 3 GEN_CFG_2.
+ .UNKNOWN12 = 0, // [268] 0a
+ .UNKNOWN13 = 0, // [26C] 0a
+ .UNKNOWN14 = 0, // [270] 0a
+ .UNKNOWN15 = 0, // [274] 0a
+ .func0CfgHW2 = swap32(0x00000042),
+ .func1CfgHW2 = swap32(0x00000042),
+ .func2CfgHW2 = swap32(0x00000042),
+ .func3CfgHW2 = swap32(0x00000042),
.mfr2CRC = 0, // [288] 1A AC 41 A6 // could be CRC
};
NVRAMInfo_t gKH08PNVRAMInfo = {
- .macAddr0 = { htobe32(0x1022), htobe32(0x33445566) },
+ .macAddr0 = { swap32(0x1022), swap32(0x33445566) },
.partNumber = "BCM95719",
.partRevision = { 'A', '0' },
.firmwareRevision = 0, /* Placeholder*/
.mfrData = { 0 },
- .func1PXEVLAN = htobe16(1),
- .func0PXEVLAN = htobe16(1),
- .deviceID = htobe16(0x1657), /*< PCI Device ID. */
- .vendorID = htobe16(0x14E4), /*< PCI Vendor ID. */
- .subsystemDeviceID = htobe16(0x1657), /*< PCI Subsystem Device ID. */
- .subsystemVendorID = htobe16(0x14E4), /*< PCI Subsystem Vendor ID. */
+ .func1PXEVLAN = swap16(1),
+ .func0PXEVLAN = swap16(1),
+ .deviceID = swap16(0x1657), /*< PCI Device ID. */
+ .vendorID = swap16(0x14E4), /*< PCI Vendor ID. */
+ .subsystemDeviceID = swap16(0x1657), /*< PCI Subsystem Device ID. */
+ .subsystemVendorID = swap16(0x14E4), /*< PCI Subsystem Vendor ID. */
- .cpuClock = htobe16(66), /*< 66MHz, Legacy */
+ .cpuClock = swap16(66), /*< 66MHz, Legacy */
.SMBusAddr = 0x64,
.SMBusAddrBMC = 0,
@@ -136,23 +127,23 @@ NVRAMInfo_t gKH08PNVRAMInfo = {
.powerConsumedD2 = 0x00, /*< Power consumed in the D2 state. The NetXtreme II family does not support the D2 state. */
.powerConsumedD3 = 0x0A, /*< Power consumed in the D3 state. Note: The data scale is hard coded at 0.1. */
- .func0CfgFeature = htobe32(0xCDB50282),
- .func0CfgHW = htobe32(0x00006014),
+ .func0CfgFeature = swap32(0xCDB50282),
+ .func0CfgHW = swap32(0x00006014),
- .macAddr1 = { htobe32(0x1022), htobe32(0x33445567) },
- .func1CfgFeature = htobe32(0xCDB50202),
- .func1CfgHW = htobe32(0x00006014),
+ .macAddr1 = { swap32(0x1022), swap32(0x33445567) },
+ .func1CfgFeature = swap32(0xCDB50202),
+ .func1CfgHW = swap32(0x00006014),
- .cfgShared = htobe32(0x0012AA38),
- .powerBudget0 = htobe32(0x2C163C2C),
- .powerBudget1 = htobe32(0x0000230A),
+ .cfgShared = swap32(0x0012AA38),
+ .powerBudget0 = swap32(0x2C163C2C),
+ .powerBudget1 = swap32(0x0000230A),
.serworksUse = 0,
.func1SERDESOverride = 0,
.func0SERDESOverride = 0,
.tpmNVMSize = 0,
- .macNVMSize = htobe16(2),
- .powerBudget2 = htobe32(0x00000000),
- .powerBudget3 = htobe32(0x00000000),
+ .macNVMSize = swap16(2),
+ .powerBudget2 = swap32(0x00000000),
+ .powerBudget3 = swap32(0x00000000),
.mfrCRC = 0,
};
diff --git a/utils/bcmflash/nvm_talos2.c b/utils/bcmflash/nvm_talos2.c
index c47e391..8158df4 100644
--- a/utils/bcmflash/nvm_talos2.c
+++ b/utils/bcmflash/nvm_talos2.c
@@ -44,24 +44,15 @@
#include "create_header.h"
+#include <bcm5719-endian.h>
#include <bcm5719_eeprom.h>
-#ifdef __LITTLE_ENDIAN__
-#define htobe32(__x__) ((((__x__)&0x000000FF) << 24) | (((__x__)&0x0000FF00) << 8) | (((__x__)&0x00FF0000) >> 8) | (((__x__)&0xFF000000) >> 24))
-#define htobe16(__x__) ((((__x__)&0x00FF) << 8) | (((__x__)&0xFF00) >> 8))
-#elif __BIG_ENDIAN__
-#define htobe32(__x__) (__x__)
-#define htobe16(__x__) (__x__)
-#else
-#error Unknown endianness
-#endif
-
NVRAMInfo2_t gTalosIINVRAMInfo2 = {
- .mfr2Unk = 0, // [200] 00 00 -- Unknown, probably unused.
- .mfr2Len = htobe16(sizeof(NVRAMInfo2_t)), // [202] 00 8C -- Length of manufacturing section 2.
- .UNKNOWN0 = 0, // [204] 00 00 00 00 -- Could be reserved.
+ .mfr2Unk = 0, // [200] 00 00 -- Unknown, probably unused.
+ .mfr2Len = swap16(sizeof(NVRAMInfo2_t)), // [202] 00 8C -- Length of manufacturing section 2.
+ .UNKNOWN0 = 0, // [204] 00 00 00 00 -- Could be reserved.
- .macAddr2 = { htobe32(0x1022), htobe32(0x33445572) },
+ .macAddr2 = { swap32(0x1022), swap32(0x33445572) },
.UNKNOWN1 = 0, // [210] 0
.UNKNOWN2 = 0, // [214] 0
@@ -70,55 +61,55 @@ NVRAMInfo2_t gTalosIINVRAMInfo2 = {
.UNKNOWN4 = 0, // [220] 0
.UNKNOWN5 = 0, // [224] 0
- .func3PXEVLAN = htobe16(0),
- .func2PXEVLAN = htobe16(0),
-
- .pciSubsystemF1GPHY = htobe16(0x1981),
- .pciSubsystemF0GPHY = htobe16(0x1981),
- .pciSubsystemF3GPHY = htobe16(0x1981),
- .pciSubsystemF2GPHY = htobe16(0x1981),
- .pciSubsystemF1SERDES = htobe16(0x1657),
- .pciSubsystemF0SERDES = htobe16(0x1657),
- .pciSubsystemF3SERDES = htobe16(0x1657),
- .pciSubsystemF2SERDES = htobe16(0x1657),
-
- .UNKNOWN7 = 0, // [23C] 0
- .UNKNOWN8 = 0, // [240] 0
- .UNKNOWN9 = 0, // [244] 0
- .UNKNOWN10 = 0, // [248] 0
- .UNKNOWN11 = 0, // [24C] 0
- .func2CfgFeature = htobe32(0xC5C00000), // 1 [250] C5 C0 00 00 - Function 2 GEN_CFG_1E4.
- .func2CfgHW = htobe32(0x00004014), // 1 [254] 00 00 40 14 - Function 2 GEN_CFG_2.
-
- .macAddr3 = { htobe32(0x1022), htobe32(0x33445573) },
-
- .func3CfgFeature = htobe32(0xC5C00000), // 1 [260] C5 C0 00 00 - Function 3 GEN_CFG_1E4.
- .func3CfgHW = htobe32(0x00004014), // 1 [264] 00 00 40 14 - Function 3 GEN_CFG_2.
- .UNKNOWN12 = 0, // [268] 0a
- .UNKNOWN13 = 0, // [26C] 0a
- .UNKNOWN14 = 0, // [270] 0a
- .UNKNOWN15 = 0, // [274] 0a
- .func0CfgHW2 = htobe32(0x00000040), // 1 [278] 00 00 00 40 - Function 0 GEN_CFG_2A8.a
- .func1CfgHW2 = htobe32(0x00000040), // 1 [27C] 00 00 00 40 - Function 1 GEN_CFG_2A8.a
- .func2CfgHW2 = htobe32(0x00000040), // 1 [280] 00 00 00 40 - Function 2 GEN_CFG_2A8.a
- .func3CfgHW2 = htobe32(0x00000040), // 1 [284] 00 00 00 40 - Function 3 GEN_CFG_2A8.a
- .mfr2CRC = 0, // [288] 1A AC 41 A6 // could be CRC
+ .func3PXEVLAN = swap16(0),
+ .func2PXEVLAN = swap16(0),
+
+ .pciSubsystemF1GPHY = swap16(0x1981),
+ .pciSubsystemF0GPHY = swap16(0x1981),
+ .pciSubsystemF3GPHY = swap16(0x1981),
+ .pciSubsystemF2GPHY = swap16(0x1981),
+ .pciSubsystemF1SERDES = swap16(0x1657),
+ .pciSubsystemF0SERDES = swap16(0x1657),
+ .pciSubsystemF3SERDES = swap16(0x1657),
+ .pciSubsystemF2SERDES = swap16(0x1657),
+
+ .UNKNOWN7 = 0, // [23C] 0
+ .UNKNOWN8 = 0, // [240] 0
+ .UNKNOWN9 = 0, // [244] 0
+ .UNKNOWN10 = 0, // [248] 0
+ .UNKNOWN11 = 0, // [24C] 0
+ .func2CfgFeature = swap32(0xC5C00000), // 1 [250] C5 C0 00 00 - Function 2 GEN_CFG_1E4.
+ .func2CfgHW = swap32(0x00004014), // 1 [254] 00 00 40 14 - Function 2 GEN_CFG_2.
+
+ .macAddr3 = { swap32(0x1022), swap32(0x33445573) },
+
+ .func3CfgFeature = swap32(0xC5C00000), // 1 [260] C5 C0 00 00 - Function 3 GEN_CFG_1E4.
+ .func3CfgHW = swap32(0x00004014), // 1 [264] 00 00 40 14 - Function 3 GEN_CFG_2.
+ .UNKNOWN12 = 0, // [268] 0a
+ .UNKNOWN13 = 0, // [26C] 0a
+ .UNKNOWN14 = 0, // [270] 0a
+ .UNKNOWN15 = 0, // [274] 0a
+ .func0CfgHW2 = swap32(0x00000040), // 1 [278] 00 00 00 40 - Function 0 GEN_CFG_2A8.a
+ .func1CfgHW2 = swap32(0x00000040), // 1 [27C] 00 00 00 40 - Function 1 GEN_CFG_2A8.a
+ .func2CfgHW2 = swap32(0x00000040), // 1 [280] 00 00 00 40 - Function 2 GEN_CFG_2A8.a
+ .func3CfgHW2 = swap32(0x00000040), // 1 [284] 00 00 00 40 - Function 3 GEN_CFG_2A8.a
+ .mfr2CRC = 0, // [288] 1A AC 41 A6 // could be CRC
};
NVRAMInfo_t gTalosIINVRAMInfo = {
- .macAddr0 = { htobe32(0x1022), htobe32(0x33445570) },
+ .macAddr0 = { swap32(0x1022), swap32(0x33445570) },
.partNumber = "BCM95719",
.partRevision = { 'A', '0' },
.firmwareRevision = 0, /* Placeholder*/
.mfrData = { 0 },
.func1PXEVLAN = 0,
.func0PXEVLAN = 0,
- .deviceID = htobe16(0x1657), /*< PCI Device ID. */
- .vendorID = htobe16(0x14E4), /*< PCI Vendor ID. */
- .subsystemDeviceID = htobe16(0x1657), /*< PCI Subsystem Device ID. */
- .subsystemVendorID = htobe16(0x14E4), /*< PCI Subsystem Vendor ID. */
+ .deviceID = swap16(0x1657), /*< PCI Device ID. */
+ .vendorID = swap16(0x14E4), /*< PCI Vendor ID. */
+ .subsystemDeviceID = swap16(0x1657), /*< PCI Subsystem Device ID. */
+ .subsystemVendorID = swap16(0x14E4), /*< PCI Subsystem Vendor ID. */
- .cpuClock = htobe16(66), /*< 66MHz, Legacy */
+ .cpuClock = swap16(66), /*< 66MHz, Legacy */
.SMBusAddr = 0,
.SMBusAddrBMC = 0,
@@ -136,23 +127,23 @@ NVRAMInfo_t gTalosIINVRAMInfo = {
.powerConsumedD2 = 0x00, /*< Power consumed in the D2 state. The NetXtreme II family does not support the D2 state. */
.powerConsumedD3 = 0x0A, /*< Power consumed in the D3 state. Note: The data scale is hard coded at 0.1. */
- .func0CfgFeature = htobe32(0xC5C00080),
- .func0CfgHW = htobe32(0x00004014),
+ .func0CfgFeature = swap32(0xC5C00080),
+ .func0CfgHW = swap32(0x00004014),
- .macAddr1 = { htobe32(0x1022), htobe32(0x33445571) },
- .func1CfgFeature = htobe32(0xC5C00000),
- .func1CfgHW = htobe32(0x00004014),
+ .macAddr1 = { swap32(0x1022), swap32(0x33445571) },
+ .func1CfgFeature = swap32(0xC5C00000),
+ .func1CfgHW = swap32(0x00004014),
- .cfgShared = htobe32(0x00C2AA38),
- .powerBudget0 = htobe32(0x2C163C2C),
- .powerBudget1 = htobe32(0x0000230A),
+ .cfgShared = swap32(0x00C2AA38),
+ .powerBudget0 = swap32(0x2C163C2C),
+ .powerBudget1 = swap32(0x0000230A),
.serworksUse = 0,
.func1SERDESOverride = 0,
.func0SERDESOverride = 0,
.tpmNVMSize = 0,
- .macNVMSize = htobe16(4),
- .powerBudget2 = htobe32(0x00000000),
- .powerBudget3 = htobe32(0x00000000),
+ .macNVMSize = swap16(4),
+ .powerBudget2 = swap32(0x00000000),
+ .powerBudget3 = swap32(0x00000000),
.mfrCRC = 0,
};
diff --git a/utils/bcmregtool/CMakeLists.txt b/utils/bcmregtool/CMakeLists.txt
index 4cc2376..862eb12 100644
--- a/utils/bcmregtool/CMakeLists.txt
+++ b/utils/bcmregtool/CMakeLists.txt
@@ -15,3 +15,5 @@ target_link_libraries(${PROJECT_NAME} PRIVATE simulator OptParse elfio)
format_target_sources(${PROJECT_NAME})
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+
+ADD_ENDIANNESS_DEFINES(${PROJECT_NAME})
diff --git a/utils/bcmregtool/main.cpp b/utils/bcmregtool/main.cpp
index cb273fb..a0dcb47 100644
--- a/utils/bcmregtool/main.cpp
+++ b/utils/bcmregtool/main.cpp
@@ -51,6 +51,7 @@
#include <MII.h>
#include <NVRam.h>
#include <OptionParser.h>
+#include <bcm5719-endian.h>
#include <bcm5719_APE.h>
#include <bcm5719_GEN.h>
#include <bcm5719_SHM.h>
@@ -58,7 +59,6 @@
#include <bcm5719_SHM_CHANNEL1.h>
#include <bcm5719_eeprom.h>
#include <elfio/elfio.hpp>
-#include <endian.h>
#include <iostream>
#include <stdbool.h>
#include <stdint.h>
OpenPOWER on IntegriCloud