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

📄 imginfo.c

📁 mstar 776 开发的车载dvd
💻 C
字号:
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2007 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// (¨MStar Confidential Information〃) by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////

#define IMGINFO_C

#include <string.h>

#include "Datatype.h"
#include "sysinfo.h"
#include "ImgInfo.h"
#include "Panel.h"
#include "DrvFlash.h"
#include "SramVar.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Any change of MS_IMG_INFO may not be backward compatible with external tool and previously released bootloader
MS_IMG_INFO code g_ImgInfo =
{
#if (BOOTLOADER_SYSTEM)
// Bootloader image
    MAGIC_BOOTLOADER,               // Magic number of bootloader
    0,                              // CRC32 of the bootloader image (code+pack). Filled by external tool
    0,                              // Size of the bootloader image (code+pack). Filled by external tool

    // Pack
    BIN_HEADER_ADDR,                // Flash offset of pack information

    // MCU8051 (Bootloader) code memory information
    {
        BOOTLOADER_CODE_SIZE,       // Source size in bytes
        0,                          // Flash offset relative to bootloader image.
        CODE_MAP_BASE_ADR           // DRAM start address to be loaded at.
    },

    // AEON code memory information: invalid in bootloader image because of system code dependent
    {
        0,
        0,
        0
    },

    // Database memory information: invalid in bootloader image because of system code dependent)
    {
        0,
        0,
        0
    },

    // Bootloader version
    BOOT_VER_EVENT,                 // Major number of bootloader version
    BOOT_VER_NUM,                   // Minor number of bootloader version
    0,                              // Revision number of bootloader version

    // SW version
    SW_VER_EVENT,                   // Major number of SW version
    SW_VER_NUM,                     // Minor number of SW version
    0,                              // Revision number of SW version

    // HW version
    HW_VER,                         // Hardware version number

    // Board type
    MS_BOARD_TYPE_SEL,

    // Model name
    MODEL_NAME,

    // Panel name
    PANEL_NAME,

    // Panel type
    PANEL_TYPE_SEL,

    // Reserved
    // U8      u8Reserved[32];        // Reserved for future use
#else
// App image
    MAGIC_APP,                      // Magic number of app image
    0,                              // CRC32 of the system image (code+pack). Filled by external tool
    0,                              // Size of the system image (code+pack). Filled by external tool

    // Pack
    BIN_HEADER_ADDR,                // Flash offset of pack information

    // MCU8051 (System) code information
    {
        MCU_CODE_SIZE,              // Source size in bytes
        0,                          // Flash offset relative to system image.
        CODE_MAP_BASE_ADR           // DRAM start address to be loaded at.
    },

    #if (MCU_AEON_ENABLE)
    // AEON code information
    {
        0,                          // Source size in bytes. Invalid: need to get it from pack bin.
        0,                          // Flash offset. Invalid: need to get it from pack bin.
        AEON_CODE_BASE_ADR,         // DRAM start address to be loaded at.
    },
    #else
    // AEON code memory information: N/A
    {
        0,
        0,
        0
    },
    #endif

    // Database memory information
    {
        DATABASE_LEN,               // Source size in bytes
        SYSTEM_BANK_DATADASE_BASE,  // Flash offset. To be defined!
        DATABASE_START_ADR          // DRAM start address to be loaded at.
    },

    // Bootloader version
    BOOT_VER_EVENT,                 // Major number of bootloader version
    BOOT_VER_NUM,                   // Minor number of bootloader version
    0,                              // Revision number of bootloader version

    // SW version
    SW_VER_EVENT,                   // Major number of SW version
    SW_VER_NUM,                     // Minor number of SW version
    0,                              // Revision number of SW version

    // HW version
    HW_VER,                         // Hardware version number

    // Board type
    MS_BOARD_TYPE_SEL,

    // Model name
    MODEL_NAME,

    // Panel name
    PANEL_NAME,

    // Panel type
    PANEL_TYPE_SEL,
    
    // Reserved
    // U8      u8Reserved[32];        // Reserved for future use
#endif
};

///////////////////////////////////////////////////////

BOOLEAN MApp_ImgInfo_IsBootImage(MS_IMG_INFO *pImgInfo)
{
    return (pImgInfo->u32Magic == MAGIC_BOOTLOADER);
}

BOOLEAN MApp_ImgInfo_IsAppImage(MS_IMG_INFO *pImgInfo)
{
    return (pImgInfo->u32Magic == MAGIC_APP);
}

