Skip to content

Commit 601e2d4

Browse files
manish-pandey-armTrustedFirmware Code Review
authored andcommitted
Merge changes from topic "bk/warnings" into integration
* changes: docs: describe the new warning levels build: add -Wunused-const-variable=2 to W=2 build: include -Wextra in generic builds docs(porting-guide): update a reference fix(st-usb): replace redundant checks with asserts fix(brcm): add braces around bodies of conditionals fix(renesas): align incompatible function pointers fix(zynqmp): remove redundant api_version check fix: remove old-style declarations fix: unify fallthrough annotations
2 parents 0e4655f + 291be19 commit 601e2d4

File tree

26 files changed

+163
-110
lines changed

26 files changed

+163
-110
lines changed

Makefile

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,27 +350,53 @@ ASFLAGS_aarch64 = $(march64-directive)
350350
# General warnings
351351
WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
352352
-Wdisabled-optimization -Wvla -Wshadow \
353-
-Wno-unused-parameter -Wredundant-decls
353+
-Wredundant-decls
354+
# stricter warnings
355+
WARNINGS += -Wextra -Wno-trigraphs
356+
# too verbose for generic build
357+
WARNINGS += -Wno-missing-field-initializers \
358+
-Wno-type-limits -Wno-sign-compare \
359+
# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
360+
WARNINGS += -Wno-unused-parameter
354361

355362
# Additional warnings
356-
# Level 1
357-
WARNING1 := -Wextra
358-
WARNING1 += -Wmissing-format-attribute
359-
WARNING1 += -Wmissing-prototypes
360-
WARNING1 += -Wold-style-definition
361-
362-
# Level 2
363-
WARNING2 := -Waggregate-return
364-
WARNING2 += -Wcast-align
365-
WARNING2 += -Wnested-externs
366-
363+
# Level 1 - infrequent warnings we should have none of
364+
# full -Wextra
365+
WARNING1 += -Wsign-compare
366+
WARNING1 += -Wtype-limits
367+
WARNING1 += -Wmissing-field-initializers
368+
369+
# Level 2 - problematic warnings that we want
370+
# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
371+
# TODO: disable just for them and move into default build
372+
WARNING2 += -Wold-style-definition
373+
WARNING2 += -Wmissing-prototypes
374+
WARNING2 += -Wmissing-format-attribute
375+
# TF-A aims to comply with this eventually. Effort too large at present
376+
WARNING2 += -Wundef
377+
# currently very involved and many platforms set this off
378+
WARNING2 += -Wunused-const-variable=2
379+
380+
# Level 3 - very pedantic, frequently ignored
367381
WARNING3 := -Wbad-function-cast
382+
WARNING3 += -Waggregate-return
383+
WARNING3 += -Wnested-externs
384+
WARNING3 += -Wcast-align
368385
WARNING3 += -Wcast-qual
369386
WARNING3 += -Wconversion
370387
WARNING3 += -Wpacked
371388
WARNING3 += -Wpointer-arith
372389
WARNING3 += -Wswitch-default
373390

391+
# Setting W is quite verbose and most warnings will be pre-existing issues
392+
# outside of the contributor's control. Don't fail the build on them so warnings
393+
# can be seen and hopefully addressed
394+
ifdef W
395+
ifneq (${W},0)
396+
E ?= 0
397+
endif
398+
endif
399+
374400
ifeq (${W},1)
375401
WARNINGS += $(WARNING1)
376402
else ifeq (${W},2)

docs/getting_started/build-options.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ Common build options
213213

214214
- ``E``: Boolean option to make warnings into errors. Default is 1.
215215

216+
When specifying higher warnings levels (``W=1`` and higher), this option
217+
defaults to 0. This is done to encourage contributors to use them, as they
218+
are expected to produce warnings that would otherwise fail the build. New
219+
contributions are still expected to build with ``W=0`` and ``E=1`` (the
220+
default).
221+
216222
- ``EL3_PAYLOAD_BASE``: This option enables booting an EL3 payload instead of
217223
the normal boot flow. It must specify the entry point address of the EL3
218224
payload. Please refer to the "Booting an EL3 payload" section for more
@@ -954,6 +960,43 @@ Common build options
954960
regrouped and put in the root Makefile. This flag can take the values 0 to 3,
955961
each level enabling more warning options. Default is 0.
956962

