You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@mynewt.apache.org by "kasjer (via GitHub)" <gi...@apache.org> on 2026/10/25 20:36:18 UTC

[PR] Group flash device with link table [mynewt-core]

kasjer opened a new pull request, #3834:
URL: https://github.com/apache/mynewt-core/pull/3834

   Each BSP defined `hal_bsp_flash_dev(uint8_t id)`, implementation were very similar yet in some cases board supported additional flashes and the way function work varied.
   Most common was function that return just one flash device (main flash).
   In some BSP QSPI was also available.
   Some boards had SPI flash.
   
   Main usage of this function was `hal_flash_init()` that iterated over numbers (0..HAL_FLASH_MAX_DEVICE_COUNT) looking for device pointer to call init function for individual flash driver.
   
   Now all flash devices are put to table that get populated during link time so if another driver for flash shows up there is no need to modify hal_bsp.c
   
   Now all `hal_bsp_flash_dev()` are removed and just one is used for all boards.
   
   Old functionality is still available when `HAL_FLASH_DEV_TABLE == 0`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Group flash device with link table [mynewt-core]

Posted by "kasjer (via GitHub)" <gi...@apache.org>.
kasjer merged PR #3834:
URL: https://github.com/apache/mynewt-core/pull/3834


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Group flash device with link table [mynewt-core]

Posted by "kasjer (via GitHub)" <gi...@apache.org>.
kasjer commented on code in PR #3834:
URL: https://github.com/apache/mynewt-core/pull/3834#discussion_r4404594719


##########
hw/hal/src/hal_flash.c:
##########
@@ -28,6 +28,40 @@
 
 static uint8_t protected_flash[1];
 
+#if MYNEWT_VAL(HAL_FLASH_DEV_TABLE)
+/*
+ * Common implementation, returns flash device registered with HAL_FLASH_DEV().
+ */
+const struct hal_flash *
+hal_bsp_flash_dev(uint8_t id)
+{
+    LINK_TABLE_FOREACH(e, hal_flash_devs) {
+        if (e->id == id) {
+            return e->hf;
+        }
+    }
+
+    return NULL;
+}
+
+int
+hal_flash_init(void)
+{
+    int rc = 0;
+
+    LINK_TABLE_FOREACH(e, hal_flash_devs) {
+        /* Same id registered twice, check flash id syscfg values */
+        for (const struct hal_flash_dev_entry *d = hal_flash_devs; d != e; ++d) {
+            assert(d->id != e->id);
+        }
+        if (e->hf->hf_itf->hff_init(e->hf)) {

Review Comment:
   now is sorted by id (kind of 0 to 9) during link time 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Group flash device with link table [mynewt-core]

Posted by "andrzej-kaczmarek (via GitHub)" <gi...@apache.org>.
andrzej-kaczmarek commented on code in PR #3834:
URL: https://github.com/apache/mynewt-core/pull/3834#discussion_r4372895841


##########
hw/hal/syscfg.yml:
##########
@@ -53,7 +53,7 @@ syscfg.defs:
             flash devices registered with HAL_FLASH_DEV() (hal_flash_devs
             link table). Set to 0 when BSP provides its own
             hal_bsp_flash_dev().
-        value: 0
+        value: 1

Review Comment:
   this probably breaks babblesim target in nimble so would be nice to fix it there



##########
hw/hal/src/hal_flash.c:
##########
@@ -28,6 +28,40 @@
 
 static uint8_t protected_flash[1];
 
+#if MYNEWT_VAL(HAL_FLASH_DEV_TABLE)
+/*
+ * Common implementation, returns flash device registered with HAL_FLASH_DEV().
+ */
+const struct hal_flash *
+hal_bsp_flash_dev(uint8_t id)
+{
+    LINK_TABLE_FOREACH(e, hal_flash_devs) {
+        if (e->id == id) {
+            return e->hf;
+        }
+    }
+
+    return NULL;
+}
+
+int
+hal_flash_init(void)
+{
+    int rc = 0;
+
+    LINK_TABLE_FOREACH(e, hal_flash_devs) {
+        /* Same id registered twice, check flash id syscfg values */
+        for (const struct hal_flash_dev_entry *d = hal_flash_devs; d != e; ++d) {
+            assert(d->id != e->id);
+        }
+        if (e->hf->hf_itf->hff_init(e->hf)) {

Review Comment:
   would be probably more intuitive to initialize flash devs sorted by id, not by name



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org