Skip to content

Commit

Permalink
move work handling to imx_sdp
Browse files Browse the repository at this point in the history
The work handling code interacts with imx_sdp much more, hence
moving removes three functions from the external interface.

This also avoids code dupplication between imx_usb and imx_uart.

Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
  • Loading branch information
Stefan Agner committed Apr 25, 2018
1 parent 871a070 commit e90fa1b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 139 deletions.
145 changes: 103 additions & 42 deletions imx_sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static int write_memory(struct sdp_dev *dev, unsigned addr, unsigned val)
return err;
}

void perform_mem_work(struct sdp_dev *dev, struct mem_work *mem)
static void perform_mem_work(struct sdp_dev *dev, struct mem_work *mem)
{
unsigned tmp, tmp2;

Expand All @@ -307,6 +307,46 @@ void perform_mem_work(struct sdp_dev *dev, struct mem_work *mem)
}
}

static int do_status(struct sdp_dev *dev)
{
struct sdp_command status_command = {
.cmd = SDP_ERROR_STATUS,
.addr = 0,
.format = 0,
.cnt = 0,
.data = 0,
.rsvd = 0};
unsigned int hab_security, status;
int retry = 0;
int err;

err = do_command(dev, &status_command, 5);
if (err)
return err;

while (retry < 5) {
err = do_response(dev, 3, &hab_security, false);
if (!err)
break;

retry++;
}

if (err)
return err;

printf("HAB security state: %s (0x%08x)\n", hab_security == HAB_SECMODE_PROD ?
"production mode" : "development mode", hab_security);

if (dev->mode == MODE_HID) {
err = do_response(dev, 4, &status, false);
if (err)
return err;
}

return 0;
}