963+
This option is closely related to the ``E`` option, which enables
964+
``-Werror``.
965+
966+
- ``W=0`` (default)
967+
968+
Enables a wide assortment of warnings, most notably ``-Wall`` and
969+
``-Wextra``, as well as various bad practices and things that are likely to
970+
result in errors. Includes some compiler specific flags. No warnings are
971+
expected at this level for any build.
972+
973+
- ``W=1``
974+
975+
Enables warnings we want the generic build to include but are too time
976+
consuming to fix at the moment. It re-enables warnings taken out for
977+
``W=0`` builds (a few of the ``-Wextra`` additions). This level is expected
978+
to eventually be merged into ``W=0``. Some warnings are expected on some
979+
builds, but new contributions should not introduce new ones.
980+
981+
- ``W=2`` (recommended)
982+
983+
Enables warnings we want the generic build to include but cannot be enabled
984+
due to external libraries. This level is expected to eventually be merged
985+
into ``W=0``. Lots of warnings are expected, primarily from external
986+
libraries like zlib and compiler-rt, but new controbutions should not
987+
introduce new ones.
988+
989+
- ``W=3``
990+
991+
Enables warnings that are informative but not necessary and generally too
992+
verbose and frequently ignored. A very large number of warnings are
993+
expected.
994+
995+
The exact set of warning flags depends on the compiler and TF-A warning
996+
level, however they are all succinctly set in the top-level Makefile. Please
997+
refer to the `GCC`_ or `Clang`_ documentation for more information on the
998+
individual flags.
999+
9571000
- ``WARMBOOT_ENABLE_DCACHE_EARLY`` : Boolean option to enable D-cache early on
9581001
the CPU after warm boot. This is applicable for platforms which do not
9591002
require interconnect programming to enable cache coherency (eg: single
@@ -1161,3 +1204,5 @@ Firmware update options
11611204
.. _DEN0115: https://developer.arm.com/docs/den0115/latest
11621205
.. _PSA FW update specification: https://developer.arm.com/documentation/den0118/a/
11631206
.. _PSA DRTM specification: https://developer.arm.com/documentation/den0113/a
1207+
.. _GCC: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
1208+
.. _Clang: https://clang.llvm.org/docs/DiagnosticsReference.html

docs/getting_started/porting-guide.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ CPUs. BL31 executes at EL3 and is responsible for:
21352135

21362136
#. Providing runtime firmware services. Currently, BL31 only implements a
21372137
subset of the Power State Coordination Interface (PSCI) API as a runtime
2138-
service. See Section 3.3 below for details of porting the PSCI
2138+
service. See :ref:`psci_in_bl31` below for details of porting the PSCI
21392139
implementation.
21402140

21412141
#. Optionally passing control to the BL32 image, pre-loaded at a platform-
@@ -2544,6 +2544,8 @@ Function: bool plat_get_entropy(uint64_t \*out) [mandatory]
25442544
This function writes entropy into storage provided by the caller. If no entropy
25452545
is available, it must return false and the storage must not be written.
25462546

2547+
.. _psci_in_bl31:
2548+
25472549
Power State Coordination Interface (in BL31)
25482550
--------------------------------------------
25492551

docs/process/security-hardening.rst

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -131,38 +131,9 @@ Several build options can be used to check for security issues. Refer to the
131131
overflows.
132132

133133
- The ``W`` build flag can be used to enable a number of compiler warning
134-
options to detect potentially incorrect code.
135-
136-
- W=0 (default value)
137-
138-
The ``Wunused`` with ``Wno-unused-parameter``, ``Wdisabled-optimization``
139-
and ``Wvla`` flags are enabled.
140-
141-
The ``Wunused-but-set-variable``, ``Wmaybe-uninitialized`` and
142-
``Wpacked-bitfield-compat`` are GCC specific flags that are also enabled.
143-
144-
- W=1
145-
146-
Adds ``Wextra``, ``Wmissing-format-attribute``, ``Wmissing-prototypes``,
147-
``Wold-style-definition`` and ``Wunused-const-variable``.
148-
149-
- W=2
150-
151-
Adds ``Waggregate-return``, ``Wcast-align``, ``Wnested-externs``,
152-
``Wshadow``, ``Wlogical-op``.
153-
154-
- W=3
155-
156-
Adds ``Wbad-function-cast``, ``Wcast-qual``, ``Wconversion``, ``Wpacked``,
157-
``Wpointer-arith``, ``Wredundant-decls`` and
158-
``Wswitch-default``.
159-
160-
Refer to the GCC or Clang documentation for more information on the individual
161-
options: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html and
162-
https://clang.llvm.org/docs/DiagnosticsReference.html.
163-
164-
NB: The ``Werror`` flag is enabled by default in TF-A and can be disabled by
165-
setting the ``E`` build flag to 0.
134+
options to detect potentially incorrect code. TF-A is tested with ``W=0`` but
135+
it is recommended to develop against ``W=2`` (which will eventually become the
136+
default).
166137

167138
.. rubric:: References
168139

drivers/brcm/emmc/emmc_csl_sdcard.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,11 @@ int init_mmc_card(struct sd_handle *handle)
479479
handle->device->cfg.blockSize = 512;
480480
}
481481

