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

Side by Side Diff: bootstub.c

Issue 2832078: Export the kernel partition's UniqueGuid to the kernel command line. (Closed) Base URL: ssh://git@chromiumos-git//bootstub.git
Patch Set: Created 10 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // 2 //
3 // This program is free software: you can redistribute it and/or modify 3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by 4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or 5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version. 6 // (at your option) any later version.
7 // 7 //
8 // This program is distributed in the hope that it will be useful, 8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 26 matching lines...) Expand all
37 37
38 38
39 // Find where the preloaded params struct is located in RAM. At the moment 39 // Find where the preloaded params struct is located in RAM. At the moment
40 // we're assuming that it immediately precedes the start of the bootstub, 40 // we're assuming that it immediately precedes the start of the bootstub,
41 // aligned to a 4K boundary, because that's where our build system puts it. 41 // aligned to a 4K boundary, because that's where our build system puts it.
42 struct hacked_params *find_params_struct(UINTN bootstub_location) 42 struct hacked_params *find_params_struct(UINTN bootstub_location)
43 { 43 {
44 return (struct hacked_params *)(bootstub_location - 0x1000); 44 return (struct hacked_params *)(bootstub_location - 0x1000);
45 } 45 }
46 46
47 // Copy a string to the right within a buffer.
48 static void shove_over(char *src, char *dst)
49 {
50 int i = 0;
51 for (i=0; src[i]; i++)
52 ; // find strlen(src)
53 dst += i;
54 src += i;
55 i++; // also terminating '\0';
56 while (i--)
57 *dst-- = *src--;
58 }
59
60 // sprintf(dst,"%02x",val)
61 static void one_byte(char *dst, uint8_t val)
62 {
63 dst[0] = "0123456789abcdef"[(val >> 4) & 0x0F];
64 dst[1] = "0123456789abcdef"[val & 0x0F];
65 }
66
67 // Display a GUID in canonical form
68 static void emit_guid(char *dst, uint8_t *guid)
69 {
70 one_byte(dst, guid[3]); dst += 2;
71 one_byte(dst, guid[2]); dst += 2;
72 one_byte(dst, guid[1]); dst += 2;
73 one_byte(dst, guid[0]); dst += 2;
74 *dst++ = '-';
75 one_byte(dst, guid[5]); dst += 2;
76 one_byte(dst, guid[4]); dst += 2;
77 *dst++ = '-';
78 one_byte(dst, guid[7]); dst += 2;
79 one_byte(dst, guid[6]); dst += 2;
80 *dst++ = '-';
81 one_byte(dst, guid[8]); dst += 2;
82 one_byte(dst, guid[9]); dst += 2;
83 *dst++ = '-';
84 one_byte(dst, guid[10]); dst += 2;
85 one_byte(dst, guid[11]); dst += 2;
86 one_byte(dst, guid[12]); dst += 2;
87 one_byte(dst, guid[13]); dst += 2;
88 one_byte(dst, guid[14]); dst += 2;
89 one_byte(dst, guid[15]); dst += 2;
90 }
91
92
47 // Replace any %D with the device letter, and replace any %P with the partition 93 // Replace any %D with the device letter, and replace any %P with the partition
48 // number. For example, ("root=/dev/sd%D%P",2,3) gives "root=/dev/sdc3". The 94 // number. For example, ("root=/dev/sd%D%P",2,3) gives "root=/dev/sdc3".
49 // input string must be mutable and end with a trailing '\0'. 95 // Replace any %U with the human-readable form of the GUID (if provided). The
50 void update_cmdline_inplace(char *src, int devnum, int partnum) 96 // input string must be mutable and end with a trailing '\0', and have enough
97 // room for all the expansion.
98 static void update_cmdline_inplace(char *src, int devnum, int partnum,
99 uint8_t *guid)
51 { 100 {
52 char *dst; 101 char *dst;
53 102
54 // Use sane values (sda3) for ridiculous inputs. 103 // Use sane values (sda3) for ridiculous inputs.
55 if (devnum < 0 || devnum > 25 || partnum < 1 || partnum > 99) 104 if (devnum < 0 || devnum > 25 || partnum < 1 || partnum > 99)
56 { 105 {
57 devnum = 0; 106 devnum = 0;
58 partnum = 3; 107 partnum = 3;
59 } 108 }
60 109
61 for( dst = src; *src; src++, dst++ ) 110 for( dst = src; *src; src++, dst++ )
62 { 111 {
63 if ( src[0] == '%' ) 112 if ( src[0] == '%' )
64 { 113 {
65 switch (src[1]) 114 switch (src[1])
66 { 115 {
67 case 'P': 116 case 'P':
68 if (partnum > 9) 117 if (partnum > 9)
69 *dst++ = '0' + (partnum / 10); 118 *dst++ = '0' + (partnum / 10);
70 *dst = '0' + partnum % 10; 119 *dst = '0' + partnum % 10;
71 src++; 120 src++;
72 break; 121 break;
73 case 'D': 122 case 'D':
74 *dst = 'a' + devnum; 123 *dst = 'a' + devnum;
75 src++; 124 src++;
76 break; 125 break;
126 case 'U':
127 if (guid) {
128 shove_over(src+2, dst+36);
129 emit_guid(dst, guid);
130 src = dst+35;
131 dst += 35;
132 }
77 default: 133 default:
78 *dst = *src; 134 *dst = *src;
79 } 135 }
80 } 136 }
81 else if (dst != src) 137 else if (dst != src)
82 *dst = *src; 138 *dst = *src;
83 } 139 }
84 *dst = '\0'; 140 *dst = '\0';
85 } 141 }
86 142
87 // This is handy to write status codes to the LEDs for debugging. 143 // This is handy to write status codes to the LEDs for debugging.
88 static __inline void port80w (unsigned short int value) 144 static __inline void port80w (unsigned short int value)
89 { 145 {
90 __asm__ __volatile__ ("outw %w0,$0x80": :"a" (value)); 146 __asm__ __volatile__ ("outw %w0,$0x80": :"a" (value));
91 } 147 }
92 148
93 149
94 // The code to switch to 32-bit mode and start the kernel. 150 // The code to switch to 32-bit mode and start the kernel.
95 extern void trampoline(unsigned long, void *); 151 extern void trampoline(unsigned long, void *);
96 152
97 153
98 // Reserve some space for the EFI memory map. 154 // Reserve some space for the EFI memory map.
99 // Danger Will Robinson: this is just a guess at the size and alignment. If 155 // Danger Will Robinson: this is just a guess at the size and alignment. If
100 // it's too small, the EFI GetMemoryMap() call will fail. 156 // it's too small, the EFI GetMemoryMap() call will fail.
101 // FIXME: Make the size dynamic? Retry with larger size on failure? 157 // FIXME: Make the size dynamic? Retry with larger size on failure?
102 static unsigned char mmap_buf[0x2000] __attribute__ ((aligned(0x200))); 158 static unsigned char mmap_buf[0x2000] __attribute__ ((aligned(0x200)));
103 159
104 // Parameters that we're given by the BIOS 160 // Parameters that we're given by the BIOS
105 typedef struct cros_boot_info { 161 typedef struct cros_boot_info {
106 UINTN drive_number; // 0 - 25 162 UINTN drive_number; // 0 - 25
107 UINTN partition_number; // 1 - 99 163 UINTN partition_number; // 1 - 99
108 UINTN original_address; // our RAM address prior to execution 164 UINTN original_address; // our RAM address prior to execution
165 // The guid stuff was added later, so we need to consider it optional, at
166 // least for testing.
167 uint8_t partition_guid[16]; // kernel partition GUID
109 } cros_boot_info_t; 168 } cros_boot_info_t;
110 169
111 170
112 // Here's the entry point. It will be loaded by the BIOS as a standard EFI 171 // Here's the entry point. It will be loaded by the BIOS as a standard EFI
113 // application, which means it will be relocated. 172 // application, which means it will be relocated.
114 EFI_STATUS efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 173 EFI_STATUS efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
115 { 174 {
116 UINTN mmap_size = sizeof(mmap_buf); 175 UINTN mmap_size = sizeof(mmap_buf);
117 UINTN mmap_key = 0; 176 UINTN mmap_key = 0;
118 UINTN desc_size = 0; 177 UINTN desc_size = 0;
119 UINT32 desc_version = 0; 178 UINT32 desc_version = 0;
120 EFI_LOADED_IMAGE *loaded_image; 179 EFI_LOADED_IMAGE *loaded_image;
121 EFI_GUID loaded_image_protocol = LOADED_IMAGE_PROTOCOL; 180 EFI_GUID loaded_image_protocol = LOADED_IMAGE_PROTOCOL;
181 EFI_GUID zero_guid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
182 void *guid_ptr;
122 183
123 // I'm here. 184 // I'm here.
124 port80w(0xc0de); 185 port80w(0xc0de);
125 186
126 // Find the parameters that the BIOS has passed to us. 187 // Find the parameters that the BIOS has passed to us.
127 if (uefi_call_wrapper(systab->BootServices->HandleProtocol, 3, 188 if (uefi_call_wrapper(systab->BootServices->HandleProtocol, 3,
128 image, 189 image,
129 &loaded_image_protocol, 190 &loaded_image_protocol,
130 &loaded_image) != 0) 191 &loaded_image) != 0)
131 { 192 {
132 uefi_call_wrapper(systab->ConOut->OutputString, 3, systab->ConOut, 193 uefi_call_wrapper(systab->ConOut->OutputString, 3, systab->ConOut,
133 L"Can't locate protocol\r\n"); 194 L"Can't locate protocol\r\n");
134 goto fail; 195 goto fail;
135 } 196 }
136 cros_boot_info_t *booting = loaded_image->LoadOptions; 197 cros_boot_info_t *booting = loaded_image->LoadOptions;
198 if (loaded_image->LoadOptionsSize < 40) // DWR: min size including guid
199 guid_ptr = &zero_guid;
200 else
201 guid_ptr = booting->partition_guid;
137 202
138 // Find the parameters that we're passing to the kernel. 203 // Find the parameters that we're passing to the kernel.
139 struct hacked_params *params = find_params_struct(booting->original_address) ; 204 struct hacked_params *params = find_params_struct(booting->original_address) ;
140 205
141 // Update the kernel command-line string with the correct rootfs device 206 // Update the kernel command-line string with the correct rootfs device
142 update_cmdline_inplace((char *)(unsigned long)(params->cmd_line_ptr), 207 update_cmdline_inplace((char *)(unsigned long)(params->cmd_line_ptr),
143 booting->drive_number, 208 booting->drive_number,
144 booting->partition_number + 1); 209 booting->partition_number + 1,
210 guid_ptr);
145 211
146 // Obtain the EFI memory map. 212 // Obtain the EFI memory map.
147 if (uefi_call_wrapper(systab->BootServices->GetMemoryMap, 5, 213 if (uefi_call_wrapper(systab->BootServices->GetMemoryMap, 5,
148 &mmap_size, mmap_buf, &mmap_key, 214 &mmap_size, mmap_buf, &mmap_key,
149 &desc_size, &desc_version) != 0) 215 &desc_size, &desc_version) != 0)
150 { 216 {
151 uefi_call_wrapper(systab->ConOut->OutputString, 2, systab->ConOut, 217 uefi_call_wrapper(systab->ConOut->OutputString, 2, systab->ConOut,
152 L"Can't get memory map\r\n"); 218 L"Can't get memory map\r\n");
153 goto fail; 219 goto fail;
154 } 220 }
(...skipping 22 matching lines...) Expand all
177 // Trampoline to 32-bit entry point. Should never return. 243 // Trampoline to 32-bit entry point. Should never return.
178 trampoline(params->code32_start, params); 244 trampoline(params->code32_start, params);
179 245
180 fail: 246 fail:
181 247
182 // Bad Things happened. 248 // Bad Things happened.
183 port80w(0xdead); 249 port80w(0xdead);
184 250
185 return EFI_LOAD_ERROR; 251 return EFI_LOAD_ERROR;
186 } 252 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698