您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

main.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**************************************************************************
  2. iPXE - Network Bootstrap Program
  3. Literature dealing with the network protocols:
  4. ARP - RFC826
  5. RARP - RFC903
  6. UDP - RFC768
  7. BOOTP - RFC951, RFC2132 (vendor extensions)
  8. DHCP - RFC2131, RFC2132 (options)
  9. TFTP - RFC1350, RFC2347 (options), RFC2348 (blocksize), RFC2349 (tsize)
  10. RPC - RFC1831, RFC1832 (XDR), RFC1833 (rpcbind/portmapper)
  11. **************************************************************************/
  12. FILE_LICENCE ( GPL2_OR_LATER );
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <ipxe/init.h>
  16. #include <ipxe/features.h>
  17. #include <ipxe/shell.h>
  18. #include <ipxe/image.h>
  19. #include <ipxe/keys.h>
  20. #include <ipxe/version.h>
  21. #include <usr/prompt.h>
  22. #include <usr/autoboot.h>
  23. #include <config/general.h>
  24. #define NORMAL "\033[0m"
  25. #define BOLD "\033[1m"
  26. #define CYAN "\033[36m"
  27. /** The "scriptlet" setting */
  28. struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
  29. .name = "scriptlet",
  30. .description = "Boot scriptlet",
  31. .tag = DHCP_EB_SCRIPTLET,
  32. .type = &setting_type_string,
  33. };
  34. /**
  35. * Prompt for shell entry
  36. *
  37. * @ret enter_shell User wants to enter shell
  38. */
  39. static int shell_banner ( void ) {
  40. /* Skip prompt if timeout is zero */
  41. if ( BANNER_TIMEOUT <= 0 )
  42. return 0;
  43. /* Prompt user */
  44. printf ( "\n" );
  45. return ( prompt ( "Press Ctrl-B for the iPXE command line...",
  46. ( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 );
  47. }
  48. /**
  49. * Main entry point
  50. *
  51. * @ret rc Return status code
  52. */
  53. __asmcall int main ( void ) {
  54. struct feature *feature;
  55. struct image *image;
  56. char *scriptlet;
  57. /* Some devices take an unreasonably long time to initialise */
  58. printf ( PRODUCT_SHORT_NAME " initialising devices..." );
  59. initialise();
  60. startup();
  61. printf ( "ok\n" );
  62. /*
  63. * Print welcome banner
  64. *
  65. *
  66. * If you wish to brand this build of iPXE, please do so by
  67. * defining the string PRODUCT_NAME in config/general.h.
  68. *
  69. * While nothing in the GPL prevents you from removing all
  70. * references to iPXE or http://ipxe.org, we prefer you not to
  71. * do so.
  72. *
  73. */
  74. printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE %s"
  75. NORMAL " -- Open Source Network Boot Firmware -- "
  76. CYAN "http://ipxe.org" NORMAL "\n"
  77. "Features:", product_version );
  78. for_each_table_entry ( feature, FEATURES )
  79. printf ( " %s", feature->name );
  80. printf ( "\n" );
  81. /* Boot system */
  82. if ( ( image = first_image() ) != NULL ) {
  83. /* We have an embedded image; execute it */
  84. image_exec ( image );
  85. } else if ( shell_banner() ) {
  86. /* User wants shell; just give them a shell */
  87. shell();
  88. } else {
  89. fetch_string_setting_copy ( NULL, &scriptlet_setting,
  90. &scriptlet );
  91. if ( scriptlet ) {
  92. /* User has defined a scriptlet; execute it */
  93. system ( scriptlet );
  94. free ( scriptlet );
  95. } else {
  96. /* Try booting. If booting fails, offer the
  97. * user another chance to enter the shell.
  98. */
  99. autoboot();
  100. if ( shell_banner() )
  101. shell();
  102. }
  103. }
  104. shutdown_exit();
  105. return 0;
  106. }