Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked bootloader code #2

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open

Conversation

nekromant
Copy link

This is my total rework of dfu bootloder code, that might be userful for you.
Most of the 'revolutionary' things are now done, everything should be stable now.

In short, what's changed:
Moved hardware dependant code, easy to add new boards, each can have it's own set of descriptors and start address.
Overall fixes - now works when compiled with -Os, binary as small as 5-6KiB (depending on the feature set)
Tuned dfu poll delays - uploads 80KiB in 3 instead of 20 seconds.
Xilinx Bitbang Serial Uploader driver (yet to be added to mcortex board as an example)
Now easy to add new dfu targets, e.g. fpgas, external memories etc.
Buildsystem: pretty output, support for multiple boards to build in batch, smaller Makefile
Extra RUNAPP altsetting that can be enabled via per-board config - any upload to it results in immediate code execution

I'm still working on getting DFU Upload code running, and adding the SPI flash driver, will send a pull request later.
Regards, Andrew

@poslathian
Copy link
Member

Thanks for the great patch. We will take a look, looks like a ton of great stuff!

Thanks,
Andrew

On Jun 5, 2012, at 4:54 PM, nekromant wrote:

This is my total rework of dfu bootloder code, that might be userful for you.
Most of the 'revolutionary' things are now done, everything should be stable now.

In short, what's changed:
Moved hardware dependant code, easy to add new boards, each can have it's own set of descriptors and start address.
Overall fixes - now works when compiled with -Os, binary as small as 5-6KiB (depending on the feature set)
Tuned dfu poll delays - uploads 80KiB in 3 instead of 20 seconds.
Xilinx Bitbang Serial Uploader driver (yet to be added to mcortex board as an example)
Now easy to add new dfu targets, e.g. fpgas, external memories etc.
Buildsystem: pretty output, support for multiple boards to build in batch, smaller Makefile
Extra RUNAPP altsetting that can be enabled via per-board config - any upload to it results in immediate code execution

I'm still working on getting DFU Upload code running, and adding the SPI flash driver, will send a pull request later.
Regards, Andrew

You can merge this Pull Request by running:

git pull https://github.com/nekromant/maple-bootloader master

Or you can view, comment on it, or merge it online at:

#2

-- Commit Summary --

  • initial commit a fully reworked project structure
  • moved usb_descriptors to per-board config, adjusted params.
  • minor fixes and cleanups
  • added config option to strip usb suspend/resume code
  • Set default options to -Os and no debug. Result is ~5.9KiB.
  • Fixed maple target to compile (Not tested!)
  • shut up another warning
  • added README and TODO
  • added missing usb_descriptor for maple target
  • Additions to TODO
  • shut up the last warnings from usb_regs.h
  • Changed color scheme a little bit
  • Added README.porting
  • added myself to CREDITS
  • Update TODO
  • Made a bunch of vars volatile to work properly with -Os
  • Added RUNAPP_ALT hack, see README.porting for details
  • fixed typo
  • wrapped bootloaderExitCondition in #ifdef's
  • uncommented some quite critical code.
  • implemented optional INFO endpoint support
  • include config.h in usb.c
  • te-stm32f103ret6kit: fix usb descriptors
  • Added initial stuff for Motor Cortex Board
  • added GPIOG definition
  • move FLASH_PAGE_SIZE to boardconfig
  • Fixed TODO/README added stubs for DFU refactor
  • Moved IO routines to dfu_io.c, broken config for all boards
  • fixed board configs to reflect recent dfu.c changes
  • Fixed FLASH_PAGE_SIZE for maple, added MAPLE RET6 dummy. UNTESTED!!!
  • Fixed typo in configs
  • dfu: fixed errors in dfu_io
  • fixed README
  • Added a small dev README
  • Initial stubs for dfu upload functionality
  • Do an NVIC_SetVectorTable before jump
  • Added xilinx sscu driver
  • Added licencse stuff to xsscu. Let it be MIT
  • Fixed flash corruption on copy
  • Special commit with steroid and coffeine - dfu now works 10 times faster!
  • mcortex: Fix USB disconnection handling

-- File Changes --

