kexec-tools: Introduce kexec-iomem.c and /proc/iomem parsing code This patch adds the new file kexec-iomem.c that implements code to parse /proc/iomem line-by-line. The following patches make use of this code - especially the Xen-code that use /proc/iomem to get crash note information.
Signed-off-by: Magnus Damm <[EMAIL PROTECTED]> --- kexec/Makefile | 1 kexec/kexec-iomem.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ kexec/kexec.h | 3 + 3 files changed, 97 insertions(+) --- 0001/kexec/Makefile +++ work/kexec/Makefile 2006-11-17 16:16:49.000000000 +0900 @@ -16,6 +16,7 @@ KEXEC_C_SRCS+= kexec/kexec-elf-exec.c KEXEC_C_SRCS+= kexec/kexec-elf-core.c KEXEC_C_SRCS+= kexec/kexec-elf-rel.c KEXEC_C_SRCS+= kexec/kexec-elf-boot.c +KEXEC_C_SRCS+= kexec/kexec-iomem.c KEXEC_C_SRCS+= kexec/crashdump.c KEXEC_C_GENERATED_SRCS+= $(PURGATORY_HEX_C) KEXEC_S_SRCS:= --- /dev/null +++ work/kexec/kexec-iomem.c 2006-11-17 16:19:27.000000000 +0900 @@ -0,0 +1,93 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <limits.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include "kexec.h" +#include "crashdump.h" + +static int kexec_iomem_for_each_line(char *match, + int (*callback)(void *data, + int nr, + char *str, + unsigned long base, + unsigned long length), + void *data) +{ + const char iomem[]= "/proc/iomem"; + char line[MAX_LINE]; + FILE *fp; + unsigned long long start, end, size; + char *str; + int consumed; + int count; + int nr = 0; + + fp = fopen(iomem, "r"); + if (!fp) + die("Cannot open /proc/iomem"); + + while(fgets(line, sizeof(line), fp) != 0) { + count = sscanf(line, "%Lx-%Lx : %n", &start, &end, &consumed); + if (count != 2) + continue; + str = line + consumed; + size = end - start + 1; + if (!match || memcmp(str, match, strlen(match)) == 0) { + if (callback + && callback(data, nr, str, start, size) < 0) { + break; + } + nr++; + } + } + + fclose(fp); + + return nr; +} + +static int kexec_iomem_single_callback(void *data, int nr, + char *str, + unsigned long base, + unsigned long length) +{ + struct memory_range *range = data; + + if (nr == 0) { + range->start = base; + range->end = base + length - 1; + } + + return 0; +} + +int kexec_iomem_single(char *str, uint64_t *start, uint64_t *end) +{ + struct memory_range range; + int ret; + + memset(&range, 0, sizeof(range)); + + ret = kexec_iomem_for_each_line(str, kexec_iomem_single_callback, + &range); + + if (ret == 1) { + if (start) + *start = range.start; + if (end) + *end = range.end; + + ret = 0; + } + else + ret = -1; + + return ret; +} --- 0001/kexec/kexec.h +++ work/kexec/kexec.h 2006-11-17 16:19:20.000000000 +0900 @@ -201,6 +201,9 @@ int arch_compat_trampoline(struct kexec_ void arch_update_purgatory(struct kexec_info *info); int is_crashkernel_mem_reserved(void); +int kexec_iomem_single(char *str, uint64_t *start, uint64_t *end); + + #define MAX_LINE 160 #ifdef DEBUG _______________________________________________ fastboot mailing list fastboot@lists.osdl.org https://lists.osdl.org/mailman/listinfo/fastboot