--- trunk/grubby/grubby.c 2014/07/16 10:56:09 2708 +++ trunk/grubby/grubby.c 2016/06/30 10:17:00 2972 @@ -582,6 +582,8 @@ { "initrd", LT_INITRD, ' ', ',' }, { "append", LT_KERNELARGS, ' ' }, { "prompt", LT_UNKNOWN, ' ' }, + { "fdt", LT_DEVTREE, ' ' }, + { "fdtdir", LT_DEVTREE, ' ' }, { NULL, 0, 0 }, }; int useextlinuxmenu; @@ -1960,11 +1962,13 @@ } indexVars[i + 1] = -1; - + i = 0; if (index) { - while (i < *index) i++; - if (indexVars[i] == -1) return NULL; + while (i < *index) { + i++; + if (indexVars[i] == -1) return NULL; + } } entry = findEntryByIndex(config, indexVars[i]); @@ -2118,8 +2122,12 @@ } else { entry = findEntryByTitle(cfg, defTitle, &index); } - if (entry) + if (entry && suitableImage(entry, prefix, skipRemoved, flags)) { cfg->defaultImage = index; + if (indexPtr) + *indexPtr = index; + return entry; + } } } } else if (cfg->defaultImage > -1) { @@ -2364,9 +2372,11 @@ } else { char * title; line = getLineByType(LT_MENUENTRY, entry->lines); - title = grub2ExtractTitle(line); - if (title) - printf("title=%s\n", title); + if (line) { + title = grub2ExtractTitle(line); + if (title) + printf("title=%s\n", title); + } } for (j = 0, line = entry->lines; line; line = line->next) { @@ -3303,17 +3313,36 @@ } int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel, - const char * image, const char * prefix, const char * initrd) { + const char * image, const char * prefix, const char * initrd, + const char * title) { struct singleEntry * entry; struct singleLine * line, * kernelLine, *endLine = NULL; int index = 0; if (!image) return 0; - for (; (entry = findEntryByPath(cfg, newMBKernel, prefix, &index)); index++) { + for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { kernelLine = getLineByType(LT_MBMODULE, entry->lines); if (!kernelLine) continue; + /* if title is supplied, the entry's title must match it. */ + if (title) { + char *linetitle; + + line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines); + if (!line) + continue; + + linetitle = extractTitle(line); + if (!linetitle) + continue; + if (strcmp(title, linetitle)) { + free(linetitle); + continue; + } + free(linetitle); + } + if (prefix) { int prefixLen = strlen(prefix); if (!strncmp(initrd, prefix, prefixLen)) @@ -3339,7 +3368,7 @@ } int updateInitrd(struct grubConfig * cfg, const char * image, - const char * prefix, const char * initrd) { + const char * prefix, const char * initrd, const char * title) { struct singleEntry * entry; struct singleLine * line, * kernelLine, *endLine = NULL; int index = 0; @@ -3350,6 +3379,24 @@ kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines); if (!kernelLine) continue; + /* if title is supplied, the entry's title must match it. */ + if (title) { + char *linetitle; + + line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines); + if (!line) + continue; + + linetitle = extractTitle(line); + if (!linetitle) + continue; + if (strcmp(title, linetitle)) { + free(linetitle); + continue; + } + free(linetitle); + } + line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines); if (line) removeLine(entry, line); @@ -4053,6 +4100,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. @@ -4111,6 +4165,7 @@ config->secondaryIndent, NULL); needs &= ~NEED_END; } + if (needs) { printf(_("grubby: needs=%d, aborting\n"), needs); abort(); @@ -4216,6 +4271,8 @@ _("display the title of the default kernel") }, { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0, _("device tree file for new stanza"), _("dtb-path") }, + { "devtreedir", 0, POPT_ARG_STRING, &newDevTreePath, 0, + _("device tree directory for new stanza"), _("dtb-path") }, { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, _("configure elilo bootloader") }, { "efi", 0, POPT_ARG_NONE, &isEfi, 0, @@ -4400,7 +4457,7 @@ if (newKernelPath && !newKernelTitle) { fprintf(stderr, _("grubby: kernel title must be specified\n")); return 1; - } else if (!newKernelPath && (newKernelTitle || copyDefault || + } else if (!newKernelPath && (copyDefault || (newKernelInitrd && !updateKernelPath)|| makeDefault || extraInitrdCount > 0)) { fprintf(stderr, _("grubby: kernel path expected\n")); @@ -4622,11 +4679,12 @@ if (updateKernelPath && newKernelInitrd) { if (newMBKernel) { if (addMBInitrd(config, newMBKernel, updateKernelPath, - bootPrefix, newKernelInitrd)) + bootPrefix, newKernelInitrd, + newKernelTitle)) return 1; } else { if (updateInitrd(config, updateKernelPath, bootPrefix, - newKernelInitrd)) + newKernelInitrd, newKernelTitle)) return 1; } }