summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Lojewski <github@meklort.com>2021-02-06 16:29:58 -0700
committerGitHub <noreply@github.com>2021-02-06 16:29:58 -0700
commita1b8330b2506ffa6a30bfc4153149b9184ea76cf (patch)
treef503723aebe715a0acd1eba2d6ba066f3fe53754
parentaf7847795c9096067c976901a6149350534ae42c (diff)
downloadbcm5719-ortega-a1b8330b2506ffa6a30bfc4153149b9184ea76cf.tar.gz
bcm5719-ortega-a1b8330b2506ffa6a30bfc4153149b9184ea76cf.zip
build: Fix a number of compiler issues when building utils with gcc. (#208)
-rw-r--r--libs/Compress/decompress.c2
-rw-r--r--libs/NCSI/tests/tests.cpp2
-rw-r--r--libs/VPD/vpd.c2
-rw-r--r--simulator/HAL.cpp8
-rw-r--r--utils/ape2elf/main.cpp4
-rwxr-xr-xutils/bcmflash/CMakeLists.txt5
-rw-r--r--utils/bcmflash/create_header.cpp (renamed from utils/bcmflash/create_header.c)0
-rw-r--r--utils/bcmflash/ethtool.c6
-rwxr-xr-xutils/bcmflash/ethtool.h10
-rw-r--r--utils/bcmflash/main.cpp12
-rw-r--r--utils/bcmregtool/main.cpp4
-rw-r--r--utils/elf2ape/main.cpp7
12 files changed, 34 insertions, 28 deletions
diff --git a/libs/Compress/decompress.c b/libs/Compress/decompress.c
index 886ed7e..3fb3b02 100644
--- a/libs/Compress/decompress.c
+++ b/libs/Compress/decompress.c
@@ -68,7 +68,7 @@ static struct
static void state_init(const uint8_t *inBuffer, int32_t inBytes)
{
g_DecompressorState.cursor = DICTIONARY_INIT_INDEX;
- int i = 0;
+ uint32_t i = 0;
for (; i < g_DecompressorState.cursor; i++)
{
g_DecompressorState.dictionary[i] = DICTIONARY_INIT_0x20;
diff --git a/libs/NCSI/tests/tests.cpp b/libs/NCSI/tests/tests.cpp
index 0f916b2..10dcb6a 100644
--- a/libs/NCSI/tests/tests.cpp
+++ b/libs/NCSI/tests/tests.cpp
@@ -132,7 +132,7 @@ void print_capabilities(uint8_t* packet)
void print_packet(uint32_t *packet_u32, size_t len)
{
// Correct endian
- for(int i = 0; i < len; i++)
+ for(size_t i = 0; i < len; i++)
{
printf("0x%08X\n", packet_u32[i]);
}
diff --git a/libs/VPD/vpd.c b/libs/VPD/vpd.c
index c2b9622..678c62f 100644
--- a/libs/VPD/vpd.c
+++ b/libs/VPD/vpd.c
@@ -72,7 +72,7 @@ bool vpd_is_checksum(uint16_t field)
}
const char *vpd_get_field_name(uint16_t field)
{
- for (int i = 0; i < sizeof(mNames) / sizeof(mNames[0]); i++)
+ for (size_t i = 0; i < ARRAY_ELEMENTS(mNames); i++)
{
if (0 == strncmp(mNames[i].name, (const char *)&field, 2))
{
diff --git a/simulator/HAL.cpp b/simulator/HAL.cpp
index c677eba..ab4fce4 100644
--- a/simulator/HAL.cpp
+++ b/simulator/HAL.cpp
@@ -99,7 +99,7 @@ devices_t gSupportedDevices[] = {
bool is_supported(uint16_t vendor_id, uint16_t device_id)
{
- for (unsigned int i = 0; i < ARRAY_ELEMENTS(gSupportedDevices); i++)
+ for (size_t i = 0; i < ARRAY_ELEMENTS(gSupportedDevices); i++)
{
devices_t *pDevice = &gSupportedDevices[i];
if (vendor_id == pDevice->vendor_id && device_id == pDevice->device_id)
@@ -134,7 +134,7 @@ static size_t barlen[MAX_NUM_BARS];
static void unmap_bars()
{
- for(int i = 0; i < ARRAY_ELEMENTS(bar); i++)
+ for(size_t i = 0; i < ARRAY_ELEMENTS(bar); i++)
{
if(bar[i] && barlen[i])
{
@@ -272,7 +272,7 @@ bool initHAL(const char *pci_path, int wanted_function)
printf("Found supported device %x:%x at %s\n", config.vendor_id,
config.device_id, configPath.c_str());
- for (unsigned int i = 0; i < ARRAY_ELEMENTS(config.BAR); i++)
+ for (size_t i = 0; i < ARRAY_ELEMENTS(config.BAR); i++)
{
int memfd;
string BARPath = string(located_pci_path) + "/" BAR_STR + to_string(i);
@@ -288,7 +288,7 @@ bool initHAL(const char *pci_path, int wanted_function)
}
else
{
- printf("mmaping BAR[%d]: %s\n", i, pBARPath);
+ printf("mmaping BAR[%zu]: %s\n", i, pBARPath);
}
if (fstat(memfd, &st) < 0)
diff --git a/utils/ape2elf/main.cpp b/utils/ape2elf/main.cpp
index 7daa80a..355ca37 100644
--- a/utils/ape2elf/main.cpp
+++ b/utils/ape2elf/main.cpp
@@ -95,7 +95,7 @@ int main(int argc, char const *argv[])
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 (size_t i = 0; i < sizeof(ape) / sizeof(ape.words[0]); i++)
{
ape.words[i] = be32toh(ape.words[i]);
}
@@ -151,7 +151,7 @@ int main(int argc, char const *argv[])
printf("UNK0: 0x%08X\n", ape.header.unk0);
char name[sizeof(ape.header.name) + 1] = { 0 };
- strncpy(name, (char *)ape.header.name, sizeof(ape.header.name));
+ strncpy(name, (char *)ape.header.name, sizeof(name) - 1);
printf("Name: %s\n", name);
printf("Version: 0x%08X (%d.%d.%d)\n", ape.header.version, version_major, version_minor, version_patch);
printf("Start: 0x%08X\n", ape.header.entrypoint);
diff --git a/utils/bcmflash/CMakeLists.txt b/utils/bcmflash/CMakeLists.txt
index fd41194..fb6e5b7 100755
--- a/utils/bcmflash/CMakeLists.txt
+++ b/utils/bcmflash/CMakeLists.txt
@@ -9,7 +9,7 @@ set(SOURCES
bcmflash.h
# Support files for initializing the firmware header
- create_header.c create_header.h
+ create_header.cpp create_header.h
nvm_talos2.c
nvm_blackbird.c
nvm_kh08p.c
@@ -21,8 +21,9 @@ IF(CONFIG_HAVE_LINUX_ETHTOOL_H)
)
ENDIF()
-simulator_add_executable(${PROJECT_NAME} ${SOURCES})
+add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE NVRam VPD simulator OptParse)
+target_compile_options(${PROJECT_NAME} PRIVATE -DCXX_SIMULATOR)
format_target_sources(${PROJECT_NAME})
diff --git a/utils/bcmflash/create_header.c b/utils/bcmflash/create_header.cpp
index 133c351..133c351 100644
--- a/utils/bcmflash/create_header.c
+++ b/utils/bcmflash/create_header.cpp
diff --git a/utils/bcmflash/ethtool.c b/utils/bcmflash/ethtool.c
index 76d2ed3..2aaad36 100644
--- a/utils/bcmflash/ethtool.c
+++ b/utils/bcmflash/ethtool.c
@@ -71,7 +71,7 @@ static int do_ioctl(struct cmd_context *ctx, void *cmd)
size_t bcmflash_ethtool_size(const char *name)
{
- cmd_context ctx = { 0 };
+ struct cmd_context ctx = { 0 };
strcpy(ctx.ifr.ifr_name, name);
@@ -97,7 +97,7 @@ bool bcmflash_ethtool_read(const char *name, void *buffer, size_t len)
uint32_t eeprom_size = bcmflash_ethtool_size(name);
- cmd_context ctx = { 0 };
+ struct cmd_context ctx = { 0 };
strcpy(ctx.ifr.ifr_name, name);
@@ -137,7 +137,7 @@ bool bcmflash_ethtool_write(const char *name, void *buffer, size_t len)
uint32_t eeprom_size = bcmflash_ethtool_size(name);
- cmd_context ctx = { 0 };
+ struct cmd_context ctx = { 0 };
strcpy(ctx.ifr.ifr_name, name);
diff --git a/utils/bcmflash/ethtool.h b/utils/bcmflash/ethtool.h
index d42906b..08655f0 100755
--- a/utils/bcmflash/ethtool.h
+++ b/utils/bcmflash/ethtool.h
@@ -42,12 +42,12 @@
/// @endcond
////////////////////////////////////////////////////////////////////////////////
-#ifndef IFACE_H
-#define IFACE_H
+#ifndef ETHTOOL_H
+#define ETHTOOL_H
#include <stdint.h>
-#ifdef __cplusplus__
+#ifdef __cplusplus
extern "C" {
#endif
@@ -55,8 +55,8 @@ bool bcmflash_ethtool_read(const char *name, void *buffer, size_t len);
bool bcmflash_ethtool_write(const char *name, void *buffer, size_t len);
size_t bcmflash_ethtool_size(const char *name);
-#ifdef __cplusplus__
+#ifdef __cplusplus
}
#endif
-#endif /* IFACE_H */
+#endif /* ETHTOOL_H */
diff --git a/utils/bcmflash/main.cpp b/utils/bcmflash/main.cpp
index 1a48e9b..6e32edf 100644
--- a/utils/bcmflash/main.cpp
+++ b/utils/bcmflash/main.cpp
@@ -337,7 +337,7 @@ void dump_info(NVRAMInfo_t *info, NVRAMInfo2_t *info2)
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 (size_t i = 0; i < ARRAY_ELEMENTS(pb_raw); i++)
{
uint32_t raw = pb_raw[i];
RegDEVICEPciPowerBudget0_t pb0;
@@ -351,7 +351,7 @@ void dump_info(NVRAMInfo_t *info, NVRAMInfo2_t *info2)
pb0.bits.PowerRail = (raw & 0xE000) >> 13;
}
- printf("Translated Power Budget[%d]: 0x%08X\n", i, (uint32_t)pb0.r32);
+ printf("Translated Power Budget[%zu]: 0x%08X\n", i, (uint32_t)pb0.r32);
}
printf("\n=== Port 0 ===\n");
@@ -482,7 +482,7 @@ int main(int argc, char const *argv[])
string target_type_help;
string target_name_help;
std::list<std::string> target_options;
- for (int i = 0; i < ARRAY_ELEMENTS(gStorage); i++)
+ for (size_t i = 0; i < ARRAY_ELEMENTS(gStorage); i++)
{
target_type_help += gStorage[i].type;
target_type_help += ": ";
@@ -543,7 +543,7 @@ int main(int argc, char const *argv[])
vector<string> args = parser.args();
storage_t *target = NULL;
- for (int i = 0; i < ARRAY_ELEMENTS(gStorage); i++)
+ for (size_t i = 0; i < ARRAY_ELEMENTS(gStorage); i++)
{
if (gStorage[i].type == options["target_type"])
{
@@ -768,7 +768,7 @@ int main(int argc, char const *argv[])
}
}
- for (int i = 0; i < ARRAY_ELEMENTS(nvram.contents.directory); i++)
+ for (size_t i = 0; i < ARRAY_ELEMENTS(nvram.contents.directory); i++)
{
char *cd_name = NULL;
if (extract)
@@ -821,7 +821,7 @@ int main(int argc, char const *argv[])
if (gApeWd[0] == APE_HEADER_MAGIC)
{
// Ensure everything is in the correct endianness.
- for (int i = 0; i < (new_ape_length - 4) / 4; i++)
+ for (uint32_t i = 0; i < (new_ape_length - 4) / 4; i++)
{
gApeWd[i] = be32toh(gApeWd[i]);
}
diff --git a/utils/bcmregtool/main.cpp b/utils/bcmregtool/main.cpp
index 0896b00..5eb2c4c 100644
--- a/utils/bcmregtool/main.cpp
+++ b/utils/bcmregtool/main.cpp
@@ -233,11 +233,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 (size_t i = 0; i < ARRAY_ELEMENTS(r) / 4; i++)
{
for (int j = 0; j < numCols; j++)
{
- printf("$%d(%5s): 0x%08X ", i + j * offset, regnames[i + j * offset], r[i + j * offset]);
+ printf("$%zd(%5s): 0x%08X ", i + j * offset, regnames[i + j * offset], r[i + j * offset]);
}
printf("\n");
}
diff --git a/utils/elf2ape/main.cpp b/utils/elf2ape/main.cpp
index 78c95a5..c73975f 100644
--- a/utils/elf2ape/main.cpp
+++ b/utils/elf2ape/main.cpp
@@ -284,7 +284,12 @@ int main(int argc, char const *argv[])
if (options.is_set("name"))
{
string name = options["name"];
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas" // Ignore Wunknown-warning-option error on GCC
+#pragma GCC diagnostic ignored "-Wunknown-warning-option" // Ignore Wstringop-truncation on Clang
+#pragma GCC diagnostic ignored "-Wstringop-truncation" // Ignore destination size not allowing a null terminator
strncpy((char *)ape.header.name, name.c_str(), sizeof(ape.header.name));
+#pragma GCC diagnostic pop
}
uint8_t version_major = get_symbol_value("VERSION_MAJOR", reader);
@@ -302,7 +307,7 @@ int main(int argc, char const *argv[])
printf("UNK0: 0x%08X\n", ape.header.unk0);
char name[sizeof(ape.header.name) + 1] = { 0 };
- strncpy(name, (char *)ape.header.name, sizeof(ape.header.name));
+ strncpy(name, (char *)ape.header.name, sizeof(name) - 1);
printf("Name: %s\n", name);
printf("Version: 0x%08X (%d.%d.%d)\n", ape.header.version, version_major, version_minor, version_patch);
printf("Start: 0x%08X\n", ape.header.entrypoint);
OpenPOWER on IntegriCloud