Bugfix/fix bluetooth bt tool log moudle cb change to const#447
Bugfix/fix bluetooth bt tool log moudle cb change to const#447huangyulong3 wants to merge 29 commits intoopen-vela:devfrom
Conversation
…k to const for reduce the ram size. bug: v/84934 Rootcause: To reduce RAM resource consumption, the `adv_callback` in the ble impl module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…re_gattc_cbs to const for reduce the ram size. bug: v/84935 Rootcause: To reduce RAM resource consumption, the `s_feature_gattc_cbs` in the gatt feature module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…v_callback to const for reduce the ram size. bug: v/84941 Rootcause: To reduce RAM resource consumption, the `g_advertiser_socket_cb` in the socket advertiser module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…back to const for reduce the ram size. bug: v/84944 Rootcause: To reduce RAM resource consumption, the `g_advertiser_socket_cb` in the socket scan module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…ket_cb to const for reduce the ram size. bug: v/84945 Rootcause: To reduce RAM resource consumption, the `g_spp_socket_cb` in the socket spp module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…o const for reduce the ram size. bug:v/84946 Rootcause: To reduce RAM resource consumption, the `deviceInterface` in the hid device service module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
… for reduce the ram size. bug:v/84947 Rootcause: To reduce RAM resource consumption, the `sppInterface` in the spp service module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…o const for reduce the ram size. bug:v/84950 Rootcause: To reduce RAM resource consumption, the `stream_ops` in the sal a2dp interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…e to const for reduce the ram size. bug:v/84951 Rootcause: To reduce RAM resource consumption, the `g_conn_cbs`, `g_setting_cbs`, `g_conn_auth_info_cbs`and `g_br_discovery_cb`, in the sal adapter interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…dule to const for reduce the ram size. bug:v/84952 Rootcause: To reduce RAM resource consumption, the `g_conn_auth_info_cbs`, `g_conn_cbs`, and `g_setting_cbs` in the sal adapter interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size. bug:v/84953 Rootcause: To reduce RAM resource consumption, the `avrcp_tg_cbks`, in the sal avrcp interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… to const for reduce the ram size. bug:v/84954 Rootcause: To reduce RAM resource consumption, the `g_hfp_ag_cb`, in the sal hfp ag interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…e to const for reduce the ram size. bug:v/84956 Rootcause: To reduce RAM resource consumption, the `hf_callbacks`, in the sal hfp hf interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM.
…dule to const for reduce the ram size. bug:v/84957 Rootcause: To reduce RAM resource consumption, the `hid_attrs_template` and `hid_callback`, in the sal hid device interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM.
…dule to const for reduce the ram size. bug:v/84958 Rootcause: To reduce RAM resource consumption, the `spp_attrs_template` and `g_rfcomm_ops`, in the sal spp interface module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size. bug:v/84959 Rootcause: To reduce RAM resource consumption, the `g_a2dp_tables`, in the bt_tools a2dp source module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… for reduce the ram size. bug:v/84960 Rootcause: To reduce RAM resource consumption, the `adv_options`,a dv_stop_options, `g_adv_tables` and `adv_callback` in the bt_tools adv module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… const for reduce the ram size. bug:v/84961 Rootcause: To reduce RAM resource consumption, the `adv_options`, `adv_stop_options`, `g_adv_async_tables` and `adv_callback` in the bt_tools async adv module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… const for reduce the ram size. bug:v/84961 Rootcause: To reduce RAM resource consumption, the `le_conn_options`, `g_set_cmd_tables`, `g_get_cmd_tables` and `g_pair_cmd_tables` in the bt_tools async gap module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…odule to const for reduce the ram size. bug:v/84966 Rootcause: To reduce RAM resource consumption, the `g_gattc_async_tables`, `gattc_cbs`, in the bt_tools async gatt client module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… for reduce the ram size. bug:v/84967 Rootcause: To reduce RAM resource consumption, the `g_log_async_tables`, in the bt_tools log module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…t for reduce the ram size. bug:v/84968 Rootcause: To reduce RAM resource consumption, the `scan_options`, in the bt_tools scan module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… reduce the ram size. bug:v/84969 Rootcause: To reduce RAM resource consumption, the `le_conn_options`, `g_cmd_tables`, `g_set_cmd_tables` and `g_pair_cmd_tables` in the bt_tools module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size.
bug:v/84970
Rootcause: To reduce RAM resource consumption, the `g_gattc_tables`,
`gattc_cbs`,
in the bt_tools gatt client module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.
Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size. bug:v/84971 Rootcause: To reduce RAM resource consumption, the `s_dis_attr_db`, `s_bas_attr_db`, `s_iot_attr_db`, `g_gatts_tables` in the bt_tools gatt server module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…nst for reduce the ram size. bug:v/84972 Rootcause: To reduce RAM resource consumption, the `g_hfp_ag_tables`, in the bt_tools hfp ag module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…nst for reduce the ram size. bug:v/84973 Rootcause: To reduce RAM resource consumption, the `g_hfp_tables`, in the bt_tools hfp hf module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…o const for reduce the ram size. bug:v/84974 Rootcause: To reduce RAM resource consumption, the `g_hidd_tables`, in the bt_tools hid device module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… for reduce the ram size. bug:v/84975 Rootcause: To reduce RAM resource consumption, the `g_log_tables`, in the bt_tools log module must be marked with the `const` modifier. This ensures it is compiled and linked into Flash memory instead of RAM. Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
There was a problem hiding this comment.
Pull request overview
This PR optimizes memory usage by marking static data structures as const, which causes them to be placed in Flash/ROM instead of RAM. The changes affect multiple Bluetooth tool modules and service stack interfaces.
Changes:
- Mark command tables, callback structures, option structures, and GATT attribute databases as
constacross multiple tool modules - Add necessary type casts when passing const-qualified structures to APIs that expect non-const pointers
- Add forward declarations in service stack files where needed
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/log.c | Mark log command table as const, add cast when passing to execute function |
| tools/hid_device.c | Mark HID device command table as const, add cast |
| tools/hfp_hf.c | Mark HFP HF command table as const, add cast |
| tools/hfp_ag.c | Mark HFP AG command table as const, add cast |
| tools/gatt_server.c | Mark GATT attribute databases and command table as const, add casts for attribute databases |
| tools/gatt_client.c | Mark GATT client command table and callbacks as const, add casts |
| tools/bt_tools.c | Mark multiple command tables and connection options as const, add casts |
| tools/async/scan.c | Mark scan options and command table as const, add cast |
| tools/async/log.c | Mark async log command table as const, add cast |
| tools/async/gatt_client.c | Mark async GATT client tables and callbacks as const, add casts |
| tools/async/gap.c | Mark multiple command tables and connection options as const, add casts |
| tools/async/adv.c | Mark advertising options, stop options, command table, and callbacks as const, add casts |
| tools/adv.c | Mark advertising options, stop options, command table, and callbacks as const, add casts |
| tools/a2dp_source.c | Mark A2DP source command table as const, add cast |
| service/stacks/zephyr/sal_spp_interface.c | Mark SDP attributes and RFCOMM ops as const, add casts |
| service/stacks/zephyr/sal_hid_device_interface.c | Mark SDP attributes and HID callbacks as const, add casts |
| service/stacks/zephyr/sal_hfp_hf_interface.c | Mark HFP HF callbacks as const, add cast |
| service/stacks/zephyr/sal_hfp_ag_interface.c | Mark HFP AG callbacks as const, add cast |
| service/stacks/zephyr/sal_avrcp_interface.c | Mark AVRCP target callbacks as const |
| service/stacks/zephyr/sal_adapter_le_interface.c | Mark BLE connection callbacks and settings callbacks as const, add casts, add forward declarations |
| service/stacks/zephyr/sal_adapter_interface.c | Mark BR/EDR connection callbacks, discovery callbacks, and settings callbacks as const, add casts |
| service/stacks/zephyr/sal_a2dp_interface.c | Mark A2DP codec info, stream ops, and callbacks as const, add casts |
| service/profiles/spp/spp_service.c | Mark SPP interface as const |
| service/profiles/hid/hid_device_service.c | Mark HID device interface as const |
| service/ipc/socket/src/bt_socket_spp.c | Mark SPP socket callbacks as const, add cast |
| service/ipc/socket/src/bt_socket_scan.c | Mark scanner socket callbacks as const, add cast |
| service/ipc/socket/src/bt_socket_advertiser.c | Mark advertiser socket callbacks as const, add cast |
| framework/btwrap/async/bt_gatt_feature.c | Mark GATT feature callbacks as const, add cast |
| feature/feature_async/src/bluetooth_ble_impl.c | Mark advertising callbacks and GATT client callbacks as const, add casts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (argc > 0) | ||
| ret = execute_command_in_table(handle, g_log_tables, ARRAY_SIZE(g_log_tables), argc, argv); | ||
| ret = execute_command_in_table(handle, (bt_command_t *)g_log_tables, ARRAY_SIZE(g_log_tables), argc, argv); |
There was a problem hiding this comment.
The cast from const bt_command_t * to bt_command_t * discards the const qualifier. While this change optimizes memory by placing the data in Flash/ROM instead of RAM, it relies on the assumption that the execute_command_in_table function doesn't modify the table. This is technically undefined behavior if the function were to attempt modification. Consider updating the API signature of execute_command_in_table to accept const bt_command_t* instead, which would eliminate the need for casting and maintain type safety.
| } | ||
|
|
||
| if (bt_gattc_create_connect(handle, &g_gattc_devies[conn_id].handle, &gattc_cbs) != BT_STATUS_SUCCESS) | ||
| if (bt_gattc_create_connect(handle, &g_gattc_devies[conn_id].handle, (gattc_callbacks_t *)&gattc_cbs) != BT_STATUS_SUCCESS) |
There was a problem hiding this comment.
The cast from const gattc_callbacks_t * to gattc_callbacks_t * discards the const qualifier. While this achieves RAM savings, it relies on the assumption that bt_gattc_create_connect doesn't modify the callbacks structure. Consider updating the callback registration API to accept const gattc_callbacks_t* instead, which would be more type-safe and eliminate the need for casting.
| static int level_cmd(void* handle, int argc, char* argv[]); | ||
|
|
||
| static bt_command_t g_log_tables[] = { | ||
| static const bt_command_t g_log_tables[] = { |
There was a problem hiding this comment.
Typo in PR title: "moudle" should be "module".
| static le_conn_info_t* le_conn_add(const bt_address_t* addr); | ||
| static le_conn_info_t* le_conn_find(const bt_address_t* addr); | ||
|
|
There was a problem hiding this comment.
The forward declarations for le_conn_add and le_conn_find appear to be unnecessary additions. These functions are not referenced in the const structure g_conn_cbs defined immediately after (lines 113-123), so forward declarations are not required for the const qualification changes in this file.
| static le_conn_info_t* le_conn_add(const bt_address_t* addr); | |
| static le_conn_info_t* le_conn_find(const bt_address_t* addr); |
| static int level_cmd(void* handle, int argc, char* argv[]); | ||
|
|
||
| static bt_command_t g_log_tables[] = { | ||
| static const bt_command_t g_log_tables[] = { |
There was a problem hiding this comment.
The PR title and description mention only "log module" changes, but this change affects multiple modules beyond just log (hid_device, hfp_hf, hfp_ag, gatt_server, gatt_client, bt_tools, adv, a2dp_source, and their async variants). While this is beneficial for memory optimization, the PR description should be updated to accurately reflect the broader scope of changes.
Memory Optimization: Change the bluetooth bt_tool log module to const for reduce the ram size.
bug:v/84975
Rootcause: To reduce RAM resource consumption, the
g_log_tables,in the bt_tools log module must be marked with the
constmodifier.This ensures it is compiled and linked into Flash memory instead of RAM.