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

Add support for partition-tables. #67

Merged
merged 7 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ on:
required: false
type: boolean
default: true
build-tables:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build-partitions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

description: Build partition tables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build partitions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

required: false
type: boolean
default: true
toit-version:
description: Toit SDK version to check out
required: true
Expand Down Expand Up @@ -192,7 +197,7 @@ jobs:
artifacts: |
envelopes/*
body: |
Envelopes for Toit SDK ${{ github.event.inputs.toit-version }}
Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Hold on a tick, baby! Let's make the release message more dynamic!

The release message mentions partition tables even when build-tables is false. That's not very groovy, is it?

Let's make it more shagadelic with a conditional message:

- Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
+ ${{ github.event.inputs.build-tables == 'true' && 'Envelopes and partition tables' || 'Envelopes' }} for Toit SDK ${{ github.event.inputs.toit-version }}

Also applies to: 308-308, 379-379

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partitions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
Expand Down Expand Up @@ -300,7 +305,7 @@ jobs:
artifacts: |
envelopes/*
body: |
Envelopes for Toit SDK ${{ github.event.inputs.toit-version }}
Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
Expand Down Expand Up @@ -371,7 +376,47 @@ jobs:
artifacts: |
envelopes/*
body: |
Envelopes for Toit SDK ${{ github.event.inputs.toit-version }}
Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
commit: main

release-partition-tables:
name: "Release partition tables - ${{ github.event.inputs.toit-version }}"
if: ${{ github.event.inputs.build-tables == 'true' }}
runs-on: ubuntu-latest

steps:
- name: Show inputs
run: echo "${{ toJSON(github.event.inputs) }}"

- uses: actions/checkout@v4

- name: Set the git version
run: |
echo "TOIT_GIT_VERSION=${{ github.event.inputs.toit-version }}" >> $GITHUB_ENV

- name: Prepare partition tables
shell: bash
run: |
mkdir -p build
shopt -s nullglob
for csv_file in partition-tables/*/partitions.csv; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put these in partitions//partitions.csv - maybe even esp32/partitions//partitions.cvs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

variant=$(basename $(dirname $csv_file))
if [ -e "partition-tables/$variant/partitions.csv" ]; then
cp "$csv_file" "build/partition-table-$variant.csv"
fi
done
floitsch marked this conversation as resolved.
Show resolved Hide resolved

