Skip to content

Commit 3728391

Browse files
pankoreandy31415
authored andcommitted
[Ameba] Implement reading and decoding factorydata from flash (#23758)
* [FactoryData] Implement reading and decoding factorydata from flash - Add FactoryDataDecoder - Revise FactoryDataProvider - Change chipinterface initialization order - Add CHIP_ENABLE_AMEBA_FACTORY_DATA macro to enable/disable flash factorydata - Revise filepath in mbedtls.cmake * [Build] Fix warning and errors * [Build] ignore warning for unused label * [factorydata] dont read factorydata if CONFIG_ENABLE_AMEBA_FACTORY_DATA is disabled Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent 9dc3a39 commit 3728391

File tree

8 files changed

+371
-68
lines changed

8 files changed

+371
-68
lines changed

config/ameba/chip.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ list(
2626
-DCONFIG_PLATFORM_8721D
2727
-DCONFIG_USE_MBEDTLS_ROM_ALG
2828
-DCONFIG_FUNCION_O0_OPTIMIZE
29+
-DCONFIG_ENABLE_AMEBA_FACTORY_DATA=0
2930
-DDM_ODM_SUPPORT_TYPE=32
3031
-DCHIP_DEVICE_LAYER_TARGET=Ameba
3132
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
@@ -43,6 +44,7 @@ list(
4344
-Wno-unused-variable
4445
-Wno-deprecated-declarations
4546
-Wno-unused-parameter
47+
-Wno-unused-label
4648
-Wno-format
4749
-Wno-stringop-truncation
4850
-Wno-format-nonliteral

examples/all-clusters-app/ameba/chip_main.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ list(
257257
-DCHIP_HAVE_CONFIG_H
258258
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
259259
-DCHIP_SHELL_MAX_TOKENS=11
260+
-DCONFIG_ENABLE_AMEBA_FACTORY_DATA=0
260261
)
261262

262263
if (matter_enable_persistentstorage_audit)

examples/all-clusters-app/ameba/main/chipinterface.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static void InitServer(intptr_t context)
131131
initParams.InitializeStaticResourcesBeforeServerInit();
132132
chip::Server::GetInstance().Init(initParams);
133133
gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
134+
// TODO: Use our own DeviceInfoProvider
134135
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
135136

136137
NetWorkCommissioningInstInit();
@@ -157,22 +158,23 @@ extern "C" void ChipTest(void)
157158

158159
initPref();
159160

160-
// Initialize device attestation, commissionable data and device instance info
161-
// TODO: Use our own DeviceInstanceInfoProvider
162-
// SetDeviceInstanceInfoProvider(&mFactoryDataProvider);
161+
mFactoryDataProvider.Init();
163162
SetCommissionableDataProvider(&mFactoryDataProvider);
164163
SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider);
164+
165165
CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance();
166166

167167
err = deviceMgr.Init(&EchoCallbacks);
168168
if (err != CHIP_NO_ERROR)
169169
{
170170
ChipLogError(DeviceLayer, "DeviceManagerInit() - ERROR!\r\n");
171171
}
172-
else
173-
{
174-
ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n");
175-
}
172+
173+
// Set DeviceInstanceInfoProvider after CHIPDeviceManager init
174+
// CHIPDeviceManager init will set GenericDeviceInsanceInfoProvider first
175+
#if CONFIG_ENABLE_AMEBA_FACTORY_DATA
176+
SetDeviceInstanceInfoProvider(&mFactoryDataProvider);
177+
#endif
176178

177179
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0);
178180

src/platform/Ameba/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static_library("Ameba") {
3535
"ConnectivityManagerImpl.h",
3636
"DiagnosticDataProviderImpl.cpp",
3737
"DiagnosticDataProviderImpl.h",
38+
"FactoryDataDecoder.cpp",
39+
"FactoryDataDecoder.h",
3840
"FactoryDataProvider.cpp",
3941
"FactoryDataProvider.h",
4042
"KeyValueStoreManagerImpl.cpp",
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
*
3+
* Copyright (c) 2022 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "FactoryDataDecoder.h"
19+
#include "chip_porting.h"
20+
#include <platform/internal/CHIPDeviceLayerInternal.h>
21+
22+
namespace chip {
23+
namespace DeviceLayer {
24+
25+
CHIP_ERROR FactoryDataDecoder::ReadFactoryData(uint8_t * buffer, uint16_t * pfactorydata_len)
26+
{
27+
uint32_t ret = 0;
28+
ret = ReadFactory(buffer, pfactorydata_len);
29+
if (ret != 1)
30+
return CHIP_ERROR_INTERNAL;
31+
32+
return CHIP_NO_ERROR;
33+
}
34+
35+
CHIP_ERROR FactoryDataDecoder::DecodeFactoryData(uint8_t * buffer, FactoryData * fdata, uint16_t factorydata_len)
36+
{
37+
uint32_t ret = 0;
38+
ret = DecodeFactory(buffer, fdata, factorydata_len);
39+
if (ret != 0)
40+
return CHIP_ERROR_INTERNAL;
41+
42+
return CHIP_NO_ERROR;
43+
}
44+
45+
} // namespace DeviceLayer
46+
} // namespace chip
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* Copyright (c) 2022 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <platform/internal/CHIPDeviceLayerInternal.h>
21+
22+
namespace chip {
23+
namespace DeviceLayer {
24+
25+
class FactoryDataDecoder
26+
{
27+
public:
28+
CHIP_ERROR ReadFactoryData(uint8_t * buffer, uint16_t * pfactorydata_len);
29+
CHIP_ERROR DecodeFactoryData(uint8_t * buffer, FactoryData * fdata, uint16_t factorydata_len);
30+
static FactoryDataDecoder & GetInstance()
31+
{
32+
static FactoryDataDecoder instance;
33+
return instance;
34+
}
35+
};
36+
37+
} // namespace DeviceLayer
38+
} // namespace chip

0 commit comments

Comments
 (0)