install.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_UTIL_INSTALL_HEADER
  19. #define GRUB_UTIL_INSTALL_HEADER 1
  20. #include <sys/types.h>
  21. #include <stdio.h>
  22. #include <grub/device.h>
  23. #include <grub/disk.h>
  24. #include <grub/emu/hostfile.h>
  25. #define GRUB_INSTALL_OPTIONS \
  26. { "modules", GRUB_INSTALL_OPTIONS_MODULES, N_("MODULES"), \
  27. 0, N_("pre-load specified modules MODULES"), 1 }, \
  28. { "dtb", GRUB_INSTALL_OPTIONS_DTB, N_("FILE"), \
  29. 0, N_("embed a specific DTB"), 1 }, \
  30. { "install-modules", GRUB_INSTALL_OPTIONS_INSTALL_MODULES, \
  31. N_("MODULES"), 0, \
  32. N_("install only MODULES and their dependencies [default=all]"), 1 }, \
  33. { "themes", GRUB_INSTALL_OPTIONS_INSTALL_THEMES, N_("THEMES"), \
  34. 0, N_("install THEMES [default=%s]"), 1 }, \
  35. { "fonts", GRUB_INSTALL_OPTIONS_INSTALL_FONTS, N_("FONTS"), \
  36. 0, N_("install FONTS [default=%s]"), 1 }, \
  37. { "locales", GRUB_INSTALL_OPTIONS_INSTALL_LOCALES, N_("LOCALES"),\
  38. 0, N_("install only LOCALES [default=all]"), 1 }, \
  39. { "compress", GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS, \
  40. "no|xz|gz|lzo", 0, \
  41. N_("compress GRUB files [optional]"), 1 }, \
  42. {"core-compress", GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS, \
  43. "xz|none|auto", \
  44. 0, N_("choose the compression to use for core image"), 2}, \
  45. /* TRANSLATORS: platform here isn't identifier. It can be translated. */ \
  46. { "directory", 'd', N_("DIR"), 0, \
  47. N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
  48. { "override-directory", GRUB_INSTALL_OPTIONS_DIRECTORY2, \
  49. N_("DIR"), OPTION_HIDDEN, \
  50. N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
  51. { "locale-directory", GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY, \
  52. N_("DIR"), 0, \
  53. N_("use translations under DIR [default=%s]"), 1 }, \
  54. { "themes-directory", GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY, \
  55. N_("DIR"), OPTION_HIDDEN, \
  56. N_("use themes under DIR [default=%s]"), 1 }, \
  57. { "grub-mkimage", GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE, \
  58. "FILE", OPTION_HIDDEN, 0, 1 }, \
  59. /* TRANSLATORS: "embed" is a verb (command description). "*/ \
  60. { "pubkey", 'k', N_("FILE"), 0, \
  61. N_("embed FILE as public key for signature checking"), 0}, \
  62. { "sbat", GRUB_INSTALL_OPTIONS_SBAT, N_("FILE"), 0, \
  63. N_("SBAT metadata"), 0 }, \
  64. { "disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, \
  65. N_("disable shim_lock verifier"), 0 }, \
  66. { "disable-cli", GRUB_INSTALL_OPTIONS_DISABLE_CLI, 0, 0, \
  67. N_("disabled command line interface access"), 0 }, \
  68. { "verbose", 'v', 0, 0, \
  69. N_("print verbose messages."), 1 }
  70. int
  71. grub_install_parse (int key, char *arg);
  72. void
  73. grub_install_push_module (const char *val);
  74. void
  75. grub_install_pop_module (void);
  76. char *
  77. grub_install_help_filter (int key, const char *text,
  78. void *input __attribute__ ((unused)));
  79. enum grub_install_plat
  80. {
  81. GRUB_INSTALL_PLATFORM_I386_PC,
  82. GRUB_INSTALL_PLATFORM_I386_EFI,
  83. GRUB_INSTALL_PLATFORM_I386_QEMU,
  84. GRUB_INSTALL_PLATFORM_I386_COREBOOT,
  85. GRUB_INSTALL_PLATFORM_I386_MULTIBOOT,
  86. GRUB_INSTALL_PLATFORM_I386_IEEE1275,
  87. GRUB_INSTALL_PLATFORM_X86_64_EFI,
  88. GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON,
  89. GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
  90. GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275,
  91. GRUB_INSTALL_PLATFORM_MIPSEL_ARC,
  92. GRUB_INSTALL_PLATFORM_MIPS_ARC,
  93. GRUB_INSTALL_PLATFORM_IA64_EFI,
  94. GRUB_INSTALL_PLATFORM_ARM_UBOOT,
  95. GRUB_INSTALL_PLATFORM_ARM_EFI,
  96. GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS,
  97. GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS,
  98. GRUB_INSTALL_PLATFORM_I386_XEN,
  99. GRUB_INSTALL_PLATFORM_X86_64_XEN,
  100. GRUB_INSTALL_PLATFORM_I386_XEN_PVH,
  101. GRUB_INSTALL_PLATFORM_ARM64_EFI,
  102. GRUB_INSTALL_PLATFORM_ARM_COREBOOT,
  103. GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI,
  104. GRUB_INSTALL_PLATFORM_RISCV32_EFI,
  105. GRUB_INSTALL_PLATFORM_RISCV64_EFI,
  106. GRUB_INSTALL_PLATFORM_MAX
  107. };
  108. enum grub_install_options {
  109. GRUB_INSTALL_OPTIONS_DIRECTORY = 'd',
  110. GRUB_INSTALL_OPTIONS_VERBOSITY = 'v',
  111. GRUB_INSTALL_OPTIONS_MODULES = 0x201,
  112. GRUB_INSTALL_OPTIONS_INSTALL_MODULES,
  113. GRUB_INSTALL_OPTIONS_INSTALL_THEMES,
  114. GRUB_INSTALL_OPTIONS_INSTALL_FONTS,
  115. GRUB_INSTALL_OPTIONS_INSTALL_LOCALES,
  116. GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS,
  117. GRUB_INSTALL_OPTIONS_DIRECTORY2,
  118. GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY,
  119. GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY,
  120. GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE,
  121. GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS,
  122. GRUB_INSTALL_OPTIONS_DTB,
  123. GRUB_INSTALL_OPTIONS_SBAT,
  124. GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK,
  125. GRUB_INSTALL_OPTIONS_DISABLE_CLI
  126. };
  127. extern char *grub_install_source_directory;
  128. enum grub_install_plat
  129. grub_install_get_target (const char *src);
  130. void
  131. grub_install_mkdir_p (const char *dst);
  132. void
  133. grub_install_copy_files (const char *src,
  134. const char *dst,
  135. enum grub_install_plat platid);
  136. char *
  137. grub_install_get_platform_name (enum grub_install_plat platid);
  138. const char *
  139. grub_install_get_platform_cpu (enum grub_install_plat platid);
  140. const char *
  141. grub_install_get_platform_platform (enum grub_install_plat platid);
  142. char *
  143. grub_install_get_platforms_string (void);
  144. typedef enum {
  145. GRUB_COMPRESSION_AUTO,
  146. GRUB_COMPRESSION_NONE,
  147. GRUB_COMPRESSION_XZ,
  148. GRUB_COMPRESSION_LZMA
  149. } grub_compression_t;
  150. void
  151. grub_install_make_image_wrap (const char *dir, const char *prefix,
  152. const char *outname, char *memdisk_path,
  153. char *config_path,
  154. const char *format, int note);
  155. void
  156. grub_install_make_image_wrap_file (const char *dir, const char *prefix,
  157. FILE *fp, const char *outname,
  158. char *memdisk_path,
  159. char *config_path,
  160. const char *mkimage_target, int note);
  161. int
  162. grub_install_copy_file (const char *src,
  163. const char *dst,
  164. int is_critical);
  165. struct grub_install_image_target_desc;
  166. void
  167. grub_install_generate_image (const char *dir, const char *prefix,
  168. FILE *out,
  169. const char *outname, char *mods[],
  170. char *memdisk_path, char **pubkey_paths,
  171. size_t npubkeys,
  172. char *config_path,
  173. const struct grub_install_image_target_desc *image_target,
  174. int note,
  175. grub_compression_t comp, const char *dtb_file,
  176. const char *sbat_path, const int disable_shim_lock,
  177. const int disable_cli);
  178. const struct grub_install_image_target_desc *
  179. grub_install_get_image_target (const char *arg);
  180. void
  181. grub_util_bios_setup (const char *dir,
  182. const char *boot_file, const char *core_file,
  183. const char *dest, int force,
  184. int fs_probe, int allow_floppy,
  185. int add_rs_codes, int warn_short_mbr_gap);
  186. void
  187. grub_util_sparc_setup (const char *dir,
  188. const char *boot_file, const char *core_file,
  189. const char *dest, int force,
  190. int fs_probe, int allow_floppy,
  191. int add_rs_codes, int warn_short_mbr_gap);
  192. char *
  193. grub_install_get_image_targets_string (void);
  194. const char *
  195. grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);
  196. void
  197. grub_install_create_envblk_file (const char *name);
  198. const char *
  199. grub_install_get_default_arm_platform (void);
  200. const char *
  201. grub_install_get_default_x86_platform (void);
  202. int
  203. grub_install_register_efi (grub_device_t efidir_grub_dev,
  204. const char *efifile_path,
  205. const char *efi_distributor);
  206. void
  207. grub_install_register_ieee1275 (int is_prep, const char *install_device,
  208. int partno, const char *relpath);
  209. void
  210. grub_install_sgi_setup (const char *install_device,
  211. const char *imgfile, const char *destname);
  212. int
  213. grub_install_compress_gzip (const char *src, const char *dest);
  214. int
  215. grub_install_compress_lzop (const char *src, const char *dest);
  216. int
  217. grub_install_compress_xz (const char *src, const char *dest);
  218. void
  219. grub_install_get_blocklist (grub_device_t root_dev,
  220. const char *core_path, const char *core_img,
  221. size_t core_size,
  222. void (*callback) (grub_disk_addr_t sector,
  223. unsigned offset,
  224. unsigned length,
  225. void *data),
  226. void *hook_data);
  227. void
  228. grub_util_create_envblk_file (const char *name);
  229. void
  230. grub_util_glue_efi (const char *file32, const char *file64, const char *out);
  231. void
  232. grub_util_render_label (const char *label_font,
  233. const char *label_bgcolor,
  234. const char *label_color,
  235. const char *label_string,
  236. const char *label);
  237. const char *
  238. grub_util_get_target_name (const struct grub_install_image_target_desc *t);
  239. extern char *grub_install_copy_buffer;
  240. #define GRUB_INSTALL_COPY_BUFFER_SIZE 1048576
  241. int
  242. grub_install_is_short_mbrgap_supported (void);
  243. /*
  244. * grub-install-common tries to make backups of modules & auxiliary files,
  245. * and restore the backup upon failure to install core.img. There are
  246. * platforms with additional actions after modules & core got installed
  247. * in place. It is a point of no return, as core.img cannot be reverted
  248. * from this point onwards, and new modules should be kept installed.
  249. * Before performing these additional actions call grub_set_install_backup_ponr()
  250. * to set the grub_install_backup_ponr flag. This way failure to perform
  251. * subsequent actions will not result in reverting new modules to the
  252. * old ones, e.g. in case efivars updates fails.
  253. */
  254. #ifdef HAVE_ATEXIT
  255. extern void
  256. grub_set_install_backup_ponr (void);
  257. #else
  258. static inline void
  259. grub_set_install_backup_ponr (void)
  260. {
  261. }
  262. #endif
  263. #endif