Skip to content

Commit bf568e5

Browse files
committed
First commit. It works on the ESP32_DevKitJ_v1 hardware.
0 parents  commit bf568e5

File tree

164 files changed

+61589
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+61589
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
sdkconfig.old
3+
*.nes
4+

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3+
# project subdirectory.
4+
#
5+
6+
PROJECT_NAME := nesemu
7+
8+
include $(IDF_PATH)/make/project.mk
9+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
menu "Bootloader config"
2+
choice LOG_BOOTLOADER_LEVEL
3+
bool "Bootloader log verbosity"
4+
default LOG_BOOTLOADER_LEVEL_WARN
5+
help
6+
Specify how much output to see in bootloader logs.
7+
8+
config LOG_BOOTLOADER_LEVEL_NONE
9+
bool "No output"
10+
config LOG_BOOTLOADER_LEVEL_ERROR
11+
bool "Error"
12+
config LOG_BOOTLOADER_LEVEL_WARN
13+
bool "Warning"
14+
config LOG_BOOTLOADER_LEVEL_INFO
15+
bool "Info"
16+
config LOG_BOOTLOADER_LEVEL_DEBUG
17+
bool "Debug"
18+
config LOG_BOOTLOADER_LEVEL_VERBOSE
19+
bool "Verbose"
20+
endchoice
21+
22+
config LOG_BOOTLOADER_LEVEL
23+
int
24+
default 0 if LOG_BOOTLOADER_LEVEL_NONE
25+
default 1 if LOG_BOOTLOADER_LEVEL_ERROR
26+
default 2 if LOG_BOOTLOADER_LEVEL_WARN
27+
default 3 if LOG_BOOTLOADER_LEVEL_INFO
28+
default 4 if LOG_BOOTLOADER_LEVEL_DEBUG
29+
default 5 if LOG_BOOTLOADER_LEVEL_VERBOSE
30+
31+
endmenu
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Bootloader component
3+
#
4+
# The bootloader is not a real component that gets linked into the project.
5+
# Instead it is an entire standalone project ( in src/) that gets built in
6+
# the upper projects build directory. This Makefile.projbuild provides the
7+
# glue to build the bootloader project from the original project. It
8+
# basically runs Make in the src/ directory but it needs to zero some variables
9+
# the ESP-IDF project.mk makefile exports first, to not let them interfere.
10+
#
11+
ifeq ("$(IS_BOOTLOADER_BUILD)","")
12+
13+
BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH)
14+
BOOTLOADER_BUILD_DIR=$(BUILD_DIR_BASE)/bootloader
15+
BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
16+
17+
.PHONY: bootloader-clean bootloader-flash bootloader $(BOOTLOADER_BIN)
18+
19+
$(BOOTLOADER_BIN): $(COMPONENT_PATH)/src/sdkconfig
20+
$(Q) PROJECT_PATH= \
21+
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
22+
$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src MAKEFLAGS= V=$(V) TARGET_BIN_LAYOUT="$(BOOTLOADER_TARGET_BIN_LAYOUT)" $(BOOTLOADER_BIN)
23+
24+
bootloader-clean:
25+
$(Q) PROJECT_PATH= \
26+
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
27+
$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src app-clean MAKEFLAGS= V=$(V)
28+
29+
clean: bootloader-clean
30+
31+
bootloader: $(BOOTLOADER_BIN)
32+
@echo "Bootloader built. Default flash command is:"
33+
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
34+
35+
all_binaries: $(BOOTLOADER_BIN)
36+
37+
ESPTOOL_ALL_FLASH_ARGS += 0x1000 $(BOOTLOADER_BIN)
38+
39+
# synchronise the project level config to the component's
40+
# config
41+
$(COMPONENT_PATH)/src/sdkconfig: $(PROJECT_PATH)/sdkconfig
42+
$(Q) cp $< $@
43+
44+
# bootloader-flash calls flash in the bootloader dummy project
45+
bootloader-flash: $(BOOTLOADER_BIN)
46+
$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src flash MAKEFLAGS= V=$(V)
47+
48+
else
49+
CFLAGS += -D BOOTLOADER_BUILD=1 -I $(IDF_PATH)/components/esp32/include
50+
51+
endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
sdkconfig

components/bootloader/src/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3+
# project subdirectory.
4+
#
5+
6+
PROJECT_NAME := bootloader
7+
COMPONENTS := esptool_py bootloader log
8+
9+
# The bootloader pseudo-component is also included in this build, for its Kconfig.projbuild to be included.
10+
#
11+
# IS_BOOTLOADER_BUILD tells the component Makefile.projbuild to be a no-op
12+
IS_BOOTLOADER_BUILD := 1
13+
14+
#We cannot include the esp32 component directly but we need its includes.
15+
#This is fixed by adding CFLAGS from Makefile.projbuild
16+
17+
include $(IDF_PATH)/make/project.mk
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2+
//
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+
#ifndef __BOOT_CONFIG_H__
15+
#define __BOOT_CONFIG_H__
16+
17+
#include <stdint.h>
18+
19+
#ifdef __cplusplus
20+
extern "C"
21+
{
22+
#endif
23+
#define BOOT_VERSION "V0.1"
24+
#define SPI_SEC_SIZE 0x1000
25+
#define MEM_CACHE(offset) (uint8_t *)(0x3f400000 + (offset))
26+
#define CACHE_READ_32(offset) ((uint32_t *)(0x3f400000 + (offset)))
27+
#define PARTITION_ADD 0x4000
28+
#define PARTITION_MAGIC 0x50AA
29+
#define IROM_LOW 0x400D0000
30+
#define IROM_HIGH 0x40400000
31+
#define DROM_LOW 0x3F400000
32+
#define DROM_HIGH 0x3F800000
33+
#define RTC_IRAM_LOW 0x400C0000
34+
#define RTC_IRAM_HIGH 0x400C2000
35+
#define RTC_DATA_LOW 0x50000000
36+
#define RTC_DATA_HIGH 0x50002000
37+
38+
/*spi mode,saved in third byte in flash */
39+
enum {
40+
SPI_MODE_QIO,
41+
SPI_MODE_QOUT,
42+
SPI_MODE_DIO,
43+
SPI_MODE_DOUT,
44+
SPI_MODE_FAST_READ,
45+
SPI_MODE_SLOW_READ
46+
};
47+
/* spi speed*/
48+
enum {
49+
SPI_SPEED_40M,
50+
SPI_SPEED_26M,
51+
SPI_SPEED_20M,
52+
SPI_SPEED_80M = 0xF
53+
};
54+
/*suppport flash size in esp32 */
55+
enum {
56+
SPI_SIZE_1MB = 0,
57+
SPI_SIZE_2MB,
58+
SPI_SIZE_4MB,
59+
SPI_SIZE_8MB,
60+
SPI_SIZE_16MB,
61+
SPI_SIZE_MAX
62+
};
63+
64+
65+
struct flash_hdr {
66+
char magic;
67+
char blocks;
68+
char spi_mode; /* flag of flash read mode in unpackage and usage in future */
69+
char spi_speed: 4; /* low bit */
70+
char spi_size: 4;
71+
unsigned int entry_addr;
72+
uint8_t encrypt_flag; /* encrypt flag */
73+
uint8_t secury_boot_flag; /* secury boot flag */
74+
char extra_header[14]; /* ESP32 additional header, unused by second bootloader */
75+
};
76+
77+
/* each header of flash bin block */
78+
struct block_hdr {
79+
unsigned int load_addr;
80+
unsigned int data_len;
81+
};
82+
83+
/* OTA selection structure (two copies in the OTA data partition.)
84+
85+
Size of 32 bytes is friendly to flash encryption */
86+
typedef struct {
87+
uint32_t ota_seq;
88+
uint8_t seq_label[24];
89+
uint32_t crc; /* CRC32 of ota_seq field only */
90+
} ota_select;
91+
92+
typedef struct {
93+
uint32_t offset;
94+
uint32_t size;
95+
} partition_pos_t;
96+
97+
typedef struct {
98+
uint16_t magic;
99+
uint8_t type; /* partition Type */
100+
uint8_t subtype; /* part_subtype */
101+
partition_pos_t pos;
102+
uint8_t label[16]; /* label for the partition */
103+
uint8_t reserved[4]; /* reserved */
104+
} partition_info_t;
105+
106+
#define PART_TYPE_APP 0x00
107+
#define PART_SUBTYPE_FACTORY 0x00
108+
#define PART_SUBTYPE_OTA_FLAG 0x10
109+
#define PART_SUBTYPE_OTA_MASK 0x0f
110+
#define PART_SUBTYPE_TEST 0x20
111+
112+
#define PART_TYPE_DATA 0x01
113+
#define PART_SUBTYPE_DATA_OTA 0x00
114+
#define PART_SUBTYPE_DATA_RF 0x01
115+
#define PART_SUBTYPE_DATA_WIFI 0x02
116+
117+
#define PART_TYPE_END 0xff
118+
#define PART_SUBTYPE_END 0xff
119+
120+
#define SPI_ERROR_LOG "spi flash error"
121+
122+
typedef struct {
123+
partition_pos_t ota_info;
124+
partition_pos_t factory;
125+
partition_pos_t test;
126+
partition_pos_t ota[16];
127+
uint32_t app_count;
128+
uint32_t selected_subtype;
129+
} bootloader_state_t;
130+
131+
void boot_cache_redirect( uint32_t pos, size_t size );
132+
uint32_t get_bin_len(uint32_t pos);
133+
134+
bool flash_encrypt(bootloader_state_t *bs);
135+
bool secure_boot(void);
136+
137+
138+
#ifdef __cplusplus
139+
}
140+
#endif
141+
142+
#endif /* __BOOT_CONFIG_H__ */

0 commit comments

Comments
 (0)