Exemplo n.º 1
0
int arch_cpu_init(void)
{
	configure_clocks();

	/*
		* Configure the memory protection unit (MPU)
		* 0x00000000 - 0xffffffff: Strong-order, Shareable
		* 0xC0000000 - 0xC0800000: Normal, Outer and inner Non-cacheable
	 */

	 /* Disable MPU */
	 writel(0, &V7M_MPU->ctrl);

	 writel(
		 0x00000000 /* address */
		 | 1 << 4	/* VALID */
		 | 0 << 0	/* REGION */
		 , &V7M_MPU->rbar
	 );

	 /* Strong-order, Shareable */
	 /* TEX=000, S=1, C=0, B=0*/
	 writel(
		 (V7M_MPU_RASR_XN_ENABLE
			 | V7M_MPU_RASR_AP_RW_RW
			 | 0x01 << V7M_MPU_RASR_S_SHIFT
			 | 0x00 << V7M_MPU_RASR_TEX_SHIFT
			 | V7M_MPU_RASR_SIZE_4GB
			 | V7M_MPU_RASR_EN)
		 , &V7M_MPU->rasr
	 );

	 writel(
		 0xC0000000 /* address */
		 | 1 << 4	/* VALID */
		 | 1 << 0	/* REGION */
		 , &V7M_MPU->rbar
	 );

	 /* Normal, Outer and inner Non-cacheable */
	 /* TEX=001, S=0, C=0, B=0*/
	 writel(
		 (V7M_MPU_RASR_XN_ENABLE
			 | V7M_MPU_RASR_AP_RW_RW
			 | 0x01 << V7M_MPU_RASR_TEX_SHIFT
			 | V7M_MPU_RASR_SIZE_8MB
			 | V7M_MPU_RASR_EN)
			 , &V7M_MPU->rasr
	 );

	 /* Enable MPU */
	 writel(V7M_MPU_CTRL_ENABLE | V7M_MPU_CTRL_HFNMIENA, &V7M_MPU->ctrl);

	return 0;
}
Exemplo n.º 2
0
static void bootloader_flash_init(void)
{
    g_bootloaderContext.flashDriverInterface->flash_init(&g_bootloaderContext.flashState);

#if BL_TARGET_FLASH
    //! @brief A static buffer used to hold flash_run_command()
    static uint32_t s_flashRunCommand[kFLASH_ExecuteInRamFunctionMaxSizeInWords];
    //! @brief A static buffer used to hold flash_cache_clear_command()
    static uint32_t s_flashCacheClearCommand[kFLASH_ExecuteInRamFunctionMaxSizeInWords];

    static flash_execute_in_ram_function_config_t s_flashExecuteInRamFunctionInfo = {
        .activeFunctionCount = 0,
        .flashRunCommand = s_flashRunCommand,
        .flashCacheClearCommand = s_flashCacheClearCommand,
    };

    g_bootloaderContext.flashState.flashExecuteInRamFunctionInfo = &s_flashExecuteInRamFunctionInfo.activeFunctionCount;
    g_bootloaderContext.flashDriverInterface->flash_prepare_execute_in_ram_functions(&g_bootloaderContext.flashState);
#endif
}

