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 <hi_loaderboot_flash.h>
17 #include <hi_boot_err.h>
18 #include "burn_file.h"
19
loaderboot_get_section_head(hi_u32 addr,hi_upg_section_head * section_head)20 hi_u32 loaderboot_get_section_head(hi_u32 addr, hi_upg_section_head *section_head)
21 {
22 hi_upg_common_head head = { 0 };
23 hi_u32 ret;
24
25 if (section_head == HI_NULL) {
26 return HI_ERR_UPG_NULL_POINTER;
27 }
28 ret = hi_flash_read(addr, sizeof(hi_upg_common_head), (hi_u8 *)(&head));
29 if (ret != HI_ERR_SUCCESS) {
30 boot_msg1("[bootupg get section head]flash read ret:", ret);
31 return ret;
32 }
33 ret = hi_flash_read(addr + head.section_offset, sizeof(hi_upg_section_head), (hi_u8 *)section_head);
34 if (ret != HI_ERR_SUCCESS) {
35 boot_msg1("[bootupg get section head]flash read ret:", ret);
36 return ret;
37 }
38
39 return ret;
40 }
41
loaderboot_get_start_addr_offset(hi_u32 addr,hi_u32 * offset)42 hi_void loaderboot_get_start_addr_offset(hi_u32 addr, hi_u32 *offset)
43 {
44 hi_upg_section_head section_head = { 0 };
45 hi_u32 ret = loaderboot_get_section_head(addr, §ion_head);
46 if (ret == HI_ERR_SUCCESS) {
47 *offset = addr + section_head.section0_offset;
48 } else {
49 boot_msg1("[boot get start addr offset]fail.", ret);
50 *offset = addr;
51 }
52 }