|
@@ -27,6 +27,7 @@
|
27
|
27
|
#include <elf.h>
|
28
|
28
|
#include <gpxe/uaccess.h>
|
29
|
29
|
#include <gpxe/segment.h>
|
|
30
|
+#include <gpxe/image.h>
|
30
|
31
|
#include <gpxe/elf.h>
|
31
|
32
|
|
32
|
33
|
typedef Elf32_Ehdr Elf_Ehdr;
|
|
@@ -36,11 +37,11 @@ typedef Elf32_Off Elf_Off;
|
36
|
37
|
/**
|
37
|
38
|
* Load ELF segment into memory
|
38
|
39
|
*
|
39
|
|
- * @v elf ELF file
|
|
40
|
+ * @v image ELF file
|
40
|
41
|
* @v phdr ELF program header
|
41
|
42
|
* @ret rc Return status code
|
42
|
43
|
*/
|
43
|
|
-static int elf_load_segment ( struct elf *elf, Elf_Phdr *phdr ) {
|
|
44
|
+static int elf_load_segment ( struct image *image, Elf_Phdr *phdr ) {
|
44
|
45
|
physaddr_t dest;
|
45
|
46
|
userptr_t buffer;
|
46
|
47
|
int rc;
|
|
@@ -50,7 +51,7 @@ static int elf_load_segment ( struct elf *elf, Elf_Phdr *phdr ) {
|
50
|
51
|
return 0;
|
51
|
52
|
|
52
|
53
|
/* Check segment lies within image */
|
53
|
|
- if ( ( phdr->p_offset + phdr->p_filesz ) > elf->len ) {
|
|
54
|
+ if ( ( phdr->p_offset + phdr->p_filesz ) > image->len ) {
|
54
|
55
|
DBG ( "ELF segment outside ELF file\n" );
|
55
|
56
|
return -ENOEXEC;
|
56
|
57
|
}
|
|
@@ -81,7 +82,7 @@ static int elf_load_segment ( struct elf *elf, Elf_Phdr *phdr ) {
|
81
|
82
|
}
|
82
|
83
|
|
83
|
84
|
/* Copy image to segment */
|
84
|
|
- copy_user ( buffer, 0, elf->image, phdr->p_offset, phdr->p_filesz );
|
|
85
|
+ copy_user ( buffer, 0, image->data, phdr->p_offset, phdr->p_filesz );
|
85
|
86
|
|
86
|
87
|
return 0;
|
87
|
88
|
}
|
|
@@ -89,10 +90,10 @@ static int elf_load_segment ( struct elf *elf, Elf_Phdr *phdr ) {
|
89
|
90
|
/**
|
90
|
91
|
* Load ELF image into memory
|
91
|
92
|
*
|
92
|
|
- * @v elf ELF file
|
|
93
|
+ * @v image ELF file
|
93
|
94
|
* @ret rc Return status code
|
94
|
95
|
*/
|
95
|
|
-int elf_load ( struct elf *elf ) {
|
|
96
|
+int elf_load ( struct image *image ) {
|
96
|
97
|
Elf_Ehdr ehdr;
|
97
|
98
|
Elf_Phdr phdr;
|
98
|
99
|
Elf_Off phoff;
|
|
@@ -100,7 +101,7 @@ int elf_load ( struct elf *elf ) {
|
100
|
101
|
int rc;
|
101
|
102
|
|
102
|
103
|
/* Read ELF header */
|
103
|
|
- copy_from_user ( &ehdr, elf->image, 0, sizeof ( ehdr ) );
|
|
104
|
+ copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
|
104
|
105
|
if ( memcmp ( &ehdr.e_ident[EI_MAG0], ELFMAG, SELFMAG ) != 0 ) {
|
105
|
106
|
DBG ( "Invalid ELF signature\n" );
|
106
|
107
|
return -ENOEXEC;
|
|
@@ -109,18 +110,24 @@ int elf_load ( struct elf *elf ) {
|
109
|
110
|
/* Read ELF program headers */
|
110
|
111
|
for ( phoff = ehdr.e_phoff , phnum = ehdr.e_phnum ; phnum ;
|
111
|
112
|
phoff += ehdr.e_phentsize, phnum-- ) {
|
112
|
|
- if ( phoff > elf->len ) {
|
|
113
|
+ if ( phoff > image->len ) {
|
113
|
114
|
DBG ( "ELF program header %d outside ELF image\n",
|
114
|
115
|
phnum );
|
115
|
116
|
return -ENOEXEC;
|
116
|
117
|
}
|
117
|
|
- copy_from_user ( &phdr, elf->image, phoff, sizeof ( phdr ) );
|
118
|
|
- if ( ( rc = elf_load_segment ( elf, &phdr ) ) != 0 )
|
|
118
|
+ copy_from_user ( &phdr, image->data, phoff, sizeof ( phdr ) );
|
|
119
|
+ if ( ( rc = elf_load_segment ( image, &phdr ) ) != 0 )
|
119
|
120
|
return rc;
|
120
|
121
|
}
|
121
|
122
|
|
122
|
123
|
/* Fill in entry point address */
|
123
|
|
- elf->entry = ehdr.e_entry;
|
|
124
|
+ image->entry = ehdr.e_entry;
|
124
|
125
|
|
125
|
126
|
return 0;
|
126
|
127
|
}
|
|
128
|
+
|
|
129
|
+/** ELF image type */
|
|
130
|
+struct image_type elf_image_type __image_type = {
|
|
131
|
+ .name = "ELF",
|
|
132
|
+ .load = elf_load,
|
|
133
|
+};
|