Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
config MTK_SECURITY_SW_SUPPORT
bool "Mediatek Security SW Support"
help
If yes,
All security functions in preloader/LK/kernel/android
will be built into software images.
Otherwise, they will not be built into software images.
config MTK_SEC_MODEM_NVRAM_ANTI_CLONE
bool "Modem NVRam Anti-Clone Support"
help
This option is used to enable modem NVRAM anti-clone functionality
[dependency_relationship]: yes If this option is turned on, the
modem part should also turn on for the following setting 1. Modem
project file CUSTOM_OPTION += __NVRAM_BIND_TO_CHIP_CIPHER__ 2. by
default, only two LID is defaulted has MSP attribute
(1)NVRAM_EF_SML_LID (2)NVRAM_EF_SIM_LOCK_LID 3. if want to turn on
specific LID, please add attribute NVRAM_ATTR_MSP
config MTK_AVB20_SUPPORT
bool "Android Verified Boot 2.0 Support"
help
This option is used to enable AVB2.0, which stands for Android
Verified Boot 2.0. When enabled, linux kernel sets up dm-verity
for protected partitions(system/vendor, etc.) through vbmeta struct
instead of original dm-verity metadata.
+37
View File
@@ -0,0 +1,37 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 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 the
# GNU General Public License for more details.
#
ifeq ($(CONFIG_MTK_SECURITY_SW_SUPPORT), y)
#######################################
# Specify source files
#######################################
#include $(MTK_ROOT_BUILD)/Makefile
MTK_PLATFORM := $(subst ",,$(CONFIG_MTK_PLATFORM))
MASP_CORE_DRIVER_DIR := $(srctree)/drivers/misc/mediatek/masp
#Kernel 3.18 always use asfv2
asf_link := asfv2
############################################
#[core_obj] include all the files under asf/core
################################################
include $(MASP_CORE_DRIVER_DIR)/$(asf_link)/Makefile.core
include $(MASP_CORE_DRIVER_DIR)/$(asf_link)/Makefile.mach
# INCLUDE ASP LIBRARY
sec-y += $(core_obj) $(mach_obj)
# BUILD-IN
obj-y += sec.o
endif
@@ -0,0 +1,19 @@
#######################################
# Specify source files
#######################################
core_obj += $(asf_link)/core/sec_boot_core.o
core_obj += $(asf_link)/core/sec_mod_core.o
core_obj += $(asf_link)/core/sec_osal.o
core_obj += $(asf_link)/core/sec_legacy.o
core_obj += $(asf_link)/module/sec_mod.o
ifneq ($(wildcard $(MASP_CORE_DRIVER_DIR)/$(asf_link)/module/$(MTK_PLATFORM)/sec_clk.c),)
core_obj += $(asf_link)/module/$(MTK_PLATFORM)/sec_clk.o
else
core_obj += $(asf_link)/module/sec_clk.o
endif
# HEADER FILE
ccflags-y += -I$(src)/$(asf_link)/asf_inc
ccflags-y += -I$(src)/$(asf_link)/asf_export_inc
ccflags-y += -I$(src)/$(asf_link)/module
@@ -0,0 +1,18 @@
###################################################################
#[mach_obj][HACC]: if TEE is enabled, HACC is done in secure world.
###################################################################
mach_obj += $(asf_link)/mach/hacc_lib.o
mach_obj += $(asf_link)/mach/hacc_export.o
mach_obj += $(asf_link)/mach/hacc_hk.o
mach_obj += $(asf_link)/mach/hacc_sk.o
mach_obj += $(asf_link)/mach/sec_lib.o
ifeq (,$(wildcard $(MASP_CORE_DRIVER_DIR)/$(asf_link)/mach/$(MTK_PLATFORM)))
mach_obj += $(asf_link)/mach/security_ao_dummy.o
else
mach_obj += $(asf_link)/mach/$(MTK_PLATFORM)/security_ao.o
endif
ccflags-y += -I$(src)/$(asf_link)/asf_inc
@@ -0,0 +1,80 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SEC_EXPORT_H
#define SEC_EXPORT_H
/**************************************************************************
* Security Module ERROR CODE
**************************************************************************/
#define SEC_OK 0x0000
/* IMAGE CIPHER */
#define ERR_IMAGE_CIPHER_KEY_ERR 0x1000
#define ERR_IMAGE_CIPHER_IMG_NOT_FOUND 0x1001
#define ERR_IMAGE_CIPHER_READ_FAIL 0x1002
#define ERR_IMAGE_CIPHER_WRONG_OPERATION 0x1003
#define ERR_IMAGE_CIPHER_DEC_TEST_ERROR 0x1004
#define ERR_IMAGE_CIPHER_ENC_TEST_ERROR 0x1005
#define ERR_IMAGE_CIPHER_HEADER_NOT_FOUND 0x1006
#define ERR_IMAGE_CIPHER_DEC_Fail 0x1007
/* AUTH */
#define ERR_AUTH_IMAGE_VERIFY_FAIL 0x2000
#define ERR_AES_KEY_NOT_FOUND 0x2005
/* LIB */
#define ERR_LIB_SEC_CFG_NOT_EXIST 0x3000
#define ERR_LIB_VER_INVALID 0x3001
#define ERR_LIB_SEC_CFG_ERASE_FAIL 0x3002
#define ERR_LIB_SEC_CFG_CANNOT_WRITE 0x3003
/* SECURE DOWNLOAD / IMAGE VERIFICATION */
#define ERR_IMG_VERIFY_THIS_IMG_INFO_NOT_EXIST 0x4000
#define ERR_IMG_VERIFY_HASH_COMPARE_FAIL 0x4001
#define ERR_IMG_VERIFY_NO_SPACE_ADD_IMG_INFO 0x4002
#define ERR_SEC_DL_TOKEN_NOT_FOUND_IN_IMG 0x4003
#define ERR_SEC_DL_FLOW_ERROR 0x4004
/* IMAGE DOWNLOAD LOCK */
#define ERR_IMG_LOCK_TABLE_NOT_EXIST 0x5000
#define ERR_IMG_LOCK_ALL_LOCK 0x5001
#define ERR_IMG_LOCK_NO_SPACE_ADD_LOCK_INFO 0x5002
#define ERR_IMG_LOCK_THIS_IMG_INFO_NOT_EXIST 0x5003
#define ERR_IMG_LOCK_MAGIC_ERROR 0x5004
/* KERNEL DRIVER */
#define ERR_KERNEL_CRYPTO_INVALID_MODE 0xA000
/**************************************************************************
* Security Module Export API
**************************************************************************/
int masp_boot_init(void);
void masp_secure_algo(unsigned char Direction,
unsigned char *ContentAddr,
unsigned int ContentLen,
unsigned char *CustomSeed,
unsigned char *ResText);
unsigned char masp_secure_algo_init(void);
unsigned char masp_secure_algo_deinit(void);
int masp_ccci_signfmt_verify_file(char *file_path,
unsigned int *data_offset,
unsigned int *data_sec_len);
int masp_ccci_version_info(void);
int masp_ccci_is_cipherfmt(int fp_id, unsigned int start_off,
unsigned int *img_len);
int masp_ccci_decrypt_cipherfmt(int fp_id,
unsigned int start_off,
char *buf,
unsigned int buf_len,
unsigned int *data_offset);
unsigned char masp_secro_en(void);
unsigned int masp_secro_md_len(unsigned char *md_info);
unsigned int masp_secro_md_get_data(unsigned char *md_info,
unsigned char *buf,
unsigned int offset, unsigned int len);
unsigned int masp_secro_blk_sz(void);
#endif /* SEC_EXPORT_H */
@@ -0,0 +1,69 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SEC_OSAL_H
#define SEC_OSAL_H
/**************************************************************************
* Operating System Abstract Layer - ERROR Definition
**************************************************************************/
#define OSAL_FILE_NULL (0)
#define OSAL_FILE_OPEN_FAIL (-1)
#define OSAL_FILE_CLOSE_FAIL (-2)
#define OSAL_FILE_SEEK_FAIL (-3)
#define OSAL_FILE_GET_POS_FAIL (-4)
#define OSAL_FILE_READ_FAIL (-5)
/**************************************************************************
* Operating System Abstract Layer - External Function
**************************************************************************/
void osal_kfree(void *buf);
void *osal_kmalloc(unsigned int size);
unsigned long osal_copy_from_user(void *to, void *from, unsigned long size);
unsigned long osal_copy_to_user(void *to, void *from, unsigned long size);
int osal_hacc_lock(void);
void osal_hacc_unlock(void);
int osal_verify_lock(void);
void osal_verify_unlock(void);
int osal_secro_lock(void);
void osal_secro_unlock(void);
int osal_secro_v5_lock(void);
void osal_secro_v5_unlock(void);
int osal_mtd_lock(void);
void osal_mtd_unlock(void);
int osal_rid_lock(void);
void osal_rid_unlock(void);
void osal_msleep(unsigned int msec);
void osal_assert(unsigned int val);
int osal_set_kernel_fs(void);
void osal_restore_fs(void);
void *osal_get_filp_struct(int fp_id);
long long osal_filp_seek_set(int fp_id, long long off);
long long osal_filp_seek_end(int fp_id, long long off);
long long osal_filp_pos(int fp_id);
long osal_filp_read(int fp_id, char *buf, unsigned long len);
long osal_is_err(int fp_id);
/**************************************************************************
* Operating System Abstract Layer - Macro
**************************************************************************/
#define SEC_ASSERT(a) osal_assert(a)
#define ASF_FILE int
#define ASF_FILE_NULL OSAL_FILE_NULL
#define ASF_GET_DS osal_set_kernel_fs()
#define ASF_PUT_DS osal_restore_fs()
#define ASF_FILE_ERROR(fp) (fp == OSAL_FILE_NULL)
#define ASF_SEEK_SET(fp, off) osal_filp_seek_set(fp, off)
#define ASF_SEEK_END(fp, off) osal_filp_seek_end(fp, off)
#define ASF_FILE_POS(fp) osal_filp_pos(fp)
#define ASF_MALLOC(len) osal_kmalloc(len)
#define ASF_FREE(buf) osal_kfree(buf)
#define ASF_READ(fp, buf, len) osal_filp_read(fp, buf, len)
#define ASF_STRTOK(str, delim) strsep(&str, delim)
#define ASF_IS_ERR(fp) osal_is_err(fp)
#endif /* SEC_OSAL_H */
@@ -0,0 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#define BUILD_TIME "CST 2015"
#define BUILD_BRANCH "(M)"
#define CCCI_VERSION 1
@@ -0,0 +1,72 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SEC_BOOT_LIB_H
#define SEC_BOOT_LIB_H
/**************************************************************************
* INCLUDE LINUX HEADER
**************************************************************************/
#include "sec_osal_light.h"
/**************************************************************************
* INCLUDE MTK HEADERS
**************************************************************************/
#include "masp_version.h"
#include <linux/types.h>
#include "sec_error.h"
#include "sec_osal.h"
#include "sec_mod.h"
/**************************************************************************
* [S-BOOT]
**************************************************************************/
/* S-BOOT Attribute */
#define ATTR_SBOOT_DISABLE 0x00
#define ATTR_SBOOT_ENABLE 0x11
#define ATTR_SBOOT_ONLY_ENABLE_ON_SCHIP 0x22
/**************************************************************************
* [S-USBDL]
**************************************************************************/
/* S-USBDL Attribute */
#define ATTR_SUSBDL_DISABLE 0x00
#define ATTR_SUSBDL_ENABLE 0x11
#define ATTR_SUSBDL_ONLY_ENABLE_ON_SCHIP 0x22
/**************************************************************************
* EXTERNAL VARIABLE
**************************************************************************/
/*extern AND_ROMINFO_T rom_info;*/
/*extern SECURE_INFO sec_info;*/
/*extern SECCFG_U seccfg;*/
/*extern AND_SECROIMG_T secroimg;*/
extern unsigned int g_rom_info_sbc_attr;
extern unsigned int g_rom_info_sdl_attr;
extern unsigned int g_hw_sbcen;
extern unsigned int g_lock_state;
extern unsigned int g_random_id[NUM_RID];
extern unsigned char g_crypto_seed[NUM_CRYPTO_SEED];
extern unsigned int g_sbc_pubk_hash[NUM_SBC_PUBK_HASH];
extern unsigned int lks;
/**************************************************************************
* EXPORT FUNCTION
**************************************************************************/
extern int masp_boot_init(void);
extern int sec_boot_enabled(void);
extern int sec_usbdl_enabled(void);
extern int sec_modem_auth_enabled(void);
extern int sec_schip_enabled(void);
extern int sec_get_random_id(unsigned int *rid);
/* HACC HW init */
extern unsigned int sec_boot_hacc_init(void);
#endif /* SEC_BOOT_LIB_H */
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SEC_CCCI_LIB_H
#define SEC_CCCI_LIB_H
int masp_ccci_signfmt_verify_file(char *file_path, unsigned int *data_offset,
unsigned int *data_sec_len);
int masp_ccci_version_info(void);
int masp_ccci_is_cipherfmt(int fp_id, unsigned int start_off,
unsigned int *img_len);
int masp_ccci_decrypt_cipherfmt(int fp_id, unsigned int start_off, char *buf,
unsigned int buf_len,
unsigned int *data_offset);
#endif /* SEC_CCCI_LIB_H */
@@ -0,0 +1,234 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SEC_ERROR_H
#define SEC_ERROR_H
/**************************************************************************
* COMPILE ASSERT
**************************************************************************/
#define COMPILE_ASSERT(condition) ((void)sizeof(char[1 - 2*!!!(condition)]))
#define SEC_OK 0x0000
/* IMAGE CIPHER */
#define ERR_IMAGE_CIPHER_KEY_ERR 0x1000
#define ERR_IMAGE_CIPHER_IMG_NOT_FOUND 0x1001
#define ERR_IMAGE_CIPHER_READ_FAIL 0x1002
#define ERR_IMAGE_CIPHER_WRONG_OPERATION 0x1003
#define ERR_IMAGE_CIPHER_DEC_TEST_ERROR 0x1004
#define ERR_IMAGE_CIPHER_ENC_TEST_ERROR 0x1005
#define ERR_IMAGE_CIPHER_HEADER_NOT_FOUND 0x1006
#define ERR_IMAGE_CIPHER_DEC_Fail 0x1007
/* SW AES */
#define ERR_AES_KEY_SIZE_ERR 0x2000
#define ERR_AES_ALLOCATE_CTX_ERR 0x2001
#define ERR_AES_ILEN_SHOULD_EQUAL_OLEN 0x2002
#define ERR_AES_DATA_NOT_MULTIPLE_OF_BLOCK_SIZE 0x2004
#define ERR_AES_KEY_NOT_FOUND 0x2005
/* ROM INFO */
#define ERR_ROM_INFO_ALLOCATE_BUF_FAIL 0x3000
#define ERR_ROM_INFO_MTD_OPEN_FAIL 0x3001
#define ERR_ROM_INFO_MTD_READ_FAIL 0x3002
#define ERR_ROM_INFO_MTD_NOT_FOUND 0x3003
#define ERR_ROM_INFO_RESET_FAIL 0x3004
#define ERR_ROM_INFO_MOD_READ_FAIL 0x3005
#define ERR_ROM_INFO_ID_INVALID 0x3006
#define ERR_INFO_MTD_NUM_INVALID 0x3007
#define ERR_INFO_PART_NOT_FOUND 0x3008
#define ERR_INFO_OVER_MAX_PART_COUNT 0x3009
/* SW RSA */
#define ERR_RSA_KEY_NOT_FOUND 0x4000
#define ERR_RSA_WRONG_SIGNATURE_LEN 0x4001
#define ERR_RSA_SIGNATURE_VERIFY_FAIL 0x4002
/* SW HASH */
#define ERR_HASH_WRONG_HASH_LEN 0x5000
/* HW AES */
#define ERR_KER_CRYPTO_INVALID_MODE 0x6000
#define ERR_HACC_MODE_INVALID 0x6001
#define ERR_HACC_KEY_INVALID 0x6002
#define ERR_HACC_DATA_UNALIGNED 0x6003
#define ERR_HACC_SEED_LEN_ERROR 0x6004
#define ERR_HACC_ENC_FAIL 0x6005
#define ERR_HACC_DEC_FAIL 0x6006
#define ERR_HACC_HW_WRAP_KEY_NOT_INIT 0x6007
#define ERR_HACC_SW_KEY_NOT_INIT 0x6008
#define ERR_SBOOT_HACC_INIT_FAIL 0x6009
#define ERR_SBOOT_HACC_LOCK_FAIL 0x600A
#define ERR_HACC_ENABLE_CLK_FAIL 0x600B
#define ERR_HACC_UNKNOWN_USER 0x600C
#define ERR_HACC_OPEN_SECURE_CONNECTION_FAIL 0x6010
#define ERR_HACC_REQUEST_SECURE_SERVICE_FAIL 0x6011
#define ERR_HACC_ALLOCATE_BUFFER_FAIL 0x6012
#define ERR_HACC_MCMAP_BUFFER_FAIL 0x6013
#define ERR_HACC_NOTIFY_TO_TRUSTLET_FAIL 0x6014
#define ERR_HACC_NOTIFY_FROM_TRUSTLET_FAIL 0x6015
#define ERR_HACC_CLOSE_SECURE_CONNECTION_FAIL 0x6016
/* SEC CFG */
#define ERR_SEC_CFG_ALLOCATE_BUF_FAIL 0x7000
#define ERR_SEC_CFG_MTD_OPEN_FAIL 0x7001
#define ERR_SEC_CFG_MTD_READ_FAIL 0x7002
#define ERR_SEC_CFG_MTD_NOT_FOUND 0x7003
#define ERR_SEC_CFG_END_PATTERN_NOT_EXIST 0x7004
#define ERR_SEC_CFG_STATUS_INVALID 0x7005
#define ERR_SEC_CFG_INVALID_ID 0x7006
#define ERR_SEC_CFG_INVALID_END_PATTERN 0x7007
#define ERR_SEC_CFG_MARK_INCOMPLETE_FAIL 0x7008
#define ERR_SEC_CFG_RESET_FAIL 0x7009
#define ERR_SEC_CFG_IMG_NOT_FOUND 0x700A
#define ERR_SEC_CFG_IS_FULL 0x700B
#define ERR_SEC_CFG_VERSION_INVALID 0x700C
#define ERR_SEC_CFG_EXT_REGION_SPACE_OVERFLOW 0x700D
#define ERR_SEC_CFG_MAGIC_INVALID 0x700E
#define ERR_SEC_CFG_EXT_REGION_SELF_COPY_FAIL 0x700F
#define ERR_SEC_CFG_EXT_REGION_OFFSET_INVALID 0x7010
#define ERR_SEC_CFG_EXT_REGION_SIZE_CHANGE 0x7011
/* SEC BOOT UPDATE */
#define ERR_SBOOT_UPDATE_IMG_NOT_FOUND_IN_SECCFG 0x8000
#define ERR_SBOOT_UPDATE_IMG_NOT_FOUND_IN_MTD 0x8001
#define ERR_SBOOT_UPDATE_IMG_OPEN_FAIL 0x8002
#define ERR_SBOOT_UPDATE_IMG_READ_FAIL 0x8003
#define ERR_SBOOT_UPDATE_SEC_CFG_FAIL 0x8004
#define ERR_SBOOT_UPDATE_SEC_RO_FAIL 0x8005
#define ERR_SBOOT_UPDATE_CANNOT_ROLLBACK_VER 0x8006
#define ERR_SBOOT_UPDATE_SEC_VER_NOT_FOUND 0x8007
#define ERR_SBOOT_UPDATE_CUST_NAME_MISMATCH 0x8008
#define ERR_SBOOT_UPDATE_IMG_INVALID 0x8009
#define ERR_SBOOT_UPDATE_CUST_NAME_CANNOT_BE_NULL 0x800A
/* SEC BOOT LIBRARY */
#define SEC_SBOOT_INFO_PART_NOT_FOUND 0x9000
#define SEC_SBOOT_OPEN_SEC_DRV_FAIL 0x9001
#define SEC_SBOOT_SEC_DRV_IOCTL_FAIL 0x9002
#define SEC_SBOOT_INFO_PART_WRITE_OPEN_FAIL 0x9003
#define SEC_SBOOT_INFO_PART_WRITE_FAIL 0x9004
#define SEC_SBOOT_INFO_INIT_FAIL 0x9005
#define SEC_SBOOT_STATUE_QUERY_FAIL 0x9006
#define SEC_SBOOT_NOT_ENABLED 0x9007
#define SEC_SUSBDL_STATUE_QUERY_FAIL 0x9008
#define SEC_SUSBDL_NOT_ENABLED 0x9009
#define SEC_SBOOT_MARK_STATUS_FAIL 0x900A
#define SEC_SBOOT_NOT_INIT_YET 0x900B
#define SEC_SBOOT_NOTIFY_DRIVER_FAIL 0x900C
#define SEC_SBOOT_INVALID_IMG_ATTR 0x900D
/* MTD / USIF */
#define ERR_MTD_INFO_NOT_FOUND 0xA000
#define ERR_MTD_PART_COUNT_INVALID 0xA001
#define ERR_MTD_PART_NOT_FOUND 0xA002
#define ERR_MTD_PART_READ_FAIL 0xA003
#define ERR_MTD_PART_WRITE_FAIL 0xA004
#define ERR_MTD_PART_ADJUST_OFFSET_FAIL 0xA005
#define ERR_MTD_PART_READ_MEMINFO_FAIL 0xA006
#define ERR_MTD_PART_INVALID_MEMINFO_FAIL 0xA007
#define ERR_MTD_NOT_SUPPORT_READ_YAFFS2 0xA008
#define ERR_USIF_PART_READ_FAIL 0xA009
#define ERR_USIF_PART_WRITE_FAIL 0xA00A
#define ERR_USIF_PROC_READ_FAIL 0xA00B
#define ERR_USIF_PROC_RN_NOT_FOUND 0xA00C
#define ERR_MTD_NOT_SUPPORT_WRITE_YAFFS2 0xA00D
#define ERR_USIF_NOT_SUPPORT_WRITE_YAFFS2 0xA00E
#define ERR_USIF_NOT_SUPPORT_READ_YAFFS2 0xA00F
#define ERR_GPT_PART_NAME_IS_NULL 0xA010
#define ERR_GPT_PART_NAME_NOT_FOUND 0xA011
/* SEC BOOT CHECK */
#define ERR_SBOOT_CHECK_IMG_NOT_FOUND_IN_SECCFG 0xB000
#define ERR_SBOOT_CHECK_IMG_NOT_FOUND_IN_MTD 0xB001
#define ERR_SBOOT_CHECK_IMG_OPEN_FAIL 0xB002
#define ERR_SBOOT_CHECK_IMG_READ_FAIL 0xB003
#define ERR_SBOOT_CHECK_SEC_CFG_FAIL 0xB004
#define ERR_SBOOT_CHECK_IMG_VERIFY_FAIL 0xB005
#define ERR_SBOOT_CHECK_INVALID_IMAGE_OFFSET 0xB006
#define ERR_SBOOT_CHECK_QUERY_ENABLED_FAIL 0xB007
#define ERR_SBOOT_CHECK_PART_INVALID_STATUS 0xB008
#define ERR_SBOOT_CHECK_MD_HDR_MAGIC_ERROR 0xB009
#define ERR_SBOOT_CHECK_MD_NAME_INVLAID 0xB00A
#define ERR_SBOOT_CHECK_MD_VER_CANNOT_ROLLBACK 0xB00B
#define ERR_SBOOT_CHECK_INVALID_IMG_MAGIC_NUM 0xB00C
#define ERR_SBOOT_CHECK_INVALID_MODEM 0xB00D
#define ERR_SBOOT_CHECK_FL_NAME_INVLAID 0xB00E
#define ERR_SBOOT_CHECK_FL_VER_CANNOT_ROLLBACK 0xB00F
#define ERR_SBOOT_CHECK_INVALID_IMG_TYPE 0xB010
#define ERR_SBOOT_CHECK_NULL_POINTER 0xB011
/* META */
#define ERR_META_NOT_CORRECT_MODE 0xC000
#define ERR_NVRAM_DATA_NOT_ALIGNED 0xC001
#define ERR_NVRAM_ENC_IOCTL_FAIL 0xC002
#define ERR_NVRAM_DEC_IOCTL_FAIL 0xC002
#define ERR_NVRAM_CIPHER_UT_FAIL 0xC003
/* YAFFS2 COMMON */
#define ERR_YAFFS2_PART_READ_FAIL 0xD000
/* FILE SYSTEM */
#define ERR_FS_ANDROID_SEC_LIST_NOT_SPECIFY 0xE000
#define ERR_FS_SECRO_SEC_LIST_NOT_SPECIFY 0xE001
#define ERR_FS_SEC_LIST_NOT_SPECIFY 0xE002
#define ERR_FS_READ_SEC_LIST_FAIL 0xE003
#define ERR_FS_SIGN_LENGTH_INVALID 0xE004
#define ERR_FS_READ_BUF_IS_NULL 0xE005
#define ERR_FS_OPEN_SEC_FILE_FAIL 0xE006
#define ERR_FS_READ_SEC_FILE_FAIL 0xE007
#define ERR_FS_READ_BUF_ALLOCATE_FAIL 0xE008
#define ERR_FS_READ_SIZE_FAIL 0xE009
#define ERR_FS_UNSUPPORT_IMAGE_NAME 0xE00A
#define ERR_FS_SEC_LIST_NOT_SIGNED 0xE00B
#define ERR_FS_READ_MODEM_FAIL 0xE00C
#define ERR_FS_MD_BIN_NOT_SPECIFY 0xE00D
#define ERR_FS_SECRO_OPEN_FAIL 0xE00E
#define ERR_FS_SECRO_READ_SIZE_CANNOT_BE_ZERO 0xE00F
#define ERR_FS_SECRO_READ_FAIL 0xE010
#define ERR_FS_SECRO_AP_INVALID 0xE011
#define ERR_FS_SECRO_MD_INVALID 0xE012
#define ERR_FS_SECRO_READ_WRONG_SIZE 0xE013
/* SIGN FORMAT */
#define ERR_SIGN_FORMAT_HASH_SIZE_WRONG 0xE100
#define ERR_SIGN_FORMAT_MAGIC_WRONG 0xE101
#define ERR_SIGN_FORMAT_GENERATE_HASH_FAIL 0xE102
#define ERR_SIGN_FORMAT_EXT_MAGIC_WRONG 0xE103
#define ERR_SIGN_FORMAT_EXT_HDR_MAGIC_WRONG 0xE104
#define ERR_SIGN_FORMAT_EXT_TYPE_NOT_SUPPORT 0xE105
#define ERR_SIGN_FORMAT_EXT_HDR_NOT_FOUND 0xE106
#define ERR_SIGN_FORMAT_CAL_HASH_BY_CHUNK_FAIL 0xE107
/* SECRO IMAGE */
#define ERR_SECROIMG_MTD_NOT_FOUND 0xF000
#define ERR_SECROIMG_HACC_IS_LOCK 0xF001
#define ERR_SECROIMG_HACC_INIT_FAIL 0xF002
#define ERR_SECROIMG_DECRYPT_INVALID 0xF003
#define ERR_SECROIMG_PART_NOT_FOUND 0xF004
#define ERR_SECROIMG_INVALID_IMG_LEN 0xF005
#define ERR_SECROIMG_ALLOCATE_BUF_FAIL 0xF006
#define ERR_SECROIMG_IS_EMPTY 0xF007
#define ERR_SECROIMG_MD_BUF_NOT_ENOUGH 0xF008
#define ERR_SECROIMG_HACC_AP_DECRYPT_FAIL 0xF009
#define ERR_SECROIMG_HACC_MD_DECRYPT_FAIL 0xF00A
#define ERR_SECROIMG_INVALID_BUF_LEN 0xF00B
#define ERR_SECROIMG_LEN_INCONSISTENT_WITH_PL 0xF00C
#define ERR_SECROIMG_HASH_CHECK_FAIL 0xF00D
#define ERR_SECROIMG_EMPTY_MD_INFO_STR 0xF00E
#define ERR_SECROIMG_MD_INFO_NOT_EXIST 0xF00F
#define ERR_SECROIMG_NEITHER_V3_NOR_V5_FORMAT 0xF010
#define ERR_SECROIMG_V5_HASH_CHECK_FAIL 0xF011
#define ERR_SECROIMG_V3_OFFSET_NOT_INIT 0xF012
#endif /* SEC_ERROR_H */
@@ -0,0 +1,34 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2012 MediaTek Inc.
*/
#ifndef __MT_SEC_HAL_H__
#define __MT_SEC_HAL_H__
enum hacc_user {
HACC_USER1 = 0,
HACC_USER2,
HACC_USER3,
HACC_USER4
};
/*int masp_hal_get_uuid(unsigned int *uuid);*/
int masp_hal_sbc_enabled(void);
int masp_hal_get_sbc_checksum(unsigned int *pChecksum);
int masp_hal_set_dm_verity_error(void);
unsigned char masp_hal_secure_algo_init(void);
unsigned char masp_hal_secure_algo_deinit(void);
void masp_hal_secure_algo(unsigned char Direction, unsigned char *ContentAddr,
unsigned int ContentLen, unsigned char *CustomSeed,
unsigned char *ResText);
unsigned int masp_hal_sp_hacc_init(unsigned char *sec_seed, unsigned int size);
unsigned int masp_hal_sp_hacc_blk_sz(void);
unsigned char *masp_hal_sp_hacc_enc(unsigned char *buf, unsigned int size,
unsigned char bAC,
enum hacc_user user, unsigned char bDoLock);
unsigned char *masp_hal_sp_hacc_dec(unsigned char *buf, unsigned int size,
unsigned char bAC,
enum hacc_user user, unsigned char bDoLock);
#endif /* !__MT_SEC_HAL_H__ */
@@ -0,0 +1,59 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SEC_IOCTL_H
#define SEC_IOCTL_H
struct sec_rid {
unsigned int rid_val[4];
};
/* use 's' as magic number */
#define SEC_IOC_MAGIC 's'
/* random id */
#define SEC_GET_RANDOM_ID _IOR(SEC_IOC_MAGIC, 1, struct sec_rid)
/* secure boot init */
#define SEC_BOOT_INIT _IOR(SEC_IOC_MAGIC, 2, unsigned int)
#define SEC_BOOT_IS_ENABLED _IOR(SEC_IOC_MAGIC, 3, unsigned int)
/* secure seccfg process */
#define SEC_SECCFG_DECRYPT _IOR(SEC_IOC_MAGIC, 4, unsigned int)
#define SEC_SECCFG_ENCRYPT _IOR(SEC_IOC_MAGIC, 5, unsigned int)
/* secure usbdl */
#define SEC_USBDL_IS_ENABLED _IOR(SEC_IOC_MAGIC, 6, unsigned int)
/* HACC HW */
#define SEC_HACC_CONFIG _IOR(SEC_IOC_MAGIC, 7, unsigned int)
#define SEC_HACC_LOCK _IOR(SEC_IOC_MAGIC, 8, unsigned int)
#define SEC_HACC_UNLOCK _IOR(SEC_IOC_MAGIC, 9, unsigned int)
#define SEC_HACC_ENABLE_CLK _IOR(SEC_IOC_MAGIC, 10, unsigned int)
/* secure boot check */
#define SEC_BOOT_PART_CHECK_ENABLE _IOR(SEC_IOC_MAGIC, 11, unsigned int)
#define SEC_BOOT_NOTIFY_MARK_STATUS _IOR(SEC_IOC_MAGIC, 12, unsigned int)
#define SEC_BOOT_NOTIFY_PASS _IOR(SEC_IOC_MAGIC, 13, unsigned int)
#define SEC_BOOT_NOTIFY_FAIL _IOR(SEC_IOC_MAGIC, 14, unsigned int)
#define SEC_BOOT_NOTIFY_RMSDUP_DONE _IOR(SEC_IOC_MAGIC, 15, unsigned int)
#define SEC_BOOT_NOTIFY_STATUS _IOR(SEC_IOC_MAGIC, 19, unsigned int)
/* rom info */
#define SEC_READ_ROM_INFO _IOR(SEC_IOC_MAGIC, 16, unsigned int)
/* META */
#define SEC_NVRAM_HW_ENCRYPT _IOR(SEC_IOC_MAGIC, 17, unsigned int)
#define SEC_NVRAM_HW_DECRYPT _IOR(SEC_IOC_MAGIC, 18, unsigned int)
/* HEVC */
#define SEC_HEVC_EOP _IOR(SEC_IOC_MAGIC, 20, unsigned int)
#define SEC_HEVC_DOP _IOR(SEC_IOC_MAGIC, 21, unsigned int)
#define SEC_IOC_MAXNR (22)
#define SEC_DEV "/dev/sec"
#endif /* end of SEC_IOCTL_H */
@@ -0,0 +1,21 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SEC_OSAL_LIGHT_H
#define SEC_OSAL_LIGHT_H
/**************************************************************************
* INCLUDE HEADERS
**************************************************************************/
#include <linux/string.h>
#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <stdbool.h>
#include <linux/printk.h>
#include <linux/io.h>
#include <linux/err.h>
#endif /* SEC_OSAL_LIGHT_H */
@@ -0,0 +1,158 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
/******************************************************************************
* INCLUDE LIBRARY
******************************************************************************/
#include "sec_boot_lib.h"
#include "sec_osal.h"
#include "sec_hal.h"
/**************************************************************************
* DEFINITIONS
**************************************************************************/
#define MOD "ASF"
/**************************************************************************
* LOCAL VARIABLE
**************************************************************************/
/**************************************************************************
* GLOBAL VARIABLE
**************************************************************************/
unsigned int g_rom_info_sbc_attr;
unsigned int g_rom_info_sdl_attr;
unsigned int g_hw_sbcen;
unsigned int g_lock_state;
unsigned int g_random_id[NUM_RID];
unsigned char g_crypto_seed[NUM_CRYPTO_SEED];
unsigned int g_sbc_pubk_hash[NUM_SBC_PUBK_HASH];
int sec_get_random_id(unsigned int *rid)
{
int ret = 0;
if (rid == NULL) {
SEC_ASSERT(0);
ret = ERR_SBOOT_CHECK_NULL_POINTER;
}
if (rid)
memcpy(rid, g_random_id, 16);
return ret;
}
/******************************************************************************
* CHECK IF SECURITY CHIP IS ENABLED
******************************************************************************/
int sec_schip_enabled(void)
{
if (true == masp_hal_sbc_enabled()) {
pr_debug("SC\n");
return 1;
}
pr_debug("NSC\n");
return 0;
}
/******************************************************************************
* CHECK IF SECURE USBDL IS ENABLED
******************************************************************************/
int sec_usbdl_enabled(void)
{
switch (g_rom_info_sdl_attr) {
case ATTR_SUSBDL_ENABLE:
pr_debug("[%s] SUSBDL is enabled\n", MOD);
pr_debug("0x%x, SD-FORCE\n", ATTR_SUSBDL_ENABLE);
return 1;
/* SUSBDL can't be disabled on security chip */
case ATTR_SUSBDL_DISABLE:
case ATTR_SUSBDL_ONLY_ENABLE_ON_SCHIP:
pr_debug("[%s] SUSBDL is only enabled on S-CHIP\n", MOD);
if (true == masp_hal_sbc_enabled()) {
pr_debug("0x%x, SD-SC\n",
ATTR_SUSBDL_ONLY_ENABLE_ON_SCHIP);
return 1;
}
pr_debug("0x%x, SD-NSC\n", ATTR_SUSBDL_ONLY_ENABLE_ON_SCHIP);
return 0;
default:
pr_debug("[%s] invalid susbdl config (SD-0x%x)\n",
MOD, g_rom_info_sdl_attr);
SEC_ASSERT(0);
return 1;
}
}
/******************************************************************************
* CHECK IF SECURE BOOT IS NEEDED
******************************************************************************/
int sec_boot_enabled(void)
{
switch (g_rom_info_sbc_attr) {
case ATTR_SBOOT_ENABLE:
pr_debug("[%s] SBOOT is enabled\n", MOD);
pr_debug("0x%x, SB-FORCE\n", ATTR_SBOOT_ENABLE);
return 1;
/* secure boot can't be disabled on security chip */
case ATTR_SBOOT_DISABLE:
case ATTR_SBOOT_ONLY_ENABLE_ON_SCHIP:
pr_debug("[%s] SBOOT is only enabled on S-CHIP\n", MOD);
if (true == masp_hal_sbc_enabled()) {
pr_debug("0x%x, SB-SC\n",
ATTR_SBOOT_ONLY_ENABLE_ON_SCHIP);
return 1;
}
pr_debug("0x%x, SB-NSC\n", ATTR_SBOOT_ONLY_ENABLE_ON_SCHIP);
return 0;
default:
pr_debug("[%s] invalid sboot config (SB-0x%x)\n",
MOD, g_rom_info_sbc_attr);
SEC_ASSERT(0);
}
return 0;
}
/**************************************************************************
* SECURE BOOT INIT HACC
**************************************************************************/
unsigned int sec_boot_hacc_init(void)
{
unsigned int ret = SEC_OK;
/* ----------------------------------- */
/* lnit hacc key */
/* ----------------------------------- */
ret = masp_hal_sp_hacc_init(g_crypto_seed, sizeof(g_crypto_seed));
if (ret != SEC_OK)
goto end;
end:
return ret;
}
/**************************************************************************
* SECURE BOOT INIT
**************************************************************************/
int masp_boot_init(void)
{
int ret = SEC_OK;
pr_debug("[%s] error (0x%x)\n", MOD, ret);
return ret;
}
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#include "sec_hal.h"
#include "sec_error.h"
#include "sec_boot_lib.h"
/******************************************************************************
* DEFINITIONS
******************************************************************************/
#define MOD "ASF"
/******************************************************************************
* CHECK IF SECROIMG IS USED
******************************************************************************/
unsigned char masp_secro_en(void)
{
return 0;
}
/******************************************************************************
* RETURN SECROIMG BLK SIZE
******************************************************************************/
unsigned int masp_secro_blk_sz(void)
{
return masp_hal_sp_hacc_blk_sz();
}
/******************************************************************************
* RETURN SECROIMG MD LENGTH
******************************************************************************/
unsigned int masp_secro_md_len(unsigned char *md_info)
{
return 0;
}
/******************************************************************************
* RETURN SECROIMG MD PLAINTEXT DATA
******************************************************************************/
unsigned int masp_secro_md_get_data(unsigned char *md_info, unsigned char *buf,
unsigned int offset, unsigned int len)
{
unsigned int ret = 0;
return ret;
}
/******************************************************************************
* CHECK IF MODEM AUTH IS NEEDED
******************************************************************************/
int sec_modem_auth_enabled(void)
{
return 0;
}
/**************************************************************************
* SECURE BOOT
**************************************************************************/
int sec_boot_key_init(void)
{
int ret = SEC_OK;
return ret;
}
int masp_ccci_signfmt_verify_file(char *file_path, unsigned int *data_offset,
unsigned int *data_sec_len)
{
unsigned int ret = SEC_OK;
return ret;
}
int masp_ccci_version_info(void)
{
return CCCI_VERSION;
}
int masp_ccci_is_cipherfmt(int fp_id, unsigned int start_off,
unsigned int *img_len)
{
return 0;
}
int masp_ccci_decrypt_cipherfmt(int fp_id, unsigned int start_off, char *buf,
unsigned int buf_len,
unsigned int *data_offset)
{
return 0;
}
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
/******************************************************************************
* INCLUDE LIBRARY
******************************************************************************/
/******************************************************************************
* INCLUDE LINUX HEADER
******************************************************************************/
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/ioctl.h>
/******************************************************************************
* INCLUDE LIBRARY
******************************************************************************/
#include "sec_hal.h"
#include "sec_boot_lib.h"
#include "masp_version.h"
#include "sec_ioctl.h"
#include "sec_osal_light.h"
#define MOD "ASF"
#define CI_BLK_SIZE 16
#define CI_BLK_ALIGN(len) (((len)+CI_BLK_SIZE-1) & ~(CI_BLK_SIZE-1))
/**************************************************************************
* GLOBAL VARIABLES
**************************************************************************/
/* if sec is not enabled, this param will not be updated */
uint lks = 2;
module_param(lks, uint, 0444); /* r--r--r-- */
MODULE_PARM_DESC(lks, "A device lks parameter under sysfs (0=NL, 1=L, 2=NA)");
/**************************************************************************
* SEC DRIVER EXIT
**************************************************************************/
void sec_core_exit(void)
{
pr_debug("[%s] version '%s%s', exit.\n", MOD, BUILD_TIME, BUILD_BRANCH);
}
/* extern void osal_msleep(unsigned int msec); */
/**************************************************************************
* SEC DRIVER IOCTL
**************************************************************************/
long sec_core_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int err = 0;
int ret = 0;
unsigned int rid[4] = {0};
/* ---------------------------------- */
/* IOCTL */
/* ---------------------------------- */
if (_IOC_TYPE(cmd) != SEC_IOC_MAGIC)
return -ENOTTY;
if (_IOC_NR(cmd) > SEC_IOC_MAXNR)
return -ENOTTY;
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE,
(void __user *)arg,
_IOC_SIZE(cmd));
if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_READ,
(void __user *)arg,
_IOC_SIZE(cmd));
if (err)
return -EFAULT;
switch (cmd) {
/* ---------------------------------- */
/* get random id */
/* ---------------------------------- */
case SEC_GET_RANDOM_ID:
pr_debug("[%s] CMD - SEC_GET_RANDOM_ID\n", MOD);
sec_get_random_id(&rid[0]);
ret =
osal_copy_to_user((void __user *)arg, (void *)&rid[0],
sizeof(unsigned int) * 4);
break;
/* ---------------------------------- */
/* init boot info */
/* ---------------------------------- */
case SEC_BOOT_INIT:
pr_debug("[%s] CMD - SEC_BOOT_INIT\n", MOD);
ret = masp_boot_init();
ret = osal_copy_to_user((void __user *)arg,
(void *)&ret,
sizeof(int));
break;
/* ---------------------------------- */
/* check if secure usbdl is enbaled */
/* ---------------------------------- */
case SEC_USBDL_IS_ENABLED:
pr_debug("[%s] CMD - SEC_USBDL_IS_ENABLED\n", MOD);
ret = sec_usbdl_enabled();
ret = osal_copy_to_user((void __user *)arg,
(void *)&ret,
sizeof(int));
break;
/* ---------------------------------- */
/* check if secure boot is enbaled */
/* ---------------------------------- */
case SEC_BOOT_IS_ENABLED:
pr_debug("[%s] CMD - SEC_BOOT_IS_ENABLED\n", MOD);
ret = sec_boot_enabled();
ret = osal_copy_to_user((void __user *)arg,
(void *)&ret,
sizeof(int));
break;
}
return 0;
}
@@ -0,0 +1,306 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
/******************************************************************************
* KERNEL HEADER
******************************************************************************/
#include "sec_osal.h"
#include <linux/string.h>
#include <linux/bug.h>
#include <linux/spinlock.h>
#include <linux/semaphore.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/mtd/mtd.h>
#include <linux/fs.h>
#include <linux/mtd/partitions.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/vmalloc.h>
/*****************************************************************************
* MACRO
*****************************************************************************/
#ifndef ASSERT
#define ASSERT(expr) WARN_ON(!(expr))
#endif
/*****************************************************************************
* GLOBAL VARIABLE
*****************************************************************************/
DEFINE_SEMAPHORE(hacc_sem);
DEFINE_SEMAPHORE(mtd_sem);
DEFINE_SEMAPHORE(rid_sem);
DEFINE_SEMAPHORE(sec_mm_sem);
DEFINE_SEMAPHORE(osal_fp_sem);
DEFINE_SEMAPHORE(osal_verify_sem);
DEFINE_SEMAPHORE(osal_secro_sem);
DEFINE_SEMAPHORE(osal_secro_v5_sem);
/*****************************************************************************
* LOCAL VARIABLE
*****************************************************************************/
static mm_segment_t curr_fs;
#define OSAL_MAX_FP_COUNT 4096
#define OSAL_FP_OVERFLOW OSAL_MAX_FP_COUNT
/* The array 0 will be not be used, and fp_id=0 will be though as NULL file */
static struct file *g_osal_fp[OSAL_MAX_FP_COUNT] = { 0 };
/*****************************************************************************
* PORTING LAYER
*****************************************************************************/
void osal_kfree(void *buf)
{
/* kfree(buf); */
vfree(buf);
}
EXPORT_SYMBOL(osal_kfree);
void *osal_kmalloc(unsigned int size)
{
/* return kmalloc(size,GFP_KERNEL); */
return vmalloc(size);
}
EXPORT_SYMBOL(osal_kmalloc);
unsigned long osal_copy_from_user(void *to, void *from, unsigned long size)
{
return copy_from_user(to, from, size);
}
EXPORT_SYMBOL(osal_copy_from_user);
unsigned long osal_copy_to_user(void *to, void *from, unsigned long size)
{
return copy_to_user(to, from, size);
}
EXPORT_SYMBOL(osal_copy_to_user);
int osal_hacc_lock(void)
{
return down_interruptible(&hacc_sem);
}
EXPORT_SYMBOL(osal_hacc_lock);
void osal_hacc_unlock(void)
{
up(&hacc_sem);
}
EXPORT_SYMBOL(osal_hacc_unlock);
int osal_verify_lock(void)
{
return down_interruptible(&osal_verify_sem);
}
EXPORT_SYMBOL(osal_verify_lock);
void osal_verify_unlock(void)
{
up(&osal_verify_sem);
}
EXPORT_SYMBOL(osal_verify_unlock);
int osal_secro_lock(void)
{
return down_interruptible(&osal_secro_sem);
}
EXPORT_SYMBOL(osal_secro_lock);
void osal_secro_unlock(void)
{
up(&osal_secro_sem);
}
EXPORT_SYMBOL(osal_secro_unlock);
int osal_secro_v5_lock(void)
{
return down_interruptible(&osal_secro_v5_sem);
}
EXPORT_SYMBOL(osal_secro_v5_lock);
void osal_secro_v5_unlock(void)
{
up(&osal_secro_v5_sem);
}
EXPORT_SYMBOL(osal_secro_v5_unlock);
int osal_mtd_lock(void)
{
return down_interruptible(&mtd_sem);
}
EXPORT_SYMBOL(osal_mtd_lock);
void osal_mtd_unlock(void)
{
up(&mtd_sem);
}
EXPORT_SYMBOL(osal_mtd_unlock);
int osal_rid_lock(void)
{
return down_interruptible(&rid_sem);
}
EXPORT_SYMBOL(osal_rid_lock);
void osal_rid_unlock(void)
{
up(&rid_sem);
}
EXPORT_SYMBOL(osal_rid_unlock);
void osal_msleep(unsigned int msec)
{
msleep(msec);
}
EXPORT_SYMBOL(osal_msleep);
void osal_assert(unsigned int val)
{
ASSERT(val);
}
EXPORT_SYMBOL(osal_assert);
int osal_set_kernel_fs(void)
{
int val = 0;
val = down_interruptible(&sec_mm_sem);
curr_fs = get_fs();
set_fs(KERNEL_DS);
return val;
}
EXPORT_SYMBOL(osal_set_kernel_fs);
void osal_restore_fs(void)
{
set_fs(curr_fs);
up(&sec_mm_sem);
}
EXPORT_SYMBOL(osal_restore_fs);
void *osal_get_filp_struct(int fp_id)
{
int val = 0;
struct file *ret;
if (fp_id >= 1 && fp_id < OSAL_MAX_FP_COUNT) {
val = down_interruptible(&osal_fp_sem);
ret = g_osal_fp[fp_id];
up(&osal_fp_sem);
return (void *)ret;
}
return (struct file *)(-ENOENT); /* No such file or directory */
}
EXPORT_SYMBOL(osal_get_filp_struct);
loff_t osal_filp_seek_set(int fp_id, loff_t off)
{
loff_t offset;
int val = 0;
if (fp_id >= 1 && fp_id < OSAL_MAX_FP_COUNT) {
val = down_interruptible(&osal_fp_sem);
offset = g_osal_fp[fp_id]->f_op->llseek(g_osal_fp[fp_id],
off,
SEEK_SET);
up(&osal_fp_sem);
return offset;
}
return OSAL_FILE_SEEK_FAIL;
}
EXPORT_SYMBOL(osal_filp_seek_set);
loff_t osal_filp_seek_end(int fp_id, loff_t off)
{
loff_t offset;
int val = 0;
if (fp_id >= 1 && fp_id < OSAL_MAX_FP_COUNT) {
val = down_interruptible(&osal_fp_sem);
offset = g_osal_fp[fp_id]->f_op->llseek(g_osal_fp[fp_id],
off,
SEEK_END);
up(&osal_fp_sem);
return offset;
}
return OSAL_FILE_SEEK_FAIL;
}
EXPORT_SYMBOL(osal_filp_seek_end);
loff_t osal_filp_pos(int fp_id)
{
loff_t offset;
int val = 0;
if (fp_id >= 1 && fp_id < OSAL_MAX_FP_COUNT) {
val = down_interruptible(&osal_fp_sem);
offset = g_osal_fp[fp_id]->f_pos;
up(&osal_fp_sem);
return offset;
}
return OSAL_FILE_GET_POS_FAIL;
}
EXPORT_SYMBOL(osal_filp_pos);
long osal_filp_read(int fp_id, char *buf, unsigned long len)
{
ssize_t read_len;
int val = 0;
if (fp_id >= 1 && fp_id < OSAL_MAX_FP_COUNT) {
val = down_interruptible(&osal_fp_sem);
read_len =
g_osal_fp[fp_id]->f_op->read(g_osal_fp[fp_id], buf, len,
&g_osal_fp[fp_id]->f_pos);
up(&osal_fp_sem);
return read_len;
}
return OSAL_FILE_READ_FAIL;
}
EXPORT_SYMBOL(osal_filp_read);
long osal_is_err(int fp_id)
{
bool err;
int val = 0;
if (fp_id >= 1 && fp_id < OSAL_MAX_FP_COUNT) {
val = down_interruptible(&osal_fp_sem);
err = IS_ERR(g_osal_fp[fp_id]);
up(&osal_fp_sem);
return err;
}
/*osal_assert(0); */
return 1;
}
EXPORT_SYMBOL(osal_is_err);
@@ -0,0 +1,214 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include "sec_osal.h"
#include "sec_hal.h"
#include "sec_osal_light.h"
#include "sec_boot_lib.h"
#include "sec_error.h"
#include "hacc_mach.h"
/******************************************************************************
* This file provide the HACC operation function to secure library
* All the functions should be general ...
******************************************************************************/
#define MOD "ASF"
/******************************************************************************
* GLOBAL VARIABLES
******************************************************************************/
bool bHACC_HWWrapKeyInit;
bool bHACC_SWKeyInit;
/******************************************************************************
* INTERNAL VARIABLES
******************************************************************************/
static const unsigned int g_HACC_CFG_1[8] = {
0x9ED40400, 0x00E884A1, 0xE3F083BD, 0x2F4E6D8A,
0xFF838E5C, 0xE940A0E3, 0x8D4DECC6, 0x45FC0989
};
static const unsigned int g_HACC_CFG_2[8] = {
0xAA542CDA, 0x55522114, 0xE3F083BD, 0x55522114,
0xAA542CDA, 0xAA542CDA, 0x55522114, 0xAA542CDA
};
static const unsigned int g_HACC_CFG_3[8] = {
0x2684B690, 0xEB67A8BE, 0xA113144C, 0x177B1215,
0x168BEE66, 0x1284B684, 0xDF3BCE3A, 0x217F6FA2
};
/******************************************************************************
* INTERNAL ENGINE
******************************************************************************/
static unsigned char *sp_hacc_internal(unsigned char *buf, unsigned int size,
bool bAC,
enum hacc_user user,
bool bDoLock,
enum aes_ops aes_type,
bool bEn)
{
unsigned int err = 0;
/* ---------------------------- */
/* get hacc lock */
/* ---------------------------- */
if (true == bDoLock) {
/* If the semaphore is successfully acquired,
* this function returns 0.
*/
err = osal_hacc_lock();
if (err) {
err = ERR_SBOOT_HACC_LOCK_FAIL;
goto _err;
}
}
/* ---------------------------- */
/* ciphering and force AC */
/* ---------------------------- */
switch (user) {
case HACC_USER1:
/* ------------------------------- */
/* use smart phone hacc function 1 */
/* ------------------------------- */
HACC_V3_Init(bEn, g_HACC_CFG_1);
HACC_V3_Run((unsigned int *)buf, size, (unsigned int *)buf);
HACC_V3_Terminate();
break;
case HACC_USER2:
/* ---------------------------- */
/* use smart phone hacc function 2 */
/* ---------------------------- */
HACC_V3_Init(bEn, g_HACC_CFG_2);
HACC_V3_Run((unsigned int *)buf, size, (unsigned int *)buf);
HACC_V3_Terminate();
break;
case HACC_USER3:
/* use smart phone hacc function 3 */
/* ---------------------------- */
if (false == bHACC_HWWrapKeyInit) {
err = ERR_HACC_HW_WRAP_KEY_NOT_INIT;
goto _err;
}
err = hacc_set_key(AES_HW_WRAP_KEY, AES_KEY_256);
if (err != SEC_OK)
goto _err;
err = hacc_do_aes(aes_type, buf, buf, AES_BLK_SZ_ALIGN(size));
if (err != SEC_OK)
goto _err;
break;
case HACC_USER4:
/* ---------------------------- */
/* use smart phone hacc function 4 */
/* ---------------------------- */
HACC_V3_Init(bEn, g_HACC_CFG_3);
HACC_V3_Run((unsigned int *)buf, size, (unsigned int *)buf);
HACC_V3_Terminate();
break;
default:
err = ERR_HACC_UNKNOWN_USER;
goto _err;
}
/* ---------------------------- */
/* release hacc lock */
/* ---------------------------- */
if (true == bDoLock)
osal_hacc_unlock();
return buf;
_err:
if (true == bDoLock)
osal_hacc_unlock();
pr_debug("[%s] HACC Fail (0x%x)\n", MOD, err);
WARN_ON(!(0));
return buf;
}
/******************************************************************************
* ENCRYPTION
******************************************************************************/
unsigned char *masp_hal_sp_hacc_enc(unsigned char *buf, unsigned int size,
unsigned char bAC,
enum hacc_user user,
unsigned char bDoLock)
{
return sp_hacc_internal(buf, size, true, user, bDoLock, AES_ENC, true);
}
/******************************************************************************
* DECRYPTION
******************************************************************************/
unsigned char *masp_hal_sp_hacc_dec(unsigned char *buf, unsigned int size,
unsigned char bAC,
enum hacc_user user,
unsigned char bDoLock)
{
return sp_hacc_internal(buf, size, true, user, bDoLock, AES_DEC, false);
}
/******************************************************************************
* HACC BLK SIZE
******************************************************************************/
unsigned int masp_hal_sp_hacc_blk_sz(void)
{
return AES_BLK_SZ;
}
/******************************************************************************
* HACC INITIALIZATION
******************************************************************************/
unsigned int masp_hal_sp_hacc_init(unsigned char *sec_seed, unsigned int size)
{
struct aes_key_seed keyseed;
unsigned int i = 0;
bHACC_HWWrapKeyInit = false;
bHACC_SWKeyInit = false;
if (size != _CRYPTO_SEED_LEN)
return ERR_HACC_SEED_LEN_ERROR;
keyseed.size = HACC_AES_MAX_KEY_SZ;
for (i = 0; i < HACC_AES_MAX_KEY_SZ / 2; i++) {
keyseed.seed[i] = sec_seed[i];
keyseed.seed[HACC_AES_MAX_KEY_SZ - i - 1] = sec_seed[i] +
MTK_HACC_SEED;
}
pr_debug("0x%x,0x%x,0x%x,0x%x\n",
keyseed.seed[0],
keyseed.seed[1],
keyseed.seed[2],
keyseed.seed[3]);
return hacc_init(&keyseed);
}
@@ -0,0 +1,148 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include "sec_hal.h"
#include <linux/types.h>
#include "hacc_mach.h"
/******************************************************************************
* DEBUG
******************************************************************************/
#define SEC_DEBUG (false)
#define SMSG DBG_MSG
#if SEC_DEBUG
#define DMSG DBG_MSG
#else
#define DMSG
#endif
static const unsigned int g_CFG_RANDOM_PATTERN[3][4] = {
{0x2D44BB70, 0xA744D227, 0xD0A9864B, 0x83FFC244},
{0x7EC8266B, 0x43E80FB2, 0x01A6348A, 0x2067F9A0},
{0x54536405, 0xD546A6B1, 0x1CC3EC3A, 0xDE377A83}
};
/******************************************************************************
* HACC HW internal function
******************************************************************************/
void HACC_V3_Init(bool encode, const unsigned int g_AC_CFG[])
{
unsigned int i, j;
const unsigned int *p1;
unsigned int acon_setting;
/* Power On HACC */
masp_hal_secure_algo_init();
/* Configuration */
/* set little endian */
acon_setting = HACC_AES_CHG_BO_OFF;
/* set mode */
acon_setting |= HACC_AES_CBC;
/* type */
acon_setting |= HACC_AES_128;
/* operation */
if (encode)
acon_setting |= HACC_AES_ENC;
else
acon_setting |= HACC_AES_DEC;
/* clear key */
for (i = 0; i < 8; i++)
writel(0, (void *)(HACC_AKEY0 + 4 * i));
/* Generate META Key */
writel(HACC_AES_CHG_BO_OFF | HACC_AES_128 | HACC_AES_CBC | HACC_AES_DEC,
(void *)HACC_ACON);
/* init ACONK
* B2C: bind HUID/HUK to HACC
*/
writel(HACC_AES_BK2C, (void *)HACC_ACONK);
/* enable R2K, so that output data is feedback to key
* by HACC internal algorithm
*/
writel(readl((const void *)HACC_ACONK) | HACC_AES_R2K,
(void *)HACC_ACONK);
/* clear HACC_ASRC/HACC_ACFG/HACC_AOUT */
writel(HACC_AES_CLR, (void *)HACC_ACON2);
/* set cfg */
p1 = &g_AC_CFG[0];
for (i = 0; i < 4; i++)
writel(*(p1 + i), (void *)(HACC_ACFG0 + 4 * i));
/* encrypt fix pattern 3 rounds to generate a pattern from HUID/HUK */
for (i = 0; i < 3; i++) {
/* set fixed pattern into source */
p1 = g_CFG_RANDOM_PATTERN[i];
for (j = 0; j < 4; j++)
writel(*(p1 + j), (void *)(HACC_ASRC0 + 4 * j));
/* start decryption */
writel(HACC_AES_START, (void *)HACC_ACON2);
/* polling ready */
while (0 == (readl((const void *)HACC_ACON2) & HACC_AES_RDY))
;
}
/* Set CFG */
/* clear HACC_ASRC/HACC_ACFG/HACC_AOUT */
writel(HACC_AES_CLR, (void *)HACC_ACON2);
/* set cfg */
p1 = &g_AC_CFG[0];
for (i = 0; i < 4; i++)
writel(*(p1 + i), (void *)(HACC_ACFG0 + 4 * i));
/* set config without R2K */
writel(acon_setting, (void *)HACC_ACON);
writel(0, (void *)HACC_ACONK);
}
void HACC_V3_Run(unsigned int *p_src, unsigned int src_len, unsigned int *p_dst)
{
unsigned int i, j;
/* config src/dst addr and len */
unsigned int len = src_len;
/* fo operation */
for (i = 0; i < len; i += 16, p_src += 4, p_dst += 4) {
/* set fixed pattern into source */
for (j = 0; j < 4; j++)
writel(*(p_src + j), (void *)(HACC_ASRC0 + 4 * j));
/* start encryption */
writel(HACC_AES_START, (void *)HACC_ACON2);
/* polling ready */
while (0 == (readl((const void *)HACC_ACON2) & HACC_AES_RDY))
;
/* read out data */
for (j = 0; j < 4; j++) {
writel(readl((const void *)(HACC_AOUT0 + 4 * j)),
(void *)(p_dst + j));
}
}
}
void HACC_V3_Terminate(void)
{
unsigned int i;
/* clear HACC_ASRC/HACC_ACFG/HACC_AOUT */
writel(HACC_AES_CLR, (void *)HACC_ACON2);
/* clear key */
for (i = 0; i < 8; i++)
writel(0, (void *)(HACC_AKEY0 + 4 * i));
masp_hal_secure_algo_deinit();
}
@@ -0,0 +1,126 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include "sec_osal.h"
#include "sec_hal.h"
#include "hacc_mach.h"
#include "sec_error.h"
/******************************************************************************
* Crypto Engine Test Driver Debug Control
******************************************************************************/
#define MOD "CE"
/******************************************************************************
* Seed Definition
******************************************************************************/
#define _CRYPTO_SEED_LEN (16)
/******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************/
/* return the result of hwEnableClock ( )
* - TRUE (1) means crypto engine init success
* - false (0) means crypto engine init fail
*/
unsigned char masp_hal_secure_algo_init(void)
{
bool ret = true;
return ret;
}
/* return the result of hwDisableClock ( )
* - true (1) means crypto engine de-init success
* - false (0) means crypto engine de-init fail
*/
unsigned char masp_hal_secure_algo_deinit(void)
{
bool ret = true;
return ret;
}
/******************************************************************************
* CRYPTO ENGINE EXPORTED APIs
******************************************************************************/
/* perform crypto operation
* @ Direction : true (1) means encrypt
* false (0) means decrypt
* @ ContentAddr : input source address
* @ ContentLen : input source length
* @ CustomSeed : customization seed for crypto engine
* @ ResText : output destination address
*/
void masp_hal_secure_algo(unsigned char Direction, unsigned char *ContentAddr,
unsigned int ContentLen, unsigned char *CustomSeed,
unsigned char *ResText)
{
unsigned int err;
unsigned char *src, *dst, *seed;
unsigned int i = 0;
/* try to get hacc lock */
do {
/* If the semaphore is successfully acquired, this function
* returns 0.
*/
err = osal_hacc_lock();
} while (err != 0);
/* initialize hacc crypto configuration */
seed = (unsigned char *)CustomSeed;
err = masp_hal_sp_hacc_init(seed, _CRYPTO_SEED_LEN);
if (err != SEC_OK)
goto error;
/* initialize source and destination address */
src = (unsigned char *)ContentAddr;
dst = (unsigned char *)ResText;
/* according to input parameter to encrypt or decrypt */
switch (Direction) {
case true:
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* ! CCCI driver already got HACC lock ! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
dst = masp_hal_sp_hacc_enc((unsigned char *)src,
ContentLen,
true, HACC_USER3, false);
break;
case false:
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* ! CCCI driver already got HACC lock ! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
dst = masp_hal_sp_hacc_dec((unsigned char *)src,
ContentLen,
true, HACC_USER3, false);
break;
default:
err = ERR_KER_CRYPTO_INVALID_MODE;
goto error;
}
/* copy result */
for (i = 0; i < ContentLen; i++)
*(ResText + i) = *(dst + i);
/* try to release hacc lock */
osal_hacc_unlock();
return;
error:
/* try to release hacc lock */
osal_hacc_unlock();
pr_notice("[%s] %s error (0x%x)\n", MOD, __func__, err);
WARN_ON(!(0));
}
@@ -0,0 +1,178 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
/* to avoid disclosing any secret and let customer know we have hacc hardware,
* the file name 'hacc' is changed to 'hacc_hw' in kernel driver
*/
#ifndef HACC_MACH_H
#define HACC_MACH_H
#include "sec_osal_light.h"
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *hacc_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
#define AES_BLK_SZ_ALIGN(size) ((size) & ~((AES_BLK_SZ << 3) - 1))
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define HACC_CG (0x1 << 10)
#define HACC_AES_TEST_SRC (0x02000000)
#define HACC_AES_TEST_TMP (0x02100000)
#define HACC_AES_TEST_DST (0x02200000)
#define HACC_CFG_0 (0x5a5a3257) /* CHECKME */
#define HACC_CFG_1 (0x66975412) /* CHECKME */
#define HACC_CFG_2 (0x66975412) /* CHECKME */
#define HACC_CFG_3 (0x5a5a3257) /* CHECKME */
#define HACC_CON (hacc_base+0x0000)
#define HACC_ACON (hacc_base+0x0004)
#define HACC_ACON2 (hacc_base+0x0008)
#define HACC_ACONK (hacc_base+0x000C)
#define HACC_ASRC0 (hacc_base+0x0010)
#define HACC_ASRC1 (hacc_base+0x0014)
#define HACC_ASRC2 (hacc_base+0x0018)
#define HACC_ASRC3 (hacc_base+0x001C)
#define HACC_AKEY0 (hacc_base+0x0020)
#define HACC_AKEY1 (hacc_base+0x0024)
#define HACC_AKEY2 (hacc_base+0x0028)
#define HACC_AKEY3 (hacc_base+0x002C)
#define HACC_AKEY4 (hacc_base+0x0030)
#define HACC_AKEY5 (hacc_base+0x0034)
#define HACC_AKEY6 (hacc_base+0x0038)
#define HACC_AKEY7 (hacc_base+0x003C)
#define HACC_ACFG0 (hacc_base+0x0040)
#define HACC_AOUT0 (hacc_base+0x0050)
#define HACC_AOUT1 (hacc_base+0x0054)
#define HACC_AOUT2 (hacc_base+0x0058)
#define HACC_AOUT3 (hacc_base+0x005C)
#define HACC_SW_OTP0 (hacc_base+0x0060)
#define HACC_SW_OTP1 (hacc_base+0x0064)
#define HACC_SW_OTP2 (hacc_base+0x0068)
#define HACC_SW_OTP3 (hacc_base+0x006c)
#define HACC_SW_OTP4 (hacc_base+0x0070)
#define HACC_SW_OTP5 (hacc_base+0x0074)
#define HACC_SW_OTP6 (hacc_base+0x0078)
#define HACC_SW_OTP7 (hacc_base+0x007c)
#define HACC_SECINIT0 (hacc_base+0x0080)
#define HACC_SECINIT1 (hacc_base+0x0084)
#define HACC_SECINIT2 (hacc_base+0x0088)
#define HACC_MKJ (hacc_base+0x00a0)
/* AES */
#define HACC_AES_DEC 0x00000000
#define HACC_AES_ENC 0x00000001
#define HACC_AES_MODE_MASK 0x00000002
#define HACC_AES_ECB 0x00000000
#define HACC_AES_CBC 0x00000002
#define HACC_AES_TYPE_MASK 0x00000030
#define HACC_AES_128 0x00000000
#define HACC_AES_192 0x00000010
#define HACC_AES_256 0x00000020
#define HACC_AES_CHG_BO_MASK 0x00001000
#define HACC_AES_CHG_BO_OFF 0x00000000
#define HACC_AES_CHG_BO_ON 0x00001000
#define HACC_AES_START 0x00000001
#define HACC_AES_CLR 0x00000002
#define HACC_AES_RDY 0x00008000
/* AES key relevant */
#define HACC_AES_BK2C 0x00000010
#define HACC_AES_R2K 0x00000100
/* SECINIT magic */
#define HACC_SECINIT0_MAGIC 0xAE0ACBEA
#define HACC_SECINIT1_MAGIC 0xCD957018
#define HACC_SECINIT2_MAGIC 0x46293911
/******************************************************************************
* CONSTANT DEFINITIONS
******************************************************************************/
#define HACC_AES_MAX_KEY_SZ (32)
#define AES_CFG_SZ (16)
#define AES_BLK_SZ (16)
#define HACC_HW_KEY_SZ (16)
#define _CRYPTO_SEED_LEN (16)
/* In order to support NAND writer and keep MTK secret,
* use MTK HACC seed and custom crypto seed to generate SW key
* to encrypt SEC_CFG
*/
#define MTK_HACC_SEED (0x1)
/******************************************************************************
* TYPE DEFINITIONS
******************************************************************************/
enum aes_mode {
AES_ECB_MODE,
AES_CBC_MODE
};
enum aes_ops {
AES_DEC,
AES_ENC
};
enum aes_key {
AES_KEY_128 = 16,
AES_KEY_192 = 24,
AES_KEY_256 = 32
};
enum aes_key_id {
AES_SW_KEY,
AES_HW_KEY,
AES_HW_WRAP_KEY
};
struct aes_cfg {
unsigned char config[AES_CFG_SZ];
};
struct aes_key_seed {
unsigned int size;
unsigned char seed[HACC_AES_MAX_KEY_SZ];
};
struct hacc_context {
struct aes_cfg cfg;
unsigned int blk_sz;
unsigned char sw_key[HACC_AES_MAX_KEY_SZ];
unsigned char hw_key[HACC_AES_MAX_KEY_SZ];
};
/******************************************************************************
* EXPORT FUNCTION
******************************************************************************/
extern unsigned int hacc_set_key(enum aes_key_id id, enum aes_key key);
extern unsigned int hacc_do_aes(enum aes_ops ops,
unsigned char *src,
unsigned char *dst,
unsigned int size);
extern unsigned int hacc_init(struct aes_key_seed *keyseed);
extern unsigned int hacc_deinit(void);
extern void HACC_V3_Init(bool encode, const unsigned int g_AC_CFG[]);
extern void HACC_V3_Run(unsigned int *p_src, unsigned int src_len,
unsigned int *p_dst);
extern void HACC_V3_Terminate(void);
/******************************************************************************
* EXTERNAL VARIABLE
******************************************************************************/
extern bool bHACC_HWWrapKeyInit;
extern bool bHACC_SWKeyInit;
#endif
@@ -0,0 +1,320 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
/*#include <mach/mt_typedefs.h>
* #include <mach/mt_reg_base.h>
*/
#include "sec_error.h"
#include "hacc_mach.h"
#include <linux/io.h>
/******************************************************************************
* this file contains the hardware secure engine low-level operations
* note that : all the functions in this file are ONLY for HACC internal usages.
******************************************************************************/
/******************************************************************************
* CONSTANT DEFINITIONS
******************************************************************************/
#define MOD "HACC"
#define HACC_TEST (0)
/******************************************************************************
* DEBUG
******************************************************************************/
#define SEC_DEBUG (0)
#define SMSG
#define DMSG
#if SEC_DEBUG
#else
#define DMSG
#endif
/******************************************************************************
* LOCAL VERIABLE
******************************************************************************/
static struct hacc_context hacc_ctx;
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
#if HACC_TEST
static void hacc_test(void)
{
unsigned int i, test_sz = HACC_AES_MAX_KEY_SZ * 24;
unsigned int test_keysz = AES_KEY_256;
unsigned char *test_src = (unsigned char *)HACC_AES_TEST_SRC;
unsigned char *test_dst = (unsigned char *)HACC_AES_TEST_DST;
unsigned char *test_tmp = (unsigned char *)HACC_AES_TEST_TMP;
/* prepare data */
for (i = 0; i < test_sz; i++)
test_src[i] = i + 1;
hacc_set_key(AES_HW_WRAP_KEY, test_keysz);
hacc_do_aes(AES_ENC, test_src, test_tmp, test_sz);
hacc_set_key(AES_HW_WRAP_KEY, test_keysz);
hacc_do_aes(AES_DEC, test_tmp, test_dst, test_sz);
for (i = 0; i < test_sz; i++) {
if (test_src[i] != test_dst[i]) {
DMSG("[%s] mismatch at %d, ", MOD, i);
DMSG("src = 0x%x, ", test_src[i]);
DMSG("dst = 0x%x\n", test_dst[i]);
}
}
DMSG("[%s] encrypt & descrypt unit test pass. (Key = %dbits)\n",
MOD,
test_keysz << 3);
}
#else
#define hacc_test() do {} while (0)
#endif
/******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************/
static unsigned int hacc_set_cfg(struct aes_cfg *cfg)
{
memcpy(&hacc_ctx.cfg, cfg, sizeof(struct aes_cfg));
return SEC_OK;
}
static unsigned int hacc_set_mode(enum aes_mode mode)
{
struct aes_cfg cfg;
writel(readl((const void *)HACC_ACON) & ~(HACC_AES_MODE_MASK),
(void *)HACC_ACON);
switch (mode) {
case AES_ECB_MODE:
/* no need cfg */
memset(&cfg.config[0], 0, sizeof(cfg.config));
writel(readl((const void *)HACC_ACON) | HACC_AES_ECB,
(void *)HACC_ACON);
break;
case AES_CBC_MODE:
writel(readl((const void *)HACC_ACON) | HACC_AES_CBC,
(void *)HACC_ACON);
break;
default:
return ERR_HACC_MODE_INVALID;
}
return SEC_OK;
}
unsigned int hacc_set_key(enum aes_key_id id, enum aes_key key)
{
unsigned int i, acon = 0;
unsigned int akey;
unsigned char *tkey;
switch (key) {
case AES_KEY_128:
acon |= HACC_AES_128;
break;
case AES_KEY_192:
acon |= HACC_AES_192;
break;
case AES_KEY_256:
acon |= HACC_AES_256;
break;
default:
return ERR_HACC_KEY_INVALID;
}
/* set aes block size */
hacc_ctx.blk_sz = key;
/* set aes key length */
writel(readl((const void *)HACC_ACON) & ~(HACC_AES_TYPE_MASK),
(void *)HACC_ACON);
writel(readl((const void *)HACC_ACON) | acon, (void *)HACC_ACON);
/* clear key */
for (i = 0; i < HACC_AES_MAX_KEY_SZ; i += 4)
writel(0, (void *)(HACC_AKEY0 + i));
/* set aes key */
switch (id) {
case AES_HW_KEY:
writel(readl((const void *)HACC_ACONK) | HACC_AES_BK2C,
(void *)HACC_ACONK);
return 0;
case AES_HW_WRAP_KEY:
tkey = &hacc_ctx.hw_key[0];
break;
case AES_SW_KEY:
default:
tkey = &hacc_ctx.sw_key[0];
break;
}
/* non hardware binding key */
writel(readl((const void *)HACC_ACONK) & ~(HACC_AES_BK2C),
(void *)HACC_ACONK);
/* update key. note that don't use key directly */
for (i = 0; i < HACC_AES_MAX_KEY_SZ; i += 4) {
akey = (tkey[i] << 24) |
(tkey[i + 1] << 16) |
(tkey[i + 2] << 8) |
(tkey[i + 3]);
writel(akey, (void *)(HACC_AKEY0 + i));
}
return SEC_OK;
}
unsigned int hacc_do_aes(enum aes_ops ops,
unsigned char *src,
unsigned char *dst,
unsigned int size)
{
unsigned int i;
unsigned int *ds, *dt, *vt;
/* make sure size is aligned to aes block size */
if ((size % AES_BLK_SZ) != 0) {
SMSG("[%s] size = %d is not %d bytes alignment\n",
MOD,
size,
AES_BLK_SZ);
return ERR_HACC_DATA_UNALIGNED;
}
vt = (unsigned int *)&hacc_ctx.cfg.config[0];
/* erase src, cfg, out register */
writel(readl((const void *)HACC_ACON2) | HACC_AES_CLR,
(void *)HACC_ACON2);
/* set init config */
for (i = 0; i < AES_CFG_SZ; i += 4)
writel(*vt++, (void *)(HACC_ACFG0 + i));
if (ops == AES_ENC)
writel(readl((const void *)HACC_ACON) | HACC_AES_ENC,
(void *)HACC_ACON);
else
writel(readl((const void *)HACC_ACON) & ~HACC_AES_ENC,
(void *)HACC_ACON);
ds = (unsigned int *)src;
dt = (unsigned int *)dst;
do {
/* fill in the data */
for (i = 0; i < AES_BLK_SZ; i += 4)
writel(*ds++, (void *)(HACC_ASRC0 + i));
/* start aes engine */
writel(readl((const void *)HACC_ACON2) | HACC_AES_START,
(char *)HACC_ACON2);
/* wait for aes engine ready */
while ((readl((const void *)HACC_ACON2) & HACC_AES_RDY) == 0)
;
/* read out the data */
for (i = 0; i < AES_BLK_SZ; i += 4)
* dt++ = readl((const void *)(HACC_AOUT0 + i));
if (size == 0)
goto end;
size -= AES_BLK_SZ;
} while (size != 0);
end:
return SEC_OK;
}
unsigned int hacc_deinit(void)
{
unsigned int ret = 0;
/* clear aes module */
writel(readl((const void *)HACC_ACON2) | HACC_AES_CLR,
(void *)HACC_ACON2);
return ret;
}
unsigned int hacc_init(struct aes_key_seed *keyseed)
{
unsigned int i = 0;
unsigned int *config;
unsigned int ret = 0;
hacc_deinit();
/* clear aes module */
writel(readl((const void *)HACC_ACON2) | HACC_AES_CLR,
(void *)HACC_ACON2);
/* set aes module in cbc mode with no byte order change */
writel(readl((const void *)HACC_ACON2) &
~(HACC_AES_CHG_BO_MASK |
HACC_AES_MODE_MASK),
(void *)HACC_ACON2);
writel(readl((const void *)HACC_ACON2) |
(HACC_AES_CHG_BO_OFF |
HACC_AES_CBC),
(void *)HACC_ACON2);
/* aes secure initialiation */
memset(&hacc_ctx, 0, sizeof(struct hacc_context));
for (i = 0; i < keyseed->size; i++)
hacc_ctx.sw_key[i] = keyseed->seed[i];
config = (unsigned int *)&hacc_ctx.cfg.config[0];
*config++ = HACC_CFG_0;
*config++ = HACC_CFG_1;
*config++ = HACC_CFG_2;
*config = HACC_CFG_3;
ret = hacc_set_cfg(&hacc_ctx.cfg);
if (ret != SEC_OK)
goto end;
ret = hacc_set_mode(AES_CBC_MODE);
if (ret != SEC_OK)
goto end;
/* derive the hardware wrapper key */
ret = hacc_set_key(AES_HW_KEY, HACC_HW_KEY_SZ);
if (ret != SEC_OK)
goto end;
ret = hacc_do_aes(AES_ENC,
&hacc_ctx.sw_key[0],
&hacc_ctx.hw_key[0],
AES_KEY_256);
if (ret != SEC_OK)
goto end;
ret = hacc_set_key(AES_HW_WRAP_KEY, AES_KEY_256);
if (ret != SEC_OK)
goto end;
hacc_test();
/* from now on, HACC HW wrap key can be used */
bHACC_HWWrapKeyInit = 1;
/* from now on, HACC SW key can be used */
bHACC_SWKeyInit = 1;
end:
return ret;
}
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,34 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "security_ao.h"
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
void __iomem *security_ao_base;
static const struct of_device_id security_ao_ids[] = {
{.compatible = "mediatek,security_ao"},
{}
};
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
struct device_node *np_secao = NULL;
unsigned int rst_con = 0;
unsigned int reg_val = 0;
const char *compatible = security_ao_ids[0].compatible;
/* get security ao base address */
if (!security_ao_base) {
np_secao = of_find_compatible_node(NULL,
NULL,
compatible);
if (!np_secao) {
pr_notice("[SEC AO] security ao node not found\n");
return -ENXIO;
}
security_ao_base = (void __iomem *)of_iomap(np_secao, 0);
if (!security_ao_base) {
pr_notice("[SEC AO] security ao register remapping failed\n");
return -ENXIO;
}
}
/* configure to make misc register live after system reset */
mt_reg_sync_writel(MISC_LOCK_KEY_MAGIC, (void *)MISC_LOCK_KEY);
rst_con = __raw_readl((const void *)RST_CON);
rst_con |= RST_CON_BIT(BOOT_MISC2_IDX);
mt_reg_sync_writel(rst_con, (void *)RST_CON);
mt_reg_sync_writel(0, (void *)MISC_LOCK_KEY);
/* set dm-verity error flag to misc2 */
reg_val = __raw_readl((const void *)BOOT_MISC2);
reg_val |= BOOT_MISC2_VERITY_ERR;
mt_reg_sync_writel(reg_val, (void *)BOOT_MISC2);
return ret;
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECURITY_AO_H
#define SECURITY_AO_H
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
extern void __iomem *security_ao_base;
/******************************************************************************
* MACROS DEFINITIONS
******************************************************************************/
/* miscx index*/
#define BOOT_MISC2_IDX (2)
#define RST_CON_BIT(idx) (0x1 << idx)
/* boot misc2 flags */
#define BOOT_MISC2_VERITY_ERR (0x1 << 0)
/******************************************************************************
* HARDWARE DEFINITIONS
******************************************************************************/
#define MISC_LOCK_KEY_MAGIC (0x0000ad98)
#define BOOT_MISC2 (security_ao_base + 0x088)
#define MISC_LOCK_KEY (security_ao_base + 0x100)
#define RST_CON (security_ao_base + 0x108)
#endif /* SECURITY_AO_H */
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
/******************************************************************************
* CHIP SELECTION
******************************************************************************/
/*#include <mach/mt_typedefs.h>*/
#include "hacc_mach.h"
/******************************************************************************
* REGISTER
******************************************************************************/
#include "sec_boot_lib.h"
#include "sec_mod.h"
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_sbc_enabled(void)
{
return g_hw_sbcen;
}
int masp_hal_get_sbc_checksum(unsigned int *pChecksum)
{
int i;
for (i = 0; i < NUM_SBC_PUBK_HASH; i++)
*pChecksum += g_sbc_pubk_hash[i];
return 0;
}
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
#include <linux/of_fdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "sec_boot_lib.h"
#include "mt-plat/sync_write.h"
/******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************/
int masp_hal_set_dm_verity_error(void)
{
int ret = 0;
/* do nothing, used when platform security porting is not completed */
return ret;
}
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
/******************************************************************************
* INCLUDE LINUX HEADER
******************************************************************************/
#include <linux/platform_device.h>
#include <linux/device.h>
#include <linux/string.h>
#include <linux/clk.h>
#include <linux/of_platform.h>
#include "sec_clk.h"
int sec_clk_enable(struct platform_device *dev)
{
pr_debug("[sec] Need not to get hacc clock\n");
return 0;
}
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#ifndef SECCLK_H
#define SECCLK_H
/**************************************************************************
* EXTERNAL FUNCTION
**************************************************************************/
extern int sec_clk_enable(struct platform_device *dev);
#endif /* end of SECCLK_H */
@@ -0,0 +1,377 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2011 MediaTek Inc.
*/
/******************************************************************************
* INCLUDE LINUX HEADER
******************************************************************************/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/unistd.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/version.h>
#include <linux/spinlock.h>
#include <linux/semaphore.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/errno.h>
#include <linux/cdev.h>
#include <linux/kdev_t.h>
#include <linux/platform_device.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/vmalloc.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/reboot.h>
#include <linux/reboot-mode.h>
#include <linux/of.h>
#include <sec_hal.h>
#include <mt-plat/sync_write.h>
/* #include <mach/memory.h> */
#include <linux/io.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/of_platform.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#ifdef CONFIG_OF
#include <linux/of_fdt.h>
#endif
/******************************************************************************
* INCLUDE LIBRARY
******************************************************************************/
#include "sec_osal.h"
#include "sec_mod.h"
#include "sec_boot_lib.h"
#include "sec_clk.h"
#ifdef MTK_SECURITY_MODULE_LITE
#include "masp_version.h"
#endif
#define SEC_DEV_NAME "sec"
#define SEC_MAJOR 182
#define MOD "MASP"
#define TRACE_FUNC() MSG_FUNC(SEC_DEV_NAME)
/*************************************************************************
* GLOBAL VARIABLE
**************************************************************************/
static struct sec_mod sec = { 0 };
static struct cdev sec_dev;
static struct class *sec_class;
static struct device *sec_device;
void __iomem *hacc_base;
static const struct of_device_id masp_of_ids[] = {
{.compatible = "mediatek,hacc",},
{}
};
/**************************************************************************
* SEC DRIVER OPEN
**************************************************************************/
static int sec_open(struct inode *inode, struct file *file)
{
return 0;
}
/**************************************************************************
* SEC DRIVER RELEASE
**************************************************************************/
static int sec_release(struct inode *inode, struct file *file)
{
return 0;
}
/**************************************************************************
* SEC DRIVER IOCTL
**************************************************************************/
static long sec_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
#ifdef MTK_SECURITY_MODULE_LITE
return -EIO;
#else
return sec_core_ioctl(file, cmd, arg);
#endif
}
static const struct file_operations sec_fops = {
.owner = THIS_MODULE,
.open = sec_open,
.release = sec_release,
.write = NULL,
.read = NULL,
.unlocked_ioctl = sec_ioctl
};
/**************************************************************************
* SEC RID PROC FUNCTION
**************************************************************************/
static int sec_proc_rid_show(struct seq_file *m, void *v)
{
unsigned int rid[4] = { 0 };
unsigned int i = 0;
sec_get_random_id((unsigned int *)rid);
for (i = 0; i < 16; i++)
seq_putc(m, *((char *)rid + i));
return 0;
}
static int sec_proc_rid_open(struct inode *inode, struct file *file)
{
return single_open(file, sec_proc_rid_show, NULL);
}
static const struct file_operations sec_proc_rid_fops = {
.open = sec_proc_rid_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/**************************************************************************
* set_dmverity_reboot eio flag
**************************************************************************/
// notify_call function
static int reboot_handler_set_eio_flag(struct notifier_block *reboot,
unsigned long mode,
void *cmd)
{ int ret = 0;
const char *dm_error_cmd = "dm-verity device corrupted";
if (cmd && !strcmp(cmd, dm_error_cmd))
ret = masp_hal_set_dm_verity_error();
return ret;
}
static struct notifier_block reboot_handler_notifier = {
.notifier_call = reboot_handler_set_eio_flag,
};
/**************************************************************************
* SEC MODULE PARAMETER
**************************************************************************/
static uint recovery_done;
module_param(recovery_done, uint, 0644); /* rw-r--r-- */
MODULE_PARM_DESC(recovery_done,
"recovery_done status(0 = complete, 1 = on-going, 2 = error)");
/* SEC DRIVER INIT */
static int sec_init(struct platform_device *dev)
{
int ret = 0;
dev_t id;
pr_debug("[%s] %s (%d)\n", SEC_DEV_NAME, __func__, ret);
hacc_base = of_iomap(dev->dev.of_node, 0);
if (!hacc_base) {
pr_notice("[%s] hacc register remapping failed\n",
SEC_DEV_NAME);
return -ENXIO;
}
ret = sec_clk_enable(dev);
if (ret) {
pr_notice("[%s] Cannot get hacc clock\n", SEC_DEV_NAME);
return ret;
}
id = MKDEV(SEC_MAJOR, 0);
ret = register_chrdev_region(id, 1, SEC_DEV_NAME);
if (ret) {
pr_notice("[%s] Regist Failed (%d)\n", SEC_DEV_NAME, ret);
return ret;
}
sec_class = class_create(THIS_MODULE, SEC_DEV_NAME);
if (sec_class == NULL) {
pr_notice("[%s] Create class failed(0x%x)\n",
SEC_DEV_NAME,
ret);
ret = -1;
return ret;
}
cdev_init(&sec_dev, &sec_fops);
sec_dev.owner = THIS_MODULE;
ret = cdev_add(&sec_dev, id, 1);
if (ret < 0)
goto exit;
sec_device = device_create(sec_class, NULL, id, NULL, SEC_DEV_NAME);
if (sec_class == NULL) {
pr_notice("[%s] Create device failed(0x%x)\n",
SEC_DEV_NAME,
ret);
class_destroy(sec_class);
ret = -1;
return ret;
}
sec.id = id;
sec.init = 1;
spin_lock_init(&sec.lock);
proc_create("rid", 0444, NULL, &sec_proc_rid_fops);
#ifdef MTK_SECURITY_MODULE_LITE
pr_debug("[MASP Lite] version '%s%s', enter.\n",
BUILD_TIME,
BUILD_BRANCH);
#endif
exit:
if (ret != 0) {
device_destroy(sec_class, id);
class_destroy(sec_class);
unregister_chrdev_region(id, 1);
memset(&sec, 0, sizeof(sec));
}
return ret;
}
/**************************************************************************
* SEC DRIVER EXIT
**************************************************************************/
static void sec_exit(void)
{
remove_proc_entry("rid", NULL);
cdev_del(&sec_dev);
unregister_chrdev_region(sec.id, 1);
memset(&sec, 0, sizeof(sec));
#ifdef MTK_SECURITY_MODULE_LITE
pr_debug("[MASP Lite] version '%s%s', exit.\n",
BUILD_TIME,
BUILD_BRANCH);
#else
sec_core_exit();
#endif
}
/**************************************************************************
* MASP PLATFORM DRIVER WRAPPER, FOR BUILD-IN SEQUENCE
**************************************************************************/
int masp_probe(struct platform_device *dev)
{
int ret = 0;
ret = sec_init(dev);
return ret;
}
int masp_remove(struct platform_device *dev)
{
sec_exit();
return 0;
}
static struct platform_driver masp_driver = {
.driver = {
.name = "masp",
.owner = THIS_MODULE,
.of_match_table = masp_of_ids,
},
.probe = masp_probe,
.remove = masp_remove,
};
static int __init masp_init(void)
{
int ret;
ret = platform_driver_register(&masp_driver);
if (ret) {
pr_notice("[%s] Reg platform driver failed (%d)\n",
SEC_DEV_NAME,
ret);
return ret;
}
register_reboot_notifier(&reboot_handler_notifier);
return ret;
}
#ifdef CONFIG_OF
static int __init masp_parse_dt(unsigned long node,
const char *uname,
int depth,
void *data)
{
struct masp_tag *tags;
int i;
if (depth != 1 || (strcmp(uname, "chosen") != 0 &&
strcmp(uname, "chosen@0") != 0))
return 0;
tags = (struct masp_tag *)of_get_flat_dt_prop(node, "atag,masp", NULL);
if (tags) {
g_rom_info_sbc_attr = tags->rom_info_sbc_attr;
g_rom_info_sdl_attr = tags->rom_info_sdl_attr;
g_hw_sbcen = tags->hw_sbcen;
g_lock_state = tags->lock_state;
lks = tags->lock_state;
for (i = 0; i < NUM_RID; i++)
g_random_id[i] = tags->rid[i];
for (i = 0; i < NUM_CRYPTO_SEED; i++)
g_crypto_seed[i] = tags->crypto_seed[i];
for (i = 0; i < NUM_SBC_PUBK_HASH; i++)
g_sbc_pubk_hash[i] = tags->sbc_pubk_hash[i];
}
return 1;
}
static int __init masp_of_init(void)
{
of_scan_flat_dt(masp_parse_dt, NULL);
return 0;
}
#endif
static void __exit masp_exit(void)
{
/*platform_driver_unregister(&es_driver);*/
platform_driver_unregister(&masp_driver);
unregister_reboot_notifier(&reboot_handler_notifier);
}
module_init(masp_init);
module_exit(masp_exit);
/**************************************************************************
* EXPORT FUNCTION
**************************************************************************/
EXPORT_SYMBOL(sec_get_random_id);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("MediaTek Inc.");
#ifdef CONFIG_OF
early_initcall(masp_of_init);
#endif
#ifdef MTK_SECURITY_MODULE_LITE
MODULE_DESCRIPTION("Mediatek Security Module Lite");
#else
MODULE_DESCRIPTION("Mediatek Security Module");
#endif
@@ -0,0 +1,58 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef SECMOD_H
#define SECMOD_H
#include <linux/init.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/fs.h>
struct sec_ops {
int (*sec_get_rid)(unsigned int *rid);
};
struct sec_mod {
dev_t id;
int init;
spinlock_t lock;
const struct sec_ops *ops;
};
/**************************************************************************
* EXTERNAL VARIABLE
**************************************************************************/
extern const struct sec_ops *sec_get_ops(void);
extern struct semaphore hacc_sem;
/**************************************************************************
* EXTERNAL FUNCTION
**************************************************************************/
extern long sec_core_ioctl(struct file *file,
unsigned int cmd,
unsigned long arg);
extern void sec_core_init(void);
extern void sec_core_exit(void);
#define NUM_SBC_PUBK_HASH 8
#define NUM_CRYPTO_SEED 16
#define NUM_RID 4
#ifdef CONFIG_OF
/*device information data*/
struct masp_tag {
u32 size;
u32 tag;
unsigned int rom_info_sbc_attr;
unsigned int rom_info_sdl_attr;
unsigned int hw_sbcen;
unsigned int lock_state;
unsigned int rid[NUM_RID];
/*rom_info.m_SEC_KEY.crypto_seed */
unsigned char crypto_seed[NUM_CRYPTO_SEED];
unsigned int sbc_pubk_hash[NUM_SBC_PUBK_HASH];
};
#endif
#endif /* end of SECMOD_H */
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2013-2016 TRUSTONIC LIMITED
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 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 the
* GNU General Public License for more details.
*/
#ifndef _TL_SEC_TCI_H_
#define _TL_SEC_TCI_H_
/**< Responses have bit 31 set */
#define RSP_ID_MASK (1U << 31)
#define RSP_ID(cmdId) (((uint32_t)(cmdId)) | RSP_ID_MASK)
#define IS_CMD(cmdId) ((((uint32_t)(cmdId)) & RSP_ID_MASK) == 0)
#define IS_RSP(cmdId) ((((uint32_t)(cmdId)) & RSP_ID_MASK) == RSP_ID_MASK)
/*
* Return codes of Trustlet commands.
*/
#define RET_OK 0 /* Set, if processing is error free */
#define RET_ERR_UNKNOWN_CMD 1 /* Unknown command */
#define INVALID_VIRTUAL_ADDR 2
/*
* TCI command header.
*/
struct tciCommandHeader_t {
uint32_t commandId; /* Command ID */
};
/*
* TCI response header.
*/
struct tciResponseHeader_t {
/* Response ID (must be command ID | RSP_ID_MASK ) */
uint32_t responseId;
/* Return code of command */
uint32_t returnCode;
};
#endif /* TCI_H_ */
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2013-2016 TRUSTONIC LIMITED
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 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 the
* GNU General Public License for more details.
*/
#ifndef _TL_SEC_API_H_
#define _TL_SEC_API_H_
#include "tci.h"
/*
* Command ID's for communication Trustlet Connector -> Trustlet.
*/
#define CMD_DEVINFO_GET 1
#define CMD_DAPC_SET 2
#define CMD_HACC_REQUEST 3
/*
* Termination codes
*/
#define EXIT_ERROR ((uint32_t)(-1))
/*
* command message.
*
* @param len Length of the data to process.
* @param data Data to processed (cleartext or ciphertext).
*/
struct dapc_cmd_t {
struct tciCommandHeader_t header; /* Command header */
uint32_t len; /* Length of data or buffer */
uint32_t respLen; /* Length of response buffer */
};
/*
* Response structure Trustlet -> Trustlet Connector.
*/
struct dapc_rsp_t {
struct tciResponseHeader_t header; /**< Response header */
uint32_t len;
};
/*
* TCI message data.
*/
struct dapc_tciMessage_t {
union {
struct dapc_cmd_t cmd;
struct dapc_rsp_t rsp;
};
uint32_t index;
uint32_t result;
uint32_t data_addr;
uint32_t data_len;
uint32_t seed_addr;
uint32_t seed_len;
uint32_t hacc_user;
uint32_t direction;
uint32_t reserve[2];
};
/*
* Trustlet UUID.
*/
#define TL_SEC_UUID { { 0x5, 0x11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
#endif /* _TL_SEC_API_H_ */