Skip to content

Commit

Permalink
Add remaining libraries to CMake build
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Jan 12, 2024
1 parent ae13b7e commit 25cb382
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 4,696 deletions.
4 changes: 3 additions & 1 deletion ide-config-files/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ foreach(MBED_LIB ${MBED_LIBS_TO_INSTALL})
string(APPEND BOARDS_TXT_LIBRARY_LIST "\"{build.variant.path}/libs/lib${MBED_LIB}.a\" ")
endforeach()

# After all the optional libraries, we want to link Mbed itself
# After all the optional libraries, we want to link Mbed itself (must use whole archive)
string(APPEND BOARDS_TXT_LIBRARY_LIST "-Wl,--whole-archive ")
string(APPEND BOARDS_TXT_LIBRARY_LIST "\"{build.variant.path}/libs/libmbed-os-static.a\" ")
string(APPEND BOARDS_TXT_LIBRARY_LIST "-Wl,--no-whole-archive ")

# Finally grab the binary dependencies
foreach(A_FILE ${ARDUINO_PRECOMPILED_A_FILES})
Expand Down
2 changes: 1 addition & 1 deletion ide-config-files/universal/platform.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compil
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.elf.cmd}" -E -P -x c "{build.variant.path}/{build.ldscript}" -o "{build.path}/{build.ldscript}"

## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" "@{compiler.mbedce.cxxflags}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} "-T{build.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} -Wl,--whole-archive "{build.path}/{archive_file}" {compiler.mbedce.libraries} -Wl,--no-whole-archive -Wl,--start-group {compiler.libraries.ldflags} -Wl,--end-group "@{compiler.mbedce.ldflags}"
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" "@{compiler.mbedce.cxxflags}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} "-T{build.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} -Wl,--whole-archive "{build.path}/{archive_file}" -Wl,--no-whole-archive {compiler.mbedce.libraries} -Wl,--start-group {compiler.libraries.ldflags} -Wl,--end-group "@{compiler.mbedce.ldflags}"

