From 6954812f9fabc1b2d3dc2ea7761fdcb82f0dd350 Mon Sep 17 00:00:00 2001 From: Greg Meiste Date: Wed, 8 Aug 2012 14:03:02 -0500 Subject: [PATCH] arm: Add bootinfo support Motorola bootinfo support, add serial number and hw revision as needed for SYSTEM_BOOT event (cherry picked from commit 2c5d15e240fc23e2c03840cf28fe0a1aeb222b34) (cherry picked from commit d8c9bffaf7ec254a6a0529a4c968b4c0d2e5c1eb) Signed-off-by: Jeffrey Carlyle Conflicts: arch/arm/Kconfig --- arch/arm/Kconfig | 8 + arch/arm/include/asm/bootinfo.h | 102 ++++++++++ arch/arm/kernel/Makefile | 1 + arch/arm/kernel/bootinfo.c | 326 ++++++++++++++++++++++++++++++++ arch/arm/kernel/setup.c | 3 + 5 files changed, 440 insertions(+) create mode 100644 arch/arm/include/asm/bootinfo.h create mode 100644 arch/arm/kernel/bootinfo.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 7dba0b5f7..0fc8d3293 100755 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -267,6 +267,14 @@ config GENERIC_BUG def_bool y depends on BUG +config BOOTINFO + bool "Boot Information Feature" + default n + help + This feature provides access to certain boot information + from both kernel context (via function call) and user + context (via /proc/bootinfo). + source "init/Kconfig" source "kernel/Kconfig.freezer" diff --git a/arch/arm/include/asm/bootinfo.h b/arch/arm/include/asm/bootinfo.h new file mode 100644 index 000000000..e9ebf2f4e --- /dev/null +++ b/arch/arm/include/asm/bootinfo.h @@ -0,0 +1,102 @@ +/* + * linux/include/asm/bootinfo.h: Include file for boot information + * provided on Motorola phones + * + * Copyright (C) 2009 Motorola, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Date Author Comment + * 01/07/2009 Motorola Initial version + */ + +#ifndef __ASMARM_BOOTINFO_H +#define __ASMARM_BOOTINFO_H + + +#if !defined(__KERNEL__) || defined(CONFIG_BOOTINFO) + +/* + * These #defines are used for the bits in powerup_reason. + */ +#define PU_REASON_USB_CABLE 0x00000010 /* Bit 4 */ +#define PU_REASON_FACTORY_CABLE 0x00000020 /* Bit 5 */ +#define PU_REASON_PWR_KEY_PRESS 0x00000080 /* Bit 7 */ +#define PU_REASON_CHARGER 0x00000100 /* Bit 8 */ +#define PU_REASON_POWER_CUT 0x00000200 /* bit 9 */ +#define PU_REASON_SW_AP_RESET 0x00004000 /* Bit 14 */ +#define PU_REASON_WDOG_AP_RESET 0x00008000 /* Bit 15 */ +#define PU_REASON_AP_KERNEL_PANIC 0x00020000 /* Bit 17 */ + + +/* + * These #defines are used for the battery status at boot. + * When no battery is present, the status is BATTERY_LO_VOLTAGE. + */ +#define BATTERY_GOOD_VOLTAGE 1 +#define BATTERY_LO_VOLTAGE 2 +#define BATTERY_UNKNOWN (-1) + +/* + * /proc/bootinfo has a strict format. Each line contains a name/value + * pair which are separated with a colon and a single space on both + * sides of the colon. The following defines help you size the + * buffers used to read the data from /proc/bootinfo. + * + * BOOTINFO_MAX_NAME_LEN: maximum size in bytes of a name in the + * bootinfo line. Don't forget to add space + * for the NUL if you need it. + * BOOTINFO_MAX_VAL_LEN: maximum size in bytes of a value in the + * bootinfo line. Don't forget to add space + * for the NUL if you need it. + * BOOTINFO_BUF_SIZE: size in bytes of buffer that is large enough + * to read a /proc/bootinfo line. The extra + * 3 is for the " : ". Don't forget to add + * space for the NUL and newline if you + * need them. + */ +#define BOOTINFO_MAX_NAME_LEN 32 +#define BOOTINFO_MAX_VAL_LEN 128 +#define BOOTINFO_BUF_SIZE (BOOTINFO_MAX_NAME_LEN + \ + 3 + BOOTINFO_MAX_VAL_LEN) + +#endif + + +#if defined(__KERNEL__) && defined(CONFIG_BOOTINFO) + +extern struct proc_dir_entry proc_root; + +u32 bi_powerup_reason(void); +void bi_set_powerup_reason(u32 powerup_reason); + +u32 bi_mbm_version(void); +void bi_set_mbm_version(u32 mbm_version); + +u32 bi_mbm_loader_version(void); +void bi_set_mbm_loader_version(u32 mbm_loader_version); + +u32 bi_flat_dev_tree_address(void); +void bi_set_flat_dev_tree_address(u32 flat_dev_tree_address); + +u16 bi_battery_status_at_boot(void); +void bi_set_battery_status_at_boot(u16 battery_status_at_boot); + +u32 bi_cid_recover_boot(void); +void bi_set_cid_recover_boot(u32 cid_recover_boot); + +#endif /* defined(__KERNEL__) && defined(CONFIG_BOOTINFO) */ + +#endif diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index 0b30ad47c..54a91c36b 100755 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -59,6 +59,7 @@ obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_HAVE_TCM) += tcm.o obj-$(CONFIG_OF) += devtree.o +obj-$(CONFIG_BOOTINFO) += bootinfo.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_SPRD_SYSDUMP) += sprd_sysdump.o obj-$(CONFIG_SWP_EMULATE) += swp_emulate.o diff --git a/arch/arm/kernel/bootinfo.c b/arch/arm/kernel/bootinfo.c new file mode 100644 index 000000000..6947feb42 --- /dev/null +++ b/arch/arm/kernel/bootinfo.c @@ -0,0 +1,326 @@ +/* + * bootinfo.c: This file contains the bootinfo code. This code + * provides boot information via /proc/bootinfo. The + * information currently includes: + * the powerup reason + * This file also provides EZX compatible interfaces for + * retrieving the powerup reason. All new user-space consumers + * of the powerup reason should use the /proc/bootinfo + * interface and all kernel-space consumers of the powerup + * reason should use the bi_powerup_reason interface. The EZX + * compatibility code is deprecated. + * + * + * Copyright (C) 2009 Motorola, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision History: + * + * Date Author Comment + * ---------- -------- ----------- + * 30/06/2009 Motorola Initialize version + */ + + +#ifdef CONFIG_BOOTINFO + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* + * EMIT_BOOTINFO and EMIT_BOOTINFO_STR are used to emit the bootinfo + * information for data provided via DEVICE TREE. + * + * The format for all bootinfo lines is "name : val" and these macros + * enforce that format. + * + * strname is the name printed in the name/val pair. + * name is the name of the function to call + * + * EMIT_BOOTINFO and EMIT_BOOTINFO_STR depend on buf and len to already + * be defined. + */ +#define EMIT_BOOTINFO(strname, fmt, name) \ + do { \ + seq_printf(m, strname " : " fmt "\n", \ + bi_##name()); \ + } while (0) + +#define EMIT_BOOTINFO_STR(strname, name) \ + do { \ + unsigned char *ptr; \ + ptr = (unsigned char *)bi_##name(); \ + if (strlen(ptr) == 0) { \ + seq_printf(m, strname \ + " : UNKNOWN\n"); \ + } else { \ + seq_printf(m, strname \ + " : %s\n", ptr); \ + } \ + } while (0) + +/*-------------------------------------------------------------------------*/ + +/* + * powerup_reason contains the powerup reason provided by the ATAGs when + * the machine boots. + * + * Exported symbols: + * bi_powerup_reason() -- returns the powerup reason + * bi_set_powerup_reason() -- sets the powerup reason + */ +static u32 powerup_reason; +u32 bi_powerup_reason(void) +{ + return powerup_reason; +} +EXPORT_SYMBOL(bi_powerup_reason); + +void bi_set_powerup_reason(u32 __powerup_reason) +{ + powerup_reason = __powerup_reason; +} +EXPORT_SYMBOL(bi_set_powerup_reason); + +#define EMIT_POWERUPREASON() \ + EMIT_BOOTINFO("POWERUPREASON", "0x%08x", powerup_reason) + + +/* + * mbm_version contains the MBM version. + * mbm_loader_version contains the MBM loader version. + * mbm_version and mbm_loader_version default to 0 if they are + * not set. + * + * Exported symbols: + * bi_mbm_version() -- returns the MBM version + * bi_set_mbm_version() -- sets the MBM version + * bi_mbm_loader_version() -- returns the MBM loader version + * bi_set_mbm_loader_version() -- sets the MBM loader version + */ +static u32 mbm_version; +u32 bi_mbm_version(void) +{ + return mbm_version; +} +EXPORT_SYMBOL(bi_mbm_version); + +void bi_set_mbm_version(u32 __mbm_version) +{ + mbm_version = __mbm_version; +} +EXPORT_SYMBOL(bi_set_mbm_version); + +static u32 mbm_loader_version; +u32 bi_mbm_loader_version(void) +{ + return mbm_loader_version; +} +EXPORT_SYMBOL(bi_mbm_loader_version); + +void bi_set_mbm_loader_version(u32 __mbm_loader_version) +{ + mbm_loader_version = __mbm_loader_version; +} +EXPORT_SYMBOL(bi_set_mbm_loader_version); + +#define EMIT_MBM_VERSION() \ + EMIT_BOOTINFO("MBM_VERSION", "0x%08x", mbm_version) +#define EMIT_MBM_LOADER_VERSION() \ + EMIT_BOOTINFO("MBM_LOADER_VERSION", "0x%08x", mbm_loader_version) + + +/* + * flat_dev_tree_address contains the Motorola flat dev tree address. + * flat_dev_tree_address defaults to -1 (0xffffffff) if it is not set. + * + * Exported symbols: + * bi_flat_dev_tree_address() -- returns the flat dev tree address + * bi_set_flat_dev_tree_address() -- sets the flat dev tree address + */ +static u32 flat_dev_tree_address = -1; +u32 bi_flat_dev_tree_address(void) +{ + return flat_dev_tree_address; +} +EXPORT_SYMBOL(bi_flat_dev_tree_address); + +void bi_set_flat_dev_tree_address(u32 __flat_dev_tree_address) +{ + flat_dev_tree_address = __flat_dev_tree_address; +} +EXPORT_SYMBOL(bi_set_flat_dev_tree_address); + +#define EMIT_FLAT_DEV_TREE_ADDRESS() \ + EMIT_BOOTINFO("FLAT_DEV_TREE_ADDRESS", "0x%08x", \ + flat_dev_tree_address) + + +/* + * battery_status_at_boot indicates the battery status + * when the machine started to boot. + * battery_status_at_boot defaults to -1 (0xffff) if the battery + * status can't be determined. + * + * Exported symbols: + * bi_battery_status_at_boot() -- returns the battery boot status + * bi_set_battery_status_at_boot() -- sets the battery boot status + */ +static u16 battery_status_at_boot = -1; +u16 bi_battery_status_at_boot(void) +{ + return battery_status_at_boot; +} +EXPORT_SYMBOL(bi_battery_status_at_boot); + +void bi_set_battery_status_at_boot(u16 __battery_status_at_boot) +{ + battery_status_at_boot = __battery_status_at_boot; +} +EXPORT_SYMBOL(bi_set_battery_status_at_boot); + +#define EMIT_BATTERY_STATUS_AT_BOOT() \ + EMIT_BOOTINFO("BATTERY_STATUS_AT_BOOT", "0x%04x", \ + battery_status_at_boot) + +/* + * cid_recover_boot contains the flag to indicate whether phone should + * boot into recover mode or not. + * cid_recover_boot defaults to 0 if it is not set. + * + * Exported symbols: + * bi_cid_recover_boot() -- returns the value of recover boot + * bi_set_cid_recover_boot() -- sets the value of recover boot + */ +static u32 cid_recover_boot; +u32 bi_cid_recover_boot(void) +{ + return cid_recover_boot; +} +EXPORT_SYMBOL(bi_cid_recover_boot); + +void bi_set_cid_recover_boot(u32 __cid_recover_boot) +{ + cid_recover_boot = __cid_recover_boot; +} +EXPORT_SYMBOL(bi_set_cid_recover_boot); + + +#define EMIT_CID_RECOVER_BOOT() \ + EMIT_BOOTINFO("CID_RECOVER_BOOT", "0x%04x", cid_recover_boot) + +/* System revision s global symbol exported by setup.c + * use wrapper to maintain coherent format with the other + * boot info elements + */ + +static u32 bi_hwrev(void) +{ + return system_rev; +} + +#define EMIT_HWREV() \ + EMIT_BOOTINFO("HW_REV", "0x%04x", hwrev) + +/* Serial high and low are symbols exported by setup.c + * use wrapper to maintain coherent format with the other + * boot info elements + */ + +static u64 bi_serial(void) +{ + return ((u64)system_serial_high << 32) + | (u64)system_serial_low; +} + +#define EMIT_SERIAL() \ + EMIT_BOOTINFO("SERIAL", "0x%llx", serial) + +/* get_bootinfo fills in the /proc/bootinfo information. + * We currently only have the powerup reason, mbm_version, serial + * and hwrevision. + */ + +static int get_bootinfo(struct seq_file *m, void *v) +{ + int len = 0; + + EMIT_SERIAL(); + EMIT_HWREV(); + EMIT_POWERUPREASON(); + EMIT_MBM_VERSION(); + EMIT_BATTERY_STATUS_AT_BOOT(); + EMIT_CID_RECOVER_BOOT(); + + return len; +} + +static int bootinfo_panic(struct notifier_block *this, + unsigned long event, void *ptr) +{ + printk(KERN_ERR "mbm_version=0x%08x", mbm_version); + return NOTIFY_DONE; +} + +static struct notifier_block panic_block = { + .notifier_call = bootinfo_panic, + .priority = 1, +}; + +static struct proc_dir_entry *proc_bootinfo; + +static int bootinfo_proc_open(struct inode *inode, struct file *file) { + return single_open(file, get_bootinfo, PDE_DATA(inode)); +} + +static const struct file_operations bootinfo_proc_fops = { + .open = bootinfo_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + +int __init bootinfo_init_module(void) +{ + proc_bootinfo = &proc_root; + if (!proc_create_data("bootinfo", 0, NULL, &bootinfo_proc_fops, NULL)) + printk(KERN_ERR "Failed to create bootinfo entry"); + atomic_notifier_chain_register(&panic_notifier_list, &panic_block); + return 0; +} + +void __exit bootinfo_cleanup_module(void) +{ + if (proc_bootinfo) { + remove_proc_entry("bootinfo", proc_bootinfo); + proc_bootinfo = NULL; + } +} + +module_init(bootinfo_init_module); +module_exit(bootinfo_cleanup_module); + +MODULE_AUTHOR("MOTOROLA"); +#endif /* CONFIG_BOOTINFO */ diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 633e11128..6b0b9ae11 100755 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -56,6 +56,9 @@ #include #include #include +#ifdef CONFIG_BOOTINFO +#include +#endif #include "atags.h"