huangcm
2025-04-07 511b111543524704f6182b374e489f5d0e51db8c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * (C) Copyright 2007-2013
 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
 * Jerry Wang <wangflord@allwinnertech.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */
#ifndef __SUNXI_FLASH_H__
#define __SUNXI_FLASH_H__
#include <common.h>
#include <sunxi_nand.h>
 
 
 
/*normal*/
int sunxi_flash_init(void);
uint sunxi_flash_size(void);
int sunxi_flash_exit(int force);
int sunxi_flash_read(unsigned int start_block, unsigned int nblock,
            void *buffer);
int sunxi_flash_write(unsigned int start_block, unsigned int nblock,
             void *buffer);
int sunxi_flash_flush(void);
int sunxi_flash_erase(int erase, void *mbr_buffer);
int sunxi_flash_erase_area(uint start_block, uint nblock);
int sunxi_flash_force_erase(void);
 
int sunxi_flash_phyread(unsigned int start_block, unsigned int nblock,
           void *buffer);
int sunxi_flash_phywrite(unsigned int start_block, unsigned int nblock,
            void *buffer);
int check_secure_storage_map(void *buffer);
int sunxi_secstorage_read(int item, unsigned char *buf, unsigned int len);
int sunxi_secstorage_write(int item, unsigned char *buf, unsigned int len);
int sunxi_flash_download_spl(unsigned char *buf, int len, unsigned int ext);
int sunxi_flash_download_toc(unsigned char *buf, int len, unsigned int ext);
 
/*sprite*/
int sunxi_sprite_init(int boot_mode);
uint sunxi_sprite_size(void);
int sunxi_sprite_exit(int force);
int sunxi_sprite_read(unsigned int start_block, unsigned int nblock,
             void *buffer);
int sunxi_sprite_write(unsigned int start_block, unsigned int nblock,
              void *buffer);
int sunxi_sprite_flush(void);
int sunxi_sprite_erase(int erase, void *mbr_buffer);
int sunxi_sprite_force_erase(void);
 
int sunxi_sprite_phyread(unsigned int start_block, unsigned int nblock,
            void *buffer);
int sunxi_sprite_phywrite(unsigned int start_block, unsigned int nblock,
             void *buffer);
int sunxi_sprite_secstorage_read(int item, unsigned char *buf,
                unsigned int len);
int sunxi_sprite_secstorage_write(int item, unsigned char *buf,
                 unsigned int len);
int sunxi_sprite_download_spl(unsigned char *buf, int len, unsigned int ext);
int sunxi_sprite_download_toc(unsigned char *buf, int len, unsigned int ext);
 
int sunxi_flash_probe(void);
int sunxi_flash_init_ext(void);
 
int sunxi_flash_boot_init(int storage_type, int workmode);
int save_fdt_to_flash(void *fdt_buf, size_t fdt_size);
 
#define SUNXI_SECSTORE_VERSION 1
 
#define MAX_STORE_LEN 0xc00 /*3K payload*/
#define STORE_OBJECT_MAGIC 0x17253948
#define STORE_REENCRYPT_MAGIC 0x86734716
#define STORE_WRITE_PROTECT_MAGIC 0x8ad3820f
typedef struct {
   unsigned int magic; /* store object magic*/
   int id; /*store id, 0x01,0x02.. for user*/
   char name[64]; /*OEM name*/
   unsigned int re_encrypt; /*flag for OEM object*/
   unsigned int version;
   unsigned int
       write_protect; /*can be placed or not, =0, can be write_protectd*/
   unsigned int reserved[3];
   unsigned int actual_len; /*the actual len in data buffer*/
   unsigned char data[MAX_STORE_LEN]; /*the payload of secure object*/
   unsigned int crc; /*crc to check the sotre_objce valid*/
} store_object_t;
 
/* secure storage map, have the key info in the keysecure storage */
#define SEC_BLK_SIZE (4096)
#define MAP_KEY_NAME_SIZE    (64)
#define MAP_KEY_DATA_SIZE    (32)
struct map_info {
   unsigned char data[SEC_BLK_SIZE - sizeof(int) * 2];
   unsigned int magic;
   unsigned int crc;
};
 
#endif /* __SUNXI_FLASH_H__ */