Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
rboot.h
1 #ifndef __RBOOT_H__
2 #define __RBOOT_H__
3 
5 // rBoot open source boot loader for ESP8266.
6 // Copyright 2015 Richard A Burton
7 // richardaburton@gmail.com
8 // See license.txt for license terms.
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 // uncomment to use only c code
16 // if you aren't using gcc you may need to do this
17 //#define BOOT_NO_ASM
18 
19 // uncomment to have a checksum on the boot config
20 //#define BOOT_CONFIG_CHKSUM
21 
22 // uncomment to enable big flash support (>1MB)
23 //#define BOOT_BIG_FLASH
24 
25 // uncomment to enable 2 way communication between
26 // rBoot and the user app via the esp rtc data area
27 //#define BOOT_RTC_ENABLED
28 
29 // uncomment to enable GPIO booting of specific rom
30 // (specified in rBoot config block)
31 // cannot be used at same time as BOOT_GPIO_SKIP_ENABLED
32 //#define BOOT_GPIO_ENABLED
33 
34 // uncomment to enable GPIO rom skip mode, trigger
35 // GPIO at boot time to skip to next rom
36 // cannot be used at same time as BOOT_GPIO_ENABLED
37 //#define BOOT_GPIO_SKIP_ENABLED
38 
39 // set the GPIO pin used by GPIO modes above (will default
40 // to 16 if not manually set), only applicable when
41 // BOOT_GPIO_ENABLED or BOOT_GPIO_SKIP_ENABLED is enabled
42 //#define BOOT_GPIO_NUM 16
43 
44 // uncomment to include .irom0.text section in the checksum
45 // roms must be built with esptool2 using -iromchksum option
46 //#define BOOT_IROM_CHKSUM
47 
48 // uncomment to add a boot delay, allows you time to connect
49 // a terminal before rBoot starts to run and output messages
50 // value is in microseconds
51 //#define BOOT_DELAY_MICROS 2000000
52 
53 // define your own default custom rBoot config, used on
54 // first boot and in case of corruption, standard fields
55 // (magic, version and chksum (if applicable) are included
56 // for you automatically), see example at end of this file
57 // and customise as required
58 //#define BOOT_CUSTOM_DEFAULT_CONFIG
59 
60 // max number of roms in the config (defaults to 4), higher
61 // values will use more ram at run time
62 //#define MAX_ROMS 4
63 
64 
65 // you should not need to modify anything below this line,
66 // except default_config() right at the bottom of the file
67 
68 
69 #define CHKSUM_INIT 0xef
70 
71 #define SECTOR_SIZE 0x1000
72 #define BOOT_CONFIG_SECTOR 1
73 
74 #define BOOT_CONFIG_MAGIC 0xe1
75 #define BOOT_CONFIG_VERSION 0x01
76 
77 #define MODE_STANDARD 0x00
78 #define MODE_GPIO_ROM 0x01
79 #define MODE_TEMP_ROM 0x02
80 #define MODE_GPIO_ERASES_SDKCONFIG 0x04
81 #define MODE_GPIO_SKIP 0x08
82 
83 #define RBOOT_RTC_MAGIC 0x2334ae68
84 #define RBOOT_RTC_READ 1
85 #define RBOOT_RTC_WRITE 0
86 #define RBOOT_RTC_ADDR 64
87 
88 // defaults for unset user options
89 #ifndef BOOT_GPIO_NUM
90 #define BOOT_GPIO_NUM 16
91 #endif
92 
93 #ifndef MAX_ROMS
94 #define MAX_ROMS 4
95 #endif
96 
107 typedef struct {
108  uint8 magic;
109  uint8 version;
110  uint8 mode;
111  uint8 current_rom;
112  uint8 gpio_rom;
113  uint8 count;
114  uint8 unused[2];
115  uint32 roms[MAX_ROMS];
116 #ifdef BOOT_CONFIG_CHKSUM
117  uint8 chksum;
118 #endif
119 } rboot_config;
120 
121 #ifdef BOOT_RTC_ENABLED
122 
127 typedef struct {
128  uint32 magic;
129  uint8 next_mode;
130  uint8 last_mode;
131  uint8 last_rom;
132  uint8 temp_rom;
133  uint8 chksum;
134 } rboot_rtc_data;
135 #endif
136 
137 // override function to create default config, must be placed after type
138 // and constant defines as it uses some of them, flashsize is the used size
139 // (may be smaller than actual flash size if big flash mode is not enabled,
140 // or just plain wrong if the device has not been programmed correctly!)
141 #ifdef BOOT_CUSTOM_DEFAULT_CONFIG
142 static uint8 default_config(rboot_config *romconf, uint32 flashsize) {
143  romconf->count = 2;
144  romconf->roms[0] = SECTOR_SIZE * (BOOT_CONFIG_SECTOR + 1);
145  romconf->roms[1] = (flashsize / 2) + (SECTOR_SIZE * (BOOT_CONFIG_SECTOR + 1));
146 }
147 #endif
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif
uint32 roms[MAX_ROMS]
Flash addresses of each ROM.
Definition: rboot.h:115
uint8 current_rom
Currently selected ROM (will be used for next standard boot)
Definition: rboot.h:111
Structure containing rBoot configuration.
Definition: rboot.h:107
uint8 mode
Boot loader mode (MODE_STANDARD | MODE_GPIO_ROM | MODE_GPIO_SKIP)
Definition: rboot.h:110
uint8 version
Version of configuration structure - should be BOOT_CONFIG_VERSION.
Definition: rboot.h:109
uint8 count
Quantity of ROMs available to boot.
Definition: rboot.h:113
uint8 gpio_rom
ROM to use for GPIO boot (hardware switch) with mode set to MODE_GPIO_ROM.
Definition: rboot.h:112
uint8 magic
Our magic, identifies rBoot configuration - should be BOOT_CONFIG_MAGIC.
Definition: rboot.h:108