9
0
Fork 0

exitcall: Add exitcall infrastructure

exitcall infrastructure is based on initcall infrastructure.
It allows to have and use exit call hooks on barebox shutdown.

Signed-off-by: Herve Codina <Herve.CODINA@celad.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Herve Codina 2015-07-06 09:36:43 +02:00 committed by Sascha Hauer
parent d46b6785c4
commit a2136e6cbd
14 changed files with 86 additions and 1 deletions

View File

@ -90,6 +90,10 @@ SECTIONS
.barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
__barebox_exitcalls_start = .;
.barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
__usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;

View File

@ -76,6 +76,10 @@ SECTIONS
.barebox_initcalls : { INITCALLS }
___barebox_initcalls_end = .;
___barebox_exitcalls_start = .;
.barebox_exitcalls : { EXITCALLS }
___barebox_exitcalls_end = .;
___usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
___usymtab_end = .;

View File

@ -56,6 +56,10 @@ SECTIONS
__barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
__barebox_exitcalls_start = .;
__barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
. = ALIGN(64);
__barebox_magicvar_start = .;
.barebox_magicvar : { BAREBOX_MAGICVARS }

View File

@ -58,6 +58,10 @@ SECTIONS
__barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
__barebox_exitcalls_start = .;
__barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
. = ALIGN(64);
__barebox_magicvar_start = .;
.barebox_magicvar : { BAREBOX_MAGICVARS }

View File

@ -67,6 +67,10 @@ SECTIONS
.barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
__barebox_exitcalls_start = .;
.barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
__usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;

View File

@ -63,6 +63,10 @@ SECTIONS
.barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
__barebox_exitcalls_start = .;
.barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
___usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
___usymtab_end = .;

View File

@ -65,6 +65,10 @@ SECTIONS
.barebox_initcalls : { INITCALLS } > ram
__barebox_initcalls_end = .;
__barebox_exitcalls_start = .;
.barebox_exitcalls : { EXITCALLS } > ram
__barebox_exitcalls_end = .;
___usymtab_start = .;
__usymtab : { BAREBOX_SYMS } > ram
___usymtab_end = .;

View File

@ -112,6 +112,11 @@ SECTIONS
__barebox_initcalls_end = .;
__initcall_entries = (__barebox_initcalls_end - __barebox_initcalls_start) >> 2;
__barebox_exitcalls_start = .;
.barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
__exitcall_entries = (__barebox_exitcalls_end - __barebox_exitcalls_start) >> 2;
__usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;

View File

@ -109,6 +109,11 @@ SECTIONS
__barebox_initcalls_end = .;
__initcall_entries = (__barebox_initcalls_end - __barebox_initcalls_start)>>2;
__barebox_exitcalls_start = .;
.barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
__exitcall_entries = (__barebox_exitcalls_end - __barebox_exitcalls_start) >> 2;
__usymtab_start = .;
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;

View File

@ -7,6 +7,11 @@ SECTIONS
__barebox_initcalls : { INITCALLS }
__barebox_initcalls_end = .;
. = ALIGN(64);
__barebox_exitcalls_start = .;
__barebox_exitcalls : { EXITCALLS }
__barebox_exitcalls_end = .;
. = ALIGN(64);
__barebox_magicvar_start = .;
.barebox_magicvar : { BAREBOX_MAGICVARS }

View File

@ -185,7 +185,14 @@ SECTIONS
. = ALIGN(4);
} > barebox
.__usymtab : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
.barebox_exitcalls : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
__barebox_exitcalls_start = .;
EXITCALLS
__barebox_exitcalls_end = .;
. = ALIGN(4);
} > barebox
.__usymtab : AT ( LOADADDR(.barebox_exitcalls) + SIZEOF (.barebox_exitcalls) ) {
__usymtab_start = .;
BAREBOX_SYMS
__usymtab_end = .;

View File

@ -45,6 +45,9 @@
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
extern exitcall_t __barebox_exitcalls_start[], __barebox_exitcalls_end[];
#if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
static int mount_root(void)
{
@ -140,6 +143,14 @@ void (*board_shutdown)(void);
*/
void shutdown_barebox(void)
{
exitcall_t *exitcall;
for (exitcall = __barebox_exitcalls_start;
exitcall < __barebox_exitcalls_end; exitcall++) {
pr_debug("exitcall-> %pS\n", *exitcall);
(*exitcall)();
}
devices_shutdown();
#ifdef ARCH_SHUTDOWN
arch_shutdown();

View File

@ -38,6 +38,15 @@
KEEP(*(.initcall.13)) \
KEEP(*(.initcall.14))
#define EXITCALLS \
KEEP(*(.exitcall.0)) \
KEEP(*(.exitcall.1)) \
KEEP(*(.exitcall.2)) \
KEEP(*(.exitcall.3)) \
KEEP(*(.exitcall.4)) \
KEEP(*(.exitcall.5)) \
KEEP(*(.exitcall.6))
#define BAREBOX_CMDS KEEP(*(SORT_BY_NAME(.barebox_cmd*)))
#define BAREBOX_SYMS KEEP(*(__usymtab))

View File

@ -7,17 +7,24 @@
#define __init
#define __initdata
#define __initconst
#define __exit
#define __exitdata
/* For assembly routines */
#define __BARE_INIT .section ".text_bare_init.text","ax"
#ifndef __ASSEMBLY__
typedef int (*initcall_t)(void);
typedef void (*exitcall_t)(void);
#define __define_initcall(level,fn,id) \
static initcall_t __initcall_##fn##id __attribute__((__used__)) \
__attribute__((__section__(".initcall." level))) = fn
#define __define_exitcall(level,fn,id) \
static exitcall_t __exitcall_##fn##id __attribute__((__used__)) \
__attribute__((__section__(".exitcall." level))) = fn
/*
* A "pure" initcall has no dependencies on anything else, and purely
@ -42,6 +49,14 @@ typedef int (*initcall_t)(void);
#define environment_initcall(fn) __define_initcall("13",fn,13)
#define postenvironment_initcall(fn) __define_initcall("14",fn,14)
#define early_exitcall(fn) __define_exitcall("0",fn,0)
#define predevshutdown_exitcall(fn) __define_exitcall("1",fn,1)
#define devshutdown_exitcall(fn) __define_exitcall("2",fn,2)
#define postdevshutdown_exitcall(fn) __define_exitcall("3",fn,3)
#define prearchshutdown_exitcall(fn) __define_exitcall("4",fn,4)
#define archshutdown_exitcall(fn) __define_exitcall("5",fn,5)
#define postarchshutdown_exitcall(fn) __define_exitcall("6",fn,6)
/* section for code used very early when
* - we're not running from where we linked at
* - bss not cleared