static int do_data_transfer(struct sdp_dev *dev, unsigned char *buf, int len)
{
int err;
Expand Down Expand Up @@ -1206,46 +1246,6 @@ static int get_dl_start(struct sdp_dev *dev, unsigned char *p,
return 0;
}

int do_status(struct sdp_dev *dev)
{
struct sdp_command status_command = {
.cmd = SDP_ERROR_STATUS,
.addr = 0,
.format = 0,
.cnt = 0,
.data = 0,
.rsvd = 0};
unsigned int hab_security, status;
int retry = 0;
int err;

err = do_command(dev, &status_command, 5);
if (err)
return err;

while (retry < 5) {
err = do_response(dev, 3, &hab_security, false);
if (!err)
break;

retry++;
}

if (err)
return err;

printf("HAB security state: %s (0x%08x)\n", hab_security == HAB_SECMODE_PROD ?
"production mode" : "development mode", hab_security);

if (dev->mode == MODE_HID) {
err = do_response(dev, 4, &status, false);
if (err)
return err;
}

return 0;
}

static unsigned offset_search_list[] = {0, 0x400, 0x8400};

static int process_header(struct sdp_dev *dev, struct sdp_work *curr,
Expand Down Expand Up @@ -1356,7 +1356,7 @@ static int process_header(struct sdp_dev *dev, struct sdp_work *curr,
return -EINVAL;
}

int DoIRomDownload(struct sdp_dev *dev, struct sdp_work *curr, int verify)
static int do_download(struct sdp_dev *dev, struct sdp_work *curr, int verify)
{
int ret;
struct load_desc ld = {};
Expand Down Expand Up @@ -1434,3 +1434,64 @@ int DoIRomDownload(struct sdp_dev *dev, struct sdp_work *curr, int verify)
return ret;
}

int do_work(struct sdp_dev *p_id, struct sdp_work **work, int verify)
{
struct sdp_work *curr = *work;
int err = 0;

err = do_status(p_id);
if (err) {
fprintf(stderr, "status failed\n");
return err;
}

while (curr) {
/* Do current job */
if (curr->mem)
perform_mem_work(p_id, curr->mem);
if (curr->filename[0])
err = do_download(p_id, curr, verify);
if (err) {
fprintf(stderr, "do_download failed, err=%d\n", err);
do_status(p_id);
break;
}

/* Check if more work is to do... */
if (!curr->next) {
/*
* If only one job, but with a plug-in is specified
* reexecute the same job, but this time download the
* image. This allows to specify a single file with
* plugin and image, and imx_usb will download & run
* the plugin first and then the image.
* NOTE: If the file does not contain a plugin,
* DoIRomDownload->process_header will set curr->plug
* to 0, so we won't download the same image twice...
*/
if (curr->plug) {
curr->plug = 0;
} else {
curr = NULL;
break;
}
} else {
curr = curr->next;
}

/*
* Check if device is still here, otherwise return
* with work (retry)
*/
err = do_status(p_id);
if (err < 0) {
err = 0;
break;
}
}

*work = curr;

return err;
}

5 changes: 1 addition & 4 deletions imx_sdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ struct sdp_command {
void dump_long(unsigned char *src, unsigned cnt, unsigned addr, unsigned skip);
void dump_bytes(unsigned char *src, unsigned cnt, unsigned addr);

void perform_mem_work(struct sdp_dev *dev, struct mem_work *mem);
int do_status(struct sdp_dev *dev);

int DoIRomDownload(struct sdp_dev *dev, struct sdp_work *curr, int verify);
int do_work(struct sdp_dev *p_id, struct sdp_work **work, int verify);

#endif /* __IMX_SDP_H__ */
34 changes: 2 additions & 32 deletions imx_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,43 +419,13 @@ int main(int argc, char * const argv[])
// UART private pointer is TTY file descriptor...
p_id->priv = &uart_fd;

err = do_status(p_id);
if (err) {
printf("status failed\n");
goto out;
}

// By default, use work from config file...
if (curr == NULL)
curr = p_id->work;

while (curr) {
if (curr->mem)
perform_mem_work(p_id, curr->mem);
// printf("jump_mode %x\n", curr->jump_mode);
if (curr->filename[0]) {
err = DoIRomDownload(p_id, curr, verify);
}
if (err) {
err = do_status(p_id);
break;
}
if (!curr->next && !curr->plug)
break;
err = do_status(p_id);
printf("jump_mode %x plug=%i err=%i\n", curr->jump_mode, curr->plug, err);

if (err)
goto out;

if (curr->plug) {
curr->plug = 0;
continue;
}
curr = curr->next;
}
err = do_work(p_id, &curr, verify);
dbg_printf("do_work finished with err=%d, curr=%p\n", err, curr);

out:
uart_close(&uart_fd, &orig);
return err;
}
61 changes: 0 additions & 61 deletions imx_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,67 +385,6 @@ void print_usage(void)
"is being used.\n");
}

int do_work(struct sdp_dev *p_id, struct sdp_work **work, int verify)
{
struct sdp_work *curr = *work;
int err = 0;

err = do_status(p_id);
if (err) {
fprintf(stderr, "status failed\n");
return err;
}

while (curr) {
/* Do current job */
if (curr->mem)
perform_mem_work(p_id, curr->mem);
if (curr->filename[0])
err = DoIRomDownload(p_id, curr, verify);
if (err) {
fprintf(stderr, "DoIRomDownload failed, err=%d\n", err);
do_status(p_id);
break;
}

/* Check if more work is to do... */
if (!curr->next) {
/*
* If only one job, but with a plug-in is specified
* reexecute the same job, but this time download the
* image. This allows to specify a single file with
* plugin and image, and imx_usb will download & run
* the plugin first and then the image.
* NOTE: If the file does not contain a plugin,
* DoIRomDownload->process_header will set curr->plug
* to 0, so we won't download the same image twice...
*/
if (curr->plug) {
curr->plug = 0;
} else {
curr = NULL;
break;
}
} else {
curr = curr->next;
}

/*
* Check if device is still here, otherwise return
* with work (retry)
*/
err = do_status(p_id);
if (err < 0) {
err = 0;
break;
}
}

*work = curr;

return err;
}

int do_simulation_dev(char const *base_path, char const *conf_path,
struct mach_id *list, int verify, struct sdp_work *cmd_head,
char const *vidpid)
Expand Down

0 comments on commit e90fa1b

Please sign in to comment.