diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-09-26 20:19:30 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-09-26 20:19:30 +0200 |
commit | b60712deb674ee6809966538176f4bb182b8c50b (patch) | |
tree | e6f6ca003fc34096e2ee428b4610e84f5614e879 | |
parent | d527c5595c92dafbba223afae0ed472c62d2728a (diff) | |
download | rockbox-b60712deb674ee6809966538176f4bb182b8c50b.tar.gz rockbox-b60712deb674ee6809966538176f4bb182b8c50b.zip |
sonynwz: rework dualboot mechanismbootloader_nwze370_v1bootloader_nwze360_v1
Now boot to RB if play/pause is pressed during 1 second, and to OF if
back is pressed 1 second. Otherwise power off. If hold is on, also power
off. In USB and alarm context, always boot and back determines OF vs RB.
Change-Id: Ie1d6c971901d6473255461cc7d71a5ee3177ecad
-rw-r--r-- | rbutil/mkimxboot/dualboot.c | 64 | ||||
-rw-r--r-- | rbutil/mkimxboot/dualboot.h | 4 | ||||
-rw-r--r-- | rbutil/mkimxboot/dualboot/dualboot.c | 64 |
3 files changed, 117 insertions, 15 deletions
diff --git a/rbutil/mkimxboot/dualboot.c b/rbutil/mkimxboot/dualboot.c index 8b5ca5b2b6..e2bbdae8a9 100644 --- a/rbutil/mkimxboot/dualboot.c +++ b/rbutil/mkimxboot/dualboot.c | |||
@@ -33,15 +33,59 @@ unsigned char dualboot_zenxfi3[56] = { | |||
33 | 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0x81, 0x15, 0x01, 0x00, 0xa0, 0x13, 0x1e, 0xff, 0x2f, 0xe1, | 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 | 34 | 0x00, 0x40, 0x04, 0x80, 0x00, 0x80, 0x01, 0x80 |
35 | }; | 35 | }; |
36 | unsigned char dualboot_nwze370[52] = { | 36 | unsigned char dualboot_nwze370[416] = { |
37 | 0x10, 0x40, 0x2d, 0xe9, 0x00, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x1c, 0x30, 0x9f, 0xe5, | 37 | 0x10, 0x40, 0x2d, 0xe9, 0x1e, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x68, 0x30, 0x9f, 0xe5, |
38 | 0xc0, 0x20, 0x93, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x03, 0x36, 0x03, 0xe2, 0x01, 0x06, 0x53, 0xe3, | 38 | 0x01, 0x20, 0xa0, 0xe3, 0x18, 0x20, 0x83, 0xe5, 0x04, 0x20, 0x83, 0xe5, 0x03, 0x20, 0xa0, 0xe1, |
39 | 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0x81, 0x15, 0x01, 0x00, 0xa0, 0x13, 0x1e, 0xff, 0x2f, 0xe1, | 39 | 0x10, 0x30, 0x92, 0xe5, 0x01, 0x00, 0x13, 0xe3, 0xfc, 0xff, 0xff, 0x0a, 0x48, 0x30, 0x9f, 0xe5, |
40 | 0x00, 0x40, 0x04, 0x80 | 40 | 0x50, 0x30, 0x93, 0xe5, 0x44, 0x20, 0x9f, 0xe5, 0x00, 0x26, 0x92, 0xe5, 0x02, 0x0c, 0x12, 0xe3, |
41 | 0x00, 0x00, 0xa0, 0x03, 0x1e, 0xff, 0x2f, 0x01, 0xff, 0x34, 0xc3, 0xe3, 0x3f, 0x37, 0xc3, 0xe3, | ||
42 | 0x41, 0x2e, 0x43, 0xe2, 0x0a, 0x20, 0x42, 0xe2, 0x63, 0x00, 0x52, 0xe3, 0x02, 0x00, 0xa0, 0x93, | ||
43 | 0x1e, 0xff, 0x2f, 0x91, 0x16, 0x3d, 0x43, 0xe2, 0x0c, 0x30, 0x43, 0xe2, 0x63, 0x00, 0x53, 0xe3, | ||
44 | 0x00, 0x00, 0xa0, 0x83, 0x01, 0x00, 0xa0, 0x93, 0x1e, 0xff, 0x2f, 0xe1, 0x00, 0x00, 0x05, 0x80, | ||
45 | 0x00, 0x80, 0x01, 0x80, 0xf0, 0x41, 0x2d, 0xe9, 0x00, 0x70, 0xa0, 0xe1, 0x01, 0x60, 0xa0, 0xe1, | ||
46 | 0xf8, 0x30, 0x9f, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x3f, 0x34, 0x03, 0xe2, 0x23, 0x3c, 0xa0, 0xe1, | ||
47 | 0x20, 0x00, 0x13, 0xe3, 0x01, 0x00, 0x00, 0x1a, 0x10, 0x00, 0x13, 0xe3, 0x23, 0x00, 0x00, 0x0a, | ||
48 | 0xdc, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, | ||
49 | 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, | ||
50 | 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, | ||
51 | 0xc9, 0xff, 0xff, 0xeb, 0x00, 0x40, 0x50, 0xe2, 0x06, 0x00, 0x00, 0x1a, 0x0a, 0x00, 0x00, 0xea, | ||
52 | 0xc5, 0xff, 0xff, 0xeb, 0x00, 0x00, 0x54, 0xe1, 0x0a, 0x00, 0x00, 0x1a, 0xc0, 0x30, 0x98, 0xe5, | ||
53 | 0x03, 0x00, 0x55, 0xe1, 0xf9, 0xff, 0xff, 0x8a, 0x01, 0x00, 0x54, 0xe3, 0x02, 0x00, 0x00, 0x0a, | ||
54 | 0x02, 0x00, 0x54, 0xe3, 0x03, 0x00, 0x00, 0x1a, 0x06, 0x00, 0x00, 0xea, 0x00, 0x70, 0x86, 0xe5, | ||
55 | 0x01, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, 0x68, 0x20, 0x9f, 0xe5, 0x5c, 0x30, 0x9f, 0xe5, | ||
56 | 0x00, 0x21, 0x83, 0xe5, 0xfe, 0xff, 0xff, 0xea, 0x00, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, | ||
57 | 0x4c, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, | ||
58 | 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, | ||
59 | 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, | ||
60 | 0xa5, 0xff, 0xff, 0xeb, 0x00, 0x40, 0xa0, 0xe1, 0x1c, 0x30, 0x9f, 0xe5, 0xc0, 0x50, 0x93, 0xe5, | ||
61 | 0x3d, 0x59, 0x85, 0xe2, 0x09, 0x5d, 0x85, 0xe2, 0x03, 0x80, 0xa0, 0xe1, 0xda, 0xff, 0xff, 0xea, | ||
62 | 0x00, 0x40, 0x04, 0x80, 0x00, 0x00, 0x05, 0x80, 0x01, 0x00, 0xff, 0xff, 0x00, 0xc0, 0x01, 0x80 | ||
41 | }; | 63 | }; |
42 | unsigned char dualboot_nwze360[52] = { | 64 | unsigned char dualboot_nwze360[416] = { |
43 | 0x10, 0x40, 0x2d, 0xe9, 0x00, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x1c, 0x30, 0x9f, 0xe5, | 65 | 0x10, 0x40, 0x2d, 0xe9, 0x1e, 0x00, 0x00, 0xeb, 0x10, 0x80, 0xbd, 0xe8, 0x68, 0x30, 0x9f, 0xe5, |
44 | 0xc0, 0x20, 0x93, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x03, 0x36, 0x03, 0xe2, 0x01, 0x06, 0x53, 0xe3, | 66 | 0x01, 0x20, 0xa0, 0xe3, 0x18, 0x20, 0x83, 0xe5, 0x04, 0x20, 0x83, 0xe5, 0x03, 0x20, 0xa0, 0xe1, |
45 | 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, 0x81, 0x15, 0x01, 0x00, 0xa0, 0x13, 0x1e, 0xff, 0x2f, 0xe1, | 67 | 0x10, 0x30, 0x92, 0xe5, 0x01, 0x00, 0x13, 0xe3, 0xfc, 0xff, 0xff, 0x0a, 0x48, 0x30, 0x9f, 0xe5, |
46 | 0x00, 0x40, 0x04, 0x80 | 68 | 0x50, 0x30, 0x93, 0xe5, 0x44, 0x20, 0x9f, 0xe5, 0x00, 0x26, 0x92, 0xe5, 0x02, 0x0c, 0x12, 0xe3, |
69 | 0x00, 0x00, 0xa0, 0x03, 0x1e, 0xff, 0x2f, 0x01, 0xff, 0x34, 0xc3, 0xe3, 0x3f, 0x37, 0xc3, 0xe3, | ||
70 | 0x41, 0x2e, 0x43, 0xe2, 0x0a, 0x20, 0x42, 0xe2, 0x63, 0x00, 0x52, 0xe3, 0x02, 0x00, 0xa0, 0x93, | ||
71 | 0x1e, 0xff, 0x2f, 0x91, 0x16, 0x3d, 0x43, 0xe2, 0x0c, 0x30, 0x43, 0xe2, 0x63, 0x00, 0x53, 0xe3, | ||
72 | 0x00, 0x00, 0xa0, 0x83, 0x01, 0x00, 0xa0, 0x93, 0x1e, 0xff, 0x2f, 0xe1, 0x00, 0x00, 0x05, 0x80, | ||
73 | 0x00, 0x80, 0x01, 0x80, 0xf0, 0x41, 0x2d, 0xe9, 0x00, 0x70, 0xa0, 0xe1, 0x01, 0x60, 0xa0, 0xe1, | ||
74 | 0xf8, 0x30, 0x9f, 0xe5, 0xc0, 0x30, 0x93, 0xe5, 0x3f, 0x34, 0x03, 0xe2, 0x23, 0x3c, 0xa0, 0xe1, | ||
75 | 0x20, 0x00, 0x13, 0xe3, 0x01, 0x00, 0x00, 0x1a, 0x10, 0x00, 0x13, 0xe3, 0x23, 0x00, 0x00, 0x0a, | ||
76 | 0xdc, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, | ||
77 | 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, | ||
78 | 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, | ||
79 | 0xc9, 0xff, 0xff, 0xeb, 0x00, 0x40, 0x50, 0xe2, 0x06, 0x00, 0x00, 0x1a, 0x0a, 0x00, 0x00, 0xea, | ||
80 | 0xc5, 0xff, 0xff, 0xeb, 0x00, 0x00, 0x54, 0xe1, 0x0a, 0x00, 0x00, 0x1a, 0xc0, 0x30, 0x98, 0xe5, | ||
81 | 0x03, 0x00, 0x55, 0xe1, 0xf9, 0xff, 0xff, 0x8a, 0x01, 0x00, 0x54, 0xe3, 0x02, 0x00, 0x00, 0x0a, | ||
82 | 0x02, 0x00, 0x54, 0xe3, 0x03, 0x00, 0x00, 0x1a, 0x06, 0x00, 0x00, 0xea, 0x00, 0x70, 0x86, 0xe5, | ||
83 | 0x01, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, 0x68, 0x20, 0x9f, 0xe5, 0x5c, 0x30, 0x9f, 0xe5, | ||
84 | 0x00, 0x21, 0x83, 0xe5, 0xfe, 0xff, 0xff, 0xea, 0x00, 0x00, 0xa0, 0xe3, 0xf0, 0x81, 0xbd, 0xe8, | ||
85 | 0x4c, 0x30, 0x9f, 0xe5, 0x02, 0x21, 0xa0, 0xe3, 0x08, 0x20, 0x83, 0xe5, 0x03, 0x21, 0x82, 0xe2, | ||
86 | 0x08, 0x20, 0x83, 0xe5, 0xff, 0x24, 0x82, 0xe2, 0x58, 0x20, 0x83, 0xe5, 0xc2, 0x24, 0x82, 0xe2, | ||
87 | 0x24, 0x20, 0x83, 0xe5, 0x02, 0x2c, 0xa0, 0xe3, 0x0e, 0x39, 0x43, 0xe2, 0x04, 0x24, 0x83, 0xe5, | ||
88 | 0xa5, 0xff, 0xff, 0xeb, 0x00, 0x40, 0xa0, 0xe1, 0x1c, 0x30, 0x9f, 0xe5, 0xc0, 0x50, 0x93, 0xe5, | ||
89 | 0x3d, 0x59, 0x85, 0xe2, 0x09, 0x5d, 0x85, 0xe2, 0x03, 0x80, 0xa0, 0xe1, 0xda, 0xff, 0xff, 0xea, | ||
90 | 0x00, 0x40, 0x04, 0x80, 0x00, 0x00, 0x05, 0x80, 0x01, 0x00, 0xff, 0xff, 0x00, 0xc0, 0x01, 0x80 | ||
47 | }; | 91 | }; |
diff --git a/rbutil/mkimxboot/dualboot.h b/rbutil/mkimxboot/dualboot.h index 9bf271299a..17ee1979fb 100644 --- a/rbutil/mkimxboot/dualboot.h +++ b/rbutil/mkimxboot/dualboot.h | |||
@@ -3,5 +3,5 @@ | |||
3 | extern unsigned char dualboot_fuzeplus[228]; | 3 | extern unsigned char dualboot_fuzeplus[228]; |
4 | extern unsigned char dualboot_zenxfi2[96]; | 4 | extern unsigned char dualboot_zenxfi2[96]; |
5 | extern unsigned char dualboot_zenxfi3[56]; | 5 | extern unsigned char dualboot_zenxfi3[56]; |
6 | extern unsigned char dualboot_nwze370[52]; | 6 | extern unsigned char dualboot_nwze370[416]; |
7 | extern unsigned char dualboot_nwze360[52]; | 7 | extern unsigned char dualboot_nwze360[416]; |
diff --git a/rbutil/mkimxboot/dualboot/dualboot.c b/rbutil/mkimxboot/dualboot/dualboot.c index f75673efbe..3cca59bb8a 100644 --- a/rbutil/mkimxboot/dualboot/dualboot.c +++ b/rbutil/mkimxboot/dualboot/dualboot.c | |||
@@ -20,6 +20,8 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "regs-pinctrl.h" | 21 | #include "regs-pinctrl.h" |
22 | #include "regs-power.h" | 22 | #include "regs-power.h" |
23 | #include "regs-lradc.h" | ||
24 | #include "regs-digctl.h" | ||
23 | 25 | ||
24 | #define BOOT_ROM_CONTINUE 0 /* continue boot */ | 26 | #define BOOT_ROM_CONTINUE 0 /* continue boot */ |
25 | #define BOOT_ROM_SECTION 1 /* switch to new section *result_id */ | 27 | #define BOOT_ROM_SECTION 1 /* switch to new section *result_id */ |
@@ -59,6 +61,28 @@ static inline int __attribute__((always_inline)) read_pswitch(void) | |||
59 | #endif | 61 | #endif |
60 | } | 62 | } |
61 | 63 | ||
64 | /* only works for channels <=7, always divide by 2, never accumulates */ | ||
65 | static inline void __attribute__((always_inline)) setup_lradc(int src) | ||
66 | { | ||
67 | BF_CLR(LRADC_CTRL0, SFTRST); | ||
68 | BF_CLR(LRADC_CTRL0, CLKGATE); | ||
69 | /* don't bother changing the source, we are early enough at boot so that | ||
70 | * channel x is mapped to source x */ | ||
71 | HW_LRADC_CHn_CLR(src) = BM_OR2(LRADC_CHn, NUM_SAMPLES, ACCUMULATE); | ||
72 | BF_SETV(LRADC_CTRL2, DIVIDE_BY_TWO, 1 << src); | ||
73 | } | ||
74 | |||
75 | #define BP_LRADC_CTRL1_LRADCx_IRQ(x) (x) | ||
76 | #define BM_LRADC_CTRL1_LRADCx_IRQ(x) (1 << (x)) | ||
77 | |||
78 | static inline int __attribute__((always_inline)) read_lradc(int src) | ||
79 | { | ||
80 | BF_CLR(LRADC_CTRL1, LRADCx_IRQ(src)); | ||
81 | BF_SETV(LRADC_CTRL0, SCHEDULE, 1 << src); | ||
82 | while(!BF_RD(LRADC_CTRL1, LRADCx_IRQ(src))); | ||
83 | return BF_RDn(LRADC_CHn, src, VALUE); | ||
84 | } | ||
85 | |||
62 | static inline void __attribute__((noreturn)) power_down() | 86 | static inline void __attribute__((noreturn)) power_down() |
63 | { | 87 | { |
64 | #ifdef SANSA_FUZEPLUS | 88 | #ifdef SANSA_FUZEPLUS |
@@ -120,11 +144,45 @@ static int boot_decision(int context) | |||
120 | return !read_gpio(2, 7) ? BOOT_OF : BOOT_ROCK; | 144 | return !read_gpio(2, 7) ? BOOT_OF : BOOT_ROCK; |
121 | } | 145 | } |
122 | #elif defined(SONY_NWZE360) || defined(SONY_NWZE370) | 146 | #elif defined(SONY_NWZE360) || defined(SONY_NWZE370) |
147 | static int local_decision(void) | ||
148 | { | ||
149 | /* read keys and pswitch */ | ||
150 | int val = read_lradc(0); | ||
151 | /* if hold is on, power off | ||
152 | * if back is pressed, boot to OF | ||
153 | * if play is pressed, boot RB | ||
154 | * otherwise power off */ | ||
155 | if(read_gpio(0, 9) == 0) | ||
156 | return BOOT_STOP; | ||
157 | if(val >= 1050 && val < 1150) | ||
158 | return BOOT_OF; | ||
159 | if(val >= 1420 && val < 1520) | ||
160 | return BOOT_ROCK; | ||
161 | return BOOT_STOP; | ||
162 | } | ||
163 | |||
123 | static int boot_decision(int context) | 164 | static int boot_decision(int context) |
124 | { | 165 | { |
125 | /* Power button set PSWITCH to 3, all other buttons to 1. So any | 166 | setup_lradc(0); // setup LRADC channel 0 to read keys |
126 | * button press will boot OF */ | 167 | HW_PINCTRL_PULLn_SET(0) = 1 << 9; // enable pullup on hold key (B0P09) |
127 | return read_pswitch() == 1 ? BOOT_OF : BOOT_ROCK; | 168 | /* make a decision */ |
169 | int decision = local_decision(); | ||
170 | /* in USB or alarm context, stick to it */ | ||
171 | if(context == CONTEXT_USB || context == CONTEXT_RTC) | ||
172 | { | ||
173 | /* never power down so replace power off decision by rockbox */ | ||
174 | return decision == BOOT_STOP ? BOOT_ROCK : decision; | ||
175 | } | ||
176 | /* otherwise start a 1 second timeout. Any decision change | ||
177 | * will result in power down */ | ||
178 | uint32_t tmo = HW_DIGCTL_MICROSECONDS + 1000000; | ||
179 | while(HW_DIGCTL_MICROSECONDS < tmo) | ||
180 | { | ||
181 | int new_dec = local_decision(); | ||
182 | if(new_dec != decision) | ||
183 | return BOOT_STOP; | ||
184 | } | ||
185 | return decision; | ||
128 | } | 186 | } |
129 | #else | 187 | #else |
130 | #warning You should define a target specific boot decision function | 188 | #warning You should define a target specific boot decision function |