--- trunk/grubby/grubby.c 2014/07/16 09:49:24 2682 +++ trunk/grubby/grubby.c 2014/07/16 10:45:12 2692 @@ -60,6 +60,12 @@ int isEfi = 0; +#if defined(__arch64__) +#define isEfiOnly 1 +#else +#define isEfiOnly 0 +#endif + char *saved_command_line = NULL; /* comments get lumped in with indention */ @@ -90,7 +96,10 @@ LT_SET_VARIABLE = 1 << 19, LT_KERNEL_EFI = 1 << 20, LT_INITRD_EFI = 1 << 21, - LT_UNKNOWN = 1 << 22, + LT_KERNEL_16 = 1 << 22, + LT_INITRD_16 = 1 << 23, + LT_DEVTREE = 1 << 24, + LT_UNKNOWN = 1 << 25, }; struct singleLine { @@ -119,6 +128,7 @@ #define NEED_ARGS (1 << 3) #define NEED_MB (1 << 4) #define NEED_END (1 << 5) +#define NEED_DEVTREE (1 << 6) #define MAIN_DEFAULT (1 << 0) #define DEFAULT_SAVED -2 @@ -151,6 +161,7 @@ int defaultIsVariable; int defaultSupportSaved; int defaultIsSaved; + int defaultIsUnquoted; enum lineType_e entryStart; enum lineType_e entryEnd; int needsBootPrefix; @@ -223,10 +234,13 @@ { "fallback", LT_FALLBACK, ' ' }, { "linux", LT_KERNEL, ' ' }, { "linuxefi", LT_KERNEL_EFI, ' ' }, + { "linux16", LT_KERNEL_16, ' ' }, { "initrd", LT_INITRD, ' ', ' ' }, { "initrdefi", LT_INITRD_EFI, ' ', ' ' }, + { "initrd16", LT_INITRD_16, ' ', ' ' }, { "module", LT_MBMODULE, ' ' }, { "kernel", LT_HYPER, ' ' }, + { "devicetree", LT_DEVTREE, ' ' }, { NULL, 0, 0 }, }; @@ -398,11 +412,11 @@ } static int iskernel(enum lineType_e type) { - return (type == LT_KERNEL || type == LT_KERNEL_EFI); + return (type == LT_KERNEL || type == LT_KERNEL_EFI || type == LT_KERNEL_16); } static int isinitrd(enum lineType_e type) { - return (type == LT_INITRD || type == LT_INITRD_EFI); + return (type == LT_INITRD || type == LT_INITRD_EFI || type == LT_INITRD_16); } char *grub2ExtractTitle(struct singleLine * line) { @@ -623,6 +637,7 @@ .needsBootPrefix = 1, .maxTitleLength = 255, .mbAllowExtraInitRds = 1, + .defaultIsUnquoted = 1, }; struct grubConfig { @@ -714,12 +729,23 @@ if (isEfi && cfi == &grub2ConfigType) { switch (type) { case LT_KERNEL: - return LT_KERNEL_EFI; + return isEfiOnly ? LT_KERNEL : LT_KERNEL_EFI; case LT_INITRD: - return LT_INITRD_EFI; + return isEfiOnly ? LT_INITRD : LT_INITRD_EFI; default: return type; } +#if defined(__i386__) || defined(__x86_64__) + } else if (cfi == &grub2ConfigType) { + switch (type) { + case LT_KERNEL: + return LT_KERNEL_16; + case LT_INITRD: + return LT_INITRD_16; + default: + return type; + } +#endif } return type; } @@ -1167,9 +1193,6 @@ cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; defaultLine = line; } - } else if (line->type == LT_DEFAULT && line->numElements == 2) { - cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; - defaultLine = line; } else if (iskernel(line->type)) { /* if by some freak chance this is multiboot and the "module" @@ -1202,8 +1225,9 @@ cfg->fallbackImage = strtol(line->elements[1].item, &end, 10); if (*end) cfg->fallbackImage = -1; - } else if (line->type == LT_TITLE && line->numElements > 1) { - /* make the title a single argument (undoing our parsing) */ + } else if ((line->type == LT_DEFAULT && cfi->defaultIsUnquoted) || + (line->type == LT_TITLE && line->numElements > 1)) { + /* make the title/default a single argument (undoing our parsing) */ len = 0; for (int i = 1; i < line->numElements; i++) { len += strlen(line->elements[i].item); @@ -1310,6 +1334,11 @@ } } + if (line->type == LT_DEFAULT && line->numElements == 2) { + cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT; + defaultLine = line; + } + /* If we find a generic config option which should live at the top of the file, move it there. Old versions of grubby were probably responsible for putting new images in the wrong @@ -1807,7 +1836,7 @@ return 0; } - 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); if (!line) { notSuitablePrintf(entry, 0, "no line found\n"); return 0; @@ -1941,7 +1970,7 @@ entry = findEntryByIndex(config, indexVars[i]); if (!entry) return NULL; - 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); if (!line) return NULL; if (index) *index = indexVars[i]; @@ -1992,9 +2021,9 @@ for (line = entry->lines; line; line = line->next) { enum lineType_e ct = checkType; if (entry->multiboot && checkType == LT_KERNEL) - ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER; + ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER|LT_KERNEL_16; else if (checkType & LT_KERNEL) - ct = checkType | LT_KERNEL_EFI; + ct = checkType | LT_KERNEL_EFI | LT_KERNEL_16; line = getLineByType(ct, line); if (!line) break; /* not found in this entry */ @@ -2016,7 +2045,7 @@ * non-Linux boot entries (could find netbsd etc, though, which is * unfortunate) */ - 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)) break; /* found 'im! */ } @@ -2250,7 +2279,7 @@ printf("index=%d\n", index); - 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); if (!line) { printf("non linux entry\n"); return; @@ -2315,7 +2344,7 @@ printf("root=%s\n", s); } - line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); + line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); if (line && line->numElements >= 2) { if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) @@ -2732,7 +2761,7 @@ insertElement(newLine, val, 1, cfi); /* but try to keep the rootspec from the template... sigh */ - 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)) { char * rootspec = getRootSpecifier(tmplLine->elements[1].item); if (rootspec != NULL) { free(newLine->elements[1].item); @@ -3102,7 +3131,7 @@ firstElement = 2; } else { - 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); if (!line) { /* no LT_KERNEL or LT_MBMODULE in this entry? */ continue; @@ -3303,10 +3332,10 @@ if (!image) return 0; for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { - kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI, entry->lines); + kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); if (!kernelLine) continue; - line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines); + line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); if (line) removeLine(entry, line); if (prefix) { @@ -3317,8 +3346,21 @@ endLine = getLineByType(LT_ENTRY_END, entry->lines); if (endLine) removeLine(entry, endLine); - line = addLine(entry, cfg->cfi, preferredLineType(LT_INITRD, cfg->cfi), - kernelLine->indent, initrd); + enum lineType_e lt; + switch(kernelLine->type) { + case LT_KERNEL: + lt = LT_INITRD; + break; + case LT_KERNEL_EFI: + lt = LT_INITRD_EFI; + break; + case LT_KERNEL_16: + lt = LT_INITRD_16; + break; + default: + lt = preferredLineType(LT_INITRD, cfg->cfi); + } + line = addLine(entry, cfg->cfi, lt, kernelLine->indent, initrd); if (!line) return 1; if (endLine) { @@ -3677,7 +3719,8 @@ const char * newKernelPath, const char * newKernelTitle, const char * newKernelArgs, const char * newKernelInitrd, const char ** extraInitrds, int extraInitrdCount, - const char * newMBKernel, const char * newMBKernelArgs) { + const char * newMBKernel, const char * newMBKernelArgs, + const char * newDevTreePath) { struct singleEntry * new; struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL; int needs; @@ -3718,6 +3761,8 @@ needs |= NEED_MB; new->multiboot = 1; } + if (newDevTreePath && getKeywordByType(LT_DEVTREE, config->cfi)) + needs |= NEED_DEVTREE; if (template) { for (masterLine = template->lines; @@ -3903,6 +3948,21 @@ newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); } + } else if (tmplLine->type == LT_DEVTREE && + tmplLine->numElements == 2 && newDevTreePath) { + newLine = addLineTmpl(new, tmplLine, newLine, + newDevTreePath + strlen(prefix), + config->cfi); + needs &= ~NEED_DEVTREE; + } else if (tmplLine->type == LT_ENTRY_END && needs & NEED_DEVTREE) { + const char *ndtp = newDevTreePath; + if (!strncmp(newDevTreePath, prefix, strlen(prefix))) + ndtp += strlen(prefix); + newLine = addLine(new, config->cfi, LT_DEVTREE, + config->secondaryIndent, + ndtp); + needs &= ~NEED_DEVTREE; + newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); } else { /* pass through other lines from the template */ newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi); @@ -3916,6 +3976,7 @@ switch (config->cfi->entryStart) { case LT_KERNEL: case LT_KERNEL_EFI: + case LT_KERNEL_16: if (new->multiboot && config->cfi->mbHyperFirst) { /* fall through to LT_HYPER */ } else { @@ -4022,12 +4083,19 @@ free(initrdVal); needs &= ~NEED_INITRD; } + if (needs & NEED_DEVTREE) { + newLine = addLine(new, config->cfi, LT_DEVTREE, + config->secondaryIndent, + newDevTreePath); + needs &= ~NEED_DEVTREE; + } + + /* NEEDS_END must be last on bootloaders that need it... */ if (needs & NEED_END) { newLine = addLine(new, config->cfi, LT_ENTRY_END, config->secondaryIndent, NULL); needs &= ~NEED_END; } - if (needs) { printf(_("grubby: needs=%d, aborting\n"), needs); abort(); @@ -4073,7 +4141,7 @@ char * newKernelArgs = NULL; char * newKernelInitrd = NULL; char * newKernelTitle = NULL; - char * newKernelVersion = NULL; + char * newDevTreePath = NULL; char * newMBKernel = NULL; char * newMBKernelArgs = NULL; char * removeMBKernelArgs = NULL; @@ -4131,6 +4199,8 @@ _("display the index of the default kernel") }, { "default-title", 0, 0, &displayDefaultTitle, 0, _("display the title of the default kernel") }, + { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0, + _("device tree file for new stanza"), _("dtb-path") }, { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, _("configure elilo bootloader") }, { "efi", 0, POPT_ARG_NONE, &isEfi, 0, @@ -4296,7 +4366,7 @@ grubConfig = cfi->defaultConfig; } - if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || + if (bootloaderProbe && (displayDefault || kernelInfo || newKernelPath || removeKernelPath || makeDefault || defaultKernel || displayDefaultIndex || displayDefaultTitle || (defaultIndex >= 0))) { @@ -4305,7 +4375,7 @@ return 1; } - if ((displayDefault || kernelInfo) && (newKernelVersion || newKernelPath || + if ((displayDefault || kernelInfo) && (newKernelPath || removeKernelPath)) { fprintf(stderr, _("grubby: --default-kernel and --info may not " "be used when adding or removing kernels\n")); @@ -4474,7 +4544,7 @@ if (!entry) return 0; if (!suitableImage(entry, bootPrefix, 0, flags)) return 0; - 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); if (!line) return 0; rootspec = getRootSpecifier(line->elements[1].item); @@ -4548,7 +4618,7 @@ if (addNewKernel(config, template, bootPrefix, newKernelPath, newKernelTitle, newKernelArgs, newKernelInitrd, (const char **)extraInitrds, extraInitrdCount, - newMBKernel, newMBKernelArgs)) return 1; + newMBKernel, newMBKernelArgs, newDevTreePath)) return 1; if (numEntries(config) == 0) {