aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/arm/SH-Mobile/Makefile8
-rw-r--r--Documentation/arm/SH-Mobile/vrl4.c169
-rw-r--r--Documentation/arm/SH-Mobile/zboot-rom-mmcif.txt29
-rw-r--r--arch/arm/Kconfig12
-rw-r--r--arch/arm/boot/compressed/Makefile13
-rw-r--r--arch/arm/boot/compressed/head-shmobile.S30
-rw-r--r--arch/arm/boot/compressed/mmcif-sh7372.c87
-rw-r--r--arch/arm/mach-shmobile/include/mach/mmcif-ap4eb.h29
-rw-r--r--arch/arm/mach-shmobile/include/mach/mmcif-mackerel.h39
-rw-r--r--arch/arm/mach-shmobile/include/mach/mmcif.h18
10 files changed, 433 insertions, 1 deletions
diff --git a/Documentation/arm/SH-Mobile/Makefile b/Documentation/arm/SH-Mobile/Makefile
new file mode 100644
index 000000000000..8771d832cf8c
--- /dev/null
+++ b/Documentation/arm/SH-Mobile/Makefile
@@ -0,0 +1,8 @@
1BIN := vrl4
2
3.PHONY: all
4all: $(BIN)
5
6.PHONY: clean
7clean:
8 rm -f *.o $(BIN)
diff --git a/Documentation/arm/SH-Mobile/vrl4.c b/Documentation/arm/SH-Mobile/vrl4.c
new file mode 100644
index 000000000000..e8a191358ad2
--- /dev/null
+++ b/Documentation/arm/SH-Mobile/vrl4.c
@@ -0,0 +1,169 @@
1/*
2 * vrl4 format generator
3 *
4 * Copyright (C) 2010 Simon Horman
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11/*
12 * usage: vrl4 < zImage > out
13 * dd if=out of=/dev/sdx bs=512 seek=1 # Write the image to sector 1
14 *
15 * Reads a zImage from stdin and writes a vrl4 image to stdout.
16 * In practice this means writing a padded vrl4 header to stdout followed
17 * by the zImage.
18 *
19 * The padding places the zImage at ALIGN bytes into the output.
20 * The vrl4 uses ALIGN + START_BASE as the start_address.
21 * This is where the mask ROM will jump to after verifying the header.
22 *
23 * The header sets copy_size to min(sizeof(zImage), MAX_BOOT_PROG_LEN) + ALIGN.
24 * That is, the mask ROM will load the padded header (ALIGN bytes)
25 * And then MAX_BOOT_PROG_LEN bytes of the image, or the entire image,
26 * whichever is smaller.
27 *
28 * The zImage is not modified in any way.
29 */
30
31#define _BSD_SOURCE
32#include <endian.h>
33#include <unistd.h>
34#include <stdint.h>
35#include <stdio.h>
36#include <errno.h>
37
38struct hdr {
39 uint32_t magic1;
40 uint32_t reserved1;
41 uint32_t magic2;
42 uint32_t reserved2;
43 uint16_t copy_size;
44 uint16_t boot_options;
45 uint32_t reserved3;
46 uint32_t start_address;
47 uint32_t reserved4;
48 uint32_t reserved5;
49 char reserved6[308];
50};
51
52#define DECLARE_HDR(h) \
53 struct hdr (h) = { \
54 .magic1 = htole32(0xea000000), \
55 .reserved1 = htole32(0x56), \
56 .magic2 = htole32(0xe59ff008), \
57 .reserved3 = htole16(0x1) }
58
59/* Align to 512 bytes, the MMCIF sector size */
60#define ALIGN_BITS 9
61#define ALIGN (1 << ALIGN_BITS)
62
63#define START_BASE 0xe55b0000
64
65/*
66 * With an alignment of 512 the header uses the first sector.
67 * There is a 128 sector (64kbyte) limit on the data loaded by the mask ROM.
68 * So there are 127 sectors left for the boot programme. But in practice
69 * Only a small portion of a zImage is needed, 16 sectors should be more
70 * than enough.
71 *
72 * Note that this sets how much of the zImage is copied by the mask ROM.
73 * The entire zImage is present after the header and is loaded
74 * by the code in the boot program (which is the first portion of the zImage).
75 */
76#define MAX_BOOT_PROG_LEN (16 * 512)
77
78#define ROUND_UP(x) ((x + ALIGN - 1) & ~(ALIGN - 1))
79
80ssize_t do_read(int fd, void *buf, size_t count)
81{
82 size_t offset = 0;
83 ssize_t l;
84
85 while (offset < count) {
86 l = read(fd, buf + offset, count - offset);
87 if (!l)
88 break;
89 if (l < 0) {
90 if (errno == EAGAIN || errno == EWOULDBLOCK)
91 continue;
92 perror("read");
93 return -1;
94 }
95 offset += l;
96 }
97
98 return offset;
99}
100
101ssize_t do_write(int fd, const void *buf, size_t count)
102{
103 size_t offset = 0;
104 ssize_t l;
105
106 while (offset < count) {
107 l = write(fd, buf + offset, count - offset);
108 if (l < 0) {
109 if (errno == EAGAIN || errno == EWOULDBLOCK)
110 continue;
111 perror("write");
112 return -1;
113 }
114 offset += l;
115 }
116
117 return offset;
118}
119
120ssize_t write_zero(int fd, size_t len)
121{
122 size_t i = len;
123
124 while (i--) {
125 const char x = 0;
126 if (do_write(fd, &x, 1) < 0)
127 return -1;
128 }
129
130 return len;
131}
132
133int main(void)
134{
135 DECLARE_HDR(hdr);
136 char boot_program[MAX_BOOT_PROG_LEN];
137 size_t aligned_hdr_len, alligned_prog_len;
138 ssize_t prog_len;
139
140 prog_len = do_read(0, boot_program, sizeof(boot_program));
141 if (prog_len <= 0)
142 return -1;
143
144 aligned_hdr_len = ROUND_UP(sizeof(hdr));
145 hdr.start_address = htole32(START_BASE + aligned_hdr_len);
146 alligned_prog_len = ROUND_UP(prog_len);
147 hdr.copy_size = htole16(aligned_hdr_len + alligned_prog_len);
148
149 if (do_write(1, &hdr, sizeof(hdr)) < 0)
150 return -1;
151 if (write_zero(1, aligned_hdr_len - sizeof(hdr)) < 0)
152 return -1;
153
154 if (do_write(1, boot_program, prog_len) < 0)
155 return 1;
156
157 /* Write out the rest of the kernel */
158 while (1) {
159 prog_len = do_read(0, boot_program, sizeof(boot_program));
160 if (prog_len < 0)
161 return 1;
162 if (prog_len == 0)
163 break;
164 if (do_write(1, boot_program, prog_len) < 0)
165 return 1;
166 }
167
168 return 0;
169}
diff --git a/Documentation/arm/SH-Mobile/zboot-rom-mmcif.txt b/Documentation/arm/SH-Mobile/zboot-rom-mmcif.txt
new file mode 100644
index 000000000000..efff8ae2713d
--- /dev/null
+++ b/Documentation/arm/SH-Mobile/zboot-rom-mmcif.txt
@@ -0,0 +1,29 @@
1ROM-able zImage boot from MMC
2-----------------------------
3
4An ROM-able zImage compiled with ZBOOT_ROM_MMCIF may be written to MMC and
5SuperH Mobile ARM will to boot directly from the MMCIF hardware block.
6
7This is achieved by the mask ROM loading the first portion of the image into
8MERAM and then jumping to it. This portion contains loader code which
9copies the entire image to SDRAM and jumps to it. From there the zImage
10boot code proceeds as normal, uncompressing the image into its final
11location and then jumping to it.
12
13This code has been tested on an AP4EB board using the developer 1A eMMC
14boot mode which is configured using the following jumper settings.
15The board used for testing required a patched mask ROM in order for
16this mode to function.
17
18 8 7 6 5 4 3 2 1
19 x|x|x|x|x| |x|
20S4 -+-+-+-+-+-+-+-
21 | | | | |x| |x on
22
23The zImage must be written to the MMC card at sector 1 (512 bytes) in
24vrl4 format. A utility vrl4 is supplied to accomplish this.
25
26e.g.
27 vrl4 < zImage | dd of=/dev/sdX bs=512 seek=1
28
29A dual-voltage MMC 4.0 card was used for testing.
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 5cff165b7eb0..2d0a1dc15994 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1619,6 +1619,18 @@ config ZBOOT_ROM
1619 Say Y here if you intend to execute your compressed kernel image 1619 Say Y here if you intend to execute your compressed kernel image
1620 (zImage) directly from ROM or flash. If unsure, say N. 1620 (zImage) directly from ROM or flash. If unsure, say N.
1621 1621
1622config ZBOOT_ROM_MMCIF
1623 bool "Include MMCIF loader in zImage (EXPERIMENTAL)"
1624 depends on ZBOOT_ROM && ARCH_SH7372 && EXPERIMENTAL
1625 help
1626 Say Y here to include experimental MMCIF loading code in the
1627 ROM-able zImage. With this enabled it is possible to write the
1628 the ROM-able zImage kernel image to an MMC card and boot the
1629 kernel straight from the reset vector. At reset the processor
1630 Mask ROM will load the first part of the the ROM-able zImage
1631 which in turn loads the rest the kernel image to RAM using the
1632 MMCIF hardware block.
1633
1622config CMDLINE 1634config CMDLINE
1623 string "Default kernel command string" 1635 string "Default kernel command string"
1624 default "" 1636 default ""
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 0a8f748e506a..198007d0a7ed 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -4,9 +4,20 @@
4# create a compressed vmlinuz image from the original vmlinux 4# create a compressed vmlinuz image from the original vmlinux
5# 5#
6 6
7OBJS =
8
9# Ensure that mmcif loader code appears early in the image
10# to minimise that number of bocks that have to be read in
11# order to load it.
12ifeq ($(CONFIG_ZBOOT_ROM_MMCIF),y)
13ifeq ($(CONFIG_ARCH_SH7372),y)
14OBJS += mmcif-sh7372.o
15endif
16endif
17
7AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET) 18AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET)
8HEAD = head.o 19HEAD = head.o
9OBJS = misc.o decompress.o 20OBJS += misc.o decompress.o
10FONTC = $(srctree)/drivers/video/console/font_acorn_8x8.c 21FONTC = $(srctree)/drivers/video/console/font_acorn_8x8.c
11 22
12# 23#
diff --git a/arch/arm/boot/compressed/head-shmobile.S b/arch/arm/boot/compressed/head-shmobile.S
index 30973b76e6ae..c943d2e7da9d 100644
--- a/arch/arm/boot/compressed/head-shmobile.S
+++ b/arch/arm/boot/compressed/head-shmobile.S
@@ -25,6 +25,36 @@
25 /* load board-specific initialization code */ 25 /* load board-specific initialization code */
26#include <mach/zboot.h> 26#include <mach/zboot.h>
27 27
28#ifdef CONFIG_ZBOOT_ROM_MMCIF
29 /* Load image from MMC */
30 adr sp, __tmp_stack + 128
31 ldr r0, __image_start
32 ldr r1, __image_end
33 subs r1, r1, r0
34 ldr r0, __load_base
35 bl mmcif_loader
36
37 /* Jump to loaded code */
38 ldr r0, __loaded
39 ldr r1, __image_start
40 sub r0, r0, r1
41 ldr r1, __load_base
42 add pc, r0, r1
43
44__image_start:
45 .long _start
46__image_end:
47 .long _got_end
48__load_base:
49 .long CONFIG_MEMORY_START + 0x02000000 @ Load at 32Mb into SDRAM
50__loaded:
51 .long __continue
52 .align
53__tmp_stack:
54 .space 128
55__continue:
56#endif /* CONFIG_ZBOOT_ROM_MMCIF */
57
28 b 1f 58 b 1f
29__atags:@ tag #1 59__atags:@ tag #1
30 .long 12 @ tag->hdr.size = tag_size(tag_core); 60 .long 12 @ tag->hdr.size = tag_size(tag_core);
diff --git a/arch/arm/boot/compressed/mmcif-sh7372.c b/arch/arm/boot/compressed/mmcif-sh7372.c
new file mode 100644
index 000000000000..e6180af241f6
--- /dev/null
+++ b/arch/arm/boot/compressed/mmcif-sh7372.c
@@ -0,0 +1,87 @@
1/*
2 * sh7372 MMCIF loader
3 *
4 * Copyright (C) 2010 Magnus Damm
5 * Copyright (C) 2010 Simon Horman
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/mmc/sh_mmcif.h>
13#include <mach/mmcif.h>
14
15#define MMCIF_BASE (void __iomem *)0xe6bd0000
16
17#define PORT84CR (void __iomem *)0xe6050054
18#define PORT85CR (void __iomem *)0xe6050055
19#define PORT86CR (void __iomem *)0xe6050056
20#define PORT87CR (void __iomem *)0xe6050057
21#define PORT88CR (void __iomem *)0xe6050058
22#define PORT89CR (void __iomem *)0xe6050059
23#define PORT90CR (void __iomem *)0xe605005a
24#define PORT91CR (void __iomem *)0xe605005b
25#define PORT92CR (void __iomem *)0xe605005c
26#define PORT99CR (void __iomem *)0xe6050063
27
28#define SMSTPCR3 (void __iomem *)0xe615013c
29
30/* SH7372 specific MMCIF loader
31 *
32 * loads the zImage from an MMC card starting from block 1.
33 *
34 * The image must be start with a vrl4 header and
35 * the zImage must start at offset 512 of the image. That is,
36 * at block 2 (=byte 1024) on the media
37 *
38 * Use the following line to write the vrl4 formated zImage
39 * to an MMC card
40 * # dd if=vrl4.out of=/dev/sdx bs=512 seek=1
41 */
42asmlinkage void mmcif_loader(unsigned char *buf, unsigned long len)
43{
44 mmcif_init_progress();
45 mmcif_update_progress(MMCIF_PROGRESS_ENTER);
46
47 /* Initialise MMC
48 * registers: PORT84CR-PORT92CR
49 * (MMCD0_0-MMCD0_7,MMCCMD0 Control)
50 * value: 0x04 - select function 4
51 */
52 __raw_writeb(0x04, PORT84CR);
53 __raw_writeb(0x04, PORT85CR);
54 __raw_writeb(0x04, PORT86CR);
55 __raw_writeb(0x04, PORT87CR);
56 __raw_writeb(0x04, PORT88CR);
57 __raw_writeb(0x04, PORT89CR);
58 __raw_writeb(0x04, PORT90CR);
59 __raw_writeb(0x04, PORT91CR);
60 __raw_writeb(0x04, PORT92CR);
61
62 /* Initialise MMC
63 * registers: PORT99CR (MMCCLK0 Control)
64 * value: 0x10 | 0x04 - enable output | select function 4
65 */
66 __raw_writeb(0x14, PORT99CR);
67
68 /* Enable clock to MMC hardware block */
69 __raw_writel(__raw_readl(SMSTPCR3) & ~(1 << 12), SMSTPCR3);
70
71 mmcif_update_progress(MMCIF_PROGRESS_INIT);
72
73 /* setup MMCIF hardware */
74 sh_mmcif_boot_init(MMCIF_BASE);
75
76 mmcif_update_progress(MMCIF_PROGRESS_LOAD);
77
78 /* load kernel via MMCIF interface */
79 sh_mmcif_boot_do_read(MMCIF_BASE, 2, /* Kernel is at block 2 */
80 (len + SH_MMCIF_BBS - 1) / SH_MMCIF_BBS, buf);
81
82
83 /* Disable clock to MMC hardware block */
84 __raw_writel(__raw_readl(SMSTPCR3) & (1 << 12), SMSTPCR3);
85
86 mmcif_update_progress(MMCIF_PROGRESS_DONE);
87}
diff --git a/arch/arm/mach-shmobile/include/mach/mmcif-ap4eb.h b/arch/arm/mach-shmobile/include/mach/mmcif-ap4eb.h
new file mode 100644
index 000000000000..a8d02be8d2b6
--- /dev/null
+++ b/arch/arm/mach-shmobile/include/mach/mmcif-ap4eb.h
@@ -0,0 +1,29 @@
1#ifndef MMCIF_AP4EB_H
2#define MMCIF_AP4EB_H
3
4#define PORT185CR (void __iomem *)0xe60520b9
5#define PORT186CR (void __iomem *)0xe60520ba
6#define PORT187CR (void __iomem *)0xe60520bb
7#define PORT188CR (void __iomem *)0xe60520bc
8
9#define PORTR191_160DR (void __iomem *)0xe6056014
10
11static inline void mmcif_init_progress(void)
12{
13 /* Initialise LEDS1-4
14 * registers: PORT185CR-PORT188CR (LED1-LED4 Control)
15 * value: 0x10 - enable output
16 */
17 __raw_writeb(0x10, PORT185CR);
18 __raw_writeb(0x10, PORT186CR);
19 __raw_writeb(0x10, PORT187CR);
20 __raw_writeb(0x10, PORT188CR);
21}
22
23static inline void mmcif_update_progress(int n)
24{
25 __raw_writel((__raw_readl(PORTR191_160DR) & ~(0xf << 25)) |
26 (1 << (25 + n)), PORTR191_160DR);
27}
28
29#endif /* MMCIF_AP4EB_H */
diff --git a/arch/arm/mach-shmobile/include/mach/mmcif-mackerel.h b/arch/arm/mach-shmobile/include/mach/mmcif-mackerel.h
new file mode 100644
index 000000000000..4b4f6949a868
--- /dev/null
+++ b/arch/arm/mach-shmobile/include/mach/mmcif-mackerel.h
@@ -0,0 +1,39 @@
1#ifndef MMCIF_MACKEREL_H
2#define MMCIF_MACKEREL_H
3
4#define PORT0CR (void __iomem *)0xe6051000
5#define PORT1CR (void __iomem *)0xe6051001
6#define PORT2CR (void __iomem *)0xe6051002
7#define PORT159CR (void __iomem *)0xe605009f
8
9#define PORTR031_000DR (void __iomem *)0xe6055000
10#define PORTL159_128DR (void __iomem *)0xe6054010
11
12static inline void mmcif_init_progress(void)
13{
14 /* Initialise LEDS0-3
15 * registers: PORT0CR-PORT2CR,PORT159CR (LED0-LED3 Control)
16 * value: 0x10 - enable output
17 */
18 __raw_writeb(0x10, PORT0CR);
19 __raw_writeb(0x10, PORT1CR);
20 __raw_writeb(0x10, PORT2CR);
21 __raw_writeb(0x10, PORT159CR);
22}
23
24static inline void mmcif_update_progress(int n)
25{
26 unsigned a = 0, b = 0;
27
28 if (n < 3)
29 a = 1 << n;
30 else
31 b = 1 << 31;
32
33 __raw_writel((__raw_readl(PORTR031_000DR) & ~0x7) | a,
34 PORTR031_000DR);
35 __raw_writel((__raw_readl(PORTL159_128DR) & ~(1 << 31)) | b,
36 PORTL159_128DR);
37}
38
39#endif /* MMCIF_MACKEREL_H */
diff --git a/arch/arm/mach-shmobile/include/mach/mmcif.h b/arch/arm/mach-shmobile/include/mach/mmcif.h
new file mode 100644
index 000000000000..f4dc3279cf03
--- /dev/null
+++ b/arch/arm/mach-shmobile/include/mach/mmcif.h
@@ -0,0 +1,18 @@
1#ifndef MMCIF_H
2#define MMCIF_H
3
4/**************************************************
5 *
6 * board specific settings
7 *
8 **************************************************/
9
10#ifdef CONFIG_MACH_AP4EVB
11#include "mach/mmcif-ap4eb.h"
12#elif CONFIG_MACH_MACKEREL
13#include "mach/mmcif-mackerel.h"
14#else
15#error "unsupported board."
16#endif
17
18#endif /* MMCIF_H */