//
// 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 OR INDEMNITIES.
//

// -- Intel Copyright Notice --
// 
// @par
// Copyright (c) 2002-2008 Intel Corporation All Rights Reserved.
// 
// @par
// The source code contained or described herein and all documents
// related to the source code ("Material") are owned by Intel Corporation
// or its suppliers or licensors.  Title to the Material remains with
// Intel Corporation or its suppliers and licensors.
// 
// @par
// The Material is protected by worldwide copyright and trade secret laws
// and treaty provisions. No part of the Material may be used, copied,
// reproduced, modified, published, uploaded, posted, transmitted,
// distributed, or disclosed in any way except in accordance with the
// applicable license agreement .
// 
// @par
// No license under any patent, copyright, trade secret or other
// intellectual property right is granted to or conferred upon you by
// disclosure or delivery of the Materials, either expressly, by
// implication, inducement, estoppel, except in accordance with the
// applicable license agreement.
// 
// @par
// Unless otherwise agreed by Intel in writing, you may not remove or
// alter this notice or any other notice embedded in Materials by Intel
// or Intel's suppliers or licensors in any way.
// 
// @par
// For further details, please see the file README.TXT distributed with
// this software.
// 
// @par
// -- End Intel Copyright Notice --
//

//------------------------------------------------------------------------------
//
//  File:  sdmmc.c
//
//  This file implements bootloader functions related to SD/MMC download
//  
#include <windows.h>
#include <blcommon.h>
#include <sdfat.h>

//------------------------------------------------------------------------------
//
//  Static: g_fnFileInfo
//
//  This structure contains local state variables.
//
FILEINFO g_fnFileInfo;

//------------------------------------------------------------------------------
//
//  Function:  BLSDMMCDownload
//
//  This function initialize SD/MMC controller and file system
//
UINT32 BLSDMMCDownload(CHAR *szBinFileName)
{
    if(!FATInitDisk())
    {
        return BL_ERROR;
    }
    
    if(!FATOpenFile(&g_fnFileInfo, szBinFileName))
    {
        return BL_ERROR;
    }
    
    return BL_DOWNLOAD;
}

//------------------------------------------------------------------------------
//
//  Function:  BLSDMMCReadData
//
//  Read data from SD/MMC card through FAT file system
//
BOOL BLSDMMCReadData(DWORD cbData, LPBYTE pbData)
{
    if(FATReadFile(&g_fnFileInfo, pbData, cbData) != cbData)
    {
        RETAILMSG(TRUE, (TEXT("BLSDMMCReadData(): read image data failure\r\n")));
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}

