Commit aaca524c authored by Vowstar's avatar Vowstar
Browse files

Merge pull request #529 from nodemcu/dev096

Dev096 into master.
parents 3430e5f8 2224f24d
...@@ -84,6 +84,9 @@ typedef enum { ...@@ -84,6 +84,9 @@ typedef enum {
#define ICACHE_FLASH_ATTR #define ICACHE_FLASH_ATTR
#endif /* ICACHE_FLASH */ #endif /* ICACHE_FLASH */
#define TEXT_SECTION_ATTR __attribute__((section(".text")))
#define RAM_CONST_ATTR __attribute__((section(".text")))
#ifndef __cplusplus #ifndef __cplusplus
typedef unsigned char bool; typedef unsigned char bool;
#define BOOL bool #define BOOL bool
......
...@@ -5,7 +5,7 @@ MEMORY ...@@ -5,7 +5,7 @@ MEMORY
dport0_0_seg : org = 0x3FF00000, len = 0x10 dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000 dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000 iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x60000 irom0_0_seg : org = 0x40210000, len = 0x80000
} }
PHDRS PHDRS
...@@ -19,7 +19,7 @@ PHDRS ...@@ -19,7 +19,7 @@ PHDRS
/* Default entry point: */ /* Default entry point: */
ENTRY(call_user_start) ENTRY(user_start_trampoline)
PROVIDE(_memmap_vecbase_reset = 0x40000000); PROVIDE(_memmap_vecbase_reset = 0x40000000);
/* Various memory-map dependent cache attribute settings: */ /* Various memory-map dependent cache attribute settings: */
_memmap_cacheattr_wb_base = 0x00000110; _memmap_cacheattr_wb_base = 0x00000110;
...@@ -72,8 +72,9 @@ SECTIONS ...@@ -72,8 +72,9 @@ SECTIONS
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text) *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
*(.literal.* .text.*) *(.literal.* .text.*)
/* put font and progmem data into irom0 */ /* Trade some performance for lots of ram. At the time of writing the
*(.u8g_progmem.*) * available Lua heap went from 18248 to 34704. */
*(.rodata*)
_irom0_text_end = ABSOLUTE(.); _irom0_text_end = ABSOLUTE(.);
_flash_used_end = ABSOLUTE(.); _flash_used_end = ABSOLUTE(.);
...@@ -124,10 +125,7 @@ SECTIONS ...@@ -124,10 +125,7 @@ SECTIONS
.rodata : ALIGN(4) .rodata : ALIGN(4)
{ {
_rodata_start = ABSOLUTE(.); _rodata_start = ABSOLUTE(.);
*(.rodata)
*(.rodata.*)
*(.gnu.linkonce.r.*) *(.gnu.linkonce.r.*)
*(.rodata1)
__XT_EXCEPTION_TABLE__ = ABSOLUTE(.); __XT_EXCEPTION_TABLE__ = ABSOLUTE(.);
*(.xt_except_table) *(.xt_except_table)
*(.gcc_except_table) *(.gcc_except_table)
......
No preview for this file type
--this version actually works
local tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
base64 = {
enc = function(data)
local l,out = 0,''
local m = (3-data:len()%3)%3
local d = data..string.rep('\0',m)
for i=1,d:len() do
l = bit.lshift(l,8)
l = l+d:byte(i,i)
if i%3==0 then
for j=1,4 do
local a = bit.rshift(l,18)+1
out = out..tab:sub(a,a)
l = bit.band(bit.lshift(l,6),0xFFFFFF)
end
end
end
return out:sub(1,-1-m)..string.rep('=',m)
end,
dec = function(data)
local a,b = data:gsub('=','A')
local out = ''
local l = 0
for i=1,a:len() do
l=l+tab:find(a:sub(i,i))-1
if i%4==0 then
out=out..string.char(bit.rshift(l,16),bit.band(bit.rshift(l,8),255),bit.band(l,255))
l=0
end
l=bit.lshift(l,6)
end
return out:sub(1,-b-1)
end
}
...@@ -128,38 +128,32 @@ class ESPROM: ...@@ -128,38 +128,32 @@ class ESPROM:
def connect(self): def connect(self):
print 'Connecting...' print 'Connecting...'
# RTS = CH_PD (i.e reset) for _ in xrange(4):
# DTR = GPIO0 # issue reset-to-bootloader:
# self._port.setRTS(True) # RTS = either CH_PD or nRESET (both active low = chip in reset)
# self._port.setDTR(True) # DTR = GPIO0 (active low = boot to flasher)
# self._port.setRTS(False) self._port.setDTR(False)
# time.sleep(0.1) self._port.setRTS(True)
# self._port.setDTR(False) time.sleep(0.05)
self._port.setDTR(True)
# NodeMCU devkit self._port.setRTS(False)
self._port.setRTS(True) time.sleep(0.05)
self._port.setDTR(True) self._port.setDTR(False)
time.sleep(0.1)
self._port.setRTS(False) self._port.timeout = 0.3 # worst-case latency timer should be 255ms (probably <20ms)
self._port.setDTR(False) for _ in xrange(4):
time.sleep(0.1) try:
self._port.setRTS(True) self._port.flushInput()
time.sleep(0.1) self._port.flushOutput()
self._port.setDTR(True) self.sync()
self._port.setRTS(False) self._port.timeout = 5
time.sleep(0.3) return
self._port.setDTR(True) except:
time.sleep(0.05)
self._port.timeout = 0.5 # this is a workaround for the CH340 serial driver on current versions of Linux,
for i in xrange(10): # which seems to sometimes set the serial port up with wrong parameters
try: self._port.close()
self._port.flushInput() self._port.open()
self._port.flushOutput()
self.sync()
self._port.timeout = 5
return
except:
time.sleep(0.1)
raise Exception('Failed to connect') raise Exception('Failed to connect')
""" Read memory address in target """ """ Read memory address in target """
...@@ -268,6 +262,15 @@ class ESPROM: ...@@ -268,6 +262,15 @@ class ESPROM:
return data return data
""" Abuse the loader protocol to force flash to be left in write mode """
def flash_unlock_dio(self):
# Enable flash write mode
self.flash_begin(0, 0)
# Reset the chip rather than call flash_finish(), which would have
# write protected the chip again (why oh why does it do that?!)
self.mem_begin(0,0,0,0x40100000)
self.mem_finish(0x40000080)
""" Perform a chip erase of SPI flash """ """ Perform a chip erase of SPI flash """
def flash_erase(self): def flash_erase(self):
# Trick ROM to initialize SFlash # Trick ROM to initialize SFlash
...@@ -360,6 +363,20 @@ class ELFFile: ...@@ -360,6 +363,20 @@ class ELFFile:
self._fetch_symbols() self._fetch_symbols()
return self.symbols[sym] return self.symbols[sym]
def get_entry_point(self):
tool_readelf = "xtensa-lx106-elf-readelf"
if os.getenv('XTENSA_CORE')=='lx106':
tool_objcopy = "xt-readelf"
try:
proc = subprocess.Popen([tool_readelf, "-h", self.name], stdout=subprocess.PIPE)
except OSError:
print "Error calling "+tool_nm+", do you have Xtensa toolchain in PATH?"
sys.exit(1)
for l in proc.stdout:
fields = l.strip().split()
if fields[0] == "Entry":
return int(fields[3], 0);
def load_section(self, section): def load_section(self, section):
tool_objcopy = "xtensa-lx106-elf-objcopy" tool_objcopy = "xtensa-lx106-elf-objcopy"
if os.getenv('XTENSA_CORE')=='lx106': if os.getenv('XTENSA_CORE')=='lx106':
...@@ -552,7 +569,10 @@ if __name__ == '__main__': ...@@ -552,7 +569,10 @@ if __name__ == '__main__':
seq += 1 seq += 1
print print
print '\nLeaving...' print '\nLeaving...'
esp.flash_finish(False) if args.flash_mode == 'dio':
esp.flash_unlock_dio()
else:
esp.flash_finish(False)
elif args.operation == 'run': elif args.operation == 'run':
esp.run() esp.run()
...@@ -586,7 +606,7 @@ if __name__ == '__main__': ...@@ -586,7 +606,7 @@ if __name__ == '__main__':
args.output = args.input + '-' args.output = args.input + '-'
e = ELFFile(args.input) e = ELFFile(args.input)
image = ESPFirmwareImage() image = ESPFirmwareImage()
image.entrypoint = e.get_symbol_addr("call_user_start") image.entrypoint = e.get_entry_point()
for section, start in ((".text", "_text_start"), (".data", "_data_start"), (".rodata", "_rodata_start")): for section, start in ((".text", "_text_start"), (".data", "_data_start"), (".rodata", "_rodata_start")):
data = e.load_section(section) data = e.load_section(section)
image.add_segment(e.get_symbol_addr(start), data) image.add_segment(e.get_symbol_addr(start), data)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment