(i). Defined as follows:
#define __setup (str, fn) \__setup_param (str, FN, FN,0)#define __setup_param (str, unique_id, FN, early) \Static Char__setup_str_# #unique_id [] __initdata __aligned (1) = str; \Static structObs_kernel_param __setup_# #unique_id \__used __section (. Init.setup) __attribute__ ((Aligned (sizeof(Long)))) = {__setup_str_# #unique_id, FN, early}structObs_kernel_param {Const Char*STR;int(*setup_func) (Char*);intEarly;};
(b). Example: (From: NET/CORE/DEV.C)
__setup ("netdev=", Netdev_boot_setup) '
From (a) can be converted to:
__setup_param("netdev=", netdev_boot_setup, netdev_boot_setup, 0)
=====>
#define __setup_param("netdev=", netdev_boot_setup, netdev_boot_setup, 0) \staticchar __setup_str_netdev_boot_setup[] __initdata __aligned(1"netdev="staticstruct obs_kernel_param __setup_unique_id __used __section(.init.setup) __attribute__((aligned((sizeof(long0 }
__setup (str, FN)
STR is the keyword, and FN is the correlation handler function. __setup just tells the kernel to execute FN When the input string contains str when it starts. STR must end with a "=" character to make the Parse_args more convenient to parse. Any text immediately following the "=" will be passed as input to FN.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Continue to take __setup ("netdev=", Netdev_boot_setup) for example:
To achieve netdev_boot_setup, which form does it appear in? :
struct obs_kernel_param { constchar *str; int (*setup_func)(char *); int early;};
This should be done in the form of:
int netdev_boot_setup(char *str){ ... 0;}
When the kernel starts parsing parameters with a "Netdev" string, the Netdev_boot_setup function is executed and the string after "netdev=" is passed as a parameter.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux driver Macro __setup (str, FN)