1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 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 #ifndef _BOOTLOADER_H_ 16 #define _BOOTLOADER_H_ 17 #include "plf.h" 18 #include "chip.h" 19 20 /** 21 * Memory map with bootloader: 22 * +--------------+ <--------------- 0x08000000 23 * | | ^ 24 * | bootloader | | 12KB 25 * | | v 26 * +--------------+ <--------------- 0x08003000 27 * | | ^ 28 * | image_info | | 4KB 29 * | | v 30 * +--------------+ <--------------- 0x08004000 31 * | | ^ 32 * | cur_image | | 636KB : current image 33 * | | v 34 * +--------------+ <--------------- 0x080A3000 35 * | | ^ 36 * | image_header | | 4KB 37 * | | v 38 * +--------------+ <--------------- 0x080A4000 39 * | | ^ 40 * | bak_image | | 636KB : backup image 41 * | | v 42 * +--------------+ <--------------- 0x08143000 43 * | | ^ 44 * | image_header | | 4KB 45 * | | v 46 * +--------------+ <--------------- 0x08144000 47 * | | ^ 48 * | upg_image | | 636KB : upgrade image 49 * | | v 50 * +--------------+ <--------------- 0x081E3000 51 * | | ^ 52 * | user_data | | 100KB : user specified 53 * | | v 54 * +--------------+ <--------------- 0x081FC000 55 * | | ^ 56 * | bt_ble_info | | 4KB 57 * | | v 58 * +--------------+ <--------------- 0x081FD000 59 * | | ^ 60 * | wifi_info | | 4KB 61 * | | v 62 * +--------------+ <--------------- 0x081FE000 63 * | | ^ 64 * | calib_info | | 4KB : factory calib(RO) 65 * | | v 66 * +--------------+ <--------------- 0x081FF000 67 * | | ^ 68 * | boot_info | | 4KB : chip reserved(RO) 69 * | | v 70 * +--------------+ <--------------- 0x08200000 71 */ 72 73 #define IMAGE_INFO_SIZE 0x1000 74 75 #define CURRENT_START_ADDR 0x08003000 76 #define CURRENT_INFO_ADDR (CURRENT_START_ADDR) 77 #define CURRENT_IMAGE_ADDR (CURRENT_START_ADDR + IMAGE_INFO_SIZE) 78 79 #define UPGRADE_START_ADDR 0x08143000 80 #define UPGRADE_INFO_ADDR (UPGRADE_START_ADDR) 81 #define UPGRADE_IMAGE_ADDR (UPGRADE_START_ADDR + IMAGE_INFO_SIZE) 82 83 #define BACKUP_START_ADDR 0x080A3000 84 #define BACKUP_INFO_ADDR (BACKUP_START_ADDR) 85 #define BACKUP_IMAGE_ADDR (BACKUP_START_ADDR + IMAGE_INFO_SIZE) 86 87 #define IMAGE_INFO_MAGIC 0x49474D49 // "IMGI" 88 #define IMAGE_HEADER_MAGIC 0x48474D49 // "IMGH" 89 #define VER_BYTE_CNT 16 90 91 #define FLASH_IMAGE_MAGIC_NUM 0x474D4946 /* "FIMG" */ 92 #define FLASH_IMAGE_INFO_OFFSET ((NVIC_USER_IRQ_OFFSET + NVIC_USER_IRQ_NUMBER) * 4) 93 94 #define IS_FLASH_MEM_VALID(addr) (((uint32_t)(addr) >> 26) == (CS_CACHE0_MEM_BASE >> 26)) // 0x08000000 ~ 0x0BFFFFFF 95 96 typedef struct { 97 unsigned int magic_num; 98 unsigned int image_end; 99 unsigned int reserved0; 100 unsigned int reserved1; 101 } flash_image_info_t; 102 103 struct image_info 104 { 105 uint32_t magic; 106 uint32_t addr; 107 uint32_t size; 108 uint32_t crc32; 109 uint8_t version[VER_BYTE_CNT]; 110 uint32_t bootaddr; 111 uint32_t bootmagic; 112 }; 113 114 struct image_header { 115 uint32_t magic; 116 uint32_t addr; 117 uint32_t size; 118 uint32_t crc32; 119 uint8_t version[VER_BYTE_CNT]; 120 uint32_t encrypt_algo; 121 }; 122 123 #endif /* _BOOTLOADER_H_ */ 124