portable.h: Remove broken check for __FUNCTION__

Since the macro is only defined /inside/ a function, this
check could never work.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Do not return from function before free'ing

At least on normal exit.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Move DfuSe options handling into dfuse.c

This will allow us to extend the DfuSe support with modifiers
and subcommands without introducing new command line switches
or handling of this in the main code.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Add upload length modifier to --dfuse-address option

The default is to upload to the end of the memory segment,
or just 16KB if the start address is unknown.

Now a length can be added after the address, separated by a colon,
for instance to upload just 4KB:
 dfu-util -U file --dfuse-address 0x08003000:4096

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Support arbitrary upload lengths

Not only multiples of transfer size.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Add "force" modifier

The "force" modifier can be added to the --dfuse-address
argument, separated by a colon.

It is meant as an expert option, and its use and abuse can
cause all kinds of trouble, brick your device, etc.

For now, it allows uploading from a memory location not
advertised in the memory map. The bootloader may or may not
deal with this.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Add support for sending DFU_LEAVE request

The "leave" modifier can be added to the --dfuse-address
argument, separated by a colon.

It tells dfu-util to send a DFU_LEAVE request after
downloading/uploading, which is meant to cause the device
to leave DFU mode and start the normal application, often
by resetting itself.

DFU Leave operation is described in ST document AN3156 section 5.5.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Add support for Read Unprotect command

Thanks to Uwe Bonnes for writing an initial patch.

The command is described in ST document AN3156 section 5.4

The "unprotect" modifier can be added to the --dfuse-address argument,
separated by a colon. Since this command will erase the whole flash
memory, it must be combined with the "force" option to take effect.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Add support for Mass Erase command

The "mass-erase" modifier can be added to the --dfuse-address argument,
separated by a colon. Since this command will erase the whole flash
memory, it must be combined with the "force" modifier to take effect.

The command is described in ST document AN3156 section 5.3

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfuse: Skip page erases when downloading after a mass erase

If we have performed a mass erase of the device, we do not
need to erase each page before writing to it during a
following download.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfu-suffix: Add, remove and check TI Stellaris DFU prefix

Add functionality to add, remove and check TI Stellaris DFU prefix using
the dfu-suffix tool. The TI Stellaris bootloader expects to have an 8
byte prefix at the beginning of the binary image. The patch adds an
option -s --stellaris-address to dfu-suffix for adding this prefix (in
combination with -a --add).

When adding (-a) prefix (and suffix), the -s option requires an address
as an argument. To delete the prefix use both -D and -T options. If -D
alone is used on a Stellaris prefixed file, only the suffix gets
removed. Use -D again with -T option to delete the prefix.

To check for TI Stellaris prefix use -c combined with the -T option.

Examples:

To add DFU suffix and prefix use:
dfu-suffix -s 0x2000 -v 0x1cbe -p 0x00ff -d 0x0000 -a image.bin

To remove DFU suffix and prefix use:
dfu-suffix -T -D image.bin

To check DFU suffix use:
dfu-suffix -T -c image.bin

Signed-off-by: Tommi Keisala <tommi.keisala@ray.fi>