You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.c 2.4KB

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