/*******************************************************************************
 * 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-2024 Renesas Electronics Corporation All rights reserved.
 *******************************************************************************/

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

#ifndef LOAD_IMAGE_FLASH_H_
#define LOAD_IMAGE_FLASH_H_

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

/* define */
/* Flash address */
#define FLASH_BASE      (0x08000000U)
#define FLASH_SIZE      (0x04000000U)
#define FLASH_END       ((FLASH_BASE + FLASH_SIZE) - 1U)
#define SRC_TOP         (FLASH_BASE)
#define SRC_END         (FLASH_END)

/* Flash address of content certificate */
#define CONTENT_CERT_SA (9U)        /* Content Cert SA9 */
#define SA_SIZE         (0x00040000U)
#define CONTENT_CERT_2nd_OFFSET         (0x00280000U)    /* 256KB * 10 */
#define FLASH_CONTENT_CERT_ADDR (uint32_t)(FLASH_BASE + (SA_SIZE * CONTENT_CERT_SA))    /* FLASH Base + SA9 offset */
#if (SW_VERSION_CHECK == OPT_VERSION_CHECK_ENABLE)
#define VER_TBL_CNT_CERT_OFFSET         (0x0000D000U)
#define FLASH_VER_TBL_CNT_CERT_ADDR     (FLASH_CONTENT_CERT_ADDR + VER_TBL_CNT_CERT_OFFSET) /* SA9 top + offset */
#endif /* (SW_VERSION_CHECK == OPT_VERSION_CHECK_ENABLE) */
#if (RTOS_LOAD_NUM == RTOS_LOAD_NUM_3)
#define RTOS12_CNT_CERT_OFFSET          (0x0000E000U)
#define FLASH_RTOS12_CNT_CERT_ADDR      (FLASH_CONTENT_CERT_ADDR + RTOS12_CNT_CERT_OFFSET)  /* SA9 top + offset */
#endif /* RTOS_LOAD_NUM == RTOS_LOAD_NUM_3 */

static inline void load_image_info_print_for_flash(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= 0x%08x\n",
        li->name, li->boot_addr, li->image_size, li->src_addr);
}

/* Prototype */
uint32_t load_content_cert_for_flash(int slot);
#endif /* LOAD_IMAGE_FLASH_H_ */

