diff options
author | Claas Ziemke <ziemke@irs.uni-stuttgart.de> | 2012-08-22 14:39:02 +0200 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@oarcorp.com> | 2014-11-03 14:19:47 -0600 |
commit | 7a669866eea8b66b87b22015b793b5ea4ff950c1 (patch) | |
tree | f7faffb2cd20b45894ddabbc60f1a0e5ee96403d /c/src/lib/libbsp/arm/beagle/startup | |
parent | Add some generic ARM am335x and omap definitions (diff) | |
download | rtems-7a669866eea8b66b87b22015b793b5ea4ff950c1.tar.bz2 |
Added BeagleBoard BSP
Coding done in course of GSoC2012.
Commit edited to be brought up-to-date with mainline by
Ben Gras <beng@shrike-systems.com>.
Diffstat (limited to 'c/src/lib/libbsp/arm/beagle/startup')
-rw-r--r-- | c/src/lib/libbsp/arm/beagle/startup/bspreset.c | 48 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/beagle/startup/bspstart.c | 33 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/beagle/startup/bspstarthooks.c | 366 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/beagle/startup/linkcmds.beagle | 54 |
4 files changed, 501 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/beagle/startup/bspreset.c b/c/src/lib/libbsp/arm/beagle/startup/bspreset.c new file mode 100644 index 0000000000..d937a18abd --- /dev/null +++ b/c/src/lib/libbsp/arm/beagle/startup/bspreset.c @@ -0,0 +1,48 @@ +/** + * @file + * + * @ingroup beagle + * + * @brief Reset code. + */ + +/* + * Copyright (c) 2012 Claas Ziemke. All rights reserved. + * + * Claas Ziemke + * Kernerstrasse 11 + * 70182 Stuttgart + * Germany + * <claas.ziemke@gmx.net> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include <stdbool.h> + +#include <bspopts.h> +#include <bsp/bootcard.h> +#include <bsp/beagle.h> + +static void watchdog_reset(void) +{ + #ifdef BEAGLE_ENABLE_WATCHDOG_RESET + //BEAGLE_TIMCLK_CTRL |= TIMCLK_CTRL_WDT; + //beagle.wdt.mctrl |= WDTTIM_MCTRL_M_RES1 | WDTTIM_MCTRL_M_RES2; + //beagle.wdt.emr = WDTTIM_EMR_MATCH_CTRL_SET(beagle.wdt.emr, 0x2); + //beagle.wdt.ctrl |= WDTTIM_CTRL_COUNT_ENAB; + //beagle.wdt.match0 = 1; + //beagle.wdt.counter = 0; + #endif +} + +void bsp_reset( void) +{ + watchdog_reset(); + + while (true) { + /* Do nothing */ + } +} diff --git a/c/src/lib/libbsp/arm/beagle/startup/bspstart.c b/c/src/lib/libbsp/arm/beagle/startup/bspstart.c new file mode 100644 index 0000000000..9cdd04a8fb --- /dev/null +++ b/c/src/lib/libbsp/arm/beagle/startup/bspstart.c @@ -0,0 +1,33 @@ +/** + * @file + * + * @ingroup beagle + * + * @brief Startup code. + */ + +/* + * Copyright (c) 2012 Claas Ziemke. All rights reserved. + * + * Claas Ziemke + * Kernerstrasse 11 + * 70182 Stuttgart + * Germany + * <claas.ziemke@gmx.net> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include <bsp.h> +#include <bsp/bootcard.h> +#include <bsp/irq-generic.h> +#include <bsp/irq.h> +#include <bsp/linker-symbols.h> +#include <bsp/beagle.h> + +void bsp_start(void) +{ + bsp_interrupt_initialize(); +} diff --git a/c/src/lib/libbsp/arm/beagle/startup/bspstarthooks.c b/c/src/lib/libbsp/arm/beagle/startup/bspstarthooks.c new file mode 100644 index 0000000000..4538b0c2d9 --- /dev/null +++ b/c/src/lib/libbsp/arm/beagle/startup/bspstarthooks.c @@ -0,0 +1,366 @@ +/** + * @file + * + * @ingroup beagle + * + * @brief Startup code. + */ + +/* + * Copyright (c) 2012 Claas Ziemke. All rights reserved. + * + * Claas Ziemke + * Kernerstrasse 11 + * 70182 Stuttgart + * Germany + * <claas.ziemke@gmx.net> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include <bsp.h> +#include <bsp/start.h> +#include <bsp/beagle.h> +#include <bsp/linker-symbols.h> +#include <bsp/uart-output-char.h> +#include <libcpu/arm-cp15.h> + +#ifdef BEAGLE_DISABLE_READ_WRITE_DATA_CACHE + #define BEAGLE_MMU_READ_WRITE_DATA BEAGLE_MMU_READ_WRITE +#else + #define BEAGLE_MMU_READ_WRITE_DATA BEAGLE_MMU_READ_WRITE_CACHED +#endif + +#ifdef BEAGLE_DISABLE_READ_ONLY_PROTECTION + #define BEAGLE_MMU_READ_ONLY_DATA BEAGLE_MMU_READ_WRITE_CACHED + #define BEAGLE_MMU_CODE BEAGLE_MMU_READ_WRITE_CACHED +#else + #define BEAGLE_MMU_READ_ONLY_DATA BEAGLE_MMU_READ_ONLY_CACHED + #define BEAGLE_MMU_CODE BEAGLE_MMU_READ_ONLY_CACHED +#endif + +//LINKER_SYMBOL(beagle_translation_table_base); + +static BSP_START_TEXT_SECTION void clear_bss(void) +{ + const int *end = (const int *) bsp_section_bss_end; + int *out = (int *) bsp_section_bss_begin; + + /* Clear BSS */ + while (out != end) { + *out = 0; + ++out; + } +} + +/*#ifndef BEAGLE_DISABLE_MMU + typedef struct { + uint32_t begin; + uint32_t end; + uint32_t flags; + } beagle_mmu_config; + + static const BSP_START_DATA_SECTION beagle_mmu_config + beagle_mmu_config_table [] = { + { + .begin = (uint32_t) bsp_section_fast_text_begin, + .end = (uint32_t) bsp_section_fast_text_end, + .flags = BEAGLE_MMU_CODE + }, { + .begin = (uint32_t) bsp_section_fast_data_begin, + .end = (uint32_t) bsp_section_fast_data_end, + .flags = BEAGLE_MMU_READ_WRITE_DATA +#ifdef BEAGLE_SCRATCH_AREA_SIZE + }, { + .begin = (uint32_t) &beagle_scratch_area [0], + .end = (uint32_t) &beagle_scratch_area [BEAGLE_SCRATCH_AREA_SIZE], + .flags = BEAGLE_MMU_READ_ONLY_DATA +#endif + }, { + .begin = (uint32_t) bsp_section_start_begin, + .end = (uint32_t) bsp_section_start_end, + .flags = BEAGLE_MMU_CODE + }, { + .begin = (uint32_t) bsp_section_vector_begin, + .end = (uint32_t) bsp_section_vector_end, + .flags = BEAGLE_MMU_READ_WRITE_CACHED + }, { + .begin = (uint32_t) bsp_section_text_begin, + .end = (uint32_t) bsp_section_text_end, + .flags = BEAGLE_MMU_CODE + }, { + .begin = (uint32_t) bsp_section_rodata_begin, + .end = (uint32_t) bsp_section_rodata_end, + .flags = BEAGLE_MMU_READ_ONLY_DATA + }, { + .begin = (uint32_t) bsp_section_data_begin, + .end = (uint32_t) bsp_section_data_end, + .flags = BEAGLE_MMU_READ_WRITE_DATA + }, { + .begin = (uint32_t) bsp_section_bss_begin, + .end = (uint32_t) bsp_section_bss_end, + .flags = BEAGLE_MMU_READ_WRITE_DATA + }, { + .begin = (uint32_t) bsp_section_work_begin, + .end = (uint32_t) bsp_section_work_end, + .flags = BEAGLE_MMU_READ_WRITE_DATA + }, { + .begin = (uint32_t) bsp_section_stack_begin, + .end = (uint32_t) bsp_section_stack_end, + .flags = BEAGLE_MMU_READ_WRITE_DATA + }, { + .begin = 0x0U, + .end = 0x100000U, + .flags = BEAGLE_MMU_READ_ONLY_CACHED + }, { + .begin = 0x20000000U, + .end = 0x200c0000U, + .flags = BEAGLE_MMU_READ_WRITE + }, { + .begin = 0x30000000U, + .end = 0x32000000U, + .flags = BEAGLE_MMU_READ_WRITE + }, { + .begin = 0x40000000U, + .end = 0x40100000U, + .flags = BEAGLE_MMU_READ_WRITE + }, { + .begin = (uint32_t) beagle_magic_zero_begin, + .end = (uint32_t) beagle_magic_zero_end, + .flags = BEAGLE_MMU_READ_WRITE_DATA + } + }; + + static BSP_START_TEXT_SECTION void set_translation_table_entries( + uint32_t *ttb, + const beagle_mmu_config *config + ) + { + uint32_t i = ARM_MMU_SECT_GET_INDEX(config->begin); + uint32_t iend = + ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end)); + + if (config->begin != config->end) { + while (i < iend) { + ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | config->flags; + ++i; + } + } + } + + static BSP_START_TEXT_SECTION void + setup_translation_table_and_enable_mmu(uint32_t ctrl) + { + uint32_t const dac = + ARM_CP15_DAC_DOMAIN(BEAGLE_MMU_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT); + uint32_t *const ttb = (uint32_t *) beagle_translation_table_base; + size_t const config_entry_count = + sizeof(beagle_mmu_config_table) / sizeof(beagle_mmu_config_table [0]); + size_t i = 0; + + arm_cp15_set_domain_access_control(dac); + arm_cp15_set_translation_table_base(ttb); + + // Initialize translation table with invalid entries + for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) { + ttb [i] = 0; + } + + for (i = 0; i < config_entry_count; ++i) { + set_translation_table_entries(ttb, &beagle_mmu_config_table [i]); + } + + // Enable MMU and cache + ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M; + arm_cp15_set_control(ctrl); + } +#endif*/ + +/*static BSP_START_TEXT_SECTION void setup_mmu_and_cache(void) +{ + uint32_t ctrl = 0; + + // Disable MMU and cache, basic settings + ctrl = arm_cp15_get_control(); + ctrl &= ~(ARM_CP15_CTRL_I | ARM_CP15_CTRL_R | ARM_CP15_CTRL_C + | ARM_CP15_CTRL_V | ARM_CP15_CTRL_M); + ctrl |= ARM_CP15_CTRL_S | ARM_CP15_CTRL_A; + arm_cp15_set_control(ctrl); + + arm_cp15_cache_invalidate(); + arm_cp15_tlb_invalidate(); + + #ifndef BEAGLE_DISABLE_MMU + //setup_translation_table_and_enable_mmu(ctrl); + #endif +}*/ + +/*BSP_START_TEXT_SECTION bool beagle_start_pll_setup( + uint32_t hclkpll_ctrl, + uint32_t hclkdiv_ctrl, + bool force +) +{ + uint32_t pwr_ctrl = BEAGLE_PWR_CTRL; + bool settings_ok = + ((BEAGLE_HCLKPLL_CTRL ^ hclkpll_ctrl) & BSP_MSK32(1, 16)) == 0 + && ((BEAGLE_HCLKDIV_CTRL ^ hclkdiv_ctrl) & BSP_MSK32(0, 8)) == 0; + + if ((pwr_ctrl & PWR_NORMAL_RUN_MODE) == 0 || (!settings_ok && force)) { + // Disable HCLK PLL output + BEAGLE_PWR_CTRL = pwr_ctrl & ~PWR_NORMAL_RUN_MODE; + + // Configure HCLK PLL + BEAGLE_HCLKPLL_CTRL = hclkpll_ctrl; + while ((BEAGLE_HCLKPLL_CTRL & HCLK_PLL_LOCK) == 0) { + // Wait + } + + // Setup HCLK divider + BEAGLE_HCLKDIV_CTRL = hclkdiv_ctrl; + + // Enable HCLK PLL output + BEAGLE_PWR_CTRL = pwr_ctrl | PWR_NORMAL_RUN_MODE; + } + + return settings_ok; +}*/ + +#if BEAGLE_OSCILLATOR_MAIN != 13000000U + #error "unexpected main oscillator frequency" +#endif + +/*static BSP_START_TEXT_SECTION void setup_pll(void) +{ + uint32_t hclkpll_ctrl = BEAGLE_HCLKPLL_CTRL_INIT_VALUE; + uint32_t hclkdiv_ctrl = BEAGLE_HCLKDIV_CTRL_INIT_VALUE; + + beagle_start_pll_setup(hclkpll_ctrl, hclkdiv_ctrl, false); +}*/ + +BSP_START_TEXT_SECTION void bsp_start_hook_0(void) +{ + //setup_pll(); + //setup_mmu_and_cache(); +} + +/*static BSP_START_TEXT_SECTION void stop_dma_activities(void) +{ + #ifdef BEAGLE_STOP_GPDMA + BEAGLE_DO_STOP_GPDMA; + #endif + + #ifdef BEAGLE_STOP_ETHERNET + BEAGLE_DO_STOP_ETHERNET; + #endif + + #ifdef BEAGLE_STOP_USB + BEAGLE_DO_STOP_USB; + #endif +}*/ + +static BSP_START_TEXT_SECTION void setup_uarts(void) +{ + uint32_t uartclk_ctrl = 0; + + #ifdef BEAGLE_CONFIG_U3CLK + uartclk_ctrl |= 1U << 0; + BEAGLE_U3CLK = BEAGLE_CONFIG_U3CLK; + #endif + #ifdef BEAGLE_CONFIG_U4CLK + uartclk_ctrl |= 1U << 1; + BEAGLE_U4CLK = BEAGLE_CONFIG_U4CLK; + #endif + #ifdef BEAGLE_CONFIG_U5CLK + uartclk_ctrl |= 1U << 2; + BEAGLE_U5CLK = BEAGLE_CONFIG_U5CLK; + #endif + #ifdef BEAGLE_CONFIG_U6CLK + uartclk_ctrl |= 1U << 3; + BEAGLE_U6CLK = BEAGLE_CONFIG_U6CLK; + #endif + + #ifdef BEAGLE_CONFIG_UART_CLKMODE + BEAGLE_UART_CLKMODE = BEAGLE_CONFIG_UART_CLKMODE; + #endif + + BEAGLE_UARTCLK_CTRL = uartclk_ctrl; + BEAGLE_UART_CTRL = 0x0; + BEAGLE_UART_LOOP = 0x0; + + #ifdef BEAGLE_CONFIG_U5CLK + // Clock is already set in BEAGLE_U5CLK + BSP_CONSOLE_UART_INIT(0x01); + #endif +} + +/*static BSP_START_TEXT_SECTION void setup_timer(void) +{ + volatile beagle_timer *timer = BEAGLE_STANDARD_TIMER; + + BEAGLE_TIMCLK_CTRL1 = (1U << 2) | (1U << 3); + + timer->tcr = BEAGLE_TIMER_TCR_RST; + timer->ctcr = 0x0; + timer->pr = 0x0; + timer->ir = 0xff; + timer->mcr = 0x0; + timer->ccr = 0x0; + timer->tcr = BEAGLE_TIMER_TCR_EN; +}*/ + +BSP_START_TEXT_SECTION void bsp_start_hook_1(void) +{ + //stop_dma_activities(); + setup_uarts(); + //setup_timer(); + + // Copy .text section + arm_cp15_instruction_cache_invalidate(); + bsp_start_memcpy( + (int *) bsp_section_text_begin, + (const int *) bsp_section_text_load_begin, + (size_t) bsp_section_text_size + ); + + // Copy .rodata section + arm_cp15_instruction_cache_invalidate(); + bsp_start_memcpy( + (int *) bsp_section_rodata_begin, + (const int *) bsp_section_rodata_load_begin, + (size_t) bsp_section_rodata_size + ); + + // Copy .data section + arm_cp15_instruction_cache_invalidate(); + bsp_start_memcpy( + (int *) bsp_section_data_begin, + (const int *) bsp_section_data_load_begin, + (size_t) bsp_section_data_size + ); + + // Copy .fast_text section + arm_cp15_instruction_cache_invalidate(); + bsp_start_memcpy( + (int *) bsp_section_fast_text_begin, + (const int *) bsp_section_fast_text_load_begin, + (size_t) bsp_section_fast_text_size + ); + + // Copy .fast_data section + arm_cp15_instruction_cache_invalidate(); + bsp_start_memcpy( + (int *) bsp_section_fast_data_begin, + (const int *) bsp_section_fast_data_load_begin, + (size_t) bsp_section_fast_data_size + ); + + // Clear .bss section + clear_bss(); + + + + // At this point we can use objects outside the .start section +} diff --git a/c/src/lib/libbsp/arm/beagle/startup/linkcmds.beagle b/c/src/lib/libbsp/arm/beagle/startup/linkcmds.beagle new file mode 100644 index 0000000000..29e948d4e7 --- /dev/null +++ b/c/src/lib/libbsp/arm/beagle/startup/linkcmds.beagle @@ -0,0 +1,54 @@ +/** + * @file + * + * @ingroup beagle_linker + * + * @brief Memory map. + */ + +/** + * @defgroup beagle_linker BeagleBoard Application Memory Map + * + * @ingroup bsp_linker + * + * @brief BeagleBoard application memory map. + * + */ + +MEMORY { + RAM : ORIGIN = 0x80000000, LENGTH = 32M + NIRVANA : ORIGIN = 0, LENGTH = 0 +} + +REGION_ALIAS ("REGION_START", RAM); +REGION_ALIAS ("REGION_VECTOR", RAM); +REGION_ALIAS ("REGION_TEXT", RAM); +REGION_ALIAS ("REGION_TEXT_LOAD", RAM); +REGION_ALIAS ("REGION_RODATA", RAM); +REGION_ALIAS ("REGION_RODATA_LOAD", RAM); +REGION_ALIAS ("REGION_DATA", RAM); +REGION_ALIAS ("REGION_DATA_LOAD", RAM); +REGION_ALIAS ("REGION_FAST_TEXT", RAM); +REGION_ALIAS ("REGION_FAST_TEXT_LOAD", RAM); +REGION_ALIAS ("REGION_FAST_DATA", RAM); +REGION_ALIAS ("REGION_FAST_DATA_LOAD", RAM); +REGION_ALIAS ("REGION_BSS", RAM); +REGION_ALIAS ("REGION_WORK", RAM); +REGION_ALIAS ("REGION_STACK", RAM); + +//beagle_scratch_area = ORIGIN (RAM_SCRATCH); + +bsp_stack_irq_size = DEFINED (bsp_stack_irq_size) ? bsp_stack_irq_size : 4096; +bsp_stack_abt_size = DEFINED (bsp_stack_abt_size) ? bsp_stack_abt_size : 1024; + +bsp_section_rwbarrier_align = DEFINED (bsp_section_rwbarrier_align) ? bsp_section_rwbarrier_align : 1M; + +beagle = 0x20020000; + +beagle_magic_zero_begin = 0x05000000; +beagle_magic_zero_end = 0x07000000; +beagle_magic_zero_size = beagle_magic_zero_end - beagle_magic_zero_end; + +INCLUDE linkcmds.armv4 + +HeapSize = 1024 * 1024; |