@@ -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