//! @brief Initialize the bootloader and peripherals.
//!
//! This function initializes hardware and clocks, loads user configuration data, and initialzes
//! a number of drivers. It then enters the active peripheral detection phase by calling
//! get_active_peripheral(). Once the peripheral is detected, the packet and comand interfaces
//! are initialized.
//!
//! Note that this routine may not return if peripheral detection times out and the bootloader
//! jumps directly to the user application in flash.
static void bootloader_init(void)
{
    // Init the global irq lock
    lock_init();

    // Init pinmux and other hardware setup.
    init_hardware();

    // Init flash driver.
    bootloader_flash_init();

    // Load the user configuration data so that we can configure the clocks
    g_bootloaderContext.propertyInterface->load_user_config();

// Init QSPI module if needed
#if BL_FEATURE_QSPI_MODULE
    configure_quadspi_as_needed();
#endif // BL_FEATURE_QSPI_MODULE

    // Configure clocks.
    configure_clocks(kClockOption_EnterBootloader);

    // Start the lifetime counter
    microseconds_init();

#if BL_FEATURE_BYPASS_WATCHDOG
    g_bootloaderContext.flashDriverInterface->flash_register_callback(&g_bootloaderContext.flashState,
                                                                      bootloader_watchdog_service);
    bootloader_watchdog_init();
#endif // BL_FEATURE_BYPASS_WATCHDOG

    // Init address range of flash array, SRAM_L and SRAM U.
    g_bootloaderContext.memoryInterface->init();

    // Fully init the property store.
    g_bootloaderContext.propertyInterface->init();

#if BL_FEATURE_RELIABLE_UPDATE
    bootloader_reliable_update_as_requested(kReliableUpdateOption_Normal, 0);
#endif // BL_FEATURE_RELIABLE_UPDATE

    // Message so python instantiated debugger can tell the
    // bootloader application is running on the target.
    debug_printf("\r\n\r\nRunning bootloader...\r\n");

#if DEBUG && !DEBUG_PRINT_DISABLE
    standard_version_t version = g_bootloaderContext.propertyInterface->store->bootloaderVersion;
    debug_printf("Bootloader version %c%d.%d.%d\r\n", version.name, version.major, version.minor, version.bugfix);
#endif

    // Wait for a peripheral to become active.
    g_bootloaderContext.activePeripheral = get_active_peripheral();
    assert(g_bootloaderContext.activePeripheral);

    // Validate required active peripheral interfaces.
    assert(g_bootloaderContext.activePeripheral->controlInterface);

    // Init the active peripheral.
    if (g_bootloaderContext.activePeripheral->byteInterface &&
        g_bootloaderContext.activePeripheral->byteInterface->init)
    {
        g_bootloaderContext.activePeripheral->byteInterface->init(g_bootloaderContext.activePeripheral);
    }
    if (g_bootloaderContext.activePeripheral->packetInterface &&
        g_bootloaderContext.activePeripheral->packetInterface->init)
    {
        g_bootloaderContext.activePeripheral->packetInterface->init(g_bootloaderContext.activePeripheral);
    }

    // Initialize the command processor component.
    g_bootloaderContext.commandInterface->init();
}
Exemplo n.º 3
0
// See bl_shutdown_cleanup.h for documentation of this function.
void shutdown_cleanup(shutdown_type_t shutdown)
{
#if !defined(BOOTLOADER_HOST)
    if (shutdown != kShutdownType_Reset)
    {
        // Clear (flush) the flash cache.
        flash_cache_clear(NULL);
    }

    if (shutdown != kShutdownType_Cleanup)
    {
        // Shutdown all peripherals because they could be active
        uint32_t i;
        for (i = 0; g_peripherals[i].typeMask != 0; i++)
        {
            if (g_peripherals[i].controlInterface->shutdown)
            {
                g_peripherals[i].controlInterface->shutdown(&g_peripherals[i]);
            }
        }
    }

    // If we are permanently exiting the bootloader, there are a few extra things to do.
    if (shutdown == kShutdownType_Shutdown)
    {
        // Turn off global interrupt
        lock_acquire();

        // Shutdown microseconds driver.
        microseconds_shutdown();

#if defined(RCM_FM)
        // Disable force ROM.
        RCM_BWR_FM_FORCEROM(RCM, 0);

        // Clear status register (bits are w1c).
        RCM_BWR_MR_BOOTROM(RCM, 3);
#endif // defined(RCM_FM)

        init_interrupts();

        // Set the VTOR to default.
        SCB->VTOR = kDefaultVectorTableAddress;

        // Restore clock to default before leaving bootloader.
        configure_clocks(kClockOption_ExitBootloader);

        // De-initialize hardware such as disabling port clock gate
        deinit_hardware();

        // Restore global interrupt.
        __enable_irq();

#if BL_FEATURE_BYPASS_WATCHDOG
        // De-initialize watchdog
        bootloader_watchdog_deinit();
#endif // BL_FEATURE_BYPASS_WATCHDOG
    }

    // Memory barriers for good measure.
    __ISB();
    __DSB();
#endif
}