Wykres commitów

154 Commity (master)

Autor SHA1 Wiadomość Data
Damien George a7d34b6f7c stm32/mboot: Buffer the correct amount of bytes for a flash write.
Different MCUs have different requirements for the minimum number of bytes
that can be written to internal flash.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-01 22:49:38 +10:00
Damien George 9651046edd stm32/mboot: Add support for a raw filesystem.
This is enabled by default if MBOOT_FSLOAD is enabled, although a board
can explicitly disable it by `#define MBOOT_VFS_RAW (0)`.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 11:38:36 +11:00
Angus Gratton decf8e6a8b all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a.  The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.

This STATIC feature is rarely (if ever) used.  And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.

So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing.  For example, newcomers don't have
to learn what the STATIC macro is and why it exists.  Reading the code is
also less "loud" with a lowercase static.

One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.

Methodology for this commit was:

1) git ls-files | egrep '\.[ch]$' | \
   xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"

2) Do some manual cleanup in the diff by searching for the word STATIC in
   comments and changing those back.

3) "git-grep STATIC docs/", manually fixed those cases.

4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-07 14:20:42 +11:00
Damien George 802a88c3b1 stm32/mboot: Generate FLASH_LAYOUT_STR at runtime on H5 MCUs.
The size of the flash varies among MCU variants.  Instead of requiring a
build-time variable to configure this, compute it at runtime using the
special device information word accessible through the FLASH_SIZE macro.

This feature is currently only implemented for H5 MCUs, but can be extended
to others.

Signed-off-by: Damien George <damien@micropython.org>
2024-02-20 12:32:45 +11:00
Damien George 982ffdee7e stm32/mboot/Makefile: Revert change to BOARD_DIR that removed abspath.
This reverts the change from ce2058685b.

Without abspath, the build artefacts (object files) for boards with source
files are placed outside the build directory, because the BOARD_DIR
variable starts with "..".  For the list of source files added to SRC_C,
none of them can start with "..".  The usual fix for that would be to make
the files relative to the top of the MicroPython repo (because of the vpath
rule), eg ports/stm32/boards/$(BOARD).  But then the $(wildcard ...)
pattern won't find files in this directory.

So abspath is necessary, although it will prevent building when there is a
space in the path.  A better solution for spaces needs to be found.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-25 11:30:14 +11:00
Iksas ce2058685b ports: Fix handling of paths containing spaces in Makefiles.
Make can't handle paths with spaces, see https://savannah.gnu.org/bugs/?712

The following workarounds exist:

- When using make's built-in functions:
    - Use relative paths wherever possible to avoid spaces in the first
      place.
    - All spaces in paths can be escaped with backslashes; quotes don't
      work.
    - Some users use the shell to temporarily rename directories, or to
      create symlinks without spaces.

- When using make to pass commands to the system's shell, enclose paths in
  quotes.  While make will still interpret quoted strings with spaces as
  multiple words, the system's shell will correctly parse the resulting
  command.

This commit contains the following fixes:

- In ports/stm32/mboot/Makefile: Use relative paths to avoid spaces when
  using built-in functions.

- In all other files: Use quotes to enclose paths when make is used to call
  shell functions.

All changes have been tested with a directory containing spaces.

Signed-off-by: Iksas <iksas@mailbox.org>
2024-01-24 10:43:18 +11:00
Damien George b6ab9e420b stm32/flash: Change flash_erase to only erase a single sector at a time.
An erase sector sits in a given flash bank and some MCUs have two flash
banks.  If trying to erase a range of sectors and that range crosses from
one flash bank into the next, the original implementation of
`flash_erase()` would not handle this case and would do the wrong thing.

