/* Sets the pending flag for the specified image slot. That is, the system will swap to the specified image on the next reboot. If the permanent argument is specified, the system doesn't require a confirm after the swap occurs.  */
int img_mgmt_state_set_pending(int slot, int permanent)
/* Sets the pending flag for the specified image slot. That is, the system will swap to the specified image on the next reboot. If the permanent argument is specified, the system doesn't require a confirm after the swap occurs.  */
int img_mgmt_state_set_pending(int slot, int permanent)
{
	uint8_t state_flags;
	int rc;
	state_flags = img_mgmt_state_flags(slot);
	if (state_flags & IMG_MGMT_STATE_F_CONFIRMED && slot != 0) {
		rc = IMG_MGMT_ERR_IMAGE_ALREADY_PENDING;
		goto done;
	}
	rc = img_mgmt_write_pending(slot, permanent);
done:
	return rc;
}