Commit e5bf9878ea743564bcc7a15a79654fe06731a1e2
Committed by
Tom Rini
1 parent
593cbd93f3
Exists in
v2017.01-smarct4x
and in
37 other branches
usb/gadget: fastboot: implement sparse format
- add capability to "fastboot flash" with sparse format images Signed-off-by: Steve Rae <srae@broadcom.com> Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Showing 2 changed files with 23 additions and 10 deletions Side-by-side Diff
common/Makefile
common/fb_mmc.c
... | ... | @@ -7,18 +7,26 @@ |
7 | 7 | #include <common.h> |
8 | 8 | #include <fb_mmc.h> |
9 | 9 | #include <part.h> |
10 | +#include <aboot.h> | |
11 | +#include <sparse_format.h> | |
10 | 12 | |
11 | 13 | /* The 64 defined bytes plus the '\0' */ |
12 | 14 | #define RESPONSE_LEN (64 + 1) |
13 | 15 | |
14 | 16 | static char *response_str; |
15 | 17 | |
16 | -static void fastboot_resp(const char *s) | |
18 | +void fastboot_fail(const char *s) | |
17 | 19 | { |
18 | - strncpy(response_str, s, RESPONSE_LEN); | |
19 | - response_str[RESPONSE_LEN - 1] = '\0'; | |
20 | + strncpy(response_str, "FAIL", 4); | |
21 | + strncat(response_str, s, RESPONSE_LEN - 4 - 1); | |
20 | 22 | } |
21 | 23 | |
24 | +void fastboot_okay(const char *s) | |
25 | +{ | |
26 | + strncpy(response_str, "OKAY", 4); | |
27 | + strncat(response_str, s, RESPONSE_LEN - 4 - 1); | |
28 | +} | |
29 | + | |
22 | 30 | static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info, |
23 | 31 | const char *part_name, void *buffer, |
24 | 32 | unsigned int download_bytes) |
... | ... | @@ -32,7 +40,7 @@ |
32 | 40 | |
33 | 41 | if (blkcnt > info->size) { |
34 | 42 | error("too large for partition: '%s'\n", part_name); |
35 | - fastboot_resp("FAILtoo large for partition"); | |
43 | + fastboot_fail("too large for partition"); | |
36 | 44 | return; |
37 | 45 | } |
38 | 46 | |
39 | 47 | |
... | ... | @@ -42,13 +50,13 @@ |
42 | 50 | buffer); |
43 | 51 | if (blks != blkcnt) { |
44 | 52 | error("failed writing to device %d\n", dev_desc->dev); |
45 | - fastboot_resp("FAILfailed writing to device"); | |
53 | + fastboot_fail("failed writing to device"); | |
46 | 54 | return; |
47 | 55 | } |
48 | 56 | |
49 | 57 | printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz, |
50 | 58 | part_name); |
51 | - fastboot_resp("OKAY"); | |
59 | + fastboot_okay(""); | |
52 | 60 | } |
53 | 61 | |
54 | 62 | void fb_mmc_flash_write(const char *cmd, void *download_buffer, |
55 | 63 | |
56 | 64 | |
... | ... | @@ -64,18 +72,22 @@ |
64 | 72 | dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); |
65 | 73 | if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { |
66 | 74 | error("invalid mmc device\n"); |
67 | - fastboot_resp("FAILinvalid mmc device"); | |
75 | + fastboot_fail("invalid mmc device"); | |
68 | 76 | return; |
69 | 77 | } |
70 | 78 | |
71 | 79 | ret = get_partition_info_efi_by_name(dev_desc, cmd, &info); |
72 | 80 | if (ret) { |
73 | 81 | error("cannot find partition: '%s'\n", cmd); |
74 | - fastboot_resp("FAILcannot find partition"); | |
82 | + fastboot_fail("cannot find partition"); | |
75 | 83 | return; |
76 | 84 | } |
77 | 85 | |
78 | - write_raw_image(dev_desc, &info, cmd, download_buffer, | |
79 | - download_bytes); | |
86 | + if (is_sparse_image(download_buffer)) | |
87 | + write_sparse_image(dev_desc, &info, cmd, download_buffer, | |
88 | + download_bytes); | |
89 | + else | |
90 | + write_raw_image(dev_desc, &info, cmd, download_buffer, | |
91 | + download_bytes); | |
80 | 92 | } |