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