/*******************************************************************************
 * DISCLAIMER
 * This software is supplied by Renesas Electronics Corporation and is only
 * intended for use with Renesas products. No other uses are authorized. This
 * software is owned by Renesas Electronics Corporation and is protected under
 * all applicable laws, including copyright laws.
 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * Renesas reserves the right, without notice, to make changes to this software
 * and to discontinue the availability of this software. By using this software,
 * you agree to the additional terms and conditions found by accessing the
 * following link:
 * http://www.renesas.com/disclaimer
 * Copyright 2021-2022 Renesas Electronics Corporation All rights reserved.
 *******************************************************************************/

/*******************************************************************************
 * DESCRIPTION   : Image load function for eMMC header
 ******************************************************************************/

#ifndef LOAD_IMAGE_EMMC_H_
#define LOAD_IMAGE_EMMC_H_

#include <image_load.h>
#include <ram_def.h>
#include <log.h>
#include <rom_api.h>

/* define */
/* eMMC */
#define EMMC_TOP            (0x00000000U)
#define EMMC_BOOT_PART_SIZE (31U * 1024U * 1024U)    /* 31MB */
#define EMMC_END            ((EMMC_TOP + EMMC_BOOT_PART_SIZE) - 1U)
#define SRC_TOP (EMMC_TOP)
#define SRC_END (EMMC_END)

/* For eMMC */
#define EMMC_SECTOR_SIZE                 (512U)
#define EMMC_SECTOR_SIZE_SHIFT           (9U)           /* 512 = 2^9 */
#define EMMC_CONTENT_CERT_ADDR           (0x00240000U)
#define EMMC_CONTENT_CERT_SECTOR_NUMBER  (EMMC_CONTENT_CERT_ADDR >> EMMC_SECTOR_SIZE_SHIFT)
#define EMMC_PARTITION_1                 (1U)
#if (SW_VERSION_CHECK == OPT_VERSION_CHECK_ENABLE)
#define EMMC_VER_TBL_OFFSET              (0x0000D000U)
#define EMMC_VER_TBL_CNT_CERT_ADDR       (EMMC_CONTENT_CERT_ADDR + EMMC_VER_TBL_OFFSET)
#define EMMC_VER_TBL_CNT_CERT_SEC_NUM    (EMMC_VER_TBL_CNT_CERT_ADDR >> EMMC_SECTOR_SIZE_SHIFT)
#endif /* (SW_VERSION_CHECK == OPT_VERSION_CHECK_ENABLE) */

static inline void load_image_info_print_for_emmc(const LOAD_INFO* li)
{
    NOTICE("======== %s image load info ========\n"
        "load address \t= 0x%08x\n" "image size \t= 0x%08x\n"
        "source address \t= (p:%d)0x%08x\n",
        li->name, li->boot_addr, li->image_size,
        li->part_num, li->src_addr);
}

static inline uint32_t get_part_num_in_cert(uint32_t id)
{
    return (SA9_DEST_ADDR + ((id + 1U) * 0x10U));
}

/* Prototype */
uint32_t load_content_cert_for_emmc(void);
#endif /* LOAD_IMAGE_EMMC_H_ */

