soc: qcom: minidump: move elf global variables to structure
Current driver implementation uses global variables to create minidump elf header. Move all elf global variables into a structure, and also replace 'msm_minidump_enabled' API with 'minidump_enabled' global variable. And also add minidump_table address in elf, which would be useful for parsers to get memory dump table addresses without vmlinux symbols. Change-Id: I8829d88ce234179f429ae9537a3582df794c2cdf Signed-off-by: Lingutla Chandrasekhar <clingutla@codeaurora.org>
This commit is contained in:
parent
6437df9e5d
commit
198c5bc334
3 changed files with 80 additions and 61 deletions
|
@ -497,7 +497,7 @@ static size_t store_dload_mode(struct kobject *kobj, struct attribute *attr,
|
||||||
if (sysfs_streq(buf, "full")) {
|
if (sysfs_streq(buf, "full")) {
|
||||||
dload_type = SCM_DLOAD_FULLDUMP;
|
dload_type = SCM_DLOAD_FULLDUMP;
|
||||||
} else if (sysfs_streq(buf, "mini")) {
|
} else if (sysfs_streq(buf, "mini")) {
|
||||||
if (!msm_minidump_enabled()) {
|
if (!minidump_enabled) {
|
||||||
pr_err("Minidump is not enabled\n");
|
pr_err("Minidump is not enabled\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,24 +62,31 @@ struct md_table {
|
||||||
struct md_region entry[MAX_NUM_ENTRIES];
|
struct md_region entry[MAX_NUM_ENTRIES];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* md_elfhdr: Minidump table elf header
|
||||||
|
* @md_ehdr: elf main header
|
||||||
|
* @shdr: Section header
|
||||||
|
* @phdr: Program header
|
||||||
|
* @elf_offset: section offset in elf
|
||||||
|
* @strtable_idx: string table current index position
|
||||||
|
*/
|
||||||
|
struct md_elfhdr {
|
||||||
|
struct elfhdr *md_ehdr;
|
||||||
|
struct elf_shdr *shdr;
|
||||||
|
struct elf_phdr *phdr;
|
||||||
|
u64 elf_offset;
|
||||||
|
u64 strtable_idx;
|
||||||
|
};
|
||||||
|
|
||||||
/* Protect elfheader and smem table from deferred calls contention */
|
/* Protect elfheader and smem table from deferred calls contention */
|
||||||
static DEFINE_SPINLOCK(mdt_lock);
|
static DEFINE_SPINLOCK(mdt_lock);
|
||||||
static bool minidump_enabled;
|
|
||||||
static struct md_table minidump_table;
|
static struct md_table minidump_table;
|
||||||
|
static struct md_elfhdr minidump_elfheader;
|
||||||
|
|
||||||
|
bool minidump_enabled;
|
||||||
static unsigned int pendings;
|
static unsigned int pendings;
|
||||||
static unsigned int region_idx = 1; /* First entry is ELF header*/
|
static unsigned int region_idx = 1; /* First entry is ELF header*/
|
||||||
|
|
||||||
/* ELF Header */
|
|
||||||
static struct elfhdr *md_ehdr;
|
|
||||||
/* ELF Program header */
|
|
||||||
static struct elf_phdr *phdr;
|
|
||||||
/* ELF Section header */
|
|
||||||
static struct elf_shdr *shdr;
|
|
||||||
/* Section offset in elf image */
|
|
||||||
static u64 elf_offset;
|
|
||||||
/* String table index, first byte must be '\0' */
|
|
||||||
static unsigned int stringtable_idx = 1;
|
|
||||||
|
|
||||||
static inline struct elf_shdr *elf_sheader(struct elfhdr *hdr)
|
static inline struct elf_shdr *elf_sheader(struct elfhdr *hdr)
|
||||||
{
|
{
|
||||||
return (struct elf_shdr *)((size_t)hdr + (size_t)hdr->e_shoff);
|
return (struct elf_shdr *)((size_t)hdr + (size_t)hdr->e_shoff);
|
||||||
|
@ -90,6 +97,16 @@ static inline struct elf_shdr *elf_section(struct elfhdr *hdr, int idx)
|
||||||
return &elf_sheader(hdr)[idx];
|
return &elf_sheader(hdr)[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct elf_phdr *elf_pheader(struct elfhdr *hdr)
|
||||||
|
{
|
||||||
|
return (struct elf_phdr *)((size_t)hdr + (size_t)hdr->e_phoff);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct elf_phdr *elf_program(struct elfhdr *hdr, int idx)
|
||||||
|
{
|
||||||
|
return &elf_pheader(hdr)[idx];
|
||||||
|
}
|
||||||
|
|
||||||
static inline char *elf_str_table(struct elfhdr *hdr)
|
static inline char *elf_str_table(struct elfhdr *hdr)
|
||||||
{
|
{
|
||||||
if (hdr->e_shstrndx == SHN_UNDEF)
|
if (hdr->e_shstrndx == SHN_UNDEF)
|
||||||
|
@ -101,23 +118,24 @@ static inline char *elf_lookup_string(struct elfhdr *hdr, int offset)
|
||||||
{
|
{
|
||||||
char *strtab = elf_str_table(hdr);
|
char *strtab = elf_str_table(hdr);
|
||||||
|
|
||||||
if ((strtab == NULL) || (stringtable_idx < offset))
|
if ((strtab == NULL) || (minidump_elfheader.strtable_idx < offset))
|
||||||
return NULL;
|
return NULL;
|
||||||
return strtab + offset;
|
return strtab + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned int set_section_name(const char *name)
|
static inline unsigned int set_section_name(const char *name)
|
||||||
{
|
{
|
||||||
char *strtab = elf_str_table(md_ehdr);
|
char *strtab = elf_str_table(minidump_elfheader.md_ehdr);
|
||||||
|
int idx = minidump_elfheader.strtable_idx;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if ((strtab == NULL) || (name == NULL))
|
if ((strtab == NULL) || (name == NULL))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = stringtable_idx;
|
ret = idx;
|
||||||
stringtable_idx += strlcpy((strtab + stringtable_idx),
|
idx += strlcpy((strtab + idx), name, MAX_NAME_LENGTH);
|
||||||
name, MAX_NAME_LENGTH);
|
minidump_elfheader.strtable_idx = idx + 1;
|
||||||
stringtable_idx += 1;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,11 +155,9 @@ static inline bool md_check_name(const char *name)
|
||||||
static int md_update_smem_table(const struct md_region *entry)
|
static int md_update_smem_table(const struct md_region *entry)
|
||||||
{
|
{
|
||||||
struct md_smem_region *mdr;
|
struct md_smem_region *mdr;
|
||||||
|
struct elfhdr *hdr = minidump_elfheader.md_ehdr;
|
||||||
if (!minidump_enabled) {
|
struct elf_shdr *shdr = elf_section(hdr, hdr->e_shnum++);
|
||||||
pr_err("Table in smem is not setup\n");
|
struct elf_phdr *phdr = elf_program(hdr, hdr->e_phnum++);
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
mdr = &minidump_table.region[region_idx++];
|
mdr = &minidump_table.region[region_idx++];
|
||||||
|
|
||||||
|
@ -155,36 +171,21 @@ static int md_update_smem_table(const struct md_region *entry)
|
||||||
shdr->sh_addr = (elf_addr_t)entry->virt_addr;
|
shdr->sh_addr = (elf_addr_t)entry->virt_addr;
|
||||||
shdr->sh_size = mdr->size;
|
shdr->sh_size = mdr->size;
|
||||||
shdr->sh_flags = SHF_WRITE;
|
shdr->sh_flags = SHF_WRITE;
|
||||||
shdr->sh_offset = elf_offset;
|
shdr->sh_offset = minidump_elfheader.elf_offset;
|
||||||
shdr->sh_entsize = 0;
|
shdr->sh_entsize = 0;
|
||||||
|
|
||||||
phdr->p_type = PT_LOAD;
|
phdr->p_type = PT_LOAD;
|
||||||
phdr->p_offset = elf_offset;
|
phdr->p_offset = minidump_elfheader.elf_offset;
|
||||||
phdr->p_vaddr = entry->virt_addr;
|
phdr->p_vaddr = entry->virt_addr;
|
||||||
phdr->p_paddr = entry->phys_addr;
|
phdr->p_paddr = entry->phys_addr;
|
||||||
phdr->p_filesz = phdr->p_memsz = mdr->size;
|
phdr->p_filesz = phdr->p_memsz = mdr->size;
|
||||||
phdr->p_flags = PF_R | PF_W;
|
phdr->p_flags = PF_R | PF_W;
|
||||||
|
|
||||||
md_ehdr->e_shnum += 1;
|
minidump_elfheader.elf_offset += shdr->sh_size;
|
||||||
md_ehdr->e_phnum += 1;
|
|
||||||
elf_offset += shdr->sh_size;
|
|
||||||
shdr++;
|
|
||||||
phdr++;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool msm_minidump_enabled(void)
|
|
||||||
{
|
|
||||||
bool ret;
|
|
||||||
|
|
||||||
spin_lock(&mdt_lock);
|
|
||||||
ret = minidump_enabled;
|
|
||||||
spin_unlock(&mdt_lock);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL(msm_minidump_enabled);
|
|
||||||
|
|
||||||
int msm_minidump_add_region(const struct md_region *entry)
|
int msm_minidump_add_region(const struct md_region *entry)
|
||||||
{
|
{
|
||||||
u32 entries;
|
u32 entries;
|
||||||
|
@ -238,23 +239,32 @@ EXPORT_SYMBOL(msm_minidump_add_region);
|
||||||
static int msm_minidump_add_header(void)
|
static int msm_minidump_add_header(void)
|
||||||
{
|
{
|
||||||
struct md_smem_region *mdreg = &minidump_table.region[0];
|
struct md_smem_region *mdreg = &minidump_table.region[0];
|
||||||
char *banner;
|
struct elfhdr *md_ehdr;
|
||||||
|
struct elf_shdr *shdr;
|
||||||
|
struct elf_phdr *phdr;
|
||||||
unsigned int strtbl_off, elfh_size, phdr_off;
|
unsigned int strtbl_off, elfh_size, phdr_off;
|
||||||
|
char *banner;
|
||||||
|
|
||||||
|
/* Header buffer contains:
|
||||||
|
* elf header, MAX_NUM_ENTRIES+1 of section and program elf headers,
|
||||||
|
* string table section and linux banner.
|
||||||
|
*/
|
||||||
elfh_size = sizeof(*md_ehdr) + MAX_STRTBL_SIZE + MAX_MEM_LENGTH +
|
elfh_size = sizeof(*md_ehdr) + MAX_STRTBL_SIZE + MAX_MEM_LENGTH +
|
||||||
((sizeof(*shdr) + sizeof(*phdr)) * (MAX_NUM_ENTRIES + 1));
|
((sizeof(*shdr) + sizeof(*phdr)) * (MAX_NUM_ENTRIES + 1));
|
||||||
|
|
||||||
md_ehdr = kzalloc(elfh_size, GFP_KERNEL);
|
minidump_elfheader.md_ehdr = kzalloc(elfh_size, GFP_KERNEL);
|
||||||
if (!md_ehdr)
|
if (!minidump_elfheader.md_ehdr)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
strlcpy(mdreg->name, "KELF_HEADER", sizeof(mdreg->name));
|
strlcpy(mdreg->name, "KELF_HEADER", sizeof(mdreg->name));
|
||||||
mdreg->address = virt_to_phys(md_ehdr);
|
mdreg->address = virt_to_phys(minidump_elfheader.md_ehdr);
|
||||||
mdreg->size = elfh_size;
|
mdreg->size = elfh_size;
|
||||||
|
|
||||||
/* Section headers*/
|
md_ehdr = minidump_elfheader.md_ehdr;
|
||||||
shdr = (struct elf_shdr *)(md_ehdr + 1);
|
/* Assign section/program headers offset */
|
||||||
phdr = (struct elf_phdr *)(shdr + MAX_NUM_ENTRIES);
|
minidump_elfheader.shdr = shdr = (struct elf_shdr *)(md_ehdr + 1);
|
||||||
|
minidump_elfheader.phdr = phdr =
|
||||||
|
(struct elf_phdr *)(shdr + MAX_NUM_ENTRIES);
|
||||||
phdr_off = sizeof(*md_ehdr) + (sizeof(*shdr) * MAX_NUM_ENTRIES);
|
phdr_off = sizeof(*md_ehdr) + (sizeof(*shdr) * MAX_NUM_ENTRIES);
|
||||||
|
|
||||||
memcpy(md_ehdr->e_ident, ELFMAG, SELFMAG);
|
memcpy(md_ehdr->e_ident, ELFMAG, SELFMAG);
|
||||||
|
@ -268,18 +278,19 @@ static int msm_minidump_add_header(void)
|
||||||
md_ehdr->e_ehsize = sizeof(*md_ehdr);
|
md_ehdr->e_ehsize = sizeof(*md_ehdr);
|
||||||
md_ehdr->e_phoff = phdr_off;
|
md_ehdr->e_phoff = phdr_off;
|
||||||
md_ehdr->e_phentsize = sizeof(*phdr);
|
md_ehdr->e_phentsize = sizeof(*phdr);
|
||||||
md_ehdr->e_phnum = 1;
|
|
||||||
md_ehdr->e_shoff = sizeof(*md_ehdr);
|
md_ehdr->e_shoff = sizeof(*md_ehdr);
|
||||||
md_ehdr->e_shentsize = sizeof(*shdr);
|
md_ehdr->e_shentsize = sizeof(*shdr);
|
||||||
md_ehdr->e_shnum = 3; /* NULL, STR TABLE, Linux banner */
|
|
||||||
md_ehdr->e_shstrndx = 1;
|
md_ehdr->e_shstrndx = 1;
|
||||||
|
|
||||||
elf_offset = elfh_size;
|
minidump_elfheader.elf_offset = elfh_size;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First section header should be NULL,
|
||||||
|
* 2nd section is string table.
|
||||||
|
*/
|
||||||
|
minidump_elfheader.strtable_idx = 1;
|
||||||
strtbl_off = sizeof(*md_ehdr) +
|
strtbl_off = sizeof(*md_ehdr) +
|
||||||
((sizeof(*phdr) + sizeof(*shdr)) * MAX_NUM_ENTRIES);
|
((sizeof(*phdr) + sizeof(*shdr)) * MAX_NUM_ENTRIES);
|
||||||
/* First section header should be NULL
|
|
||||||
* 2nd entry for string table
|
|
||||||
*/
|
|
||||||
shdr++;
|
shdr++;
|
||||||
shdr->sh_type = SHT_STRTAB;
|
shdr->sh_type = SHT_STRTAB;
|
||||||
shdr->sh_offset = (elf_addr_t)strtbl_off;
|
shdr->sh_offset = (elf_addr_t)strtbl_off;
|
||||||
|
@ -289,7 +300,15 @@ static int msm_minidump_add_header(void)
|
||||||
shdr->sh_name = set_section_name("STR_TBL");
|
shdr->sh_name = set_section_name("STR_TBL");
|
||||||
shdr++;
|
shdr++;
|
||||||
|
|
||||||
/* 3rd entry for linux banner */
|
/* 3rd section is for minidump_table VA, used by parsers */
|
||||||
|
shdr->sh_type = SHT_PROGBITS;
|
||||||
|
shdr->sh_entsize = 0;
|
||||||
|
shdr->sh_flags = 0;
|
||||||
|
shdr->sh_addr = (elf_addr_t)&minidump_table;
|
||||||
|
shdr->sh_name = set_section_name("minidump_table");
|
||||||
|
shdr++;
|
||||||
|
|
||||||
|
/* 4th section is linux banner */
|
||||||
banner = (char *)md_ehdr + strtbl_off + MAX_STRTBL_SIZE;
|
banner = (char *)md_ehdr + strtbl_off + MAX_STRTBL_SIZE;
|
||||||
strlcpy(banner, linux_banner, MAX_MEM_LENGTH);
|
strlcpy(banner, linux_banner, MAX_MEM_LENGTH);
|
||||||
|
|
||||||
|
@ -300,7 +319,6 @@ static int msm_minidump_add_header(void)
|
||||||
shdr->sh_entsize = 0;
|
shdr->sh_entsize = 0;
|
||||||
shdr->sh_flags = SHF_WRITE;
|
shdr->sh_flags = SHF_WRITE;
|
||||||
shdr->sh_name = set_section_name("linux_banner");
|
shdr->sh_name = set_section_name("linux_banner");
|
||||||
shdr++;
|
|
||||||
|
|
||||||
phdr->p_type = PT_LOAD;
|
phdr->p_type = PT_LOAD;
|
||||||
phdr->p_offset = (elf_addr_t)(strtbl_off + MAX_STRTBL_SIZE);
|
phdr->p_offset = (elf_addr_t)(strtbl_off + MAX_STRTBL_SIZE);
|
||||||
|
@ -309,8 +327,9 @@ static int msm_minidump_add_header(void)
|
||||||
phdr->p_filesz = phdr->p_memsz = strlen(linux_banner) + 1;
|
phdr->p_filesz = phdr->p_memsz = strlen(linux_banner) + 1;
|
||||||
phdr->p_flags = PF_R | PF_W;
|
phdr->p_flags = PF_R | PF_W;
|
||||||
|
|
||||||
md_ehdr->e_phnum += 1;
|
/* Update headers count*/
|
||||||
phdr++;
|
md_ehdr->e_phnum = 1;
|
||||||
|
md_ehdr->e_shnum = 4;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct md_region {
|
||||||
*/
|
*/
|
||||||
#ifdef CONFIG_QCOM_MINIDUMP
|
#ifdef CONFIG_QCOM_MINIDUMP
|
||||||
extern int msm_minidump_add_region(const struct md_region *entry);
|
extern int msm_minidump_add_region(const struct md_region *entry);
|
||||||
extern bool msm_minidump_enabled(void);
|
extern bool minidump_enabled;
|
||||||
#else
|
#else
|
||||||
static inline int msm_minidump_add_region(const struct md_region *entry)
|
static inline int msm_minidump_add_region(const struct md_region *entry)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue