summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-07-07 17:34:04 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-07-07 17:36:21 +0200
commit03a4ba54815c634f57d5be1ebd44354b40c962dd (patch)
tree5f5287657acc29c858980a29f933126562a116fe
parent3afcb53fb94b7bb937147236f338dd89afb781d0 (diff)
downloadrockbox-03a4ba54815c634f57d5be1ebd44354b40c962dd.tar.gz
rockbox-03a4ba54815c634f57d5be1ebd44354b40c962dd.zip
mkimxboot: rewrite dualboot
Rewrite dualboot in C code instead of assembly. Also properly handle subtarget and simply Makefile. This should make the dualboot stub more readable and easier to extend. The new code also gracefully handles power up from RTC alarm on imx233. Change-Id: I7c225254b1463a97e76b6cb4de476aa2d2c9d2f9
-rw-r--r--rbutil/mkimxboot/dualboot.c50
-rw-r--r--rbutil/mkimxboot/dualboot.h6
-rw-r--r--rbutil/mkimxboot/dualboot/Makefile41
-rw-r--r--rbutil/mkimxboot/dualboot/dualboot.S118
-rw-r--r--rbutil/mkimxboot/dualboot/dualboot.c167
-rw-r--r--rbutil/mkimxboot/dualboot/dualboot.lds1
6 files changed, 222 insertions, 161 deletions
diff --git a/rbutil/mkimxboot/dualboot.c b/rbutil/mkimxboot/dualboot.c
index 20876d77b0..6f8f5c423d 100644
--- a/rbutil/mkimxboot/dualboot.c
+++ b/rbutil/mkimxboot/dualboot.c
@@ -2,28 +2,34 @@
2 2
3#include "dualboot.h" 3#include "dualboot.h"
4 4
5unsigned char dualboot_fuzeplus[152] = { 5unsigned char dualboot_fuzeplus[228] = {
6 0x78, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 0x01, 0x01, 0x12, 0xe3, 0x00, 0x00, 0xa0, 0x03, 6 0x10, 0x40, 0x2d, 0xe9, 0x00, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x30, 0x00, 0x2d, 0xe9,
7 0x1e, 0xff, 0x2f, 0x01, 0x70, 0x40, 0x2d, 0xe9, 0x64, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 7 0x01, 0x50, 0xa0, 0xe1, 0xb4, 0x30, 0x9f, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x3f, 0x34, 0x03, 0xe2,
8 0x02, 0x21, 0xa0, 0xe1, 0x22, 0x2d, 0xa0, 0xe1, 0x20, 0x00, 0x12, 0xe3, 0x0c, 0x00, 0x00, 0x1a, 8 0x23, 0x3c, 0xa0, 0xe1, 0x20, 0x00, 0x13, 0xe3, 0x01, 0x30, 0xa0, 0x13, 0x02, 0x00, 0x00, 0x1a,
9 0x50, 0x20, 0x9f, 0xe5, 0x00, 0x40, 0xa0, 0xe3, 0x44, 0x30, 0x9f, 0xe5, 0x00, 0x30, 0x93, 0xe5, 9 0x10, 0x00, 0x13, 0xe3, 0x02, 0x30, 0xa0, 0x13, 0x00, 0x30, 0xa0, 0x03, 0x90, 0x20, 0x9f, 0xe5,
10 0x03, 0x35, 0xa0, 0xe1, 0x23, 0x3f, 0xa0, 0xe1, 0x01, 0x00, 0x53, 0xe3, 0x03, 0x40, 0x84, 0x00, 10 0x10, 0x26, 0x92, 0xe5, 0x01, 0x01, 0x12, 0xe3, 0x10, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x53, 0xe3,
11 0x01, 0x20, 0x52, 0xe2, 0xf7, 0xff, 0xff, 0x1a, 0x2c, 0x20, 0x9f, 0xe5, 0x02, 0x00, 0x54, 0xe1, 11 0x11, 0x00, 0x00, 0x1a, 0x03, 0x40, 0xa0, 0xe1, 0x70, 0x10, 0x9f, 0xe5, 0x74, 0xc0, 0x9f, 0xe5,
12 0x02, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x81, 0xe5, 0x01, 0x00, 0xa0, 0xe3, 0x70, 0x80, 0xbd, 0xe8, 12 0xc0, 0x20, 0x91, 0xe5, 0x03, 0x26, 0x02, 0xe2, 0x01, 0x06, 0x52, 0xe3, 0x01, 0x40, 0x84, 0x02,
13 0x18, 0x00, 0x9f, 0xe5, 0x18, 0x10, 0x9f, 0xe5, 0x00, 0x10, 0x80, 0xe5, 0xfb, 0xff, 0xff, 0xea, 13 0x01, 0x30, 0x83, 0xe2, 0x0c, 0x00, 0x53, 0xe1, 0xf8, 0xff, 0xff, 0x1a, 0x58, 0x30, 0x9f, 0xe5,
14 0x10, 0x86, 0x01, 0x80, 0xc0, 0x40, 0x04, 0x80, 0x70, 0x64, 0x08, 0x00, 0x80, 0x1a, 0x06, 0x00, 14 0x03, 0x00, 0x54, 0xe1, 0x04, 0x00, 0x00, 0xca, 0x06, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea,
15 0x00, 0x41, 0x04, 0x80, 0x01, 0x00, 0x77, 0x3e 15 0x00, 0x00, 0xa0, 0xe3, 0x30, 0x00, 0xbd, 0xe8, 0x1e, 0xff, 0x2f, 0xe1, 0x00, 0x00, 0x85, 0xe5,
16 0x01, 0x00, 0xa0, 0xe3, 0xfa, 0xff, 0xff, 0xea, 0x24, 0x30, 0x9f, 0xe5, 0x03, 0x27, 0xa0, 0xe3,
17 0x04, 0x21, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x00, 0x27, 0x83, 0xe5, 0x00, 0x25, 0x83, 0xe5,
18 0x18, 0x20, 0x9f, 0xe5, 0x0b, 0x39, 0x83, 0xe2, 0x00, 0x21, 0x83, 0xe5, 0xee, 0xff, 0xff, 0xea,
19 0x00, 0x40, 0x04, 0x80, 0x00, 0x80, 0x01, 0x80, 0x70, 0x64, 0x08, 0x00, 0x7f, 0x1a, 0x06, 0x00,
20 0x01, 0x00, 0xff, 0xff
16}; 21};
17unsigned char dualboot_zenxfi2[92] = { 22unsigned char dualboot_zenxfi2[96] = {
18 0x4c, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 0x02, 0x21, 0xa0, 0xe1, 0x22, 0x2d, 0xa0, 0xe1, 23 0x10, 0x40, 0x2d, 0xe9, 0x00, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x44, 0x30, 0x9f, 0xe5,
19 0x20, 0x00, 0x12, 0xe3, 0x06, 0x00, 0x00, 0x0a, 0x34, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 24 0xc0, 0x30, 0x93, 0xe5, 0x02, 0x02, 0x13, 0xe3, 0x04, 0x00, 0x00, 0x1a, 0x38, 0x30, 0x9f, 0xe5,
20 0x02, 0x25, 0xa0, 0xe1, 0x22, 0x2f, 0xa0, 0xe1, 0x01, 0x00, 0x52, 0xe3, 0x00, 0x00, 0xa0, 0x03, 25 0x00, 0x36, 0x93, 0xe5, 0x01, 0x09, 0x13, 0xe3, 0x08, 0x00, 0x00, 0x0a, 0x04, 0x00, 0x00, 0xea,
21 0x03, 0x00, 0x00, 0xea, 0x1c, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 0x01, 0x09, 0x12, 0xe3, 26 0x20, 0x30, 0x9f, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x03, 0x36, 0x03, 0xe2, 0x01, 0x06, 0x53, 0xe3,
22 0x00, 0x00, 0xa0, 0x03, 0x1e, 0xff, 0x2f, 0x01, 0x00, 0x00, 0x81, 0xe5, 0x01, 0x00, 0xa0, 0xe3, 27 0x02, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x81, 0xe5, 0x01, 0x00, 0xa0, 0xe3, 0x1e, 0xff, 0x2f, 0xe1,
23 0x1e, 0xff, 0x2f, 0xe1, 0xc0, 0x40, 0x04, 0x80, 0x00, 0x86, 0x01, 0x80 28 0x00, 0x00, 0xa0, 0xe3, 0x1e, 0xff, 0x2f, 0xe1, 0x00, 0x40, 0x04, 0x80, 0x00, 0x80, 0x01, 0x80
24}; 29};
25unsigned char dualboot_zenxfi3[36] = { 30unsigned char dualboot_zenxfi3[56] = {
26 0x18, 0x20, 0x9f, 0xe5, 0x00, 0x20, 0x92, 0xe5, 0x80, 0x00, 0x12, 0xe3, 0x00, 0x00, 0xa0, 0x03, 31 0x10, 0x40, 0x2d, 0xe9, 0x00, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x1c, 0x30, 0x9f, 0xe5,
27 0x1e, 0xff, 0x2f, 0x01, 0x00, 0x00, 0x81, 0xe5, 0x01, 0x00, 0xa0, 0xe3, 0x1e, 0xff, 0x2f, 0xe1, 32 0xc0, 0x30, 0x93, 0xe5, 0x18, 0x30, 0x9f, 0xe5, 0x20, 0x36, 0x93, 0xe5, 0x80, 0x00, 0x13, 0xe3,
28 0x20, 0x86, 0x01, 0x80 33 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0x81, 0x15, 0x01, 0x00, 0xa0, 0x13, 0x1e, 0xff, 0x2f, 0xe1,
34 0x00, 0x40, 0x04, 0x80, 0x00, 0x80, 0x01, 0x80
29}; 35};
diff --git a/rbutil/mkimxboot/dualboot.h b/rbutil/mkimxboot/dualboot.h
index eff50cc6c5..8ebde559f5 100644
--- a/rbutil/mkimxboot/dualboot.h
+++ b/rbutil/mkimxboot/dualboot.h
@@ -1,5 +1,5 @@
1/* Generated by bin2c */ 1/* Generated by bin2c */
2 2
3extern unsigned char dualboot_fuzeplus[152]; 3extern unsigned char dualboot_fuzeplus[228];
4extern unsigned char dualboot_zenxfi2[92]; 4extern unsigned char dualboot_zenxfi2[96];
5extern unsigned char dualboot_zenxfi3[36]; 5extern unsigned char dualboot_zenxfi3[56];
diff --git a/rbutil/mkimxboot/dualboot/Makefile b/rbutil/mkimxboot/dualboot/Makefile
index 6386b7c622..4bad3a4a12 100644
--- a/rbutil/mkimxboot/dualboot/Makefile
+++ b/rbutil/mkimxboot/dualboot/Makefile
@@ -1,33 +1,38 @@
1CC=gcc 1CC=gcc
2CROSS_PREFIX=arm-elf-eabi 2LD=ld
3# Edit the following variables (plus copy/paste another set of rules) when 3OC=objcopy
4# adding a new target. mkimxboot.c also needs to be edited to refer to these 4CROSS_PREFIX=arm-elf-eabi-
5# new images. 5REGS_PATH=../../../firmware/target/arm/imx233/regs
6 6CFLAGS=-mcpu=arm926ej-s -std=gnu99 -I. -I$(REGS_PATH) -nostdlib -ffreestanding -fomit-frame-pointer -O
7BOOTOBJS = dualboot_fuzeplus.o dualboot_zenxfi2.o dualboot_zenxfi3.o 7# Edit the following variables when adding a new target.
8BOOTBINS = dualboot_fuzeplus.arm-bin dualboot_zenxfi2.arm-bin dualboot_zenxfi3.arm-bin 8# mkimxboot.c also needs to be edited to refer to these
9# To add a new target x you need to:
10# 1) add x to the list in TARGETS
11# 2) create a variable named OPT_x of the form:
12# OPT_x=target specific defines
13TARGETS=fuzeplus zenxfi2 zenxfi3
14OPT_fuzeplus=-DSANSA_FUZEPLUS -DIMX233_SUBTARGET=3780
15OPT_zenxfi2=-DCREATIVE_ZENXFI2 -DIMX233_SUBTARGET=3780
16OPT_zenxfi3=-DCREATIVE_ZENXFI3 -DIMX233_SUBTARGET=3780
17
18BOOTOBJS=$(patsubst %, dualboot_%.o, $(TARGETS))
19BOOTBINS=$(patsubst %, dualboot_%.arm-bin, $(TARGETS))
9 20
10all: ../dualboot.h ../dualboot.c 21all: ../dualboot.h ../dualboot.c
11 22
12# Dualboot bootloaders 23# Dualboot bootloaders
13 24
14dualboot_fuzeplus.o: dualboot.S 25dualboot_%.o: dualboot.c
15 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DSANSA_FUZEPLUS -c -o dualboot_fuzeplus.o dualboot.S 26 $(CROSS_PREFIX)$(CC) $(CFLAGS) $(OPT_$(@:dualboot_%.o=%)) -c -o $@ $^
16
17dualboot_zenxfi2.o: dualboot.S
18 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DCREATIVE_ZENXFI2 -c -o dualboot_zenxfi2.o dualboot.S
19 27
20dualboot_zenxfi3.o: dualboot.S 28dualboot_%.arm-elf: dualboot_%.o
21 $(CROSS_PREFIX)-$(CC) -mcpu=arm926ej-s -DCREATIVE_ZENXFI3 -c -o dualboot_zenxfi3.o dualboot.S 29 $(CROSS_PREFIX)$(LD) $(LDFLAGS) -Tdualboot.lds -o $@ $<
22 30
23# Rules for the ARM code embedded in mkamsboot - assemble, link, then extract 31# Rules for the ARM code embedded in mkamsboot - assemble, link, then extract
24# the binary code and finally convert to .h for building in mkamsboot 32# the binary code and finally convert to .h for building in mkamsboot
25 33
26%.arm-elf: %.o
27 $(CROSS_PREFIX)-ld -Tdualboot.lds -o $@ $<
28
29%.arm-bin: %.arm-elf 34%.arm-bin: %.arm-elf
30 $(CROSS_PREFIX)-objcopy -O binary $< $@ 35 $(CROSS_PREFIX)$(OC) -O binary $< $@
31 36
32../dualboot.c ../dualboot.h: $(BOOTBINS) bin2c 37../dualboot.c ../dualboot.h: $(BOOTBINS) bin2c
33 ./bin2c ../dualboot $(BOOTBINS) 38 ./bin2c ../dualboot $(BOOTBINS)
diff --git a/rbutil/mkimxboot/dualboot/dualboot.S b/rbutil/mkimxboot/dualboot/dualboot.S
deleted file mode 100644
index 0508f7e16a..0000000000
--- a/rbutil/mkimxboot/dualboot/dualboot.S
+++ /dev/null
@@ -1,118 +0,0 @@
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 /* save registers for the ROM */
34 stmfd sp!, {r4-r6,lr}
35 /* if the power source was 5v (ie usb), bypass the power button delay */
36 ldr r2, =0x800440c0 @ HW_POWER_STS
37 ldr r2, [r2]
38 mov r2, r2, lsl#2
39 mov r2, r2, lsr#26 @ extract PWRUP_SOURCE
40 tst r2, #0x20 @ bit 5: five volts
41 bne boot_rockbox
42 /* otherwise monitor the power button for a short time */
43 ldr r2, =550000 @ loop count
44 ldr r4, =0 @ number of times PSWITCH was 1
45pswitch_monitor_loop:
46 ldr r3, =0x800440c0 @ HW_POWER_STS
47 ldr r3, [r3]
48 mov r3, r3, lsl#10
49 mov r3, r3, lsr#30 @ extract PSWITCH
50 cmp r3, #1
51 addeq r4, r3 @ add one if PSWITCH=1 (means power hold)
52 subs r2, #1
53 bne pswitch_monitor_loop
54 /* power down if power wasn't hold long enough */
55 ldr r2, =400000
56 cmp r4, r2
57 bcc power_down
58 /* jump to section given as argument */
59boot_rockbox:
60 str r0, [r1]
61 mov r0, #1
62 ldmfd sp!, {r4-r6,pc}
63power_down:
64 ldr r0, =0x80044100 @ HW_POWER_RESET
65 ldr r1, =0x3E770001 @ unlock key + power down
66 str r1, [r0]
67 b power_down
68#elif defined(CREATIVE_ZENXFI2)
69 /* We are lacking buttons on the Zen X-Fi2 because on USB, the select button
70 * enters recovery mode ! So we can only use power but power is used to power up
71 * on normal boots and then select is free ! Thus use a non-uniform scheme:
72 * - normal boot:
73 * - no key: Rockbox
74 * - select: OF
75 * - USB boot:
76 * - no key: Rockbox
77 * - power: OF
78 */
79 /* if the power source was 5v (ie usb), check for power (pswitch) */
80 ldr r2, =0x800440c0 @ HW_POWER_STS
81 ldr r2, [r2]
82 mov r2, r2, lsl#2
83 mov r2, r2, lsr#26 @ extract PWRUP_SOURCE
84 tst r2, #0x20 @ bit 5: five volts
85 beq boot_normal
86 /* check pswitch*/
87 ldr r2, =0x800440c0 @ HW_POWER_STS
88 ldr r2, [r2]
89 mov r2, r2, lsl#10
90 mov r2, r2, lsr#30 @ extract PSWITCH
91 cmp r2, #1
92 moveq r0, #0 @ 1 => boot OF
93 b do_boot
94boot_normal:
95 /* If select key is hold, return so that the OF can boot */
96 ldr r2, =0x80018600 @ HW_PINCTRL_DIN0
97 ldr r2, [r2]
98 tst r2, #0x4000 @ bit 14, active low
99 moveq r0, #0 @ return 0, continue boot
100 /* r0 must contain the 0 to boot OF and 1 to boot RB */
101do_boot:
102 bxeq lr
103 str r0, [r1]
104 mov r0, #1
105 bx lr
106#elif defined(CREATIVE_ZENXFI3)
107 /* If volume down key is hold, return so that the OF can boot */
108 ldr r2, =0x80018620 @ HW_PINCTRL_DIN2
109 ldr r2, [r2]
110 tst r2, #0x80 @ bit 7, active low
111 moveq r0, #0 @ return 0, continue boot
112 bxeq lr
113 str r0, [r1]
114 mov r0, #1
115 bx lr
116#else
117#error No target defined !
118#endif
diff --git a/rbutil/mkimxboot/dualboot/dualboot.c b/rbutil/mkimxboot/dualboot/dualboot.c
new file mode 100644
index 0000000000..301eca87ad
--- /dev/null
+++ b/rbutil/mkimxboot/dualboot/dualboot.c
@@ -0,0 +1,167 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2013 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#include "regs-pinctrl.h"
22#include "regs-power.h"
23
24#define BOOT_ROM_CONTINUE 0 /* continue boot */
25#define BOOT_ROM_SECTION 1 /* switch to new section *result_id */
26
27typedef unsigned long uint32_t;
28
29// target specific boot context
30enum context_t
31{
32 CONTEXT_NORMAL, /* normal boot */
33 CONTEXT_USB, /* USB plugged boot */
34 CONTEXT_RTC, /* RTC wake up boot */
35};
36// target specific boot decision
37enum boot_t
38{
39 BOOT_STOP, /* power down */
40 BOOT_ROCK, /* boot to Rockbox */
41 BOOT_OF, /* boot to OF */
42};
43
44/**
45 * Helper functions
46 */
47
48static inline int __attribute__((always_inline)) read_gpio(int bank, int pin)
49{
50 return (HW_PINCTRL_DINn(bank) >> pin) & 1;
51}
52
53static inline int __attribute__((always_inline)) read_pswitch(void)
54{
55#if IMX233_SUBTARGET >= 3700
56 return BF_RD(POWER_STS, PSWITCH);
57#else
58 return BF_RD(DIGCTL_STATUS, PSWITCH);
59#endif
60}
61
62static inline void __attribute__((noreturn)) power_down()
63{
64#ifdef SANSA_FUZEPLUS
65 /* B0P09: this pin seems to be important to shutdown the hardware properly */
66 HW_PINCTRL_MUXSELn_SET(0) = 3 << 18;
67 HW_PINCTRL_DOEn(0) = 1 << 9;
68 HW_PINCTRL_DOUTn(0) = 1 << 9;
69#endif
70 /* power down */
71 HW_POWER_RESET = BM_OR2(POWER_RESET, UNLOCK, PWD);
72 while(1);
73}
74
75/**
76 * Boot decision functions
77 */
78
79#if defined(SANSA_FUZEPLUS)
80static enum boot_t boot_decision(enum context_t context)
81{
82 /* if volume down is hold, boot to OF */
83 if(!read_gpio(1, 30))
84 return BOOT_OF;
85 /* on normal boot, make sure power button is hold long enough */
86 if(context == CONTEXT_NORMAL)
87 {
88 // monitor PSWITCH
89 int count = 0;
90 for(int i = 0; i < 550000; i++)
91 if(read_pswitch() == 1)
92 count++;
93 if(count < 400000)
94 return BOOT_STOP;
95 }
96 return BOOT_ROCK;
97}
98#elif defined(CREATIVE_ZENXFI2)
99static int boot_decision(int context)
100{
101 /* We are lacking buttons on the Zen X-Fi2 because on USB, the select button
102 * enters recovery mode ! So we can only use power but power is used to power up
103 * on normal boots and then select is free ! Thus use a non-uniform scheme:
104 * - normal boot/RTC:
105 * - no key: Rockbox
106 * - select: OF
107 * - USB boot:
108 * - no key: Rockbox
109 * - power: OF
110 */
111 if(context == CONTEXT_USB)
112 return read_pswitch() == 1 ? BOOT_OF : BOOT_ROCK;
113 else
114 return !read_gpio(0, 14) ? BOOT_OF : BOOT_ROCK;
115}
116#elif defined(CREATIVE_ZENXFI3)
117static int boot_decision(int context)
118{
119 /* if volume down is hold, boot to OF */
120 return !read_gpio(2, 7) ? BOOT_OF : BOOT_ROCK;
121}
122#else
123#warning You should define a target specific boot decision function
124static int boot_decision(int context)
125{
126 return BOOT_ROCK;
127}
128#endif
129
130/**
131 * Context functions
132 */
133static inline enum context_t get_context(void)
134{
135#if IMX233_SUBTARGET >= 3780
136 /* On the imx233 it's easy because we know the power up source */
137 unsigned pwrup_src = BF_RD(POWER_STS, PWRUP_SOURCE);
138 if(pwrup_src & (1 << 5))
139 return CONTEXT_USB;
140 else if(pwrup_src & (1 << 4))
141 return CONTEXT_RTC;
142 else
143 return CONTEXT_NORMAL;
144#else
145 /* On the other targets, we need to poke a few more registers */
146#endif
147}
148
149int main(uint32_t arg, uint32_t *result_id)
150{
151 switch(boot_decision(get_context()))
152 {
153 case BOOT_ROCK:
154 *result_id = arg;
155 return BOOT_ROM_SECTION;
156 case BOOT_OF:
157 return BOOT_ROM_CONTINUE;
158 case BOOT_STOP:
159 default:
160 power_down();
161 }
162}
163
164int __attribute__((section(".start"))) start(uint32_t arg, uint32_t *result_id)
165{
166 return main(arg, result_id);
167} \ No newline at end of file
diff --git a/rbutil/mkimxboot/dualboot/dualboot.lds b/rbutil/mkimxboot/dualboot/dualboot.lds
index caaff1a41d..09739aee15 100644
--- a/rbutil/mkimxboot/dualboot/dualboot.lds
+++ b/rbutil/mkimxboot/dualboot/dualboot.lds
@@ -11,6 +11,7 @@ SECTIONS
11{ 11{
12 .text 0 : 12 .text 0 :
13 { 13 {
14 *(.start*)
14 *(.text*) 15 *(.text*)
15 } > OCRAM 16 } > OCRAM
16} 17}