This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] LP-AM243:如何在 SBL 处理中将 XIP 映像写入闪存?

Guru**** 2455560 points
Other Parts Discussed in Thread: SYSCONFIG, UNIFLASH

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1454372/lp-am243-how-to-write-xip-image-to-flash-in-sbl-processing

器件型号:LP-AM243
主题中讨论的其他器件:SysConfigUNIFLASH

工具与软件:

您好、TI 专家!

我正在尝试修改 SBL、以将固件(XIP 格式)写入闪存。
SDK 版本为 MCU+ SDK v10.00.00.20。

我在这里有两个问题、如果你能回答、我将不胜感激。


我无法在 SBL 过程中写入闪存。 (Flash_WRITE()的返回值为错误。)
我采取的步骤如下。

 1.我从 SBL 示例中删除了固件读取过程[*1]并添加了闪存写入过程。

 2.我参考了 OSPI 示例[*2]的闪存写入过程。

 *1: examples/drivers/boot/sbl_ospi.
 *2: examples/ospi/ospi_flash_io

生成的源代码(main.c)如下所示。

闪存写入过程从第135行开始。

/*
 *  Copyright (C) 2018-2022 Texas Instruments Incorporated
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>
#include "ti_drivers_config.h"
#include "ti_drivers_open_close.h"
#include "ti_board_open_close.h"
#include <drivers/sciclient.h>
#include <drivers/bootloader/soc/bootloader_soc.h>
#include <drivers/bootloader.h>
#include <kernel/dpl/ClockP.h>

#define DELAY_SEC (1000U)

#define APP_OSPI_FLASH_OFFSET_BASE  (0x200000U)
#define APP_OSPI_DATA_SIZE (2048)
static uint8_t gOspiTxBuf[APP_OSPI_DATA_SIZE];

void flashFixUpQspiBoot(void);
void ospi_flash_io_fill_buffers(void);

/* call this API to stop the booting process and spin, do that you can connect
 * debugger, load symbols and then make the 'loop' variable as 0 to continue execution
 * with debugger connected.
 */
void loop_forever(void)
{
    volatile uint32_t loop = 1;
    while(loop)
        ;
}

int main(void)
{
    int32_t status;

    Bootloader_profileReset();

    Bootloader_socWaitForFWBoot();

#ifndef DISABLE_WARM_REST_WA
    /* Warm Reset Workaround to prevent CPSW register lockup */
    if (!Bootloader_socIsMCUResetIsoEnabled())
    {
        Bootloader_socResetWorkaround();
    }
#endif

    Bootloader_profileAddProfilePoint("SYSFW init");

    if (!Bootloader_socIsMCUResetIsoEnabled())
    {
        /* Update devGrp to ALL to initialize MCU domain when reset isolation is
        not enabled */
        Sciclient_BoardCfgPrms_t boardCfgPrms_pm =
            {
                .boardConfigLow = (uint32_t)0,
                .boardConfigHigh = 0,
                .boardConfigSize = 0,
                .devGrp = DEVGRP_ALL,
            };

        status = Sciclient_boardCfgPm(&boardCfgPrms_pm);

        Sciclient_BoardCfgPrms_t boardCfgPrms_rm =
        {
            .boardConfigLow = (uint32_t)0,
            .boardConfigHigh = 0,
            .boardConfigSize = 0,
            .devGrp = DEVGRP_ALL,
        };

        status = Sciclient_boardCfgRm(&boardCfgPrms_rm);

        /* Enable MCU PLL. MCU PLL will not be enabled by DMSC when devGrp is set
        to Main in boardCfg */
        Bootloader_enableMCUPLL();
    }

    Bootloader_socOpenFirewalls();

    Bootloader_socNotifyFirewallOpen();

    System_init();
    Bootloader_profileAddProfilePoint("System_init");

    Drivers_open();
    Bootloader_profileAddProfilePoint("Drivers_open");

    #if 0
    DebugP_log("\r\n");
    DebugP_log("Starting OSPI Bootloader ... \r\n");
    #endif

	/* ROM doesn't reset the QSPI flash. So do a flash reset */
    flashFixUpQspiBoot();

    status = Board_driversOpen();
    DebugP_assert(status == SystemP_SUCCESS);
    Bootloader_profileAddProfilePoint("Board_driversOpen");

    status = Sciclient_getVersionCheck(1);
    Bootloader_profileAddProfilePoint("Sciclient Get Version");

#if (1)
	// Flash writing process based on ospi_flash_io exmaple code.
	uint32_t block;
	uint32_t page;
	uint32_t offset = APP_OSPI_FLASH_OFFSET_BASE;

    if(SystemP_SUCCESS == status) {
		// Erase block
		ospi_flash_io_fill_buffers();
		DebugP_log("Erase Flash (%x)...", offset);
		Flash_offsetToBlkPage(gFlashHandle[CONFIG_FLASH0], offset, &block, &page);
		DebugP_log("block=[%x], page=[%x]\r\n", block, page);
		status = Flash_eraseBlk(gFlashHandle[CONFIG_FLASH0], block);
	}

	if (status == SystemP_SUCCESS) {
		// Write
		DebugP_log("Writing to Flash (src: %p, dst: %x)...", gOspiTxBuf, offset);
		ospi_flash_io_fill_buffers();
		status = Flash_write(gFlashHandle[CONFIG_FLASH0], offset, gOspiTxBuf, APP_OSPI_DATA_SIZE);
		DebugP_log("Done. status=[%d]\r\n", status);
	}
#endif

    if(status != SystemP_SUCCESS )
    {
        DebugP_log("Some tests have failed!!\r\n");
    }
    Drivers_close();
    System_deinit();

    return 0;
}

