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
|
@ -60,11 +60,8 @@ struct flash_area {
|
||||||
off_t fa_off;
|
off_t fa_off;
|
||||||
/** Total size */
|
/** Total size */
|
||||||
size_t fa_size;
|
size_t fa_size;
|
||||||
/**
|
/** Backing flash device */
|
||||||
* Name of the flash device, suitable for passing to
|
const struct device *fa_dev;
|
||||||
* device_get_binding().
|
|
||||||
*/
|
|
||||||
const char *fa_dev_name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -101,7 +101,6 @@ fcb_init(int f_area_id, struct fcb *fcb)
|
||||||
int oldest = -1, newest = -1;
|
int oldest = -1, newest = -1;
|
||||||
struct flash_sector *oldest_sector = NULL, *newest_sector = NULL;
|
struct flash_sector *oldest_sector = NULL, *newest_sector = NULL;
|
||||||
struct fcb_disk_area fda;
|
struct fcb_disk_area fda;
|
||||||
const struct device *dev = NULL;
|
|
||||||
const struct flash_parameters *fparam;
|
const struct flash_parameters *fparam;
|
||||||
|
|
||||||
if (!fcb->f_sectors || fcb->f_sector_cnt - fcb->f_scratch_cnt < 1) {
|
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;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = device_get_binding(fcb->fap->fa_dev_name);
|
fparam = flash_get_parameters(fcb->fap->fa_dev);
|
||||||
fparam = flash_get_parameters(dev);
|
|
||||||
fcb->f_erase_value = fparam->erase_value;
|
fcb->f_erase_value = fparam->erase_value;
|
||||||
|
|
||||||
align = fcb_get_align(fcb);
|
align = fcb_get_align(fcb);
|
||||||
|
|
|
@ -37,7 +37,7 @@ int flash_area_open(uint8_t id, const struct flash_area **fap)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_get_binding(area->fa_dev_name) == NULL) {
|
if (!device_is_ready(area->fa_dev)) {
|
||||||
return -ENODEV;
|
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,
|
int flash_area_read(const struct flash_area *fa, off_t off, void *dst,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
const struct device *dev;
|
|
||||||
|
|
||||||
if (!is_in_flash_area_bounds(fa, off, len)) {
|
if (!is_in_flash_area_bounds(fa, off, len)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = device_get_binding(fa->fa_dev_name);
|
return flash_read(fa->fa_dev, fa->fa_off + off, dst, len);
|
||||||
|
|
||||||
return flash_read(dev, fa->fa_off + off, dst, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
|
int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
const struct device *flash_dev;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (!is_in_flash_area_bounds(fa, off, len)) {
|
if (!is_in_flash_area_bounds(fa, off, len)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_dev = device_get_binding(fa->fa_dev_name);
|
return flash_write(fa->fa_dev, fa->fa_off + off, (void *)src, len);
|
||||||
|
|
||||||
rc = flash_write(flash_dev, fa->fa_off + off, (void *)src, len);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int flash_area_erase(const struct flash_area *fa, off_t off, size_t 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)) {
|
if (!is_in_flash_area_bounds(fa, off, len)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_dev = device_get_binding(fa->fa_dev_name);
|
return flash_erase(fa->fa_dev, fa->fa_off + off, len);
|
||||||
|
|
||||||
rc = flash_erase(flash_dev, fa->fa_off + off, len);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flash_area_align(const struct flash_area *fa)
|
uint32_t flash_area_align(const struct flash_area *fa)
|
||||||
{
|
{
|
||||||
const struct device *dev;
|
return flash_get_write_block_size(fa->fa_dev);
|
||||||
|
|
||||||
dev = device_get_binding(fa->fa_dev_name);
|
|
||||||
|
|
||||||
return flash_get_write_block_size(dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int flash_area_has_driver(const struct flash_area *fa)
|
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;
|
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)
|
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)
|
uint8_t flash_area_erased_val(const struct flash_area *fa)
|
||||||
{
|
{
|
||||||
const struct flash_parameters *param;
|
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;
|
return param->erase_value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,14 @@
|
||||||
|
|
||||||
#define DT_DRV_COMPAT fixed_partitions
|
#define DT_DRV_COMPAT fixed_partitions
|
||||||
|
|
||||||
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/zephyr.h>
|
#include <zephyr/zephyr.h>
|
||||||
#include <zephyr/storage/flash_map.h>
|
#include <zephyr/storage/flash_map.h>
|
||||||
|
|
||||||
#define FLASH_AREA_FOO(part) \
|
#define FLASH_AREA_FOO(part) \
|
||||||
{.fa_id = DT_FIXED_PARTITION_ID(part), \
|
{.fa_id = DT_FIXED_PARTITION_ID(part), \
|
||||||
.fa_off = DT_REG_ADDR(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),},
|
.fa_size = DT_REG_SIZE(part),},
|
||||||
|
|
||||||
#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_FOO)
|
#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;
|
mbedtls_md_context_t mbed_hash_ctx;
|
||||||
const mbedtls_md_info_t *mbed_hash_info;
|
const mbedtls_md_info_t *mbed_hash_info;
|
||||||
#endif
|
#endif
|
||||||
const struct device *dev;
|
|
||||||
int to_read;
|
int to_read;
|
||||||
int pos;
|
int pos;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -71,7 +70,6 @@ int flash_area_check_int_sha256(const struct flash_area *fa,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dev = device_get_binding(fa->fa_dev_name);
|
|
||||||
to_read = fac->rblen;
|
to_read = fac->rblen;
|
||||||
|
|
||||||
for (pos = 0; pos < fac->clen; pos += to_read) {
|
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;
|
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);
|
fac->rbuf, to_read);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
#if defined(CONFIG_FLASH_AREA_CHECK_INTEGRITY_TC)
|
#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->ret_len = *cnt;
|
||||||
cb_data->status = 0;
|
cb_data->status = 0;
|
||||||
|
|
||||||
flash_dev = device_get_binding(fa->fa_dev_name);
|
flash_dev = fa->fa_dev;
|
||||||
flash_area_close(fa);
|
flash_area_close(fa);
|
||||||
if (flash_dev == NULL) {
|
if (flash_dev == NULL) {
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
|
@ -157,7 +157,7 @@ void test_get_flash_erase_value(void)
|
||||||
rc = flash_area_open(TEST_FCB_FLASH_AREA_ID, &fa);
|
rc = flash_area_open(TEST_FCB_FLASH_AREA_ID, &fa);
|
||||||
zassert_equal(rc, 0, "Failed top open flash area");
|
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);
|
flash_area_close(fa);
|
||||||
|
|
||||||
zassert_true(dev != NULL, "Failed to obtain device");
|
zassert_true(dev != NULL, "Failed to obtain device");
|
||||||
|
|
|
@ -166,7 +166,7 @@ void test_flash_area_erased_val(void)
|
||||||
|
|
||||||
val = flash_area_erased_val(fa);
|
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,
|
zassert_equal(param->erase_value, val,
|
||||||
"value different than the flash erase value");
|
"value different than the flash erase value");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue