Skip to content

Commit

Permalink
added support for board matching
Browse files Browse the repository at this point in the history
  • Loading branch information
zonque committed Jul 26, 2013
1 parent 2a9b9b1 commit c8e5040
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.bin
matcher
uImage
input/zImage
input/*.dtb
31 changes: 20 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@ LD=$(CROSS_COMPILE)ld
LOADADDR=0xa0008000
BINFMT=elf32-littlearm

INPUT_OBJS = \
zimage.o \
dtb-raumfeld-controller-0.o \
dtb-raumfeld-controller-1.o \
dtb-raumfeld-controller-2.o \
dtb-raumfeld-connector-0.o \
dtb-raumfeld-connector-1.o \
dtb-raumfeld-connector-2.o \
dtb-raumfeld-speaker-0.o \
dtb-raumfeld-speaker-1.o \
dtb-raumfeld-speaker-2.o

all: matcher.bin matcher.image

dtb-%.o: input/%.dtb
$(OBJCOPY) -I binary -O $(BINFMT) -B arm $^ $@

zimage.o: input/zImage
$(OBJCOPY) -I binary -O $(BINFMT) -B arm $^ $@

start.o: start.S
$(GCC) -c $^

main.o: main.c
%.o: %.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 print.o zimage-in.o dtb-in.o
matcher: start.o main.o print.o board.o $(INPUT_OBJS)
$(LD) $(LDFLAGS) -T matcher.lds -o matcher $^

matcher.bin: matcher
Expand Down
88 changes: 88 additions & 0 deletions board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "types.h"
#include "board.h"

extern __u32 _binary_input_zImage_start;
extern __u32 _binary_input_raumfeld_controller_0_dtb_start;
extern __u32 _binary_input_raumfeld_controller_1_dtb_start;
extern __u32 _binary_input_raumfeld_controller_2_dtb_start;
extern __u32 _binary_input_raumfeld_connector_0_dtb_start;
extern __u32 _binary_input_raumfeld_connector_1_dtb_start;
extern __u32 _binary_input_raumfeld_connector_2_dtb_start;
extern __u32 _binary_input_raumfeld_speaker_0_dtb_start;
extern __u32 _binary_input_raumfeld_speaker_1_dtb_start;
extern __u32 _binary_input_raumfeld_speaker_2_dtb_start;

static struct board boards[] = {
/* Controller */
{
.machid = 2413,
.system_rev = 0,
.dtb = &_binary_input_raumfeld_controller_0_dtb_start,
.name = "Raumfeld Controller, revision 0",
},
{
.machid = 2413,
.system_rev = 1,
.dtb = &_binary_input_raumfeld_controller_1_dtb_start,
.name = "Raumfeld Controller, revision 1",
},
{
.machid = 2413,
.system_rev = 2,
.dtb = &_binary_input_raumfeld_controller_2_dtb_start,
.name = "Raumfeld Controller, revision 2",
},

/* Controller */
{
.machid = 2414,
.system_rev = 0,
.dtb = &_binary_input_raumfeld_connector_0_dtb_start,
.name = "Raumfeld Connector, revision 0",
},
{
.machid = 2414,
.system_rev = 1,
.dtb = &_binary_input_raumfeld_connector_1_dtb_start,
.name = "Raumfeld Connector, revision 1",
},
{
.machid = 2414,
.system_rev = 2,
.dtb = &_binary_input_raumfeld_connector_2_dtb_start,
.name = "Raumfeld Connector, revision 2",
},

/* Speaker */
{
.machid = 2415,
.system_rev = 0,
.dtb = &_binary_input_raumfeld_speaker_0_dtb_start,
.name = "Raumfeld Speaker, revision 0",
},
{
.machid = 2415,
.system_rev = 1,
.dtb = &_binary_input_raumfeld_speaker_1_dtb_start,
.name = "Raumfeld Speaker, revision 1",
},
{
.machid = 2415,
.system_rev = 2,
.dtb = &_binary_input_raumfeld_speaker_2_dtb_start,
.name = "Raumfeld Speaker, revision 2",
},
{ 0, 0, NULL, NULL } /* sentinel */
};

struct board *match_board(__u32 machid, __u32 revision)
{
struct board *board;

for (board = boards; board->machid; board++)
if (board->machid == machid && board->system_rev == revision)
return board;

return NULL;
}

13 changes: 13 additions & 0 deletions board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _BOARD_H
#define _BOARD_H

struct board {
__u32 machid;
__u32 system_rev;
void *dtb;
const char *name;
};

struct board *match_board(__u32 machid, __u32 revision);

#endif
Empty file added input/.gitkeep
Empty file.
30 changes: 21 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "types.h"
#include "atags.h"
#include "print.h"
#include "board.h"

extern __u32 _binary____linux_arch_arm_boot_zImage_start;
extern __u32 _binary____linux_dtb_start;
extern __u32 _binary_input_zImage_start;

void init(__u32 dummy, __u32 machid, const struct tag *tags) __attribute__ ((noreturn));
void init(__u32 dummy, __u32 machid, const struct tag *tags)
{
__u32 system_rev = 0;
const struct tag *t;
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;
void *zimage = &_binary_input_zImage_start;
struct board *board = NULL;

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

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

putstr("Booting into Linux kernel @0x");
printhex((__u32) zimage);
putstr(" with DTB blob @0x");
printhex((__u32) dtb);
board = match_board(machid, system_rev & 0xff);
if (!board) {
putstr("ERROR MATCHING BOARD!\n");
putstr("MACHID: 0x");
printhex(machid);
putstr("\n");
putstr("SYSTEM_REV: 0x");
printhex(system_rev);
putstr("\n");
for(;;);
}

putstr("Detected board: ");
putstr(board->name);
putstr("\n");

putstr("Booting into Linux kernel ...\n");

start_kernel = zimage;
start_kernel(0, 0xffff, dtb);
start_kernel(0, 0xffff, board->dtb);
}

1 change: 1 addition & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define _TYPES_H

typedef unsigned int __u32;
#define NULL ((void *) 0)

#endif /* _TYPES_H */

0 comments on commit c8e5040

Please sign in to comment.