void MApp_ImgInfo_GetBootInfo(MS_IMG_INFO *pImgInfo)
{
    MDrv_Flash_Read(IMG_INFO_OFFSET, sizeof(MS_IMG_INFO), (U8 *)pImgInfo);
}

void MApp_Imginfo_GetAppInfo(MS_IMG_INFO *pImgInfo)
{
    MDrv_Flash_Read((U32)BOOTLOADER_CODE_SIZE + IMG_INFO_OFFSET, sizeof(MS_IMG_INFO), (U8 *)pImgInfo);
}

void MApp_Imginfo_GetCurModel(U8 *pModel)
{
    MS_IMG_INFO ImgInfo;

    pModel[0] = 0;

    MApp_Imginfo_GetAppInfo(&ImgInfo);
    
    if (!MApp_ImgInfo_IsAppImage(&ImgInfo))
    {
        MApp_ImgInfo_GetBootInfo(&ImgInfo);
        if (!MApp_ImgInfo_IsBootImage(&ImgInfo))
        {
            return;
        }
    }
    
    memcpy(pModel, ImgInfo.u8ModelName, IMG_MODEL_NAME_LEN);

    pModel[IMG_MODEL_NAME_LEN] = 0;

}

BOOLEAN MApp_ImgInfo_IsSameModelAndPanelType(MS_IMG_INFO *pImgInfo, U8 *pModel)
{
    return ((pImgInfo->u8PanelType == PANEL_TYPE_SEL) && (0 == strcmp(pImgInfo->u8ModelName, pModel)));
}

#if (BOOTLOADER_SYSTEM)
void MApp_ImgInfo_VersionToString(U8 u8Major, U8 u8Minor, U8 *pBuffer)
#else
void MApp_ImgInfo_VersionToString(U8 u8Major, U8 u8Minor, U16 *pBuffer)
#endif
{
    U8 ndx = 0;

    if (u8Major >= 100)
    {
        pBuffer[ndx++] = u8Major/100 + '0';
        u8Major %= 100;
    }
    pBuffer[ndx++] = u8Major/10 + '0';
    pBuffer[ndx++] = u8Major%10 + '0';
    
    pBuffer[ndx++] = '.';
    
    if (u8Minor >= 100)
    {
        pBuffer[ndx++] = u8Minor/100 + '0';
        u8Minor %= 100;
    }
    pBuffer[ndx++] = u8Minor/10 + '0';
    pBuffer[ndx++] = u8Minor%10 + '0';
    
    pBuffer[ndx] = 0;
}

#if (BOOTLOADER_SYSTEM)
BOOLEAN MApp_ImgInfo_GetBootVersion(U8 *pBuffer)
{
    MApp_ImgInfo_VersionToString((U8)BOOT_VER_EVENT, (U8)BOOT_VER_NUM, pBuffer);
    return TRUE;
}

BOOLEAN MApp_ImgInfo_GetAppVersion(U8 *pBuffer)
{
    MS_IMG_INFO ImgInfo;
    
    MApp_Imginfo_GetAppInfo(&ImgInfo);
    if (MApp_ImgInfo_IsAppImage(&ImgInfo))
    {
        if (ImgInfo.u8SW_VerMajor <= 99 && ImgInfo.u8SW_VerMinor <= 99)
        {
            MApp_ImgInfo_VersionToString(ImgInfo.u8SW_VerMajor, ImgInfo.u8SW_VerMinor, pBuffer);
            return TRUE;
        }
    }

    // Illegal version
    pBuffer[0] = 0;
    return FALSE;
}

#else
BOOLEAN MApp_ImgInfo_GetBootVersion(U16 *pBuffer)
{
    MS_IMG_INFO ImgInfo;
    
    MApp_ImgInfo_GetBootInfo(&ImgInfo);
    if (MApp_ImgInfo_IsBootImage(&ImgInfo))
    {
        if (ImgInfo.u8BL_VerMajor <= 99 && ImgInfo.u8BL_VerMinor <= 99)
        {
            MApp_ImgInfo_VersionToString(ImgInfo.u8BL_VerMajor, ImgInfo.u8BL_VerMinor, pBuffer);
            return TRUE;
        }
    }

    // Illegal version
    pBuffer[0] = 0;
    return FALSE;
}

BOOLEAN MApp_ImgInfo_GetAppVersion(U16 *pBuffer)
{
    MApp_ImgInfo_VersionToString((U8)SW_VER_EVENT, (U8)SW_VER_NUM, pBuffer);
    return TRUE;
}
#endif

⌨️ 快捷键说明

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