iPXE
init.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <ipxe/device.h>
27 #include <ipxe/console.h>
28 #include <ipxe/init.h>
29 
30 /** @file
31  *
32  * Initialisation, startup and shutdown routines
33  *
34  */
35 
36 /** "startup() has been called" flag */
37 static int started = 0;
38 
39 /** Colour for debug messages */
40 #define colour table_start ( INIT_FNS )
41 
42 /**
43  * Initialise iPXE
44  *
45  * This function performs the one-time-only and irreversible
46  * initialisation steps, such as initialising the heap. It must be
47  * called before (almost) any other function.
48  *
49  * There is, by definition, no counterpart to this function on the
50  * shutdown path.
51  */
52 void initialise ( void ) {
53  struct init_fn *init_fn;
54 
55  /* Call registered initialisation functions */
57  init_fn->initialise ();
58 }
59 
60 /**
61  * Start up iPXE
62  *
63  * This function performs the repeatable initialisation steps, such as
64  * probing devices. You may call startup() and shutdown() multiple
65  * times (as is done via the PXE API when PXENV_START_UNDI is used).
66  */
67 void startup ( void ) {
68  struct startup_fn *startup_fn;
69 
70  if ( started )
71  return;
72 
73  /* Call registered startup functions */
75  if ( startup_fn->startup ) {
76  DBGC ( colour, "INIT startup %s...\n",
77  startup_fn->name );
79  }
80  }
81 
82  started = 1;
83  DBGC ( colour, "INIT startup complete\n" );
84 }
85 
86 /**
87  * Shut down iPXE
88  *
89  * @v flags Shutdown behaviour flags
90  *
91  * This function reverses the actions of startup(), and leaves iPXE in
92  * a state ready to be removed from memory. You may call startup()
93  * again after calling shutdown().
94  *
95  * Call this function only once, before either exiting main() or
96  * starting up a non-returnable image.
97  */
98 void shutdown ( int flags ) {
99  struct startup_fn *startup_fn;
100 
101  if ( ! started )
102  return;
103 
104  /* Call registered shutdown functions (in reverse order) */
106  if ( startup_fn->shutdown ) {
107  DBGC ( colour, "INIT shutdown %s...\n",
108  startup_fn->name );
110  }
111  }
112 
113  /* Reset console */
114  console_reset();
115 
116  started = 0;
117  DBGC ( colour, "INIT shutdown complete\n" );
118 }
#define INIT_FNS
Initialisation function table.
Definition: init.h:19
void(* initialise)(void)
Definition: init.h:15
#define DBGC(...)
Definition: compiler.h:505
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
Definition: tables.h:413
const char * name
Definition: init.h:42
void initialise(void)
Initialise iPXE.
Definition: init.c:52
A startup/shutdown function.
Definition: init.h:41
#define colour
Colour for debug messages.
Definition: init.c:40
static int started
"startup() has been called" flag
Definition: init.c:37
An initialisation function.
Definition: init.h:14
User interaction.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
static void console_reset(void)
Reset console.
Definition: console.h:214
void(* startup)(void)
Definition: init.h:43
void(* shutdown)(int booting)
Definition: init.h:44
Device model.
void shutdown(int flags)
Shut down iPXE.
Definition: init.c:98
#define STARTUP_FNS
Startup/shutdown function table.
Definition: init.h:48
void startup(void)
Start up iPXE.
Definition: init.c:67
uint8_t flags
Flags.
Definition: ena.h:18