storage: flash_map: remove `device_get_binding`

Remove all usage of `device_get_binding` in the subsys by directly
storing the `const struct device*` in the `struct flash_area`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2022-07-02 21:20:23 +10:00 committed by Carles Cufí
parent a6a9a35d0a
commit 4543f82c12
8 changed files with 17 additions and 45 deletions

View File

@ -60,11 +60,8 @@ struct flash_area {
off_t fa_off;
/** Total size */
size_t fa_size;
/**
* Name of the flash device, suitable for passing to
* device_get_binding().
*/
const char *fa_dev_name;
/** Backing flash device */
const struct device *fa_dev;
};
/**

View File

@ -101,7 +101,6 @@ fcb_init(int f_area_id, struct fcb *fcb)
int oldest = -1, newest = -1;
struct flash_sector *oldest_sector = NULL, *newest_sector = NULL;
struct fcb_disk_area fda;
const struct device *dev = NULL;
const struct flash_parameters *fparam;
if (!fcb->f_sectors || fcb->f_sector_cnt - fcb->f_scratch_cnt < 1) {
@ -113,8 +112,7 @@ fcb_init(int f_area_id, struct fcb *fcb)
return -EINVAL;
}
dev = device_get_binding(fcb->fap->fa_dev_name);
fparam = flash_get_parameters(dev);
fparam = flash_get_parameters(fcb->fap->fa_dev);
fcb->f_erase_value = fparam->erase_value;
align = fcb_get_align(fcb);

View File

@ -37,7 +37,7 @@ int flash_area_open(uint8_t id, const struct flash_area **fap)
return -ENOENT;
}
if (device_get_binding(area->fa_dev_name) == NULL) {
if (!device_is_ready(area->fa_dev)) {
return -ENODEV;
}
@ -54,62 +54,40 @@ void flash_area_close(const struct flash_area *fa)
int flash_area_read(const struct flash_area *fa, off_t off, void *dst,
size_t len)
{
const struct device *dev;
if (!is_in_flash_area_bounds(fa, off, len)) {
return -EINVAL;
}
dev = device_get_binding(fa->fa_dev_name);
return flash_read(dev, fa->fa_off + off, dst, len);
return flash_read(fa->fa_dev, fa->fa_off + off, dst, len);
}
int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
size_t len)
{
const struct device *flash_dev;
int rc;
if (!is_in_flash_area_bounds(fa, off, len)) {
return -EINVAL;
}
flash_dev = device_get_binding(fa->fa_dev_name);
rc = flash_write(flash_dev, fa->fa_off + off, (void *)src, len);
return rc;
return flash_write(fa->fa_dev, fa->fa_off + off, (void *)src, len);
}
int flash_area_erase(const struct flash_area *fa, off_t off, size_t len)
{
const struct device *flash_dev;
int rc;
if (!is_in_flash_area_bounds(fa, off, len)) {
return -EINVAL;
}
flash_dev = device_get_binding(fa->fa_dev_name);
rc = flash_erase(flash_dev, fa->fa_off + off, len);
return rc;
return flash_erase(fa->fa_dev, fa->fa_off + off, len);
}
uint32_t flash_area_align(const struct flash_area *fa)
{
const struct device *dev;
dev = device_get_binding(fa->fa_dev_name);
return flash_get_write_block_size(dev);
return flash_get_write_block_size(fa->fa_dev);
}
int flash_area_has_driver(const struct flash_area *fa)
{
if (device_get_binding(fa->fa_dev_name) == NULL) {
if (!device_is_ready(fa->fa_dev)) {
return -ENODEV;
}
@ -118,14 +96,14 @@ int flash_area_has_driver(const struct flash_area *fa)
const struct device *flash_area_get_device(const struct flash_area *fa)
{
return device_get_binding(fa->fa_dev_name);
return fa->fa_dev;
}
uint8_t flash_area_erased_val(const struct flash_area *fa)
{
const struct flash_parameters *param;
param = flash_get_parameters(device_get_binding(fa->fa_dev_name));
param = flash_get_parameters(fa->fa_dev);
return param->erase_value;
}

View File

@ -7,13 +7,14 @@
#define DT_DRV_COMPAT fixed_partitions
#include <zephyr/device.h>
#include <zephyr/zephyr.h>
#include <zephyr/storage/flash_map.h>
#define FLASH_AREA_FOO(part) \
{.fa_id = DT_FIXED_PARTITION_ID(part), \
.fa_off = DT_REG_ADDR(part), \
.fa_dev_name = DT_LABEL(DT_MTD_FROM_FIXED_PARTITION(part)), \
.fa_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(part)), \
.fa_size = DT_REG_SIZE(part),},
#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_FOO)

View File

@ -38,7 +38,6 @@ int flash_area_check_int_sha256(const struct flash_area *fa,
mbedtls_md_context_t mbed_hash_ctx;
const mbedtls_md_info_t *mbed_hash_info;
#endif
const struct device *dev;
int to_read;
int pos;
int rc;
@ -71,7 +70,6 @@ int flash_area_check_int_sha256(const struct flash_area *fa,
}
#endif
dev = device_get_binding(fa->fa_dev_name);
to_read = fac->rblen;
for (pos = 0; pos < fac->clen; pos += to_read) {
@ -79,7 +77,7 @@ int flash_area_check_int_sha256(const struct flash_area *fa,
to_read = fac->clen - pos;
}
rc = flash_read(dev, (fa->fa_off + fac->off + pos),
rc = flash_read(fa->fa_dev, (fa->fa_off + fac->off + pos),
fac->rbuf, to_read);
if (rc != 0) {
#if defined(CONFIG_FLASH_AREA_CHECK_INTEGRITY_TC)

View File

@ -84,7 +84,7 @@ flash_page_cb cb, struct layout_data *cb_data)
cb_data->ret_len = *cnt;
cb_data->status = 0;
flash_dev = device_get_binding(fa->fa_dev_name);
flash_dev = fa->fa_dev;
flash_area_close(fa);
if (flash_dev == NULL) {
return -ENODEV;

View File

@ -157,7 +157,7 @@ void test_get_flash_erase_value(void)
rc = flash_area_open(TEST_FCB_FLASH_AREA_ID, &fa);
zassert_equal(rc, 0, "Failed top open flash area");
dev = device_get_binding(fa->fa_dev_name);
dev = fa->fa_dev;
flash_area_close(fa);
zassert_true(dev != NULL, "Failed to obtain device");

View File

@ -166,7 +166,7 @@ void test_flash_area_erased_val(void)
val = flash_area_erased_val(fa);
param = flash_get_parameters(device_get_binding(fa->fa_dev_name));
param = flash_get_parameters(fa->fa_dev);
zassert_equal(param->erase_value, val,
"value different than the flash erase value");