--- trunk/grubby/grubby.c 2014/07/16 09:51:14 2683 +++ trunk/grubby/grubby.c 2014/07/16 10:57:06 2709 @@ -60,6 +60,12 @@ int isEfi = 0; +#if defined(__aarch64__) +#define isEfiOnly 1 +#else +#define isEfiOnly 0 +#endif + char *saved_command_line = NULL; /* comments get lumped in with indention */ @@ -92,7 +98,8 @@ LT_INITRD_EFI = 1 << 21, LT_KERNEL_16 = 1 << 22, LT_INITRD_16 = 1 << 23, - LT_UNKNOWN = 1 << 24, + LT_DEVTREE = 1 << 24, + LT_UNKNOWN = 1 << 25, }; struct singleLine { @@ -121,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 @@ -153,6 +161,7 @@ int defaultIsVariable; int defaultSupportSaved; int defaultIsSaved; + int defaultIsUnquoted; enum lineType_e entryStart; enum lineType_e entryEnd; int needsBootPrefix; @@ -231,6 +240,7 @@ { "initrd16", LT_INITRD_16, ' ', ' ' }, { "module", LT_MBMODULE, ' ' }, { "kernel", LT_HYPER, ' ' }, + { "devicetree", LT_DEVTREE, ' ' }, { NULL, 0, 0 }, }; @@ -627,6 +637,7 @@ .needsBootPrefix = 1, .maxTitleLength = 255, .mbAllowExtraInitRds = 1, + .defaultIsUnquoted = 1, }; struct grubConfig { @@ -718,9 +729,9 @@ 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; } @@ -1182,16 +1193,13 @@ 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" * lines came earlier in the template, make sure to use LT_HYPER * instead of LT_KERNEL now */ - if (entry->multiboot) + if (entry && entry->multiboot) line->type = LT_HYPER; } else if (line->type == LT_MBMODULE) { @@ -1217,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); @@ -1325,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 @@ -2262,6 +2276,7 @@ struct singleLine * line; char * root = NULL; int i; + int j; printf("index=%d\n", index); @@ -2353,6 +2368,20 @@ if (title) printf("title=%s\n", title); } + + for (j = 0, line = entry->lines; line; line = line->next) { + if ((line->type & LT_MBMODULE) && line->numElements >= 2) { + if (!strncmp(prefix, line->elements[1].item, strlen(prefix))) + printf("mbmodule%d=", j); + else + printf("mbmodule%d=%s", j, prefix); + + for (i = 1; i < line->numElements; i++) + printf("%s%s", line->elements[i].item, line->elements[i].indent); + printf("\n"); + j++; + } + } } int isSuseSystem(void) { @@ -3705,7 +3734,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; @@ -3746,6 +3776,8 @@ needs |= NEED_MB; new->multiboot = 1; } + if (newDevTreePath && getKeywordByType(LT_DEVTREE, config->cfi)) + needs |= NEED_DEVTREE; if (template) { for (masterLine = template->lines; @@ -3931,6 +3963,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); @@ -4006,6 +4053,13 @@ } } + struct singleLine *endLine = NULL; + endLine = getLineByType(LT_ENTRY_END, new->lines); + if (endLine) { + removeLine(new, endLine); + needs |= NEED_END; + } + /* add the remainder of the lines, i.e. those that either * weren't present in the template, or in the case of no template, * all the lines following the entryStart. @@ -4051,6 +4105,14 @@ 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); @@ -4102,7 +4164,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; @@ -4160,6 +4222,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, @@ -4325,7 +4389,7 @@ grubConfig = cfi->defaultConfig; } - if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || + if (bootloaderProbe && (displayDefault || kernelInfo || newKernelPath || removeKernelPath || makeDefault || defaultKernel || displayDefaultIndex || displayDefaultTitle || (defaultIndex >= 0))) { @@ -4334,7 +4398,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")); @@ -4577,7 +4641,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) {