@@ -927,12 +927,15 @@ efi_status_t efi_net_register(void)
927
927
& netobj -> net );
928
928
if (r != EFI_SUCCESS )
929
929
goto failure_to_add_protocol ;
930
- if (!net_dp )
931
- efi_net_set_dp ("Net" , NULL );
932
- r = efi_add_protocol (& netobj -> header , & efi_guid_device_path ,
933
- net_dp );
930
+
931
+ if (net_dp )
932
+ r = efi_add_protocol (& netobj -> header , & efi_guid_device_path ,
933
+ net_dp );
934
+ else
935
+ r = efi_net_set_dp ("Net" , NULL );
934
936
if (r != EFI_SUCCESS )
935
937
goto failure_to_add_protocol ;
938
+
936
939
r = efi_add_protocol (& netobj -> header , & efi_pxe_base_code_protocol_guid ,
937
940
& netobj -> pxe );
938
941
if (r != EFI_SUCCESS )
@@ -1057,18 +1060,58 @@ efi_status_t efi_net_register(void)
1057
1060
*/
1058
1061
efi_status_t efi_net_set_dp (const char * dev , const char * server )
1059
1062
{
1060
- efi_free_pool (net_dp );
1063
+ efi_status_t ret = EFI_SUCCESS ;
1064
+ struct efi_handler * phandler ;
1065
+ struct efi_device_path * old_net_dp , * new_net_dp ;
1061
1066
1062
- net_dp = NULL ;
1067
+ old_net_dp = net_dp ;
1068
+ new_net_dp = NULL ;
1063
1069
if (!strcmp (dev , "Net" ))
1064
- net_dp = efi_dp_from_eth ();
1070
+ new_net_dp = efi_dp_from_eth ();
1065
1071
else if (!strcmp (dev , "Http" ))
1066
- net_dp = efi_dp_from_http (server );
1072
+ new_net_dp = efi_dp_from_http (server );
1067
1073
1068
- if (!net_dp )
1074
+ if (!new_net_dp ) {
1069
1075
return EFI_OUT_OF_RESOURCES ;
1076
+ }
1077
+
1078
+ // If netobj is not started yet, end here.
1079
+ if (!netobj ) {
1080
+ goto exit ;
1081
+ }
1082
+
1083
+ phandler = NULL ;
1084
+ efi_search_protocol (& netobj -> header , & efi_guid_device_path , & phandler );
1085
+
1086
+ // If the device path protocol is not yet installed, install it
1087
+ if (!phandler )
1088
+ goto add ;
1089
+
1090
+ // If it is already installed, try to update it
1091
+ ret = efi_reinstall_protocol_interface (& netobj -> header , & efi_guid_device_path ,
1092
+ old_net_dp , new_net_dp );
1093
+ if (ret != EFI_SUCCESS )
1094
+ goto error ;
1095
+
1096
+ net_dp = new_net_dp ;
1097
+ efi_free_pool (old_net_dp );
1070
1098
1071
1099
return EFI_SUCCESS ;
1100
+ add :
1101
+ ret = efi_add_protocol (& netobj -> header , & efi_guid_device_path ,
1102
+ new_net_dp );
1103
+ if (ret != EFI_SUCCESS )
1104
+ goto error ;
1105
+ exit :
1106
+ net_dp = new_net_dp ;
1107
+ efi_free_pool (old_net_dp );
1108
+
1109
+ return ret ;
1110
+ error :
1111
+ // Failed, restore
1112
+ efi_free_pool (new_net_dp );
1113
+
1114
+ return ret ;
1072
1115
}
1073
1116
1074
1117
/**
0 commit comments