This commit changes `flash_erase()` to only erase a single sector, which
sidesteps the need to handle flash-bank-crossing.  Most callers of this
function only need to erase a single sector anyway.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:33:34 +11:00
Damien George 7002a19be2 stm32/mboot: Improve mass erase to erase all non-protected pages.
Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:29:19 +11:00
Damien George b7b99522e4 stm32/mboot: Improve detection of invalid flash erase/write.
This commit replaces the linker symbol `_mboot_writable_flash_start` with
`_mboot_protected_flash_start` and `_mboot_protected_flash_end_exclusive`,
to provide better configuration of the protected flash area.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-08 12:22:55 +11:00
Damien George e9bcd49b3e stm32/mboot: Add support for Microsoft WCID.
This adds support to stm32's mboot for the Microsoft WCID USB 0xee string
and Compatible ID Feature Descriptor.  This allows the USB device to
automatically set the default USB driver, so that when the device is
plugged in Windows will assign the winusb driver to it.  This means that
USB DFU mode can be used without installing any drivers.

For example this page will work (allow the board to be updated over DFU)
with zero install: https://devanlai.github.io/webdfu/dfu-util/

Tested on Windows 10, Windows can read the 0xee string correctly, and
requests the second special descriptor, which then configures the USB
device to use the winusb driver.

Signed-off-by: Damien George <damien@micropython.org>
2023-12-20 19:40:03 +11:00
Damien George 49d0c22b11 stm32/mboot: Expand device descriptor to make it easier to understand.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-20 19:31:15 +11:00
Damien George 859f219690 stm32/mboot: Guard use of tx_pending with USE_USB_POLLING option.
Signed-off-by: Damien George <damien@micropython.org>
2023-12-20 17:25:57 +11:00
Jim Mussared 9cabee8252 ports: Standardise arguments and output for make-pins.py script.
All ports now use `--board-csv`, `--prefix`, `--output-souce`,
`--output-header` and no longer write to stdout.  This matches the esp32
implementation.

Ports that have an AF input use `--af-csv` (to match `--board-csv`).

Any additional output files are now prefixed with `output-` (e.g.
`--output-af-const`).

Default arguments are removed (all makefiles should always specify all
arguments, using default values is likely an error).

Replaced the `af-defs-cmp-strings` and `hdr-obj-decls` args for stm32 with
just `mboot-mode`.  Previously they were set on the regular build, now the
logic is reversed so mboot sets it.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 14:04:35 +11:00
Jim Mussared 59f3c7facb examples/pins.py: Remove this pins printing example.
It's not supported on all ports, adds complexity to the build to generate
pins_af.py, and can mostly be replicated just by printing the pin objects.

Remove support for generating pins_af.py from all ports (nrf, stm32,
renesas-ra, mimxrt, rp2).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 14:03:28 +11:00
Jim Mussared fc54d25a45 stm32/boards/make-pins.py: Don't generate qstrs.
Qstrs are picked up from the generated pin source files in the usual qstr
processing stage.

Similarly for the stm constant qstrs.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 13:59:19 +11:00
Damien George 95d8b5fd55 extmod/machine_adc: Factor ports' ADC Python bindings to common code.
No functional change, just code factoring to have the Python bindings in
one location, and all the ports use those same bindings.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-23 17:16:45 +11:00
Oliver Joos a175f98a65 stm32/mboot: Fix fwupdate by replacing zlib with new deflate module.
Since commit 3533924c36 the zlib module has
been replaced by the new deflate module.  This commit updates the script
fwupdate.py to use the new deflate module.

Signed-off-by: Oliver Joos <oliver.joos@hispeed.ch>
2023-09-01 12:39:06 +10:00
Jim Mussared e6c290c3d1 lib/uzlib: Add a source_read_data var to pass to source_read_cb.
For better abstraction for users of this API.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:34 +10:00
Jim Mussared d75a3cd861 lib/uzlib: Combine zlib/gzip header parsing to allow auto-detect.
This supports `wbits` values between +40 to +47.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:34 +10:00
Jim Mussared c2b8e6e5d6 lib/uzlib: Clean up tinf -> uzlib rename.
This library used a mix of "tinf" and "uzlib" to refer to itself.  Remove
all use of "tinf" in the public API.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21 19:29:24 +10:00
Damien George 61339aa506 stm32: Add initial support for H5 MCUs.
This commit adds initial support for STM32H5xx MCUs.  The following
features have been confirmed to be working on an STM32H573:
- UART over REPL and USB CDC
- USB CDC and MSC
- internal flash filesystem
- machine.Pin
- machine.SPI transfers with DMA
- machine.ADC
- machine.RTC
- pyb.LED
- pyb.Switch
- pyb.rng
- mboot

