forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
723 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2015 Ivan Grokhotkov | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. The name of the authors may not be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
OF SUCH DAMAGE. | ||
|
||
Authors: Ivan Grokhotkov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
XTENSA_TOOCHAIN ?= | ||
|
||
BIN_DIR := ./ | ||
TARGET_DIR := ./ | ||
|
||
TARGET_OBJ_FILES := \ | ||
eboot_debug.o \ | ||
|
||
TARGET_OBJ_PATHS := $(addprefix $(TARGET_DIR)/,$(TARGET_OBJ_FILES)) | ||
|
||
CC := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-gcc | ||
CXX := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-g++ | ||
AR := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-ar | ||
LD := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-gcc | ||
OBJDUMP := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-objdump | ||
|
||
|
||
CFLAGS += -std=gnu99 | ||
|
||
CFLAGS += -O0 -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals | ||
|
||
LDFLAGS += -nostdlib -Wl,--no-check-sections -umain | ||
|
||
LD_SCRIPT := -Teboot.ld | ||
|
||
APP_OUT:= eboot.elf | ||
APP_AR := eboot.a | ||
APP_FW := eboot.bin | ||
|
||
all: $(APP_FW) | ||
|
||
$(APP_AR): $(TARGET_OBJ_PATHS) | ||
$(AR) cru $@ $^ | ||
|
||
|
||
$(APP_OUT): $(APP_AR) | ||
$(LD) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group -Wl,--whole-archive $(APP_AR) -Wl,--end-group -o $@ | ||
|
||
$(APP_FW): $(APP_OUT) | ||
$(ESPTOOL) -vvv -eo $(APP_OUT) -bo $@ -bs .text -bs .data -bs .rodata -bc -ec || true | ||
|
||
|
||
clean: | ||
rm -f *.o | ||
rm -f $(APP_AR) | ||
rm -f $(APP_OUT) | ||
|
||
|
||
.PHONY: all clean default | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. | ||
* This file is part of eboot bootloader. | ||
* | ||
* Redistribution and use is permitted according to the conditions of the | ||
* 3-clause BSD license to be found in the LICENSE file. | ||
*/ | ||
|
||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include "eboot.h" | ||
extern void* flashchip; | ||
|
||
#define SWRST do { (*((volatile uint32_t*) 0x60000700)) |= 0x80000000; } while(0); | ||
|
||
|
||
int load_app_from_flash_raw(const uint32_t flash_addr) | ||
{ | ||
image_header_t image_header; | ||
uint32_t pos = flash_addr + APP_START_OFFSET; | ||
|
||
if (SPIRead(pos, &image_header, sizeof(image_header))) { | ||
return 1; | ||
} | ||
pos += sizeof(image_header); | ||
|
||
|
||
for (uint32_t section_index = 0; | ||
section_index < image_header.num_segments; | ||
++section_index) | ||
{ | ||
section_header_t section_header = {0}; | ||
if (SPIRead(pos, §ion_header, sizeof(section_header))) { | ||
return 2; | ||
} | ||
pos += sizeof(section_header); | ||
|
||
const uint32_t address = section_header.address; | ||
|
||
bool load = false; | ||
|
||
if (address < 0x40000000) { | ||
load = true; | ||
} | ||
|
||
if (address >= 0x40100000 && address < 0x40108000) { | ||
load = true; | ||
} | ||
|
||
if (address >= 0x60000000) { | ||
load = true; | ||
} | ||
|
||
if (!load) { | ||
pos += section_header.size; | ||
continue; | ||
} | ||
|
||
if (SPIRead(pos, (void*)address, section_header.size)) | ||
return 3; | ||
|
||
pos += section_header.size; | ||
} | ||
|
||
register uint32_t sp asm("a1") = 0x3ffffff0; | ||
register uint32_t pc asm("a3") = image_header.entry; | ||
__asm__ __volatile__ ("jx a3"); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
void main() | ||
{ | ||
int res = load_app_from_flash_raw(0); | ||
if (res) { | ||
ets_putc('\n'); | ||
ets_putc('#'); | ||
ets_putc('0' + res); | ||
ets_putc('\n'); | ||
SWRST; | ||
} | ||
|
||
while(true){} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. | ||
* This file is part of eboot bootloader. | ||
* | ||
* Redistribution and use is permitted according to the conditions of the | ||
* 3-clause BSD license to be found in the LICENSE file. | ||
*/ | ||
|
||
#ifndef EBOOT_H | ||
#define EBOOT_H | ||
|
||
|
||
int SPIEraseBlock(uint32_t block); | ||
int SPIEraseSector(uint32_t sector); | ||
int SPIRead(uint32_t addr, void *dest, size_t size); | ||
int SPIWrite(uint32_t addr, void *src, size_t size); | ||
|
||
#define APP_START_OFFSET 0x1000 | ||
|
||
typedef struct { | ||
unsigned char magic; | ||
unsigned char num_segments; | ||
|
||
/* SPI Flash Interface (0 = QIO, 1 = QOUT, 2 = DIO, 0x3 = DOUT) */ | ||
unsigned char flash_mode; | ||
|
||
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M, | ||
Low four bits: 0 = 40MHz, 1= 26MHz, 2 = 20MHz, 0xf = 80MHz */ | ||
unsigned char flash_size_freq; | ||
|
||
uint32_t entry; | ||
} image_header_t; | ||
|
||
|
||
typedef struct { | ||
uint32_t address; | ||
uint32_t size; | ||
} section_header_t; | ||
|
||
|
||
|
||
#endif //EBOOT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/* This linker script generated from xt-genldscripts.tpp for LSP . */ | ||
/* Linker Script for ld -N */ | ||
MEMORY | ||
{ | ||
dport0_0_seg : org = 0x3FF00000, len = 0x10 | ||
dram0_0_seg : org = 0x3FFE8000, len = 0x14000 | ||
iram1_0_seg : org = 0x4010f800, len = 0x800 | ||
irom0_0_seg : org = 0x40240000, len = 0x32000 | ||
} | ||
|
||
PHDRS | ||
{ | ||
dport0_0_phdr PT_LOAD; | ||
dram0_0_phdr PT_LOAD; | ||
dram0_0_bss_phdr PT_LOAD; | ||
iram1_0_phdr PT_LOAD; | ||
irom0_0_phdr PT_LOAD; | ||
} | ||
|
||
|
||
/* Default entry point: */ | ||
ENTRY(main) | ||
PROVIDE(_memmap_vecbase_reset = 0x40000000); | ||
/* Various memory-map dependent cache attribute settings: */ | ||
_memmap_cacheattr_wb_base = 0x00000110; | ||
_memmap_cacheattr_wt_base = 0x00000110; | ||
_memmap_cacheattr_bp_base = 0x00000220; | ||
_memmap_cacheattr_unused_mask = 0xFFFFF00F; | ||
_memmap_cacheattr_wb_trapnull = 0x2222211F; | ||
_memmap_cacheattr_wba_trapnull = 0x2222211F; | ||
_memmap_cacheattr_wbna_trapnull = 0x2222211F; | ||
_memmap_cacheattr_wt_trapnull = 0x2222211F; | ||
_memmap_cacheattr_bp_trapnull = 0x2222222F; | ||
_memmap_cacheattr_wb_strict = 0xFFFFF11F; | ||
_memmap_cacheattr_wt_strict = 0xFFFFF11F; | ||
_memmap_cacheattr_bp_strict = 0xFFFFF22F; | ||
_memmap_cacheattr_wb_allvalid = 0x22222112; | ||
_memmap_cacheattr_wt_allvalid = 0x22222112; | ||
_memmap_cacheattr_bp_allvalid = 0x22222222; | ||
PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); | ||
|
||
SECTIONS | ||
{ | ||
|
||
.dport0.rodata : ALIGN(4) | ||
{ | ||
_dport0_rodata_start = ABSOLUTE(.); | ||
*(.dport0.rodata) | ||
*(.dport.rodata) | ||
_dport0_rodata_end = ABSOLUTE(.); | ||
} >dport0_0_seg :dport0_0_phdr | ||
|
||
.dport0.literal : ALIGN(4) | ||
{ | ||
_dport0_literal_start = ABSOLUTE(.); | ||
*(.dport0.literal) | ||
*(.dport.literal) | ||
_dport0_literal_end = ABSOLUTE(.); | ||
} >dport0_0_seg :dport0_0_phdr | ||
|
||
.dport0.data : ALIGN(4) | ||
{ | ||
_dport0_data_start = ABSOLUTE(.); | ||
*(.dport0.data) | ||
*(.dport.data) | ||
_dport0_data_end = ABSOLUTE(.); | ||
} >dport0_0_seg :dport0_0_phdr | ||
|
||
.data : ALIGN(4) | ||
{ | ||
_heap_start = ABSOLUTE(.); | ||
/* _stack_sentry = ALIGN(0x8); */ | ||
} >dram0_0_seg :dram0_0_bss_phdr | ||
/* __stack = 0x3ffc8000; */ | ||
|
||
.text : ALIGN(4) | ||
{ | ||
_stext = .; | ||
_text_start = ABSOLUTE(.); | ||
*(.entry.text) | ||
*(.init.literal) | ||
*(.init) | ||
*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) | ||
*(.fini.literal) | ||
*(.fini) | ||
*(.gnu.version) | ||
_text_end = ABSOLUTE(.); | ||
_etext = .; | ||
. = ALIGN (8); | ||
_data_start = ABSOLUTE(.); | ||
*(.data) | ||
*(.data.*) | ||
*(.gnu.linkonce.d.*) | ||
*(.data1) | ||
*(.sdata) | ||
*(.sdata.*) | ||
*(.gnu.linkonce.s.*) | ||
*(.sdata2) | ||
*(.sdata2.*) | ||
*(.gnu.linkonce.s2.*) | ||
*(.jcr) | ||
_data_end = ABSOLUTE(.); | ||
. = ALIGN (8); | ||
_rodata_start = ABSOLUTE(.); | ||
*(.rodata) | ||
*(.rodata.*) | ||
*(.gnu.linkonce.r.*) | ||
*(.rodata1) | ||
__XT_EXCEPTION_TABLE__ = ABSOLUTE(.); | ||
*(.xt_except_table) | ||
*(.gcc_except_table) | ||
*(.gnu.linkonce.e.*) | ||
*(.gnu.version_r) | ||
*(.eh_frame) | ||
/* C++ constructor and destructor tables, properly ordered: */ | ||
KEEP (*crtbegin.o(.ctors)) | ||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) | ||
KEEP (*(SORT(.ctors.*))) | ||
KEEP (*(.ctors)) | ||
KEEP (*crtbegin.o(.dtors)) | ||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) | ||
KEEP (*(SORT(.dtors.*))) | ||
KEEP (*(.dtors)) | ||
/* C++ exception handlers table: */ | ||
__XT_EXCEPTION_DESCS__ = ABSOLUTE(.); | ||
*(.xt_except_desc) | ||
*(.gnu.linkonce.h.*) | ||
__XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); | ||
*(.xt_except_desc_end) | ||
*(.dynamic) | ||
*(.gnu.version_d) | ||
. = ALIGN(4); /* this table MUST be 4-byte aligned */ | ||
_bss_table_start = ABSOLUTE(.); | ||
LONG(_bss_start) | ||
LONG(_bss_end) | ||
_bss_table_end = ABSOLUTE(.); | ||
_rodata_end = ABSOLUTE(.); | ||
|
||
. = ALIGN (8); | ||
_bss_start = ABSOLUTE(.); | ||
*(.dynsbss) | ||
*(.sbss) | ||
*(.sbss.*) | ||
*(.gnu.linkonce.sb.*) | ||
*(.scommon) | ||
*(.sbss2) | ||
*(.sbss2.*) | ||
*(.gnu.linkonce.sb2.*) | ||
*(.dynbss) | ||
*(.bss) | ||
*(.bss.*) | ||
*(.gnu.linkonce.b.*) | ||
*(COMMON) | ||
. = ALIGN (8); | ||
_bss_end = ABSOLUTE(.); | ||
} >iram1_0_seg :iram1_0_phdr | ||
|
||
.lit4 : ALIGN(4) | ||
{ | ||
_lit4_start = ABSOLUTE(.); | ||
*(*.lit4) | ||
*(.lit4.*) | ||
*(.gnu.linkonce.lit4.*) | ||
_lit4_end = ABSOLUTE(.); | ||
} >iram1_0_seg :iram1_0_phdr | ||
|
||
.irom0.text : ALIGN(4) | ||
{ | ||
_irom0_text_start = ABSOLUTE(.); | ||
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text) | ||
_irom0_text_end = ABSOLUTE(.); | ||
} >irom0_0_seg :irom0_0_phdr | ||
} | ||
|
||
/* get ROM code address */ | ||
INCLUDE "rom.ld" |
Oops, something went wrong.