/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * 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 the copyright holder 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
 * HOLDER 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.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * Description:
 *
 *---------------------------------------------------------------------------*/

#ifndef X_LDR_ENV_H
#define X_LDR_ENV_H

#include "x_bim.h"

#ifndef CC_LDR_ENV_OFFSET
#define CC_LDR_ENV_OFFSET            (0xf000) // use 60k~64k to save loader env.
#endif /* CC_LDR_ENV_OFFSET */

#define LDR_TIMESTAMP_SIZE 32

// for loader use
#define LDR_SetDramTimeLog(x)   ((LDR_ENV_T*)CC_LDR_ENV_OFFSET)->au4TimeStamp[(x)] = BIM_READ32(REG_RW_TIMER2_LOW)

#define USIG_VERIFY_FAIL 0
#define USIG_DO_UPGRADE '1'
#define USIG_RUN_ON_USB '2'
#define USIG_DO_DIAG		'3'

typedef struct
{
    CHAR    szCustomer[16];
    CHAR    szMagic[16];
    CHAR    szModel[32];
    CHAR    szVersion[64];
} LDR_ENV_HDR_T;

typedef union
{
    UINT8           au1Raw[128];
    LDR_ENV_HDR_T   rHdr;
} LDR_ENV_HDR_UNION_T;

typedef struct
{
    UINT32 u4LoaderPlainSize;
    UINT32 u4LoaderLzhsSize;
    UINT32 u4LoaderLzhsAddress;
    UINT32 u4CfgFlag;
    //0x010
    LDR_ENV_HDR_UNION_T u; //128byte
    //0x090
    UINT32 au4TimeStamp[LDR_TIMESTAMP_SIZE]; //128byte
    //0x110
    UINT8 au1DtvCfg[16]; //DTVCFG_T use 9bytes
    //0x120
    UINT32 au4CustKey[64]; //2048bit key
    //0x220
    CHAR szUenv[128]; //additional uboot env
    //0x2a0
#if defined(CC_EMMC_BOOT)
    UINT8 szMSDCenv[72];  // preloader -> loader
    //0x2E0
    UINT8 szMSDCenv1[64]; //loader -> uboot 
	//0x320
#endif
	#if defined(CC_LOADER_CONSOLE_KEY_SUPPORT)

	UINT8 console_key[16];  // preloader -> loader
	UINT8 console_iv[16]; //preloader -> loader
	#endif
#if defined(CC_SECURE_BOOT_SCRAMBLE)
	
	UINT8 aes_key2[16];  // preloader -> loader
	UINT8 aes_iv2[16]; //preloader -> loader
#endif
	UINT8 AndroidSerailNo[16];  // customized android serial no.

} LDR_ENV_T;



#endif // X_LDR_ENV_H
