Skip to content

Commit

Permalink
Fix DTB loading bug.
Browse files Browse the repository at this point in the history
Relocate boot parameters to a 'safe' location before booting to ensure none of it is corrupted.
  • Loading branch information
tangrs committed May 11, 2013
1 parent bd369a5 commit 0503ca6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,14 @@ void dump_settings(char * ignored __attribute__((unused))) {
printl("serialnr = 0x%x%x" NEWLINE, settings.serialnr[1], settings.serialnr[0]);

}

/* Standalone memcpy for when we can't have external dependencies */
void *builtin_memcpy(void *_dst, const void *_src, size_t size) {
const char *src = _src;
char *dst = _dst;

while (size--)
*dst++ = *src++;

return _dst;
}
2 changes: 2 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ void peek(char *arg);

void break_on_entry(char *arg);

void *builtin_memcpy(void *dst, const void *src, size_t size);

#endif
7 changes: 6 additions & 1 deletion kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "atag.h"
#include "fdt.h"

/* Where to relocate boot parameters? Defined as start of memory + 0x100 */
#define BOOT_PARAM_RELADDR ((char*)(settings.phys.start) + 0x100)

typedef void kentry(int, int, void*);

void kernel_cmdline(char * cmdline) {
Expand All @@ -49,6 +52,8 @@ void kernel_boot(char * ignored __attribute__((unused))) {
if(update_fdt()) return;
}

builtin_memcpy(BOOT_PARAM_RELADDR, settings.boot_param.start, settings.boot_param.size);

clear_cache();
/* Disable D-Cache and MMU */
asm volatile("mrc p15, 0, r0, c1, c0, 0 \n"
Expand All @@ -60,6 +65,6 @@ void kernel_boot(char * ignored __attribute__((unused))) {
asm volatile("bkpt #0");
}

entry(0, settings.machine_id, settings.boot_param.start);
entry(0, settings.machine_id, BOOT_PARAM_RELADDR);
__builtin_unreachable();
}

0 comments on commit 0503ca6

Please sign in to comment.