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

[BL602] Fix sve2 problems #22582

Merged
merged 10 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl602/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declare_args() {
enable_heap_monitoring = false

# OTA periodic query timeout in seconds
ota_periodic_query_timeout = 86400
ota_periodic_query_timeout = 300
}

show_qr_code = false
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl602/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The steps in this document were validated on Ubuntu 18.04 and 20.04.
```
cd third_party/bouffalolab/repo/tools/flash_tool

./bflb_iot_tool-ubuntu18 --chipname=BL602 --baudrate=115200 --port=/dev/ttyACM0 --pt=chips/bl602/partition/partition_cfg_4M.toml --dts=chips/bl602/device_tree/bl_factory_params_IoTKitA_40M.dts --firmware=../../../../../../out/bl602-light/chip-bl602-lighting-example.bin
./bflb_iot_tool --chipname=BL602 --baudrate=115200 --port=/dev/ttyACM0 --pt=chips/bl602/partition/partition_cfg_4M.toml --dts=chips/bl602/device_tree/bl_factory_params_IoTKitA_40M.dts --firmware=../../../../../out/bl602-light/chip-bl602-lighting-example.bin
```

```
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
#define APP_EVENT_QUEUE_SIZE 10
#define APP_TASK_STACK_SIZE (8192)
#define APP_TASK_STACK_SIZE (4096)
#define APP_TASK_PRIORITY 2
#define STATUS_LED_GPIO_NUM GPIO_NUM_2 // Use LED1 (blue LED) as status LED on DevKitC

Expand Down
2 changes: 1 addition & 1 deletion examples/platform/bouffalolab/bl602/ldscripts/flash_rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ __RFTLV_HEAD1_L = (0x41524150); /* PAPA */
__RAM_START = 0x4200C000;
__RAM_END = 0x4200C000 + 256K - __EM_SIZE; /* leave 8K left for BLE */

__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K);
__RAM_TCM_LEN = (16K + 16K + 48K + 64K + 64K - 16K - 16K);
__RAM_WIFI_LEN = (__RAM_END - __RAM_START - __RAM_TCM_LEN);

MEMORY
Expand Down
4 changes: 4 additions & 0 deletions src/platform/bouffalolab/BL602/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
#define CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS 4
#endif // CHIP_CONFIG_MAX_LOCAL_ADDR_UDP_ENDPOINTS

#ifndef CHIP_CONFIG_MAX_FABRICS
#define CHIP_CONFIG_MAX_FABRICS 6 // 5 fabrics + 1 for rotation slack
#endif

// ==================== Security Configuration Overrides ====================

#ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION
Expand Down
43 changes: 39 additions & 4 deletions src/platform/bouffalolab/BL602/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,33 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetBootReason(BootReasonType & bootReason
return CHIP_NO_ERROR;
}

static int bl_netif_get_all_ip6(struct netif * netif, ip6_addr_t if_ip6[])
{
if (netif == NULL || if_ip6 == NULL)
{
return 0;
}

int addr_count = 0;
for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++)
{
if (!ip_addr_cmp(&netif->ip6_addr[i], IP6_ADDR_ANY))
{
memcpy(&if_ip6[addr_count++], &netif->ip6_addr[i], sizeof(ip6_addr_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

how do you ensure that if_ip6 has sufficient space for addr_count ?

I think the size of input arrays should be passed in to methods. Currently nothing seems to guarantee that kMaxIPv6AddrCount >= LWIP_IPV6_NUM_ADDRESSES

Copy link
Contributor

Choose a reason for hiding this comment

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

what guarantees that if_ip6 has at least min(kMaxIPv6AddrCount, LWIP_IPV6_NUM_ADDRESSES) elements?

The size of if_ip6 should be passed in to this method as an argument, not assumed.

}
}

return addr_count;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** netifpp)
{
NetworkInterface * ifp = new NetworkInterface();
struct netif * netif;
uint8_t mac_addr[6];
uint32_t ip, gw, mask;
ip6_addr_t ip6_addr[kMaxIPv6AddrCount];
uint8_t ipv6_addr_count = 0;
jczhang777 marked this conversation as resolved.
Show resolved Hide resolved

netif = wifi_mgmr_sta_netif_get();
if (netif)
Expand All @@ -179,10 +201,24 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface **
ifp->type = EMBER_ZCL_INTERFACE_TYPE_WI_FI;
ifp->offPremiseServicesReachableIPv4.SetNull();
ifp->offPremiseServicesReachableIPv6.SetNull();
bl_efuse_read_mac(mac_addr);
memcpy(ifp->MacAddress, mac_addr, sizeof(mac_addr));
bl_efuse_read_mac(ifp->MacAddress);
ifp->hardwareAddress = ByteSpan(ifp->MacAddress, 6);

wifi_mgmr_sta_ip_get(&ip, &gw, &mask);
Copy link
Contributor

Choose a reason for hiding this comment

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

do these methods never fail? Like is there always an ip/gw/mask?

Copy link
Contributor

Choose a reason for hiding this comment

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

What was the resolution here? This was marked resolved yet I see no comment of "this never fails" nor do I see code changes that would check for a return value from the wifi_mgmr_sta_ip_get

memcpy(ifp->Ipv4AddressesBuffer[0], &ip, kMaxIPv4AddrSize);
ifp->Ipv4AddressSpans[0] = ByteSpan(ifp->Ipv4AddressesBuffer[0], kMaxIPv4AddrSize);
ifp->IPv4Addresses = chip::app::DataModel::List<chip::ByteSpan>(ifp->Ipv4AddressSpans, 1);
ipv6_addr_count = bl_netif_get_all_ip6(netif, ip6_addr);
for (uint8_t idx = 0; idx < ipv6_addr_count; ++idx)
{
memcpy(ifp->Ipv6AddressesBuffer[idx], ip6_addr[idx].addr, kMaxIPv6AddrSize);
ifp->Ipv6AddressSpans[idx] = ByteSpan(ifp->Ipv6AddressesBuffer[idx], kMaxIPv6AddrSize);
}
ifp->IPv6Addresses = chip::app::DataModel::List<chip::ByteSpan>(ifp->Ipv6AddressSpans, ipv6_addr_count);
}

*netifpp = ifp;

return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -256,8 +292,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiBeaconLostCount(uint32_t & beaconL

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiCurrentMaxRate(uint64_t & currentMaxRate)
{
currentMaxRate = 0;
return CHIP_NO_ERROR;
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount)
Expand Down
17 changes: 16 additions & 1 deletion src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ bool BLWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan networkId)
Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText,
uint8_t & outNetworkIndex)
{
outDebugText.reduce_size(0);
outNetworkIndex = 0;

VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded);
VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange);
VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange);
Expand All @@ -136,6 +139,9 @@ Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, Mut

Status BLWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex)
{
outDebugText.reduce_size(0);
outNetworkIndex = 0;

VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound);

// Use empty ssid for representing invalid network
Expand All @@ -145,6 +151,8 @@ Status BLWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebu

Status BLWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText)
{
outDebugText.reduce_size(0);

// Only one network is supported now
VerifyOrReturnError(index == 0, Status::kOutOfRange);
VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound);
Expand All @@ -157,12 +165,18 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,

char wifi_ssid[64] = { 0 };
char passwd[64] = { 0 };

// Set the wifi configuration
wifi_mgmr_sta_disconnect();
vTaskDelay(500);
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
wifi_mgmr_sta_disable(NULL);
vTaskDelay(500);

memcpy(wifi_ssid, ssid, ssidLen);
memcpy(passwd, key, keyLen);
wifi_interface_t wifi_interface;
wifi_interface = wifi_mgmr_sta_enable();
wifi_mgmr_sta_connect(wifi_interface, ssid, passwd, NULL, NULL, 0, 0);
wifi_mgmr_sta_connect(wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these methods return an error code we could check and log on failures?

Copy link
Contributor

Choose a reason for hiding this comment

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

These were marked resolved ... what was the resolution? I see no deltas.

An answer like "this never fails" or implementation change would make sense.


ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled));

Expand Down Expand Up @@ -280,6 +294,7 @@ void BLWiFiDriver::OnScanWiFiNetworkDone()
}
}))
{
vPortFree(ScanResult);
ChipLogProgress(DeviceLayer, "ScheduleLambda OK");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
}

DeviceLayer::SystemLayer().StartTimer(
System::Clock::Seconds32(2),
System::Clock::Seconds32(4),
[](Layer *, void *) {
ChipLogProgress(SoftwareUpdate, "Rebooting...");
hal_reboot();
Expand Down
3 changes: 2 additions & 1 deletion src/platform/bouffalolab/BL602/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s

static void WifiStaDisconect(void)
{
NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL);

uint16_t reason = NetworkCommissioning::BLWiFiDriver::GetInstance().GetLastDisconnectReason();
uint8_t associationFailureCause =
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kUnknown);
Expand Down Expand Up @@ -138,7 +140,6 @@ static void WifiStaDisconect(void)
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::WiFiConnectionStatus::kNotConnected));
}

NetworkCommissioning::BLWiFiDriver::GetInstance().SetLastDisconnectReason(NULL);
ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManagerImpl::kWiFiStationState_Disconnecting);
}

Expand Down
3 changes: 2 additions & 1 deletion third_party/bouffalolab/bl602/bl602_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ template("bl602_sdk") {
"SYS_AOS_LOOP_ENABLE=1",
"BL602_USE_HAL_DRIVER=1",
"BL602=BL602",
"SYS_LOOPRT_ENABLE=1",

#"SYS_LOOPRT_ENABLE=1",
jczhang777 marked this conversation as resolved.
Show resolved Hide resolved
"CFG_TXDESC=2",
"CFG_STA_MAX=1",
"CFG_CHIP_BL602",
Expand Down
2 changes: 1 addition & 1 deletion third_party/bouffalolab/repo