diff options
author | Mark A. Greer <mgreer@mvista.com> | 2007-03-27 18:29:50 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-04-12 13:55:16 -0400 |
commit | 88e687313e683ee006152d611b95f40900e3bce0 (patch) | |
tree | f4929de1202fb2f16bce5b5bfc144b60c7f9571b /arch | |
parent | 5e41763ae9b4b6335fab88da85600f16d7a5a7b5 (diff) |
[POWERPC] Move bootwrapper ELF parsing routines to a file
The ELF parsing routines local to arch/powerpc/boot/main.c are useful
to other callers therefore move them to their own file.
Signed-off-by: Mark A. Greer <mgreer@mvista.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/powerpc/boot/Makefile | 2 | ||||
-rw-r--r-- | arch/powerpc/boot/elf.h | 8 | ||||
-rw-r--r-- | arch/powerpc/boot/elf_util.c | 76 | ||||
-rw-r--r-- | arch/powerpc/boot/main.c | 66 |
4 files changed, 85 insertions, 67 deletions
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index fac6ed0c5bcd..be001d923d3f 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile | |||
@@ -42,7 +42,7 @@ $(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) \ | |||
42 | 42 | ||
43 | src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ | 43 | src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ |
44 | ns16550.c serial.c simple_alloc.c div64.S util.S \ | 44 | ns16550.c serial.c simple_alloc.c div64.S util.S \ |
45 | gunzip_util.c $(zlib) devtree.c | 45 | gunzip_util.c elf_util.c $(zlib) devtree.c |
46 | src-plat := of.c | 46 | src-plat := of.c |
47 | src-boot := $(src-wlib) $(src-plat) empty.c | 47 | src-boot := $(src-wlib) $(src-plat) empty.c |
48 | 48 | ||
diff --git a/arch/powerpc/boot/elf.h b/arch/powerpc/boot/elf.h index d4828fcf1cb9..1941bc50d4c5 100644 --- a/arch/powerpc/boot/elf.h +++ b/arch/powerpc/boot/elf.h | |||
@@ -146,4 +146,12 @@ typedef struct elf64_phdr { | |||
146 | #define ELFOSABI_NONE 0 | 146 | #define ELFOSABI_NONE 0 |
147 | #define ELFOSABI_LINUX 3 | 147 | #define ELFOSABI_LINUX 3 |
148 | 148 | ||
149 | struct elf_info { | ||
150 | unsigned long loadsize; | ||
151 | unsigned long memsize; | ||
152 | unsigned long elfoffset; | ||
153 | }; | ||
154 | int parse_elf64(void *hdr, struct elf_info *info); | ||
155 | int parse_elf32(void *hdr, struct elf_info *info); | ||
156 | |||
149 | #endif /* _PPC_BOOT_ELF_H_ */ | 157 | #endif /* _PPC_BOOT_ELF_H_ */ |
diff --git a/arch/powerpc/boot/elf_util.c b/arch/powerpc/boot/elf_util.c new file mode 100644 index 000000000000..7454aa4cc20c --- /dev/null +++ b/arch/powerpc/boot/elf_util.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * Copyright (C) Paul Mackerras 1997. | ||
3 | * | ||
4 | * Updates for PPC64 by Todd Inglett, Dave Engebretsen & Peter Bergner. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | #include <stdarg.h> | ||
12 | #include <stddef.h> | ||
13 | #include "elf.h" | ||
14 | #include "page.h" | ||
15 | #include "string.h" | ||
16 | #include "stdio.h" | ||
17 | |||
18 | int parse_elf64(void *hdr, struct elf_info *info) | ||
19 | { | ||
20 | Elf64_Ehdr *elf64 = hdr; | ||
21 | Elf64_Phdr *elf64ph; | ||
22 | unsigned int i; | ||
23 | |||
24 | if (!(elf64->e_ident[EI_MAG0] == ELFMAG0 && | ||
25 | elf64->e_ident[EI_MAG1] == ELFMAG1 && | ||
26 | elf64->e_ident[EI_MAG2] == ELFMAG2 && | ||
27 | elf64->e_ident[EI_MAG3] == ELFMAG3 && | ||
28 | elf64->e_ident[EI_CLASS] == ELFCLASS64 && | ||
29 | elf64->e_ident[EI_DATA] == ELFDATA2MSB && | ||
30 | elf64->e_type == ET_EXEC && | ||
31 | elf64->e_machine == EM_PPC64)) | ||
32 | return 0; | ||
33 | |||
34 | elf64ph = (Elf64_Phdr *)((unsigned long)elf64 + | ||
35 | (unsigned long)elf64->e_phoff); | ||
36 | for (i = 0; i < (unsigned int)elf64->e_phnum; i++, elf64ph++) | ||
37 | if (elf64ph->p_type == PT_LOAD) | ||
38 | break; | ||
39 | if (i >= (unsigned int)elf64->e_phnum) | ||
40 | return 0; | ||
41 | |||
42 | info->loadsize = (unsigned long)elf64ph->p_filesz; | ||
43 | info->memsize = (unsigned long)elf64ph->p_memsz; | ||
44 | info->elfoffset = (unsigned long)elf64ph->p_offset; | ||
45 | |||
46 | return 1; | ||
47 | } | ||
48 | |||
49 | int parse_elf32(void *hdr, struct elf_info *info) | ||
50 | { | ||
51 | Elf32_Ehdr *elf32 = hdr; | ||
52 | Elf32_Phdr *elf32ph; | ||
53 | unsigned int i; | ||
54 | |||
55 | if (!(elf32->e_ident[EI_MAG0] == ELFMAG0 && | ||
56 | elf32->e_ident[EI_MAG1] == ELFMAG1 && | ||
57 | elf32->e_ident[EI_MAG2] == ELFMAG2 && | ||
58 | elf32->e_ident[EI_MAG3] == ELFMAG3 && | ||
59 | elf32->e_ident[EI_CLASS] == ELFCLASS32 && | ||
60 | elf32->e_ident[EI_DATA] == ELFDATA2MSB && | ||
61 | elf32->e_type == ET_EXEC && | ||
62 | elf32->e_machine == EM_PPC)) | ||
63 | return 0; | ||
64 | |||
65 | elf32ph = (Elf32_Phdr *) ((unsigned long)elf32 + elf32->e_phoff); | ||
66 | for (i = 0; i < elf32->e_phnum; i++, elf32ph++) | ||
67 | if (elf32ph->p_type == PT_LOAD) | ||
68 | break; | ||
69 | if (i >= elf32->e_phnum) | ||
70 | return 0; | ||
71 | |||
72 | info->loadsize = elf32ph->p_filesz; | ||
73 | info->memsize = elf32ph->p_memsz; | ||
74 | info->elfoffset = elf32ph->p_offset; | ||
75 | return 1; | ||
76 | } | ||
diff --git a/arch/powerpc/boot/main.c b/arch/powerpc/boot/main.c index 03c0ccaecf29..30390621203d 100644 --- a/arch/powerpc/boot/main.c +++ b/arch/powerpc/boot/main.c | |||
@@ -36,76 +36,10 @@ struct addr_range { | |||
36 | unsigned long size; | 36 | unsigned long size; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | struct elf_info { | ||
40 | unsigned long loadsize; | ||
41 | unsigned long memsize; | ||
42 | unsigned long elfoffset; | ||
43 | }; | ||
44 | |||
45 | typedef void (*kernel_entry_t)(unsigned long, unsigned long, void *); | 39 | typedef void (*kernel_entry_t)(unsigned long, unsigned long, void *); |
46 | 40 | ||
47 | #undef DEBUG | 41 | #undef DEBUG |
48 | 42 | ||
49 | static int parse_elf64(void *hdr, struct elf_info *info) | ||
50 | { | ||
51 | Elf64_Ehdr *elf64 = hdr; | ||
52 | Elf64_Phdr *elf64ph; | ||
53 | unsigned int i; | ||
54 | |||
55 | if (!(elf64->e_ident[EI_MAG0] == ELFMAG0 && | ||
56 | elf64->e_ident[EI_MAG1] == ELFMAG1 && | ||
57 | elf64->e_ident[EI_MAG2] == ELFMAG2 && | ||
58 | elf64->e_ident[EI_MAG3] == ELFMAG3 && | ||
59 | elf64->e_ident[EI_CLASS] == ELFCLASS64 && | ||
60 | elf64->e_ident[EI_DATA] == ELFDATA2MSB && | ||
61 | elf64->e_type == ET_EXEC && | ||
62 | elf64->e_machine == EM_PPC64)) | ||
63 | return 0; | ||
64 | |||
65 | elf64ph = (Elf64_Phdr *)((unsigned long)elf64 + | ||
66 | (unsigned long)elf64->e_phoff); | ||
67 | for (i = 0; i < (unsigned int)elf64->e_phnum; i++, elf64ph++) | ||
68 | if (elf64ph->p_type == PT_LOAD) | ||
69 | break; | ||
70 | if (i >= (unsigned int)elf64->e_phnum) | ||
71 | return 0; | ||
72 | |||
73 | info->loadsize = (unsigned long)elf64ph->p_filesz; | ||
74 | info->memsize = (unsigned long)elf64ph->p_memsz; | ||
75 | info->elfoffset = (unsigned long)elf64ph->p_offset; | ||
76 | |||
77 | return 1; | ||
78 | } | ||
79 | |||
80 | static int parse_elf32(void *hdr, struct elf_info *info) | ||
81 | { | ||
82 | Elf32_Ehdr *elf32 = hdr; | ||
83 | Elf32_Phdr *elf32ph; | ||
84 | unsigned int i; | ||
85 | |||
86 | if (!(elf32->e_ident[EI_MAG0] == ELFMAG0 && | ||
87 | elf32->e_ident[EI_MAG1] == ELFMAG1 && | ||
88 | elf32->e_ident[EI_MAG2] == ELFMAG2 && | ||
89 | elf32->e_ident[EI_MAG3] == ELFMAG3 && | ||
90 | elf32->e_ident[EI_CLASS] == ELFCLASS32 && | ||
91 | elf32->e_ident[EI_DATA] == ELFDATA2MSB && | ||
92 | elf32->e_type == ET_EXEC && | ||
93 | elf32->e_machine == EM_PPC)) | ||
94 | return 0; | ||
95 | |||
96 | elf32ph = (Elf32_Phdr *) ((unsigned long)elf32 + elf32->e_phoff); | ||
97 | for (i = 0; i < elf32->e_phnum; i++, elf32ph++) | ||
98 | if (elf32ph->p_type == PT_LOAD) | ||
99 | break; | ||
100 | if (i >= elf32->e_phnum) | ||
101 | return 0; | ||
102 | |||
103 | info->loadsize = elf32ph->p_filesz; | ||
104 | info->memsize = elf32ph->p_memsz; | ||
105 | info->elfoffset = elf32ph->p_offset; | ||
106 | return 1; | ||
107 | } | ||
108 | |||
109 | static struct addr_range prep_kernel(void) | 43 | static struct addr_range prep_kernel(void) |
110 | { | 44 | { |
111 | char elfheader[256]; | 45 | char elfheader[256]; |