Magellan Linux

Diff of /trunk/grubby/grubby.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2255 by niro, Mon Oct 21 14:00:38 2013 UTC revision 2991 by niro, Thu Jun 30 10:34:31 2016 UTC
# Line 60  int debug = 0; /* Currently just for tem Line 60  int debug = 0; /* Currently just for tem
60    
61  int isEfi = 0;  int isEfi = 0;
62    
63    #if defined(__aarch64__)
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 */
# Line 90  enum lineType_e { Line 96  enum lineType_e {
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 {
# Line 119  struct singleEntry { Line 128  struct singleEntry {
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
# Line 151  struct configFileInfo { Line 161  struct configFileInfo {
161      int defaultIsVariable;      int defaultIsVariable;
162      int defaultSupportSaved;      int defaultSupportSaved;
163      int defaultIsSaved;      int defaultIsSaved;
164        int defaultIsUnquoted;
165      enum lineType_e entryStart;      enum lineType_e entryStart;
166      enum lineType_e entryEnd;      enum lineType_e entryEnd;
167      int needsBootPrefix;      int needsBootPrefix;
# Line 182  const char *grubFindConfig(struct config Line 193  const char *grubFindConfig(struct config
193   "/boot/grub/grub.conf",   "/boot/grub/grub.conf",
194   "/boot/grub/menu.lst",   "/boot/grub/menu.lst",
195   "/etc/grub.conf",   "/etc/grub.conf",
196     "/boot/grub2/grub.cfg",
197     "/boot/grub2-efi/grub.cfg",
198   NULL   NULL
199      };      };
200      static int i = -1;      static int i = -1;
# Line 209  struct configFileInfo grubConfigType = { Line 222  struct configFileInfo grubConfigType = {
222      .mbHyperFirst = 1,      .mbHyperFirst = 1,
223      .mbInitRdIsModule = 1,      .mbInitRdIsModule = 1,
224      .mbAllowExtraInitRds = 1,      .mbAllowExtraInitRds = 1,
225        .titlePosition = 1,
226  };  };
227    
228  struct keywordTypes grub2Keywords[] = {  struct keywordTypes grub2Keywords[] = {
# Line 221  struct keywordTypes grub2Keywords[] = { Line 235  struct keywordTypes grub2Keywords[] = {
235      { "fallback",   LT_FALLBACK,    ' ' },      { "fallback",   LT_FALLBACK,    ' ' },
236      { "linux",      LT_KERNEL,      ' ' },      { "linux",      LT_KERNEL,      ' ' },
237      { "linuxefi",   LT_KERNEL_EFI,  ' ' },      { "linuxefi",   LT_KERNEL_EFI,  ' ' },
238        { "linux16",    LT_KERNEL_16,   ' ' },
239      { "initrd",     LT_INITRD,      ' ', ' ' },      { "initrd",     LT_INITRD,      ' ', ' ' },
240      { "initrdefi",  LT_INITRD_EFI,  ' ', ' ' },      { "initrdefi",  LT_INITRD_EFI,  ' ', ' ' },
241        { "initrd16",   LT_INITRD_16,   ' ', ' ' },
242      { "module",     LT_MBMODULE,    ' ' },      { "module",     LT_MBMODULE,    ' ' },
243      { "kernel",     LT_HYPER,       ' ' },      { "kernel",     LT_HYPER,       ' ' },
244        { "devicetree", LT_DEVTREE,  ' ' },
245      { NULL, 0, 0 },      { NULL, 0, 0 },
246  };  };
247    
# Line 273  static char *grub2GetEnv(struct configFi Line 290  static char *grub2GetEnv(struct configFi
290      static char buf[1025];      static char buf[1025];
291      char *s = NULL;      char *s = NULL;
292      char *ret = NULL;      char *ret = NULL;
293      char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";      char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv";
294      int rc = asprintf(&s, "grub2-editenv %s list | grep '^%s='", envFile, name);      int rc = asprintf(&s, "grub-editenv %s list | grep '^%s='", envFile, name);
295    
296      if (rc < 0)      if (rc < 0)
297   return NULL;   return NULL;
# Line 297  out: Line 314  out:
314      return ret;      return ret;
315  }  }
316    
317    static int sPopCount(const char *s, const char *c)
318    {
319        int ret = 0;
320        if (!s)
321     return -1;
322        for (int i = 0; s[i] != '\0'; i++)
323     for (int j = 0; c[j] != '\0'; j++)
324        if (s[i] == c[j])
325     ret++;
326        return ret;
327    }
328    
329    static char *shellEscape(const char *s)
330    {
331        int l = strlen(s) + sPopCount(s, "'") * 2;
332    
333        char *ret = calloc(l+1, sizeof (*ret));
334        if (!ret)
335     return NULL;
336        for (int i = 0, j = 0; s[i] != '\0'; i++, j++) {
337     if (s[i] == '\'')
338        ret[j++] = '\\';
339     ret[j] = s[i];
340        }
341        return ret;
342    }
343    
344    static void unquote(char *s)
345    {
346        int l = strlen(s);
347    
348        if ((s[l-1] == '\'' && s[0] == '\'') || (s[l-1] == '"' && s[0] == '"')) {
349     memmove(s, s+1, l-2);
350     s[l-2] = '\0';
351        }
352    }
353    
354  static int grub2SetEnv(struct configFileInfo *info, char *name, char *value)  static int grub2SetEnv(struct configFileInfo *info, char *name, char *value)
355  {  {
356      char *s = NULL;      char *s = NULL;
357      int rc = 0;      int rc = 0;
358      char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";      char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv";
359    
360        unquote(value);
361        value = shellEscape(value);
362        if (!value)
363        return -1;
364    
365      rc = asprintf(&s, "grub2-editenv %s set '%s=%s'", envFile, name, value);      rc = asprintf(&s, "grub-editenv %s set '%s=%s'", envFile, name, value);
366        free(value);
367      if (rc <0)      if (rc <0)
368   return -1;   return -1;
369    
# Line 353  static int isquote(char q) Line 413  static int isquote(char q)
413  }  }
414    
415  static int iskernel(enum lineType_e type) {  static int iskernel(enum lineType_e type) {
416      return (type == LT_KERNEL || type == LT_KERNEL_EFI);      return (type == LT_KERNEL || type == LT_KERNEL_EFI || type == LT_KERNEL_16);
417  }  }
418    
419  static int isinitrd(enum lineType_e type) {  static int isinitrd(enum lineType_e type) {
420      return (type == LT_INITRD || type == LT_INITRD_EFI);      return (type == LT_INITRD || type == LT_INITRD_EFI || type == LT_INITRD_16);
421  }  }
422    
423  char *grub2ExtractTitle(struct singleLine * line) {  char *grub2ExtractTitle(struct singleLine * line) {
# Line 392  char *grub2ExtractTitle(struct singleLin Line 452  char *grub2ExtractTitle(struct singleLin
452       * whose last character is also quote (assuming it's the closing one) */       * whose last character is also quote (assuming it's the closing one) */
453      int resultMaxSize;      int resultMaxSize;
454      char * result;      char * result;
455        /* need to ensure that ' does not match " as we search */
456        char quote_char = *current;
457            
458      resultMaxSize = sizeOfSingleLine(line);      resultMaxSize = sizeOfSingleLine(line);
459      result = malloc(resultMaxSize);      result = malloc(resultMaxSize);
# Line 405  char *grub2ExtractTitle(struct singleLin Line 467  char *grub2ExtractTitle(struct singleLin
467   current_indent_len = strlen(current_indent);   current_indent_len = strlen(current_indent);
468    
469   strncat(result, current_indent, current_indent_len);   strncat(result, current_indent, current_indent_len);
470   if (!isquote(current[current_len-1])) {   if (current[current_len-1] != quote_char) {
471      strncat(result, current, current_len);      strncat(result, current, current_len);
472   } else {   } else {
473      strncat(result, current, current_len - 1);      strncat(result, current, current_len - 1);
# Line 523  struct keywordTypes extlinuxKeywords[] = Line 585  struct keywordTypes extlinuxKeywords[] =
585      { "initrd",    LT_INITRD,      ' ', ',' },      { "initrd",    LT_INITRD,      ' ', ',' },
586      { "append",    LT_KERNELARGS,  ' ' },      { "append",    LT_KERNELARGS,  ' ' },
587      { "prompt",     LT_UNKNOWN,     ' ' },      { "prompt",     LT_UNKNOWN,     ' ' },
588        { "fdt",        LT_DEVTREE,     ' ' },
589        { "fdtdir",     LT_DEVTREE,     ' ' },
590      { NULL,    0, 0 },      { NULL,    0, 0 },
591  };  };
592  int useextlinuxmenu;  int useextlinuxmenu;
# Line 533  struct configFileInfo eliloConfigType = Line 597  struct configFileInfo eliloConfigType =
597      .needsBootPrefix = 1,      .needsBootPrefix = 1,
598      .argsInQuotes = 1,      .argsInQuotes = 1,
599      .mbConcatArgs = 1,      .mbConcatArgs = 1,
600        .titlePosition = 1,
601  };  };
602    
603  struct configFileInfo liloConfigType = {  struct configFileInfo liloConfigType = {
# Line 541  struct configFileInfo liloConfigType = { Line 606  struct configFileInfo liloConfigType = {
606      .entryStart = LT_KERNEL,      .entryStart = LT_KERNEL,
607      .argsInQuotes = 1,      .argsInQuotes = 1,
608      .maxTitleLength = 15,      .maxTitleLength = 15,
609        .titlePosition = 1,
610  };  };
611    
612  struct configFileInfo yabootConfigType = {  struct configFileInfo yabootConfigType = {
# Line 551  struct configFileInfo yabootConfigType = Line 617  struct configFileInfo yabootConfigType =
617      .argsInQuotes = 1,      .argsInQuotes = 1,
618      .maxTitleLength = 15,      .maxTitleLength = 15,
619      .mbAllowExtraInitRds = 1,      .mbAllowExtraInitRds = 1,
620        .titlePosition = 1,
621  };  };
622    
623  struct configFileInfo siloConfigType = {  struct configFileInfo siloConfigType = {
# Line 560  struct configFileInfo siloConfigType = { Line 627  struct configFileInfo siloConfigType = {
627      .needsBootPrefix = 1,      .needsBootPrefix = 1,
628      .argsInQuotes = 1,      .argsInQuotes = 1,
629      .maxTitleLength = 15,      .maxTitleLength = 15,
630        .titlePosition = 1,
631  };  };
632    
633  struct configFileInfo ziplConfigType = {  struct configFileInfo ziplConfigType = {
# Line 578  struct configFileInfo extlinuxConfigType Line 646  struct configFileInfo extlinuxConfigType
646      .needsBootPrefix = 1,      .needsBootPrefix = 1,
647      .maxTitleLength = 255,      .maxTitleLength = 255,
648      .mbAllowExtraInitRds = 1,      .mbAllowExtraInitRds = 1,
649        .defaultIsUnquoted = 1,
650        .titlePosition = 1,
651  };  };
652    
653  struct grubConfig {  struct grubConfig {
# Line 669  static enum lineType_e preferredLineType Line 739  static enum lineType_e preferredLineType
739      if (isEfi && cfi == &grub2ConfigType) {      if (isEfi && cfi == &grub2ConfigType) {
740   switch (type) {   switch (type) {
741   case LT_KERNEL:   case LT_KERNEL:
742      return LT_KERNEL_EFI;      return isEfiOnly ? LT_KERNEL : LT_KERNEL_EFI;
743   case LT_INITRD:   case LT_INITRD:
744      return LT_INITRD_EFI;      return isEfiOnly ? LT_INITRD : LT_INITRD_EFI;
745   default:   default:
746      return type;      return type;
747   }   }
748    #if defined(__i386__) || defined(__x86_64__)
749        } else if (cfi == &grub2ConfigType) {
750     switch (type) {
751     case LT_KERNEL:
752        return LT_KERNEL_16;
753     case LT_INITRD:
754        return LT_INITRD_16;
755     default:
756        return type;
757     }
758    #endif
759      }      }
760      return type;      return type;
761  }  }
# Line 755  static int isEntryStart(struct singleLin Line 836  static int isEntryStart(struct singleLin
836  }  }
837    
838  /* extract the title from within brackets (for zipl) */  /* extract the title from within brackets (for zipl) */
839  static char * extractTitle(struct singleLine * line) {  static char * extractTitle(struct grubConfig *cfg, struct singleLine * line) {
840      /* bracketed title... let's extract it (leaks a byte) */      /* bracketed title... let's extract it */
841      char * title = NULL;      char * title = NULL;
842      if (line->type == LT_TITLE) {      if (line->type == LT_TITLE) {
843   title = strdup(line->elements[0].item);   char *tmp = line->elements[cfg->cfi->titlePosition].item;
844   title++;   if (cfg->cfi->titleBracketed) {
845   *(title + strlen(title) - 1) = '\0';      tmp++;
846        title = strdup(tmp);
847        *(title + strlen(title) - 1) = '\0';
848     } else {
849        title = strdup(tmp);
850     }
851      } else if (line->type == LT_MENUENTRY)      } else if (line->type == LT_MENUENTRY)
852   title = strdup(line->elements[1].item);   title = strdup(line->elements[1].item);
853      else      else
# Line 845  static int lineWrite(FILE * out, struct Line 931  static int lineWrite(FILE * out, struct
931   /* Need to handle this, because we strip the quotes from   /* Need to handle this, because we strip the quotes from
932   * menuentry when read it. */   * menuentry when read it. */
933   if (line->type == LT_MENUENTRY && i == 1) {   if (line->type == LT_MENUENTRY && i == 1) {
934      if(!isquote(*line->elements[i].item))      if(!isquote(*line->elements[i].item)) {
935   fprintf(out, "\'%s\'", line->elements[i].item);   int substring = 0;
936      else   /* If the line contains nested quotes, we did not strip
937     * the "interna" quotes and we must use the right quotes
938     * again when writing the updated file. */
939     for (int j = i; j < line->numElements; j++) {
940        if (strchr(line->elements[i].item, '\'') != NULL) {
941           substring = 1;
942           fprintf(out, "\"%s\"", line->elements[i].item);
943           break;
944        }
945     }
946     if (!substring)
947        fprintf(out, "\'%s\'", line->elements[i].item);
948        } else {
949   fprintf(out, "%s", line->elements[i].item);   fprintf(out, "%s", line->elements[i].item);
950        }
951      fprintf(out, "%s", line->elements[i].indent);      fprintf(out, "%s", line->elements[i].indent);
952    
953      continue;      continue;
# Line 1023  static int getNextLine(char ** bufPtr, s Line 1122  static int getNextLine(char ** bufPtr, s
1122      return 0;      return 0;
1123  }  }
1124    
1125    static int isnumber(const char *s)
1126    {
1127        int i;
1128        for (i = 0; s[i] != '\0'; i++)
1129     if (s[i] < '0' || s[i] > '9')
1130        return 0;
1131        return i;
1132    }
1133    
1134  static struct grubConfig * readConfig(const char * inName,  static struct grubConfig * readConfig(const char * inName,
1135        struct configFileInfo * cfi) {        struct configFileInfo * cfi) {
1136      int in;      int in;
# Line 1113  static struct grubConfig * readConfig(co Line 1221  static struct grubConfig * readConfig(co
1221   cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT;   cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT;
1222   defaultLine = line;   defaultLine = line;
1223      }      }
  } else if (line->type == LT_DEFAULT && line->numElements == 2) {  
     cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT;  
     defaultLine = line;  
1224    
1225          } else if (iskernel(line->type)) {          } else if (iskernel(line->type)) {
1226      /* if by some freak chance this is multiboot and the "module"      /* if by some freak chance this is multiboot and the "module"
1227       * lines came earlier in the template, make sure to use LT_HYPER       * lines came earlier in the template, make sure to use LT_HYPER
1228       * instead of LT_KERNEL now       * instead of LT_KERNEL now
1229       */       */
1230      if (entry->multiboot)      if (entry && entry->multiboot)
1231   line->type = LT_HYPER;   line->type = LT_HYPER;
1232    
1233          } else if (line->type == LT_MBMODULE) {          } else if (line->type == LT_MBMODULE) {
# Line 1148  static struct grubConfig * readConfig(co Line 1253  static struct grubConfig * readConfig(co
1253      cfg->fallbackImage = strtol(line->elements[1].item, &end, 10);      cfg->fallbackImage = strtol(line->elements[1].item, &end, 10);
1254      if (*end) cfg->fallbackImage = -1;      if (*end) cfg->fallbackImage = -1;
1255    
1256   } else if (line->type == LT_TITLE && line->numElements > 1) {   } else if ((line->type == LT_DEFAULT && cfi->defaultIsUnquoted) ||
1257      /* make the title a single argument (undoing our parsing) */                  (line->type == LT_TITLE && line->numElements > 1)) {
1258        /* make the title/default a single argument (undoing our parsing) */
1259      len = 0;      len = 0;
1260      for (int i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
1261   len += strlen(line->elements[i].item);   len += strlen(line->elements[i].item);
# Line 1177  static struct grubConfig * readConfig(co Line 1283  static struct grubConfig * readConfig(co
1283      len = 0;      len = 0;
1284      char *extras;      char *extras;
1285      char *title;      char *title;
1286        /* initially unseen value */
1287        char quote_char = '\0';
1288    
1289      for (int i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
1290   len += strlen(line->elements[i].item);   len += strlen(line->elements[i].item);
# Line 1193  static struct grubConfig * readConfig(co Line 1301  static struct grubConfig * readConfig(co
1301      for (int i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1302   if (!strcmp(line->elements[i].item, "menuentry"))   if (!strcmp(line->elements[i].item, "menuentry"))
1303      continue;      continue;
1304   if (isquote(*line->elements[i].item))   if (isquote(*line->elements[i].item) && quote_char == '\0') {
1305        /* ensure we properly pair off quotes */
1306        quote_char = *line->elements[i].item;
1307      title = line->elements[i].item + 1;      title = line->elements[i].item + 1;
1308   else   } else {
1309      title = line->elements[i].item;      title = line->elements[i].item;
1310     }
1311    
1312   len = strlen(title);   len = strlen(title);
1313          if (isquote(title[len-1])) {          if (title[len-1] == quote_char) {
1314      strncat(buf, title,len-1);      strncat(buf, title,len-1);
1315      break;      break;
1316   } else {   } else {
# Line 1210  static struct grubConfig * readConfig(co Line 1321  static struct grubConfig * readConfig(co
1321    
1322      /* get extras */      /* get extras */
1323      int count = 0;      int count = 0;
1324        quote_char = '\0';
1325      for (int i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1326   if (count >= 2) {   if (count >= 2) {
1327      strcat(extras, line->elements[i].item);      strcat(extras, line->elements[i].item);
# Line 1220  static struct grubConfig * readConfig(co Line 1332  static struct grubConfig * readConfig(co
1332      continue;      continue;
1333    
1334   /* count ' or ", there should be two in menuentry line. */   /* count ' or ", there should be two in menuentry line. */
1335   if (isquote(*line->elements[i].item))   if (isquote(*line->elements[i].item) && quote_char == '\0') {
1336        /* ensure we properly pair off quotes */
1337                quote_char = *line->elements[i].item;
1338      count++;      count++;
1339     }
1340    
1341   len = strlen(line->elements[i].item);   len = strlen(line->elements[i].item);
1342    
1343   if (isquote(line->elements[i].item[len -1]))   if (line->elements[i].item[len -1] == quote_char)
1344      count++;      count++;
1345    
1346   /* ok, we get the final ' or ", others are extras. */   /* ok, we get the final ' or ", others are extras. */
# Line 1256  static struct grubConfig * readConfig(co Line 1371  static struct grubConfig * readConfig(co
1371      }      }
1372   }   }
1373    
1374     if (line->type == LT_DEFAULT && line->numElements == 2) {
1375        cfg->flags &= ~GRUB_CONFIG_NO_DEFAULT;
1376        defaultLine = line;
1377     }
1378    
1379   /* If we find a generic config option which should live at the   /* If we find a generic config option which should live at the
1380     top of the file, move it there. Old versions of grubby were     top of the file, move it there. Old versions of grubby were
1381     probably responsible for putting new images in the wrong     probably responsible for putting new images in the wrong
# Line 1319  static struct grubConfig * readConfig(co Line 1439  static struct grubConfig * readConfig(co
1439      char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry");      char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry");
1440      if (defTitle) {      if (defTitle) {
1441   int index = 0;   int index = 0;
1442   entry = findEntryByTitle(cfg, defTitle, &index);   if (isnumber(defTitle)) {
1443        index = atoi(defTitle);
1444        entry = findEntryByIndex(cfg, index);
1445     } else {
1446        entry = findEntryByTitle(cfg, defTitle, &index);
1447     }
1448   if (entry)   if (entry)
1449      cfg->defaultImage = index;      cfg->defaultImage = index;
1450      }      }
# Line 1352  static struct grubConfig * readConfig(co Line 1477  static struct grubConfig * readConfig(co
1477                                  line->elements[1].item)) break;                                  line->elements[1].item)) break;
1478                  } else if (line) {                  } else if (line) {
1479                      if (!strcmp(defaultLine->elements[1].item,                      if (!strcmp(defaultLine->elements[1].item,
1480                                  extractTitle(line))) break;                                  extractTitle(cfg, line))) break;
1481                  }                  }
1482   i++;   i++;
1483   entry = NULL;   entry = NULL;
# Line 1368  static struct grubConfig * readConfig(co Line 1493  static struct grubConfig * readConfig(co
1493   char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry");   char *defTitle = cfi->getEnv(cfg->cfi, "saved_entry");
1494   if (defTitle) {   if (defTitle) {
1495      int index = 0;      int index = 0;
1496      entry = findEntryByTitle(cfg, defTitle, &index);      if (isnumber(defTitle)) {
1497     index = atoi(defTitle);
1498     entry = findEntryByIndex(cfg, index);
1499        } else {
1500     entry = findEntryByTitle(cfg, defTitle, &index);
1501        }
1502      if (entry)      if (entry)
1503   cfg->defaultImage = index;   cfg->defaultImage = index;
1504   }   }
# Line 1398  static void writeDefault(FILE * out, cha Line 1528  static void writeDefault(FILE * out, cha
1528      if (!line)      if (!line)
1529   line = getLineByType(LT_TITLE, entry->lines);   line = getLineByType(LT_TITLE, entry->lines);
1530      if (line) {      if (line) {
1531   title = extractTitle(line);   title = extractTitle(cfg, line);
1532   if (title)   if (title)
1533      cfg->cfi->setEnv(cfg->cfi, "saved_entry", title);      cfg->cfi->setEnv(cfg->cfi, "saved_entry", title);
1534      }      }
# Line 1436  static void writeDefault(FILE * out, cha Line 1566  static void writeDefault(FILE * out, cha
1566              else if (line && (line->numElements == 1) &&              else if (line && (line->numElements == 1) &&
1567                       cfg->cfi->titleBracketed) {                       cfg->cfi->titleBracketed) {
1568   fprintf(out, "%sdefault%s%s\n", indent, separator,   fprintf(out, "%sdefault%s%s\n", indent, separator,
1569                          extractTitle(line));                          extractTitle(cfg, line));
1570              }              }
1571   }   }
1572      }      }
# Line 1743  int suitableImage(struct singleEntry * e Line 1873  int suitableImage(struct singleEntry * e
1873   return 0;   return 0;
1874      }      }
1875    
1876      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);
1877      if (!line) {      if (!line) {
1878   notSuitablePrintf(entry, 0, "no line found\n");   notSuitablePrintf(entry, 0, "no line found\n");
1879   return 0;   return 0;
# Line 1867  struct singleEntry * findEntryByPath(str Line 1997  struct singleEntry * findEntryByPath(str
1997   }   }
1998    
1999   indexVars[i + 1] = -1;   indexVars[i + 1] = -1;
2000    
2001   i = 0;   i = 0;
2002   if (index) {   if (index) {
2003      while (i < *index) i++;      while (i < *index) {
2004      if (indexVars[i] == -1) return NULL;   i++;
2005     if (indexVars[i] == -1) return NULL;
2006        }
2007   }   }
2008    
2009   entry = findEntryByIndex(config, indexVars[i]);   entry = findEntryByIndex(config, indexVars[i]);
2010   if (!entry) return NULL;   if (!entry) return NULL;
2011    
2012   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);
2013   if (!line) return NULL;   if (!line) return NULL;
2014    
2015   if (index) *index = indexVars[i];   if (index) *index = indexVars[i];
# Line 1928  struct singleEntry * findEntryByPath(str Line 2060  struct singleEntry * findEntryByPath(str
2060      for (line = entry->lines; line; line = line->next) {      for (line = entry->lines; line; line = line->next) {
2061   enum lineType_e ct = checkType;   enum lineType_e ct = checkType;
2062   if (entry->multiboot && checkType == LT_KERNEL)   if (entry->multiboot && checkType == LT_KERNEL)
2063      ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER;      ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER|LT_KERNEL_16;
2064   else if (checkType & LT_KERNEL)   else if (checkType & LT_KERNEL)
2065      ct = checkType | LT_KERNEL_EFI;      ct = checkType | LT_KERNEL_EFI | LT_KERNEL_16;
2066   line = getLineByType(ct, line);   line = getLineByType(ct, line);
2067   if (!line)   if (!line)
2068      break;  /* not found in this entry */      break;  /* not found in this entry */
# Line 1952  struct singleEntry * findEntryByPath(str Line 2084  struct singleEntry * findEntryByPath(str
2084       * non-Linux boot entries (could find netbsd etc, though, which is       * non-Linux boot entries (could find netbsd etc, though, which is
2085       * unfortunate)       * unfortunate)
2086       */       */
2087      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))
2088   break; /* found 'im! */   break; /* found 'im! */
2089   }   }
2090    
# Line 2019  struct singleEntry * findTemplate(struct Line 2151  struct singleEntry * findTemplate(struct
2151      char *defTitle = cfg->cfi->getEnv(cfg->cfi, "saved_entry");      char *defTitle = cfg->cfi->getEnv(cfg->cfi, "saved_entry");
2152      if (defTitle) {      if (defTitle) {
2153   int index = 0;   int index = 0;
2154   entry = findEntryByTitle(cfg, defTitle, &index);   if (isnumber(defTitle)) {
2155        index = atoi(defTitle);
2156        entry = findEntryByIndex(cfg, index);
2157     } else {
2158        entry = findEntryByTitle(cfg, defTitle, &index);
2159     }
2160     if (entry && suitableImage(entry, prefix, skipRemoved, flags)) {
2161        cfg->defaultImage = index;
2162        if (indexPtr)
2163     *indexPtr = index;
2164        return entry;
2165     }
2166      }      }
2167   }   }
2168      } else if (cfg->defaultImage > -1) {      } else if (cfg->defaultImage > -1) {
# Line 2176  void displayEntry(struct singleEntry * e Line 2319  void displayEntry(struct singleEntry * e
2319      struct singleLine * line;      struct singleLine * line;
2320      char * root = NULL;      char * root = NULL;
2321      int i;      int i;
2322        int j;
2323    
2324      printf("index=%d\n", index);      printf("index=%d\n", index);
2325    
2326      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);
2327      if (!line) {      if (!line) {
2328          printf("non linux entry\n");          printf("non linux entry\n");
2329          return;          return;
# Line 2244  void displayEntry(struct singleEntry * e Line 2388  void displayEntry(struct singleEntry * e
2388   printf("root=%s\n", s);   printf("root=%s\n", s);
2389      }      }
2390    
2391      line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines);      line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);
2392    
2393      if (line && line->numElements >= 2) {      if (line && line->numElements >= 2) {
2394   if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))   if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))
# Line 2263  void displayEntry(struct singleEntry * e Line 2407  void displayEntry(struct singleEntry * e
2407      } else {      } else {
2408   char * title;   char * title;
2409   line = getLineByType(LT_MENUENTRY, entry->lines);   line = getLineByType(LT_MENUENTRY, entry->lines);
2410   title = grub2ExtractTitle(line);   if (line) {
2411   if (title)      title = grub2ExtractTitle(line);
2412      printf("title=%s\n", title);      if (title)
2413     printf("title=%s\n", title);
2414     }
2415        }
2416    
2417        for (j = 0, line = entry->lines; line; line = line->next) {
2418     if ((line->type & LT_MBMODULE) && line->numElements >= 2) {
2419        if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))
2420     printf("mbmodule%d=", j);
2421        else
2422     printf("mbmodule%d=%s", j, prefix);
2423    
2424        for (i = 1; i < line->numElements; i++)
2425     printf("%s%s", line->elements[i].item, line->elements[i].indent);
2426        printf("\n");
2427        j++;
2428     }
2429      }      }
2430  }  }
2431    
# Line 2661  struct singleLine * addLineTmpl(struct s Line 2821  struct singleLine * addLineTmpl(struct s
2821   insertElement(newLine, val, 1, cfi);   insertElement(newLine, val, 1, cfi);
2822    
2823   /* but try to keep the rootspec from the template... sigh */   /* but try to keep the rootspec from the template... sigh */
2824   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)) {
2825      char * rootspec = getRootSpecifier(tmplLine->elements[1].item);      char * rootspec = getRootSpecifier(tmplLine->elements[1].item);
2826      if (rootspec != NULL) {      if (rootspec != NULL) {
2827   free(newLine->elements[1].item);   free(newLine->elements[1].item);
# Line 3031  int updateActualImage(struct grubConfig Line 3191  int updateActualImage(struct grubConfig
3191      firstElement = 2;      firstElement = 2;
3192    
3193   } else {   } else {
3194      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);
3195      if (!line) {      if (!line) {
3196   /* no LT_KERNEL or LT_MBMODULE in this entry? */   /* no LT_KERNEL or LT_MBMODULE in this entry? */
3197   continue;   continue;
# Line 3187  int updateImage(struct grubConfig * cfg, Line 3347  int updateImage(struct grubConfig * cfg,
3347      return rc;      return rc;
3348  }  }
3349    
3350    int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel,
3351     const char * image, const char * prefix, const char * initrd,
3352     const char * title) {
3353        struct singleEntry * entry;
3354        struct singleLine * line, * kernelLine, *endLine = NULL;
3355        int index = 0;
3356    
3357        if (!image) return 0;
3358    
3359        for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {
3360            kernelLine = getLineByType(LT_MBMODULE, entry->lines);
3361            if (!kernelLine) continue;
3362    
3363     /* if title is supplied, the entry's title must match it. */
3364     if (title) {
3365        char *linetitle;
3366    
3367        line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines);
3368        if (!line)
3369     continue;
3370    
3371        linetitle = extractTitle(cfg, line);
3372        if (!linetitle)
3373     continue;
3374        if (strcmp(title, linetitle)) {
3375     free(linetitle);
3376     continue;
3377        }
3378        free(linetitle);
3379     }
3380    
3381            if (prefix) {
3382                int prefixLen = strlen(prefix);
3383                if (!strncmp(initrd, prefix, prefixLen))
3384                    initrd += prefixLen;
3385            }
3386     endLine = getLineByType(LT_ENTRY_END, entry->lines);
3387     if (endLine)
3388        removeLine(entry, endLine);
3389            line = addLine(entry, cfg->cfi, preferredLineType(LT_MBMODULE,cfg->cfi),
3390     kernelLine->indent, initrd);
3391            if (!line)
3392        return 1;
3393     if (endLine) {
3394        line = addLine(entry, cfg->cfi, LT_ENTRY_END, "", NULL);
3395                if (!line)
3396     return 1;
3397     }
3398    
3399            break;
3400        }
3401    
3402        return 0;
3403    }
3404    
3405  int updateInitrd(struct grubConfig * cfg, const char * image,  int updateInitrd(struct grubConfig * cfg, const char * image,
3406                   const char * prefix, const char * initrd) {                   const char * prefix, const char * initrd, const char * title) {
3407      struct singleEntry * entry;      struct singleEntry * entry;
3408      struct singleLine * line, * kernelLine, *endLine = NULL;      struct singleLine * line, * kernelLine, *endLine = NULL;
3409      int index = 0;      int index = 0;
# Line 3196  int updateInitrd(struct grubConfig * cfg Line 3411  int updateInitrd(struct grubConfig * cfg
3411      if (!image) return 0;      if (!image) return 0;
3412    
3413      for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {      for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {
3414          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI, entry->lines);          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines);
3415          if (!kernelLine) continue;          if (!kernelLine) continue;
3416    
3417          line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines);   /* if title is supplied, the entry's title must match it. */
3418     if (title) {
3419        char *linetitle;
3420    
3421        line = getLineByType(LT_TITLE|LT_MENUENTRY, entry->lines);
3422        if (!line)
3423     continue;
3424    
3425        linetitle = extractTitle(cfg, line);
3426        if (!linetitle)
3427     continue;
3428        if (strcmp(title, linetitle)) {
3429     free(linetitle);
3430     continue;
3431        }
3432        free(linetitle);
3433     }
3434    
3435            line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);
3436          if (line)          if (line)
3437              removeLine(entry, line);              removeLine(entry, line);
3438          if (prefix) {          if (prefix) {
# Line 3210  int updateInitrd(struct grubConfig * cfg Line 3443  int updateInitrd(struct grubConfig * cfg
3443   endLine = getLineByType(LT_ENTRY_END, entry->lines);   endLine = getLineByType(LT_ENTRY_END, entry->lines);
3444   if (endLine)   if (endLine)
3445      removeLine(entry, endLine);      removeLine(entry, endLine);
3446          line = addLine(entry, cfg->cfi, preferredLineType(LT_INITRD, cfg->cfi),   enum lineType_e lt;
3447   kernelLine->indent, initrd);   switch(kernelLine->type) {
3448        case LT_KERNEL:
3449            lt = LT_INITRD;
3450     break;
3451        case LT_KERNEL_EFI:
3452            lt = LT_INITRD_EFI;
3453     break;
3454        case LT_KERNEL_16:
3455            lt = LT_INITRD_16;
3456     break;
3457        default:
3458            lt = preferredLineType(LT_INITRD, cfg->cfi);
3459     }
3460            line = addLine(entry, cfg->cfi, lt, kernelLine->indent, initrd);
3461          if (!line)          if (!line)
3462      return 1;      return 1;
3463   if (endLine) {   if (endLine) {
# Line 3570  int addNewKernel(struct grubConfig * con Line 3816  int addNewKernel(struct grubConfig * con
3816   const char * newKernelPath, const char * newKernelTitle,   const char * newKernelPath, const char * newKernelTitle,
3817   const char * newKernelArgs, const char * newKernelInitrd,   const char * newKernelArgs, const char * newKernelInitrd,
3818   const char ** extraInitrds, int extraInitrdCount,   const char ** extraInitrds, int extraInitrdCount,
3819                   const char * newMBKernel, const char * newMBKernelArgs) {                   const char * newMBKernel, const char * newMBKernelArgs,
3820     const char * newDevTreePath) {
3821      struct singleEntry * new;      struct singleEntry * new;
3822      struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL;      struct singleLine * newLine = NULL, * tmplLine = NULL, * masterLine = NULL;
3823      int needs;      int needs;
# Line 3611  int addNewKernel(struct grubConfig * con Line 3858  int addNewKernel(struct grubConfig * con
3858          needs |= NEED_MB;          needs |= NEED_MB;
3859          new->multiboot = 1;          new->multiboot = 1;
3860      }      }
3861        if (newDevTreePath && getKeywordByType(LT_DEVTREE, config->cfi))
3862     needs |= NEED_DEVTREE;
3863    
3864      if (template) {      if (template) {
3865   for (masterLine = template->lines;   for (masterLine = template->lines;
# Line 3796  int addNewKernel(struct grubConfig * con Line 4045  int addNewKernel(struct grubConfig * con
4045   newLine = addLineTmpl(new, tmplLine, newLine, NULL,   newLine = addLineTmpl(new, tmplLine, newLine, NULL,
4046   config->cfi);   config->cfi);
4047      }      }
4048        } else if (tmplLine->type == LT_DEVTREE &&
4049           tmplLine->numElements == 2 && newDevTreePath) {
4050            newLine = addLineTmpl(new, tmplLine, newLine,
4051          newDevTreePath + strlen(prefix),
4052          config->cfi);
4053     needs &= ~NEED_DEVTREE;
4054        } else if (tmplLine->type == LT_ENTRY_END && needs & NEED_DEVTREE) {
4055     const char *ndtp = newDevTreePath;
4056     if (!strncmp(newDevTreePath, prefix, strlen(prefix)))
4057        ndtp += strlen(prefix);
4058     newLine = addLine(new, config->cfi, LT_DEVTREE,
4059      config->secondaryIndent,
4060      ndtp);
4061     needs &= ~NEED_DEVTREE;
4062     newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi);
4063      } else {      } else {
4064   /* pass through other lines from the template */   /* pass through other lines from the template */
4065   newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi);   newLine = addLineTmpl(new, tmplLine, newLine, NULL, config->cfi);
# Line 3809  int addNewKernel(struct grubConfig * con Line 4073  int addNewKernel(struct grubConfig * con
4073   switch (config->cfi->entryStart) {   switch (config->cfi->entryStart) {
4074      case LT_KERNEL:      case LT_KERNEL:
4075      case LT_KERNEL_EFI:      case LT_KERNEL_EFI:
4076        case LT_KERNEL_16:
4077   if (new->multiboot && config->cfi->mbHyperFirst) {   if (new->multiboot && config->cfi->mbHyperFirst) {
4078      /* fall through to LT_HYPER */      /* fall through to LT_HYPER */
4079   } else {   } else {
# Line 3870  int addNewKernel(struct grubConfig * con Line 4135  int addNewKernel(struct grubConfig * con
4135   }   }
4136      }      }
4137    
4138        struct singleLine *endLine = NULL;
4139        endLine = getLineByType(LT_ENTRY_END, new->lines);
4140        if (endLine) {
4141        removeLine(new, endLine);
4142        needs |= NEED_END;
4143        }
4144    
4145      /* add the remainder of the lines, i.e. those that either      /* add the remainder of the lines, i.e. those that either
4146       * weren't present in the template, or in the case of no template,       * weren't present in the template, or in the case of no template,
4147       * all the lines following the entryStart.       * all the lines following the entryStart.
# Line 3915  int addNewKernel(struct grubConfig * con Line 4187  int addNewKernel(struct grubConfig * con
4187   free(initrdVal);   free(initrdVal);
4188   needs &= ~NEED_INITRD;   needs &= ~NEED_INITRD;
4189      }      }
4190        if (needs & NEED_DEVTREE) {
4191     newLine = addLine(new, config->cfi, LT_DEVTREE,
4192      config->secondaryIndent,
4193      newDevTreePath);
4194     needs &= ~NEED_DEVTREE;
4195        }
4196    
4197        /* NEEDS_END must be last on bootloaders that need it... */
4198      if (needs & NEED_END) {      if (needs & NEED_END) {
4199   newLine = addLine(new, config->cfi, LT_ENTRY_END,   newLine = addLine(new, config->cfi, LT_ENTRY_END,
4200   config->secondaryIndent, NULL);   config->secondaryIndent, NULL);
# Line 3932  int addNewKernel(struct grubConfig * con Line 4212  int addNewKernel(struct grubConfig * con
4212      return 0;      return 0;
4213  }  }
4214    
 static void traceback(int signum)  
 {  
     void *array[40];  
     size_t size;  
   
     signal(SIGSEGV, SIG_DFL);  
     memset(array, '\0', sizeof (array));  
     size = backtrace(array, 40);  
   
     fprintf(stderr, "grubby received SIGSEGV!  Backtrace (%ld):\n",  
             (unsigned long)size);  
     backtrace_symbols_fd(array, size, STDERR_FILENO);  
     exit(1);  
 }  
   
4215  int main(int argc, const char ** argv) {  int main(int argc, const char ** argv) {
4216      poptContext optCon;      poptContext optCon;
4217      const char * grubConfig = NULL;      const char * grubConfig = NULL;
# Line 3966  int main(int argc, const char ** argv) { Line 4231  int main(int argc, const char ** argv) {
4231      char * newKernelArgs = NULL;      char * newKernelArgs = NULL;
4232      char * newKernelInitrd = NULL;      char * newKernelInitrd = NULL;
4233      char * newKernelTitle = NULL;      char * newKernelTitle = NULL;
4234      char * newKernelVersion = NULL;      char * newDevTreePath = NULL;
4235      char * newMBKernel = NULL;      char * newMBKernel = NULL;
4236      char * newMBKernelArgs = NULL;      char * newMBKernelArgs = NULL;
4237      char * removeMBKernelArgs = NULL;      char * removeMBKernelArgs = NULL;
# Line 4024  int main(int argc, const char ** argv) { Line 4289  int main(int argc, const char ** argv) {
4289      _("display the index of the default kernel") },      _("display the index of the default kernel") },
4290   { "default-title", 0, 0, &displayDefaultTitle, 0,   { "default-title", 0, 0, &displayDefaultTitle, 0,
4291      _("display the title of the default kernel") },      _("display the title of the default kernel") },
4292     { "devtree", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4293        _("device tree file for new stanza"), _("dtb-path") },
4294     { "devtreedir", 0, POPT_ARG_STRING, &newDevTreePath, 0,
4295        _("device tree directory for new stanza"), _("dtb-path") },
4296   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
4297      _("configure elilo bootloader") },      _("configure elilo bootloader") },
4298   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,   { "efi", 0, POPT_ARG_NONE, &isEfi, 0,
# Line 4085  int main(int argc, const char ** argv) { Line 4354  int main(int argc, const char ** argv) {
4354    
4355      useextlinuxmenu=0;      useextlinuxmenu=0;
4356    
     signal(SIGSEGV, traceback);  
   
4357      int i = 0;      int i = 0;
4358      for (int j = 1; j < argc; j++)      for (int j = 1; j < argc; j++)
4359   i += strlen(argv[j]) + 1;   i += strlen(argv[j]) + 1;
# Line 4164  int main(int argc, const char ** argv) { Line 4431  int main(int argc, const char ** argv) {
4431      }      }
4432    
4433      if (!cfi) {      if (!cfi) {
4434          if (grub2FindConfig(&grub2ConfigType))          if (grub2FindConfig(&grub2ConfigType)) {
4435      cfi = &grub2ConfigType;      cfi = &grub2ConfigType;
4436   else      if (envPath)
4437     cfi->envFile = envPath;
4438            } else
4439        #ifdef __ia64__        #ifdef __ia64__
4440      cfi = &eliloConfigType;      cfi = &eliloConfigType;
4441        #elif __powerpc__        #elif __powerpc__
# Line 4189  int main(int argc, const char ** argv) { Line 4458  int main(int argc, const char ** argv) {
4458      grubConfig = cfi->defaultConfig;      grubConfig = cfi->defaultConfig;
4459      }      }
4460    
4461      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||      if (bootloaderProbe && (displayDefault || kernelInfo ||
4462      newKernelPath || removeKernelPath || makeDefault ||      newKernelPath || removeKernelPath || makeDefault ||
4463      defaultKernel || displayDefaultIndex || displayDefaultTitle ||      defaultKernel || displayDefaultIndex || displayDefaultTitle ||
4464      (defaultIndex >= 0))) {      (defaultIndex >= 0))) {
# Line 4198  int main(int argc, const char ** argv) { Line 4467  int main(int argc, const char ** argv) {
4467   return 1;   return 1;
4468      }      }
4469    
4470      if ((displayDefault || kernelInfo) && (newKernelVersion || newKernelPath ||      if ((displayDefault || kernelInfo) && (newKernelPath ||
4471     removeKernelPath)) {     removeKernelPath)) {
4472   fprintf(stderr, _("grubby: --default-kernel and --info may not "   fprintf(stderr, _("grubby: --default-kernel and --info may not "
4473    "be used when adding or removing kernels\n"));    "be used when adding or removing kernels\n"));
# Line 4208  int main(int argc, const char ** argv) { Line 4477  int main(int argc, const char ** argv) {
4477      if (newKernelPath && !newKernelTitle) {      if (newKernelPath && !newKernelTitle) {
4478   fprintf(stderr, _("grubby: kernel title must be specified\n"));   fprintf(stderr, _("grubby: kernel title must be specified\n"));
4479   return 1;   return 1;
4480      } else if (!newKernelPath && (newKernelTitle  || copyDefault ||      } else if (!newKernelPath && (copyDefault ||
4481    (newKernelInitrd && !updateKernelPath)||    (newKernelInitrd && !updateKernelPath)||
4482    makeDefault || extraInitrdCount > 0)) {    makeDefault || extraInitrdCount > 0)) {
4483   fprintf(stderr, _("grubby: kernel path expected\n"));   fprintf(stderr, _("grubby: kernel path expected\n"));
# Line 4367  int main(int argc, const char ** argv) { Line 4636  int main(int argc, const char ** argv) {
4636   if (!entry) return 0;   if (!entry) return 0;
4637   if (!suitableImage(entry, bootPrefix, 0, flags)) return 0;   if (!suitableImage(entry, bootPrefix, 0, flags)) return 0;
4638    
4639   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);
4640   if (!line) return 0;   if (!line) return 0;
4641    
4642          rootspec = getRootSpecifier(line->elements[1].item);          rootspec = getRootSpecifier(line->elements[1].item);
# Line 4428  int main(int argc, const char ** argv) { Line 4697  int main(int argc, const char ** argv) {
4697      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,
4698                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;
4699      if (updateKernelPath && newKernelInitrd) {      if (updateKernelPath && newKernelInitrd) {
4700              if (updateInitrd(config, updateKernelPath, bootPrefix,      if (newMBKernel) {
4701                               newKernelInitrd)) return 1;      if (addMBInitrd(config, newMBKernel, updateKernelPath,
4702     bootPrefix, newKernelInitrd,
4703     newKernelTitle))
4704        return 1;
4705        } else {
4706        if (updateInitrd(config, updateKernelPath, bootPrefix,
4707     newKernelInitrd, newKernelTitle))
4708     return 1;
4709        }
4710      }      }
4711      if (addNewKernel(config, template, bootPrefix, newKernelPath,      if (addNewKernel(config, template, bootPrefix, newKernelPath,
4712                       newKernelTitle, newKernelArgs, newKernelInitrd,                       newKernelTitle, newKernelArgs, newKernelInitrd,
4713                       (const char **)extraInitrds, extraInitrdCount,                       (const char **)extraInitrds, extraInitrdCount,
4714                       newMBKernel, newMBKernelArgs)) return 1;                       newMBKernel, newMBKernelArgs, newDevTreePath)) return 1;
4715            
4716    
4717      if (numEntries(config) == 0) {      if (numEntries(config) == 0) {

Legend:
Removed from v.2255  
changed lines
  Added in v.2991