1 /* 2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #ifndef __RESC_IMG_H_ 8 #define __RESC_IMG_H_ 9 10 #include <linux/list.h> 11 12 #define MAX_FILE_NAME_LEN 220 13 #define MAX_HASH_LEN 32 14 #define ROOT_COMPAT_PROP_OFFSET 0x4c /* Property: "/compatible" */ 15 #define DTB_SUFFIX ".dtb" 16 17 struct resource_file { 18 char name[MAX_FILE_NAME_LEN]; 19 char hash[MAX_HASH_LEN]; 20 uint32_t hash_size; 21 uint32_t f_offset; /* Sector offset */ 22 uint32_t f_size; /* Bytes */ 23 struct list_head link; 24 struct list_head dtbs; 25 /* Sector base of resource when ram=false, byte base when ram=true */ 26 uint32_t rsce_base; 27 bool ram; 28 }; 29 30 extern struct list_head entrys_head; 31 extern struct list_head entrys_dtbs_head; 32 33 /* 34 * resource_image_check_header - check resource image header 35 * 36 * @rsce_hdr: resource file hdr 37 * 38 * return 0 on header okay, otherwise failed 39 */ 40 int resource_image_check_header(void *rsce_hdr); 41 42 /* 43 * resource_create_ram_list - create resource file list by data from memory 44 * 45 * @dev_desc: blk dev descritpion 46 * @rsce_hdr: resource file hdr 47 * 48 * return 0 on header okay, otherwise failed 49 */ 50 int resource_create_ram_list(struct blk_desc *dev_desc, void *rsce_hdr); 51 52 /* 53 * rockchip_read_resource_file - read file from resource partition 54 * 55 * @buf: destination buf to store file data 56 * @name: file name 57 * @offset: blocks offset in the file, 1 block = 512 bytes 58 * @len: the size(by bytes) of file to read. 59 * 60 * return negative num on failed, otherwise the file size 61 */ 62 int rockchip_read_resource_file(void *buf, const char *name, int offset, int len); 63 64 /* 65 * rockchip_read_resource_dtb() - read dtb file 66 * 67 * @fdt_addr: destination buf to store dtb file 68 * @hash: hash value buffer 69 * @hash_size: hash value length 70 */ 71 int rockchip_read_resource_dtb(void *fdt_addr, char **hash, int *hash_size); 72 73 /* 74 * resource_init_list - init resource list of android image from storage 75 */ 76 int resource_init_list(void); 77 78 /* 79 * resource_replace_entry - replace resource entry, override if find exist one 80 */ 81 int resource_replace_entry(const char *f_name, uint32_t base, 82 uint32_t f_offset, uint32_t f_size); 83 84 /* 85 * resource_read_logo_bmps() - read logo bmp from "logo" partition 86 */ 87 int resource_read_logo_bmps(void); 88 89 /* 90 * resource_read_hwid_dtb() - read hwid dtb 91 */ 92 struct resource_file *resource_read_hwid_dtb(void); 93 94 /* 95 * resource_is_empty() - return if resource is empty 96 */ 97 int resource_is_empty(void); 98 99 /* 100 * resource_populate_dtb() - read fdt from this image: android/fit. 101 */ 102 int resource_populate_dtb(void *img, void *fdt); 103 104 /* 105 * resource_traverse_init_list() - traverse all image(android/fit/uimage) 106 */ 107 int resource_traverse_init_list(void); 108 109 /* 110 * board_resource_dtb_accepted() - check if this dtb is accepted 111 * 112 * return 0 if not accepted, otherwise accepted. 113 */ 114 int board_resource_dtb_accepted(char *dtb_name); 115 116 #endif 117