M CREDITS (4)
M Makefile (331)
A Makefile.old (249)
M README (66)
A README.dev (24)
A README.old (38)
A README.porting (50)
A TODO (10)
A boards/maple-ret6/Makefile (1)
A boards/maple-ret6/board.c (100)
A boards/maple-ret6/config.h (88)
R boards/maple-ret6/usb_descriptor.c (4)
A boards/maple/Makefile (1)
A boards/maple/board.c (100)
A boards/maple/config.h (88)
A boards/maple/usb_descriptor.c (206)
A boards/mcortex/Makefile (2)
A boards/mcortex/board.c (75)
A boards/mcortex/config.h (95)
A boards/mcortex/usb_descriptor.c (223)
A boards/te-stm32f103ret6kit/Makefile (2)
A boards/te-stm32f103ret6kit/board.c (103)
A boards/te-stm32f103ret6kit/config.h (92)
A boards/te-stm32f103ret6kit/usb_descriptor.c (228)
D dfu.c (372)
D hardware.c (304)
A src/Makefile (1)
A src/common/Makefile (8)
A src/common/common.h (0)
A src/common/dfu.c (359)
R src/common/dfu.h (2)
A src/common/dfu_io.c (101)
A src/common/hardware.c (250)
R src/common/hardware.h (29)
R src/common/main.c (65)
R src/common/usb.c (61)
R src/common/usb.h (14)
A src/common/usb_callbacks.c (0)
R src/common/usb_descriptor.h (5)
A src/common/xsscu.c (72)
R src/common/xsscu.h (45)
A src/startup/Makefile (2)
R src/startup/c_only_md.ld (2)
A src/startup/c_only_md_RAM.ld (0)
A src/startup/c_only_startup.s (0)
A src/startup/c_only_startup_user.s (0)
A src/startup/cortexm3_macro.h (0)
A src/startup/cortexm3_macro.s (0)
A src/startup/stm32f10x_type.h (0)
A src/usb_lib/Makefile (7)
A src/usb_lib/usb_conf.h (0)
A src/usb_lib/usb_core.c (0)
A src/usb_lib/usb_core.h (0)
A src/usb_lib/usb_def.h (0)
A src/usb_lib/usb_init.c (0)
A src/usb_lib/usb_init.h (0)
A src/usb_lib/usb_int.c (0)
A src/usb_lib/usb_int.h (0)
A src/usb_lib/usb_lib.h (0)
A src/usb_lib/usb_mem.c (0)
A src/usb_lib/usb_mem.h (0)
A src/usb_lib/usb_regs.c (0)
R src/usb_lib/usb_regs.h (6)
A src/usb_lib/usb_type.h (0)

-- Patch Links --

https://github.com/leaflabs/maple-bootloader/pull/2.patch
https://github.com/leaflabs/maple-bootloader/pull/2.diff


Reply to this email directly or view it on GitHub:
#2

@mbolivar
Copy link
Contributor

mbolivar commented Jun 6, 2012

Yes, thank you very much. I look forward to reading your patches and getting them merged.

@nekromant
Copy link
Author

Yes, and please, do double-test the board-specific code against maple targets if you can. I have no maple or maple-clone boards around, so I can't test these. Thanks. Only te-stm32f103ret6kit and mcortex targets are well-tested. The first one is a dev board from terra-electronica.ru ( http://www.terraelectronica.ru/catalog_info.php?ID=1001&CODE=333824 sorry, it's in russian, schematics here: http://www.terraelectronica.ru/files/modules/te-stm32f103/te-stm32f103_red_v100.pdf ). The other one is a huge board of our own design, with no schematics yet published. Some early photos here: http://pics.ncrmnt.org/junk/motor-cortex/ )
In general it 'should' work for maple targets, since board init code is mostly copy-paste, but it might need extra polish to work as expected.

@mbolivar
Copy link
Contributor

mbolivar commented Jun 7, 2012

Hey, I see Xilinx FPGAs in those early photos! Cool. Are you using FSMC for STM32<->FPGA communication? That's our plan for Oak.

Thanks for the heads-up re: testing. We'll make sure to try out your code on all of our boards, and I'll send a heads-up to the maintainers of non-LeafLabs boards that have support in the LeafLabs libmaple tree that they should test things as well.

@nekromant
Copy link
Author

Yeah, it's FSMC. 8-bits of data and about 14 bits of address + an extra interrupt line, that is expanded into a bunch of software interrupts, depending on what happened in the FPGA. The config is downloaded in slave serial mode (right now) via xmodem to the fpga or from SPI flash attached to STM32. I now want to use DFU for that. This allows dynamic FPGA reconfig at runtime. Bitbanging config takes about a second for xc3s100e-tq144. Basically, my xsscu stuff is a port to bare metal of my linux kernel driver that does the same stuff: http://ncrmnt.org/wp/2011/11/18/configuring-a-xilinx-fpga-from-arm/
FPGA is clocked async of STM32, via 12M oscillator, and runs that 12Mhz, since I screwed up clock routing dcm will not lock. Hopefully I'll get the second iteration of the board with all the remaining bugs fixed later this month.
EDIT: Just uploaded a bunch more pics of the board.

Andrew 'Necromant' Andrianov and others added 25 commits June 8, 2012 14:52
This is the first patch in series.

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
TE board works, maple is broken.
Also fixes lots of compiler warnings.

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Result is ~5.9KiB.

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Add coloring support to Makefile

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
The dfu state machine locks and globals get called in ISR,
hence must be volatile. If not, we are screwed.

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Looks useless, unless I can get upload code to work

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
te-stm32f103ret6kit: Fix usb descriptors
maple: fix config.h to reflect recent core changes

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
nekromant and others added 30 commits June 8, 2012 14:52
No example usages, yet

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Fix flash corruption on copy
Add blinks before jump
Fix formatting of hardware.c

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
dfu now works 10 times faster!

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Results: ~20KiloBytes/s when downloading to flash

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Flash writing speed is now the bottleneck
Implemented DUMMY altsetting for USB performance testing.
Results: 490k in 8 secs => ~61Kilobyte/sec.
Looks like the max we can get here.

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
It screws up ST's SysTickConfig() routine if using stock libs
Needs more testing

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
This reverts commit bcf9376.
That was a bad idea.

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Doing so screws all interrupts in the user app.

Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Signed-off-by: Andrew 'Necromant' Andrianov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants