Merge pull request #32 from ptesarik/bootloader

bootloader improvements
unplugged_action updated to work reliably with the latest power saving changes.
Merge branch 'master' of github.com:dhiltonp/hexbright
bootloader: use length as counter for PROG_PAGE and READ_PAGE

One would think that this kind of optimization is done automatically
by GCC, but this commit actually reduces code size of the Hexbright
Tinyboot by 12 bytes...

Or, maybe the difference is caused by using a different comparison
type (equality instead of less-than).
bootloader: use C code to set SREG and SP

There's no need to use inline assembly to set these two registers.
C code is easier understood and less prone to errors.
bootloader: put load_address in its own function

No code change, but easier to read both main() and load_address().
bootloader: fix data initialization for non-LPMX

The substitution was %[ptr] instead of the correct %[lptr].
I also replaced the explicit "X" and "Z" with a substitution, so
it's easier to spot such mistakes.
bootloader: error if terminator is not received after READ_PAGE

If the READ_PAGE command is not terminated by Sync_CRC_EOP, treat it
as an error.

This looks like an omission, because all other command call error in
such case.
bootloader: re-implement app_start() as an inline function

This function pointer is constant (always a jump to location 0), but
it is implemented by gcc as an indirect call, which needs two "ldi"
instructions and one "icall" instruction. But it is possible to
implement this as one "jmp" instruction.

Note that after this change, getch() is considered small enough to be
inlined, but that would increase the bootloader size, so inlining
getch() mustd be disabled explicitly.
bootloader: move sync checking to its own function

No code change, but the check for sync is no longer scattered around
the code.
bootloader: send Resp_STK_NOSYNC when out of sync

Follow the stk500 specification if Sync_CRC_EOP is not received when
it is expected and send back Resp_STK_NOSYNC.
bootloader: send Resp_STK_UNKNOWN on unknown commands

The STK500 protocol says that the programmer should respond with
Resp_STK_UNKNOWN when a command is not recognized.
bootloader: prevent inlining putch()

This function is small enough to be inlined, but even then it
increases code size above 1k for hexbright_tiny. The size is OK
without inlining.
bootloader: advertise support for auto-increment

Now that the auto-increment feature is fixed, we can confirm the
corresponding command.
bootloader: NO_DATA/NO_BSS instead of HAVE_DATA/HAVE_BSS

The use of -U in DEFS= is confusing, and it makes it harder to specify
special defines for targets that don't care about the DATA/BSS
optimisation.

Turn on this special optimisation explicitly when needed.
bootloader: indicate upload/download

Turn on the green LED while reading memory. Turn on the red LED while
writing memory. Since the LED is turned on only during the block
operation, it flickers a bit during upload/download operations, giving
the user nice feedback on the progress.
Merge branch 'master' of github.com:dhiltonp/hexbright into bootloader
bootloader: update hex files for convenience

Tested again on my Hexbright.