482-
if (handle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY)
482+
if (handle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY) {
483483
EMMC_TRACE("Sector addressing\n");
484-
else
484+
} else {
485485
EMMC_TRACE("Byte addressing\n");
486+
}
486487

487488
EMMC_TRACE("Ext_CSD_storage[162]: 0x%02X Ext_CSD_storage[179]: 0x%02X\n",
488489
emmc_global_buf_ptr->u.Ext_CSD_storage[162],

drivers/brcm/emmc/emmc_pboot_hal_memory_drv.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ struct sd_handle *sdio_init(void)
278278

279279
SDIO_base = EMMC_CTRL_REGS_BASE_ADDR;
280280

281-
if (SDIO_base == SDIO0_EMMCSDXC_SYSADDR)
281+
if (SDIO_base == SDIO0_EMMCSDXC_SYSADDR) {
282282
EMMC_TRACE(" ---> for SDIO 0 Controller\n\n");
283+
}
283284

284285
memset(p_sdhandle, 0, sizeof(struct sd_handle));
285286

@@ -290,8 +291,9 @@ struct sd_handle *sdio_init(void)
290291
memset(p_sdhandle->card, 0, sizeof(struct sd_card_info));
291292

292293
if (chal_sd_start((CHAL_HANDLE *) p_sdhandle->device,
293-
SD_PIO_MODE, SDIO_base, SDIO_base) != SD_OK)
294+
SD_PIO_MODE, SDIO_base, SDIO_base) != SD_OK) {
294295
return NULL;
296+
}
295297

296298
set_config(p_sdhandle, SD_NORMAL_SPEED, MAX_CMD_RETRY, SD_DMA_OFF,
297299
SD_DMA_BOUNDARY_4K, EMMC_BLOCK_SIZE, EMMC_WFE_RETRY);
@@ -330,14 +332,16 @@ uint32_t sdio_read(struct sd_handle *p_sdhandle,
330332
VERBOSE("EMMC READ: dst=0x%lx, src=0x%lx, size=0x%lx\n",
331333
storage_addr, mem_addr, bytes_to_read);
332334

333-
if (storage_size < bytes_to_read)
335+
if (storage_size < bytes_to_read) {
334336
/* Don't have sufficient storage to complete the operation */
335337
return 0;
338+
}
336339

337340
/* Range check non high capacity memory */
338341
if ((p_sdhandle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY) == 0) {
339-
if (mem_addr > 0x80000000)
342+
if (mem_addr > 0x80000000) {
340343
return 0;
344+
}
341345
}
342346

343347
/* High capacity card use block address mode */
@@ -384,21 +388,23 @@ uint32_t sdio_read(struct sd_handle *p_sdhandle,
384388
/* Update Physical address */
385389
outputBuf += manual_copy_size;
386390

387-
if (p_sdhandle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY)
391+
if (p_sdhandle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY) {
388392
blockAddr++;
389-
else
393+
} else {
390394
blockAddr += blockSize;
395+
}
391396
} else {
392397
return 0;
393398
}
394399
}
395400

