Git Product home page Git Product logo

arduino-stk500v2-bootloader's Introduction

arduino-stk500v2-bootloader's People

Contributors

msproul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

arduino-stk500v2-bootloader's Issues

bootloader not erasing all usable flash on atmega2560

On a atmega2560 the usable flash is meant to be 256k-8k bootloader. Ie 0-0x3E000 (253952 bytes.) but in the code is

#if FLASHEND > 0x0F000
	#define BOOTSIZE 8192
#else
	#define BOOTSIZE 2048
#endif

#define APP_END  (FLASHEND -(2*BOOTSIZE) + 1)

FLASHEND is 0x3FFFF on mega2560's so the the BOOTSIZE is set to 8192, but the APP_END is set to (0x3FFFF - (2*0x2000)) + 1 = 0x3C000

The code then uses "if (eraseAddress < APP_END )" so uploading over serial will only erase bytes from 0x00000 to 0x3C000. So 0x3C000--0x3E000 is not erased and can't be reused till a full erase is done.

This has been causing headaches for years.

EEPROM progamming starting at addresses other than zero...

It looks (form code inspection) like the "load address" command left-shifts the provided address (assuming a word address for flash programming), but the Write EEPROM code doesn't shift that back, which should cause EEPROM programming that starts at any location other than zero to end up in the wrong place.

USBASP could not set SCK

Hi, I got a warning: cannot set sck period. please check for usbasp firmware update.
Yet, it seems like other upload logs are fine as attached.

$ avrdude -p atmega2560 -c usbasp -P /dev/ttyUSB0 -B 115200 -e -u -Ulock:w:0x3f:m -U flash:w:./stk500boot_v2_mega2560.hex -Ulock:w:0x0F:m

avrdude: set SCK frequency to 0 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9801
avrdude: erasing chip
avrdude: set SCK frequency to 0 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3f:
avrdude: load data lock data from input file 0x3f:
avrdude: input file 0x3f contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "./stk500boot_v2_mega2560.hex"
avrdude: input file ./stk500boot_v2_mega2560.hex auto detected as Intel Hex
avrdude: writing flash (255720 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 255720 bytes of flash written
avrdude: verifying flash memory against ./stk500boot_v2_mega2560.hex:
avrdude: load data flash data from input file ./stk500boot_v2_mega2560.hex:
avrdude: input file ./stk500boot_v2_mega2560.hex auto detected as Intel Hex
avrdude: input file ./stk500boot_v2_mega2560.hex contains 255720 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 255720 bytes of flash verified
avrdude: reading input file "0x0F"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0F:
avrdude: load data lock data from input file 0x0F:
avrdude: input file 0x0F contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lock verified

avrdude done.  Thank you.

When I try to upload sketch or dump flash, it showed up as nothing is uploaded:

wenhui-2:Compile WenhuiZhang$ avrdude -p atmega2560 -c usbasp -P /dev/ttyUSB0 -c usbasp -t

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9801
avrdude> dump 
>>> dump 
Usage: dump <memtype> [<addr> <len>]
avrdude> dump flash 
>>> dump flash 
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> dump flash 0x3eff
>>> dump flash 0x3eff 
Usage: dump <memtype> [<addr> <len>]
avrdude> dump flash 0x3eff 100
>>> dump flash 0x3eff 100 
3eff  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
3f0f  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
3f1f  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
3f2f  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
3f3f  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
3f4f  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
3f5f  ff ff ff ff  

stk500v2 always erases starting address zero

On lines 517/518, both address and eraseAddress are set to zero:

https://github.com/msproul/Arduino-stk500v2-bootloader/blob/master/stk500boot.c#L517

When we get a CMD_CHIP_ERASE_ISP, eraseAddress is reset to zero (properly):

https://github.com/msproul/Arduino-stk500v2-bootloader/blob/master/stk500boot.c#L903

When we get either a CMD_PROGRAM_FLASH_ISP or a CMD_PROGRAM_EEPROM_ISP, both address and eraseAddress will be zero.

https://github.com/msproul/Arduino-stk500v2-bootloader/blob/master/stk500boot.c#L919

This is, I would argue, incorrect behavior. Not all programs are uploaded to location zero. We specifically encountered this in our work with a small virtual machine (http://concurrency.cc/), where we upload the VM to address zero, and then upload the bytecode somewhere else in flash separately. This way, users can upload the VM once (~20K), and upload new programs (bytecode) many times without having to reflash the VM every time.

On the 168, 328, and 1280 everything has (in the past) worked fine. With the introduction of the 2560, our bytecode started clobbering the VM from address zero, despite providing location information to avrdude. We believe that the problem is in the bootloader. It seems like the bootloader puts the bytecode at the correct location (having extracted 'address' properly), but 'eraseAddress' remains initialized to zero, and therefore blocks are erased starting from address zero, while our bytecode is written into the correct location. Thus, the VM gets destroyed in the process of uploading bytecode.

I had a patch started, but do not have an ISP that works reliably on the Mac. If someone tells me what ISP to buy, I'll work on a patch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.