Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(582)

Unified Diff: vboot_firmware/lib/load_kernel_fw.c

Issue 2718012: More cleanup (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vboot_firmware/lib/include/vboot_kernel.h ('k') | vboot_firmware/lib/vboot_common.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vboot_firmware/lib/load_kernel_fw.c
diff --git a/vboot_firmware/lib/load_kernel_fw.c b/vboot_firmware/lib/load_kernel_fw.c
index 2a17c6cda4adfed0d5a79c779d21165fa5fd060d..88870679c0f621aa76c3143ac259736aceec21b7 100644
--- a/vboot_firmware/lib/load_kernel_fw.c
+++ b/vboot_firmware/lib/load_kernel_fw.c
@@ -13,6 +13,7 @@
#include "kernel_image_fw.h"
#include "rollback_index.h"
#include "utility.h"
+#include "vboot_kernel.h"
#define GPT_ENTRIES_SIZE 16384 /* Bytes to read for GPT entries */
@@ -20,134 +21,9 @@
// TODO: for testing
#include <stdio.h>
#include <inttypes.h> /* For PRIu64 macro */
-#endif
-
-/* TODO: Remove this terrible hack which fakes partition attributes
- * for the kernel partitions so that GptNextKernelEntry() won't
- * choke. */
#include "cgptlib_internal.h"
-void FakePartitionAttributes(GptData* gpt) {
- GptHeader* h = (GptHeader*)gpt->primary_header;
- GptEntry* entries = (GptEntry*)gpt->primary_entries;
- GptEntry* e;
- int i;
-
- for (i = 0, e = entries; i < h->number_of_entries; i++, e++) {
- if (!IsKernelEntry(e))
- continue;
-
-#ifdef PRINT_DEBUG_INFO
-
- printf("%2d %08x %04x %04x %02x %02x %02x %02x %02x %02x %02x %02x",
- i,
- e->type.u.Uuid.time_low,
- e->type.u.Uuid.time_mid,
- e->type.u.Uuid.time_high_and_version,
- e->type.u.Uuid.clock_seq_high_and_reserved,
- e->type.u.Uuid.clock_seq_low,
- e->type.u.Uuid.node[0],
- e->type.u.Uuid.node[1],
- e->type.u.Uuid.node[2],
- e->type.u.Uuid.node[3],
- e->type.u.Uuid.node[4],
- e->type.u.Uuid.node[5]
- );
- printf(" %8" PRIu64 " %8" PRIu64"\n", e->starting_lba,
- e->ending_lba - e->starting_lba + 1);
- printf("Hacking attributes for kernel partition %d\n", i);
#endif
- SetEntryPriority(e, 2);
- SetEntrySuccessful(e, 1);
- }
-}
-
-
-/* Allocates and reads GPT data from the drive. The sector_bytes and
- * drive_sectors fields should be filled on input. The primary and
- * secondary header and entries are filled on output.
- *
- * Returns 0 if successful, 1 if error. */
-int AllocAndReadGptData(GptData* gptdata) {
-
- uint64_t entries_sectors = GPT_ENTRIES_SIZE / gptdata->sector_bytes;
-
- /* No data to be written yet */
- gptdata->modified = 0;
-
- /* Allocate all buffers */
- gptdata->primary_header = (uint8_t*)Malloc(gptdata->sector_bytes);
- gptdata->secondary_header = (uint8_t*)Malloc(gptdata->sector_bytes);
- gptdata->primary_entries = (uint8_t*)Malloc(GPT_ENTRIES_SIZE);
- gptdata->secondary_entries = (uint8_t*)Malloc(GPT_ENTRIES_SIZE);
-
- if (gptdata->primary_header == NULL || gptdata->secondary_header == NULL ||
- gptdata->primary_entries == NULL || gptdata->secondary_entries == NULL)
- return 1;
-
- /* Read data from the drive, skipping the protective MBR */
- if (0 != BootDeviceReadLBA(1, 1, gptdata->primary_header))
- return 1;
- if (0 != BootDeviceReadLBA(2, entries_sectors, gptdata->primary_entries))
- return 1;
- if (0 != BootDeviceReadLBA(gptdata->drive_sectors - entries_sectors - 1,
- entries_sectors, gptdata->secondary_entries))
- return 1;
- if (0 != BootDeviceReadLBA(gptdata->drive_sectors - 1,
- 1, gptdata->secondary_header))
- return 1;
-
- return 0;
-}
-
-
-/* Writes any changes for the GPT data back to the drive, then frees
- * the buffers.
- *
- * Returns 0 if successful, 1 if error. */
-int WriteAndFreeGptData(GptData* gptdata) {
-
- uint64_t entries_sectors = GPT_ENTRIES_SIZE / gptdata->sector_bytes;
-
- if (gptdata->primary_header) {
- if (gptdata->modified & GPT_MODIFIED_HEADER1) {
- if (0 != BootDeviceWriteLBA(1, 1, gptdata->primary_header))
- return 1;
- }
- Free(gptdata->primary_header);
- }
-
- if (gptdata->primary_entries) {
- if (gptdata->modified & GPT_MODIFIED_ENTRIES1) {
- if (0 != BootDeviceWriteLBA(2, entries_sectors,
- gptdata->primary_entries))
- return 1;
- }
- Free(gptdata->primary_entries);
- }
-
- if (gptdata->secondary_entries) {
- if (gptdata->modified & GPT_MODIFIED_ENTRIES2) {
- if (0 != BootDeviceWriteLBA(gptdata->drive_sectors - entries_sectors - 1,
- entries_sectors, gptdata->secondary_entries))
- return 1;
- }
- Free(gptdata->secondary_entries);
- }
-
- if (gptdata->secondary_header) {
- if (gptdata->modified & GPT_MODIFIED_HEADER2) {
- if (0 != BootDeviceWriteLBA(gptdata->drive_sectors - 1, 1,
- gptdata->secondary_header))
- return 1;
- }
- Free(gptdata->secondary_header);
- }
-
- /* Success */
- return 0;
-}
-
#define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */
@@ -194,9 +70,6 @@ int LoadKernel(LoadKernelParams* params) {
if (GPT_SUCCESS != GptInit(&gpt))
break;
- /* TODO: TERRIBLE KLUDGE - fake partition attributes */
- FakePartitionAttributes(&gpt);
-
/* Allocate kernel header and image work buffers */
kbuf = (uint8_t*)Malloc(KBUF_SIZE);
if (!kbuf)
« no previous file with comments | « vboot_firmware/lib/include/vboot_kernel.h ('k') | vboot_firmware/lib/vboot_common.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698