summaryrefslogtreecommitdiff
path: root/rbutil/mkimxboot/dualboot
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/mkimxboot/dualboot')
-rw-r--r--rbutil/mkimxboot/dualboot/Makefile33
-rw-r--r--rbutil/mkimxboot/dualboot/bin2c.c140
-rw-r--r--rbutil/mkimxboot/dualboot/dualboot.S39
-rw-r--r--rbutil/mkimxboot/dualboot/dualboot.lds16
4 files changed, 228 insertions, 0 deletions
diff --git a/rbutil/mkimxboot/dualboot/Makefile b/rbutil/mkimxboot/dualboot/Makefile
new file mode 100644
index 0000000000..fa5f341b6d
--- /dev/null
+++ b/rbutil/mkimxboot/dualboot/Makefile
@@ -0,0 +1,33 @@
1CC=gcc
2CROSS_PREFIX=arm-elf-eabi
3# Edit the following variables (plus copy/paste another set of rules) when
4# adding a new target. mkimxboot.c also needs to be edited to refer to these
5# new images.
6
7BOOTOBJS = dualboot_fuzeplus.o
8BOOTBINS = dualboot_fuzeplus.arm-bin
9
10all: ../dualboot.h ../dualboot.c
11
12# Dualboot bootloaders
13
14dualboot_fuzeplus.o: dualboot.S
15 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DSANSA_FUZEPLUS -c -o dualboot_fuzeplus.o dualboot.S
16
17# Rules for the ARM code embedded in mkamsboot - assemble, link, then extract
18# the binary code and finally convert to .h for building in mkamsboot
19
20%.arm-elf: %.o
21 $(CROSS_PREFIX)-ld -Tdualboot.lds -o $@ $<
22
23%.arm-bin: %.arm-elf
24 $(CROSS_PREFIX)-objcopy -O binary $< $@
25
26../dualboot.c ../dualboot.h: $(BOOTBINS) bin2c
27 ./bin2c ../dualboot $(BOOTBINS)
28
29bin2c: bin2c.c
30 $(CC) -o bin2c bin2c.c
31
32clean:
33 rm -f *~ bin2c $(BOOTBINS) $(BOOTOBJS)
diff --git a/rbutil/mkimxboot/dualboot/bin2c.c b/rbutil/mkimxboot/dualboot/bin2c.c
new file mode 100644
index 0000000000..b02af88a4d
--- /dev/null
+++ b/rbutil/mkimxboot/dualboot/bin2c.c
@@ -0,0 +1,140 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Dave Chapman
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdio.h>
23#include <string.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <unistd.h>
27#include <fcntl.h>
28#include <stdlib.h>
29#include <libgen.h>
30
31#ifndef O_BINARY
32#define O_BINARY 0
33#endif
34
35static off_t filesize(int fd)
36{
37 struct stat buf;
38
39 fstat(fd,&buf);
40 return buf.st_size;
41}
42
43static void write_cfile(const unsigned char* buf, off_t len, FILE* fp, const char *name)
44{
45 int i;
46
47 fprintf(fp,"unsigned char %s[%ld] = {",name,len);
48
49 for (i=0;i<len;i++) {
50 if ((i % 16) == 0) {
51 fprintf(fp,"\n ");
52 }
53 if (i == (len-1)) {
54 fprintf(fp,"0x%02x",buf[i]);
55 } else if ((i % 16) == 15) {
56 fprintf(fp,"0x%02x,",buf[i]);
57 } else {
58 fprintf(fp,"0x%02x, ",buf[i]);
59 }
60 }
61 fprintf(fp,"\n};\n");
62}
63
64int main (int argc, char* argv[])
65{
66 char* cname;
67 int i;
68 FILE *cfile, *hfile;
69 char cfilename[256], hfilename[256];
70
71 if (argc < 3) {
72 fprintf(stderr,"Usage: bin2c cname file1 [file2 [file3 ...]]\n");
73 return 1;
74 }
75
76 cname=argv[1];
77
78 snprintf(cfilename,256,"%s.c",cname);
79 cfile = fopen(cfilename,"w+");
80 if (cfile == NULL) {
81 fprintf(stderr,"Couldn't open %s\n",cfilename);
82 return 2;
83 }
84
85 snprintf(hfilename,256,"%s.h",cname);
86 hfile = fopen(hfilename,"w+");
87 if (hfile == NULL) {
88 fprintf(stderr,"Couldn't open %s\n",hfilename);
89 fclose(cfile);
90 return 3;
91 }
92
93 fprintf(cfile,"/* Generated by bin2c */\n\n");
94 fprintf(cfile,"#include \"%s\"\n\n", basename(hfilename));
95 fprintf(hfile,"/* Generated by bin2c */\n\n");
96
97 for(i=0; i < argc - 2; i++) {
98 unsigned char* buf;
99 off_t len;
100 off_t orig_len;
101 char *ext;
102 char *array = argv[2+i];
103
104 int fd = open(array,O_RDONLY|O_BINARY);
105 if (fd < 0) {
106 fprintf(stderr,"Can not open %s\n",argv[2+i]);
107 fclose(cfile);
108 fclose(hfile);
109 return 4;
110 }
111
112 orig_len = filesize(fd);
113 /* pad to 32bit */
114 len = (orig_len + 3) & ~3;
115
116 buf = malloc(len);
117 if (read(fd,buf,orig_len) < orig_len) {
118 fprintf(stderr,"Short read, aborting\n");
119 return 5;
120 }
121
122 /* pad to 32bit with zeros */
123 if (len > orig_len)
124 memset(buf+orig_len, 0, len-orig_len);
125
126 /* remove file extension */
127 ext = strchr (array, '.');
128 if (ext != NULL)
129 *ext = '\0';
130 write_cfile (buf, len, cfile, array);
131 fprintf(hfile,"extern unsigned char %s[%ld];\n",array,len);
132
133 close(fd);
134 }
135
136 fclose(cfile);
137 fclose(hfile);
138
139 return 0;
140}
diff --git a/rbutil/mkimxboot/dualboot/dualboot.S b/rbutil/mkimxboot/dualboot/dualboot.S
new file mode 100644
index 0000000000..8302829a81
--- /dev/null
+++ b/rbutil/mkimxboot/dualboot/dualboot.S
@@ -0,0 +1,39 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22.text
23.global start
24@ int start(uint32_t arg, uint32_t *result_id)
25start:
26#if defined(SANSA_FUZEPLUS)
27 /* If volume down key is hold, return so that the OF can boot */
28 ldr r2, =0x80018610 @ HW_PINCTRL_DIN1
29 ldr r2, [r2]
30 tst r2, #0x40000000 @ bit 30, active low
31 moveq r0, #0 @ return 0, continue boot
32 bxeq lr
33 /* otherwise jump to section given as argument */
34 str r0, [r1]
35 mov r0, #1
36 bx lr
37#else
38#error No target defined !
39#endif
diff --git a/rbutil/mkimxboot/dualboot/dualboot.lds b/rbutil/mkimxboot/dualboot/dualboot.lds
new file mode 100644
index 0000000000..caaff1a41d
--- /dev/null
+++ b/rbutil/mkimxboot/dualboot/dualboot.lds
@@ -0,0 +1,16 @@
1ENTRY(start)
2OUTPUT_FORMAT(elf32-littlearm)
3OUTPUT_ARCH(arm)
4
5MEMORY
6{
7 OCRAM : ORIGIN = 0, LENGTH = 0x8000
8}
9
10SECTIONS
11{
12 .text 0 :
13 {
14 *(.text*)
15 } > OCRAM
16}