summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--polux/devkit/plcd/src/plcd_autoswitch.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/polux/devkit/plcd/src/plcd_autoswitch.c b/polux/devkit/plcd/src/plcd_autoswitch.c
index a94ce20d82..fd3d1d84f5 100644
--- a/polux/devkit/plcd/src/plcd_autoswitch.c
+++ b/polux/devkit/plcd/src/plcd_autoswitch.c
@@ -89,6 +89,40 @@ plcd_autoswitch_handler (int evt)
}
}
+static void
+plcd_autoswitch_image_update (void)
+{
+ spidcom_image_desc_t img_desc[2];
+ char mtd_name[32] = {0};
+
+ if (spidlib_get_image_desc (SPIDLIB_IMAGE_DESC_TYPE_ALTERNATE,
+ &img_desc[1], mtd_name) != 0)
+ {
+ syslog (LOG_WARNING, "%s: unable to retrieve alternate image desc", __FUNCTION__);
+ return;
+ }
+ if (spidlib_get_image_desc (SPIDLIB_IMAGE_DESC_TYPE_CURRENT,
+ &img_desc[0], mtd_name) != 0)
+ {
+ syslog (LOG_WARNING, "%s: unable to retrieve current image desc", __FUNCTION__);
+ return;
+ }
+
+ /* First check if we really need to update the index:
+ * - is it greater than the alternate
+ * - is the alternate OK_ORIGIN
+ * - is the alternate valid */
+ if ((img_desc[0].index > img_desc[1].index)
+ || (img_desc[1].index == SPIDCOM_IMG_DESC_ORIGIN_INDEX)
+ || !img_desc[1].is_valid)
+ {
+ syslog (LOG_INFO, "%s: current image index update not required for autoswitch", __FUNCTION__);
+ return;
+ }
+
+ spidlib_image_update_current_index (img_desc[1].index + 1, mtd_name);
+}
+
void
plcd_autoswitch_timer_init (void)
{
@@ -173,5 +207,7 @@ plcd_autoswitch_timer_stop (void)
setitimer (ITIMER_REAL, &its, NULL);
autoswitch_timer_alive = 0;
+
+ plcd_autoswitch_image_update ();
}
}