Skip to content

Commit cc55fda

Browse files
authored
Merge pull request #108 from igoropaniuk/vip_table_generation
VIP table generation
2 parents 5db7794 + 4ed250c commit cc55fda

File tree

11 files changed

+1064
-9
lines changed

11 files changed

+1064
-9
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CFLAGS += -O2 -Wall -g `pkg-config --cflags libxml-2.0 libusb-1.0`
66
LDFLAGS += `pkg-config --libs libxml-2.0 libusb-1.0`
77
prefix := /usr/local
88

9-
QDL_SRCS := firehose.c io.c qdl.c sahara.c util.c patch.c program.c read.c sim.c ufs.c usb.c ux.c oscompat.c
9+
QDL_SRCS := firehose.c io.c qdl.c sahara.c util.c patch.c program.c read.c sha2.c sim.c ufs.c usb.c ux.c oscompat.c vip.c
1010
QDL_OBJS := $(QDL_SRCS:.c=.o)
1111

1212
RAMDUMP_SRCS := ramdump.c sahara.c io.c sim.c usb.c util.c ux.c oscompat.c

firehose.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "qdl.h"
5151
#include "ufs.h"
5252
#include "oscompat.h"
53+
#include "vip.h"
5354

5455
enum {
5556
FIREHOSE_ACK = 0,
@@ -183,9 +184,11 @@ static int firehose_write(struct qdl_device *qdl, xmlDoc *doc)
183184

184185
xmlDocDumpMemory(doc, &s, &len);
185186

187+
vip_gen_chunk_init(qdl);
188+
186189
for (;;) {
187190
ux_debug("FIREHOSE WRITE: %s\n", s);
188-
191+
vip_gen_chunk_update(qdl, s, len);
189192
ret = qdl_write(qdl, s, len);
190193
saved_errno = errno;
191194

@@ -202,6 +205,7 @@ static int firehose_write(struct qdl_device *qdl, xmlDoc *doc)
202205
}
203206
}
204207
xmlFree(s);
208+
vip_gen_chunk_store(qdl);
205209
return ret < 0 ? -saved_errno : 0;
206210
}
207211

@@ -423,7 +427,16 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
423427

424428
lseek(fd, (off_t) program->file_offset * program->sector_size, SEEK_SET);
425429
left = num_sectors;
430+
431+
ux_debug("FIREHOSE RAW BINARY WRITE: %s, %d bytes\n",
432+
program->filename, program->sector_size * num_sectors);
433+
426434
while (left > 0) {
435+
/*
436+
* We should calculate hash for every raw packet sent,
437+
* not for the whole binary.
438+
*/
439+
vip_gen_chunk_init(qdl);
427440
chunk_size = MIN(max_payload_size / program->sector_size, left);
428441

429442
n = read(fd, buf, chunk_size * program->sector_size);
@@ -435,6 +448,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
435448
if (n < max_payload_size)
436449
memset(buf + n, 0, max_payload_size - n);
437450

451+
vip_gen_chunk_update(qdl, buf, chunk_size * program->sector_size);
438452
n = qdl_write(qdl, buf, chunk_size * program->sector_size);
439453
if (n < 0) {
440454
ux_err("USB write failed for data chunk\n");
@@ -448,6 +462,7 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int
448462
}
449463

450464
left -= chunk_size;
465+
vip_gen_chunk_store(qdl);
451466

452467
ux_progress("%s", num_sectors - left, num_sectors, program->label);
453468
}

qdl.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "program.h"
4444
#include "ufs.h"
4545
#include "oscompat.h"
46+
#include "vip.h"
4647

4748
#ifdef _WIN32
4849
const char *__progname = "qdl";
@@ -107,7 +108,7 @@ static void print_usage(void)
107108
{
108109
extern const char *__progname;
109110
fprintf(stderr,
110-
"%s [--debug] [--dry-run] [--version] [--allow-missing] [--storage <emmc|nand|ufs>] [--finalize-provisioning] [--include <PATH>] [--serial <NUM>] [--out-chunk-size <SIZE>] <prog.mbn> [<program> <patch> ...]\n",
111+
"%s [--debug] [--dry-run] [--version] [--allow-missing] [--storage <emmc|nand|ufs>] [--finalize-provisioning] [--include <PATH>] [--serial <NUM>] [--out-chunk-size <SIZE>] [--create-digests <PATH>] <prog.mbn> [<program> <patch> ...]\n",
111112
__progname);
112113
}
113114

@@ -120,6 +121,7 @@ int main(int argc, char **argv)
120121
char *prog_mbn, *storage="ufs";
121122
char *incdir = NULL;
122123
char *serial = NULL;
124+
const char *vip_generate_dir= NULL;
123125
int type;
124126
int ret;
125127
int opt;
@@ -141,6 +143,7 @@ int main(int argc, char **argv)
141143
{"allow-missing", no_argument, 0, 'f'},
142144
{"allow-fusing", no_argument, 0, 'c'},
143145
{"dry-run", no_argument, 0, 'n'},
146+
{"create-digests", required_argument, 0, 't'},
144147
{0, 0, 0, 0}
145148
};
146149

@@ -152,6 +155,11 @@ int main(int argc, char **argv)
152155
case 'n':
153156
qdl_dev_type = QDL_DEVICE_SIM;
154157
break;
158+
case 't':
159+
vip_generate_dir = optarg;
160+
/* we also enforce dry-run mode */
161+
qdl_dev_type = QDL_DEVICE_SIM;
162+
break;
155163
case 'v':
156164
print_version();
157165
return 0;
@@ -197,6 +205,12 @@ int main(int argc, char **argv)
197205
if (out_chunk_size)
198206
qdl_set_out_chunk_size(qdl, out_chunk_size);
199207

208+
if (vip_generate_dir) {
209+
ret = vip_gen_init(qdl, vip_generate_dir);
210+
if (ret)
211+
goto out_cleanup;
212+
}
213+
200214
ux_init();
201215

202216
if (qdl_debug)
@@ -254,6 +268,9 @@ int main(int argc, char **argv)
254268
goto out_cleanup;
255269

256270
out_cleanup:
271+
if (vip_generate_dir)
272+
vip_gen_finalize(qdl);
273+
257274
qdl_close(qdl);
258275
free_programs();
259276
free_patches();

qdl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
#include "read.h"
99
#include <libxml/tree.h>
1010

11+
#define container_of(ptr, typecast, member) ({ \
12+
void *_ptr = (void *)(ptr); \
13+
((typecast *)(_ptr - offsetof(typecast, member))); })
14+
1115
#define MAPPING_SZ 64
1216

1317
enum QDL_DEVICE_TYPE
1418
{
1519
QDL_DEVICE_USB,
16-
QDL_DEVICE_SIM,
20+
QDL_DEVICE_SIM,
1721
};
1822

1923
struct qdl_device

0 commit comments

Comments
 (0)