Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit 9e123a4

Browse files
tanmingerbuildslave
authored andcommitted
Fix a bug about fastboot oem set-storage failed when run it twice.
Now if the command 'fastboot oem set-storage xxx' failed, will not change the current boot device. Change-Id: I6d4ce7ec9b3cc1670ba3b874d01267a28e0944ff Tracked-On: OAM-85408 Signed-off-by: Ming Tan <ming.tan@intel.com> Reviewed-on: https://android.intel.com:443/679104
1 parent 2534a6c commit 9e123a4

2 files changed

Lines changed: 25 additions & 18 deletions

File tree

libfastboot/fastboot_oem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ static void cmd_oem_set_storage(INTN argc, CHAR8 **argv)
387387
for (i = 0; i < total_types; i++) {
388388
if ((boot_device_type == types[i]) && (user_lun == UFS_DEFAULT_USER_LUN) &&
389389
(factory_lun == UFS_DEFAULT_FACTORY_LUN)) {
390+
warning(L"Already use such type device");
390391
fastboot_info("Already use such type device");
391392
fastboot_okay("");
392393
return;

libkernelflinger/storage.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,19 @@ EFI_STATUS identify_boot_device(enum storage_type filter)
115115
struct storage *storage;
116116
enum storage_type type;
117117
EFI_HANDLE new_boot_device_handle = NULL;
118+
PCI_DEVICE_PATH new_boot_device = { .Function = -1, .Device = -1 };
119+
enum storage_type new_boot_device_type;
120+
struct storage *new_storage;
118121

119-
cur_storage = NULL;
122+
new_storage = NULL;
120123
ret = uefi_call_wrapper(BS->LocateHandleBuffer, 5, ByProtocol,
121124
&BlockIoProtocol, NULL, &nb_handle, &handles);
122125
if (EFI_ERROR(ret)) {
123126
efi_perror(ret, L"Failed to locate Block IO Protocol");
124127
return ret;
125128
}
126129

127-
boot_device.Header.Type = 0;
130+
new_boot_device.Header.Type = 0;
128131
for (i = 0; i < nb_handle; i++) {
129132
device_path = DevicePathFromHandle(handles[i]);
130133
if (!device_path)
@@ -134,42 +137,45 @@ EFI_STATUS identify_boot_device(enum storage_type filter)
134137
if (!pci)
135138
continue;
136139

137-
if (boot_device.Function == pci->Function &&
138-
boot_device.Device == pci->Device &&
139-
boot_device.Header.Type == pci->Header.Type &&
140-
boot_device.Header.SubType == pci->Header.SubType)
140+
if (new_boot_device.Function == pci->Function &&
141+
new_boot_device.Device == pci->Device &&
142+
new_boot_device.Header.Type == pci->Header.Type &&
143+
new_boot_device.Header.SubType == pci->Header.SubType)
141144
continue;
142145

143146
ret = identify_storage(device_path, filter, &storage, &type);
144147
if (EFI_ERROR(ret))
145148
continue;
146149

147-
if (!boot_device.Header.Type || boot_device_type >= type) {
148-
memcpy(&boot_device, pci, sizeof(boot_device));
149-
boot_device_type = type;
150-
cur_storage = storage;
151-
new_boot_device_handle = handles[i];
150+
if (!new_boot_device.Header.Type || new_boot_device_type >= type) {
151+
memcpy(&new_boot_device, pci, sizeof(new_boot_device));
152+
new_boot_device_type = type;
153+
new_storage = storage;
154+
new_boot_device_handle = handles[i];
152155
continue;
153156
}
154157

155-
if (boot_device_type == type &&
156-
type != STORAGE_GENERAL_BLOCK &&
157-
filter > type) {
158+
if (new_boot_device_type == type &&
159+
type != STORAGE_GENERAL_BLOCK &&
160+
filter > type) {
158161
error(L"Multiple identifcal storage found! Can't make a decision");
159-
cur_storage = NULL;
160-
boot_device.Header.Type = 0;
162+
new_storage = NULL;
163+
new_boot_device.Header.Type = 0;
161164
FreePool(handles);
162165
return EFI_UNSUPPORTED;
163166
}
164167
}
165168

166169
FreePool(handles);
167170

168-
if (!cur_storage) {
169-
error(L"No PCI storage found");
171+
if (!new_storage) {
172+
error(L"No PCI storage found for type %d", filter);
170173
return EFI_UNSUPPORTED;
171174
}
175+
cur_storage = new_storage;
176+
boot_device_type = new_boot_device_type;
172177
boot_device_handle = new_boot_device_handle;
178+
memcpy(&boot_device, &new_boot_device, sizeof(new_boot_device));
173179

174180
debug(L"%s storage selected", cur_storage->name);
175181
return EFI_SUCCESS;

0 commit comments

Comments
 (0)