• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "upg_user_verify.h"
17 
18 HI_PRV upg_user_verify_inf g_user_file_verify_inf = {HI_NULL, HI_NULL};
19 
upg_get_user_verify_inf(hi_void)20 upg_user_verify_inf *upg_get_user_verify_inf(hi_void)
21 {
22     return &g_user_file_verify_inf;
23 }
24 
upg_user_define_verify(const hi_upg_user_info * info)25 hi_u32 upg_user_define_verify(const hi_upg_user_info *info)
26 {
27     hi_u32 ret = HI_ERR_SUCCESS;
28     upg_user_verify_inf *user_inf_ctx = upg_get_user_verify_inf();
29 
30     if (user_inf_ctx->upg_file_check_fn) {
31         ret = user_inf_ctx->upg_file_check_fn(info, user_inf_ctx->user_param);
32     } else {
33         upg_print("[upg user verify]not define \r\n");
34     }
35 
36     if (ret != HI_ERR_SUCCESS) {
37         upg_print("[upg user verify]check ret:0x%x \r\n", ret);
38         return HI_ERR_UPG_USER_VERIFY;
39     }
40 
41     return HI_ERR_SUCCESS;
42 }
43 
hi_upg_register_file_verify_fn(hi_u32 (* upg_file_check_fn)(const hi_upg_user_info * info,hi_void * param),hi_void * param)44 hi_u32 hi_upg_register_file_verify_fn(
45     hi_u32 (*upg_file_check_fn)(const hi_upg_user_info *info, hi_void *param),
46     hi_void *param)
47 {
48     upg_user_verify_inf *user_info_ctx = upg_get_user_verify_inf();
49 
50     if (!hi_is_valid_code_addr((uintptr_t)upg_file_check_fn)) {
51         return HI_ERR_UPG_PARAMETER;
52     }
53     user_info_ctx->upg_file_check_fn = upg_file_check_fn;
54     user_info_ctx->user_param        = param;
55     return HI_ERR_SUCCESS;
56 }
57