mirror of
git://projects.qi-hardware.com/xburst-tools.git
synced 2024-11-29 09:06:14 +02:00
Implemented transfer progress
This commit is contained in:
parent
9679d05aa0
commit
9773d34f38
45
ingenic.c
45
ingenic.c
@ -34,6 +34,12 @@
|
|||||||
#define CPUID(id) ((id) & 0xFFFF)
|
#define CPUID(id) ((id) & 0xFFFF)
|
||||||
#define CMDSET(id) (((id) & 0xFFFF0000) >> 16)
|
#define CMDSET(id) (((id) & 0xFFFF0000) >> 16)
|
||||||
|
|
||||||
|
#define CFGOPT(name, var, exp) { char *str = cfg_getenv(name); if(str == NULL) { debug(LEVEL_ERROR, "%s is not set\n", name); errno = EINVAL; return -1; }; int v = atoi(str); if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", name, #exp); return -1; }; handle->cfg.var = v; }
|
||||||
|
|
||||||
|
#define NOPT(name, var, exp) { char *str = cfg_getenv("NAND_" name); if(str == NULL) { debug(LEVEL_ERROR, "%s is not set\n", "NAND_" name); errno = EINVAL; return -1; }; int v = atoi(str); if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", "NAND_" name, #exp); return -1; }; handle->nand.nand_##var = v; }
|
||||||
|
|
||||||
|
#define CALLBACK(function, ...) if(handle->callbacks && handle->callbacks->function) handle->callbacks->function(__VA_ARGS__, handle->callbacks_data)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *usb;
|
void *usb;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
@ -138,8 +144,9 @@ int ingenic_redetect(void *hndl) {
|
|||||||
|
|
||||||
handle->type = type;
|
handle->type = type;
|
||||||
|
|
||||||
if(CMDSET(prev) != CMDSET(type) && handle->callbacks && handle->callbacks->cmdset_change)
|
if(CMDSET(prev) != CMDSET(type)) {
|
||||||
handle->callbacks->cmdset_change(handle->callbacks_data);
|
CALLBACK(cmdset_change, CMDSET(type));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -169,10 +176,6 @@ void ingenic_close(void *hndl) {
|
|||||||
free(handle);
|
free(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CFGOPT(name, var, exp) { char *str = cfg_getenv(name); if(str == NULL) { debug(LEVEL_ERROR, "%s is not set\n", name); errno = EINVAL; return -1; }; int v = atoi(str); if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", name, #exp); return -1; }; handle->cfg.var = v; }
|
|
||||||
|
|
||||||
#define NOPT(name, var, exp) { char *str = cfg_getenv("NAND_" name); if(str == NULL) { debug(LEVEL_ERROR, "%s is not set\n", "NAND_" name); errno = EINVAL; return -1; }; int v = atoi(str); if(!(exp)) { debug(LEVEL_ERROR, "%s must be in %s\n", "NAND_" name, #exp); return -1; }; handle->nand.nand_##var = v; }
|
|
||||||
|
|
||||||
int ingenic_rebuild(void *hndl) {
|
int ingenic_rebuild(void *hndl) {
|
||||||
HANDLE;
|
HANDLE;
|
||||||
|
|
||||||
@ -390,6 +393,10 @@ int ingenic_configure_stage2(void *hndl) {
|
|||||||
int ingenic_load_sdram(void *hndl, void *data, uint32_t base, uint32_t size) {
|
int ingenic_load_sdram(void *hndl, void *data, uint32_t base, uint32_t size) {
|
||||||
HANDLE;
|
HANDLE;
|
||||||
|
|
||||||
|
int max = size, value = 0;
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_INIT, 0, max);
|
||||||
|
|
||||||
while(size) {
|
while(size) {
|
||||||
int block = size > STAGE2_IOBUF ? STAGE2_IOBUF : size;
|
int block = size > STAGE2_IOBUF ? STAGE2_IOBUF : size;
|
||||||
|
|
||||||
@ -419,7 +426,14 @@ int ingenic_load_sdram(void *hndl, void *data, uint32_t base, uint32_t size) {
|
|||||||
data += block;
|
data += block;
|
||||||
base += block;
|
base += block;
|
||||||
size -= block;
|
size -= block;
|
||||||
|
value += block;
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_UPDATE, value, max);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_FINI, 0, 0);
|
||||||
|
|
||||||
debug(LEVEL_DEBUG, "Load done\n");
|
debug(LEVEL_DEBUG, "Load done\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -505,6 +519,9 @@ int ingenic_dump_nand(void *hndl, int cs, int start, int pages, int type, const
|
|||||||
void *iobuf = malloc(chunk_pages * page_size);
|
void *iobuf = malloc(chunk_pages * page_size);
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int value = 0, max = pages;
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_INIT, 0, max);
|
||||||
|
|
||||||
while(pages > 0) {
|
while(pages > 0) {
|
||||||
int chunk = pages < chunk_pages ? pages : chunk_pages;
|
int chunk = pages < chunk_pages ? pages : chunk_pages;
|
||||||
@ -558,11 +575,17 @@ int ingenic_dump_nand(void *hndl, int cs, int start, int pages, int type, const
|
|||||||
|
|
||||||
start += chunk;
|
start += chunk;
|
||||||
pages -= chunk;
|
pages -= chunk;
|
||||||
|
|
||||||
|
value += chunk;
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_UPDATE, value, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(iobuf);
|
free(iobuf);
|
||||||
fclose(dest);
|
fclose(dest);
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_FINI, 0, 0);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,6 +635,10 @@ int ingenic_program_nand(void *hndl, int cs, int start, int type, const char *fi
|
|||||||
|
|
||||||
debug(LEVEL_INFO, "Programming %d pages from %d (%d bytes, %d bytes/page)\n", pages, start, file_size, page_size);
|
debug(LEVEL_INFO, "Programming %d pages from %d (%d bytes, %d bytes/page)\n", pages, start, file_size, page_size);
|
||||||
|
|
||||||
|
int value = 0, max = pages;
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_INIT, 0, max);
|
||||||
|
|
||||||
while(pages > 0) {
|
while(pages > 0) {
|
||||||
int chunk = pages < chunk_pages ? pages : chunk_pages;
|
int chunk = pages < chunk_pages ? pages : chunk_pages;
|
||||||
int bytes = chunk * page_size;
|
int bytes = chunk * page_size;
|
||||||
@ -658,10 +685,15 @@ int ingenic_program_nand(void *hndl, int cs, int start, int type, const char *fi
|
|||||||
|
|
||||||
start += chunk;
|
start += chunk;
|
||||||
pages -= chunk;
|
pages -= chunk;
|
||||||
|
value += chunk;
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_UPDATE, value, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(iobuf);
|
free(iobuf);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
|
CALLBACK(progress, PROGRESS_FINI, 0, 0);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -688,3 +720,4 @@ int ingenic_load_nand(void *hndl, int cs, int start, int pages, uint32_t base) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@
|
|||||||
#define NO_OOB 2
|
#define NO_OOB 2
|
||||||
#define NAND_RAW (1 << 7)
|
#define NAND_RAW (1 << 7)
|
||||||
|
|
||||||
|
#define PROGRESS_INIT 0
|
||||||
|
#define PROGRESS_UPDATE 1
|
||||||
|
#define PROGRESS_FINI 2
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* debug args */
|
/* debug args */
|
||||||
uint8_t debug_ops;
|
uint8_t debug_ops;
|
||||||
@ -111,8 +115,10 @@ typedef struct {
|
|||||||
uint8_t plane;
|
uint8_t plane;
|
||||||
} nand_info_t;
|
} nand_info_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*cmdset_change)(void *arg);
|
void (*cmdset_change)(uint32_t cmdset, void *arg);
|
||||||
|
void (*progress)(int action, int value, int max, void *arg);
|
||||||
} ingenic_callbacks_t;
|
} ingenic_callbacks_t;
|
||||||
|
|
||||||
void *ingenic_open(void *usb_hndl);
|
void *ingenic_open(void *usb_hndl);
|
||||||
|
74
shell.c
74
shell.c
@ -26,15 +26,18 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include "shell_internal.h"
|
#include "shell_internal.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "ingenic.h"
|
#include "ingenic.h"
|
||||||
|
|
||||||
static void shell_update_cmdset(void *arg);
|
static void shell_update_cmdset(uint32_t cmdset, void *arg);
|
||||||
|
static void shell_progress(int action, int value, int max, void *arg);
|
||||||
|
|
||||||
static const ingenic_callbacks_t shell_callbacks = {
|
static const ingenic_callbacks_t shell_callbacks = {
|
||||||
shell_update_cmdset,
|
shell_update_cmdset,
|
||||||
|
shell_progress
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
@ -60,7 +63,7 @@ shell_context_t *shell_init(void *ingenic) {
|
|||||||
|
|
||||||
ingenic_set_callbacks(ingenic, &shell_callbacks, ctx);
|
ingenic_set_callbacks(ingenic, &shell_callbacks, ctx);
|
||||||
|
|
||||||
shell_update_cmdset(ctx);
|
shell_update_cmdset(ingenic_cmdset(ingenic), ctx);
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
@ -424,15 +427,13 @@ void shell_interactive(shell_context_t *ctx) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shell_update_cmdset(void *arg) {
|
static void shell_update_cmdset(uint32_t cmdset, void *arg) {
|
||||||
shell_context_t *ctx = arg;
|
shell_context_t *ctx = arg;
|
||||||
|
|
||||||
ctx->set_cmds = NULL;
|
ctx->set_cmds = NULL;
|
||||||
|
|
||||||
int set = ingenic_cmdset(ctx->device);
|
|
||||||
|
|
||||||
for(int i = 0; cmdsets[i].name != NULL; i++) {
|
for(int i = 0; cmdsets[i].name != NULL; i++) {
|
||||||
if(cmdsets[i].set == set) {
|
if(cmdsets[i].set == cmdset) {
|
||||||
printf("Shell: using command set '%s', run 'help' for command list. CPU: %04X\n", cmdsets[i].name, ingenic_type(ctx->device));
|
printf("Shell: using command set '%s', run 'help' for command list. CPU: %04X\n", cmdsets[i].name, ingenic_type(ctx->device));
|
||||||
|
|
||||||
ctx->set_cmds = cmdsets[i].commands;
|
ctx->set_cmds = cmdsets[i].commands;
|
||||||
@ -441,7 +442,7 @@ static void shell_update_cmdset(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(LEVEL_ERROR, "Shell: unknown cmdset %d\n", set);
|
debug(LEVEL_ERROR, "Shell: unknown cmdset %u\n", cmdset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *shell_device(shell_context_t *ctx) {
|
void *shell_device(shell_context_t *ctx) {
|
||||||
@ -452,3 +453,62 @@ void shell_exit(shell_context_t *ctx, int val) {
|
|||||||
ctx->shell_exit = val;
|
ctx->shell_exit = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void shell_progress(int action, int value, int max, void *arg) {
|
||||||
|
shell_context_t *ctx = arg;
|
||||||
|
|
||||||
|
if(isatty(STDOUT_FILENO)) {
|
||||||
|
struct winsize size;
|
||||||
|
|
||||||
|
int progress, percent;
|
||||||
|
|
||||||
|
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int bar_size = size.ws_col - 6;
|
||||||
|
|
||||||
|
switch(action) {
|
||||||
|
case PROGRESS_INIT:
|
||||||
|
ctx->prev_progress = -1;
|
||||||
|
|
||||||
|
|
||||||
|
case PROGRESS_FINI:
|
||||||
|
putchar('\r');
|
||||||
|
|
||||||
|
for(int i = 0; i < size.ws_col; i++)
|
||||||
|
putchar(' ');
|
||||||
|
|
||||||
|
putchar('\r');
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROGRESS_UPDATE:
|
||||||
|
progress = value * bar_size / max;
|
||||||
|
percent = value * 100 / max;
|
||||||
|
|
||||||
|
if(progress != ctx->prev_progress) {
|
||||||
|
fputs("\r|", stdout);
|
||||||
|
|
||||||
|
for(int i = 0; i < progress; i++) {
|
||||||
|
putchar('=');
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = progress; i < bar_size; i++)
|
||||||
|
putchar(' ');
|
||||||
|
|
||||||
|
printf("|%3d%%", percent);
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
ctx->prev_progress = progress;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ typedef struct {
|
|||||||
char *line;
|
char *line;
|
||||||
const struct shell_command *set_cmds;
|
const struct shell_command *set_cmds;
|
||||||
int shell_exit;
|
int shell_exit;
|
||||||
|
int prev_progress;
|
||||||
} shell_context_t;
|
} shell_context_t;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user