60 |
|
|
61 |
int isEfi = 0; |
int isEfi = 0; |
62 |
|
|
63 |
|
#if defined(__arch64__) |
64 |
|
#define isEfiOnly 1 |
65 |
|
#else |
66 |
|
#define isEfiOnly 0 |
67 |
|
#endif |
68 |
|
|
69 |
char *saved_command_line = NULL; |
char *saved_command_line = NULL; |
70 |
|
|
71 |
/* comments get lumped in with indention */ |
/* comments get lumped in with indention */ |
96 |
LT_SET_VARIABLE = 1 << 19, |
LT_SET_VARIABLE = 1 << 19, |
97 |
LT_KERNEL_EFI = 1 << 20, |
LT_KERNEL_EFI = 1 << 20, |
98 |
LT_INITRD_EFI = 1 << 21, |
LT_INITRD_EFI = 1 << 21, |
99 |
LT_UNKNOWN = 1 << 22, |
LT_KERNEL_16 = 1 << 22, |
100 |
|
LT_INITRD_16 = 1 << 23, |
101 |
|
LT_DEVTREE = 1 << 24, |
102 |
|
LT_UNKNOWN = 1 << 25, |
103 |
}; |
}; |
104 |
|
|
105 |
struct singleLine { |
struct singleLine { |
128 |
#define NEED_ARGS (1 << 3) |
#define NEED_ARGS (1 << 3) |
129 |
#define NEED_MB (1 << 4) |
#define NEED_MB (1 << 4) |
130 |
#define NEED_END (1 << 5) |
#define NEED_END (1 << 5) |
131 |
|
#define NEED_DEVTREE (1 << 6) |
132 |
|
|
133 |
#define MAIN_DEFAULT (1 << 0) |
#define MAIN_DEFAULT (1 << 0) |
134 |
#define DEFAULT_SAVED -2 |
#define DEFAULT_SAVED -2 |
233 |
{ "fallback", LT_FALLBACK, ' ' }, |
{ "fallback", LT_FALLBACK, ' ' }, |
234 |
{ "linux", LT_KERNEL, ' ' }, |
{ "linux", LT_KERNEL, ' ' }, |
235 |
{ "linuxefi", LT_KERNEL_EFI, ' ' }, |
{ "linuxefi", LT_KERNEL_EFI, ' ' }, |
236 |
|
{ "linux16", LT_KERNEL_16, ' ' }, |
237 |
{ "initrd", LT_INITRD, ' ', ' ' }, |
{ "initrd", LT_INITRD, ' ', ' ' }, |
238 |
{ "initrdefi", LT_INITRD_EFI, ' ', ' ' }, |
{ "initrdefi", LT_INITRD_EFI, ' ', ' ' }, |
239 |
|
{ "initrd16", LT_INITRD_16, ' ', ' ' }, |
240 |
{ "module", LT_MBMODULE, ' ' }, |
{ "module", LT_MBMODULE, ' ' }, |
241 |
{ "kernel", LT_HYPER, ' ' }, |
{ "kernel", LT_HYPER, ' ' }, |
242 |
|
{ "devicetree", LT_DEVTREE, ' ' }, |
243 |
{ NULL, 0, 0 }, |
{ NULL, 0, 0 }, |
244 |
}; |
}; |
245 |
|
|
411 |
} |
} |
412 |
|
|
413 |
static int iskernel(enum lineType_e type) { |
static int iskernel(enum lineType_e type) { |
414 |
return (type == LT_KERNEL || type == LT_KERNEL_EFI); |
return (type == LT_KERNEL || type == LT_KERNEL_EFI || type == LT_KERNEL_16); |
415 |
} |
} |
416 |
|
|
417 |
static int isinitrd(enum lineType_e type) { |
static int isinitrd(enum lineType_e type) { |
418 |
return (type == LT_INITRD || type == LT_INITRD_EFI); |
return (type == LT_INITRD || type == LT_INITRD_EFI || type == LT_INITRD_16); |
419 |
} |
} |
420 |
|
|
421 |
char *grub2ExtractTitle(struct singleLine * line) { |
char *grub2ExtractTitle(struct singleLine * line) { |
727 |
if (isEfi && cfi == &grub2ConfigType) { |
if (isEfi && cfi == &grub2ConfigType) { |
728 |
switch (type) { |
switch (type) { |
729 |
case LT_KERNEL: |
case LT_KERNEL: |
730 |
return LT_KERNEL_EFI; |
return isEfiOnly ? LT_KERNEL : LT_KERNEL_EFI; |
731 |
|
case LT_INITRD: |
732 |
|
return isEfiOnly ? LT_INITRD : LT_INITRD_EFI; |
733 |
|
default: |
734 |
|
return type; |
735 |
|
} |
736 |
|
#if defined(__i386__) || defined(__x86_64__) |
737 |
|
} else if (cfi == &grub2ConfigType) { |
738 |
|
switch (type) { |
739 |
|
case LT_KERNEL: |
740 |
|
return LT_KERNEL_16; |
741 |
case LT_INITRD: |
case LT_INITRD: |
742 |
return LT_INITRD_EFI; |
return LT_INITRD_16; |
743 |
default: |
default: |
744 |
return type; |
return type; |
745 |
} |
} |
746 |
|
#endif |
747 |
} |
} |
748 |
return type; |
return type; |
749 |
} |
} |
1831 |
return 0; |
return 0; |
1832 |
} |
} |
1833 |
|
|
1834 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
1835 |
if (!line) { |
if (!line) { |
1836 |
notSuitablePrintf(entry, 0, "no line found\n"); |
notSuitablePrintf(entry, 0, "no line found\n"); |
1837 |
return 0; |
return 0; |
1965 |
entry = findEntryByIndex(config, indexVars[i]); |
entry = findEntryByIndex(config, indexVars[i]); |
1966 |
if (!entry) return NULL; |
if (!entry) return NULL; |
1967 |
|
|
1968 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
1969 |
if (!line) return NULL; |
if (!line) return NULL; |
1970 |
|
|
1971 |
if (index) *index = indexVars[i]; |
if (index) *index = indexVars[i]; |
2016 |
for (line = entry->lines; line; line = line->next) { |
for (line = entry->lines; line; line = line->next) { |
2017 |
enum lineType_e ct = checkType; |
enum lineType_e ct = checkType; |
2018 |
if (entry->multiboot && checkType == LT_KERNEL) |
if (entry->multiboot && checkType == LT_KERNEL) |
2019 |
ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER; |
ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER|LT_KERNEL_16; |
2020 |
else if (checkType & LT_KERNEL) |
else if (checkType & LT_KERNEL) |
2021 |
ct = checkType | LT_KERNEL_EFI; |
ct = checkType | LT_KERNEL_EFI | LT_KERNEL_16; |
2022 |
line = getLineByType(ct, line); |
line = getLineByType(ct, line); |
2023 |
if (!line) |
if (!line) |
2024 |
break; /* not found in this entry */ |
break; /* not found in this entry */ |
2040 |
* non-Linux boot entries (could find netbsd etc, though, which is |
* non-Linux boot entries (could find netbsd etc, though, which is |
2041 |
* unfortunate) |
* unfortunate) |
2042 |
*/ |
*/ |
2043 |
if (line && getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines)) |
if (line && getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines)) |
2044 |
break; /* found 'im! */ |
break; /* found 'im! */ |
2045 |
} |
} |
2046 |
|
|
2274 |
|
|
2275 |
printf("index=%d\n", index); |
printf("index=%d\n", index); |
2276 |
|
|
2277 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
2278 |
if (!line) { |
if (!line) { |
2279 |
printf("non linux entry\n"); |
printf("non linux entry\n"); |
2280 |
return; |
return; |
2339 |
printf("root=%s\n", s); |
printf("root=%s\n", s); |
2340 |
} |
} |
2341 |
|
|
2342 |
line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); |
line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); |
2343 |
|
|
2344 |
if (line && line->numElements >= 2) { |
if (line && line->numElements >= 2) { |
2345 |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) |
2756 |
insertElement(newLine, val, 1, cfi); |
insertElement(newLine, val, 1, cfi); |
2757 |
|
|
2758 |
/* but try to keep the rootspec from the template... sigh */ |
/* but try to keep the rootspec from the template... sigh */ |
2759 |
if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD|LT_KERNEL_EFI|LT_INITRD_EFI)) { |
if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD|LT_KERNEL_EFI|LT_INITRD_EFI|LT_KERNEL_16|LT_INITRD_16)) { |
2760 |
char * rootspec = getRootSpecifier(tmplLine->elements[1].item); |
char * rootspec = getRootSpecifier(tmplLine->elements[1].item); |
2761 |
if (rootspec != NULL) { |
if (rootspec != NULL) { |
2762 |
free(newLine->elements[1].item); |
free(newLine->elements[1].item); |
3126 |
firstElement = 2; |
firstElement = 2; |
3127 |
|
|
3128 |
} else { |
} else { |
3129 |
line = getLineByType(LT_KERNEL|LT_MBMODULE|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_MBMODULE|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
3130 |
if (!line) { |
if (!line) { |
3131 |
/* no LT_KERNEL or LT_MBMODULE in this entry? */ |
/* no LT_KERNEL or LT_MBMODULE in this entry? */ |
3132 |
continue; |
continue; |
3327 |
if (!image) return 0; |
if (!image) return 0; |
3328 |
|
|
3329 |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
3330 |
kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI, entry->lines); |
kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
3331 |
if (!kernelLine) continue; |
if (!kernelLine) continue; |
3332 |
|
|
3333 |
line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); |
line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); |
3334 |
if (line) |
if (line) |
3335 |
removeLine(entry, line); |
removeLine(entry, line); |
3336 |
if (prefix) { |
if (prefix) { |
3341 |
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
3342 |
if (endLine) |
if (endLine) |
3343 |
removeLine(entry, endLine); |
removeLine(entry, endLine); |
3344 |
line = addLine(entry, cfg->cfi, preferredLineType(LT_INITRD, cfg->cfi), |
enum lineType_e lt; |
3345 |
kernelLine->indent, initrd); |
switch(kernelLine->type) { |
3346 |
|
case LT_KERNEL: |
3347 |
|
lt = LT_INITRD; |
3348 |
|
break; |
3349 |
|
case LT_KERNEL_EFI: |
3350 |
|
lt = LT_INITRD_EFI; |
3351 |
|
break; |
3352 |
|
case LT_KERNEL_16: |
3353 |
|
lt = LT_INITRD_16; |
3354 |
|
break; |
3355 |
|
default: |
3356 |
|
lt = preferredLineType(LT_INITRD, cfg->cfi); |
3357 |
|
} |
3358 |
|
line = addLine(entry, cfg->cfi, lt, kernelLine->indent, initrd); |
3359 |
if (!line) |
if (!line) |
3360 |
return 1; |
return 1; |
3361 |
if (endLine) { |
if (endLine) { |
3714 |
const char * newKernelPath, const char * newKernelTitle, |
const char * newKernelPath, const char * newKernelTitle, |
3715 |
const char * newKernelArgs, const char * newKernelInitrd, |
const char * newKernelArgs, const char * newKernelInitrd, |
3716 |
const char ** extraInitrds, int extraInitrdCount, |
const char ** extraInitrds, int extraInitrdCount, |
3717 |
const char * newMBKernel, const char * newMBKernelArgs) { |
const char * newMBKernel, const char * newMBKernelArgs, |
3718 |
|
const char * newDevTreePath) { |
3719 |
struct singleEntry * new; |
struct singleEntry * new; |
3720 |
struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL; |
struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL; |
3721 |
int needs; |
int needs; |
3756 |
needs |= NEED_MB; |
needs |= NEED_MB; |
3757 |
new->multiboot = 1; |
new->multiboot = 1; |
3758 |
} |
} |
3759 |
|
if (newDevTreePath && getKeywordByType(LT_DEVTREE, config->cfi)) |
3760 |
|
needs |= NEED_DEVTREE; |
3761 |
|
|
3762 |
if (template) { |
if (template) { |
3763 |
for (masterLine = template->lines; |
for (masterLine = template->lines; |
3943 |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, |
3944 |
config->cfi); |
config->cfi); |
3945 |
} |
} |
3946 |
|
} else if (tmplLine->type == LT_DEVTREE && |
3947 |
|
tmplLine->numElements == 2 && newDevTreePath) { |
3948 |
|
newLine = addLineTmpl(new, tmplLine, newLine, |
3949 |
|
newDevTreePath + strlen(prefix), |
3950 |
|
config->cfi); |
3951 |
|
needs &= ~NEED_DEVTREE; |
3952 |
|
} else if (tmplLine->type == LT_ENTRY_END && needs & NEED_DEVTREE) { |
3953 |
|
const char *ndtp = newDevTreePath; |
3954 |
|
if (!strncmp(newDevTreePath, prefix, strlen(prefix))) |
3955 |
|
ndtp += strlen(prefix); |
3956 |
|
newLine = addLine(new, config->cfi, LT_DEVTREE, |
3957 |
|
config->secondaryIndent, |
3958 |
|
ndtp); |
3959 |
|
needs &= ~NEED_DEVTREE; |
3960 |
|
newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); |
3961 |
} else { |
} else { |
3962 |
/* pass through other lines from the template */ |
/* pass through other lines from the template */ |
3963 |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); |
newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); |
3971 |
switch (config->cfi->entryStart) { |
switch (config->cfi->entryStart) { |
3972 |
case LT_KERNEL: |
case LT_KERNEL: |
3973 |
case LT_KERNEL_EFI: |
case LT_KERNEL_EFI: |
3974 |
|
case LT_KERNEL_16: |
3975 |
if (new->multiboot && config->cfi->mbHyperFirst) { |
if (new->multiboot && config->cfi->mbHyperFirst) { |
3976 |
/* fall through to LT_HYPER */ |
/* fall through to LT_HYPER */ |
3977 |
} else { |
} else { |
4078 |
free(initrdVal); |
free(initrdVal); |
4079 |
needs &= ~NEED_INITRD; |
needs &= ~NEED_INITRD; |
4080 |
} |
} |
4081 |
|
if (needs & NEED_DEVTREE) { |
4082 |
|
newLine = addLine(new, config->cfi, LT_DEVTREE, |
4083 |
|
config->secondaryIndent, |
4084 |
|
newDevTreePath); |
4085 |
|
needs &= ~NEED_DEVTREE; |
4086 |
|
} |
4087 |
|
|
4088 |
|
/* NEEDS_END must be last on bootloaders that need it... */ |
4089 |
if (needs & NEED_END) { |
if (needs & NEED_END) { |
4090 |
newLine = addLine(new, config->cfi, LT_ENTRY_END, |
newLine = addLine(new, config->cfi, LT_ENTRY_END, |
4091 |
config->secondaryIndent, NULL); |
config->secondaryIndent, NULL); |
4092 |
needs &= ~NEED_END; |
needs &= ~NEED_END; |
4093 |
} |
} |
|
|
|
4094 |
if (needs) { |
if (needs) { |
4095 |
printf(_("grubby: needs=%d, aborting\n"), needs); |
printf(_("grubby: needs=%d, aborting\n"), needs); |
4096 |
abort(); |
abort(); |
4136 |
char * newKernelArgs = NULL; |
char * newKernelArgs = NULL; |
4137 |
char * newKernelInitrd = NULL; |
char * newKernelInitrd = NULL; |
4138 |
char * newKernelTitle = NULL; |
char * newKernelTitle = NULL; |
4139 |
char * newKernelVersion = NULL; |
char * newDevTreePath = NULL; |
4140 |
char * newMBKernel = NULL; |
char * newMBKernel = NULL; |
4141 |
char * newMBKernelArgs = NULL; |
char * newMBKernelArgs = NULL; |
4142 |
char * removeMBKernelArgs = NULL; |
char * removeMBKernelArgs = NULL; |
4194 |
_("display the index of the default kernel") }, |
_("display the index of the default kernel") }, |
4195 |
{ "default-title", 0, 0, &displayDefaultTitle, 0, |
{ "default-title", 0, 0, &displayDefaultTitle, 0, |
4196 |
_("display the title of the default kernel") }, |
_("display the title of the default kernel") }, |
4197 |
|
{ "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0, |
4198 |
|
_("device tree file for new stanza"), _("dtb-path") }, |
4199 |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
4200 |
_("configure elilo bootloader") }, |
_("configure elilo bootloader") }, |
4201 |
{ "efi", 0, POPT_ARG_NONE, &isEfi, 0, |
{ "efi", 0, POPT_ARG_NONE, &isEfi, 0, |
4361 |
grubConfig = cfi->defaultConfig; |
grubConfig = cfi->defaultConfig; |
4362 |
} |
} |
4363 |
|
|
4364 |
if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || |
if (bootloaderProbe && (displayDefault || kernelInfo || |
4365 |
newKernelPath || removeKernelPath || makeDefault || |
newKernelPath || removeKernelPath || makeDefault || |
4366 |
defaultKernel || displayDefaultIndex || displayDefaultTitle || |
defaultKernel || displayDefaultIndex || displayDefaultTitle || |
4367 |
(defaultIndex >= 0))) { |
(defaultIndex >= 0))) { |
4370 |
return 1; |
return 1; |
4371 |
} |
} |
4372 |
|
|
4373 |
if ((displayDefault || kernelInfo) && (newKernelVersion || newKernelPath || |
if ((displayDefault || kernelInfo) && (newKernelPath || |
4374 |
removeKernelPath)) { |
removeKernelPath)) { |
4375 |
fprintf(stderr, _("grubby: --default-kernel and --info may not " |
fprintf(stderr, _("grubby: --default-kernel and --info may not " |
4376 |
"be used when adding or removing kernels\n")); |
"be used when adding or removing kernels\n")); |
4539 |
if (!entry) return 0; |
if (!entry) return 0; |
4540 |
if (!suitableImage(entry, bootPrefix, 0, flags)) return 0; |
if (!suitableImage(entry, bootPrefix, 0, flags)) return 0; |
4541 |
|
|
4542 |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI, entry->lines); |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); |
4543 |
if (!line) return 0; |
if (!line) return 0; |
4544 |
|
|
4545 |
rootspec = getRootSpecifier(line->elements[1].item); |
rootspec = getRootSpecifier(line->elements[1].item); |
4613 |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
4614 |
newKernelTitle, newKernelArgs, newKernelInitrd, |
newKernelTitle, newKernelArgs, newKernelInitrd, |
4615 |
(const char **)extraInitrds, extraInitrdCount, |
(const char **)extraInitrds, extraInitrdCount, |
4616 |
newMBKernel, newMBKernelArgs)) return 1; |
newMBKernel, newMBKernelArgs, newDevTreePath)) return 1; |
4617 |
|
|
4618 |
|
|
4619 |
if (numEntries(config) == 0) { |
if (numEntries(config) == 0) { |