compile-time enforcement of printf strings

This commit is contained in:
Matthew Kennedy 2024-06-10 00:51:14 -07:00
parent 2dbe992780
commit cf87e64119
22 changed files with 45 additions and 48 deletions

View File

@ -124,7 +124,7 @@ static void runCommands(SerialTsChannelBase* tsChannel) {
return;
}
efiPrintf("Restarting at %d", baudRates[baudIdx].rate);
efiPrintf("Restarting at %lu", baudRates[baudIdx].rate);
tsChannel->start(baudRates[baudIdx].rate);
chThdSleepMilliseconds(10); // safety

View File

@ -188,7 +188,7 @@ void TunerStudio::handleCrc32Check(TsChannelBase *tsChannel, uint16_t offset, ui
const uint8_t* start = getWorkingPageAddr() + offset;
uint32_t crc = crc32(start, count);
efiPrintf("TS <- Get CRC offset %d count %d result %08x", offset, count, crc);
efiPrintf("TS <- Get CRC offset %d count %d result %08x", offset, count, (unsigned int)crc);
crc = SWAP_UINT32(crc);
tsChannel->copyAndWriteSmallCrcPacket((const uint8_t *) &crc, sizeof(crc));
@ -464,7 +464,7 @@ static int tsProcessOne(TsChannelBase* tsChannel) {
/* send error only if previously we were in sync */
if (tsChannel->in_sync) {
efiPrintf("TunerStudio: command %c actual CRC %x/expected %x", tsChannel->scratchBuffer[0],
actualCrc, expectedCrc);
(unsigned int)actualCrc, (unsigned int)expectedCrc);
tunerStudioError(tsChannel, "ERROR: CRC issue");
sendErrorCode(tsChannel, TS_RESPONSE_CRC_FAILURE);
tsChannel->in_sync = false;

View File

@ -57,7 +57,7 @@ static void sayHello() {
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
uint32_t *uid = ((uint32_t *)UID_BASE);
efiPrintf("UID=%x %x %x", uid[0], uid[1], uid[2]);
efiPrintf("UID=%x %x %x", (unsigned int)uid[0], (unsigned int)uid[1], (unsigned int)uid[2]);
efiPrintf("can read 0x20000010 %d", ramReadProbe((const char *)0x20000010));
efiPrintf("can read 0x20020010 %d", ramReadProbe((const char *)0x20020010));
@ -129,7 +129,7 @@ static void cmd_threads() {
while (tp) {
int freeBytes = CountFreeStackSpace(tp->wabase);
efiPrintf("%s\t%08x\t%lu\t%d", tp->name, tp->wabase, tp->time, freeBytes);
efiPrintf("%s\t%08x\t%lu\t%d", tp->name, (unsigned int)tp->wabase, tp->time, freeBytes);
if (freeBytes < 100) {
firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Ran out of stack on thread %s, %d bytes remain", tp->name, freeBytes);

View File

@ -106,11 +106,11 @@ static Timer printVersionTimer;
static void printRusefiVersion(const char *engineTypeName, const char *firmwareBuildId) {
// VersionChecker in rusEFI console is parsing these version string, please follow the expected format
efiPrintfProto(PROTOCOL_VERSION_TAG, "%d@%s %s %s %d",
efiPrintfProto(PROTOCOL_VERSION_TAG, "%d@%s %s %s %lu",
getRusEfiVersion(), GIT_HASH_SHORT,
firmwareBuildId,
engineTypeName,
getTimeNowS());
(uint32_t)getTimeNowS());
}
// Inform the console about the mapping between a pin's logical name (for example, injector 3)

View File

@ -306,7 +306,7 @@ void Engine::OnTriggerSyncronization(bool wasSynchronized, bool isDecodingError)
if (isDecodingError) {
#if EFI_PROD_CODE
if (engineConfiguration->verboseTriggerSynchDetails || (triggerCentral.triggerState.someSortOfTriggerError() && !engineConfiguration->silentTriggerError)) {
efiPrintf("error: synchronizationPoint @ index %d expected %d/%d got %d/%d",
efiPrintf("error: synchronizationPoint @ index %lu expected %d/%d got %d/%d",
triggerCentral.triggerState.currentCycle.current_index,
triggerCentral.triggerShape.getExpectedEventCount(TriggerWheel::T_PRIMARY),
triggerCentral.triggerShape.getExpectedEventCount(TriggerWheel::T_SECONDARY),

View File

@ -40,11 +40,11 @@ void resetMaxValues() {
}
void printRuntimeStats(void) {
efiPrintf("maxSchedulingPrecisionLoss=%d", maxSchedulingPrecisionLoss);
efiPrintf("maxSchedulingPrecisionLoss=%lu", maxSchedulingPrecisionLoss);
#if EFI_CLOCK_LOCKS
efiPrintf("maxLockedDuration=%d / maxTriggerReentrant=%d", maxLockedDuration, maxTriggerReentrant);
efiPrintf("maxLockedDuration=%lu / maxTriggerReentrant=%d", maxLockedDuration, maxTriggerReentrant);
#endif // EFI_CLOCK_LOCKS
efiPrintf("maxEventCallbackDuration=%d", maxEventCallbackDuration);
efiPrintf("maxEventCallbackDuration=%lu", maxEventCallbackDuration);
}

View File

@ -30,7 +30,7 @@ void checkLastBootError() {
efiPrintf("Last boot had firmware error: %s", sramState->Err.ErrorString);
break;
case ErrorCookie::HardFault: {
efiPrintf("Last boot had hard fault type: %x addr: %x CSFR: %x", sramState->Err.FaultType, sramState->Err.FaultAddress, sramState->Err.Csfr);
efiPrintf("Last boot had hard fault type: %x addr: %x CSFR: %x", (unsigned int)sramState->Err.FaultType, (unsigned int)sramState->Err.FaultAddress, (unsigned int)sramState->Err.Csfr);
// Print out the context as a sequence of uintptr
uintptr_t* data = reinterpret_cast<uintptr_t*>(&sramState->Err.FaultCtx);
@ -53,7 +53,7 @@ void checkLastBootError() {
sramState->Err.BootCount = 0;
}
efiPrintf("Power cycle count: %d", sramState->Err.BootCount);
efiPrintf("Power cycle count: %lu", sramState->Err.BootCount);
sramState->Err.BootCount++;
}

View File

@ -64,7 +64,7 @@ void PrimeController::onIgnitionStateChanged(bool ignitionOn) {
auto startTime = getTimeNowNt() + primeDelayNt;
getExecutorInterface()->scheduleByTimestampNt("prime start", nullptr, startTime, { PrimeController::onPrimeStartAdapter, this });
} else {
efiPrintf("Skipped priming pulse since ignSwitchCounter = %d", ignSwitchCounter);
efiPrintf("Skipped priming pulse since ignSwitchCounter = %lu", ignSwitchCounter);
}
// we'll reset it later when the engine starts

View File

@ -306,7 +306,7 @@ void readFromFlash() {
break;
case FlashState::IncompatibleVersion:
// Preserve engine type from old config
efiPrintf("Resetting due to version mismatch but preserving engine type [%d]", engineConfiguration->engineType);
efiPrintf("Resetting due to version mismatch but preserving engine type [%d]", (int)engineConfiguration->engineType);
resetConfigurationExt(engineConfiguration->engineType);
break;
case FlashState::Ok:

View File

@ -31,7 +31,7 @@ void addLuaCanRxFilter(int32_t eid, uint32_t mask, CanBusIndex bus, int callback
firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Too many Lua CAN RX filters");
}
efiPrintf("Added Lua CAN RX filter id 0x%x mask 0x%x with%s custom function", eid, mask, (callback == -1 ? "out" : ""));
efiPrintf("Added Lua CAN RX filter id 0x%x mask 0x%x with%s custom function", (unsigned int)eid, (unsigned int)mask, (callback == -1 ? "out" : ""));
filters[filterCount].Id = eid;
filters[filterCount].Mask = mask;

View File

@ -718,8 +718,8 @@ void triggerInfo(void) {
#endif /* HAL_TRIGGER_USE_PAL */
efiPrintf("Template %s (%d) trigger %s (%d) syncEdge=%s tdcOffset=%.2f",
getEngine_type_e(engineConfiguration->engineType), engineConfiguration->engineType,
getTrigger_type_e(engineConfiguration->trigger.type), engineConfiguration->trigger.type,
getEngine_type_e(engineConfiguration->engineType), (int)engineConfiguration->engineType,
getTrigger_type_e(engineConfiguration->trigger.type), (int)engineConfiguration->trigger.type,
getSyncEdge(TRIGGER_WAVEFORM(m_syncEdge)), TRIGGER_WAVEFORM(tdcPosition));
if (engineConfiguration->trigger.type == trigger_type_e::TT_TOOTHED_WHEEL) {
@ -739,11 +739,11 @@ void triggerInfo(void) {
TRIGGER_WAVEFORM(getExpectedEventCount(TriggerWheel::T_PRIMARY)),
TRIGGER_WAVEFORM(getExpectedEventCount(TriggerWheel::T_SECONDARY)));
efiPrintf("trigger type=%d/need2ndChannel=%s", engineConfiguration->trigger.type,
efiPrintf("trigger type=%d/need2ndChannel=%s", (int)engineConfiguration->trigger.type,
boolToString(TRIGGER_WAVEFORM(needSecondTriggerInput)));
efiPrintf("synchronizationNeeded=%s/isError=%s/total errors=%d ord_err=%d/total revolutions=%d/self=%s",
efiPrintf("synchronizationNeeded=%s/isError=%s/total errors=%lu ord_err=%lu/total revolutions=%d/self=%s",
boolToString(ts->isSynchronizationNeeded),
boolToString(tc->isTriggerDecoderError()),
tc->triggerState.totalTriggerErrorCounter,
@ -788,7 +788,7 @@ void triggerInfo(void) {
efiPrintf("secondary logic input: %s", hwPortname(engineConfiguration->logicAnalyzerPins[1]));
efiPrintf("totalTriggerHandlerMaxTime=%d", triggerMaxDuration);
efiPrintf("totalTriggerHandlerMaxTime=%lu", triggerMaxDuration);
#endif /* EFI_PROD_CODE */

View File

@ -476,16 +476,13 @@ expected<TriggerDecodeResult> TriggerDecoderBase::decodeTriggerEvent(
float gap = 1.0 * toothDurations[i] / toothDurations[i + 1];
if (cisnan(gap)) {
efiPrintf("%s index=%d NaN gap, you have noise issues?",
i,
prefix
);
efiPrintf("%s index=%d NaN gap, you have noise issues?", prefix, i);
} else {
float ratioTo = triggerShape.syncronizationRatioTo[i];
bool gapOk = isInRange(ratioFrom, gap, ratioTo);
efiPrintf("%s %srpm=%d time=%d eventIndex=%d gapIndex=%d: %s gap=%.3f expected from %.3f to %.3f error=%s",
efiPrintf("%s %srpm=%d time=%d eventIndex=%lu gapIndex=%d: %s gap=%.3f expected from %.3f to %.3f error=%s",
prefix,
triggerConfiguration.PrintPrefix,
(int)Sensor::getOrZero(SensorType::Rpm),

View File

@ -118,7 +118,7 @@ int WaveChart::getSize() {
#if ! EFI_UNIT_TEST
static void printStatus() {
efiPrintf("engine sniffer: %s", boolToString(getTriggerCentral()->isEngineSnifferEnabled));
efiPrintf("engine sniffer size=%d", engineConfiguration->engineChartSize);
efiPrintf("engine sniffer size=%lu", engineConfiguration->engineChartSize);
}
void setChartSize(int newSize) {

View File

@ -300,7 +300,7 @@ static uint32_t slowAdcErrorsCount = 0;
void printFullAdcReport(void) {
#if EFI_USE_FAST_ADC
efiPrintf("fast %d samples", fastAdc.conversionCount);
efiPrintf("fast %lu samples", fastAdc.conversionCount);
for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) {
adc_channel_e hwIndex = fastAdc.getAdcHardwareIndexByInternalIndex(internalIndex);
@ -316,7 +316,7 @@ void printFullAdcReport(void) {
}
}
#endif // EFI_USE_FAST_ADC
efiPrintf("slow %d samples", slowAdcConversionCount);
efiPrintf("slow %lu samples", slowAdcConversionCount);
/* we assume that all slow ADC channels are enabled */
for (int internalIndex = 0; internalIndex < ADC_MAX_CHANNELS_COUNT; internalIndex++) {

View File

@ -117,7 +117,7 @@ void ButtonDebounce::debug() {
ButtonDebounce *listItem = s_firstDebounce;
while (listItem != nullptr) {
#if EFI_PROD_CODE || EFI_UNIT_TEST
efiPrintf("%s timeLast %d", listItem->m_name, listItem->timeLast);
efiPrintf("%s timeLast %lu", listItem->m_name, (uint32_t)listItem->timeLast);
efiPrintf("physical state %d value %d", efiReadPin(listItem->active_pin), listItem->storedValue);
#endif

View File

@ -66,9 +66,9 @@ CanTxMessage::~CanTxMessage() {
efiPrintf("Sending CAN bus%d message: ID=%x/l=%x %x %x %x %x %x %x %x %x",
busIndex,
#ifndef STM32H7XX
(m_frame.IDE == CAN_IDE_EXT) ? CAN_EID(m_frame) : CAN_SID(m_frame),
(unsigned int)((m_frame.IDE == CAN_IDE_EXT) ? CAN_EID(m_frame) : CAN_SID(m_frame)),
#else
m_frame.common.XTD ? CAN_EID(m_frame) : CAN_SID(m_frame),
(unsigned int)(m_frame.common.XTD ? CAN_EID(m_frame) : CAN_SID(m_frame)),
#endif
m_frame.DLC,
m_frame.data8[0], m_frame.data8[1],

View File

@ -506,8 +506,8 @@ void sent_channel::Info(void) {
uint8_t stat;
uint16_t sig0, sig1;
efiPrintf("Unit time %d CPU ticks %f uS", tickPerUnit, TicksToUs(getTickTime()));
efiPrintf("Total pulses %d", pulseCounter);
efiPrintf("Unit time %lu CPU ticks %f uS", tickPerUnit, TicksToUs(getTickTime()));
efiPrintf("Total pulses %lu", pulseCounter);
if (GetSignals(&stat, &sig0, &sig1) == 0) {
efiPrintf("Last valid fast msg Status 0x%01x Sig0 0x%03x Sig1 0x%03x", stat, sig0, sig1);
@ -523,11 +523,11 @@ void sent_channel::Info(void) {
}
#if SENT_STATISTIC_COUNTERS
efiPrintf("Restarts %d", statistic.RestartCnt);
efiPrintf("Interval errors %d short, %d long", statistic.ShortIntervalErr, statistic.LongIntervalErr);
efiPrintf("Total frames %d with CRC error %d (%f%%)", statistic.FrameCnt, statistic.CrcErrCnt, statistic.CrcErrCnt * 100.0 / statistic.FrameCnt);
efiPrintf("Total slow channel messages %d with crc6 errors %d (%f%%)", statistic.sc, statistic.scCrcErr, statistic.scCrcErr * 100.0 / statistic.sc);
efiPrintf("Sync errors %d", statistic.SyncErr);
efiPrintf("Restarts %lu", statistic.RestartCnt);
efiPrintf("Interval errors %lu short, %lu long", statistic.ShortIntervalErr, statistic.LongIntervalErr);
efiPrintf("Total frames %lu with CRC error %lu (%f%%)", statistic.FrameCnt, statistic.CrcErrCnt, statistic.CrcErrCnt * 100.0 / statistic.FrameCnt);
efiPrintf("Total slow channel messages %lu with crc6 errors %lu (%f%%)", statistic.sc, statistic.scCrcErr, statistic.scCrcErr * 100.0 / statistic.sc);
efiPrintf("Sync errors %lu", statistic.SyncErr);
#endif
}

View File

@ -275,7 +275,7 @@ static void listDirectory(const char *path) {
if ((fno.fattrib & AM_DIR) || mystrncasecmp(RUSEFI_LOG_PREFIX, fno.fname, sizeof(RUSEFI_LOG_PREFIX) - 1)) {
continue;
}
efiPrintf("logfile%lu:%s", fno.fsize, fno.fname);
efiPrintf("logfile %lu:%s", (uint32_t)fno.fsize, fno.fname);
count++;
// efiPrintf("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %-12s", (fno.fattrib & AM_DIR) ? 'D' : '-',

View File

@ -42,7 +42,7 @@ static const char * const monthAbbrs[] = {
void printRtcDateTime() {
efidatetime_t dateTime = getRtcDateTime();
// prints the date like: 19 sep 2022 21:19:55
efiPrintf("Current RTC time: %02u %s %04u %02u:%02u:%02u",
efiPrintf("Current RTC time: %02u %s %04lu %02u:%02u:%02u",
dateTime.day, monthAbbrs[dateTime.month - 1], dateTime.year,
dateTime.hour, dateTime.minute, dateTime.second);
}

View File

@ -128,14 +128,14 @@ static void egtRead() {
max_32855_code code = getResultCode(egtPacket);
efiPrintf("egt %x code=%d %s", egtPacket, code, getMcCode(code));
efiPrintf("egt %x code=%d %s", (unsigned int)egtPacket, (unsigned int)code, getMcCode(code));
if (code != MC_INVALID) {
int refBits = ((egtPacket & 0xFFFF) / 16); // bits 15:4
float refTemp = refBits / 16.0;
efiPrintf("reference temperature %.2f", refTemp);
efiPrintf("EGT temperature %d", GET_TEMPERATURE_C(egtPacket));
efiPrintf("EGT temperature %lu", GET_TEMPERATURE_C(egtPacket));
}
}

View File

@ -18,7 +18,7 @@ const char* swapOutputBuffers(size_t *actualOutputBufferSize);
namespace priv
{
// internal implementation, use efiPrintf below
void efiPrintfInternal(const char *fmt, ...);
void efiPrintfInternal(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
}
// "normal" logging messages need a header and footer, so put them in

View File

@ -47,14 +47,14 @@ static void testBinary() {
}
timeNew = getTimeNowLowerNt() - start;
}
efiPrintf("for v=%d old=%d ticks", v, timeOld);
efiPrintf("for v=%d new=%d ticks", v, timeNew);
efiPrintf("for v=%d old=%lu ticks", v, timeOld);
efiPrintf("for v=%d new=%lu ticks", v, timeNew);
totalOld += timeOld;
totalNew += timeNew;
}
efiPrintf("totalOld=%d ticks", totalOld);
efiPrintf("totalNew=%d ticks", totalNew);
efiPrintf("totalOld=%lu ticks", totalOld);
efiPrintf("totalNew=%lu ticks", totalNew);
}