Signed-off-by: Damien George <damien@micropython.org>
2023-06-15 11:09:20 +10:00
Jim Mussared 5fd042e7d1 all: Replace all uses of umodule in Python code.
Applies to drivers/examples/extmod/port-modules/tools.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Andrew Leech f03ac04321 stm32/mboot: Fix alignment of packed final buffer.
Once all the firmware has been flashed and the final signatures checked,
mboot writes the "all good" byte into the header of the application.  This
step uses the buffer firmware_head which, if unaligned in the build, fails
when cast to a uint64_t* in flash.c.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2023-05-19 22:16:53 +10:00
Christian Clauss 2a1db770ce all: Fix cases of Python variable assigned but never used.
This fixes ruff rule F841.
2023-05-02 16:36:05 +10:00
Damien George b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Damien George 31638473b7 stm32/mboot: Add support for G0 MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2023-03-22 16:38:03 +11:00
Damien George 8b3f1d47a6 stm32/powerctrlboot: Provide custom SystemInit for WB55.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Damien George <damien@micropython.org>
2023-03-08 14:04:14 +11:00
Jim Mussared 69b93527d5 ports: Make BOARD default from BOARD_DIR in Makefile's.
This allows:

    $ make BOARD_DIR=path/to/board

to infer BOARD=board, rather than the previous behavior that required
additionally setting BOARD explicitly.

Also makes the same change for VARIANT_DIR -> VARIANT on Unix.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2023-02-23 09:47:08 +11:00
Damien George 771c16f3d9 stm32/mboot: Make all mboot sectors erase/write protected.
Prior to this commit, only sector 0 was erase/write protected, which may
not be enough to protect all of mboot (especially if mboot lives at a
higher address than the start of flash).

This commit makes sure all internal flash sectors that mboot lives in are
protected from erasing and writing.  The linker script must define
_mboot_writable_flash_start for this to work.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-30 17:19:36 +11:00
Jim Mussared d6d8722558 extmod: Make extmod.mk self-contained.
This makes it so that all a port needs to do is set the relevant variables
and "include extmod.mk" and doesn't need to worry about adding anything to
OBJ, CFLAGS, SRC_QSTR, etc.

Make all extmod variables (src, flags, etc) private to extmod.mk.

Also move common/shared, extmod-related fragments (e.g. wiznet, cyw43,
bluetooth) into extmod.mk.

Now that SRC_MOD, CFLAGS_MOD, CXXFLAGS_MOD are unused by both extmod.mk
(and user-C-modules in a previous commit), remove all uses of them from
port makefiles.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:31:49 +11:00
Jim Mussared 17f2783e4a all: Use += rather than = everywhere for CFLAGS/LDFLAGS/LIBS.
This avoids a surprise where an = can cancel out an earlier +=.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:17:41 +11:00
David Lechner fc3d7ae11b py/make_root_pointers: Add MP_REGISTER_ROOT_POINTER parser/generator.
This adds new compile-time infrastructure to parse source code files for
`MP_REGISTER_ROOT_POINTER()` and generates a new `root_pointers.h` header
file containing the collected declarations.  This works the same as the
existing `MP_REGISTER_MODULE()` feature.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:48:23 +10:00
Damien George d27e58449b stm32/mboot: Remove redundant code in mboot_state_change function.
This code was made redundant in 87fbceef26

