Skip to content

Commit eed013e

Browse files
de-nordicm-alperen-sener
authored andcommitted
[nrf fromtree] Bluetooth: Mesh: Improve logic for serving devices erase capabilities
The commit fixes issue where flash_area_flatten has been used where code was only supposed to erase devices by hardware requirement prior to write, by replacing the call with flash_area_erase and supporting logic to select proper path. There have been following Kconfig options added: - CONFIG_BT_MESH_BLOB_IO_FLASH_WITHOUT_ERASE - CONFIG_BT_MESH_BLOB_IO_FLASH_WITH_ERASE that are available for user depending on devices in the system and allow to turn off paths that are not used by BLOB IO; for example if user never writes to device with erase CONFIG_BT_MESH_BLOB_IO_FLASH_WITH_ERASE will disable the path. Both Kconfig options are y by default and enable all paths. Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 49f5598)
1 parent e6f53d4 commit eed013e

File tree

2 files changed

+63
-24
lines changed

2 files changed

+63
-24
lines changed

subsys/bluetooth/mesh/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,30 @@ config BT_MESH_BLOB_IO_FLASH
10551055
Enable the BLOB flash stream for reading and writing BLOBs directly to
10561056
and from flash.
10571057

1058+
if BT_MESH_BLOB_IO_FLASH
1059+
1060+
config BT_MESH_BLOB_IO_FLASH_WITHOUT_ERASE
1061+
bool "BLOB flash support for devices without erase"
1062+
default y if FLASH_HAS_NO_EXPLICIT_ERASE
1063+
depends on FLASH_HAS_NO_EXPLICIT_ERASE
1064+
help
1065+
Enable path supporting devices without erase. This option appears only
1066+
if there are devices without explicit erase requirements in the system
1067+
and may be disabled to reduce code size in case when no operations
1068+
are intended on such type of devices.
1069+
1070+
config BT_MESH_BLOB_IO_FLASH_WITH_ERASE
1071+
bool "BLOB flash support for devices with erase"
1072+
default y if FLASH_HAS_EXPLICIT_ERASE
1073+
depends on FLASH_HAS_EXPLICIT_ERASE
1074+
help
1075+
Enable path supporting devices with erase. This option appears only
1076+
if there are devices requiring erase, before write, in the system
1077+
and may be disabled to reduce code size in case when no operations
1078+
are intended on such type of devices.
1079+
1080+
endif # BT_MESH_BLOB_IO_FLASH
1081+
10581082
config BT_MESH_DFU_SRV
10591083
bool "Support for Firmware Update Server model"
10601084
depends on BT_MESH_MODEL_EXTENSIONS

subsys/bluetooth/mesh/blob_io_flash.c

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,55 @@ static void io_close(const struct bt_mesh_blob_io *io,
5656
flash_area_close(flash->area);
5757
}
5858

59+
static inline int erase_device_block(const struct flash_area *fa, off_t start, size_t size)
60+
{
61+
/* If there are no devices requiring erase, then there is nothing to do */
62+
if (IS_ENABLED(CONFIG_BT_MESH_BLOB_IO_FLASH_WITH_ERASE)) {
63+
const struct device *fdev = flash_area_get_device(fa);
64+
65+
if (!fdev) {
66+
return -ENODEV;
67+
}
68+
69+
/* We have a mix of devices in system */
70+
if (IS_ENABLED(CONFIG_BT_MESH_BLOB_IO_FLASH_WITHOUT_ERASE)) {
71+
const struct flash_parameters *fparam = flash_get_parameters(fdev);
72+
73+
/* If device has no erase requirement then do nothing */
74+
if (!(flash_params_get_erase_cap(fparam) & FLASH_ERASE_C_EXPLICIT)) {
75+
return 0;
76+
}
77+
}
78+
79+
if (IS_ENABLED(CONFIG_FLASH_PAGE_LAYOUT)) {
80+
struct flash_pages_info page;
81+
int err;
82+
83+
err = flash_get_page_info_by_offs(fdev, start, &page);
84+
if (err) {
85+
return err;
86+
}
87+
88+
size = page.size * DIV_ROUND_UP(size, page.size);
89+
start = page.start_offset;
90+
}
91+
return flash_area_erase(fa, start, size);
92+
}
93+
94+
return 0;
95+
}
96+
5997
static int block_start(const struct bt_mesh_blob_io *io,
6098
const struct bt_mesh_blob_xfer *xfer,
6199
const struct bt_mesh_blob_block *block)
62100
{
63101
struct bt_mesh_blob_io_flash *flash = FLASH_IO(io);
64-
size_t erase_size;
65102

66103
if (flash->mode == BT_MESH_BLOB_READ) {
67104
return 0;
68105
}
69106

70-
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
71-
struct flash_pages_info page;
72-
const struct device *flash_dev;
73-
int err;
74-
75-
flash_dev = flash_area_get_device(flash->area);
76-
if (!flash_dev) {
77-
return -ENODEV;
78-
}
79-
80-
err = flash_get_page_info_by_offs(flash_dev,
81-
flash->offset + block->offset, &page);
82-
if (err) {
83-
return err;
84-
}
85-
86-
erase_size = page.size * DIV_ROUND_UP(block->size, page.size);
87-
#else
88-
erase_size = block->size;
89-
#endif
90-
91-
return flash_area_flatten(flash->area, flash->offset + block->offset,
92-
erase_size);
107+
return erase_device_block(flash->area, flash->offset + block->offset, block->size);
93108
}
94109

95110
static int rd_chunk(const struct bt_mesh_blob_io *io,

0 commit comments

Comments
 (0)