From 1a194b34e19852f891b563eae99f6dd892b334dd Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Fri, 1 Nov 2019 11:38:36 -0500 Subject: [PATCH 1/6] linker: move where we define _LINKER and _ASMLANGUAGE Move _LINKER and _ASMLANGUAGE to target.cmake because of how we pick the linker script that might be used. This way regardless of how or where a linker.ld gets included we will always set _LINKER & _ASMLANGUAGE (so any header that needs check based on those defines they can, specifically generated_dts_board.h) Signed-off-by: Kumar Gala --- cmake/linker/ld/target.cmake | 2 ++ include/arch/arc/v2/linker.ld | 3 --- include/arch/arm/cortex_m/scripts/linker.ld | 3 --- include/arch/arm/cortex_r/scripts/linker.ld | 3 --- include/arch/nios2/linker.ld | 3 --- include/arch/posix/linker.ld | 3 --- include/arch/riscv/common/linker.ld | 3 --- include/arch/x86/ia32/linker.ld | 3 --- include/arch/x86/intel64/linker.ld | 3 --- .../code_relocation/linker_arm_sram2.ld | 3 --- soc/riscv/openisa_rv32m1/linker.ld | 3 --- soc/xtensa/esp32/linker.ld | 3 --- soc/xtensa/intel_s1000/linker.ld | 2 -- soc/xtensa/sample_controller/linker.ld | 3 --- 14 files changed, 2 insertions(+), 38 deletions(-) diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index d3f63e474af76..9523f4298545e 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -41,6 +41,8 @@ macro(configure_linker_script linker_script_gen linker_pass_define) -x assembler-with-cpp ${NOSYSDEF_CFLAG} -MD -MF ${linker_script_gen}.dep -MT ${base_name}/${linker_script_gen} + -D_LINKER + -D_ASMLANGUAGE ${current_includes} ${current_defines} ${linker_pass_define} diff --git a/include/arch/arc/v2/linker.ld b/include/arch/arc/v2/linker.ld index ef4db72ae89b4..69458f62e453f 100644 --- a/include/arch/arc/v2/linker.ld +++ b/include/arch/arc/v2/linker.ld @@ -8,9 +8,6 @@ * @brief Common parts of the linker scripts for the ARCv2/EM targets. */ -#define _LINKER -#define _ASMLANGUAGE - #include #if defined(CONFIG_UART_NSIM) diff --git a/include/arch/arm/cortex_m/scripts/linker.ld b/include/arch/arm/cortex_m/scripts/linker.ld index e94fd90451119..478a4d45045f8 100644 --- a/include/arch/arm/cortex_m/scripts/linker.ld +++ b/include/arch/arm/cortex_m/scripts/linker.ld @@ -11,9 +11,6 @@ * Linker script for the Cortex-M platforms. */ -#define _LINKER -#define _ASMLANGUAGE - #include #include #include diff --git a/include/arch/arm/cortex_r/scripts/linker.ld b/include/arch/arm/cortex_r/scripts/linker.ld index 0685fbd3d6c74..dc08d6c3bf157 100644 --- a/include/arch/arm/cortex_r/scripts/linker.ld +++ b/include/arch/arm/cortex_r/scripts/linker.ld @@ -11,9 +11,6 @@ * Linker script for the Cortex-R platforms. */ -#define _LINKER -#define _ASMLANGUAGE - #include #include #include diff --git a/include/arch/nios2/linker.ld b/include/arch/nios2/linker.ld index cb2ecdc39d25d..f754cc1f9b361 100644 --- a/include/arch/nios2/linker.ld +++ b/include/arch/nios2/linker.ld @@ -11,9 +11,6 @@ * Linker script for the Nios II platform */ -#define _LINKER -#define _ASMLANGUAGE - #include #include diff --git a/include/arch/posix/linker.ld b/include/arch/posix/linker.ld index 8511fb7b1539e..ef41e52d97c4a 100644 --- a/include/arch/posix/linker.ld +++ b/include/arch/posix/linker.ld @@ -12,9 +12,6 @@ * Linker script for the POSIX (native) platform */ -#define _LINKER -#define _ASMLANGUAGE - #include #include diff --git a/include/arch/riscv/common/linker.ld b/include/arch/riscv/common/linker.ld index 753fdabf6a143..cff2b6bd521cd 100644 --- a/include/arch/riscv/common/linker.ld +++ b/include/arch/riscv/common/linker.ld @@ -11,9 +11,6 @@ * Generic Linker script for the riscv platform */ -#define _LINKER -#define _ASMLANGUAGE - #include #include diff --git a/include/arch/x86/ia32/linker.ld b/include/arch/x86/ia32/linker.ld index b74ec8e15744f..e6df4475de4cc 100644 --- a/include/arch/x86/ia32/linker.ld +++ b/include/arch/x86/ia32/linker.ld @@ -37,9 +37,6 @@ * order when programming the MMU. */ -#define _LINKER - -#define _ASMLANGUAGE #include #include #include diff --git a/include/arch/x86/intel64/linker.ld b/include/arch/x86/intel64/linker.ld index fe75b1d63ac05..e4424a4b5a4b8 100644 --- a/include/arch/x86/intel64/linker.ld +++ b/include/arch/x86/intel64/linker.ld @@ -3,9 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define _LINKER -#define _ASMLANGUAGE - #include #include diff --git a/samples/application_development/code_relocation/linker_arm_sram2.ld b/samples/application_development/code_relocation/linker_arm_sram2.ld index b7122991dda6a..e1e1cbed3ade2 100644 --- a/samples/application_development/code_relocation/linker_arm_sram2.ld +++ b/samples/application_development/code_relocation/linker_arm_sram2.ld @@ -11,9 +11,6 @@ * Linker script for the Cortex-M platforms. */ -#define _LINKER -#define _ASMLANGUAGE - #include #include #include diff --git a/soc/riscv/openisa_rv32m1/linker.ld b/soc/riscv/openisa_rv32m1/linker.ld index c8e86e3f9e489..7fe1ae9a6fd4f 100644 --- a/soc/riscv/openisa_rv32m1/linker.ld +++ b/soc/riscv/openisa_rv32m1/linker.ld @@ -12,9 +12,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define _LINKER -#define _ASMLANGUAGE - #include #include diff --git a/soc/xtensa/esp32/linker.ld b/soc/xtensa/esp32/linker.ld index 8085eda03bbe2..054ed9c20f92f 100644 --- a/soc/xtensa/esp32/linker.ld +++ b/soc/xtensa/esp32/linker.ld @@ -11,9 +11,6 @@ * Linker script for the Xtensa platform. */ -#define _LINKER -#define _ASMLANGUAGE - #include #include #include diff --git a/soc/xtensa/intel_s1000/linker.ld b/soc/xtensa/intel_s1000/linker.ld index 251cae3e115e2..8ebf7c911707d 100644 --- a/soc/xtensa/intel_s1000/linker.ld +++ b/soc/xtensa/intel_s1000/linker.ld @@ -12,8 +12,6 @@ */ OUTPUT_ARCH(xtensa) -#define _LINKER -#define _ASMLANGUAGE #include #include "memory.h" diff --git a/soc/xtensa/sample_controller/linker.ld b/soc/xtensa/sample_controller/linker.ld index 72370478d5336..e040e67968700 100644 --- a/soc/xtensa/sample_controller/linker.ld +++ b/soc/xtensa/sample_controller/linker.ld @@ -10,9 +10,6 @@ * Linker script for the Xtensa platform. */ -#define _LINKER -#define _ASMLANGUAGE - #include #include From d77f3aa6fc36aafe6f20b994679aff6089c7ee95 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Fri, 1 Nov 2019 05:23:51 -0500 Subject: [PATCH 2/6] device: change struct device to non-static As a pre-cursor to use DT to get access to the struct device directly we need to remove the static init of a struct device.h Signed-off-by: Kumar Gala --- drivers/counter/counter_gecko_rtcc.c | 2 +- drivers/dma/dma_cavs.c | 2 +- drivers/dma/dma_nios2_msgdma.c | 2 +- drivers/dma/dma_sam_xdmac.c | 2 +- drivers/ethernet/eth_e1000.c | 2 +- drivers/ethernet/eth_sam_gmac.c | 2 +- drivers/ethernet/eth_smsc911x.c | 2 +- drivers/ethernet/eth_stellaris.c | 2 +- drivers/ethernet/eth_stm32_hal.c | 2 +- drivers/gpio/gpio_cc32xx.c | 8 ++++---- drivers/i2c/i2c_sam_twi.c | 4 ++-- drivers/i2c/i2c_sam_twihs.c | 6 +++--- drivers/i2s/i2s_ll_stm32.c | 10 +++++----- drivers/i2s/i2s_sam_ssc.c | 2 +- drivers/neural_net/intel_gna.c | 2 +- drivers/serial/uart_cc32xx.c | 2 +- drivers/serial/uart_msp432p4xx.c | 2 +- drivers/watchdog/wdt_sam.c | 2 +- drivers/watchdog/wdt_sam0.c | 2 +- include/device.h | 6 +++--- 20 files changed, 32 insertions(+), 32 deletions(-) diff --git a/drivers/counter/counter_gecko_rtcc.c b/drivers/counter/counter_gecko_rtcc.c index 16c17e6f6252e..16abb7ea87399 100644 --- a/drivers/counter/counter_gecko_rtcc.c +++ b/drivers/counter/counter_gecko_rtcc.c @@ -320,7 +320,7 @@ static const struct counter_driver_api counter_gecko_driver_api = { /* RTCC0 */ -static struct device DEVICE_NAME_GET(counter_gecko_0); +struct device DEVICE_NAME_GET(counter_gecko_0); ISR_DIRECT_DECLARE(counter_gecko_isr_0) { diff --git a/drivers/dma/dma_cavs.c b/drivers/dma/dma_cavs.c index c954633cbcf2e..aa9be7a81ddab 100644 --- a/drivers/dma/dma_cavs.c +++ b/drivers/dma/dma_cavs.c @@ -362,7 +362,7 @@ static const struct dma_driver_api dw_dma_driver_api = { /* DMA0 */ -static struct device DEVICE_NAME_GET(dw_dma0); +struct device DEVICE_NAME_GET(dw_dma0); static void dw_dma0_irq_config(void) { diff --git a/drivers/dma/dma_nios2_msgdma.c b/drivers/dma/dma_nios2_msgdma.c index 6e164229033ad..e3324c39b95da 100644 --- a/drivers/dma/dma_nios2_msgdma.c +++ b/drivers/dma/dma_nios2_msgdma.c @@ -204,7 +204,7 @@ static const struct dma_driver_api nios2_msgdma_driver_api = { }; /* DMA0 */ -static struct device DEVICE_NAME_GET(dma0_nios2); +struct device DEVICE_NAME_GET(dma0_nios2); static int nios2_msgdma0_initialize(struct device *dev) { diff --git a/drivers/dma/dma_sam_xdmac.c b/drivers/dma/dma_sam_xdmac.c index e9521235132eb..bbdddbd0b42dc 100644 --- a/drivers/dma/dma_sam_xdmac.c +++ b/drivers/dma/dma_sam_xdmac.c @@ -346,7 +346,7 @@ static const struct dma_driver_api sam_xdmac_driver_api = { /* DMA0 */ -static struct device DEVICE_NAME_GET(dma0_sam); +struct device DEVICE_NAME_GET(dma0_sam); static void dma0_sam_irq_config(void) { diff --git a/drivers/ethernet/eth_e1000.c b/drivers/ethernet/eth_e1000.c index 8f78cc62a99ad..4c571cdf517fa 100644 --- a/drivers/ethernet/eth_e1000.c +++ b/drivers/ethernet/eth_e1000.c @@ -152,7 +152,7 @@ int e1000_probe(struct device *device) return retval; } -static struct device DEVICE_NAME_GET(eth_e1000); +struct device DEVICE_NAME_GET(eth_e1000); static void e1000_init(struct net_if *iface) { diff --git a/drivers/ethernet/eth_sam_gmac.c b/drivers/ethernet/eth_sam_gmac.c index 47a0e37f0361d..d97bac827a948 100644 --- a/drivers/ethernet/eth_sam_gmac.c +++ b/drivers/ethernet/eth_sam_gmac.c @@ -1930,7 +1930,7 @@ static const struct ethernet_api eth_api = { #endif }; -static struct device DEVICE_NAME_GET(eth0_sam_gmac); +struct device DEVICE_NAME_GET(eth0_sam_gmac); static void eth0_irq_config(void) { diff --git a/drivers/ethernet/eth_smsc911x.c b/drivers/ethernet/eth_smsc911x.c index 209cee19a14ec..6b3852aae757d 100644 --- a/drivers/ethernet/eth_smsc911x.c +++ b/drivers/ethernet/eth_smsc911x.c @@ -655,7 +655,7 @@ static void eth_smsc911x_isr(struct device *dev) /* Bindings to the platform */ -static struct device DEVICE_NAME_GET(eth_smsc911x_0); +struct device DEVICE_NAME_GET(eth_smsc911x_0); int eth_init(struct device *dev) { diff --git a/drivers/ethernet/eth_stellaris.c b/drivers/ethernet/eth_stellaris.c index 01a70d2dd3561..f3f3ea18d1103 100644 --- a/drivers/ethernet/eth_stellaris.c +++ b/drivers/ethernet/eth_stellaris.c @@ -318,7 +318,7 @@ static int eth_stellaris_dev_init(struct device *dev) return 0; } -static struct device DEVICE_NAME_GET(eth_stellaris); +struct device DEVICE_NAME_GET(eth_stellaris); static void eth_stellaris_irq_config(struct device *dev) { diff --git a/drivers/ethernet/eth_stm32_hal.c b/drivers/ethernet/eth_stm32_hal.c index 2d53673ced0f2..f76354796585a 100644 --- a/drivers/ethernet/eth_stm32_hal.c +++ b/drivers/ethernet/eth_stm32_hal.c @@ -489,7 +489,7 @@ static const struct ethernet_api eth_api = { .send = eth_tx, }; -static struct device DEVICE_NAME_GET(eth0_stm32_hal); +struct device DEVICE_NAME_GET(eth0_stm32_hal); static void eth0_irq_config(void) { diff --git a/drivers/gpio/gpio_cc32xx.c b/drivers/gpio/gpio_cc32xx.c index 3aacc04b632ef..7d0d61bb8e17c 100644 --- a/drivers/gpio/gpio_cc32xx.c +++ b/drivers/gpio/gpio_cc32xx.c @@ -202,7 +202,7 @@ static const struct gpio_cc32xx_config gpio_cc32xx_a0_config = { .irq_num = DT_GPIO_CC32XX_A0_IRQ+16, }; -static struct device DEVICE_NAME_GET(gpio_cc32xx_a0); +struct device DEVICE_NAME_GET(gpio_cc32xx_a0); static struct gpio_cc32xx_data gpio_cc32xx_a0_data; static int gpio_cc32xx_a0_init(struct device *dev) @@ -232,7 +232,7 @@ static const struct gpio_cc32xx_config gpio_cc32xx_a1_config = { .irq_num = DT_GPIO_CC32XX_A1_IRQ+16, }; -static struct device DEVICE_NAME_GET(gpio_cc32xx_a1); +struct device DEVICE_NAME_GET(gpio_cc32xx_a1); static struct gpio_cc32xx_data gpio_cc32xx_a1_data; static int gpio_cc32xx_a1_init(struct device *dev) @@ -262,7 +262,7 @@ static const struct gpio_cc32xx_config gpio_cc32xx_a2_config = { .irq_num = DT_GPIO_CC32XX_A2_IRQ+16, }; -static struct device DEVICE_NAME_GET(gpio_cc32xx_a2); +struct device DEVICE_NAME_GET(gpio_cc32xx_a2); static struct gpio_cc32xx_data gpio_cc32xx_a2_data; static int gpio_cc32xx_a2_init(struct device *dev) @@ -292,7 +292,7 @@ static const struct gpio_cc32xx_config gpio_cc32xx_a3_config = { .irq_num = DT_GPIO_CC32XX_A3_IRQ+16, }; -static struct device DEVICE_NAME_GET(gpio_cc32xx_a3); +struct device DEVICE_NAME_GET(gpio_cc32xx_a3); static struct gpio_cc32xx_data gpio_cc32xx_a3_data; static int gpio_cc32xx_a3_init(struct device *dev) diff --git a/drivers/i2c/i2c_sam_twi.c b/drivers/i2c/i2c_sam_twi.c index 4708cee614bff..599fce1ec0544 100644 --- a/drivers/i2c/i2c_sam_twi.c +++ b/drivers/i2c/i2c_sam_twi.c @@ -339,7 +339,7 @@ static const struct i2c_driver_api i2c_sam_twi_driver_api = { /* I2C0 */ #ifdef CONFIG_I2C_0 -static struct device DEVICE_NAME_GET(i2c0_sam); +struct device DEVICE_NAME_GET(i2c0_sam); static void i2c0_sam_irq_config(void) { @@ -369,7 +369,7 @@ DEVICE_AND_API_INIT(i2c0_sam, DT_I2C_0_NAME, &i2c_sam_twi_initialize, /* I2C1 */ #ifdef CONFIG_I2C_1 -static struct device DEVICE_NAME_GET(i2c1_sam); +struct device DEVICE_NAME_GET(i2c1_sam); static void i2c1_sam_irq_config(void) { diff --git a/drivers/i2c/i2c_sam_twihs.c b/drivers/i2c/i2c_sam_twihs.c index 320232999dfe2..fcff6483f3f91 100644 --- a/drivers/i2c/i2c_sam_twihs.c +++ b/drivers/i2c/i2c_sam_twihs.c @@ -326,7 +326,7 @@ static const struct i2c_driver_api i2c_sam_twihs_driver_api = { /* I2C0 */ #ifdef CONFIG_I2C_0 -static struct device DEVICE_NAME_GET(i2c0_sam); +struct device DEVICE_NAME_GET(i2c0_sam); static void i2c0_sam_irq_config(void) { @@ -356,7 +356,7 @@ DEVICE_AND_API_INIT(i2c0_sam, DT_I2C_0_NAME, &i2c_sam_twihs_initialize, /* I2C1 */ #ifdef CONFIG_I2C_1 -static struct device DEVICE_NAME_GET(i2c1_sam); +struct device DEVICE_NAME_GET(i2c1_sam); static void i2c1_sam_irq_config(void) { @@ -386,7 +386,7 @@ DEVICE_AND_API_INIT(i2c1_sam, DT_I2C_1_NAME, &i2c_sam_twihs_initialize, /* I2C2 */ #ifdef CONFIG_I2C_2 -static struct device DEVICE_NAME_GET(i2c2_sam); +struct device DEVICE_NAME_GET(i2c2_sam); static void i2c2_sam_irq_config(void) { diff --git a/drivers/i2s/i2s_ll_stm32.c b/drivers/i2s/i2s_ll_stm32.c index 76c8b40bb4b4f..1453199e3d51a 100644 --- a/drivers/i2s/i2s_ll_stm32.c +++ b/drivers/i2s/i2s_ll_stm32.c @@ -819,7 +819,7 @@ static struct device *get_dev_from_tx_dma_channel(u32_t dma_channel) } #ifdef CONFIG_I2S_1 -static struct device DEVICE_NAME_GET(i2s_stm32_1); +struct device DEVICE_NAME_GET(i2s_stm32_1); static void i2s_stm32_irq_config_func_1(struct device *dev); @@ -889,7 +889,7 @@ static void i2s_stm32_irq_config_func_1(struct device *dev) #endif /* CONFIG_I2S_1 */ #ifdef CONFIG_I2S_2 -static struct device DEVICE_NAME_GET(i2s_stm32_2); +struct device DEVICE_NAME_GET(i2s_stm32_2); static void i2s_stm32_irq_config_func_2(struct device *dev); @@ -959,7 +959,7 @@ static void i2s_stm32_irq_config_func_2(struct device *dev) #endif /* CONFIG_I2S_2 */ #ifdef CONFIG_I2S_3 -static struct device DEVICE_NAME_GET(i2s_stm32_3); +struct device DEVICE_NAME_GET(i2s_stm32_3); static void i2s_stm32_irq_config_func_3(struct device *dev); @@ -1029,7 +1029,7 @@ static void i2s_stm32_irq_config_func_3(struct device *dev) #endif /* CONFIG_I2S_3 */ #ifdef CONFIG_I2S_4 -static struct device DEVICE_NAME_GET(i2s_stm32_4); +struct device DEVICE_NAME_GET(i2s_stm32_4); static void i2s_stm32_irq_config_func_4(struct device *dev); @@ -1099,7 +1099,7 @@ static void i2s_stm32_irq_config_func_4(struct device *dev) #endif /* CONFIG_I2S_4 */ #ifdef CONFIG_I2S_5 -static struct device DEVICE_NAME_GET(i2s_stm32_5); +struct device DEVICE_NAME_GET(i2s_stm32_5); static void i2s_stm32_irq_config_func_5(struct device *dev); diff --git a/drivers/i2s/i2s_sam_ssc.c b/drivers/i2s/i2s_sam_ssc.c index 2d3d06c61ea2b..cd377820764bd 100644 --- a/drivers/i2s/i2s_sam_ssc.c +++ b/drivers/i2s/i2s_sam_ssc.c @@ -951,7 +951,7 @@ static const struct i2s_driver_api i2s_sam_driver_api = { /* I2S0 */ -static struct device DEVICE_NAME_GET(i2s0_sam); +struct device DEVICE_NAME_GET(i2s0_sam); static struct device *get_dev_from_dma_channel(u32_t dma_channel) { diff --git a/drivers/neural_net/intel_gna.c b/drivers/neural_net/intel_gna.c index e2b6c9466c4e6..fad7872a2a7cd 100644 --- a/drivers/neural_net/intel_gna.c +++ b/drivers/neural_net/intel_gna.c @@ -42,7 +42,7 @@ static void intel_gna_config_desc_dump(struct device *dev); #define GNA_MODEL_VIRT_BASE_DEFAULT 0 -static struct device DEVICE_NAME_GET(gna); +struct device DEVICE_NAME_GET(gna); static struct intel_gna_config_desc __aligned(GNA_PG_SIZE_IN_BYTES) gna_config_desc; static struct intel_gna_page_table __aligned(GNA_PG_SIZE_IN_BYTES) diff --git a/drivers/serial/uart_cc32xx.c b/drivers/serial/uart_cc32xx.c index 0b29ed83c4b1d..32ba369e5a8c3 100644 --- a/drivers/serial/uart_cc32xx.c +++ b/drivers/serial/uart_cc32xx.c @@ -30,7 +30,7 @@ struct uart_cc32xx_dev_data_t { #define PRIME_CHAR '\r' /* Forward decls: */ -static struct device DEVICE_NAME_GET(uart_cc32xx_0); +struct device DEVICE_NAME_GET(uart_cc32xx_0); #ifdef CONFIG_UART_INTERRUPT_DRIVEN static void uart_cc32xx_isr(void *arg); diff --git a/drivers/serial/uart_msp432p4xx.c b/drivers/serial/uart_msp432p4xx.c index b749511891b62..71fd3dbb4f188 100644 --- a/drivers/serial/uart_msp432p4xx.c +++ b/drivers/serial/uart_msp432p4xx.c @@ -31,7 +31,7 @@ struct uart_msp432p4xx_dev_data_t { #define DEV_DATA(dev) \ ((struct uart_msp432p4xx_dev_data_t * const)(dev)->driver_data) -static struct device DEVICE_NAME_GET(uart_msp432p4xx_0); +struct device DEVICE_NAME_GET(uart_msp432p4xx_0); #ifdef CONFIG_UART_INTERRUPT_DRIVEN static void uart_msp432p4xx_isr(void *arg); diff --git a/drivers/watchdog/wdt_sam.c b/drivers/watchdog/wdt_sam.c index 70153da243ff0..3253c2664f847 100644 --- a/drivers/watchdog/wdt_sam.c +++ b/drivers/watchdog/wdt_sam.c @@ -32,7 +32,7 @@ struct wdt_sam_dev_cfg { Wdt *regs; }; -static struct device DEVICE_NAME_GET(wdt_sam); +struct device DEVICE_NAME_GET(wdt_sam); struct wdt_sam_dev_data { wdt_callback_t cb; diff --git a/drivers/watchdog/wdt_sam0.c b/drivers/watchdog/wdt_sam0.c index fe08af179aae3..a4c163993bd50 100644 --- a/drivers/watchdog/wdt_sam0.c +++ b/drivers/watchdog/wdt_sam0.c @@ -19,7 +19,7 @@ struct wdt_sam0_dev_data { bool timeout_valid; }; -static struct device DEVICE_NAME_GET(wdt_sam0); +struct device DEVICE_NAME_GET(wdt_sam0); static struct wdt_sam0_dev_data wdt_sam0_data = { 0 }; diff --git a/include/device.h b/include/device.h index d6cdc21d5aab0..ba873a2499e9a 100644 --- a/include/device.h +++ b/include/device.h @@ -107,7 +107,7 @@ extern "C" { .name = drv_name, .init = (init_fn), \ .config_info = (cfg_info) \ }; \ - static Z_DECL_ALIGN(struct device) _CONCAT(__device_, dev_name) __used \ + Z_DECL_ALIGN(struct device) _CONCAT(__device_, dev_name) __used \ __attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \ .config = &_CONCAT(__config_, dev_name), \ .driver_api = api, \ @@ -164,7 +164,7 @@ extern "C" { .pm = &_CONCAT(__pm_, dev_name), \ .config_info = (cfg_info) \ }; \ - static Z_DECL_ALIGN(struct device) _CONCAT(__device_, dev_name) __used \ + Z_DECL_ALIGN(struct device) _CONCAT(__device_, dev_name) __used \ __attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \ .config = &_CONCAT(__config_, dev_name), \ .driver_api = api, \ @@ -218,7 +218,7 @@ extern "C" { * * @param name Device name */ -#define DEVICE_DECLARE(name) static struct device DEVICE_NAME_GET(name) +#define DEVICE_DECLARE(name) struct device DEVICE_NAME_GET(name) struct device; From a1ac49346b8fe5a5a0058e98a4c5564945e19b00 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 30 Oct 2019 23:59:20 -0500 Subject: [PATCH 3/6] dts: gen_defines: generate ZDID for devices Introduce a Zephyr Device ID value that we can use to reference DT nodes by a number.... Signed-off-by: Kumar Gala add zdid support --- scripts/dts/gen_defines.py | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index 08873700bc384..7db543e3e36f5 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -29,6 +29,7 @@ def main(): global conf_file global header_file + global node2zdid args = parse_args() @@ -53,6 +54,28 @@ def main(): active_compats = set() + zdid = 1 + node2zdid = {} + + # Assign a ZDID (Zephyr Device ID) to all nodes before we start + # we do this as references to nodes like bus parents or via phandles + # may happen before we've iterated the referenced node, so we assign + # the ZDID for everyone first. + + print("\n#ifndef _ASMLANGUAGE", file=header_file) + for node in edt.nodes: + if node.enabled and node.matching_compat: + # Skip 'fixed-partitions' devices since they are handled by + # write_flash() and would generate extra spurious #defines + if node.matching_compat == "fixed-partitions": + continue + + node2zdid[node] = zdid + zdid += 1 + print("extern struct device __device_{}; /* {}*/" + .format(node2zdid[node], node.path), file=header_file) + print("#endif", file=header_file) + for node in edt.nodes: if node.enabled and node.matching_compat: # Skip 'fixed-partitions' devices since they are handled by @@ -82,6 +105,8 @@ def main(): write_bus(node) write_existence_flags(node) + out_dev_zdid(node, "", node2zdid[node]) + active_compats.update(node.compats) out_comment("Active compatibles (mentioned in DTS + binding found)") @@ -229,6 +254,9 @@ def write_bus(node): # #define DT__BUS_NAME out_dev_s(node, "BUS_NAME", str2ident(node.parent.label)) + # #define DT_ZDID__BUS + out_dev_zdid(node, "BUS", node2zdid[node.parent]) + for compat in node.compats: # #define DT__BUS_ 1 out("{}_BUS_{}".format(str2ident(compat), str2ident(node.bus)), 1) @@ -553,6 +581,8 @@ def write_phandle_val_list_entry(node, entry, i, ident): initializer_vals.append(quote_str(entry.controller.label)) out_dev_s(node, ctrl_ident, entry.controller.label) + out_dev_zdid(node, ctrl_ident, node2zdid[entry.controller]) + for cell, val in entry.data.items(): cell_ident = ident + "_" + str2ident(cell) # e.g. PWMS_CHANNEL if entry.name: @@ -662,6 +692,30 @@ def out_dev_s(node, ident, s): return out_dev(node, ident, quote_str(s)) +def out_dev_zdid(node, ident, val): + # Writes an + # + # ZDID__ = + # + # assignment, along with a set of + # + # ZDID__ + # + # aliases, for each device alias. + # + # Returns the identifier used for the macro that provides the value + # for 'ident' within 'node', e.g. DT_MFG_MODEL_CTL_GPIOS_PIN. + + dev_prefix = dev_ident(node) + + if ident: + ident = "_" + ident + + aliases = ["ZDID_" + alias + ident for alias in dev_aliases(node)] + + return out("ZDID_" + dev_prefix + ident, val, aliases) + + def out_s(ident, val): # Like out(), but puts quotes around 'val' and escapes any double # quotes and backslashes within it From 3018d7a4e71ad00dad0b0deee94d29f6b69f85a0 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 31 Oct 2019 00:00:32 -0500 Subject: [PATCH 4/6] device: Introduce DT based init of device struct Introduce DEVICE_AND_API_INIT_DT to uses DTS ZDID construct to define the name of the struct in a consistent manor. We also remove the static define from the 'struct device' since we will be able to directly provide access to it. Signed-off-by: Kumar Gala --- include/device.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/device.h b/include/device.h index ba873a2499e9a..0d7a499a3de98 100644 --- a/include/device.h +++ b/include/device.h @@ -9,6 +9,7 @@ #define ZEPHYR_INCLUDE_DEVICE_H_ #include +#include /** * @brief Device Driver APIs @@ -126,6 +127,12 @@ extern "C" { prio, api) #endif +#define DEVICE_AND_API_INIT_DT(dev_name, inst, init_fn, data, cfg_info, \ + level, prio, api) \ + DEVICE_AND_API_INIT(DT_ZDID_INST_##inst##_##dev_name,\ + DT_INST_##inst##_##dev_name##_LABEL,\ + init_fn, data, cfg_info, level, prio, api) + /** * @def DEVICE_DEFINE * From be64928a3fdb766e1f40d75a26543c409085b4e5 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 31 Oct 2019 00:01:22 -0500 Subject: [PATCH 5/6] i2c: gecko: convert to use new DEVICE_AND_API_INIT_DT make device driver DT api friendly. Signed-off-by: Kumar Gala --- drivers/i2c/i2c_gecko.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c_gecko.c b/drivers/i2c/i2c_gecko.c index e1b93d54d04cb..40a938fa1e87d 100644 --- a/drivers/i2c/i2c_gecko.c +++ b/drivers/i2c/i2c_gecko.c @@ -211,7 +211,7 @@ static struct i2c_gecko_config i2c_gecko_config_0 = { static struct i2c_gecko_data i2c_gecko_data_0; -DEVICE_AND_API_INIT(i2c_gecko_0, DT_INST_0_SILABS_GECKO_I2C_LABEL, +DEVICE_AND_API_INIT_DT(SILABS_GECKO_I2C, 0, &i2c_gecko_init, &i2c_gecko_data_0, &i2c_gecko_config_0, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &i2c_gecko_driver_api); @@ -245,7 +245,7 @@ static struct i2c_gecko_config i2c_gecko_config_1 = { static struct i2c_gecko_data i2c_gecko_data_1; -DEVICE_AND_API_INIT(i2c_gecko_1, DT_INST_1_SILABS_GECKO_I2C_LABEL, +DEVICE_AND_API_INIT_DT(SILABS_GECKO_I2C, 1, &i2c_gecko_init, &i2c_gecko_data_1, &i2c_gecko_config_1, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &i2c_gecko_driver_api); From e362e7838ad317306f71dd85b90be63541cdeadb Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 31 Oct 2019 00:02:07 -0500 Subject: [PATCH 6/6] samples: i2c_scanner: show example of device_get_dt_binding Hack up device_get_dt_binding, its really device_get_dt_binding_by_inst. Need to figure out how to handle the extern of __device_ZDID. Signed-off-by: Kumar Gala --- samples/drivers/i2c_scanner/src/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/samples/drivers/i2c_scanner/src/main.c b/samples/drivers/i2c_scanner/src/main.c index 44c1724377d6c..9cbb596302f3f 100644 --- a/samples/drivers/i2c_scanner/src/main.c +++ b/samples/drivers/i2c_scanner/src/main.c @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef ARDUINO_I2C_LABEL #define I2C_DEV ARDUINO_I2C_LABEL @@ -16,6 +17,11 @@ #define I2C_DEV "I2C_0" #endif +#define device_get_dt_binding_zdid(zdid) _CONCAT(&__device_, zdid) + +#define device_get_dt_binding(name, inst) \ +device_get_dt_binding_zdid(DT_ZDID_INST_##inst##_##name) \ + /** * @file This app scans I2C bus for any devices present */ @@ -26,7 +32,7 @@ void main(void) printk("Starting i2c scanner...\n"); - i2c_dev = device_get_binding(I2C_DEV); + i2c_dev = device_get_dt_binding(SILABS_GECKO_I2C, 0); if (!i2c_dev) { printk("I2C: Device driver not found.\n"); return;