summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2013-07-30 17:26:20 -0700
committerChromeBot <chrome-bot@google.com>2013-07-31 12:33:31 -0700
commitaf777297370e971bd4ae64e0e947cb5a1774dbfe (patch)
tree282a090d2431626ce01e4940c4a4ca722d70166e
parentf6799258c3842ef855bf1516066464431b1b1a7d (diff)
downloadchrome-ec-af777297370e971bd4ae64e0e947cb5a1774dbfe.tar.gz
Add build-time checks on board-specific array sizes.
We've been declaring a bunch of statically-sized arrays: extern struct foo_t foo[FOO_COUNT]; And then initializing them like so: struct foo_t foo[FOO_COUNT] = { /* blah */ }; That only catches cases where we initialize with too many entries. It doesn't catch cases where we haven't initialized enough. This change tests for both cases like so: extern struct foo_t foo[]; struct foo_t foo[] = { /* blah */ }; BUILD_ASSERT(ARRAY_SIZE(foo) == FOO_COUNT); The affected arrays are: adc_channels[ADC_CH_COUNT] gpio_list[GPIO_COUNT] temp_sensors[TEMP_SENSOR_COUNT] x86_signal_list[X86_SIGNAL_COUNT] i2c_ports[I2C_PORTS_USED] BUG=chrome-os-partner:18343 BRANCH=falco,peppy TEST=build all platforms All platforms should still build, all tests should still pass. Change-Id: Ibb16dc3201f32df7cdc875648e89ba4ffb09f733 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/63833 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/bds/board.c9
-rw-r--r--board/bolt/board.c15
-rw-r--r--board/daisy/board.c6
-rw-r--r--board/falco/board.c15
-rw-r--r--board/host/board.c7
-rw-r--r--board/link/board.c15
-rw-r--r--board/mccroskey/board.c3
-rw-r--r--board/peppy/board.c15
-rw-r--r--board/pit/board.c6
-rw-r--r--board/puppy/board.c6
-rw-r--r--board/slippy/board.c15
-rw-r--r--board/snow/board.c6
-rw-r--r--board/spring/board.c9
-rw-r--r--board/wolf/board.c15
-rw-r--r--chip/lm4/i2c.c1
-rw-r--r--chip/lm4/lm4_adc.h2
-rw-r--r--chip/stm32/i2c-stm32l.c2
-rw-r--r--chip/stm32/stm32_adc.h2
-rw-r--r--common/i2c_common.c2
-rw-r--r--common/mock_temp_sensor.c6
-rw-r--r--include/gpio.h2
-rw-r--r--include/i2c.h2
-rw-r--r--include/temp_sensor.h2
23 files changed, 101 insertions, 62 deletions
diff --git a/board/bds/board.c b/board/bds/board.c
index 2794ff06db..830b8fcf41 100644
--- a/board/bds/board.c
+++ b/board/bds/board.c
@@ -12,7 +12,7 @@
#include "util.h"
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/* EC internal temperature is calculated by
* 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
* = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
@@ -29,19 +29,22 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
{"BDSPot", LM4_ADC_SEQ1, 33 * 4000, ADC_READ_MAX * 16, 0,
LM4_AIN(0), 0x06 /* IE0 | END0 */, LM4_GPIO_E, (1<<3)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
{"lightbar", I2C_PORT_LIGHTBAR, 400},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
{"RECOVERYn", LM4_GPIO_D, (1<<1), GPIO_PULL_UP, NULL},
{"DEBUG_LED", LM4_GPIO_A, (1<<7), GPIO_OUT_LOW, NULL},
/* Unimplemented signals which we need to emulate for now */
GPIO_SIGNAL_NOT_IMPLEMENTED("WP"),
GPIO_SIGNAL_NOT_IMPLEMENTED("ENTERING_RW"),
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
diff --git a/board/bolt/board.c b/board/bolt/board.c
index 6d5f35172b..c567749bff 100644
--- a/board/bolt/board.c
+++ b/board/bolt/board.c
@@ -30,7 +30,7 @@
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"POWER_BUTTON_L", LM4_GPIO_A, (1<<2), GPIO_INT_BOTH,
power_button_interrupt},
@@ -124,9 +124,10 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"USB2_ENABLE", LM4_GPIO_D, (1<<5), GPIO_OUT_HIGH, NULL},
{"USB2_ILIM_SEL", LM4_GPIO_D, (1<<6), GPIO_OUT_LOW, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* x86 signal list. Must match order of enum x86_signal. */
-const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
+const struct x86_signal_info x86_signal_list[] = {
{GPIO_PP5000_PGOOD, 1, "PGOOD_PP5000"},
{GPIO_PP1350_PGOOD, 1, "PGOOD_PP1350"},
{GPIO_PP1050_PGOOD, 1, "PGOOD_PP1050"},
@@ -136,9 +137,10 @@ const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
{GPIO_PCH_SLP_S5_L, 1, "SLP_S5#_DEASSERTED"},
{GPIO_PCH_SLP_SUS_L, 1, "SLP_SUS#_DEASSERTED"},
};
+BUILD_ASSERT(ARRAY_SIZE(x86_signal_list) == X86_SIGNAL_COUNT);
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/* EC internal temperature is calculated by
* 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
* = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
@@ -155,23 +157,26 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
{"ChargerCurrent", LM4_ADC_SEQ1, 33000, ADC_READ_MAX * 2, 0,
LM4_AIN(0), 0x06 /* IE0 | END0 */, LM4_GPIO_E, (1<<3)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
/* Note: battery and charger share a port. Only include it once in
* this list so we don't double-initialize it. */
{"batt_chg", I2C_PORT_BATTERY, 100},
{"lightbar", I2C_PORT_LIGHTBAR, 400},
{"thermal", I2C_PORT_THERMAL, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
-const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
+const struct temp_sensor_t temp_sensors[] = {
/* HEY: Need correct I2C addresses and read function for external sensor */
{"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 40,
diff --git a/board/daisy/board.c b/board/daisy/board.c
index 7a3a9bad66..39eda5e549 100644
--- a/board/daisy/board.c
+++ b/board/daisy/board.c
@@ -35,7 +35,7 @@
#define GPIO_KB_OUTPUT (GPIO_OUTPUT | GPIO_PULL_UP | GPIO_OPEN_DRAIN)
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"KB_PWR_ON_L", GPIO_B, (1<<5), GPIO_INT_BOTH, gaia_power_event},
{"PP1800_LDO2", GPIO_A, (1<<1), GPIO_INT_BOTH, gaia_power_event},
@@ -99,6 +99,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
/* Unimplemented signals which we need to emulate for now */
GPIO_SIGNAL_NOT_IMPLEMENTED("WP_L"),
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* Battery temperature ranges in degrees C */
const struct battery_temperature_ranges bat_temp_ranges = {
@@ -111,10 +112,11 @@ const struct battery_temperature_ranges bat_temp_ranges = {
};
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
{"0", 0, 100},
{"1", 1, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
/* Auto detect I2C host port
* Daisy board has two I2C ports, I2C1(0) and I2C2(1), that can be configured
diff --git a/board/falco/board.c b/board/falco/board.c
index 8b1980d9e6..3b9a197584 100644
--- a/board/falco/board.c
+++ b/board/falco/board.c
@@ -30,7 +30,7 @@
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"POWER_BUTTON_L", LM4_GPIO_A, (1<<2), GPIO_INT_BOTH,
power_button_interrupt},
@@ -123,9 +123,10 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"BAT_LED0", LM4_GPIO_D, (1<<0), GPIO_OUT_LOW, NULL},
{"BAT_LED1", LM4_GPIO_D, (1<<1), GPIO_OUT_LOW, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* x86 signal list. Must match order of enum x86_signal. */
-const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
+const struct x86_signal_info x86_signal_list[] = {
{GPIO_PP5000_PGOOD, 1, "PGOOD_PP5000"},
{GPIO_PP1350_PGOOD, 1, "PGOOD_PP1350"},
{GPIO_PP1050_PGOOD, 1, "PGOOD_PP1050"},
@@ -135,9 +136,10 @@ const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
{GPIO_PCH_SLP_S5_L, 1, "SLP_S5#_DEASSERTED"},
{GPIO_PCH_SLP_SUS_L, 1, "SLP_SUS#_DEASSERTED"},
};
+BUILD_ASSERT(ARRAY_SIZE(x86_signal_list) == X86_SIGNAL_COUNT);
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/* EC internal temperature is calculated by
* 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
* = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
@@ -158,23 +160,26 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
{"AdapterIDVoltage", LM4_ADC_SEQ2, 3300, ADC_READ_MAX, 0,
LM4_AIN(11), 0x06 /* IE0 | END0 */, LM4_GPIO_B, (1<<5)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
/* Note: battery and charger share a port. Only include it once in
* this list so we don't double-initialize it. */
{"batt_chg", I2C_PORT_BATTERY, 100},
{"lvds", I2C_PORT_LVDS, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
-const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
+const struct temp_sensor_t temp_sensors[] = {
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
{"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
{"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4},
{"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4},
};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 40,
diff --git a/board/host/board.c b/board/host/board.c
index 9e81cf60d3..13389ce001 100644
--- a/board/host/board.c
+++ b/board/host/board.c
@@ -6,10 +6,11 @@
#include "gpio.h"
#include "temp_sensor.h"
+#include "util.h"
#define MOCK_GPIO(x) {#x, 0, 0, 0, 0}
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
MOCK_GPIO(EC_INT),
MOCK_GPIO(LID_OPEN),
MOCK_GPIO(POWER_BUTTON_L),
@@ -17,6 +18,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
MOCK_GPIO(ENTERING_RW),
MOCK_GPIO(AC_PRESENT),
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
static int dummy_temp_get_val(int idx, int *temp_ptr)
{
@@ -24,8 +26,9 @@ static int dummy_temp_get_val(int idx, int *temp_ptr)
return EC_SUCCESS;
}
-const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
+const struct temp_sensor_t temp_sensors[] = {
{"CPU", TEMP_SENSOR_TYPE_CPU, dummy_temp_get_val, 0, 3},
{"Board", TEMP_SENSOR_TYPE_BOARD, dummy_temp_get_val, 0, 3},
{"Case", TEMP_SENSOR_TYPE_CASE, dummy_temp_get_val, 0, 0},
};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
diff --git a/board/link/board.c b/board/link/board.c
index 5c5bfb942e..b4fa8818b4 100644
--- a/board/link/board.c
+++ b/board/link/board.c
@@ -28,7 +28,7 @@
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"POWER_BUTTON_L", LM4_GPIO_K, (1<<7), GPIO_INT_BOTH,
power_button_interrupt},
@@ -122,9 +122,10 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"USB2_ENABLE", LM4_GPIO_D, (1<<7), GPIO_OUT_LOW, NULL},
{"USB2_ILIM_SEL", LM4_GPIO_E, (1<<0), GPIO_OUT_LOW, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* x86 signal list. Must match order of enum x86_signal. */
-const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
+const struct x86_signal_info x86_signal_list[] = {
{GPIO_PGOOD_5VALW, 1, "PGOOD_5VALW"},
{GPIO_PGOOD_1_5V_DDR, 1, "PGOOD_1_5V_DDR"},
{GPIO_PGOOD_1_5V_PCH, 1, "PGOOD_1_5V_PCH"},
@@ -140,9 +141,10 @@ const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
{GPIO_PCH_SLP_SUS_L, 1, "SLP_SUS#_DEASSERTED"},
{GPIO_PCH_SLP_ME_CSW_DEV_L, 1, "SLP_ME#_DEASSERTED"},
};
+BUILD_ASSERT(ARRAY_SIZE(x86_signal_list) == X86_SIGNAL_COUNT);
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/* EC internal temperature is calculated by
* 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
* = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
@@ -156,15 +158,17 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
{"ChargerCurrent", LM4_ADC_SEQ1, 33 * 4000, ADC_READ_MAX * 16, 0,
LM4_AIN(11), 0x06 /* IE0 | END0 */, LM4_GPIO_B, (1<<5)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
/* Note: battery and charger share a port. Only include it once in
* this list so we don't double-initialize it. */
{"batt_chg", I2C_PORT_BATTERY, 100},
{"lightbar", I2C_PORT_LIGHTBAR, 400},
{"thermal", I2C_PORT_THERMAL, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
#define TEMP_PCH_REG_ADDR ((0x41 << 1) | I2C_FLAG_BIG_ENDIAN)
#define TEMP_CHARGER_REG_ADDR ((0x43 << 1) | I2C_FLAG_BIG_ENDIAN)
@@ -177,7 +181,7 @@ const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
#define TEMP_HINGE_ADDR TMP006_ADDR(I2C_PORT_THERMAL, TEMP_HINGE_REG_ADDR)
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
-const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
+const struct temp_sensor_t temp_sensors[] = {
{"I2C-USB C-Die", TEMP_SENSOR_TYPE_IGNORED, tmp006_get_val, 0, 7},
{"I2C-USB C-Object", TEMP_SENSOR_TYPE_IGNORED, tmp006_get_val, 1, 7},
{"I2C-PCH D-Die", TEMP_SENSOR_TYPE_BOARD, tmp006_get_val, 2, 7},
@@ -189,6 +193,7 @@ const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
{"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
const struct tmp006_t tmp006_sensors[TMP006_COUNT] = {
{"USB C", TEMP_USB_ADDR},
diff --git a/board/mccroskey/board.c b/board/mccroskey/board.c
index cf27e98e9c..6f76563847 100644
--- a/board/mccroskey/board.c
+++ b/board/mccroskey/board.c
@@ -25,7 +25,7 @@
static void kbd_power_on(enum gpio_signal signal);
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"KB_IN00", GPIO_B, (1<<8), GPIO_KB_INPUT,
keyboard_raw_gpio_interrupt},
@@ -96,6 +96,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"OSC32_OUT", GPIO_C, (1<<15), GPIO_DEFAULT, NULL},
#endif
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
void board_config_pre_init(void)
{
diff --git a/board/peppy/board.c b/board/peppy/board.c
index 5ef8a56998..5a0cc05d5d 100644
--- a/board/peppy/board.c
+++ b/board/peppy/board.c
@@ -28,7 +28,7 @@
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"POWER_BUTTON_L", LM4_GPIO_A, (1<<2), GPIO_INT_BOTH,
power_button_interrupt},
@@ -122,9 +122,10 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"PWR_LED0_L", LM4_GPIO_D, (1<<1), GPIO_ODR_HIGH, NULL},
{"PWR_LED1_L", LM4_GPIO_N, (1<<6), GPIO_ODR_HIGH, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* x86 signal list. Must match order of enum x86_signal. */
-const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
+const struct x86_signal_info x86_signal_list[] = {
{GPIO_PP5000_PGOOD, 1, "PGOOD_PP5000"},
{GPIO_PP1350_PGOOD, 1, "PGOOD_PP1350"},
{GPIO_PP1050_PGOOD, 1, "PGOOD_PP1050"},
@@ -134,9 +135,10 @@ const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
{GPIO_PCH_SLP_S5_L, 1, "SLP_S5#_DEASSERTED"},
{GPIO_PCH_SLP_SUS_L, 1, "SLP_SUS#_DEASSERTED"},
};
+BUILD_ASSERT(ARRAY_SIZE(x86_signal_list) == X86_SIGNAL_COUNT);
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/* EC internal temperature is calculated by
* 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
* = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
@@ -151,23 +153,26 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
{"ChargerCurrent", LM4_ADC_SEQ1, 33 * 4000, ADC_READ_MAX * 16, 0,
LM4_AIN(0), 0x06 /* IE0 | END0 */, LM4_GPIO_E, (1<<3)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
/* Note: battery and charger share a port. Only include it once in
* this list so we don't double-initialize it. */
{"batt_chg", I2C_PORT_BATTERY, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
-const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
+const struct temp_sensor_t temp_sensors[] = {
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
{"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
{"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4},
{"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4},
};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 40,
diff --git a/board/pit/board.c b/board/pit/board.c
index c5167eb3a2..616716ae89 100644
--- a/board/pit/board.c
+++ b/board/pit/board.c
@@ -22,7 +22,7 @@
#define GPIO_KB_OUTPUT GPIO_ODR_HIGH
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"KB_PWR_ON_L", GPIO_B, (1<<5), GPIO_INT_BOTH, gaia_power_event},
{"PP1800_LDO2", GPIO_A, (1<<1), GPIO_INT_BOTH, gaia_power_event},
@@ -80,6 +80,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"KB_OUT11", GPIO_C, (1<<4), GPIO_KB_OUTPUT, NULL},
{"KB_OUT12", GPIO_A, (1<<13), GPIO_KB_OUTPUT, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* Battery temperature ranges in degrees C */
const struct battery_temperature_ranges bat_temp_ranges = {
@@ -92,9 +93,10 @@ const struct battery_temperature_ranges bat_temp_ranges = {
};
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
void board_config_post_gpio_init(void)
{
diff --git a/board/puppy/board.c b/board/puppy/board.c
index 607a94b7fc..0bb2eb3a6c 100644
--- a/board/puppy/board.c
+++ b/board/puppy/board.c
@@ -22,7 +22,7 @@
#define GPIO_KB_OUTPUT GPIO_ODR_HIGH
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"KB_PWR_ON_L", GPIO_B, (1<<5), GPIO_INT_BOTH, gaia_power_event},
{"PP1800_LDO2", GPIO_A, (1<<1), GPIO_INT_BOTH, gaia_power_event},
@@ -80,6 +80,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"KB_OUT11", GPIO_C, (1<<4), GPIO_KB_OUTPUT, NULL},
{"KB_OUT12", GPIO_A, (1<<13), GPIO_KB_OUTPUT, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* Battery temperature ranges in degrees C */
const struct battery_temperature_ranges bat_temp_ranges = {
@@ -92,9 +93,10 @@ const struct battery_temperature_ranges bat_temp_ranges = {
};
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
void board_config_post_gpio_init(void)
{
diff --git a/board/slippy/board.c b/board/slippy/board.c
index 0422e434e0..fbeb7e7224 100644
--- a/board/slippy/board.c
+++ b/board/slippy/board.c
@@ -28,7 +28,7 @@
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"POWER_BUTTON_L", LM4_GPIO_A, (1<<2), GPIO_INT_BOTH,
power_button_interrupt},
@@ -120,9 +120,10 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"BAT_LED0_L", LM4_GPIO_N, (1<<6), GPIO_ODR_HIGH, NULL},
{"BAT_LED1_L", LM4_GPIO_N, (1<<4), GPIO_ODR_HIGH, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* x86 signal list. Must match order of enum x86_signal. */
-const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
+const struct x86_signal_info x86_signal_list[] = {
{GPIO_PP5000_PGOOD, 1, "PGOOD_PP5000"},
{GPIO_PP1350_PGOOD, 1, "PGOOD_PP1350"},
{GPIO_PP1050_PGOOD, 1, "PGOOD_PP1050"},
@@ -132,9 +133,10 @@ const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
{GPIO_PCH_SLP_S5_L, 1, "SLP_S5#_DEASSERTED"},
{GPIO_PCH_SLP_SUS_L, 1, "SLP_SUS#_DEASSERTED"},
};
+BUILD_ASSERT(ARRAY_SIZE(x86_signal_list) == X86_SIGNAL_COUNT);
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/* EC internal temperature is calculated by
* 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
* = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
@@ -151,23 +153,26 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
{"ChargerCurrent", LM4_ADC_SEQ1, 33000, ADC_READ_MAX * 2, 0,
LM4_AIN(0), 0x06 /* IE0 | END0 */, LM4_GPIO_E, (1<<3)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
/* Note: battery and charger share a port. Only include it once in
* this list so we don't double-initialize it. */
{"batt_chg", I2C_PORT_BATTERY, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
-const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
+const struct temp_sensor_t temp_sensors[] = {
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
{"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
{"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4},
{"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4},
};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 40,
diff --git a/board/snow/board.c b/board/snow/board.c
index 7344db6aae..0199674acc 100644
--- a/board/snow/board.c
+++ b/board/snow/board.c
@@ -30,7 +30,7 @@
#define INT_BOTH_PULL_UP (GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH)
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"KB_PWR_ON_L", GPIO_B, (1<<5), GPIO_INT_BOTH, gaia_power_event},
{"PP1800_LDO2", GPIO_A, (1<<1), GPIO_INT_BOTH, gaia_power_event},
@@ -93,6 +93,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"KB_OUT11", GPIO_C, (1<<6), GPIO_KB_OUTPUT, NULL},
{"KB_OUT12", GPIO_C, (1<<7), GPIO_KB_OUTPUT, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* Battery temperature ranges in degrees C */
const struct battery_temperature_ranges bat_temp_ranges = {
@@ -105,9 +106,10 @@ const struct battery_temperature_ranges bat_temp_ranges = {
};
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
void board_config_pre_init(void)
{
diff --git a/board/spring/board.c b/board/spring/board.c
index b22545c5d7..40b6610113 100644
--- a/board/spring/board.c
+++ b/board/spring/board.c
@@ -31,7 +31,7 @@
#define INT_BOTH_PULL_UP (GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH)
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"KB_PWR_ON_L", GPIO_B, (1<<5), GPIO_INT_BOTH, gaia_power_event},
{"PP1800_LDO2", GPIO_A, (1<<1), GPIO_INT_BOTH, gaia_power_event},
@@ -93,6 +93,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"BOOST_EN", GPIO_B, (1<<3), GPIO_OUT_HIGH, NULL},
{"ILIM", GPIO_B, (1<<4), GPIO_OUT_LOW, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* Battery temperature ranges in degrees C */
const struct battery_temperature_ranges bat_temp_ranges = {
@@ -105,7 +106,7 @@ const struct battery_temperature_ranges bat_temp_ranges = {
};
/* ADC channels */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/*
* VBUS voltage sense pin.
* Sense pin 3.3V is converted to 4096. Accounting for the 2x
@@ -117,11 +118,13 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
/* Micro USB D- sense pin. Converted to mV (3300mV/4096). */
[ADC_CH_USB_DN_SNS] = {"USB_DN_SNS", 3300, 4096, 0, STM32_AIN(4)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
void board_config_pre_init(void)
{
diff --git a/board/wolf/board.c b/board/wolf/board.c
index 757bdd0ae2..fe0db01e86 100644
--- a/board/wolf/board.c
+++ b/board/wolf/board.c
@@ -27,7 +27,7 @@
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
-const struct gpio_info gpio_list[GPIO_COUNT] = {
+const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"POWER_BUTTON_L", LM4_GPIO_A, (1<<2), GPIO_INT_BOTH,
power_button_interrupt},
@@ -118,9 +118,10 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"BAT_LED0_L", LM4_GPIO_N, (1<<6), GPIO_ODR_HIGH, NULL},
{"BAT_LED1_L", LM4_GPIO_N, (1<<4), GPIO_ODR_HIGH, NULL},
};
+BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* x86 signal list. Must match order of enum x86_signal. */
-const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
+const struct x86_signal_info x86_signal_list[] = {
{GPIO_PP5000_PGOOD, 1, "PGOOD_PP5000"},
{GPIO_PP1350_PGOOD, 1, "PGOOD_PP1350"},
{GPIO_PP1050_PGOOD, 1, "PGOOD_PP1050"},
@@ -130,9 +131,10 @@ const struct x86_signal_info x86_signal_list[X86_SIGNAL_COUNT] = {
{GPIO_PCH_SLP_S5_L, 1, "SLP_S5#_DEASSERTED"},
{GPIO_PCH_SLP_SUS_L, 1, "SLP_SUS#_DEASSERTED"},
};
+BUILD_ASSERT(ARRAY_SIZE(x86_signal_list) == X86_SIGNAL_COUNT);
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
-const struct adc_t adc_channels[ADC_CH_COUNT] = {
+const struct adc_t adc_channels[] = {
/* EC internal temperature is calculated by
* 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
* = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
@@ -149,22 +151,25 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = {
{"ChargerCurrent", LM4_ADC_SEQ1, 33000, ADC_READ_MAX * 2, 0,
LM4_AIN(0), 0x06 /* IE0 | END0 */, LM4_GPIO_E, (1<<3)},
};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* I2C ports */
-const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
+const struct i2c_port_t i2c_ports[] = {
/* Note: battery and charger share a port. Only include it once in
* this list so we don't double-initialize it. */
{"batt_chg", I2C_PORT_BATTERY, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
+BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
-const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
+const struct temp_sensor_t temp_sensors[] = {
/* HEY: Need correct I2C addresses and read function for external sensor */
{"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 40,
diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c
index 390e0eef8b..abf82f62f4 100644
--- a/chip/lm4/i2c.c
+++ b/chip/lm4/i2c.c
@@ -38,7 +38,6 @@
#define LM4_I2C_MCS_CLKTO (1 << 7)
static task_id_t task_waiting_on_port[I2C_PORT_COUNT];
-extern const struct i2c_port_t i2c_ports[I2C_PORTS_USED];
/**
* Wait for port to go idle
diff --git a/chip/lm4/lm4_adc.h b/chip/lm4/lm4_adc.h
index 770c984209..45c9ef13a4 100644
--- a/chip/lm4/lm4_adc.h
+++ b/chip/lm4/lm4_adc.h
@@ -30,7 +30,7 @@ struct adc_t {
uint8_t gpio_mask;
};
-extern const struct adc_t adc_channels[ADC_CH_COUNT];
+extern const struct adc_t adc_channels[];
/* Minimum and maximum values returned by raw ADC read. */
#define ADC_READ_MIN 0
diff --git a/chip/stm32/i2c-stm32l.c b/chip/stm32/i2c-stm32l.c
index 0f258c1ce6..28df30fb75 100644
--- a/chip/stm32/i2c-stm32l.c
+++ b/chip/stm32/i2c-stm32l.c
@@ -18,8 +18,6 @@
#include "timer.h"
#include "util.h"
-extern const struct i2c_port_t i2c_ports[I2C_PORTS_USED];
-
/* Console output macros */
#define CPUTS(outstr) cputs(CC_I2C, outstr)
#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
diff --git a/chip/stm32/stm32_adc.h b/chip/stm32/stm32_adc.h
index 13186720ca..98141ea2d2 100644
--- a/chip/stm32/stm32_adc.h
+++ b/chip/stm32/stm32_adc.h
@@ -17,7 +17,7 @@ struct adc_t {
int channel;
};
-extern const struct adc_t adc_channels[ADC_CH_COUNT];
+extern const struct adc_t adc_channels[];
/* Minimum and maximum values returned by adc_read_channel(). */
#define ADC_READ_MIN 0
diff --git a/common/i2c_common.c b/common/i2c_common.c
index 79920e5a36..f18c8004f8 100644
--- a/common/i2c_common.c
+++ b/common/i2c_common.c
@@ -17,8 +17,6 @@
#define CPUTS(outstr) cputs(CC_I2C, outstr)
#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
-extern const struct i2c_port_t i2c_ports[I2C_PORTS_USED];
-
static struct mutex port_mutex[I2C_PORT_COUNT];
void i2c_lock(int port, int lock)
diff --git a/common/mock_temp_sensor.c b/common/mock_temp_sensor.c
index 3373e299a5..d558f8898e 100644
--- a/common/mock_temp_sensor.c
+++ b/common/mock_temp_sensor.c
@@ -11,12 +11,6 @@
#include "timer.h"
#include "util.h"
-/*
- * Defined in board_temp_sensor.c. Must be in the same order as
- * in enum temp_sensor_id.
- */
-extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
-
static int temp_val[TEMP_SENSOR_TYPE_COUNT];
int temp_sensor_powered(enum temp_sensor_id id)
diff --git a/include/gpio.h b/include/gpio.h
index b66b4be794..9517cf40ee 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -51,7 +51,7 @@ struct gpio_info {
};
/* Signal information from board.c. Must match order from enum gpio_signal. */
-extern const struct gpio_info gpio_list[GPIO_COUNT];
+extern const struct gpio_info gpio_list[];
/* Macro for signals which don't exist */
#ifdef CHIP_lm4
diff --git a/include/i2c.h b/include/i2c.h
index 86535c1fa8..747967b3a6 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -20,6 +20,8 @@ struct i2c_port_t {
int kbps; /* Speed in kbps */
};
+extern const struct i2c_port_t i2c_ports[];
+
/* Flags for i2c_xfer() */
#define I2C_XFER_START (1 << 0) /* Start smbus session from idle state */
#define I2C_XFER_STOP (1 << 1) /* Terminate smbus session with stop bit */
diff --git a/include/temp_sensor.h b/include/temp_sensor.h
index d3532426e6..c4943dda38 100644
--- a/include/temp_sensor.h
+++ b/include/temp_sensor.h
@@ -45,7 +45,7 @@ struct temp_sensor_t {
* Defined in board_temp_sensor.c. Must be in the same order as
* in enum temp_sensor_id.
*/
-extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
+extern const struct temp_sensor_t temp_sensors[];
#endif
/**