-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.c
771 lines (650 loc) · 19.2 KB
/
installer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
/*
* Copyright (c) 2015, Intel Corporation
* All rights reserved.
*
* Author: Jeremy Compostella <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <efi.h>
#include <efiapi.h>
#include <efilib.h>
#include <stdio.h>
#include <transport.h>
#include "lib.h"
#include "uefi_utils.h"
#include "protocol.h"
#include "flash.h"
#include "gpt.h"
#include "sparse.h"
#include "sparse_format.h"
#include "fastboot.h"
#include "fastboot_oem.h"
#include "text_parser.h"
static BOOLEAN last_cmd_succeeded;
static fastboot_handle fastboot_flash_cmd;
static EFI_FILE_IO_INTERFACE *file_io_interface;
static data_callback_t fastboot_rx_cb, fastboot_tx_cb;
static CHAR8 DEFAULT_OPTIONS[] = "--batch installer.cmd";
static BOOLEAN need_tx_cb;
static char *fastboot_cmd_buf;
static UINTN fastboot_cmd_buf_len;
static char command_buffer[256]; /* Large enough to fit long filename
on flash command. */
#define inst_perror(ret, x, ...) do { \
fastboot_fail(x ": %r", ##__VA_ARGS__, ret); \
} while (0)
static void flush_tx_buffer(void)
{
while (need_tx_cb) {
need_tx_cb = FALSE;
fastboot_tx_cb(NULL, 0);
}
}
static void installer_flash_buffer(void *data, unsigned size,
INTN argc, CHAR8 **argv)
{
fastboot_set_dlbuffer(data, size);
fastboot_flash_cmd(argc, argv);
flush_tx_buffer();
fastboot_set_dlbuffer(NULL, 0);
}
static EFI_STATUS read_file(EFI_FILE *file, UINTN size, void *data)
{
EFI_STATUS ret;
UINTN nsize = size;
ret = uefi_call_wrapper(file->Read, 3, file, &nsize, data);
if (EFI_ERROR(ret)) {
inst_perror(ret, "Failed to read file");
return ret;
}
if (size != nsize) {
fastboot_fail("Failed to read %d bytes (only %d read)",
size, nsize);
return EFI_INVALID_PARAMETER;
}
return ret;
}
typedef struct flash_buffer {
struct sparse_header sph;
struct chunk_header skip_ckh;
union {
struct chunk_header ckh;
char data[1];
} d;
char ckh_data[1];
} __attribute__((__packed__)) flash_buffer_t;
/* This function splits a chunk too large to fit into a
MAX_DOWNLOAD_SIZE buffer into smaller chunks and flash them. */
static EFI_STATUS installer_flash_big_chunk(EFI_FILE *file, UINTN *remaining_data,
flash_buffer_t *fb, UINTN argc, CHAR8 **argv)
{
EFI_STATUS ret = EFI_INVALID_PARAMETER;
UINTN payload_size, read_size, already_read, ckh_blks, data_size;
const UINTN MAX_DATA_SIZE = MAX_DOWNLOAD_SIZE - offsetof(flash_buffer_t, ckh_data);
const UINTN MAX_BLKS = MAX_DATA_SIZE / fb->sph.blk_sz;
const UINTN HEADER_SIZE = offsetof(flash_buffer_t, d);
struct chunk_header *ckh;
void *read_ptr;
ckh = &fb->d.ckh;
payload_size = ckh->total_sz - sizeof(*ckh);
fb->sph.total_chunks = 2; /* skip and data chunks. */
for (ckh_blks = ckh->chunk_sz; ckh_blks; ckh_blks -= ckh->chunk_sz) {
ckh->chunk_sz = min(MAX_BLKS, ckh_blks);
data_size = ckh->chunk_sz * fb->sph.blk_sz;
ckh->total_sz = sizeof(*ckh) + data_size;
fb->sph.total_blks = fb->skip_ckh.chunk_sz + ckh->chunk_sz;
installer_flash_buffer(fb, ckh->total_sz + HEADER_SIZE, argc, argv);
if (!last_cmd_succeeded)
return EFI_INVALID_PARAMETER;
payload_size -= data_size;
if (!payload_size)
break;
/* Move the incomplete data from the end to the
beginning of the buffer. */
read_ptr = fb->ckh_data;
read_size = min(payload_size, MAX_DATA_SIZE);
if (data_size < MAX_DATA_SIZE) {
already_read = MAX_DATA_SIZE - data_size;
memcpy(read_ptr, fb->d.data + ckh->total_sz, already_read);
read_size -= already_read;
read_ptr += already_read;
}
ret = read_file(file, read_size, read_ptr);
if (EFI_ERROR(ret))
return ret;
*remaining_data -= read_size;
fb->skip_ckh.chunk_sz += ckh->chunk_sz;
}
if (payload_size)
return EFI_INVALID_PARAMETER;
return EFI_SUCCESS;
}
/* This function splits a huge sparse file into smaller ones and flash
them. */
static void installer_split_and_flash(CHAR16 *filename, UINTN size,
UINTN argc, CHAR8 **argv)
{
EFI_STATUS ret;
flash_buffer_t *fb;
struct sparse_header sph;
struct chunk_header *ckh;
void *buf;
UINTN read_size, flash_size, already_read, remaining_data = size;
void *read_ptr;
INTN nb_chunks;
EFI_FILE *file;
UINT32 blk_count;
const UINTN HEADER_SIZE = offsetof(flash_buffer_t, d);
const UINTN MAX_DATA_SIZE = MAX_DOWNLOAD_SIZE - HEADER_SIZE;
ret = uefi_open_file(file_io_interface, filename, &file);
if (EFI_ERROR(ret)) {
inst_perror(ret, "Failed to open %s file", filename);
return;
}
ret = read_file(file, sizeof(sph), &sph);
if (EFI_ERROR(ret))
return;
remaining_data -= sizeof(sph);
if (!is_sparse_image((void *) &sph, sizeof(sph))) {
fastboot_fail("sparse file expected");
return;
}
buf = AllocatePool(MAX_DOWNLOAD_SIZE);
if (!buf) {
fastboot_fail("Failed to allocate %d bytes", MAX_DOWNLOAD_SIZE);
return;
}
fb = buf;
/* New sparse header. */
memcpy(&fb->sph, &sph, sizeof(sph));
/* Sparse skip chunk. */
fb->skip_ckh.chunk_type = CHUNK_TYPE_DONT_CARE;
fb->skip_ckh.total_sz = sizeof(fb->skip_ckh);
nb_chunks = sph.total_chunks;
read_size = MAX_DATA_SIZE;
read_ptr = fb->d.data;
blk_count = 0;
while (nb_chunks > 0 && remaining_data > 0) {
fb->sph.total_chunks = 1;
fb->sph.total_blks = fb->skip_ckh.chunk_sz = blk_count;
if (remaining_data < read_size)
read_size = remaining_data;
/* Read a new piece of the input sparse file. */
ret = read_file(file, read_size, read_ptr);
if (EFI_ERROR(ret))
goto exit;
remaining_data -= read_size;
/* Process the loaded chunks to build the new header
and the skip chunk. */
flash_size = HEADER_SIZE;
ckh = &fb->d.ckh;
while ((void *)ckh + sizeof(*ckh) <= read_ptr + read_size &&
(void *)ckh + ckh->total_sz <= read_ptr + read_size) {
if (nb_chunks == 0) {
fastboot_fail("Corrupted sparse file: too many chunks");
goto exit;
}
flash_size += ckh->total_sz;
fb->sph.total_blks += ckh->chunk_sz;
blk_count += ckh->chunk_sz;
fb->sph.total_chunks++;
nb_chunks--;
ckh = (void *)ckh + ckh->total_sz;
}
/* chunk is too big to fit in the download buffer. */
if (flash_size == HEADER_SIZE) {
if (ckh->chunk_type != CHUNK_TYPE_RAW ||
remaining_data < ckh->total_sz - MAX_DATA_SIZE) {
fastboot_fail("Corrupted sparse file");
goto exit;
}
blk_count += ckh->chunk_sz;
nb_chunks--;
ret = installer_flash_big_chunk(file, &remaining_data,
fb, argc, argv);
if (EFI_ERROR(ret))
goto exit;
read_size = MAX_DATA_SIZE;
read_ptr = fb->d.data;
continue;
}
installer_flash_buffer(buf, flash_size, argc, argv);
if (!last_cmd_succeeded)
goto exit;
/* Move the incomplete chunk from the end to the
beginning of the buffer. */
if (buf + flash_size < read_ptr + read_size) {
already_read = read_ptr + read_size - (void *)ckh;
memcpy(fb->d.data, ckh, already_read);
read_size = MAX_DATA_SIZE - already_read;
read_ptr = fb->d.data + already_read;
} else {
read_size = MAX_DATA_SIZE;
read_ptr = fb->d.data;
}
}
exit:
FreePool(buf);
}
static void installer_flash_cmd(INTN argc, CHAR8 **argv)
{
EFI_STATUS ret;
CHAR16 *filename;
void *data;
UINTN size;
if (argc != 3) {
fastboot_fail("Flash command requires exactly 3 arguments");
return;
}
/* The fastboot flash command does not want the file parameter. */
argc--;
filename = stra_to_str(argv[2]);
if (!filename) {
fastboot_fail("Failed to convert CHAR8 filename to CHAR16");
return;
}
ret = uefi_get_file_size(file_io_interface, filename, &size);
if (EFI_ERROR(ret)) {
inst_perror(ret, "Failed to get %s file size", filename);
goto exit;
}
if (size > MAX_DOWNLOAD_SIZE) {
installer_split_and_flash(filename, size, argc, argv);
goto exit;
}
ret = uefi_read_file(file_io_interface, filename, &data, &size);
if (EFI_ERROR(ret)) {
inst_perror(ret, "Unable to read file %s", filename);
goto exit;
}
installer_flash_buffer(data, size, argc, argv);
FreePool(data);
exit:
FreePool(filename);
}
static CHAR16 *get_format_image_filename(CHAR8 *label)
{
CHAR8 *filename;
CHAR16 *filename16;
UINTN label_length;
if (!strcmp(label, (CHAR8 *)"data"))
label = (CHAR8 *)"userdata";
label_length = strlena(label);
filename = AllocateZeroPool(label_length + 5);
if (!filename) {
fastboot_fail("Unable to allocate CHAR8 filename buffer");
return NULL;
}
memcpy(filename, label, label_length);
memcpy(filename + label_length, ".img", 4);
filename16 = stra_to_str(filename);
FreePool(filename);
if (!filename16) {
fastboot_fail("Unable to allocate CHAR16 filename buffer");
return NULL;
}
return filename16;
}
/* Simulate the fastboot host format command:
1. get a filesystem image from a file;
2. erase the partition;
3. flash the filesystem image; */
static void installer_format(INTN argc, CHAR8 **argv)
{
EFI_STATUS ret;
void *data = NULL;
UINTN size;
CHAR16 *filename;
filename = get_format_image_filename(argv[1]);
if (!filename)
return;
ret = uefi_read_file(file_io_interface, filename, &data, &size);
if (ret == EFI_NOT_FOUND && !StrCmp(L"userdata.img", filename)) {
fastboot_info("userdata.img is missing, cannot format %a", argv[1]);
fastboot_info("Android fs_mgr will manage this");
} else if (EFI_ERROR(ret)) {
inst_perror(ret, "Unable to read file %s", filename);
goto free_filename;
}
fastboot_run_root_cmd("erase", argc, argv);
flush_tx_buffer();
if (!last_cmd_succeeded)
goto free_data;
if (data)
installer_flash_buffer(data, size, argc, argv);
free_data:
FreePool(data);
free_filename:
FreePool(filename);
}
static char **commands;
static UINTN command_nb;
static UINTN current_command;
static void free_commands(void)
{
UINTN i;
if (!commands)
return;
for (i = 0; i < command_nb; i++)
if (commands[i])
FreePool(commands);
FreePool(commands);
commands = NULL;
command_nb = 0;
current_command = 0;
}
static EFI_STATUS store_command(char *command, VOID *context _unused)
{
char **new_commands;
new_commands = AllocatePool((command_nb + 1) * sizeof(*new_commands));
if (!new_commands) {
free_commands();
return EFI_OUT_OF_RESOURCES;
}
memcpy(new_commands, commands, command_nb * sizeof(*commands));
new_commands[command_nb] = strdup(command);
if (!new_commands[command_nb]) {
free_commands();
return EFI_OUT_OF_RESOURCES;
}
if (commands)
FreePool(commands);
commands = new_commands;
command_nb++;
return EFI_SUCCESS;
}
static char *next_command()
{
if (command_nb == current_command) {
free_commands();
return NULL;
}
return commands[current_command++];
}
static void batch(INTN argc, CHAR8 **argv)
{
EFI_STATUS ret;
void *data;
UINTN size;
CHAR16 *filename;
if (argc != 2) {
fastboot_fail("Batch command takes one parameter");
return;
}
filename = stra_to_str(argv[1]);
if (!filename) {
fastboot_fail("Failed to convert CHAR8 filename to CHAR16");
return;
}
ret = uefi_read_file(file_io_interface, filename, &data, &size);
if (EFI_ERROR(ret)) {
inst_perror(ret, "Failed to read %s file", filename);
FreePool(filename);
return;
}
FreePool(filename);
ret = parse_text_buffer(data, size, store_command, NULL);
FreePool(data);
if (EFI_ERROR(ret))
inst_perror(ret, "Failed to parse batch file");
else
fastboot_okay("");
}
static void usage(__attribute__((__unused__)) INTN argc,
__attribute__((__unused__)) CHAR8 **argv)
{
Print(L"Usage: installer [OPTIONS | COMMANDS]\n");
Print(L" installer is an EFI application acting like the fastboot command.\n\n");
Print(L" COMMANDS fastboot commands (cf. the fastboot manual page)\n");
Print(L" --help, -h print this help and exit\n");
Print(L" --batch, -b FILE run all the fastboot commands of FILE\n");
Print(L"If no option is provided, the installer assumes '%a'\n", DEFAULT_OPTIONS);
Print(L"Note: 'boot', 'update', 'flash-raw' and 'flashall' commands are NOT supported\n");
fastboot_okay("");
}
static void unsupported_cmd(__attribute__((__unused__)) INTN argc,
CHAR8 **argv)
{
fastboot_fail("installer does not the support the '%a' command", argv[0]);
}
static struct replacements {
struct fastboot_cmd cmd;
fastboot_handle *save_handle;
} REPLACEMENTS[] = {
/* Fastboot changes. */
{ { "flash", UNKNOWN_STATE, installer_flash_cmd }, &fastboot_flash_cmd },
{ { "format", UNLOCKED, installer_format }, NULL },
/* Unsupported commands. */
{ { "update", UNKNOWN_STATE, unsupported_cmd }, NULL },
{ { "flashall", UNKNOWN_STATE, unsupported_cmd }, NULL },
{ { "boot", UNKNOWN_STATE, unsupported_cmd }, NULL },
{ { "devices", UNKNOWN_STATE, unsupported_cmd }, NULL },
{ { "download", UNKNOWN_STATE, unsupported_cmd }, NULL },
/* Installer specific commands. */
{ { "--help", LOCKED, usage }, NULL },
{ { "-h", LOCKED, usage }, NULL },
{ { "--batch", LOCKED, batch }, NULL },
{ { "-b", LOCKED, batch }, NULL }
};
static EFI_STATUS installer_replace_functions()
{
EFI_STATUS ret;
struct fastboot_cmd *cmd;
UINTN i;
for (i = 0; i < ARRAY_SIZE(REPLACEMENTS); i++) {
cmd = fastboot_get_root_cmd(REPLACEMENTS[i].cmd.name);
if (cmd && REPLACEMENTS[i].save_handle)
*(REPLACEMENTS[i].save_handle) = cmd->handle;
if (cmd && REPLACEMENTS[i].cmd.handle)
cmd->handle = REPLACEMENTS[i].cmd.handle;
if (!cmd && REPLACEMENTS[i].cmd.handle) {
ret = fastboot_register(&REPLACEMENTS[i].cmd);
if (EFI_ERROR(ret))
return ret;
}
}
return EFI_SUCCESS;
}
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
{
EFI_STATUS ret;
EFI_LOADED_IMAGE *loaded_img = NULL;
CHAR8 *options, *buf;
UINTN i;
void *bootimage;
void *efiimage;
UINTN imagesize;
enum boot_target target;
InitializeLib(image, _table);
g_parent_image = image;
ret = handle_protocol(image, &LoadedImageProtocol, (void **)&loaded_img);
if (ret != EFI_SUCCESS) {
inst_perror(ret, "LoadedImageProtocol error");
return ret;
}
/* Initialize File IO interface. */
ret = uefi_call_wrapper(BS->HandleProtocol, 3, loaded_img->DeviceHandle,
&FileSystemProtocol, (void *)&file_io_interface);
if (EFI_ERROR(ret)) {
inst_perror(ret, "Failed to get FileSystemProtocol");
return ret;
}
/* Prepare parameters. */
UINTN size = StrLen(loaded_img->LoadOptions) + 1;
buf = options = AllocatePool(size);
if (!options) {
fastboot_fail("Unable to allocate buffer for parameters");
return EFI_OUT_OF_RESOURCES;
}
str_to_stra(options, loaded_img->LoadOptions, size);
/* Snip control and space characters. */
for (i = size - 1; options[i] <= ' '; i--)
options[i] = '\0';
/* Drop the first parameter. */
options = strchr(options, ' ');
skip_whitespace((char **)&options);
store_command(*options != '\0' ? (char *)options : (char *)DEFAULT_OPTIONS,
NULL);
/* Run the fastboot library. */
ret = fastboot_start(&bootimage, &efiimage, &imagesize, &target);
if (EFI_ERROR(ret))
goto exit;
if (target != UNKNOWN_TARGET)
reboot_to_target(target);
exit:
FreePool(buf);
if (EFI_ERROR(ret))
return ret;
return last_cmd_succeeded ? EFI_SUCCESS : EFI_INVALID_PARAMETER;
}
/* Installer transport abstraction. */
EFI_STATUS installer_transport_start(start_callback_t start_cb,
data_callback_t rx_cb,
data_callback_t tx_cb)
{
EFI_STATUS ret;
ret = fastboot_set_command_buffer(command_buffer,
sizeof(command_buffer));
if (EFI_ERROR(ret)) {
efi_perror(ret, L"Failed to set fastboot command buffer");
return ret;
}
fastboot_tx_cb = tx_cb;
fastboot_rx_cb = rx_cb;
start_cb();
if (!fastboot_cmd_buf)
return EFI_INVALID_PARAMETER;
return EFI_SUCCESS;
}
EFI_STATUS installer_transport_stop(void)
{
return EFI_SUCCESS;
}
EFI_STATUS installer_transport_run(void)
{
static BOOLEAN initialized = FALSE;
EFI_STATUS ret;
char *cmd;
UINTN cmd_len;
if (!initialized) {
ret = installer_replace_functions();
if (EFI_ERROR(ret))
return ret;
if (!fastboot_flash_cmd) {
fastboot_fail("Failed to get the flash handle");
return ret;
}
initialized = TRUE;
}
if (current_command > 0) {
flush_tx_buffer();
if (!last_cmd_succeeded)
goto stop;
Print(L"Command successfully executed\n");
}
cmd = next_command();
if (!cmd)
goto stop;
cmd_len = strlena((CHAR8 *)cmd);
if (cmd_len > fastboot_cmd_buf_len) {
inst_perror(EFI_BUFFER_TOO_SMALL,
"command too long for fastboot command buffer");
goto stop;
}
memcpy(fastboot_cmd_buf, cmd, cmd_len);
Print(L"Starting command: '%a'\n", cmd);
fastboot_rx_cb(fastboot_cmd_buf, cmd_len);
return EFI_SUCCESS;
stop:
fastboot_stop(NULL, NULL, 0, EXIT_SHELL);
return EFI_SUCCESS;
}
EFI_STATUS installer_transport_read(void *buf, UINT32 size)
{
fastboot_cmd_buf = buf;
fastboot_cmd_buf_len = size;
return EFI_SUCCESS;
}
EFI_STATUS installer_transport_write(void *buf, UINT32 size)
{
#define PREFIX_LEN 4
if (size < PREFIX_LEN)
return EFI_SUCCESS;
if (!memcmp((CHAR8 *)"INFO", buf, PREFIX_LEN)) {
Print(L"(bootloader) %a\n", buf + PREFIX_LEN);
need_tx_cb = TRUE;
} if (!memcmp((CHAR8 *)"OKAY", buf, PREFIX_LEN)) {
if (((char *)buf)[PREFIX_LEN] != '\0')
Print(L"%a\n", buf + PREFIX_LEN);
last_cmd_succeeded = TRUE;
fastboot_tx_cb(NULL, 0);
} else if (!memcmp((CHAR8 *)"FAIL", buf, PREFIX_LEN)) {
error(L"%a", buf + PREFIX_LEN);
last_cmd_succeeded = FALSE;
fastboot_tx_cb(NULL, 0);
}
return EFI_SUCCESS;
}
static transport_t INSTALLER_TRANSPORT[] = {
{
.name = "Installer for fastboot",
.start = installer_transport_start,
.stop = installer_transport_stop,
.run = installer_transport_run,
.read = installer_transport_read,
.write = installer_transport_write
}
};
EFI_STATUS fastboot_transport_register(void)
{
return transport_register(INSTALLER_TRANSPORT,
ARRAY_SIZE(INSTALLER_TRANSPORT));
}
void fastboot_transport_unregister(void)
{
transport_unregister();
}
/* UI wrapper functions. */
void fastboot_ui_destroy(void)
{
}
void fastboot_ui_refresh(void)
{
}
EFI_STATUS fastboot_ui_init(void)
{
return EFI_SUCCESS;
}
enum boot_target fastboot_ui_event_handler()
{
return UNKNOWN_TARGET;
}
/* Installer does not support UI. It is intended to be used in
factory or for engineering purpose only. */
BOOLEAN fastboot_ui_confirm_for_state(__attribute__((__unused__)) enum device_state target)
{
return TRUE;
}