@@ -155,6 +155,18 @@ typedef int (*flash_api_write)(const struct device *dev, off_t offset,
155
155
typedef int (* flash_api_erase )(const struct device * dev , off_t offset ,
156
156
size_t size );
157
157
158
+ /**
159
+ * @brief Get device size in bytes.
160
+ *
161
+ * Returns total logical device size in bytes.
162
+ *
163
+ * @param[in] dev flash device.
164
+ * @param[out] size device size in bytes.
165
+ *
166
+ * @return 0 on success, negative errno code on error.
167
+ */
168
+ typedef int (* flash_api_get_size )(const struct device * dev , uint64_t * size );
169
+
158
170
typedef const struct flash_parameters * (* flash_api_get_parameters )(const struct device * dev );
159
171
160
172
#if defined(CONFIG_FLASH_PAGE_LAYOUT )
@@ -195,6 +207,7 @@ __subsystem struct flash_driver_api {
195
207
flash_api_write write ;
196
208
flash_api_erase erase ;
197
209
flash_api_get_parameters get_parameters ;
210
+ flash_api_get_size get_size ;
198
211
#if defined(CONFIG_FLASH_PAGE_LAYOUT )
199
212
flash_api_pages_layout page_layout ;
200
213
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
@@ -321,6 +334,33 @@ static inline int z_impl_flash_erase(const struct device *dev, off_t offset,
321
334
return rc ;
322
335
}
323
336
337
+ /**
338
+ * @brief Get device size in bytes.
339
+ *
340
+ * Returns total logical device size in bytes. Not all devices may support
341
+ * returning size, specifically those with non uniform page layouts or banked,
342
+ * in which case the function will return -ENOTSUP, and user has to rely
343
+ * on Flash page layout functions enabled by CONFIG_FLASH_PAGE_LAYOUT.
344
+ *
345
+ * @param[in] dev flash device.
346
+ * @param[out] size device size in bytes.
347
+ *
348
+ * @return 0 on success, negative errno code on error.
349
+ */
350
+ __syscall int flash_get_size (const struct device * dev , uint64_t * size );
351
+
352
+ static inline int z_impl_flash_get_size (const struct device * dev , uint64_t * size )
353
+ {
354
+ int rc = - ENOSYS ;
355
+ const struct flash_driver_api * api = (const struct flash_driver_api * )dev -> api ;
356
+
357
+ if (api -> get_size != NULL ) {
358
+ rc = api -> get_size (dev , size );
359
+ }
360
+
361
+ return rc ;
362
+ }
363
+
324
364
/**
325
365
* @brief Fill selected range of device with specified value
326
366
*
0 commit comments