OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 /* Routines for verifying a file's signature. Useful in testing the core | 6 /* Routines for verifying a file's signature. Useful in testing the core |
7 * RSA verification implementation. | 7 * RSA verification implementation. |
8 */ | 8 */ |
9 | 9 |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #define LBA_BYTES 512 | 26 #define LBA_BYTES 512 |
27 #define KERNEL_BUFFER_SIZE 0x600000 | 27 #define KERNEL_BUFFER_SIZE 0x600000 |
28 | 28 |
29 /* Global variables for stub functions */ | 29 /* Global variables for stub functions */ |
30 static LoadKernelParams lkp; | 30 static LoadKernelParams lkp; |
31 static FILE *image_file = NULL; | 31 static FILE *image_file = NULL; |
32 | 32 |
33 | 33 |
34 /* Boot device stub implementations to read from the image file */ | 34 /* Boot device stub implementations to read from the image file */ |
35 int BootDeviceReadLBA(uint64_t lba_start, uint64_t lba_count, void *buffer) { | 35 int BootDeviceReadLBA(uint64_t lba_start, uint64_t lba_count, void *buffer) { |
36 printf("Read(%ld, %ld)\n", lba_start, lba_count); | 36 printf("Read(%llu, %llu)\n", lba_start, lba_count); |
37 | 37 |
38 if (lba_start > lkp.ending_lba || | 38 if (lba_start > lkp.ending_lba || |
39 lba_start + lba_count - 1 > lkp.ending_lba) { | 39 lba_start + lba_count - 1 > lkp.ending_lba) { |
40 fprintf(stderr, "Read overrun: %ld + %ld > %ld\n", | 40 fprintf(stderr, "Read overrun: %llu + %llu > %llu\n", |
41 lba_start, lba_count, lkp.ending_lba); | 41 lba_start, lba_count, lkp.ending_lba); |
42 return 1; | 42 return 1; |
43 } | 43 } |
44 | 44 |
45 fseek(image_file, lba_start * lkp.bytes_per_lba, SEEK_SET); | 45 fseek(image_file, lba_start * lkp.bytes_per_lba, SEEK_SET); |
46 if (1 != fread(buffer, lba_count * lkp.bytes_per_lba, 1, image_file)) { | 46 if (1 != fread(buffer, lba_count * lkp.bytes_per_lba, 1, image_file)) { |
47 fprintf(stderr, "Read error."); | 47 fprintf(stderr, "Read error."); |
48 return 1; | 48 return 1; |
49 } | 49 } |
50 return 0; | 50 return 0; |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 int BootDeviceWriteLBA(uint64_t lba_start, uint64_t lba_count, | 54 int BootDeviceWriteLBA(uint64_t lba_start, uint64_t lba_count, |
55 const void *buffer) { | 55 const void *buffer) { |
56 printf("Write(%ld, %ld)\n", lba_start, lba_count); | 56 printf("Write(%llu, %llu)\n", lba_start, lba_count); |
57 | 57 |
58 if (lba_start > lkp.ending_lba || | 58 if (lba_start > lkp.ending_lba || |
59 lba_start + lba_count - 1 > lkp.ending_lba) { | 59 lba_start + lba_count - 1 > lkp.ending_lba) { |
60 fprintf(stderr, "Read overrun: %ld + %ld > %ld\n", | 60 fprintf(stderr, "Read overrun: %llu + %llu > %llu\n", |
61 lba_start, lba_count, lkp.ending_lba); | 61 lba_start, lba_count, lkp.ending_lba); |
62 return 1; | 62 return 1; |
63 } | 63 } |
64 | 64 |
65 /* TODO: enable writes, once we're sure it won't trash our example file */ | 65 /* TODO: enable writes, once we're sure it won't trash our example file */ |
66 return 0; | 66 return 0; |
67 | 67 |
68 fseek(image_file, lba_start * lkp.bytes_per_lba, SEEK_SET); | 68 fseek(image_file, lba_start * lkp.bytes_per_lba, SEEK_SET); |
69 if (1 != fwrite(buffer, lba_count * lkp.bytes_per_lba, 1, image_file)) { | 69 if (1 != fwrite(buffer, lba_count * lkp.bytes_per_lba, 1, image_file)) { |
70 fprintf(stderr, "Read error."); | 70 fprintf(stderr, "Read error."); |
(...skipping 25 matching lines...) Expand all Loading... |
96 | 96 |
97 /* Get image size */ | 97 /* Get image size */ |
98 image_file = fopen(image_name, "rb"); | 98 image_file = fopen(image_name, "rb"); |
99 if (!image_file) { | 99 if (!image_file) { |
100 fprintf(stderr, "Unable to open image file %s\n", image_name); | 100 fprintf(stderr, "Unable to open image file %s\n", image_name); |
101 return 1; | 101 return 1; |
102 } | 102 } |
103 fseek(image_file, 0, SEEK_END); | 103 fseek(image_file, 0, SEEK_END); |
104 lkp.ending_lba = (ftell(image_file) / LBA_BYTES) - 1; | 104 lkp.ending_lba = (ftell(image_file) / LBA_BYTES) - 1; |
105 rewind(image_file); | 105 rewind(image_file); |
106 printf("Ending LBA: %ld\n", lkp.ending_lba); | 106 printf("Ending LBA: %llu\n", lkp.ending_lba); |
107 | 107 |
108 /* Allocate a buffer for the kernel */ | 108 /* Allocate a buffer for the kernel */ |
109 lkp.kernel_buffer = Malloc(KERNEL_BUFFER_SIZE); | 109 lkp.kernel_buffer = Malloc(KERNEL_BUFFER_SIZE); |
110 if(!lkp.kernel_buffer) { | 110 if(!lkp.kernel_buffer) { |
111 fprintf(stderr, "Unable to allocate kernel buffer.\n"); | 111 fprintf(stderr, "Unable to allocate kernel buffer.\n"); |
112 return 1; | 112 return 1; |
113 } | 113 } |
114 | 114 |
115 /* TODO: Option for boot mode */ | 115 /* TODO: Option for boot mode */ |
116 lkp.boot_mode = BOOT_MODE_NORMAL; | 116 lkp.boot_mode = BOOT_MODE_NORMAL; |
117 | 117 |
118 /* Call LoadKernel() */ | 118 /* Call LoadKernel() */ |
119 rv = LoadKernel(&lkp); | 119 rv = LoadKernel(&lkp); |
120 printf("LoadKernel() returned %d\n", rv); | 120 printf("LoadKernel() returned %d\n", rv); |
121 | 121 |
122 fclose(image_file); | 122 fclose(image_file); |
123 Free(lkp.kernel_buffer); | 123 Free(lkp.kernel_buffer); |
124 return 0; | 124 return 0; |
125 } | 125 } |
OLD | NEW |