## Create eeprom
recipe.objcopy.eep.pattern=
Expand Down
5 changes: 5 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ if("ARDUINO_NANO33BLE" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(MRI)
add_subdirectory(ThreadDebug)
add_subdirectory(KernelDebug)
add_subdirectory(Nano33BLE_System)
add_subdirectory(MLC)
endif()

if("RASPBERRY_PI_PICO" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(SFU)
endif()

# Libraries for all targets
add_subdirectory(Basic)
Expand Down
3 changes: 3 additions & 0 deletions libraries/MLC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# For this library, we cannot build the examples as part of Mbed CE, because they rely on driver libraries
# which are maintained outside this repo.
install(DIRECTORY . DESTINATION libraries/MLC)
7 changes: 7 additions & 0 deletions libraries/Nano33BLE_System/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(arduino-Nano33BLE_System INTERFACE)
target_link_libraries(arduino-Nano33BLE_System INTERFACE arduino-core)
target_include_directories(arduino-Nano33BLE_System INTERFACE src)

build_arduino_examples(Nano33BLE_System examples)

install(DIRECTORY . DESTINATION libraries/Nano33BLE_System)
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* 3) Run this sketch again and flash the SoftDevice.
*/

#include <Arduino.h>

#include "FlashIAP.h"
#include "MBR.h"
#include "bootloader.h"
Expand All @@ -52,6 +54,60 @@ const unsigned int magic = 0x5f27a93d;

mbed::FlashIAP flash;

uint32_t getTargetBootloaderCrc() {
uint32_t mask = 0;
uint32_t crc = 0xFFFFFFFF;
uint32_t b = 0;
uint8_t bootByte = 0;

int iterations = BOOTLOADER_SIZE;

for (int i=0; i<iterations; i=i+4) {
b = 0;
for (int j=0; j<4; j++) {
mask = 0;
bootByte = nano33_bootloader_hex[i+j];
mask = mask + (uint32_t)bootByte;
mask = mask << 8*j;
b = b | mask;
}
crc = crc ^ b;
}
return crc;
}

uint32_t getCurrentBootloaderCrc() {
uint32_t b = 0;
uint32_t crc = 0xFFFFFFFF;

int iterations = ceil(BOOTLOADER_SIZE/4);

int addr = BOOTLOADER_ADDR;

for (int i=0; i<iterations; i++) {
//Read 32 bit from flash
flash.read(&b, addr, sizeof(b));
//Serial.println(b, HEX);
//Update crc
crc = crc ^ b;
//Update pointer
addr = addr + 4;
}
return crc;
}

void writeSoftDeviceLen(uint32_t address) {
uint32_t sd_addr = SOFTDEVICE_ADDR;
flash.erase(address, 16);
//Write flag to let Bootloader understand that SoftDevice binary must be moved
flash.program(&magic, address, 4);
//Write address where the SoftDevice binary has been written
flash.program(&sd_addr, address + 4, 4);
//Write SoftDevice binary length
unsigned int sd_len = Softdevice_bin_len - 4096;
flash.program(&sd_len, address + 8, 4);
}

bool hasLatestBootloader(){
//Check if the CRC32 of the flashed bootloader
//matches the CRC32 of the provided bootloader binary
Expand Down Expand Up @@ -180,60 +236,6 @@ void setup() {
Serial.println("Done. You may now disconnect the board.");
}

uint32_t getTargetBootloaderCrc() {
uint32_t mask = 0;
uint32_t crc = 0xFFFFFFFF;
uint32_t b = 0;
uint8_t bootByte = 0;

int iterations = BOOTLOADER_SIZE;

for (int i=0; i<iterations; i=i+4) {
b = 0;
for (int j=0; j<4; j++) {
mask = 0;
bootByte = nano33_bootloader_hex[i+j];
mask = mask + (uint32_t)bootByte;
mask = mask << 8*j;
b = b | mask;
}
crc = crc ^ b;
}
return crc;
}

uint32_t getCurrentBootloaderCrc() {
uint32_t b = 0;
uint32_t crc = 0xFFFFFFFF;

int iterations = ceil(BOOTLOADER_SIZE/4);

int addr = BOOTLOADER_ADDR;

for (int i=0; i<iterations; i++) {
//Read 32 bit from flash
flash.read(&b, addr, sizeof(b));
//Serial.println(b, HEX);
//Update crc
crc = crc ^ b;
//Update pointer
addr = addr + 4;
}
return crc;
}

void writeSoftDeviceLen(uint32_t address) {
uint32_t sd_addr = SOFTDEVICE_ADDR;
flash.erase(address, 16);
//Write flag to let Bootloader understand that SoftDevice binary must be moved
flash.program(&magic, address, 4);
//Write address where the SoftDevice binary has been written
flash.program(&sd_addr, address + 4, 4);
//Write SoftDevice binary length
unsigned int sd_len = Softdevice_bin_len - 4096;
flash.program(&sd_len, address + 8, 4);
}

void loop() {
delay(1000);
}
13 changes: 13 additions & 0 deletions libraries/SFU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SFU OTA update library for RP2040.
# Note that the bootloader source is in the 'extras' directory, and it would be cool to compile
# it as part of the core build... but it needs different build options than the main Arduino core
# (no USB console, small C library), so it would need to be moved to its own repo.

set(SFU_SOURCES
src/SFU.cpp)

add_library(arduino-SFU STATIC ${SFU_SOURCES})
target_link_libraries(arduino-SFU PUBLIC arduino-core mbed-storage-fat mbed-storage-flashiap)
target_include_directories(arduino-SFU PUBLIC src)

install(DIRECTORY . DESTINATION libraries/SFU)
Empty file modified libraries/SFU/extra/build.sh
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion libraries/SFU/src/SFU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#endif

const unsigned char SFU[0x10000] __attribute__ ((section(".second_stage_ota"), used)) = {
#include "rp2040.h"
#include "rp2040-sfu-binary.h"
};

FlashIAPBlockDevice bd(XIP_BASE + 0xF00000, 0x100000);
Expand Down
4 changes: 2 additions & 2 deletions libraries/SFU/src/SFU.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "WiFiNINA.h"
#include "FATFileSystem.h"
#include <mbed.h>
#include <FATFileSystem.h>

class SFU {
public:
Expand Down
Loading

0 comments on commit 25cb382

Please sign in to comment.