Skip to content

Commit a769094

Browse files
committed
Blackfin: fix module reloc handling for all memory regions
The current module relocation code has spotty handling wrt different memory regions (like L1 instruction). Rather than try to fix each little spot, use the new common memory functions to greatly simplify everything and make sure it is always correct. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
1 parent 459fec9 commit a769094

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

‎arch/blackfin/kernel/module.c‎

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/kernel.h>
3838
#include <asm/dma.h>
3939
#include <asm/cacheflush.h>
40+
#include <asm/uaccess.h>
4041

4142
void *module_alloc(unsigned long size)
4243
{
@@ -199,26 +200,23 @@ apply_relocate(Elf_Shdr * sechdrs, const char *strtab,
199200
/* gas does not generate it. */
200201
/*************************************************************************/
201202
int
202-
apply_relocate_add(Elf_Shdr * sechdrs, const char *strtab,
203+
apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
203204
unsigned int symindex, unsigned int relsec,
204205
struct module *mod)
205206
{
206207
unsigned int i;
207-
unsigned short tmp;
208208
Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
209209
Elf32_Sym *sym;
210-
uint32_t *location32;
211-
uint16_t *location16;
212-
uint32_t value;
210+
unsigned long location, value, size;
213211

214212
pr_debug("applying relocate section %u to %u\n", mod->name,
215213
relsec, sechdrs[relsec].sh_info);
214+
216215
for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
217216
/* This is where to make the change */
218-
location16 =
219-
(uint16_t *) (sechdrs[sechdrs[relsec].sh_info].sh_addr +
220-
rel[i].r_offset);
221-
location32 = (uint32_t *) location16;
217+
location = sechdrs[sechdrs[relsec].sh_info].sh_addr +
218+
rel[i].r_offset;
219+
222220
/* This is the symbol it is referring to. Note that all
223221
undefined symbols have been resolved. */
224222
sym = (Elf32_Sym *) sechdrs[symindex].sh_addr
@@ -227,39 +225,28 @@ apply_relocate_add(Elf_Shdr * sechdrs, const char *strtab,
227225
value += rel[i].r_addend;
228226

229227
#ifdef CONFIG_SMP
230-
if ((unsigned long)location16 >= COREB_L1_DATA_A_START) {
228+
if (location >= COREB_L1_DATA_A_START) {
231229
pr_err("cannot relocate in L1: %u (SMP kernel)",
232230
mod->name, ELF32_R_TYPE(rel[i].r_info));
233231
return -ENOEXEC;
234232
}
235233
#endif
236234

237-
pr_debug("location is %lx, value is %x type is %d\n",
238-
mod->name, (unsigned long)location32, value,
239-
ELF32_R_TYPE(rel[i].r_info));
235+
pr_debug("location is %lx, value is %lx type is %d\n",
236+
mod->name, location, value, ELF32_R_TYPE(rel[i].r_info));
240237

241238
switch (ELF32_R_TYPE(rel[i].r_info)) {
242239

243-
case R_BFIN_LUIMM16:
244-
tmp = (value & 0xffff);
245-
if ((unsigned long)location16 >= L1_CODE_START) {
246-
dma_memcpy(location16, &tmp, 2);
247-
} else
248-
*location16 = tmp;
249-
break;
250240
case R_BFIN_HUIMM16:
251-
tmp = ((value >> 16) & 0xffff);
252-
if ((unsigned long)location16 >= L1_CODE_START) {
253-
dma_memcpy(location16, &tmp, 2);
254-
} else
255-
*location16 = tmp;
256-
break;
241+
value >>= 16;
242+
case R_BFIN_LUIMM16:
257243
case R_BFIN_RIMM16:
258-
*location16 = (value & 0xffff);
244+
size = 2;
259245
break;
260246
case R_BFIN_BYTE4_DATA:
261-
*location32 = value;
247+
size = 4;
262248
break;
249+
263250
case R_BFIN_PCREL24:
264251
case R_BFIN_PCREL24_JUMP_L:
265252
case R_BFIN_PCREL12_JUMP:
@@ -268,12 +255,31 @@ apply_relocate_add(Elf_Shdr * sechdrs, const char *strtab,
268255
pr_err("unsupported relocation: %u (no -mlong-calls?)\n",
269256
mod->name, ELF32_R_TYPE(rel[i].r_info));
270257
return -ENOEXEC;
258+
271259
default:
272260
pr_err("unknown relocation: %u\n", mod->name,
273261
ELF32_R_TYPE(rel[i].r_info));
274262
return -ENOEXEC;
275263
}
264+
265+
switch (bfin_mem_access_type(location, size)) {
266+
case BFIN_MEM_ACCESS_CORE:
267+
case BFIN_MEM_ACCESS_CORE_ONLY:
268+
memcpy((void *)location, &value, size);
269+
break;
270+
case BFIN_MEM_ACCESS_DMA:
271+
dma_memcpy((void *)location, &value, size);
272+
break;
273+
case BFIN_MEM_ACCESS_ITEST:
274+
isram_memcpy((void *)location, &value, size);
275+
break;
276+
default:
277+
pr_err("invalid relocation for %#lx\n",
278+
mod->name, location);
279+
return -ENOEXEC;
280+
}
276281
}
282+
277283
return 0;
278284
}
279285

0 commit comments

Comments
 (0)