Signed-off-by: Damien George <damien@micropython.org>
2022-07-05 23:47:54 +10:00
Damien George 096954337f stm32/mboot: Only include UI code if at least one board LED is defined.
Otherwise the board must provide dummy definitions of MBOOT_LED1.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-16 14:31:09 +10:00
Damien George 45a0c6da5b stm32/mboot: Remove MP_WEAK on led funcs and make some of them static.
Both led_init and led_state are configurable via MBOOT_BOARD_LED_INIT and
MBOOT_BOARD_LED_STATE respectively, so don't need to be MP_WEAK.

Furthermore, led_state and led0_state are private to ui.c so can be made
static.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-09 13:24:08 +10:00
Damien George bd5152c928 stm32/mboot: Add board-configurable SysTick hook.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-09 13:24:08 +10:00
Damien George 87fbceef26 stm32/mboot: Pass initial_r0 to early-init and get-reset-mode funcs.
This allows a board to modify initial_r0 if needed.

Also make default board behaviour functions always available, named as
mboot_get_reset_mode_default and mboot_state_change_default.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 14:30:51 +10:00
Damien George e64947dc90 stm32/mboot: Make 0x70ad0000 values named constants with macros.
Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 14:30:51 +10:00
Damien George 9246099935 stm32/mboot: Add update_app_elements to return mboot fsload elements.
In case the elements should not be passed directly to machine.bootloader.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 14:30:51 +10:00
Damien George 1296a01f4c stm32/mboot: Move remaining led_state_all call into mboot_state_change.
This was missed in b2deea6762

Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 14:30:51 +10:00
Damien George 5c32111fa0 ports: Reformat more C and Python source code.
These files that are reformatted only now fall under the list of files to
apply uncrustify/black formatting to.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-20 16:17:35 +10:00
Damien George cb0372b5bf stm32/mboot: Add macros for use in led_state_all().
Signed-off-by: Damien George <damien@micropython.org>
2022-04-11 15:52:41 +10:00
Damien George b2deea6762 stm32/mboot: Consolidate all UI and add general state change hooks.
All user interface (LED, button) code has been moved to ui.c, and the
interface to this code with the rest of the system now goes through calls
to mboot_state_change().  This state-change function can be overridden by a
board to fully customise the user interface behaviour.

Signed-off-by: Damien George <damien@micropython.org>
2022-04-11 15:52:41 +10:00
Andrew Leech bb0ca00b77 stm32/mboot: Verify CRC32 of fsload DFU files before writing. 2022-03-22 15:04:41 +11:00
Andrew Leech bc856a1e29 stm32/mboot: Verify signature of fsload packed DFU files before writing.
When verifying the DFU contents, the signature of signed/encrypted files is
also now checked in this initial, dry-run stage.
2022-03-22 15:04:37 +11:00
Damien George 80055c2cdc stm32/mboot/fwupdate.py: Simplify calculation of CRC32.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 14:14:31 +11:00
Damien George e316306546 stm32/mboot: Add support for reading from SD card.
Tested on PYBV10 and PYBD_SF6, with MBOOT_FSLOAD enabled and programming
new firmware from a .dfu.gz file stored on the SD card.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 13:33:43 +11:00
Damien George 9b07d38c7e stm32/mboot: Add support for 64-bit mboot address space for reads.
If enabled via MBOOT_ADDRESS_SPACE_64BIT (it's disabled by default) then
read addresses will be 64-bit.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 13:33:43 +11:00
Damien George a92d45c3df stm32/mboot: Always check the magic number to enter filesystem loading.
Even if MBOOT_FSLOAD is disabled, mboot should still check for 0x70ad0080
so it can immediately return to the application if this feature is not
enabled.  Otherwise mboot will get stuck in DFU mode.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:49:00 +11:00
Damien George dc91024a73 stm32/mboot: Add pragma for GCC to ignore array bounds warning.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:44:10 +11:00