/*******************************************************************************
 * 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   : boot ROM API header
 ******************************************************************************/
#ifndef ROM_API_H__
#define ROM_API_H__

#include <stdint.h>
#include <image_load.h>

#define SECURE_BOOT (0x0U)
#define NORMAL_BOOT (0x211883DFU)

#define ROMAPI_OK                           (0x00000000U)
#define ROM_ERR_IMG_VERIFIER_NO_ENCRYPT_IMG (0xF100001DU)

#define LCS_CM                  (0x00000000U)   /* CM */
#define LCS_DM                  (0x00000001U)   /* DM */
#define LCS_SD                  (0x00000003U)   /* SD */
#define LCS_SE                  (0x00000005U)   /* SE */
#define LCS_FA                  (0x00000007U)   /* FA */

/* BOOTROM API address */
#define ROM_GETLCS              (0x01104418U)
#define ROM_SECUREBOOT_VERIFY   (0x011044C8U)
#define ROM_SECUREBOOT_DECRYPT  (0x011044D0U)
#define ROM_SECUREBOOT_COMPARE  (0x011044D8U)

/* For build option SW_VERSION_CHECK */
#define OPT_VERSION_CHECK_ENABLE    (1U)

typedef uint32_t (*ROM_SECUREBOOT_VERIFY_API)(uint32_t *pKeyCert, uint32_t *pContentCert);
typedef uint32_t (*ROM_SECUREBOOT_DECRYPT_API)(uint32_t *pContentCert);
typedef uint32_t (*ROM_SECUREBOOT_COMPARE_API)(uint32_t *pContentCert,
                                                uint32_t *hash,
                                                uint32_t hash_size);
typedef uint32_t (*ROM_GETLCS_API)(uint32_t *pLcs, uint32_t lcs_size);

static inline uint32_t get_load_info_id(const LOAD_INFO *li)
{
    return ((li->cnt_cert_addr - (SA9_DEST_ADDR + CONTENT_CERT_OFFSET)) / CONTENT_CERT_SIZE);
}
/* End of function get_load_info_id(LOAD_INFO *li) */

void rom_secureboot(LOAD_INFO* li);
uint32_t call_ROM_GetLcs(uint32_t *pLcs, uint32_t lcs_size);
void sw_version_check(const LOAD_INFO* li);
void auth_min_ver_tbl(LOAD_INFO* li);
void preload_verify_cntcert(const LOAD_INFO* li);

#endif /* ROM_API_H__ */
