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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27#include <ipxe/device.h>
28#include <ipxe/console.h>
29#include <ipxe/init.h>
30
31/** @file
32 *
33 * Initialisation, startup and shutdown routines
34 *
35 */
36
37/** "startup() has been called" flag */
38static int started = 0;
39
40/** Colour for debug messages */
41#define colour table_start ( INIT_FNS )
42
43/**
44 * Initialise iPXE
45 *
46 * This function performs the one-time-only and irreversible
47 * initialisation steps, such as initialising the heap. It must be
48 * called before (almost) any other function.
49 *
50 * There is, by definition, no counterpart to this function on the
51 * shutdown path.
52 */
53void initialise ( void ) {
54 struct init_fn *init_fn;
55
56 /* Call registered initialisation functions */
58 DBGC ( colour, "INIT initialising %s...\n", init_fn->name );
60 }
61}
62
63/**
64 * Start up iPXE
65 *
66 * This function performs the repeatable initialisation steps, such as
67 * probing devices. You may call startup() and shutdown() multiple
68 * times (as is done via the PXE API when PXENV_START_UNDI is used).
69 */
70void startup ( void ) {
71 struct startup_fn *startup_fn;
72
73 if ( started )
74 return;
75
76 /* Call registered startup functions */
78 if ( startup_fn->startup ) {
79 DBGC ( colour, "INIT startup %s...\n",
82 }
83 }
84
85 started = 1;
86 DBGC ( colour, "INIT startup complete\n" );
87}
88
89/**
90 * Shut down iPXE
91 *
92 * @v flags Shutdown behaviour flags
93 *
94 * This function reverses the actions of startup(), and leaves iPXE in
95 * a state ready to be removed from memory. You may call startup()
96 * again after calling shutdown().
97 *
98 * Call this function only once, before either exiting main() or
99 * starting up a non-returnable image.
100 */
101void shutdown ( int flags ) {
102 struct startup_fn *startup_fn;
103
104 if ( ! started )
105 return;
106
107 /* Call registered shutdown functions (in reverse order) */
109 if ( startup_fn->shutdown ) {
110 DBGC ( colour, "INIT shutdown %s...\n",
111 startup_fn->name );
113 }
114 }
115
116 /* Reset console */
118
119 started = 0;
120 DBGC ( colour, "INIT shutdown complete\n" );
121}
#define colour
Colour for debug messages.
Definition acpi.c:42
Device model.
uint8_t flags
Flags.
Definition ena.h:7
#define DBGC(...)
Definition compiler.h:505
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
User interaction.
static void console_reset(void)
Reset console.
Definition console.h:215
void startup(void)
Start up iPXE.
Definition init.c:70
void initialise(void)
Initialise iPXE.
Definition init.c:53
static int started
"startup() has been called" flag
Definition init.c:38
void shutdown(int flags)
Shut down iPXE.
Definition init.c:101
#define INIT_FNS
Initialisation function table.
Definition init.h:21
#define STARTUP_FNS
Startup/shutdown function table.
Definition init.h:50
An initialisation function.
Definition init.h:15
const char * name
Definition init.h:16
void(* initialise)(void)
Definition init.h:17
A startup/shutdown function.
Definition init.h:43
void(* startup)(void)
Definition init.h:45
const char * name
Definition init.h:44
void(* shutdown)(int booting)
Definition init.h:46
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
Definition tables.h:441