capsule-loader.c (7367633f0bfd783ae5838141f3af88bba6c45eb9) capsule-loader.c (5dce14b9d1a29cf76331f0fe8eb7efd63e0fcb9a)
1/*
2 * EFI capsule loader driver.
3 *
4 * Copyright 2015 Intel Corporation
5 *
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
8 */

--- 56 unchanged lines hidden (view full) ---

65 if (hdr_bytes < sizeof(efi_capsule_header_t))
66 return 0;
67
68 /* Reset back to the correct offset of header */
69 cap_hdr = kbuff - cap_info->count;
70 pages_needed = ALIGN(cap_hdr->imagesize, PAGE_SIZE) >> PAGE_SHIFT;
71
72 if (pages_needed == 0) {
1/*
2 * EFI capsule loader driver.
3 *
4 * Copyright 2015 Intel Corporation
5 *
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
8 */

--- 56 unchanged lines hidden (view full) ---

65 if (hdr_bytes < sizeof(efi_capsule_header_t))
66 return 0;
67
68 /* Reset back to the correct offset of header */
69 cap_hdr = kbuff - cap_info->count;
70 pages_needed = ALIGN(cap_hdr->imagesize, PAGE_SIZE) >> PAGE_SHIFT;
71
72 if (pages_needed == 0) {
73 pr_err("%s: pages count invalid\n", __func__);
73 pr_err("invalid capsule size");
74 return -EINVAL;
75 }
76
77 /* Check if the capsule binary supported */
78 ret = efi_capsule_supported(cap_hdr->guid, cap_hdr->flags,
79 cap_hdr->imagesize,
80 &cap_info->reset_type);
81 if (ret) {
74 return -EINVAL;
75 }
76
77 /* Check if the capsule binary supported */
78 ret = efi_capsule_supported(cap_hdr->guid, cap_hdr->flags,
79 cap_hdr->imagesize,
80 &cap_info->reset_type);
81 if (ret) {
82 pr_err("%s: efi_capsule_supported() failed\n",
83 __func__);
82 pr_err("capsule not supported\n");
84 return ret;
85 }
86
87 cap_info->total_size = cap_hdr->imagesize;
88 temp_page = krealloc(cap_info->pages,
89 pages_needed * sizeof(void *),
90 GFP_KERNEL | __GFP_ZERO);
91 if (!temp_page)

--- 18 unchanged lines hidden (view full) ---

110 cap_hdr_temp = vmap(cap_info->pages, cap_info->index,
111 VM_MAP, PAGE_KERNEL);
112 if (!cap_hdr_temp)
113 return -ENOMEM;
114
115 ret = efi_capsule_update(cap_hdr_temp, cap_info->pages);
116 vunmap(cap_hdr_temp);
117 if (ret) {
83 return ret;
84 }
85
86 cap_info->total_size = cap_hdr->imagesize;
87 temp_page = krealloc(cap_info->pages,
88 pages_needed * sizeof(void *),
89 GFP_KERNEL | __GFP_ZERO);
90 if (!temp_page)

--- 18 unchanged lines hidden (view full) ---

109 cap_hdr_temp = vmap(cap_info->pages, cap_info->index,
110 VM_MAP, PAGE_KERNEL);
111 if (!cap_hdr_temp)
112 return -ENOMEM;
113
114 ret = efi_capsule_update(cap_hdr_temp, cap_info->pages);
115 vunmap(cap_hdr_temp);
116 if (ret) {
118 pr_err("%s: efi_capsule_update() failed\n", __func__);
117 pr_err("capsule update failed\n");
119 return ret;
120 }
121
122 /* Indicate capsule binary uploading is done */
123 cap_info->index = NO_FURTHER_WRITE_ACTION;
118 return ret;
119 }
120
121 /* Indicate capsule binary uploading is done */
122 cap_info->index = NO_FURTHER_WRITE_ACTION;
124 pr_info("%s: Successfully upload capsule file with reboot type '%s'\n",
125 __func__, !cap_info->reset_type ? "RESET_COLD" :
123 pr_info("Successfully upload capsule file with reboot type '%s'\n",
124 !cap_info->reset_type ? "RESET_COLD" :
126 cap_info->reset_type == 1 ? "RESET_WARM" :
127 "RESET_SHUTDOWN");
128 return 0;
129}
130
131/**
132 * efi_capsule_write - store the capsule binary and pass it to
133 * efi_capsule_update() API

--- 68 unchanged lines hidden (view full) ---

202
203 cap_info->count += write_byte;
204 kunmap(page);
205
206 /* Submit the full binary to efi_capsule_update() API */
207 if (cap_info->header_obtained &&
208 cap_info->count >= cap_info->total_size) {
209 if (cap_info->count > cap_info->total_size) {
125 cap_info->reset_type == 1 ? "RESET_WARM" :
126 "RESET_SHUTDOWN");
127 return 0;
128}
129
130/**
131 * efi_capsule_write - store the capsule binary and pass it to
132 * efi_capsule_update() API

--- 68 unchanged lines hidden (view full) ---

201
202 cap_info->count += write_byte;
203 kunmap(page);
204
205 /* Submit the full binary to efi_capsule_update() API */
206 if (cap_info->header_obtained &&
207 cap_info->count >= cap_info->total_size) {
208 if (cap_info->count > cap_info->total_size) {
210 pr_err("%s: upload size exceeded header defined size\n",
211 __func__);
209 pr_err("capsule upload size exceeded header defined size\n");
212 ret = -EINVAL;
213 goto failed;
214 }
215
216 ret = efi_capsule_submit_update(cap_info);
217 if (ret)
218 goto failed;
219 }

--- 17 unchanged lines hidden (view full) ---

237 * buffer pages and -ECANCELED will be returned.
238 **/
239static int efi_capsule_flush(struct file *file, fl_owner_t id)
240{
241 int ret = 0;
242 struct capsule_info *cap_info = file->private_data;
243
244 if (cap_info->index > 0) {
210 ret = -EINVAL;
211 goto failed;
212 }
213
214 ret = efi_capsule_submit_update(cap_info);
215 if (ret)
216 goto failed;
217 }

--- 17 unchanged lines hidden (view full) ---

235 * buffer pages and -ECANCELED will be returned.
236 **/
237static int efi_capsule_flush(struct file *file, fl_owner_t id)
238{
239 int ret = 0;
240 struct capsule_info *cap_info = file->private_data;
241
242 if (cap_info->index > 0) {
245 pr_err("%s: capsule upload not complete\n", __func__);
243 pr_err("capsule upload not complete\n");
246 efi_free_all_buff_pages(cap_info);
247 ret = -ECANCELED;
248 }
249
250 return ret;
251}
252
253/**

--- 62 unchanged lines hidden (view full) ---

316{
317 int ret;
318
319 if (!efi_enabled(EFI_RUNTIME_SERVICES))
320 return -ENODEV;
321
322 ret = misc_register(&efi_capsule_misc);
323 if (ret)
244 efi_free_all_buff_pages(cap_info);
245 ret = -ECANCELED;
246 }
247
248 return ret;
249}
250
251/**

--- 62 unchanged lines hidden (view full) ---

314{
315 int ret;
316
317 if (!efi_enabled(EFI_RUNTIME_SERVICES))
318 return -ENODEV;
319
320 ret = misc_register(&efi_capsule_misc);
321 if (ret)
324 pr_err("%s: Failed to register misc char file note\n",
325 __func__);
322 pr_err("Unable to register capsule loader device\n");
326
327 return ret;
328}
329module_init(efi_capsule_loader_init);
330
331static void __exit efi_capsule_loader_exit(void)
332{
333 misc_deregister(&efi_capsule_misc);
334}
335module_exit(efi_capsule_loader_exit);
336
337MODULE_DESCRIPTION("EFI capsule firmware binary loader");
338MODULE_LICENSE("GPL v2");
323
324 return ret;
325}
326module_init(efi_capsule_loader_init);
327
328static void __exit efi_capsule_loader_exit(void)
329{
330 misc_deregister(&efi_capsule_misc);
331}
332module_exit(efi_capsule_loader_exit);
333
334MODULE_DESCRIPTION("EFI capsule firmware binary loader");
335MODULE_LICENSE("GPL v2");