typedef struct _hal_backend_board_funcs {
/* Serial number of this device */
- int (*get_device_serial_number)(char *buffer, int len);
+ int (*get_device_serial_number)(char *buffer, const int max_len);
int (*get_device_revision)(int *revision);
int (*set_boot_success)(void);
int (*clear_boot_mode)(void);
- int (*get_boot_mode)(char *buffer, int len);
- int (*get_boot_reason)(char *buffer, int len);
+ int (*get_boot_mode)(char *buffer, const int max_len);
+ int (*get_boot_reason)(char *buffer, const int max_len);
int (*get_current_partition)(char *partition_ab);
int (*switch_partition)(char partition_ab);
int (*set_partition_ab_cloned)(void);
int (*clear_partition_ab_cloned)(void);
int (*get_partition_ab_cloned)(int *cloned);
+ int (*set_partition_status)(char partition_ab, const char *status);
+ int (*get_partition_status)(char partition_ab, char *buffer, const int max_len);
int (*set_upgrade_status)(int status);
int (*get_upgrade_status)(int *status);
/**
* @brief Get device serial number and save it to a buffer
*
- * @param[in] len Buffer size
+ * @param[in] max_len Buffer size
* @param[out] buffer Serial number
*
+ * At most (max_len - 1) bytes of the serial number string will be copied to the buffer argument,
+ * and NULL is finally appended.
+ *
* @return 0 on success, otherwise a negative error value
*/
-int hal_device_board_get_device_serial_number(char *buffer, int len);
+int hal_device_board_get_device_serial_number(char *buffer, const int max_len);
/**
* @brief Get device revision (not in use, no hal backend function)
/**
* @brief Get the boot mode ("fota", "recovery", "normal")
*
- * @param[in] len Buffer size
+ * @param[in] max_len Buffer size
* @param[out] buffer boot mode
*
+ * At most (max_len - 1) bytes of the boot mode string will be copied to the buffer argument,
+ * and NULL is finally appended.
+ *
* @return 0 on success, otherwise a negative error value
*/
-int hal_device_board_get_boot_mode(char *buffer, int len);
+int hal_device_board_get_boot_mode(char *buffer, const int max_len);
/**
* @brief Get the boot reason (not in use)
*
- * @param[in] len Buffer size
- * @param[out] buffer boot mode
+ * @param[in] max_len Buffer size
+ * @param[out] buffer boot reason
+ *
+ * At most (max_len - 1) bytes of the boot reason string will be copied to the buffer argument,
+ * and NULL is finally appended.
*
* @return 0 on success, otherwise a negative error value
*/
-int hal_device_board_get_boot_reason(char *buffer, int len);// not in use
+int hal_device_board_get_boot_reason(char *buffer, const int max_len);
/**
*/
int hal_device_board_get_partition_ab_cloned(int *cloned);
+/**
+ * @brief Set the partition_status flag
+ *
+ * @param[in] partition_ab Partition slot ('a', 'b', '\0')(if '\0' then current partition)
+ * @param[in] status Status of partition ("ok", "failed", "corrupted")
+ *
+ * @return 0 on success, otherwise a negative error value
+ */
+int hal_device_board_set_partition_status(char partition_ab, const char *status);
+
+/**
+ * @brief Set the partition_status flag
+ *
+ * @param[in] partition_ab Partition slot ('a', 'b', '\0')(if '\0' then current partition)
+ * @param[out] buffer Status of partition
+ * @param[in] max_len Buffer size
+ *
+ * Examples status strings are: "ok", "failed", "corrupted"
+ * At most (max_len - 1) bytes of the status string will be copied to the buffer argument,
+ * and NULL is finally appended.
+ *
+ * @return 0 on success, otherwise a negative error value
+ */
+int hal_device_board_get_partition_status(char partition_ab, char *buffer, const int max_len);
+
/**
* @brief Set upgrade status
return 0;
}
-int hal_device_board_get_device_serial_number(char *buffer, int len)
+int hal_device_board_get_device_serial_number(char *buffer, const int max_len)
{
int ret ;
!hal_board_funcs->get_device_serial_number)
return -ENODEV;
- return hal_board_funcs->get_device_serial_number(buffer, len);
+ return hal_board_funcs->get_device_serial_number(buffer, max_len);
}
int hal_device_board_get_device_revision(int *revision)
return hal_board_funcs->clear_boot_mode();
}
-int hal_device_board_get_boot_mode(char *buffer, int len)
+int hal_device_board_get_boot_mode(char *buffer, const int max_len)
{
int ret;
!hal_board_funcs->get_boot_mode)
return -ENODEV;
- return hal_board_funcs->get_boot_mode(buffer, len);
+ return hal_board_funcs->get_boot_mode(buffer, max_len);
}
-int hal_device_board_get_boot_reason(char *buffer, int len)
+int hal_device_board_get_boot_reason(char *buffer, const int max_len)
{
int ret;
!hal_board_funcs->get_boot_reason)
return -ENODEV;
- return hal_board_funcs->get_boot_reason(buffer, len);
+ return hal_board_funcs->get_boot_reason(buffer, max_len);
}
int hal_device_board_get_current_partition(char *partition_ab)
return hal_board_funcs->get_partition_ab_cloned(cloned);
}
+int hal_device_board_set_partition_status(char partition_ab, const char *status)
+{
+ int ret;
+
+ if (!hal_board_funcs && !hal_initialized) {
+ if ((ret = hal_device_board_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_board_funcs ||
+ !hal_board_funcs->set_partition_status)
+ return -ENODEV;
+
+ return hal_board_funcs->set_partition_status(partition_ab, status);
+}
+
+int hal_device_board_get_partition_status(char partition_ab, char *buffer, const int max_len)
+{
+ int ret;
+
+ if (!hal_board_funcs && !hal_initialized) {
+ if ((ret = hal_device_board_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_board_funcs ||
+ !hal_board_funcs->get_partition_status)
+ return -ENODEV;
+
+ return hal_board_funcs->get_partition_status(partition_ab, buffer, max_len);
+}
+
int hal_device_board_set_upgrade_status(int status)
{
int ret;