void flashFixUpQspiBoot(void)
{
    uint32_t gpiobaseAddr, pinnum;

	/* Get address after translation translate */
    gpiobaseAddr = (uint32_t) AddrTranslateP_getLocalAddr(CONFIG_GPIO0_BASE_ADDR);

    pinnum = CONFIG_GPIO0_PIN;

	/* Drive the GPIO Pin low to assert the reset signal */
    GPIO_pinWriteLow(gpiobaseAddr, pinnum);
    ClockP_usleep(DELAY_SEC);

	/* Drive the GPIO Pin high to deassert the reset signal */
    GPIO_pinWriteHigh(gpiobaseAddr, pinnum);
    ClockP_usleep(DELAY_SEC);
}

void ospi_flash_io_fill_buffers(void)
{
    uint32_t i;

    for(i = 0U; i < APP_OSPI_DATA_SIZE; i++)
    {
        gOspiTxBuf[i] = i % 256;
    }
}


执行结果如下。

DMSC Firmware Version 10.0.8--v10.00.08 (Fiery Fox)
DMSC Firmware revision 0xa
DMSC ABI revision 4.0

Erase Flash (200000)...block=[8], page=[0]
Writing to Flash (src: 70075008, dst: 200000)...Done. status=[-1]
Some tests have failed!!

已确认仅运行 OSPI 示例[*2]时、闪存写入过程可以正常工作。

SBL 中错误的原因未知、因此如果您有任何线索、请告诉我。



我想使用引导加载程序模块在每个内核上执行 XIP 操作、
但是、在将 XIP 格式写入闪存时、我应该将.appimage_xip 写入什么地址?

我是否应该将其覆盖到与.appimage 相同的地址?

请告诉我步骤。

此致、

武田太郎

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    1.请在 SBL_OSPI SysConfig 中将区域属性从默认的"非缓存"更改为"严格排序"、如下所示:

    2.我可以知道使用 XIP 映像的用例吗?

    SBL OSPI 通常用于引导正常 appimage。

    此致、

    Prashant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Prashant:

    感谢您的答复。

    我想尝试一下、但由于我的假期、请等到1月中旬再回复。

    此致、

    武田太郎

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Prashant:

    很抱歉、请等到2月左右再响应、因为我还有其他优先级更高的工作。

     

    此致、

    武田太郎

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Prashant:

    感谢您的等待。

    1.
    我能够按照您的指示正确写入闪存!
    谢谢!


    2.
    >我是否可以知道使用 XIP 映像的用例?
    > SBL OSPI 通常用于引导正常 appimage。
    为了尽可能减少所使用的 RAM 容量、我曾想从 ROM 中为每个内核启动执行二进制文件。
    此外、由于开关 DIP-SW 比较麻烦、所以我想让 SBL 将通过串行方式接收的 XIP 二进制文件写入闪存。

    如果您有任何有关如何实现这一点的示例或提示、请告诉我。


    此致、

    武田太郎

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    为了最大限度地减少使用的 RAM 容量、我想从 ROM 中为每个内核启动一个执行二进制文件。

    ROM 仅引导 SBL。 SBL 将为每个内核引导应用程序。

    您是否已尝试引导正常 appimage? 如果是、您希望使用 XIP 的确切问题是什么?

    此致、

    Prashant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Prashant:

    >是否已尝试启动正常的 appimage?

    这句话让我意识到有一个严重的错误。 谢谢你。
    我没有在 SysConfig 中将代码和文本部分分配给存储器配置器设置中的闪存。

    当我分配它们时、输出.appimage_xip 的大小增加了、所以我认为将它写入闪存是正确的。

    然而,它不起作用。
    Bootloader_parseMultiCoreAppImage 函数返回错误。

    如果我需要检查一下 XIP 是否正常工作、请告诉我。

    此致、

    武田太郎

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    请参阅以下指南:

    https://software-dl.ti.com/mcu-plus-sdk/esd/AM243X/10_01_00_32/exports/docs/api_guide_am243x/BOOTFLOW_XIP.html

    此致、

    Prashant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Prashant:


    谢谢你。

    阅读本指南后、我检查了链接器命令文件(linker.cmd)、它想成那样、所以我创建的 XIP 二进制文件似乎没有问题。

    然而、正如我之前提到的、当我将串行接收到的 XIP 文件(.appimage_xip)写入闪存时、是不起作用的。

    在这里、指南中有以下一句

    此外、使用flash-xip传递给闪存写入器的特殊命令将包含 XIP 段的文件刷写到闪存中

    我想我可以按照声明中的闪存写入器的方式(可能是 uart_uniflash.py)写入闪存、但我不知道如何用代码编写它。

    这种想法是正确的吗?

    另外、如果正确、请告诉我是否有任何将 XIP 文件写入闪存的代码。


    此致、

    武田太郎

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Prashant:

    您有任何这方面的信息吗?

    此致、

    武田太郎

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    SBL_UART_UNIFLASH 使用以下 API 将 XIP 映像写入闪存:

    https://github.com/TexasInstruments/mcupsdk-core/blob/next/source/drivers/bootloader/bootloader_uniflash/bootloader_uniflash.c#L144-L144

    您可以对 SBL 使用相同的指令。

    此致、

    Prashant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Prashant:

    感谢您的答复。

    您提供的信息可能是我想要的。

    由于我几天都无法尝试、因此我现在将关闭此主题、如果我有任何问题、请打开另一个主题。

    非常感谢您的帮助!

    此致、

    武田太郎