⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfg.c

📁 arm4 driver for freescale imx35
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File:  cfg.c
//
//  This file implements functions used to load/save EBOOT configuration info.
//  The EBOOT configuration is located on last block reserved for EBOOT image
//  on NOR flash memory.
//
#include <eboot.h>
#include <utilities.h>

//------------------------------------------------------------------------------

BOOL BLReadBootCfg(BOOT_CFG *pBootCfg)
{
    // Simply copy parameter from code memory to data structure
    memcpy(pBootCfg, OALPAtoCA(IMAGE_EBOOT_CFG_PA), sizeof(BOOT_CFG));
    return TRUE;
}

//------------------------------------------------------------------------------

BOOL BLWriteBootCfg(BOOT_CFG *pBootCfg)
{
    BOOL rc = FALSE;
    UINT32 retry = 4;
    OMAP5912_BOOT_TOC toc;
    VOID *pBase, *pCode, *pAddress;
    UINT32 size;

    // Update info in code segment
    memcpy(OALPAtoUA(IMAGE_EBOOT_CFG_PA), pBootCfg, sizeof(BOOT_CFG));
    
    // Prepare NOR TOC entry 
    memset(&toc, 0, sizeof(toc));
    toc.start = DEVICE_NOR_HEADER_SIZE - 0x00000200;
    toc.size  = IMAGE_EBOOT_NOR_SIZE;
    memcpy(toc.name, "X-LOADER", 8);

    // point to start of FLASH memory
    pBase = OALPAtoUA(DEVICE_NOR_PA);

    // Then unlock, erase, write & lock all eboot code
    while (retry-- > 0)
    {
        // Unlock and erase EBOOT partition
        size = DEVICE_NOR_HEADER_SIZE + IMAGE_EBOOT_NOR_SIZE;
        if (!OALFlashLock(pBase, pBase, size, FALSE))
        {
 	        KITLOutputDebugString("Flash unlock failed\r\n");
            continue;
        }
        if (!OALFlashErase(pBase, pBase, size))
        {
 	        KITLOutputDebugString("Flash erase failed\r\n");
            continue;
        }
        // Write NOR header
        pAddress = OALPAtoUA(DEVICE_NOR_PA + 0x0200);
        if (!OALFlashWrite(pBase, pAddress, sizeof(toc), &toc))
        {
 	        KITLOutputDebugString("Flash write failed\r\n");
            continue;
        }
        // Write rest of code
        pAddress = OALPAtoUA(IMAGE_EBOOT_NOR_PA);
        pCode = OALPAtoUA(IMAGE_EBOOT_CODE_PA);
        if (!OALFlashWrite(pBase, pAddress, IMAGE_EBOOT_NOR_SIZE, pCode))
        {
 	        KITLOutputDebugString("Flash write failed\r\n");
            continue;
        }
        // Lock EBOOT partition        

        if (!OALFlashLock(pBase, pBase, size, TRUE))
       	{
 	        KITLOutputDebugString("Flash lock failed\r\n");
       	}
        break;
    }

	if(!retry)
	{
	   KITLOutputDebugString("ERR: Write FAILED\r\n");
	}
    
    return (retry > 0);
}

//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -