Skip to content
Prev Previous commit
Next Next commit
add build info for v2
  • Loading branch information
microbit-sam committed Feb 1, 2021
commit fd1fd7526706c0544250fd6f4534e711ff465c1c
43 changes: 39 additions & 4 deletions docs/devguide/hexformat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ the UICR customer[16] register:
Layout table (micro:bit V2)
---------------------------

A flash layout table is appended to the the hex file when building Micropython for a micro:bit V2.
A flash layout table is appended to the the hex file when building MicroPython for a micro:bit V2.

The layout table is a sequence of 16-byte entries. The last entry contains the
header (including magic numbers) and is aligned to the end of a page such that
Expand Down Expand Up @@ -82,13 +82,18 @@ store little endian.
MAGIC2 - 4 bytes - 0xC1B1D79D


This layout table is used to communicate the version of Micropython and the current memory layout to
This layout table is used to communicate the version of MicroPython and the current memory layout to
a Bluetooth client and enable `partial flashing <https://github.com/microbit-sam/codal-microbit-v2/blob/initial-docs-pf-and-memory-map/docs/bluetooth/MicroBitPartialFlashing.md>`_ (only updating the Python script, and keeping the existing version
of Micropython in flash).
of MicroPython in flash).

Steps to create the firmware.hex file
-------------------------------------

micro:bit V1
============

This applies to MicroPython for the micro:bit V1, the source of which can be found here: `bbcmicrobit/micropython <https://github.com/bbcmicrobit/micropython>`_.

The yotta tool is used to build MicroPython, but before that takes place
additional files have to be generated by the Makefile in preparation for the
build, and additional data is added to the hex file after.
Expand All @@ -101,10 +106,40 @@ Running the ``make all`` command executes the following steps:
- The final hex file is placed in ``build/firmware.hex``
- The user can optionally append a script using ``tools/makecombinedhex.py`` (or other tools)

micro:bit V2
============

This applies to MicroPython for the micro:bit V2, the source of which can be found here: `microbit-foundation/micropython-microbit-v2 <https://github.com/microbit-foundation/micropython-microbit-v2>`_.

This is a port of MicroPython to the micro:bit which uses the CODAL as the underlying target platform.

After cloning this repository update the submodules:

`$ git submodule update --init`

Then build the MicroPython cross-compiler:

`$ make -C lib/micropython/mpy-cross`

After setting up, go to the src/ directory and build:

`$ cd src`

`$ make`

That will build both libmicropython.a (from source in src/codal_port/) and the CODAL app (from source in src/codal_app/). The resulting firmware will be MICROBIT.hex in the src/ directory which can be copied to the micro:bit.

Including a user script
-----------------------

User scripts are stored in the MicroPython filesystem and if a `main.py` script exists it is run when MicroPython starts. Additional Python scripts can also be included and executed from the main.py file, or the REPL.

The `Python Editor <https://python.microbit.org>`_ uses `microbit-fs <https://github.com/microbit-foundation/microbit-fs>`_ to create the filesystem and include it in the HEX file. The Python Editor must add the filesystem to HEX files for MicroPython V1 & V2, and then combine both into a `Universal HEX <https://tech.microbit.org/software/hex-format/#universal-hex-files>`_ file to ensure compatibility with both hardware variants.

Appended script format (Deprecated)
-----------------------------------

*This method of appending the script to the end of Micropython is no longer used. Python files are now stored in the :doc:`filesystem <../filesystem>` and main.py is the program entry point.*
*This method of appending the script to the end of MicroPython is no longer used. Python files are now stored in the :doc:`filesystem <../filesystem>` and main.py is the program entry point.*

MicroPython checks the first 2 bytes at address ``0x0003e000`` for a magic
string to indicate if there is an appended script. If the magic string is
Expand Down