396401
while (remSize >= blockSize) {
397402

398-
if (remSize >= SD_MAX_BLK_TRANSFER_LENGTH)
403+
if (remSize >= SD_MAX_BLK_TRANSFER_LENGTH) {
399404
readLen = SD_MAX_BLK_TRANSFER_LENGTH;
400-
else
405+
} else {
401406
readLen = (remSize / blockSize) * blockSize;
407+
}
402408

403409
/* Check for overflow */
404410
if ((rdCount + readLen) > storage_size ||
@@ -409,10 +415,11 @@ uint32_t sdio_read(struct sd_handle *p_sdhandle,
409415
}
410416

411417
if (!read_block(p_sdhandle, outputBuf, blockAddr, readLen)) {
412-
if (p_sdhandle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY)
418+
if (p_sdhandle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY) {
413419
blockAddr += (readLen / blockSize);
414-
else
420+
} else {
415421
blockAddr += readLen;
422+
}
416423

417424
remSize -= readLen;
418425
rdCount += readLen;
@@ -463,8 +470,9 @@ static uint32_t sdio_write(struct sd_handle *p_sdhandle, uintptr_t mem_addr,
463470

464471
/* range check non high capacity memory */
465472
if ((p_sdhandle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY) == 0) {
466-
if (mem_addr > 0x80000000)
473+
if (mem_addr > 0x80000000) {
467474
return 0;
475+
}
468476
}
469477

470478
/* the high capacity card use block address mode */
@@ -491,11 +499,12 @@ static uint32_t sdio_write(struct sd_handle *p_sdhandle, uintptr_t mem_addr,
491499
blockAddr, p_sdhandle->device->cfg.blockSize)) {
492500

493501
if (remSize <
494-
(p_sdhandle->device->cfg.blockSize - offset))
502+
(p_sdhandle->device->cfg.blockSize - offset)) {
495503
manual_copy_size = remSize;
496-
else
504+
} else {
497505
manual_copy_size =
498506
p_sdhandle->device->cfg.blockSize - offset;
507+
}
499508

500509
memcpy((void *)((uintptr_t)
501510
(emmc_global_buf_ptr->u.tempbuf + offset)),
@@ -530,11 +539,12 @@ static uint32_t sdio_write(struct sd_handle *p_sdhandle, uintptr_t mem_addr,
530539
inputBuf += manual_copy_size;
531540

532541
if (p_sdhandle->device->ctrl.ocr &
533-
SD_CARD_HIGH_CAPACITY)
542+
SD_CARD_HIGH_CAPACITY) {
534543
blockAddr++;
535-
else
544+
} else {
536545
blockAddr +=
537546
p_sdhandle->device->cfg.blockSize;
547+
}
538548
} else
539549
return 0;
540550
} else {

drivers/imx/usdhc/imx_usdhc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,17 @@ static int imx_usdhc_send_cmd(struct mmc_cmd *cmd)
136136
break;
137137
case MMC_CMD(18):
138138
multiple = 1;
139-
/* fall thru for read op */
139+
/* for read op */
140+
/* fallthrough */
140141
case MMC_CMD(17):
141142
case MMC_CMD(8):
142143
mixctl |= MIXCTRL_DTDSEL;
143144
data = 1;
144145
break;
145146
case MMC_CMD(25):
146147
multiple = 1;
147-
/* fall thru for data op flag */
148+
/* for data op flag */
149+
/* fallthrough */
148150
case MMC_CMD(24):
149151
data = 1;
150152
break;

drivers/nxp/ddr/nxp-ddr/ddr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static int cal_odt(const unsigned int clk,
269269
unsigned int i;
270270
const struct dynamic_odt *pdodt = NULL;
271271

272-
const static struct dynamic_odt *table[2][5] = {
272+
static const struct dynamic_odt *table[2][5] = {
273273
{single_S, single_D, NULL, NULL},
274274
{dual_SS, dual_DD, NULL, NULL},
275275
};

drivers/nxp/ddr/phy-gen2/messages.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct phy_msg {
1313
const char *msg;
1414
};
1515

16-
const static struct phy_msg messages_1d[] = {
16+
static const struct phy_msg messages_1d[] = {
1717
{0x00000001,
1818
"PMU1:prbsGenCtl:%x\n"
1919
},
@@ -1239,7 +1239,7 @@ const static struct phy_msg messages_1d[] = {
12391239
},
12401240
};
12411241

1242-
const static struct phy_msg messages_2d[] = {
1242+
static const struct phy_msg messages_2d[] = {
12431243
{0x00000001,
12441244
"PMU0: Converting %d into an MR\n"
12451245
},

drivers/renesas/common/emmc/emmc_cmd.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ EMMC_ERROR_CODE emmc_exec_cmd(uint32_t error_mask, uint32_t *response)
254254
(SD_INFO2_ALL_ERR | SD_INFO2_CLEAR));
255255

256256
state = ESTATE_ISSUE_CMD;
257-
/* through */
258-
257+
/* fallthrough */
259258
case ESTATE_ISSUE_CMD:
260259
/* ARG */
261260
SETR_32(SD_ARG, mmc_drv_obj.cmd_info.arg);
@@ -454,8 +453,8 @@ EMMC_ERROR_CODE emmc_exec_cmd(uint32_t error_mask, uint32_t *response)
454453
SETR_32(SD_STOP, 0x00000000U);
455454
mmc_drv_obj.during_dma_transfer = FALSE;
456455
}
457-
/* through */
458456

457+
/* fallthrough */
459458
case ESTATE_ERROR:
460459
if (err_not_care_flag == TRUE) {
461460
mmc_drv_obj.during_cmd_processing = FALSE;

0 commit comments

Comments
 (0)