From: "H. Peter Anvin" This patch exports to userspace the boot loader ID which has been exported by (b)zImage boot loaders since boot protocol version 2. It is needed so that update tools that update kernels from vendors know which bootloader file they need to update; eg right now those tools do all kinds of hairy heuristics to find out if it's grub or lilo or .. that installed the kernel. Those heuristics are fragile in the presence of more than one bootloader (which isn't that uncommon in OS upgrade situations). Tested on i386 and x86-64; as far as I know those are the only architectures which use zImage/bzImage format. Signed-Off-By: H. Peter Anvin Signed-off-by: Andrew Morton --- 25-akpm/arch/i386/kernel/setup.c | 4 ++++ 25-akpm/arch/x86_64/kernel/setup.c | 4 ++++ 25-akpm/include/asm-i386/processor.h | 3 +++ 25-akpm/include/asm-x86_64/processor.h | 2 ++ 25-akpm/include/linux/sysctl.h | 1 + 25-akpm/kernel/sysctl.c | 10 ++++++++++ 6 files changed, 24 insertions(+) diff -puN arch/i386/kernel/setup.c~proc-sys-kernel-bootloader_type arch/i386/kernel/setup.c --- 25/arch/i386/kernel/setup.c~proc-sys-kernel-bootloader_type 2004-12-31 14:37:17.075134464 -0800 +++ 25-akpm/arch/i386/kernel/setup.c 2004-12-31 14:37:17.121127472 -0800 @@ -97,6 +97,9 @@ unsigned int mca_pentium_flag; /* For PCI or other memory-mapped resources */ unsigned long pci_mem_start = 0x10000000; +/* Boot loader ID as an integer, for the benefit of proc_dointvec */ +int bootloader_type; + /* user-defined highmem size */ static unsigned int highmem_pages = -1; @@ -1329,6 +1332,7 @@ void __init setup_arch(char **cmdline_p) BIOS_revision = SYS_DESC_TABLE.table[2]; } aux_device_present = AUX_DEVICE_INFO; + bootloader_type = LOADER_TYPE; #ifdef CONFIG_BLK_DEV_RAM rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK; diff -puN arch/x86_64/kernel/setup.c~proc-sys-kernel-bootloader_type arch/x86_64/kernel/setup.c --- 25/arch/x86_64/kernel/setup.c~proc-sys-kernel-bootloader_type 2004-12-31 14:37:17.089132336 -0800 +++ 25-akpm/arch/x86_64/kernel/setup.c 2004-12-31 14:37:17.131125952 -0800 @@ -78,6 +78,9 @@ int __initdata acpi_force = 0; /* For PCI or other memory-mapped resources */ unsigned long pci_mem_start = 0x10000000; +/* Boot loader ID as an integer, for the benefit of proc_dointvec */ +int bootloader_type; + unsigned long saved_video_mode; #ifdef CONFIG_SWIOTLB @@ -452,6 +455,7 @@ void __init setup_arch(char **cmdline_p) edid_info = EDID_INFO; aux_device_present = AUX_DEVICE_INFO; saved_video_mode = SAVED_VIDEO_MODE; + bootloader_type = LOADER_TYPE; #ifdef CONFIG_BLK_DEV_RAM rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK; diff -puN include/asm-i386/processor.h~proc-sys-kernel-bootloader_type include/asm-i386/processor.h --- 25/include/asm-i386/processor.h~proc-sys-kernel-bootloader_type 2004-12-31 14:37:17.090132184 -0800 +++ 25-akpm/include/asm-i386/processor.h 2004-12-31 14:37:17.136125192 -0800 @@ -288,6 +288,9 @@ extern unsigned int machine_submodel_id; extern unsigned int BIOS_revision; extern unsigned int mca_pentium_flag; +/* Boot loader type from the setup header */ +extern int bootloader_type; + /* * User space process size: 3GB (default). */ diff -puN include/asm-x86_64/processor.h~proc-sys-kernel-bootloader_type include/asm-x86_64/processor.h --- 25/include/asm-x86_64/processor.h~proc-sys-kernel-bootloader_type 2004-12-31 14:37:17.092131880 -0800 +++ 25-akpm/include/asm-x86_64/processor.h 2004-12-31 14:37:17.140124584 -0800 @@ -462,5 +462,7 @@ static inline void __mwait(unsigned long #define cache_line_size() (boot_cpu_data.x86_cache_alignment) extern unsigned long boot_option_idle_override; +/* Boot loader type from the setup header */ +extern int bootloader_type; #endif /* __ASM_X86_64_PROCESSOR_H */ diff -puN include/linux/sysctl.h~proc-sys-kernel-bootloader_type include/linux/sysctl.h --- 25/include/linux/sysctl.h~proc-sys-kernel-bootloader_type 2004-12-31 14:37:17.097131120 -0800 +++ 25-akpm/include/linux/sysctl.h 2004-12-31 14:37:17.140124584 -0800 @@ -134,6 +134,7 @@ enum KERN_SPARC_SCONS_PWROFF=64, /* int: serial console power-off halt */ KERN_HZ_TIMER=65, /* int: hz timer on or off */ KERN_UNKNOWN_NMI_PANIC=66, /* int: unknown nmi panic flag */ + KERN_BOOTLOADER_TYPE=67, /* int: boot loader type */ }; diff -puN kernel/sysctl.c~proc-sys-kernel-bootloader_type kernel/sysctl.c --- 25/kernel/sysctl.c~proc-sys-kernel-bootloader_type 2004-12-31 14:37:17.113128688 -0800 +++ 25-akpm/kernel/sysctl.c 2004-12-31 14:37:17.144123976 -0800 @@ -624,6 +624,16 @@ static ctl_table kern_table[] = { .proc_handler = &proc_unknown_nmi_panic, }, #endif +#if defined(CONFIG_X86) + { + .ctl_name = KERN_BOOTLOADER_TYPE, + .procname = "bootloader_type", + .data = &bootloader_type, + .maxlen = sizeof (int), + .mode = 0444, + .proc_handler = &proc_dointvec, + }, +#endif { .ctl_name = 0 } }; _