am a744f0a1: Merge "System: Fastboot: warning fixit, misc bugs and cleanup."
* commit 'a744f0a11a4ff2e4a84a0af8e8e98e2e38babc32': System: Fastboot: warning fixit, misc bugs and cleanup.
This commit is contained in:
commit
b59e7e6b21
4 changed files with 60 additions and 60 deletions
|
|
@ -66,7 +66,7 @@ struct Action
|
||||||
char cmd[CMD_SIZE];
|
char cmd[CMD_SIZE];
|
||||||
const char *prod;
|
const char *prod;
|
||||||
void *data;
|
void *data;
|
||||||
unsigned size;
|
size_t size;
|
||||||
|
|
||||||
const char *msg;
|
const char *msg;
|
||||||
int (*func)(Action *a, int status, char *resp);
|
int (*func)(Action *a, int status, char *resp);
|
||||||
|
|
@ -169,7 +169,7 @@ void fb_queue_erase(const char *ptn)
|
||||||
a->msg = mkmsg("erasing '%s'", ptn);
|
a->msg = mkmsg("erasing '%s'", ptn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fb_queue_flash(const char *ptn, void *data, unsigned sz)
|
void fb_queue_flash(const char *ptn, void *data, size_t sz)
|
||||||
{
|
{
|
||||||
Action *a;
|
Action *a;
|
||||||
|
|
||||||
|
|
@ -182,7 +182,7 @@ void fb_queue_flash(const char *ptn, void *data, unsigned sz)
|
||||||
a->msg = mkmsg("writing '%s'", ptn);
|
a->msg = mkmsg("writing '%s'", ptn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz)
|
void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, size_t sz)
|
||||||
{
|
{
|
||||||
Action *a;
|
Action *a;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,8 @@ enum fb_buffer_type {
|
||||||
|
|
||||||
struct fastboot_buffer {
|
struct fastboot_buffer {
|
||||||
enum fb_buffer_type type;
|
enum fb_buffer_type type;
|
||||||
|
size_t sz;
|
||||||
void *data;
|
void *data;
|
||||||
unsigned int sz;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
|
@ -152,7 +152,7 @@ char *find_item(const char *item, const char *product)
|
||||||
return strdup(path);
|
return strdup(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t file_size(int fd)
|
static ssize_t file_size(int fd)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -162,15 +162,12 @@ static int64_t file_size(int fd)
|
||||||
return ret ? -1 : st.st_size;
|
return ret ? -1 : st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *load_fd(int fd, unsigned *_sz)
|
static void *load_fd(int fd, size_t *_sz)
|
||||||
{
|
{
|
||||||
char *data;
|
char *data = NULL;
|
||||||
int sz;
|
ssize_t sz = file_size(fd);
|
||||||
int errno_tmp;
|
int errno_tmp;
|
||||||
|
|
||||||
data = 0;
|
|
||||||
|
|
||||||
sz = file_size(fd);
|
|
||||||
if (sz < 0) {
|
if (sz < 0) {
|
||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +189,7 @@ oops:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *load_file(const char *fn, unsigned *_sz)
|
static void *load_file(const char *fn, size_t *_sz)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
|
@ -381,34 +378,34 @@ void *load_bootable_image(const char *kernel, const char *ramdisk,
|
||||||
return bdata;
|
return bdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
|
void *unzip_file(zipfile_t zip, const char *name, size_t *sz)
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
zipentry_t entry;
|
zipentry_t entry = lookup_zipentry(zip, name);
|
||||||
unsigned datasz;
|
size_t zentrysz;
|
||||||
|
size_t datasz;
|
||||||
|
|
||||||
entry = lookup_zipentry(zip, name);
|
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
fprintf(stderr, "archive does not contain '%s'\n", name);
|
fprintf(stderr, "archive does not contain '%s'\n", name);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*sz = get_zipentry_size(entry);
|
zentrysz = get_zipentry_size(entry);
|
||||||
|
|
||||||
datasz = *sz * 1.001;
|
datasz = zentrysz * 1.001;
|
||||||
data = malloc(datasz);
|
data = malloc(datasz);
|
||||||
|
|
||||||
if(data == 0) {
|
if(data == NULL) {
|
||||||
fprintf(stderr, "failed to allocate %d bytes\n", *sz);
|
fprintf(stderr, "failed to allocate %zu bytes\n", datasz);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decompress_zipentry(entry, data, datasz)) {
|
if (decompress_zipentry(entry, data, datasz)) {
|
||||||
fprintf(stderr, "failed to unzip '%s' from archive\n", name);
|
fprintf(stderr, "failed to unzip '%s' from archive\n", name);
|
||||||
free(data);
|
free(data);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
*sz = zentrysz;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -416,24 +413,25 @@ static int unzip_to_file(zipfile_t zip, char *name)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char *data;
|
char *data;
|
||||||
unsigned sz;
|
size_t sz;
|
||||||
|
|
||||||
fd = fileno(tmpfile());
|
fd = fileno(tmpfile());
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
return -1;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = unzip_file(zip, name, &sz);
|
data = unzip_file(zip, name, &sz);
|
||||||
if (data == 0) {
|
if (data == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(fd, data, sz) != sz) {
|
if (write(fd, data, sz) != (ssize_t)sz) {
|
||||||
fd = -1;
|
fd = -1;
|
||||||
|
} else {
|
||||||
|
lseek(fd, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
lseek(fd, 0, SEEK_SET);
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -514,11 +512,10 @@ static int setup_requirement_line(char *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_requirements(char *data, unsigned sz)
|
static void setup_requirements(char *data, size_t sz)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s = data;
|
||||||
|
|
||||||
s = data;
|
|
||||||
while (sz-- > 0) {
|
while (sz-- > 0) {
|
||||||
if(*s == '\n') {
|
if(*s == '\n') {
|
||||||
*s++ = 0;
|
*s++ = 0;
|
||||||
|
|
@ -628,14 +625,15 @@ static int needs_erase(const char *part)
|
||||||
static int load_buf_fd(usb_handle *usb, int fd,
|
static int load_buf_fd(usb_handle *usb, int fd,
|
||||||
struct fastboot_buffer *buf)
|
struct fastboot_buffer *buf)
|
||||||
{
|
{
|
||||||
int64_t sz64;
|
ssize_t f_size = file_size(fd);
|
||||||
void *data;
|
void *data = NULL;
|
||||||
int64_t limit;
|
int64_t limit;
|
||||||
|
int64_t sz64;
|
||||||
|
|
||||||
|
if (f_size < 0) {
|
||||||
sz64 = file_size(fd);
|
return f_size;
|
||||||
if (sz64 < 0) {
|
} else {
|
||||||
return -1;
|
sz64 = f_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
|
|
@ -648,12 +646,12 @@ static int load_buf_fd(usb_handle *usb, int fd,
|
||||||
buf->type = FB_BUFFER_SPARSE;
|
buf->type = FB_BUFFER_SPARSE;
|
||||||
buf->data = s;
|
buf->data = s;
|
||||||
} else {
|
} else {
|
||||||
unsigned int sz;
|
size_t sz;
|
||||||
data = load_fd(fd, &sz);
|
data = load_fd(fd, &sz);
|
||||||
if (data == 0) return -1;
|
if (data == NULL) return -1;
|
||||||
buf->type = FB_BUFFER;
|
buf->type = FB_BUFFER;
|
||||||
buf->data = data;
|
|
||||||
buf->sz = sz;
|
buf->sz = sz;
|
||||||
|
buf->data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -704,10 +702,11 @@ void do_flash(usb_handle *usb, const char *pname, const char *fname)
|
||||||
|
|
||||||
void do_update_signature(zipfile_t zip, char *fn)
|
void do_update_signature(zipfile_t zip, char *fn)
|
||||||
{
|
{
|
||||||
void *data;
|
size_t sz;
|
||||||
unsigned sz;
|
void *data = unzip_file(zip, fn, &sz);
|
||||||
data = unzip_file(zip, fn, &sz);
|
if (data == NULL) {
|
||||||
if (data == 0) return;
|
die("can't unzip '%s'", fn);
|
||||||
|
}
|
||||||
fb_queue_download("signature", data, sz);
|
fb_queue_download("signature", data, sz);
|
||||||
fb_queue_command("signature", "installing signature");
|
fb_queue_command("signature", "installing signature");
|
||||||
}
|
}
|
||||||
|
|
@ -717,12 +716,12 @@ void do_update(usb_handle *usb, char *fn, int erase_first)
|
||||||
void *zdata;
|
void *zdata;
|
||||||
unsigned zsize;
|
unsigned zsize;
|
||||||
void *data;
|
void *data;
|
||||||
unsigned sz;
|
size_t sz = 0;
|
||||||
zipfile_t zip;
|
zipfile_t zip;
|
||||||
int fd;
|
int fd;
|
||||||
int rc;
|
int rc;
|
||||||
struct fastboot_buffer buf;
|
struct fastboot_buffer buf;
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
queue_info_dump();
|
queue_info_dump();
|
||||||
|
|
||||||
|
|
@ -735,11 +734,11 @@ void do_update(usb_handle *usb, char *fn, int erase_first)
|
||||||
if(zip == 0) die("failed to access zipdata in '%s'");
|
if(zip == 0) die("failed to access zipdata in '%s'");
|
||||||
|
|
||||||
data = unzip_file(zip, "android-info.txt", &sz);
|
data = unzip_file(zip, "android-info.txt", &sz);
|
||||||
if (data == 0) {
|
if (data == NULL) {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
/* fallback for older zipfiles */
|
/* fallback for older zipfiles */
|
||||||
data = unzip_file(zip, "android-product.txt", &sz);
|
data = unzip_file(zip, "android-product.txt", &sz);
|
||||||
if ((data == 0) || (sz < 1)) {
|
if ((data == NULL) || (sz < 1)) {
|
||||||
die("update package has no android-info.txt or android-product.txt");
|
die("update package has no android-info.txt or android-product.txt");
|
||||||
}
|
}
|
||||||
tmp = malloc(sz + 128);
|
tmp = malloc(sz + 128);
|
||||||
|
|
@ -775,7 +774,7 @@ void do_update(usb_handle *usb, char *fn, int erase_first)
|
||||||
void do_send_signature(char *fn)
|
void do_send_signature(char *fn)
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
unsigned sz;
|
size_t sz;
|
||||||
char *xtn;
|
char *xtn;
|
||||||
|
|
||||||
xtn = strrchr(fn, '.');
|
xtn = strrchr(fn, '.');
|
||||||
|
|
@ -794,9 +793,9 @@ void do_flashall(usb_handle *usb, int erase_first)
|
||||||
{
|
{
|
||||||
char *fname;
|
char *fname;
|
||||||
void *data;
|
void *data;
|
||||||
unsigned sz;
|
size_t sz;
|
||||||
struct fastboot_buffer buf;
|
struct fastboot_buffer buf;
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
queue_info_dump();
|
queue_info_dump();
|
||||||
|
|
||||||
|
|
@ -978,7 +977,7 @@ int main(int argc, char **argv)
|
||||||
int wants_reboot_bootloader = 0;
|
int wants_reboot_bootloader = 0;
|
||||||
int erase_first = 1;
|
int erase_first = 1;
|
||||||
void *data;
|
void *data;
|
||||||
unsigned sz;
|
size_t sz;
|
||||||
int status;
|
int status;
|
||||||
int c;
|
int c;
|
||||||
int r;
|
int r;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
#ifndef _FASTBOOT_H_
|
#ifndef _FASTBOOT_H_
|
||||||
#define _FASTBOOT_H_
|
#define _FASTBOOT_H_
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
struct sparse_file;
|
struct sparse_file;
|
||||||
|
|
@ -36,7 +37,7 @@ struct sparse_file;
|
||||||
/* protocol.c - fastboot protocol */
|
/* protocol.c - fastboot protocol */
|
||||||
int fb_command(usb_handle *usb, const char *cmd);
|
int fb_command(usb_handle *usb, const char *cmd);
|
||||||
int fb_command_response(usb_handle *usb, const char *cmd, char *response);
|
int fb_command_response(usb_handle *usb, const char *cmd, char *response);
|
||||||
int fb_download_data(usb_handle *usb, const void *data, unsigned size);
|
int fb_download_data(usb_handle *usb, const void *data, size_t size);
|
||||||
int fb_download_data_sparse(usb_handle *usb, struct sparse_file *s);
|
int fb_download_data_sparse(usb_handle *usb, struct sparse_file *s);
|
||||||
char *fb_get_error(void);
|
char *fb_get_error(void);
|
||||||
|
|
||||||
|
|
@ -47,16 +48,16 @@ char *fb_get_error(void);
|
||||||
int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...);
|
int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...);
|
||||||
int fb_format_supported(usb_handle *usb, const char *partition, const char *type_override);
|
int fb_format_supported(usb_handle *usb, const char *partition, const char *type_override);
|
||||||
void fb_queue_flash(const char *ptn, void *data, unsigned sz);
|
void fb_queue_flash(const char *ptn, void *data, unsigned sz);
|
||||||
void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz);
|
void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, size_t sz);
|
||||||
void fb_queue_erase(const char *ptn);
|
void fb_queue_erase(const char *ptn);
|
||||||
void fb_queue_format(const char *ptn, int skip_if_not_supported, unsigned int max_chunk_sz);
|
void fb_queue_format(const char *ptn, int skip_if_not_supported, unsigned int max_chunk_sz);
|
||||||
void fb_queue_require(const char *prod, const char *var, int invert,
|
void fb_queue_require(const char *prod, const char *var, int invert,
|
||||||
unsigned nvalues, const char **value);
|
unsigned nvalues, const char **value);
|
||||||
void fb_queue_display(const char *var, const char *prettyname);
|
void fb_queue_display(const char *var, const char *prettyname);
|
||||||
void fb_queue_query_save(const char *var, char *dest, unsigned dest_size);
|
void fb_queue_query_save(const char *var, char *dest, size_t dest_size);
|
||||||
void fb_queue_reboot(void);
|
void fb_queue_reboot(void);
|
||||||
void fb_queue_command(const char *cmd, const char *msg);
|
void fb_queue_command(const char *cmd, const char *msg);
|
||||||
void fb_queue_download(const char *name, void *data, unsigned size);
|
void fb_queue_download(const char *name, void *data, size_t size);
|
||||||
void fb_queue_notice(const char *notice);
|
void fb_queue_notice(const char *notice);
|
||||||
void fb_queue_wait_for_disconnect(void);
|
void fb_queue_wait_for_disconnect(void);
|
||||||
int fb_execute_queue(usb_handle *usb);
|
int fb_execute_queue(usb_handle *usb);
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@
|
||||||
|
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
static unsigned arg_size = 4096;
|
static int arg_size = 4096;
|
||||||
static unsigned arg_count = 4096;
|
static int arg_count = 4096;
|
||||||
|
|
||||||
long long NOW(void)
|
long long NOW(void)
|
||||||
{
|
{
|
||||||
|
|
@ -134,7 +134,7 @@ struct
|
||||||
{ "send", match_null, test_null, "send to null interface" },
|
{ "send", match_null, test_null, "send to null interface" },
|
||||||
{ "recv", match_zero, test_zero, "recv from zero interface" },
|
{ "recv", match_zero, test_zero, "recv from zero interface" },
|
||||||
{ "loop", match_loop, 0, "exercise loopback interface" },
|
{ "loop", match_loop, 0, "exercise loopback interface" },
|
||||||
{},
|
{ NULL, NULL, NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
int usage(void)
|
int usage(void)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue