micropython/docs/reference
Alessandro Gatti a6bc1ccbe5 py/persistentcode: Add architecture flags compatibility checks.
This commit extends the MPY file format in a backwards-compatible way to
store an encoded form of architecture-specific flags that have been
specified in the "mpy-cross" command line, or that have been explicitly
set as part of a native emitter configuration.

The file format changes are as follows:

* The features byte, previously containing the target native
  architecture and the minor file format version, now claims bit 6 as a
  flag indicating the presence of an encoded architecture flags integer
* If architecture flags need to be stored, they are placed right after
  the MPY file header.

This means that properly-written MPY parsers, if encountering a MPY file
containing encoded architecture flags, should raise an error since no
architecture identifiers have been defined that make use of bits 6 and
7 in the referenced header byte.  This should give enough guarantees of
backwards compatibility when this feature is used (improper parsers were
subjected to breakage anyway).

The encoded architecture flags could have been placed at the end, but:

* Having them right after the header makes the architecture
  compatibility checks occur before having read the whole file in memory
  (which still happens on certain platforms as the reader may be backed
  by a memory buffer), and prevents eventual memory allocations that do
  not take place if the module is rejected early
* Properly-written MPY file parsers should have checked the upper two
  bits of the flags byte to be actually zero according to the format
  specification available right before this change, so no assumptions
  should have been made on the exact order of the chunks for an
  unexpected format.

The meaning of the architecture flags value is backend-specific, with
the only common characteristic of being a variable-encoded unsigned
integer for the time being.

The changes made to the file format effectively limit the number of
possible target architectures to 16, of which 13 are already claimed.
There aren't that many new architectures planned to be supported for the
lifetime of the current MPY file format, so this change still leaves
space for architecture updates if needed.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2025-10-24 16:32:53 +02:00
..
asm_thumb2_arith.rst docs: Add reference for Thumb2 inline assembler. 2015-06-25 00:21:35 +01:00
asm_thumb2_compare.rst all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
asm_thumb2_directives.rst docs: More consistent capitalization and use of articles in headings. 2020-01-06 22:17:29 +11:00
asm_thumb2_float.rst docs: More consistent capitalization and use of articles in headings. 2020-01-06 22:17:29 +11:00
asm_thumb2_hints_tips.rst docs: Remove trailing spaces and convert tabs to spaces. 2021-12-15 11:49:22 +11:00
asm_thumb2_index.rst all: Replace legacy name with MicroPython and MPy as applicable. 2025-10-04 00:19:40 +10:00
asm_thumb2_label_branch.rst docs: Spelling mistakes 2016-08-02 11:17:46 +03:00
asm_thumb2_ldr.rst docs: Add reference for Thumb2 inline assembler. 2015-06-25 00:21:35 +01:00
asm_thumb2_logical_bit.rst docs: More consistent capitalization and use of articles in headings. 2020-01-06 22:17:29 +11:00
asm_thumb2_misc.rst docs: Several minor changes: network, pyb, ADCAll and inline asm. 2016-01-13 21:53:26 +00:00
asm_thumb2_mov.rst py/inlinethumb: Remove 30-bit restriction on movwt instruction. 2016-01-07 16:34:11 +00:00
asm_thumb2_stack.rst docs: Add reference for Thumb2 inline assembler. 2015-06-25 00:21:35 +01:00
asm_thumb2_str.rst docs: Add reference for Thumb2 inline assembler. 2015-06-25 00:21:35 +01:00
constrained.rst all: Fix "reuse" and "overridden" spelling mistakes. 2024-01-05 15:08:33 +11:00
filesystem.rst docs: Use vfs module instead of os. 2024-02-07 13:25:10 +11:00
glossary.rst docs/library/machine: Add docs for Counter and Encoder. 2025-08-02 00:00:03 +10:00
index.rst docs: Add a "Reset and Boot Sequence" reference page. 2024-11-19 10:57:26 +11:00
isr_rules.rst all: Upgrade codespell to v2.4.1. 2025-02-25 16:11:33 +11:00
manifest.rst docs,ports: Fix some comments and error messages with doubled-up words. 2024-11-30 13:08:33 +11:00
micropython2_migration.rst docs/reference/micropython2_migration.rst: Add info about os and vfs. 2024-02-07 13:25:09 +11:00
mpremote.rst docs/reference/mpremote: Document location of config file. 2025-08-02 00:23:21 +10:00
mpyfiles.rst py/persistentcode: Add architecture flags compatibility checks. 2025-10-24 16:32:53 +02:00
packages.rst tools/mpremote: Add support for relative urls in package.json files. 2025-02-24 13:29:40 +11:00
pyboard.py.rst docs/reference: Fix pyboard.py filesystem cp example with three files. 2024-09-17 11:20:17 +10:00
repl.rst docs: Fix double 'the' in documentation. 2025-02-25 17:07:16 +11:00
reset_boot.rst docs/esp32: Add a factory reset page. 2024-11-19 10:57:53 +11:00
speed_python.rst docs/reference/speed_python: Document schedule/GIL limitation of native. 2025-07-23 11:37:16 +10:00