Skip to content

Commit

Permalink
Pull request project-chip#1481: cherry-pick/provision support for Siw…
Browse files Browse the repository at this point in the history
…x917

Merge in WMN_TOOLS/matter from feature/provision_support_for_Siwx917 to RC_2.3.0-1.3

Squashed commit of the following:

commit 701b73f6b426ad08f85bcd2ae13165b8717981c4
Author: thirupathi <[email protected]>
Date:   Thu Jan 11 12:10:34 2024 +0530

    provision script missing changes

commit 51e941621576a5dbfeedf6b3c3242d63dd6a1abb
Author: thirupathi <[email protected]>
Date:   Thu Jan 11 11:05:50 2024 +0530

    removed slc fix changes

commit 17dadb84889e118dfe36dc342460feeb628af117
Author: Thirupathi S <[email protected]>
Date:   Fri Dec 8 15:29:02 2023 +0000

    Pull request project-chip#1426: Certificate Injection support for 917 SOC

    Merge in WMN_TOOLS/matter from feature/917soc_cpms_in_slc_latest to silabs_slc_1.2

    Squashed commit of the following:

    commit 51657064b09c4780621a9d8c6704b140b4cb1786
    Author: Thirupathi <[email protected]>
    Date:   Fri Dec 8 13:13:45 2023 +0530

        revert old change

    commit 60567adadbb3ef6650ea6cceb489bba536165873
    Author: Thirupathi <[email protected]>
    Date:   Fri Dec 8 13:10:36 2023 +0530

        addressed review comments

    commit 293c1bd40732a9907ec58bad1fec83e3ef213210
    Author: Thirupathi <[email protected]>
    Date:   Thu Dec 7 20:48:10 2023 +0530

        addressed review comments

    ... and 10 more commits
  • Loading branch information
Thirsrin authored and jmartinez-silabs committed Jan 11, 2024
1 parent 398ae1c commit bad8740
Show file tree
Hide file tree
Showing 41 changed files with 15,007 additions and 4,648 deletions.
3 changes: 3 additions & 0 deletions examples/platform/silabs/provision/AttestationKeyMbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <platform/silabs/SilabsConfig.h>
#include <mbedtls/x509_csr.h>
#include <mbedtls/asn1.h>
#ifdef SIWX_917
#include <mbedtls/sha256.h>
#endif
#include <em_msc.h>
#include <stdio.h>
#include <string.h>
Expand Down
23 changes: 22 additions & 1 deletion examples/platform/silabs/provision/ProvisionStorageDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#include <nvm3_hal_flash.h>
#include "silabs_creds.h"

#ifdef SIWX_917
#include "sl_si91x_common_flash_intf.h"
extern uint8_t linker_nvm_end[];
static uint8_t * _base_address = (uint8_t *) linker_nvm_end;
#endif //SIWX_917

using namespace chip::Credentials;
using namespace chip::DeviceLayer::Internal;

Expand Down Expand Up @@ -42,7 +48,11 @@ extern "C" __WEAK void setNvm3End(uint32_t addr) {}

