Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <usr/prompt.h>
  21. #include <usr/autoboot.h>
  22. #include <config/general.h>
  23. #define NORMAL "\033[0m"
  24. #define BOLD "\033[1m"
  25. #define CYAN "\033[36m"
  26. /** The "scriptlet" setting */
  27. struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
  28. .name = "scriptlet",
  29. .description = "Boot scriptlet",
  30. .tag = DHCP_EB_SCRIPTLET,
  31. .type = &setting_type_string,
  32. };
  33. /**
  34. * Prompt for shell entry
  35. *
  36. * @ret enter_shell User wants to enter shell
  37. */
  38. static int shell_banner ( void ) {
  39. /* Skip prompt if timeout is zero */
  40. if ( BANNER_TIMEOUT <= 0 )
  41. return 0;
  42. return ( prompt ( "\nPress Ctrl-B for the iPXE command line...",
  43. ( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 );
  44. }
  45. /**
  46. * Main entry point
  47. *
  48. * @ret rc Return status code
  49. */
  50. __asmcall int main ( void ) {
  51. struct feature *feature;
  52. struct image *image;
  53. char *scriptlet;
  54. /* Some devices take an unreasonably long time to initialise */
  55. printf ( PRODUCT_SHORT_NAME " initialising devices..." );
  56. initialise();
  57. startup();
  58. printf ( "ok\n" );
  59. /*
  60. * Print welcome banner
  61. *
  62. *
  63. * If you wish to brand this build of iPXE, please do so by
  64. * defining the string PRODUCT_NAME in config/general.h.
  65. *
  66. * While nothing in the GPL prevents you from removing all
  67. * references to iPXE or http://ipxe.org, we prefer you not to
  68. * do so.
  69. *
  70. */
  71. printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE " VERSION
  72. NORMAL " -- Open Source Network Boot Firmware -- "
  73. CYAN "http://ipxe.org" NORMAL "\n"
  74. "Features:" );
  75. for_each_table_entry ( feature, FEATURES )
  76. printf ( " %s", feature->name );
  77. printf ( "\n" );
  78. /* Boot system */
  79. if ( ( image = first_image() ) != NULL ) {
  80. /* We have an embedded image; execute it */
  81. image_exec ( image );
  82. } else if ( shell_banner() ) {
  83. /* User wants shell; just give them a shell */
  84. shell();
  85. } else {
  86. fetch_string_setting_copy ( NULL, &scriptlet_setting,
  87. &scriptlet );
  88. if ( scriptlet ) {
  89. /* User has defined a scriptlet; execute it */
  90. system ( scriptlet );
  91. free ( scriptlet );
  92. } else {
  93. /* Try booting. If booting fails, offer the
  94. * user another chance to enter the shell.
  95. */
  96. autoboot();
  97. if ( shell_banner() )
  98. shell();
  99. }
  100. }
  101. shutdown_exit();
  102. return 0;
  103. }