Skip to content

Commit 86bac46

Browse files
authored
Merge pull request #187 from utmapp/aarch64-virt
Extend support for aarch64 with more configuration options
2 parents 3c4f7d4 + 25f7861 commit 86bac46

File tree

7 files changed

+259
-73
lines changed

7 files changed

+259
-73
lines changed

Configuration/UTMConfiguration.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19+
typedef NS_ENUM(NSUInteger, UTMDiskImageType) {
20+
UTMDiskImageTypeDisk,
21+
UTMDiskImageTypeCD,
22+
UTMDiskImageTypeBIOS,
23+
UTMDiskImageTypeKernel,
24+
UTMDiskImageTypeInitrd,
25+
UTMDiskImageTypeDTB,
26+
UTMDiskImageTypeMax
27+
};
28+
1929
NS_ASSUME_NONNULL_BEGIN
2030

2131
@interface UTMConfiguration : NSObject
@@ -26,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
2636
+ (NSArray<NSString *>*)supportedArchitectures;
2737
+ (NSArray<NSString *>*)supportedBootDevicesPretty;
2838
+ (NSArray<NSString *>*)supportedBootDevices;
39+
+ (NSArray<NSString *>*)supportedImageTypesPretty;
40+
+ (NSArray<NSString *>*)supportedImageTypes;
2941
+ (NSArray<NSString *>*)supportedSoundCardDevices;
3042
+ (NSArray<NSString *>*)supportedSoundCardDevicesPretty;
3143
+ (NSArray<NSString *>*)supportedTargetsForArchitecture:(NSString *)architecture;
@@ -85,13 +97,13 @@ NS_ASSUME_NONNULL_BEGIN
8597
- (NSArray *)systemArguments;
8698

8799
- (NSUInteger)countDrives;
88-
- (NSUInteger)newDrive:(NSString *)name interface:(NSString *)interface isCdrom:(BOOL)isCdrom;
100+
- (NSUInteger)newDrive:(NSString *)name type:(UTMDiskImageType)type interface:(NSString *)interface;
89101
- (nullable NSString *)driveImagePathForIndex:(NSUInteger)index;
90102
- (void)setImagePath:(NSString *)path forIndex:(NSUInteger)index;
91103
- (nullable NSString *)driveInterfaceTypeForIndex:(NSUInteger)index;
92104
- (void)setDriveInterfaceType:(NSString *)interfaceType forIndex:(NSUInteger)index;
93-
- (BOOL)driveIsCdromForIndex:(NSUInteger)index;
94-
- (void)setDriveIsCdrom:(BOOL)isCdrom forIndex:(NSUInteger)index;
105+
- (UTMDiskImageType)driveImageTypeForIndex:(NSUInteger)index;
106+
- (void)setDriveImageType:(UTMDiskImageType)type forIndex:(NSUInteger)index;
95107
- (void)moveDriveIndex:(NSUInteger)index to:(NSUInteger)newIndex;
96108
- (void)removeDriveAtIndex:(NSUInteger)index;
97109

Configuration/UTMConfiguration.m

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
const NSString *const kUTMConfigChipboardSharingKey = @"ClipboardSharing";
5959

6060
const NSString *const kUTMConfigImagePathKey = @"ImagePath";
61+
const NSString *const kUTMConfigImageTypeKey = @"ImageType";
6162
const NSString *const kUTMConfigInterfaceTypeKey = @"InterfaceType";
6263
const NSString *const kUTMConfigCdromKey = @"Cdrom";
6364

@@ -195,6 +196,28 @@ @implementation UTMConfiguration {
195196
];
196197
}
197198

199+
+ (NSArray<NSString *>*)supportedImageTypesPretty {
200+
return @[
201+
NSLocalizedString(@"Disk Image", "UTMConfiguration"),
202+
NSLocalizedString(@"CD/DVD Image", "UTMConfiguration"),
203+
NSLocalizedString(@"BIOS", "UTMConfiguration"),
204+
NSLocalizedString(@"Linux Kernel", "UTMConfiguration"),
205+
NSLocalizedString(@"Linux RAM Disk", "UTMConfiguration"),
206+
NSLocalizedString(@"Linux Device Tree Binary", "UTMConfiguration")
207+
];
208+
}
209+
210+
+ (NSArray<NSString *>*)supportedImageTypes {
211+
return @[
212+
@"disk",
213+
@"cd",
214+
@"bios",
215+
@"kernel",
216+
@"initrd",
217+
@"dtb"
218+
];
219+
}
220+
198221
+ (NSArray<NSString *>*)supportedTargetsForArchitecture:(NSString *)architecture {
199222
return @{
200223
@"alpha":
@@ -1328,6 +1351,17 @@ - (void)migrateConfigurationIfNecessary {
13281351
if (!_rootDict[kUTMConfigSoundKey][kUTMConfigSoundCardDeviceKey]) {
13291352
_rootDict[kUTMConfigSoundKey][kUTMConfigSoundCardDeviceKey] = [UTMConfiguration supportedSoundCardDevices][0];
13301353
}
1354+
// Migrate Cdrom => ImageType
1355+
[_rootDict[kUTMConfigDrivesKey] enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
1356+
if (!obj[kUTMConfigImageTypeKey]) {
1357+
if ([obj[kUTMConfigCdromKey] boolValue]) {
1358+
[self setDriveImageType:UTMDiskImageTypeCD forIndex:idx];
1359+
} else {
1360+
[self setDriveImageType:UTMDiskImageTypeDisk forIndex:idx];
1361+
}
1362+
[obj removeObjectForKey:kUTMConfigCdromKey];
1363+
}
1364+
}];
13311365
}
13321366

13331367
#pragma mark - Initialization
@@ -1621,12 +1655,13 @@ - (NSUInteger)countDrives {
16211655
return [_rootDict[kUTMConfigDrivesKey] count];
16221656
}
16231657

1624-
- (NSUInteger)newDrive:(NSString *)name interface:(NSString *)interface isCdrom:(BOOL)isCdrom {
1658+
- (NSUInteger)newDrive:(NSString *)name type:(UTMDiskImageType)type interface:(NSString *)interface {
16251659
NSUInteger index = [self countDrives];
1660+
NSString *strType = [UTMConfiguration supportedImageTypes][type];
16261661
NSMutableDictionary *drive = [[NSMutableDictionary alloc] initWithDictionary:@{
16271662
kUTMConfigImagePathKey: name,
1628-
kUTMConfigInterfaceTypeKey: interface,
1629-
kUTMConfigCdromKey: @(isCdrom)
1663+
kUTMConfigImageTypeKey: strType,
1664+
kUTMConfigInterfaceTypeKey: interface
16301665
}];
16311666
[_rootDict[kUTMConfigDrivesKey] addObject:drive];
16321667
return index;
@@ -1648,12 +1683,19 @@ - (void)setDriveInterfaceType:(NSString *)interfaceType forIndex:(NSUInteger)ind
16481683
_rootDict[kUTMConfigDrivesKey][index][kUTMConfigInterfaceTypeKey] = interfaceType;
16491684
}
16501685

1651-
- (BOOL)driveIsCdromForIndex:(NSUInteger)index {
1652-
return [_rootDict[kUTMConfigDrivesKey][index][kUTMConfigCdromKey] boolValue];
1686+
- (UTMDiskImageType)driveImageTypeForIndex:(NSUInteger)index {
1687+
NSString *strType = _rootDict[kUTMConfigDrivesKey][index][kUTMConfigImageTypeKey];
1688+
NSUInteger type = [[UTMConfiguration supportedImageTypes] indexOfObject:strType];
1689+
if (type == NSNotFound || type >= UTMDiskImageTypeMax) {
1690+
return UTMDiskImageTypeDisk;
1691+
} else {
1692+
return (UTMDiskImageType)type;
1693+
}
16531694
}
16541695

1655-
- (void)setDriveIsCdrom:(BOOL)isCdrom forIndex:(NSUInteger)index {
1656-
_rootDict[kUTMConfigDrivesKey][index][kUTMConfigCdromKey] = @(isCdrom);
1696+
- (void)setDriveImageType:(UTMDiskImageType)type forIndex:(NSUInteger)index {
1697+
NSString *strType = [UTMConfiguration supportedImageTypes][type];
1698+
_rootDict[kUTMConfigDrivesKey][index][kUTMConfigImageTypeKey] = strType;
16571699
}
16581700

16591701
- (void)moveDriveIndex:(NSUInteger)index to:(NSUInteger)newIndex {

ConfigurationViews/VMConfigDriveDetailViewController.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,35 @@
1515
//
1616

1717
#import <UIKit/UIKit.h>
18+
#import "UTMConfiguration.h"
1819
#import "VMConfigViewController.h"
1920

2021
NS_ASSUME_NONNULL_BEGIN
2122

2223
@interface VMConfigDriveDetailViewController : VMConfigViewController<UIPickerViewDelegate, UIPickerViewDataSource>
2324

2425
@property (weak, nonatomic) IBOutlet UILabel *existingPathLabel;
26+
27+
// image type
28+
@property (weak, nonatomic) IBOutlet UILabel *imageTypeLabel;
29+
@property (weak, nonatomic) IBOutlet UITableViewCell *imageTypePickerCell;
30+
@property (weak, nonatomic) IBOutlet UIPickerView *imageTypePicker;
31+
@property (weak, nonatomic) IBOutlet UITableViewCell *imageTypeCell;
32+
@property (nonatomic, assign) BOOL imageTypePickerActive;
33+
@property (nonatomic, assign) UTMDiskImageType imageType;
34+
35+
// drive location
2536
@property (weak, nonatomic) IBOutlet UILabel *driveLocationLabel;
2637
@property (weak, nonatomic) IBOutlet UITableViewCell *driveLocationPickerCell;
2738
@property (weak, nonatomic) IBOutlet UIPickerView *driveLocationPicker;
2839
@property (weak, nonatomic) IBOutlet UITableViewCell *driveLocationCell;
2940
@property (nonatomic, assign) BOOL driveLocationPickerActive;
30-
@property (strong, nonatomic) IBOutletCollection(UITableViewCell) NSArray *existingImageCells;
41+
@property (nonatomic, nullable, strong) NSString *driveInterfaceType;
42+
3143
@property (weak, nonatomic) IBOutlet UISwitch *isCdromSwitch;
3244
@property (nonatomic, assign) NSUInteger driveIndex;
33-
@property (nonatomic, nullable, strong) NSString *driveInterfaceType;
3445
@property (nonatomic, assign) BOOL valid;
3546

36-
- (IBAction)isCdromSwitchChanged:(UISwitch *)sender;
37-
3847
@end
3948

4049
NS_ASSUME_NONNULL_END

ConfigurationViews/VMConfigDriveDetailViewController.m

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,40 @@ - (void)viewWillAppear:(BOOL)animated {
3535

3636
- (void)refreshViewFromConfiguration {
3737
[super refreshViewFromConfiguration];
38+
self.imageTypePickerActive = NO;
3839
self.driveLocationPickerActive = NO;
3940
if (self.valid) {
4041
self.existingPathLabel.text = [self.configuration driveImagePathForIndex:self.driveIndex];
41-
self.isCdromSwitch.on = [self.configuration driveIsCdromForIndex:self.driveIndex];
42+
self.imageType = [self.configuration driveImageTypeForIndex:self.driveIndex];
4243
self.driveInterfaceType = [self.configuration driveInterfaceTypeForIndex:self.driveIndex];
4344
} else {
45+
self.imageType = UTMDiskImageTypeDisk;
4446
self.driveInterfaceType = [UTMConfiguration defaultDriveInterface];
4547
}
4648
}
4749

4850
#pragma mark - Properties
4951

52+
- (void)setImageTypePickerActive:(BOOL)imageTypePickerActive {
53+
_imageTypePickerActive = imageTypePickerActive;
54+
[self pickerCell:self.imageTypePickerCell setActive:imageTypePickerActive];
55+
}
56+
57+
- (void)setImageType:(UTMDiskImageType)imageType {
58+
NSAssert(imageType < UTMDiskImageTypeMax, @"Invalid image type %lu", imageType);
59+
_imageType = imageType;
60+
if (self.valid) {
61+
[self.configuration setDriveImageType:imageType forIndex:self.driveIndex];
62+
}
63+
self.imageTypeLabel.text = [UTMConfiguration supportedImageTypes][imageType];
64+
if (imageType == UTMDiskImageTypeDisk || imageType == UTMDiskImageTypeCD) {
65+
[self pickerCell:self.driveLocationCell setActive:YES];
66+
} else {
67+
[self pickerCell:self.driveLocationCell setActive:NO];
68+
self.driveLocationPickerActive = NO;
69+
}
70+
}
71+
5072
- (void)setDriveLocationPickerActive:(BOOL)driveLocationPickerActive {
5173
_driveLocationPickerActive = driveLocationPickerActive;
5274
[self pickerCell:self.driveLocationPickerCell setActive:driveLocationPickerActive];
@@ -66,6 +88,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
6688
if ([tableView cellForRowAtIndexPath:indexPath] == self.driveLocationCell) {
6789
self.driveLocationPickerActive = !self.driveLocationPickerActive;
6890
[tableView deselectRowAtIndexPath:indexPath animated:YES];
91+
} else if ([tableView cellForRowAtIndexPath:indexPath] == self.imageTypeCell) {
92+
self.imageTypePickerActive = !self.imageTypePickerActive;
93+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
6994
}
7095
}
7196

@@ -74,6 +99,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
7499
- (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
75100
if (pickerView == self.driveLocationPicker) {
76101
return 1;
102+
} else if (pickerView == self.imageTypePicker) {
103+
return 1;
77104
} else {
78105
NSAssert(0, @"Invalid picker");
79106
}
@@ -84,6 +111,8 @@ - (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInCompone
84111
NSAssert(component == 0, @"Invalid component");
85112
if (pickerView == self.driveLocationPicker) {
86113
return [UTMConfiguration supportedDriveInterfaces].count;
114+
} else if (pickerView == self.imageTypePicker) {
115+
return [UTMConfiguration supportedImageTypes].count;
87116
} else {
88117
NSAssert(0, @"Invalid picker");
89118
}
@@ -94,6 +123,8 @@ - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row f
94123
NSAssert(component == 0, @"Invalid component");
95124
if (pickerView == self.driveLocationPicker) {
96125
return [UTMConfiguration supportedDriveInterfaces][row];
126+
} else if (pickerView == self.imageTypePicker) {
127+
return [UTMConfiguration supportedImageTypesPretty][row];
97128
} else {
98129
NSAssert(0, @"Invalid picker");
99130
}
@@ -104,6 +135,8 @@ - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComp
104135
NSAssert(component == 0, @"Invalid component");
105136
if (pickerView == self.driveLocationPicker) {
106137
self.driveInterfaceType = [UTMConfiguration supportedDriveInterfaces][row];
138+
} else if (pickerView == self.imageTypePicker) {
139+
self.imageType = row;
107140
} else {
108141
NSAssert(0, @"Invalid picker");
109142
}
@@ -125,19 +158,10 @@ - (IBAction)unwindToDriveDetailFromDrivePicker:(UIStoryboardSegue*)sender {
125158
VMConfigDrivePickerViewController *source = (VMConfigDrivePickerViewController *)sender.sourceViewController;
126159
if (!self.valid) {
127160
self.valid = YES;
128-
self.driveIndex = [self.configuration newDrive:source.selectedName interface:self.driveInterfaceType isCdrom:self.isCdromSwitch.on];
161+
self.driveIndex = [self.configuration newDrive:source.selectedName type:self.imageType interface:self.driveInterfaceType];
129162
} else {
130163
[self.configuration setImagePath:source.selectedName forIndex:self.driveIndex];
131164
}
132165
}
133166

134-
#pragma mark - Event handlers
135-
136-
- (IBAction)isCdromSwitchChanged:(UISwitch *)sender {
137-
NSAssert(sender == self.isCdromSwitch, @"Invalid sender");
138-
if (self.valid) {
139-
[self.configuration setDriveIsCdrom:sender.on forIndex:self.driveIndex];
140-
}
141-
}
142-
143167
@end

ConfigurationViews/VMConfigDrivesViewController.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
5757
NSAssert(cell, @"Invalid cell");
5858

5959
cell.textLabel.text = [self.configuration driveImagePathForIndex:indexPath.row];
60-
cell.detailTextLabel.text = [self.configuration driveInterfaceTypeForIndex:indexPath.row];
60+
UTMDiskImageType type = [self.configuration driveImageTypeForIndex:indexPath.row];
61+
NSString *typeStr = [UTMConfiguration supportedImageTypesPretty][type];
62+
NSString *interface = [self.configuration driveInterfaceTypeForIndex:indexPath.row];
63+
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", typeStr, interface];
6164

6265
return cell;
6366
}

0 commit comments

Comments
 (0)