CHIP_ERROR DefaultStorage::Initialize(uint32_t flash_addr, uint32_t flash_size)
{
#ifdef SIWX_917
uint32_t base_addr = (uint32_t)_base_address;
#else
uint32_t base_addr = flash_addr + flash_size - FLASH_PAGE_SIZE;
#endif
setNvm3End(base_addr);
return SilabsConfig::WriteConfigValue(SilabsConfig::kConfigKey_Creds_Base_Addr, base_addr);
}
Expand Down Expand Up @@ -457,7 +467,18 @@ CHIP_ERROR DefaultStorage::WriteFile(ConfigKey offset_key, ConfigKey size_key, u
if(_cd_set && _pai_set && _dac_set)
{
#ifdef SIWX_917
return CHIP_ERROR_NOT_IMPLEMENTED;
// Erase page
rsi_flash_erase_sector((uint32_t *)base_addr);

constexpr size_t WRITE_SIZE = 1024;
uint32_t offset = 0;
while(offset < FLASH_PAGE_SIZE)
{
// Write to flash
if (!rsi_flash_write((uint32_t *)(base_addr+offset), &_credentials_page[offset], WRITE_SIZE)) {
offset += WRITE_SIZE;
}
}
#else
// Erase page
MSC_ErasePage((uint32_t *)base_addr);
Expand Down
2 changes: 2 additions & 0 deletions provision/generator/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ Provision::Manager sProvisionManager(sProvisionStore, sProvisionChannel);

void app_init(void)
{
#ifndef SIWX_917
MSC_Init();
psa_crypto_init();
#endif
sProvisionManager.Start();
}

Expand Down
114 changes: 107 additions & 7 deletions provision/generator/generator_siwx917.slcp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ label: Matter Provisioner Generator
description: >
Generates the key-pair, and CSR for the DAC
category: Example|Platform
sdk_extension:
- id: wiseconnect3_sdk
version: "3.1.1"
toolchain_settings:
- option: gcc_c++_compiler_option
value: -std=gnu++17

config_file:
- override:
component: "%extension-wiseconnect3_sdk%board_configuration_headers"
file_id: freertos_config
path: ../../examples/platform/silabs/FreeRTOSConfig.h
filter:
- name: "Device Type"
value: ["SoC"]
Expand All @@ -15,7 +27,49 @@ filter:
source:
- path: app.cpp
- path: main.cpp
- path: nvm3.c
- path: nvm3_si917.c
- path: ../../third_party/mbedtls/repo/library/aes.c
- path: ../../third_party/mbedtls/repo/library/asn1parse.c
- path: ../../third_party/mbedtls/repo/library/asn1write.c
- path: ../../third_party/mbedtls/repo/library/base64.c
- path: ../../third_party/mbedtls/repo/library/bignum.c
- path: ../../third_party/mbedtls/repo/library/ccm.c
- path: ../../third_party/mbedtls/repo/library/cipher.c
- path: ../../third_party/mbedtls/repo/library/cipher_wrap.c
- path: ../../third_party/mbedtls/repo/library/constant_time.c
- path: ../../third_party/mbedtls/repo/library/ctr_drbg.c
- path: ../../third_party/mbedtls/repo/library/ecdh.c
- path: ../../third_party/mbedtls/repo/library/ecdsa.c
- path: ../../third_party/mbedtls/repo/library/ecp.c
- path: ../../third_party/mbedtls/repo/library/ecp_curves.c
- path: ../../third_party/mbedtls/repo/library/entropy.c
- path: ../../third_party/mbedtls/repo/library/hkdf.c
- path: ../../third_party/mbedtls/repo/library/hmac_drbg.c
- path: ../../third_party/mbedtls/repo/library/md.c
- path: ../../third_party/mbedtls/repo/library/pem.c
- path: ../../third_party/mbedtls/repo/library/pkcs5.c
- path: ../../third_party/mbedtls/repo/library/platform.c
- path: ../../third_party/mbedtls/repo/library/sha256.c
- path: ../../third_party/mbedtls/repo/library/sha512.c
- path: ../../third_party/mbedtls/repo/library/x509.c
- path: ../../third_party/mbedtls/repo/library/x509_create.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/ecc.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/ecc_dh.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/ecc_dsa.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/error.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/oid.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/pk.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/pk_wrap.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/pkparse.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/pkwrite.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/platform_util.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/x509_crt.c
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/src/x509write_csr.c
- path: ../../src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp
- path: ../../src/lib/support/CHIPMem.cpp
- path: ../../src/lib/support/CHIPPlatformMemory.cpp
- path: ../../src/lib/support/CHIPMem-Malloc.cpp
- path: ../../third_party/silabs/matter_support/matter/si91x/siwx917/BRD4338A/support/src/startup_common_RS1xxxx.c
include:
- path: .
file_list:
Expand All @@ -38,6 +92,7 @@ include:
- path: platform/silabs/provision/AttestationKey.h
- path: platform/silabs/provision/AttestationKeyMbed.cpp
- path: platform/silabs/provision/AttestationKeyMbed.h
- path: platform/silabs/syscalls_stubs.cpp
- path: ../../examples/platform/silabs/
- path: ../../src/
file_list:
Expand All @@ -50,16 +105,61 @@ include:
- path: platform/silabs/Logging.cpp
- path: setup_payload/Base38Encode.h
- path: setup_payload/Base38Encode.cpp
- path: lib/support/CHIPPlatformMemory.h
- path: ../../src/platform/silabs/SiWx917/
- path: ../../src/include/
- path: ../../zzz_generated/app-common/
- path: ../../third_party/nlassert/repo/include/
- path: ../../third_party/nlio/repo/include/
- path: ../../third_party/silabs/matter_support/matter/mbedtls/tinycrypt/inc
- path: ../../third_party/mbedtls/repo/library
- path: ../../third_party/mbedtls/repo/include
- path: ../../src/platform/silabs/SiWx917
- path: ../../src/lib/support/
- path: ../../src/platform/silabs/
- path: ../../third_party/silabs/matter_support/matter/si91x/siwx917/BRD4338A/support/inc
file_list:
- path: system_si917.h

component:
- id: device_init
- id: freertos
- id: cpp_support
- id: iostream_rtt
- id: nvm3_default
- id: mbedtls_pkcs5
- id: mbedtls_ecc
- id: mbedtls_x509
- id: bootloader_app_properties
- id: segger_rtt
- id: sl_system_init
- id: nvm3_lib
- id: rsilib_userconfig
from: wiseconnect3_sdk
- id: wiseconnect3_common
from: wiseconnect3_sdk
- id: sl_si91x_common_flash_nvm3
from: wiseconnect3_sdk
- id: sl_si91x_wireless
from: wiseconnect3_sdk
- id: basic_network_config_manager
from: wiseconnect3_sdk
- id: si917_memory_default_config
from: wiseconnect3_sdk
- id: sl_si91x_basic_buffers
from: wiseconnect3_sdk
- id: sl_si91x_mcu
from: wiseconnect3_sdk
- id: board_configuration_headers
from: wiseconnect3_sdk
- id: brd4338a
from: wiseconnect3_sdk

define:
- name: CHIP_SYSTEM_CONFIG_USE_SOCKETS
- name: SIWX_917
- name: SRAM_SIZE
value: "0x00040000UL"
- name: FLASH_PAGE_SIZE
value: "4096"
- name: EXT_IRQ_COUNT
value: "75"
- name: OPTIMIZE_TINYCRYPT_ASM
- name: PROVISION_CHANNEL_ENABLED
- name: TINYCRYPT_PRIMITIVES
- name: MBEDTLS_CONFIG_FILE
value: \"siwx917-chip-mbedtls-config.h\"
2 changes: 1 addition & 1 deletion provision/generator/nvm3.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ void setNvm3End(uint32_t end_addr)
nvm3_defaultInit->nvmAdr = (nvm3_HalPtr_t)nvm3_start_addr;
nvm3_defaultInit->nvmSize = size;
nvm3_initDefault();
}
}
116 changes: 116 additions & 0 deletions provision/generator/nvm3_si917.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/***************************************************************************//**
* @file
* @brief NVM3 definition of the default data structures.
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/

#include "nvm3.h"
#include "nvm3_hal_flash.h"
#include "nvm3_default_config.h"

#include "sl_wifi_device.h"

extern char linker_nvm_begin;
__attribute__((used)) uint8_t nvm3_default_storage[NVM3_DEFAULT_NVM_SIZE] __attribute__ ((section(".simee")));
#define NVM3_BASE (&linker_nvm_begin)

// NVM3 Default Instance Max Object Size
#define NVM3_DEFAULT_MAX_OBJECT_SIZE 4096

// WiFi Client Interface
#define SL_NET_WIFI_CLIENT_INTERFACE (1 << 3)

static nvm3_Handle_t nvm3_defaultHandleData;

#if (NVM3_DEFAULT_CACHE_SIZE != 0)
static nvm3_CacheEntry_t defaultCache[NVM3_DEFAULT_CACHE_SIZE];
#endif


static nvm3_Init_t nvm3_defaultInitData =
{
(nvm3_HalPtr_t)NVM3_BASE,
0,
#if (NVM3_DEFAULT_CACHE_SIZE != 0)
defaultCache,
#else
NULL,
#endif
NVM3_DEFAULT_CACHE_SIZE,
NVM3_DEFAULT_MAX_OBJECT_SIZE,
NVM3_DEFAULT_REPACK_HEADROOM,
&nvm3_halFlashHandle,
};

static const sl_wifi_device_configuration_t station_init_configuration = {
.boot_option = LOAD_NWP_FW,
.mac_address = NULL,
.band = SL_SI91X_WIFI_BAND_2_4GHZ,
.region_code = US,
.boot_config = { .oper_mode = SL_SI91X_CLIENT_MODE,
.coex_mode = SL_SI91X_WLAN_ONLY_MODE,
.feature_bit_map = (SL_SI91X_FEAT_SECURITY_PSK | SL_SI91X_FEAT_AGGREGATION),
.tcp_ip_feature_bit_map = (SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | SL_SI91X_TCP_IP_FEAT_HTTP_CLIENT
| SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID | SL_SI91X_TCP_IP_FEAT_OTAF
| SL_SI91X_TCP_IP_FEAT_DNS_CLIENT),
.custom_feature_bit_map = SL_SI91X_CUSTOM_FEAT_EXTENTION_VALID,
.ext_custom_feature_bit_map =
(SL_SI91X_EXT_FEAT_XTAL_CLK | SL_SI91X_EXT_FEAT_UART_SEL_FOR_DEBUG_PRINTS |
#ifndef SLI_SI91X_MCU_INTERFACE
SL_SI91X_RAM_LEVEL_NWP_ALL_MCU_ZERO
#else
SL_SI91X_RAM_LEVEL_NWP_MEDIUM_MCU_MEDIUM
#endif
),
.bt_feature_bit_map = 0,
.ext_tcp_ip_feature_bit_map =
(SL_SI91X_EXT_TCP_IP_FEAT_SSL_HIGH_PERFORMANCE | SL_SI91X_EXT_TCP_IP_SSL_16K_RECORD
| SL_SI91X_CONFIG_FEAT_EXTENTION_VALID),
.ble_feature_bit_map = 0,
.ble_ext_feature_bit_map = 0,
.config_feature_bit_map = 0 }
};

//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------

nvm3_Handle_t *nvm3_defaultHandle = &nvm3_defaultHandleData;

nvm3_Init_t *nvm3_defaultInit = &nvm3_defaultInitData;

Ecode_t nvm3_initDefault(void)
{
return nvm3_open(nvm3_defaultHandle, nvm3_defaultInit);
}

Ecode_t nvm3_deinitDefault(void)
{
return nvm3_close(nvm3_defaultHandle);
}

void setNvm3End(uint32_t end_addr)
{
uint32_t size = NVM3_DEFAULT_NVM_SIZE;
uint32_t nvm3_start_addr = (end_addr - size);
nvm3_defaultInit->nvmAdr = (nvm3_HalPtr_t)nvm3_start_addr;
nvm3_defaultInit->nvmSize = size;
sl_status_t status = SL_STATUS_OK;
status = sl_net_init(SL_NET_WIFI_CLIENT_INTERFACE, &station_init_configuration, NULL, NULL);
if (status != SL_STATUS_OK) {
printf("Failed to start Wi-Fi client interface: 0x%lx\r\n", status);
return;
}
nvm3_initDefault();
}
Binary file added provision/images/si917.rps
Binary file not shown.
Loading

0 comments on commit bad8740

Please sign in to comment.