Skip to content

Commit 00859f2

Browse files
Use CMake to generate the images
1 parent 57b5dc6 commit 00859f2

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

.github/workflows/compile.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ jobs:
2525
run: |
2626
apt-get update
2727
apt-get install -y python3-venv
28-
28+
29+
- name: Generate transient key pair
30+
run: |
31+
python3 -m pip install --user --upgrade pyopenssl # Work around runtime error
32+
python3 -m pip install --user -r mcuboot/scripts/requirements.txt
33+
python3 -m pip install --user mcuboot/scripts
34+
$HOME/.local/bin/imgtool keygen -k signing-keys.pem -t rsa-2048
35+
2936
- name: Build project for ${{ matrix.mbed_target }}
3037
run: |
3138
mkdir build && cd build
32-
cmake .. -GNinja -DMBED_TARGET=${{ matrix.mbed_target }}
39+
cmake .. -GNinja -DMBED_TARGET=${{ matrix.mbed_target }} -DMCUBOOT_SIGNING_KEY=signing-keys.pem
3340
ninja

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(MBED_OUTPUT_EXT "" CACHE STRING "" FORCE)
1111

1212
add_subdirectory(mbed-os)
1313

14-
project(mbed-mcuboot-demo-app)
14+
project(mbed-mcuboot-demo-app VERSION 1.0.0)
1515

1616
# Compile mcuboot sources
1717
add_subdirectory(mcuboot/boot/bootutil)
@@ -23,19 +23,22 @@ target_link_libraries(SimpleApp
2323
mbed-storage
2424
mbed-mcuboot)
2525
mbed_set_post_build(SimpleApp)
26+
mcuboot_generate_update_image(SimpleApp)
2627

2728
add_executable(UpdaterApp UpdaterApp.cpp secondary_bd.cpp)
2829
target_link_libraries(UpdaterApp
2930
mbed-os
3031
mbed-storage
3132
mbed-mcuboot)
3233
mbed_set_post_build(UpdaterApp)
34+
mcuboot_generate_initial_image(UpdaterApp)
35+
mcuboot_generate_update_image(UpdaterApp)
3336

3437
# Time for a bit of CMake magic: we take the bin file for SimpleApp, then link it into
3538
# UpdaterApp as block of constant data. The name in code is based on the filename passed
3639
# here to the linker.
3740
# See here for more details on this: https://gareus.org/wiki/embedding_resources_in_executables
38-
target_link_options(UpdaterApp PRIVATE -Wl,-b,binary,$<TARGET_FILE_BASE_NAME:SimpleApp>.bin -Wl,-b,elf32-littlearm)
41+
target_link_options(UpdaterApp PRIVATE -Wl,-b,binary,SimpleApp-update-image.bin -Wl,-b,elf32-littlearm)
3942
add_dependencies(UpdaterApp SimpleApp) # Ensure SimpleApp gets built before UpdaterApp
4043

4144
mbed_finalize_build()

UpdaterApp.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
// SimpleApp.bin gets loaded into ram between these addresses.
2727
// See CMakeLists.txt for details on how this is done.
28-
extern "C" uint8_t _binary_SimpleApp_bin_start;
29-
extern "C" uint8_t _binary_SimpleApp_bin_end;
30-
const size_t SimpleApp_bin_length = &_binary_SimpleApp_bin_end - &_binary_SimpleApp_bin_start;
28+
extern "C" uint8_t _binary_SimpleApp_update_image_bin_start;
29+
extern "C" uint8_t _binary_SimpleApp_update_image_bin_end;
30+
const size_t SimpleApp_update_image_bin_length = &_binary_SimpleApp_update_image_bin_end - &_binary_SimpleApp_update_image_bin_start;
3131

3232
int main()
3333
{
@@ -37,6 +37,16 @@ int main()
3737

3838
DigitalIn btn(DEMO_BUTTON);
3939

40+
// Use a buffered block device to allow arbitrary length writes to the underlying BD
41+
BlockDevice *secondary_bd = get_secondary_bd();
42+
BufferedBlockDevice bufferedSecBD(secondary_bd);
43+
int ret = bufferedSecBD.init();
44+
if (ret == 0) {
45+
tr_info("Secondary BlockDevice inited");
46+
} else {
47+
tr_error("Cannot init secondary BlockDevice: %d", ret);
48+
}
49+
4050
// Erase secondary slot
4151
// On the first boot, the secondary BlockDevice needs to be clean
4252
// If the first boot is not normal, please run the erase step, then reboot
@@ -47,17 +57,6 @@ int main()
4757
ThisThread::sleep_for(10ms);
4858
}
4959

50-
BlockDevice *secondary_bd = get_secondary_bd();
51-
int ret = secondary_bd->init();
52-
if (ret == 0) {
53-
tr_info("Secondary BlockDevice inited");
54-
} else {
55-
tr_error("Cannot init secondary BlockDevice: %d", ret);
56-
}
57-
58-
// Use a buffered block device to allow arbitrary length writes to the underlying BD
59-
BufferedBlockDevice bufferedSecBD(secondary_bd);
60-
6160
tr_info("Erasing secondary BlockDevice...");
6261
ret = bufferedSecBD.erase(0, bufferedSecBD.size());
6362
if (ret == 0) {
@@ -73,7 +72,7 @@ int main()
7372
}
7473

7574
// Copy the update image from internal flash to secondary BlockDevice
76-
bufferedSecBD.program(&_binary_SimpleApp_bin_start, 0, SimpleApp_bin_length);
75+
bufferedSecBD.program(&_binary_SimpleApp_update_image_bin_start, 0, SimpleApp_update_image_bin_length);
7776

7877
// Activate the image in the secondary BlockDevice
7978
tr_info("> Image copied to secondary BlockDevice, press button to activate");

mbed_app.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
}
6363
},
6464

65+
"demo-button-active-low": true,
66+
6567
// On K64F we store the secondary slot in external memory, not internal.
6668
// So, the primary slot can take up most of flash.
6769
"mcuboot.primary-slot-address": "0x20000",

secondary_bd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mbed::BlockDevice* get_secondary_bd(void) {
3737

3838
// In this case, our flash is much larger than a single image so
3939
// slice it into the size of an image slot
40-
static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE);
41-
return &sliced_bd;
40+
//static mbed::SlicingBlockDevice sliced_bd(default_bd, 0x0, MCUBOOT_SLOT_SIZE);
41+
return default_bd;
4242
}
4343
#endif

0 commit comments

Comments
 (0)