Skip to content

Commit

Permalink
Add force option to firmware update command
Browse files Browse the repository at this point in the history
The force option will ignore any existing update command thats in
progress. The should only be used if an update gets interrupted and you
are sure no other update is actually running.
  • Loading branch information
lsgunth authored and Kelvin Cao committed Jan 22, 2018
1 parent 91d9f8f commit acc21d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ static int fw_update(int argc, char **argv)
const char *img_filename;
int assume_yes;
int dont_activate;
int force;
int set_boot_rw;
} cfg = {};
const struct argconfig_options opts[] = {
Expand All @@ -1024,6 +1025,9 @@ static int fw_update(int argc, char **argv)
{"dont-activate", 'A', "", CFG_NONE, &cfg.dont_activate, no_argument,
"don't activate the new image, use fw-toggle to do so "
"when it is safe"},
{"force", 'f', "", CFG_NONE, &cfg.force, no_argument,
"force interrupting an existing fw-update command in case "
"firmware is stuck in the busy state"},
{"set-boot-rw", 'W', "", CFG_NONE, &cfg.set_boot_rw, no_argument,
"set the bootloader partition as RW (only valid for BOOT images)"},
{NULL}};
Expand Down Expand Up @@ -1059,7 +1063,7 @@ static int fw_update(int argc, char **argv)

progress_start();
ret = switchtec_fw_write_file(cfg.dev, cfg.fimg, cfg.dont_activate,
progress_update);
cfg.force, progress_update);
fclose(cfg.fimg);

if (ret) {
Expand Down
4 changes: 2 additions & 2 deletions inc/switchtec/switchtec.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ int switchtec_fw_wait(struct switchtec_dev *dev,
int switchtec_fw_toggle_active_partition(struct switchtec_dev *dev,
int toggle_fw, int toggle_cfg);
int switchtec_fw_write_fd(struct switchtec_dev *dev, int img_fd,
int dont_activate,
int dont_activate, int force,
void (*progress_callback)(int cur, int tot));
int switchtec_fw_write_file(struct switchtec_dev *dev, FILE *fimg,
int dont_activate,
int dont_activate, int force,
void (*progress_callback)(int cur, int tot));
int switchtec_fw_read_fd(struct switchtec_dev *dev, int fd,
unsigned long addr, size_t len,
Expand Down
12 changes: 8 additions & 4 deletions lib/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ struct cmd_fwdl {
* @brief Write a firmware file to the switchtec device
* @param[in] dev Switchtec device handle
* @param[in] img_fd File descriptor for the image file to write
* @param[in] force If 1, ignore if another download command is
* already in progress.
* @param[in] dont_activate If 1, the new image will not be activated
* @param[in] progress_callback If not NULL, this function will be called to
* indicate the progress.
* @return 0 on success, error code on failure
*/
int switchtec_fw_write_fd(struct switchtec_dev *dev, int img_fd,
int dont_activate,
int dont_activate, int force,
void (*progress_callback)(int cur, int tot))
{
enum switchtec_fw_dlstatus status;
Expand All @@ -178,7 +180,7 @@ int switchtec_fw_write_fd(struct switchtec_dev *dev, int img_fd,

switchtec_fw_dlstatus(dev, &status, &bgstatus);

if (status == SWITCHTEC_DLSTAT_INPROGRESS) {
if (!force && status == SWITCHTEC_DLSTAT_INPROGRESS) {
errno = EBUSY;
return -EBUSY;
}
Expand Down Expand Up @@ -245,12 +247,14 @@ int switchtec_fw_write_fd(struct switchtec_dev *dev, int img_fd,
* @param[in] dev Switchtec device handle
* @param[in] fimg FILE pointer for the image file to write
* @param[in] dont_activate If 1, the new image will not be activated
* @param[in] force If 1, ignore if another download command is
* already in progress.
* @param[in] progress_callback If not NULL, this function will be called to
* indicate the progress.
* @return 0 on success, error code on failure
*/
int switchtec_fw_write_file(struct switchtec_dev *dev, FILE *fimg,
int dont_activate,
int dont_activate, int force,
void (*progress_callback)(int cur, int tot))
{
enum switchtec_fw_dlstatus status;
Expand All @@ -271,7 +275,7 @@ int switchtec_fw_write_file(struct switchtec_dev *dev, FILE *fimg,

switchtec_fw_dlstatus(dev, &status, &bgstatus);

if (status == SWITCHTEC_DLSTAT_INPROGRESS) {
if (!force && status == SWITCHTEC_DLSTAT_INPROGRESS) {
errno = EBUSY;
return -EBUSY;
}
Expand Down

0 comments on commit acc21d2

Please sign in to comment.