- name: Release
if: ${{ github.event.inputs.upload-release == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: |
build/partition-table-*.csv
body: |
Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
Expand Down
109 changes: 7 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Envelopes

Envelopes for Toit.
Envelopes and partition tables for Toit.

This repository contains a tool to generate envelopes for Toit. It
also automatically builds envelopes for the variants that are stored in
Expand All @@ -19,105 +19,10 @@ compiled with and for SDK v2.0.0-alpha.90 are found on the
[v2.0.0-alpha.90 release](https://github.com/toitlang/envelopes/releases/tag/v2.0.0-alpha.90)
page.

## Variants
See the [variants/README.md](variants/README.md) for a list of the
most commonly used variants. You can also browse the `variants`
directory for more variants.

### esp32

A generic ESP32 variant. This is the default variant when using Toit.
It is built for maximum compatibility.

This variant supports Ethernet, but without the clock output.

### esp32-spiram

An ESP32 variant for boards with SPIRAM. Otherwise the same as the ESP32 variant.

### esp32-eth-clk-out0 and esp32-eth-clk-out17

A variant for ESP32 boards with Ethernet and a clock output on pin 0/17.

Olimex boards with Ethernet should use this variant. The WROOM versions need
`esp32-eth-clk-out17` and the WROVER versions need `esp32-eth-clk-out0`.

### esp32c3

A generic [ESP32-C3 variant](variants/esp32c). This is the default variant
when using Toit on ESP32-C3 boards.

### esp32s2

A generic [ESP32-S2 variant](variants/esp32s2). This is the default variant
when using Toit on ESP32-S2 boards.

### esp32s3

A generic [ESP32-S3 variant](variants/esp32s3). This is the default variant
when using Toit on ESP32-S3 boards.

This variant is configured for external Quad PSRAM.

### esp32s3-spiram-octo

A [variant](variants/esp32s3-spiram-octo/) for ESP32-S3 boards with external
octal PSRAM.

These boards are faster, but often more expensive.

### esp32-no-ble

A [variant](variants/esp32-no-ble/) for ESP32 boards. This variant
saves some RAM and flash space by removing the Bluetooth stack.
The saved IRAM enables us to make the Toit interpreter a little faster
and add support for external RAM (PSRAM, aka SPIRAM).

## Contributing

Feel free to open issues and pull requests with new variants. Make sure
they have a description (README.md) with the purpose and the changes.
We will automatically build them whenever a new Toit version is released.

Note that some variants are featured here. Consult the
Toit team before adding new variants to this README.

### Creating a variant

Variants are created by copying an existing variant and making the
necessary changes. These consists of either overwriting existing files
or by applying patches.

#### Partition changes

For partition changes, simply copy the new `partitions.csv` into the
variant directory. The `esp32-ota-1c0000` is an example of this where
the OTA partition size has been increased.

#### sdkconfig changes

For `sdkconfig` changes, a patch to the original `sdkconfig.defaults`
file is typically preferred.

For example, to create a variant `esp32s3-foo`.
* Check out Toit (or use an existing checkout).
* Copy the existing `toolchains/esp32s3` directory to `toolchains/esp32s3-foo`:
`cp -r toolchains/esp32s3 toolchains/esp32s3-foo`.
* Run `make IDF_TARGET=esp32s3 ESP32_CHIP=esp32s3-foo menuconfig` and make the changes you want.
This automatically updates the `sdkconfig.defaults` as well.
* Create patch by running:
```
diff -aur \
--label toit/toolchains/esp32s3/sdkconfig.defaults \
--label synthesized/esp32s3-foo/sdkconfig.defaults \
toolchains/esp32s3/sdkconfig.defaults \
toolchains/esp32s3-foo/sdkconfig.defaults \
> toolchains/esp32s3-foo/sdkconfig.defaults.patch
```
The labels are not crucial, but make it easier for us to update the
patch at a later time.
* Create a new variant in this (`envelopes`) repository and copy the patch file into it.

#### Main changes

For changes to the `main` directory (be it the `toit.c` or the `CMakelists.txt` in it),
use a recursive diff to create a patch on the original `main` directory.

The synthetization tool will use the flag `-p1` when applying the patch.
See the [partition-tables/README.md](partition-tables/README.md) for
a list of the most commonly used partition tables. You can also browse
the `partition-tables` directory for more partition tables.
15 changes: 15 additions & 0 deletions partition-tables/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Partition tables

This directory contains partition tables for ESP32 devices and their variants.

During flashing, users can override the default partition table that comes
with the envelope that they are flashing.

Here is a list of the most commonly used partition tables:

## OTA-1C0000

A partition table that sets the size of the OTA partitions
to 0x1C0000 (1835008) bytes. This table is typically used for
use-cases where programs are bundled with the firmware (like with
[Artemis](https://github.com/toitware/artemis)).
7 changes: 7 additions & 0 deletions partition-tables/ota-1c0000/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OTA-1C0000

A partition table that sets the size of the OTA partitions
to 0x1C0000 (1835008) bytes.

As a consequence the size of the programs partition is set to
0x60000 (393216) bytes.
17 changes: 17 additions & 0 deletions partition-tables/ota-1c0000/partitions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (C) 2023 Toitware ApS.
#
# Use of this source code is governed by a BSD0-style license that can be
# found in the LICENSE_BSD0 file.

# Partition Table for Toit.

# Name, Type, SubType, Offset, Size
# bootloader,, , 0x001000, 0x007000
# partitions,, , 0x008000, 0x000c00
secure, 0x42, 0x00, 0x009000, 0x004000,
otadata, data, ota, 0x00d000, 0x002000,
phy_init, data, phy, 0x00f000, 0x001000,
ota_0, app, ota_0, 0x010000, 0x1c0000,
ota_1, app, ota_1, 0x1d0000, 0x1c0000,
nvs, data, nvs, 0x390000, 0x010000,
programs, 0x40, 0x00, 0x3A0000, 0x060000, encrypted
51 changes: 51 additions & 0 deletions variants/Contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contributing

Feel free to open issues and pull requests with new variants. Make sure
they have a description (README.md) with the purpose and the changes. If
they are generally useful, we will add them to the repository.

Variants in this repository are automatically built whenever a new Toit
version is released.

## Creating a variant

Variants are created by copying an existing variant and making the
necessary changes. These consists of either overwriting existing files
or by applying patches.

### Partition changes

For partition changes, simply copy the new `partitions.csv` into the
variant directory. The `esp32-ota-1c0000` is an example of this where
the OTA partition size has been increased.

### sdkconfig changes

For `sdkconfig` changes, a patch to the original `sdkconfig.defaults`
file is typically preferred.

For example, to create a variant `esp32s3-foo`.
* Check out Toit (or use an existing checkout).
* Copy the existing `toolchains/esp32s3` directory to `toolchains/esp32s3-foo`:
`cp -r toolchains/esp32s3 toolchains/esp32s3-foo`.
* Run `make IDF_TARGET=esp32s3 ESP32_CHIP=esp32s3-foo menuconfig` and make the changes you want.
This automatically updates the `sdkconfig.defaults` as well.
* Create patch by running:
```
diff -aur \
--label toit/toolchains/esp32s3/sdkconfig.defaults \
--label synthesized/esp32s3-foo/sdkconfig.defaults \
toolchains/esp32s3/sdkconfig.defaults \
toolchains/esp32s3-foo/sdkconfig.defaults \
> toolchains/esp32s3-foo/sdkconfig.defaults.patch
```
The labels are not crucial, but make it easier for us to update the
patch at a later time.
* Create a new variant in this (`envelopes`) repository and copy the patch file into it.

### Main changes

For changes to the `main` directory (be it the `toit.c` or the `CMakelists.txt` in it),
use a recursive diff to create a patch on the original `main` directory.

The synthetization tool will use the flag `-p1` when applying the patch.
56 changes: 56 additions & 0 deletions variants/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Variants

Some commonly used variants are featured here. You can also browse this
directory for more variants.

See the [Contributing](Contributing.md) guide for how to create a new variant.


## esp32

A generic ESP32 variant. This is the default variant when using Toit.
It is built for maximum compatibility.

This variant supports Ethernet, but without the clock output.

## esp32-spiram

An ESP32 variant for boards with SPIRAM. Otherwise the same as the ESP32 variant.

## esp32-eth-clk-out0 and esp32-eth-clk-out17

A variant for ESP32 boards with Ethernet and a clock output on pin 0/17.

Olimex boards with Ethernet should use this variant. The WROOM versions need
`esp32-eth-clk-out17` and the WROVER versions need `esp32-eth-clk-out0`.

## esp32c3

A generic [ESP32-C3 variant](esp32c). This is the default variant
when using Toit on ESP32-C3 boards.

## esp32s2

A generic [ESP32-S2 variant](esp32s2). This is the default variant
when using Toit on ESP32-S2 boards.

## esp32s3

A generic [ESP32-S3 variant](esp32s3). This is the default variant
when using Toit on ESP32-S3 boards.

This variant is configured for external Quad PSRAM.

## esp32s3-spiram-octo

A [variant](esp32s3-spiram-octo/) for ESP32-S3 boards with external
octal PSRAM.

These boards are faster, but often more expensive.

## esp32-no-ble

A [variant](esp32-no-ble/) for ESP32 boards. This variant
saves some RAM and flash space by removing the Bluetooth stack.
The saved IRAM enables us to make the Toit interpreter a little faster
and add support for external RAM (PSRAM, aka SPIRAM).