summaryrefslogtreecommitdiff
path: root/util/runfw/googlesnow.c
blob: 25ef3a2d022c1210a05629fb92cb5be707c0ee7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * googlesnow - run google snow firmware in user mode
 *
 * Copyright (C) 2013 The ChromiumOS Authors.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
 */

#include <stdio.h>
#include <err.h>
#include <sys/mman.h>

#include <string.h>

enum addresses {
	regs = 0x10000000,
	sram = 0x2020000,
	sramsize = 0x77fff,
};

// 0x20234b0
main(int argc, char *argv[])
{
	int fd;
	int devmem;
	void *regbase;
	void *srambase;
	void (*coreboot)(void) = (void *)0x2023400;

	if (argc != 3)
		errx(1, "usage: runbios rom-file start-address");

	fd = open(argv[1], 2);
	if (fd < 0)
		err(1, argv[1]);
	devmem = open("/dev/mem", 2);
	if (devmem < 0)
		err(1, argv[1]);
	srambase = mmap((void *)sram, sramsize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
	if (-1 == (int)sram)
		err(1, "mmap");
	memset((void *)sram, 0xff, sramsize);

	/* now sort of do what bl1 does: read the 'rom' into the sram */
	/* skip the bl1. We don't run it. */
	if (pread(fd, coreboot, 30*1024, 0x2000) < 30*1024)
		err(1, "read 'rom'");
	/* you want to be in gdb at this point. */
	coreboot = (void *) (strtoul(argv[2], 0, 0));
	coreboot();
}
#if 0
/* cc -g googlesnow.c */
/* typical run
gdb a.out
(gdb) list 50

45              i2c = mmap((void *)0x12c60000, 0x10000, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, devmem, (off_t) 0x12c60000);
46              if (-1 == (int)i2c)
47                      err(1, "mmap i2c");
48
49              /* now sort of do what bl1 does: read the 'rom' into the sram */
50              if (pread(fd, coreboot, 30*1024, 0x2000) < 30*1024)
51                      err(1, "read 'rom'");
52              /* you want to be in gdb at this point. */
53              coreboot = (void *) strtoull(argv[2], 0, 0);
54              coreboot();
(gdb) br 54
Breakpoint 3 at 0x8798: file runbios.c, line 54.
(gdb) run ~/coreboot/build/coreboot.rom  0x020234b0
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program: /root/coreboot/util/runarmbios/a.out ~/coreboot/build/coreboot.rom  0x020234b0

Breakpoint 3, main (argc=3, argv=0x7efff7c4) at runbios.c:54
54              coreboot();
(gdb) symbol-file ~/coreboot/build/cbfs/fallback/bootblock.debug 
Load new symbol table from "/root/coreboot/build/cbfs/fallback/bootblock.debug"? (y or n) y
Reading symbols from /root/coreboot/build/cbfs/fallback/bootblock.debug...done.
Error in re-setting breakpoint 3: No source file named runbios.c.
(gdb) display/i $pc
1: x/i $pc
=> 0x8798:      ldr     r3, [r11, #-8]
(gdb) stepi
0x0000879c in ?? ()
1: x/i $pc
=> 0x879c:      blx     r3
(gdb) 
0x020234b0 in call_bootblock ()
1: x/i $pc
=> 0x20234b0 <call_bootblock>:  ldr     sp, [pc, #3800] ; 0x2024390
(gdb) 
0x020234b4 in call_bootblock ()
1: x/i $pc
=> 0x20234b4 <call_bootblock+4>:        bic     sp, sp, #7
(gdb) 
0x020234b8 in call_bootblock ()
1: x/i $pc
=> 0x20234b8 <call_bootblock+8>:        mov     r0, #0
(gdb) 
0x020234bc in call_bootblock ()
1: x/i $pc
=> 0x20234bc <call_bootblock+12>:       blx     0x20244b8 <main>
(gdb) 
main (bist=0) at src/arch/armv7/bootblock_simple.c:37
37      {
1: x/i $pc
=> 0x20244b8 <main>:    push    {r3, lr}
(gdb) 
42                      bootblock_mainboard_init();
1: x/i $pc
=> 0x20244ba <main+2>:  bl      0x2023c08 <bootblock_mainboard_init>
(gdb) 
bootblock_mainboard_init () at src/mainboard/google/snow/bootblock.c:2124
2124    {
1: x/i $pc
=> 0x2023c08 <bootblock_mainboard_init>:        stmdb   sp!, {r4, r5, r6, r7, r9, r10, r11, lr}
(gdb) 
2127            i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
1: x/i $pc
=> 0x2023c0c <bootblock_mainboard_init+4>:      movs    r1, #0

Note you are now debugging source, and pretty much all commands work.
*/
#endif