1+ #include "../menu.h"
2+ #include <Chipset/interrupts.h>
3+
4+ static inline void htcleo_boot_s () {
5+ asm volatile (
6+ // Save registers
7+ "MOV r9, r0\n"
8+
9+ // Cotulla's code so kernel will not crash. aux control register
10+ // Found more info here: http://www.spinics.net/lists/linux-arm-msm/msg00492.html
11+ // It looks it is Martijn Stolk's code
12+ "MRC p15, 0, r0, c1, c0, 1\n"
13+ "BIC r0, r0, #0x40\n" // (1<<6) IBE (0 = executes the CP15 Invalidate All and Invalidate by MVA instructions as a NOP instruction, reset value)
14+ "BIC r0, r0, #0x200000\n" // (1<<21) undocumented bit
15+ "MCR p15, 0, r0, c1, c0, 1\n"
16+
17+ // Disable VFP
18+ "MOV r0, #0\n"
19+ "FMXR FPEXC, r0\n"
20+
21+ // ICIALL to invalidate entire I-Cache
22+ "MCR p15, 0, r0, c7, c5, 0\n" // ICIALLU
23+
24+ // Disable dcache and i cache
25+ "MRC p15, 0, r0, c1, c0, 0\n"
26+ "BIC r0, r0, #(1<<0)\n" // disable mmu (already disabled)
27+ "BIC r0, r0, #(1<<2)\n" // disable data cache
28+ "BIC r0, r0, #(1<<12)\n" // disable instruction cache
29+ "MCR p15, 0, r0, c1, c0, 0\n"
30+ "ISB\n"
31+
32+ // DCIALL to invalidate L2 cache bank (needs to be run 4 times, once per bank)
33+ // This must be done early in code (prior to enabling the caches)
34+ "MOV r0, #0x2\n"
35+ "MCR p15, 0, r0, c9, c0, 6\n" // DCIALL bank D ([15:14] == 2'b00)
36+ "ORR r0, r0, #0x00004000\n"
37+ "MCR p15, 0, r0, c9, c0, 6\n" // DCIALL bank C ([15:14] == 2'b01)
38+ "ADD r0, r0, #0x00004000\n"
39+ "MCR p15, 0, r0, c9, c0, 6\n" // DCIALL bank B ([15:14] == 2'b10)
40+ "ADD r0, r0, #0x00004000\n"
41+ "MCR p15, 0, r0, c9, c0, 6\n" // DCIALL bank A ([15:14] == 2'b11)
42+ // DCIALL to invalidate entire D-Cache
43+ "MOV r0, #0\n"
44+ "MCR p15, 0, r0, c9, c0, 6\n" // DCIALL r0
45+ "DSB\n"
46+ "ISB\n"
47+
48+ // Invalidate the UTLB
49+ "MOV r0, #0\n"
50+ "MCR p15, 0, r0, c8, c7, 0\n" // UTLBIALL
51+ "ISB\n"
52+
53+ ".ltorg\n"
54+ );
55+ }
56+
57+ void htcleo_disable_interrupts (void )
58+ {
59+ //clear current pending interrupts
60+ MmioWrite32 (VIC_INT_CLEAR0 , 0xffffffff );
61+ MmioWrite32 (VIC_INT_CLEAR1 , 0xffffffff );
62+
63+ //disable all
64+ MmioWrite32 (VIC_INT_EN0 , 0 );
65+ MmioWrite32 (VIC_INT_EN1 , 0 );
66+ //disable interrupts
67+ MmioWrite32 (VIC_INT_MASTEREN , 0 );
68+ }
69+
70+ void htcleo_boot (void * kernel ,unsigned machtype ,void * tags )
71+ {
72+ htcleo_disable_interrupts ();
73+ htcleo_boot_s (kernel , machtype , tags );
74+ }
75+
76+ unsigned * target_atag_mem (unsigned * ptr )
77+ {
78+
79+ #if 0
80+ //MEM TAG
81+ * ptr ++ = 4 ;
82+ * ptr ++ = 0x54410002 ;
83+ //*ptr++ = 0x1e400000; //mem size from haret
84+ //*ptr++ = 0x1E7C0000; //mem size from kernel config
85+ * ptr ++ = 0x1CFC0000 ; //mem size from kernel config with bravo dsp
86+ * ptr ++ = 0x11800000 ; //mem base
87+ #endif
88+
89+ //add atag to notify nand boot
90+ * ptr ++ = 4 ;
91+ * ptr ++ = 0x4C47414D ; // NAND atag (MAGL :))
92+ * ptr ++ = 0x004b4c63 ; // cLK signature
93+ * ptr ++ = 13 ; // cLK version number
94+
95+ return ptr ;
96+ }
97+
98+
99+
100+ void boot_linux (void * kernel , unsigned * tags ,
101+ const char * cmdline , unsigned machtype ,
102+ void * ramdisk , unsigned ramdisk_size )
103+ {
104+ unsigned * ptr = tags ;
105+ unsigned pcount = 0 ;
106+ void (* entry )(unsigned ,unsigned ,unsigned * ) = kernel ;
107+ struct ptable * ptable ;
108+ int cmdline_len = 0 ;
109+ int have_cmdline = 0 ;
110+ int pause_at_bootup = 0 ;
111+
112+ /* CORE */
113+ * ptr ++ = 2 ;
114+ * ptr ++ = 0x54410001 ;
115+
116+ if (ramdisk_size ) {
117+ * ptr ++ = 4 ;
118+ * ptr ++ = 0x54420005 ;
119+ * ptr ++ = (unsigned )ramdisk ;
120+ * ptr ++ = ramdisk_size ;
121+ }
122+
123+ ptr = target_atag_mem (ptr );
124+ /* ToDo: add the needed nand stuff ????*/
125+ // if (!target_is_emmc_boot()) {
126+ // /* Skip NAND partition ATAGS for eMMC boot */
127+ // if ((ptable = flash_get_ptable()) && (ptable->count != 0)) {
128+ // int i;
129+ // for(i=0; i < ptable->count; i++) {
130+ // struct ptentry *ptn;
131+ // ptn = ptable_get(ptable, i);
132+ // if (ptn->type == TYPE_APPS_PARTITION)
133+ // pcount++;
134+ // }
135+ // *ptr++ = 2 + (pcount * (sizeof(struct atag_ptbl_entry) /
136+ // sizeof(unsigned)));
137+ // *ptr++ = 0x4d534d70;
138+ // for (i = 0; i < ptable->count; ++i)
139+ // ptentry_to_tag(&ptr, ptable_get(ptable, i));
140+ // }
141+ // }
142+
143+ if (cmdline && cmdline [0 ]) {
144+ cmdline_len = AsciiStrLen (cmdline );
145+ have_cmdline = 1 ;
146+ }
147+ if (cmdline_len > 0 ) {
148+ const char * src ;
149+ char * dst ;
150+ unsigned n ;
151+ /* include terminating 0 and round up to a word multiple */
152+ n = (cmdline_len + 4 ) & (~3 );
153+ * ptr ++ = (n / 4 ) + 2 ;
154+ * ptr ++ = 0x54410009 ;
155+ dst = (char * )ptr ;
156+ if (have_cmdline ) {
157+ src = cmdline ;
158+ while ((* dst ++ = * src ++ ));
159+ }
160+ /*J0SH1X: leo is never emmc boot, even tho sdsupport in clk would be cool*/
161+ // if (target_is_emmc_boot()) {
162+ // src = emmc_cmdline;
163+ // if (have_cmdline) --dst;
164+ // have_cmdline = 1;
165+ // while ((*dst++ = *src++));
166+ // }
167+ /*J0SH1X: we dont need clks charging since menu already handles charging itself*/
168+ // if (pause_at_bootup) {
169+ // src = battchg_pause;
170+ // if (have_cmdline) --dst;
171+ // while ((*dst++ = *src++));
172+ // }
173+ ptr += (n / 4 );
174+ }
175+
176+ /* END */
177+ * ptr ++ = 0 ;
178+ * ptr ++ = 0 ;
179+
180+ DEBUG ((EFI_D_INFO , "booting linux @ %p, ramdisk @ %p (%d)\n" ,kernel , ramdisk , ramdisk_size ));
181+ if (cmdline )
182+ DEBUG ((EFI_D_INFO , "cmdline: %s\n" , cmdline ));
183+ /*J0SH1X disable interrupts here ?! timer uninit should be done by exitbs
184+ enter_critical_section();
185+ platform_uninit_timer();
186+ */
187+
188+ /*ToDo: add uefi version of this
189+ arch_disable_cache(UCACHE);
190+ arch_disable_mmu();
191+ */
192+
193+ /*replace with crappy fade effect code i guess*/
194+ // #if DISPLAY_SPLASH_SCREEN
195+ // display_shutdown();
196+ // #endif
197+
198+ //toDo: call exit bs here
199+ htcleo_boot (kernel , machtype , tags );
200+ //entry(0, machtype, tags);
201+ }
202+
203+
204+ void BootAndroidKernel (IN EFI_HANDLE ImageHandle , IN EFI_SYSTEM_TABLE * SystemTable ) {
205+ //load kernel and ramdisk and atags in memory here and call boot_linux with it
206+
207+ }
0 commit comments