.. | .. |
---|
6 | 6 | |
---|
7 | 7 | #include <common.h> |
---|
8 | 8 | #include <malloc.h> |
---|
| 9 | +#include <dm/device.h> |
---|
9 | 10 | |
---|
10 | 11 | /* |
---|
11 | 12 | * Script file example: |
---|
.. | .. |
---|
144 | 145 | int argc, char * const argv[]) |
---|
145 | 146 | { |
---|
146 | 147 | struct blk_desc *desc; |
---|
| 148 | + struct udevice *dev; |
---|
| 149 | + int devnum = -1; |
---|
147 | 150 | int part_type; |
---|
148 | 151 | char cmd[128]; |
---|
149 | 152 | char *buf; |
---|
.. | .. |
---|
151 | 154 | |
---|
152 | 155 | printf("## retrieving usb_update.txt ...\n"); |
---|
153 | 156 | |
---|
154 | | - desc = blk_get_devnum_by_type(IF_TYPE_USB, 0); |
---|
155 | | - if (!desc) |
---|
| 157 | + if (run_command("usb reset", 0)) |
---|
156 | 158 | return CMD_RET_FAILURE; |
---|
| 159 | + |
---|
| 160 | + for (blk_first_device(IF_TYPE_USB, &dev); |
---|
| 161 | + dev; |
---|
| 162 | + blk_next_device(&dev)) { |
---|
| 163 | + desc = dev_get_uclass_platdata(dev); |
---|
| 164 | + if (desc->type == DEV_TYPE_UNKNOWN) |
---|
| 165 | + continue; |
---|
| 166 | + |
---|
| 167 | + if (desc->lba > 0L && desc->blksz > 0L) { |
---|
| 168 | + devnum = desc->devnum; |
---|
| 169 | + break; |
---|
| 170 | + } |
---|
| 171 | + } |
---|
| 172 | + if (devnum < 0) { |
---|
| 173 | + printf("No available udisk\n"); |
---|
| 174 | + return CMD_RET_FAILURE; |
---|
| 175 | + } |
---|
| 176 | + |
---|
| 177 | + desc = blk_get_devnum_by_type(IF_TYPE_USB, devnum); |
---|
| 178 | + if (!desc) { |
---|
| 179 | + printf("No usb %d found\n", devnum); |
---|
| 180 | + return CMD_RET_FAILURE; |
---|
| 181 | + } |
---|
157 | 182 | |
---|
158 | 183 | buf = memalign(ARCH_DMA_MINALIGN, SCRIPT_FILE_MAX_SIZE * 2); |
---|
159 | 184 | if (!buf) |
---|
.. | .. |
---|
162 | 187 | part_type = desc->part_type; |
---|
163 | 188 | desc->part_type = PART_TYPE_DOS; |
---|
164 | 189 | |
---|
165 | | - snprintf(cmd, sizeof(cmd), "usb reset"); |
---|
| 190 | + printf("## scanning usb %d\n", devnum); |
---|
| 191 | + snprintf(cmd, sizeof(cmd), "fatload usb %d 0x%08lx usb_update.txt", |
---|
| 192 | + devnum, (ulong)buf); |
---|
166 | 193 | ret = run_command(cmd, 0); |
---|
167 | | - if (!ret) { |
---|
168 | | - snprintf(cmd, sizeof(cmd), "fatload usb 0 0x%08lx usb_update.txt", (ulong)buf); |
---|
169 | | - ret = run_command(cmd, 0); |
---|
170 | | - } |
---|
171 | 194 | if (!ret) { |
---|
172 | 195 | snprintf(cmd, sizeof(cmd), "script 0x%08lx", (ulong)buf); |
---|
173 | 196 | ret = run_command(cmd, 0); |
---|
174 | 197 | } |
---|
175 | 198 | free(buf); |
---|
176 | | - |
---|
177 | 199 | desc->part_type = part_type; |
---|
178 | 200 | |
---|
179 | 201 | return ret; |
---|