|
35 | 35 | NSInteger threads;
|
36 | 36 | } CPUCount;
|
37 | 37 |
|
| 38 | +extern NSString *const kUTMErrorDomain; |
| 39 | + |
38 | 40 | @interface UTMQemuSystem ()
|
39 | 41 |
|
40 | 42 | @property (nonatomic, readonly) NSURL *resourceURL;
|
41 | 43 | @property (nonatomic, readonly) CPUCount emulatedCpuCount;
|
42 | 44 | @property (nonatomic, readonly) BOOL useHypervisor;
|
43 | 45 | @property (nonatomic, readonly) BOOL hasCustomBios;
|
44 | 46 | @property (nonatomic, readonly) BOOL usbSupported;
|
45 |
| -@property (nonatomic, readonly) BOOL hasVirtio; |
| 47 | +@property (nonatomic, readonly) NSURL *efiVariablesURL; |
46 | 48 |
|
47 | 49 | @end
|
48 | 50 |
|
@@ -169,12 +171,18 @@ - (void)architectureSpecificConfiguration {
|
169 | 171 | [self pushArgv:@"-global"];
|
170 | 172 | [self pushArgv:@"ICH9-LPC.disable_s3=1"]; // applies for pc-q35-* types
|
171 | 173 | }
|
172 |
| - if (self.hasVirtio) { |
| 174 | + if (self.configuration.systemBootUefi) { |
173 | 175 | NSString *name = [NSString stringWithFormat:@"edk2-%@-code.fd", arch];
|
174 | 176 | NSURL *path = [self.resourceURL URLByAppendingPathComponent:name];
|
175 | 177 | if (!self.hasCustomBios && [[NSFileManager defaultManager] fileExistsAtPath:path.path]) {
|
176 | 178 | [self pushArgv:@"-drive"];
|
177 |
| - [self pushArgv:[NSString stringWithFormat:@"if=pflash,format=raw,file=%@,readonly=on", path.path]]; // accessDataWithBookmark called already |
| 179 | + [self pushArgv:[NSString stringWithFormat:@"if=pflash,format=raw,unit=0,file=%@,readonly=on", path.path]]; // accessDataWithBookmark called already |
| 180 | + [self pushArgv:@"-drive"]; |
| 181 | + [self pushArgv:[NSString stringWithFormat:@"if=pflash,format=raw,unit=1,file=%@", self.efiVariablesURL.path]]; |
| 182 | + [self accessDataWithBookmark:[self.efiVariablesURL bookmarkDataWithOptions:0 |
| 183 | + includingResourceValuesForKeys:nil |
| 184 | + relativeToURL:nil |
| 185 | + error:nil]]; |
178 | 186 | }
|
179 | 187 | }
|
180 | 188 | }
|
@@ -549,9 +557,8 @@ - (BOOL)usbSupported {
|
549 | 557 | return ![self.configuration.systemTarget isEqualToString:@"isapc"];
|
550 | 558 | }
|
551 | 559 |
|
552 |
| -- (BOOL)hasVirtio { |
553 |
| - return [self.configuration.systemTarget hasPrefix:@"virt"] || |
554 |
| - (!self.configuration.displayConsoleOnly && [self.configuration.displayCard hasPrefix:@"virtio"]); |
| 560 | +- (NSURL *)efiVariablesURL { |
| 561 | + return [[self.imgPath URLByAppendingPathComponent:[UTMConfiguration diskImagesDirectory]] URLByAppendingPathComponent:@"efi_vars.fd"]; |
555 | 562 | }
|
556 | 563 |
|
557 | 564 | - (NSString *)machineProperties {
|
@@ -692,7 +699,34 @@ - (void)updateArgvWithUserOptions:(BOOL)userOptions {
|
692 | 699 | }
|
693 | 700 | }
|
694 | 701 |
|
| 702 | +- (BOOL)createEfiVariablesIfNeededWithError:(NSError **)error { |
| 703 | + NSString *arch = self.configuration.systemArchitecture; |
| 704 | + NSFileManager *fileManager = NSFileManager.defaultManager; |
| 705 | + NSURL *srcUrl = nil; |
| 706 | + if (![fileManager fileExistsAtPath:self.efiVariablesURL.path]) { |
| 707 | + if ([arch isEqualToString:@"arm"] || [arch isEqualToString:@"aarch64"]) { |
| 708 | + srcUrl = [self.resourceURL URLByAppendingPathComponent:@"edk2-arm-vars.fd"]; |
| 709 | + } else if ([arch isEqualToString:@"i386"] || [arch isEqualToString:@"x86_64"]) { |
| 710 | + srcUrl = [self.resourceURL URLByAppendingPathComponent:@"edk2-i386-vars.fd"]; |
| 711 | + } else { |
| 712 | + if (error) { |
| 713 | + *error = [NSError errorWithDomain:kUTMErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"UEFI is not supported with this architecture.", "UTMQemuSystem")}]; |
| 714 | + } |
| 715 | + return NO; |
| 716 | + } |
| 717 | + return [fileManager copyItemAtURL:srcUrl toURL:self.efiVariablesURL error:error]; |
| 718 | + } |
| 719 | + return YES; |
| 720 | +} |
| 721 | + |
695 | 722 | - (void)startWithCompletion:(void (^)(BOOL, NSString * _Nonnull))completion {
|
| 723 | + if (self.configuration.systemBootUefi) { |
| 724 | + NSError *err; |
| 725 | + if (![self createEfiVariablesIfNeededWithError:&err]) { |
| 726 | + completion(NO, err.localizedDescription); |
| 727 | + return; |
| 728 | + } |
| 729 | + } |
696 | 730 | [self updateArgvWithUserOptions:YES];
|
697 | 731 | [self startQemu:self.configuration.systemArchitecture completion:completion];
|
698 | 732 | }
|
|
0 commit comments