Skip to content

Commit

Permalink
factor out print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zonque committed Jul 26, 2013
1 parent aa1d8e3 commit 2a9b9b1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 31 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ start.o: start.S
main.o: main.c
$(GCC) $(CFLAGS) -c $^

print.o: print.c
$(GCC) $(CFLAGS) -c $^

zimage-in.o: $(ZIMAGE_IN)
$(OBJCOPY) -I binary -O $(BINFMT) -B arm $(ZIMAGE_IN) $@

dtb-in.o: $(DTB_IN)
$(OBJCOPY) -I binary -O $(BINFMT) -B arm $(DTB_IN) $@

matcher: start.o main.o zimage-in.o dtb-in.o
matcher: start.o main.o print.o zimage-in.o dtb-in.o
$(LD) $(LDFLAGS) -T matcher.lds -o matcher $^

matcher.bin: matcher
Expand Down
43 changes: 13 additions & 30 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
#include "types.h"
#include "atags.h"
#include "print.h"

static void putch(char c)
{
int i;
volatile __u32 *reg = (volatile __u32 *) 0x40100000;

*reg = c;

for (i = 0; i < 100; i++)
asm("nop");
}

static void putstr(const char *s)
{
while (*s) {
putch(*s);
if (*s == '\n')
putch('\r');
s++;
}
}

extern void *_binary____linux_arch_arm_boot_zImage_start;
extern void *_binary____linux_dtb_start;
extern __u32 _binary____linux_arch_arm_boot_zImage_start;
extern __u32 _binary____linux_dtb_start;

void init(__u32 dummy, __u32 machid, const struct tag *tags) __attribute__ ((noreturn));
void init(__u32 dummy, __u32 machid, const struct tag *tags)
{
int i;
__u32 system_rev = 0;
const struct tag *t;
void (*start_kernel)(__u32 dummy, __u32 machid, void *dtb);
void *zimage = _binary____linux_arch_arm_boot_zImage_start;
void *dtb = _binary____linux_dtb_start;
void (*start_kernel)(__u32 dummy, __u32 machid, void *dtb) __attribute__ ((noreturn));
void *zimage = &_binary____linux_arch_arm_boot_zImage_start;
void *dtb = &_binary____linux_dtb_start;

putstr("++ Impedance Matcher (3rd stage loader) ++\n");

Expand All @@ -45,10 +25,13 @@ void init(__u32 dummy, __u32 machid, const struct tag *tags)
}
}

putstr("Booting into Linux kernel ...\n");
putstr("Booting into Linux kernel @0x");
printhex((__u32) zimage);
putstr(" with DTB blob @0x");
printhex((__u32) dtb);
putstr("\n");

start_kernel = zimage;
start_kernel(dummy, 0xffff, 0);
//start_kernel(dummy, 0xffff, dtb);
start_kernel(0, 0xffff, dtb);
}

1 change: 1 addition & 0 deletions matcher.lds
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ SECTIONS {
. = 0xa0008000;
.text : { * (.text); }
.data : { * (.data); }
.rodata : { * (.rodata); }
}
38 changes: 38 additions & 0 deletions print.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "types.h"
#include "print.h"

void putch(char c)
{
int i;
volatile __u32 *reg = (volatile __u32 *) 0x40100000;

*reg = c;

for (i = 0; i < 100; i++)
asm("nop");
}

static const char hexdigets[] =
{ '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

void printhex(__u32 u)
{
int i;

for (i = 0; i < 8; i++) {
__u32 c = u >> (28 - (i * 4));
putch(hexdigets[c & 0xf]);
}
}

void putstr(const char *s)
{
while (*s) {
putch(*s);
if (*s == '\n')
putch('\r');
s++;
}
}

8 changes: 8 additions & 0 deletions print.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _PRINT_H
#define _PRINT_H

void putch(char c);
void printhex(__u32 u);
void putstr(const char *s);

#endif /* _PRINT_H */

0 comments on commit 2a9b9b1

Please sign in to comment.