Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 2262 by niro, Mon Oct 21 14:06:22 2013 UTC revision 2683 by niro, Wed Jul 16 09:51:14 2014 UTC
# Line 90  enum lineType_e { Line 90  enum lineType_e {
90      LT_SET_VARIABLE = 1 << 19,      LT_SET_VARIABLE = 1 << 19,
91      LT_KERNEL_EFI   = 1 << 20,      LT_KERNEL_EFI   = 1 << 20,
92      LT_INITRD_EFI   = 1 << 21,      LT_INITRD_EFI   = 1 << 21,
93      LT_UNKNOWN      = 1 << 22,      LT_KERNEL_16    = 1 << 22,
94        LT_INITRD_16    = 1 << 23,
95        LT_UNKNOWN      = 1 << 24,
96  };  };
97    
98  struct singleLine {  struct singleLine {
# Line 223  struct keywordTypes grub2Keywords[] = { Line 225  struct keywordTypes grub2Keywords[] = {
225      { "fallback",   LT_FALLBACK,    ' ' },      { "fallback",   LT_FALLBACK,    ' ' },
226      { "linux",      LT_KERNEL,      ' ' },      { "linux",      LT_KERNEL,      ' ' },
227      { "linuxefi",   LT_KERNEL_EFI,  ' ' },      { "linuxefi",   LT_KERNEL_EFI,  ' ' },
228        { "linux16",    LT_KERNEL_16,   ' ' },
229      { "initrd",     LT_INITRD,      ' ', ' ' },      { "initrd",     LT_INITRD,      ' ', ' ' },
230      { "initrdefi",  LT_INITRD_EFI,  ' ', ' ' },      { "initrdefi",  LT_INITRD_EFI,  ' ', ' ' },
231        { "initrd16",   LT_INITRD_16,   ' ', ' ' },
232      { "module",     LT_MBMODULE,    ' ' },      { "module",     LT_MBMODULE,    ' ' },
233      { "kernel",     LT_HYPER,       ' ' },      { "kernel",     LT_HYPER,       ' ' },
234      { NULL, 0, 0 },      { NULL, 0, 0 },
# Line 275  static char *grub2GetEnv(struct configFi Line 279  static char *grub2GetEnv(struct configFi
279      static char buf[1025];      static char buf[1025];
280      char *s = NULL;      char *s = NULL;
281      char *ret = NULL;      char *ret = NULL;
282      char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";      char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv";
283      int rc = asprintf(&s, "grub2-editenv %s list | grep '^%s='", envFile, name);      int rc = asprintf(&s, "grub-editenv %s list | grep '^%s='", envFile, name);
284    
285      if (rc < 0)      if (rc < 0)
286   return NULL;   return NULL;
# Line 340  static int grub2SetEnv(struct configFile Line 344  static int grub2SetEnv(struct configFile
344  {  {
345      char *s = NULL;      char *s = NULL;
346      int rc = 0;      int rc = 0;
347      char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv";      char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv";
348    
349      unquote(value);      unquote(value);
350      value = shellEscape(value);      value = shellEscape(value);
351      if (!value)      if (!value)
352      return -1;      return -1;
353    
354      rc = asprintf(&s, "grub2-editenv %s set '%s=%s'", envFile, name, value);      rc = asprintf(&s, "grub-editenv %s set '%s=%s'", envFile, name, value);
355      free(value);      free(value);
356      if (rc <0)      if (rc <0)
357   return -1;   return -1;
# Line 398  static int isquote(char q) Line 402  static int isquote(char q)
402  }  }
403    
404  static int iskernel(enum lineType_e type) {  static int iskernel(enum lineType_e type) {
405      return (type == LT_KERNEL || type == LT_KERNEL_EFI);      return (type == LT_KERNEL || type == LT_KERNEL_EFI || type == LT_KERNEL_16);
406  }  }
407    
408  static int isinitrd(enum lineType_e type) {  static int isinitrd(enum lineType_e type) {
409      return (type == LT_INITRD || type == LT_INITRD_EFI);      return (type == LT_INITRD || type == LT_INITRD_EFI || type == LT_INITRD_16);
410  }  }
411    
412  char *grub2ExtractTitle(struct singleLine * line) {  char *grub2ExtractTitle(struct singleLine * line) {
# Line 720  static enum lineType_e preferredLineType Line 724  static enum lineType_e preferredLineType
724   default:   default:
725      return type;      return type;
726   }   }
727    #if defined(__i386__) || defined(__x86_64__)
728        } else if (cfi == &grub2ConfigType) {
729     switch (type) {
730     case LT_KERNEL:
731        return LT_KERNEL_16;
732     case LT_INITRD:
733        return LT_INITRD_16;
734     default:
735        return type;
736     }
737    #endif
738      }      }
739      return type;      return type;
740  }  }
# Line 1807  int suitableImage(struct singleEntry * e Line 1822  int suitableImage(struct singleEntry * e
1822   return 0;   return 0;
1823      }      }
1824    
1825      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);
1826      if (!line) {      if (!line) {
1827   notSuitablePrintf(entry, 0, "no line found\n");   notSuitablePrintf(entry, 0, "no line found\n");
1828   return 0;   return 0;
# Line 1941  struct singleEntry * findEntryByPath(str Line 1956  struct singleEntry * findEntryByPath(str
1956   entry = findEntryByIndex(config, indexVars[i]);   entry = findEntryByIndex(config, indexVars[i]);
1957   if (!entry) return NULL;   if (!entry) return NULL;
1958    
1959   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);
1960   if (!line) return NULL;   if (!line) return NULL;
1961    
1962   if (index) *index = indexVars[i];   if (index) *index = indexVars[i];
# Line 1992  struct singleEntry * findEntryByPath(str Line 2007  struct singleEntry * findEntryByPath(str
2007      for (line = entry->lines; line; line = line->next) {      for (line = entry->lines; line; line = line->next) {
2008   enum lineType_e ct = checkType;   enum lineType_e ct = checkType;
2009   if (entry->multiboot && checkType == LT_KERNEL)   if (entry->multiboot && checkType == LT_KERNEL)
2010      ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER;      ct = LT_KERNEL|LT_KERNEL_EFI|LT_MBMODULE|LT_HYPER|LT_KERNEL_16;
2011   else if (checkType & LT_KERNEL)   else if (checkType & LT_KERNEL)
2012      ct = checkType | LT_KERNEL_EFI;      ct = checkType | LT_KERNEL_EFI | LT_KERNEL_16;
2013   line = getLineByType(ct, line);   line = getLineByType(ct, line);
2014   if (!line)   if (!line)
2015      break;  /* not found in this entry */      break;  /* not found in this entry */
# Line 2016  struct singleEntry * findEntryByPath(str Line 2031  struct singleEntry * findEntryByPath(str
2031       * non-Linux boot entries (could find netbsd etc, though, which is       * non-Linux boot entries (could find netbsd etc, though, which is
2032       * unfortunate)       * unfortunate)
2033       */       */
2034      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))
2035   break; /* found 'im! */   break; /* found 'im! */
2036   }   }
2037    
# Line 2250  void displayEntry(struct singleEntry * e Line 2265  void displayEntry(struct singleEntry * e
2265    
2266      printf("index=%d\n", index);      printf("index=%d\n", index);
2267    
2268      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);
2269      if (!line) {      if (!line) {
2270          printf("non linux entry\n");          printf("non linux entry\n");
2271          return;          return;
# Line 2315  void displayEntry(struct singleEntry * e Line 2330  void displayEntry(struct singleEntry * e
2330   printf("root=%s\n", s);   printf("root=%s\n", s);
2331      }      }
2332    
2333      line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines);      line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);
2334    
2335      if (line && line->numElements >= 2) {      if (line && line->numElements >= 2) {
2336   if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))   if (!strncmp(prefix, line->elements[1].item, strlen(prefix)))
# Line 2732  struct singleLine * addLineTmpl(struct s Line 2747  struct singleLine * addLineTmpl(struct s
2747   insertElement(newLine, val, 1, cfi);   insertElement(newLine, val, 1, cfi);
2748    
2749   /* but try to keep the rootspec from the template... sigh */   /* but try to keep the rootspec from the template... sigh */
2750   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)) {
2751      char * rootspec = getRootSpecifier(tmplLine->elements[1].item);      char * rootspec = getRootSpecifier(tmplLine->elements[1].item);
2752      if (rootspec != NULL) {      if (rootspec != NULL) {
2753   free(newLine->elements[1].item);   free(newLine->elements[1].item);
# Line 3102  int updateActualImage(struct grubConfig Line 3117  int updateActualImage(struct grubConfig
3117      firstElement = 2;      firstElement = 2;
3118    
3119   } else {   } else {
3120      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);
3121      if (!line) {      if (!line) {
3122   /* no LT_KERNEL or LT_MBMODULE in this entry? */   /* no LT_KERNEL or LT_MBMODULE in this entry? */
3123   continue;   continue;
# Line 3258  int updateImage(struct grubConfig * cfg, Line 3273  int updateImage(struct grubConfig * cfg,
3273      return rc;      return rc;
3274  }  }
3275    
3276    int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel,
3277     const char * image, const char * prefix, const char * initrd) {
3278        struct singleEntry * entry;
3279        struct singleLine * line, * kernelLine, *endLine = NULL;
3280        int index = 0;
3281    
3282        if (!image) return 0;
3283    
3284        for (; (entry = findEntryByPath(cfg, newMBKernel, prefix, &index)); index++) {
3285            kernelLine = getLineByType(LT_MBMODULE, entry->lines);
3286            if (!kernelLine) continue;
3287    
3288            if (prefix) {
3289                int prefixLen = strlen(prefix);
3290                if (!strncmp(initrd, prefix, prefixLen))
3291                    initrd += prefixLen;
3292            }
3293     endLine = getLineByType(LT_ENTRY_END, entry->lines);
3294     if (endLine)
3295        removeLine(entry, endLine);
3296            line = addLine(entry, cfg->cfi, preferredLineType(LT_MBMODULE,cfg->cfi),
3297     kernelLine->indent, initrd);
3298            if (!line)
3299        return 1;
3300     if (endLine) {
3301        line = addLine(entry, cfg->cfi, LT_ENTRY_END, "", NULL);
3302                if (!line)
3303     return 1;
3304     }
3305    
3306            break;
3307        }
3308    
3309        return 0;
3310    }
3311    
3312  int updateInitrd(struct grubConfig * cfg, const char * image,  int updateInitrd(struct grubConfig * cfg, const char * image,
3313                   const char * prefix, const char * initrd) {                   const char * prefix, const char * initrd) {
3314      struct singleEntry * entry;      struct singleEntry * entry;
# Line 3267  int updateInitrd(struct grubConfig * cfg Line 3318  int updateInitrd(struct grubConfig * cfg
3318      if (!image) return 0;      if (!image) return 0;
3319    
3320      for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {      for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) {
3321          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI, entry->lines);          kernelLine = getLineByType(LT_KERNEL|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines);
3322          if (!kernelLine) continue;          if (!kernelLine) continue;
3323    
3324          line = getLineByType(LT_INITRD|LT_INITRD_EFI, entry->lines);          line = getLineByType(LT_INITRD|LT_INITRD_EFI|LT_INITRD_16, entry->lines);
3325          if (line)          if (line)
3326              removeLine(entry, line);              removeLine(entry, line);
3327          if (prefix) {          if (prefix) {
# Line 3281  int updateInitrd(struct grubConfig * cfg Line 3332  int updateInitrd(struct grubConfig * cfg
3332   endLine = getLineByType(LT_ENTRY_END, entry->lines);   endLine = getLineByType(LT_ENTRY_END, entry->lines);
3333   if (endLine)   if (endLine)
3334      removeLine(entry, endLine);      removeLine(entry, endLine);
3335          line = addLine(entry, cfg->cfi, preferredLineType(LT_INITRD, cfg->cfi),   enum lineType_e lt;
3336   kernelLine->indent, initrd);   switch(kernelLine->type) {
3337        case LT_KERNEL:
3338            lt = LT_INITRD;
3339     break;
3340        case LT_KERNEL_EFI:
3341            lt = LT_INITRD_EFI;
3342     break;
3343        case LT_KERNEL_16:
3344            lt = LT_INITRD_16;
3345     break;
3346        default:
3347            lt = preferredLineType(LT_INITRD, cfg->cfi);
3348     }
3349            line = addLine(entry, cfg->cfi, lt, kernelLine->indent, initrd);
3350          if (!line)          if (!line)
3351      return 1;      return 1;
3352   if (endLine) {   if (endLine) {
# Line 3880  int addNewKernel(struct grubConfig * con Line 3944  int addNewKernel(struct grubConfig * con
3944   switch (config->cfi->entryStart) {   switch (config->cfi->entryStart) {
3945      case LT_KERNEL:      case LT_KERNEL:
3946      case LT_KERNEL_EFI:      case LT_KERNEL_EFI:
3947        case LT_KERNEL_16:
3948   if (new->multiboot && config->cfi->mbHyperFirst) {   if (new->multiboot && config->cfi->mbHyperFirst) {
3949      /* fall through to LT_HYPER */      /* fall through to LT_HYPER */
3950   } else {   } else {
# Line 4438  int main(int argc, const char ** argv) { Line 4503  int main(int argc, const char ** argv) {
4503   if (!entry) return 0;   if (!entry) return 0;
4504   if (!suitableImage(entry, bootPrefix, 0, flags)) return 0;   if (!suitableImage(entry, bootPrefix, 0, flags)) return 0;
4505    
4506   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);
4507   if (!line) return 0;   if (!line) return 0;
4508    
4509          rootspec = getRootSpecifier(line->elements[1].item);          rootspec = getRootSpecifier(line->elements[1].item);
# Line 4499  int main(int argc, const char ** argv) { Line 4564  int main(int argc, const char ** argv) {
4564      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,      if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs,
4565                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;                      removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1;
4566      if (updateKernelPath && newKernelInitrd) {      if (updateKernelPath && newKernelInitrd) {
4567              if (updateInitrd(config, updateKernelPath, bootPrefix,      if (newMBKernel) {
4568                               newKernelInitrd)) return 1;      if (addMBInitrd(config, newMBKernel, updateKernelPath,
4569     bootPrefix, newKernelInitrd))
4570        return 1;
4571        } else {
4572        if (updateInitrd(config, updateKernelPath, bootPrefix,
4573     newKernelInitrd))
4574     return 1;
4575        }
4576      }      }
4577      if (addNewKernel(config, template, bootPrefix, newKernelPath,      if (addNewKernel(config, template, bootPrefix, newKernelPath,
4578                       newKernelTitle, newKernelArgs, newKernelInitrd,                       newKernelTitle, newKernelArgs, newKernelInitrd,

Legend:
Removed from v.2262  
changed lines
  Added in v.2683