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:
parent
a6a9a35d0a
commit
4543f82c12
8 changed files with 17 additions and 45 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue