Commit 4a12a97c14217a5b02791040e464449f779fce43
Committed by
Tom Rini
1 parent
a2adb173ec
Exists in
v2017.01-smarct4x
and in
29 other branches
efi_loader: Split drive add into function
The snippet of code to add a drive to our drive list needs to get called from 2 places in the future. Split it into a separate function. Signed-off-by: Alexander Graf <agraf@suse.de>
Showing 1 changed file with 47 additions and 37 deletions Side-by-side Diff
lib/efi_loader/efi_disk.c
... | ... | @@ -138,6 +138,52 @@ |
138 | 138 | .flush_blocks = &efi_disk_flush_blocks, |
139 | 139 | }; |
140 | 140 | |
141 | +static void efi_disk_add_dev(char *name, | |
142 | + const struct block_drvr *cur_drvr, | |
143 | + const struct blk_desc *desc, | |
144 | + int dev_index, | |
145 | + lbaint_t offset) | |
146 | +{ | |
147 | + struct efi_disk_obj *diskobj; | |
148 | + struct efi_device_path_file_path *dp; | |
149 | + int objlen = sizeof(*diskobj) + (sizeof(*dp) * 2); | |
150 | + | |
151 | + diskobj = calloc(1, objlen); | |
152 | + | |
153 | + /* Fill in object data */ | |
154 | + diskobj->parent.protocols[0].guid = &efi_block_io_guid; | |
155 | + diskobj->parent.protocols[0].open = efi_disk_open_block; | |
156 | + diskobj->parent.protocols[1].guid = &efi_guid_device_path; | |
157 | + diskobj->parent.protocols[1].open = efi_disk_open_dp; | |
158 | + diskobj->parent.handle = diskobj; | |
159 | + diskobj->ops = block_io_disk_template; | |
160 | + diskobj->ifname = cur_drvr->name; | |
161 | + diskobj->dev_index = dev_index; | |
162 | + | |
163 | + /* Fill in EFI IO Media info (for read/write callbacks) */ | |
164 | + diskobj->media.removable_media = desc->removable; | |
165 | + diskobj->media.media_present = 1; | |
166 | + diskobj->media.block_size = desc->blksz; | |
167 | + diskobj->media.io_align = desc->blksz; | |
168 | + diskobj->media.last_block = desc->lba; | |
169 | + diskobj->ops.media = &diskobj->media; | |
170 | + | |
171 | + /* Fill in device path */ | |
172 | + dp = (void*)&diskobj[1]; | |
173 | + diskobj->dp = dp; | |
174 | + dp[0].dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE; | |
175 | + dp[0].dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH; | |
176 | + dp[0].dp.length = sizeof(*dp); | |
177 | + ascii2unicode(dp[0].str, name); | |
178 | + | |
179 | + dp[1].dp.type = DEVICE_PATH_TYPE_END; | |
180 | + dp[1].dp.sub_type = DEVICE_PATH_SUB_TYPE_END; | |
181 | + dp[1].dp.length = sizeof(*dp); | |
182 | + | |
183 | + /* Hook up to the device list */ | |
184 | + list_add_tail(&diskobj->parent.link, &efi_obj_list); | |
185 | +} | |
186 | + | |
141 | 187 | /* |
142 | 188 | * U-Boot doesn't have a list of all online disk devices. So when running our |
143 | 189 | * EFI payload, we scan through all of the potentially available ones and |
... | ... | @@ -156,9 +202,6 @@ |
156 | 202 | printf("Scanning disks on %s...\n", cur_drvr->name); |
157 | 203 | for (i = 0; i < 4; i++) { |
158 | 204 | struct blk_desc *desc; |
159 | - struct efi_disk_obj *diskobj; | |
160 | - struct efi_device_path_file_path *dp; | |
161 | - int objlen = sizeof(*diskobj) + (sizeof(*dp) * 2); | |
162 | 205 | char devname[16] = { 0 }; /* dp->str is u16[16] long */ |
163 | 206 | |
164 | 207 | desc = blk_get_dev(cur_drvr->name, i); |
165 | 208 | |
... | ... | @@ -167,42 +210,9 @@ |
167 | 210 | if (desc->type == DEV_TYPE_UNKNOWN) |
168 | 211 | continue; |
169 | 212 | |
170 | - diskobj = calloc(1, objlen); | |
171 | - | |
172 | - /* Fill in object data */ | |
173 | - diskobj->parent.protocols[0].guid = &efi_block_io_guid; | |
174 | - diskobj->parent.protocols[0].open = efi_disk_open_block; | |
175 | - diskobj->parent.protocols[1].guid = &efi_guid_device_path; | |
176 | - diskobj->parent.protocols[1].open = efi_disk_open_dp; | |
177 | - diskobj->parent.handle = diskobj; | |
178 | - diskobj->ops = block_io_disk_template; | |
179 | - diskobj->ifname = cur_drvr->name; | |
180 | - diskobj->dev_index = i; | |
181 | - | |
182 | - /* Fill in EFI IO Media info (for read/write callbacks) */ | |
183 | - diskobj->media.removable_media = desc->removable; | |
184 | - diskobj->media.media_present = 1; | |
185 | - diskobj->media.block_size = desc->blksz; | |
186 | - diskobj->media.io_align = desc->blksz; | |
187 | - diskobj->media.last_block = desc->lba; | |
188 | - diskobj->ops.media = &diskobj->media; | |
189 | - | |
190 | - /* Fill in device path */ | |
191 | - dp = (void*)&diskobj[1]; | |
192 | - diskobj->dp = dp; | |
193 | - dp[0].dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE; | |
194 | - dp[0].dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH; | |
195 | - dp[0].dp.length = sizeof(*dp); | |
196 | 213 | snprintf(devname, sizeof(devname), "%s%d", |
197 | 214 | cur_drvr->name, i); |
198 | - ascii2unicode(dp[0].str, devname); | |
199 | - | |
200 | - dp[1].dp.type = DEVICE_PATH_TYPE_END; | |
201 | - dp[1].dp.sub_type = DEVICE_PATH_SUB_TYPE_END; | |
202 | - dp[1].dp.length = sizeof(*dp); | |
203 | - | |
204 | - /* Hook up to the device list */ | |
205 | - list_add_tail(&diskobj->parent.link, &efi_obj_list); | |
215 | + efi_disk_add_dev(devname, cur_drvr, desc, i, 0); | |
206 | 216 | disks++; |
207 | 217 | } |
208 | 218 | } |