barco.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /********************************************************************
  2. *
  3. * Unless otherwise specified, Copyright (C) 2004-2005 Barco Control Rooms
  4. *
  5. * $Source: /home/services/cvs/firmware/ppc/u-boot-1.1.2/board/barco/barco.c,v $
  6. * $Revision: 1.4 $
  7. * $Author: mleeman $
  8. * $Date: 2005/03/02 16:40:20 $
  9. *
  10. * Last ChangeLog Entry
  11. * $Log: barco.c,v $
  12. * Revision 1.4 2005/03/02 16:40:20 mleeman
  13. * remove empty labels (3.4 complains)
  14. *
  15. * Revision 1.3 2005/02/21 12:48:58 mleeman
  16. * update of copyright years (feedback wd)
  17. *
  18. * Revision 1.2 2005/02/21 10:10:53 mleeman
  19. * - split up switch statement to a function call (Linux kernel coding guidelines)
  20. * ( feedback wd)
  21. *
  22. * Revision 1.1 2005/02/14 09:31:07 mleeman
  23. * renaming of files
  24. *
  25. * Revision 1.1 2005/02/14 09:23:46 mleeman
  26. * - moved 'barcohydra' directory to a more generic barco; since we will be
  27. * supporting and adding multiple boards
  28. *
  29. * Revision 1.3 2005/02/10 13:57:32 mleeman
  30. * fixed flash corruption: I should exit from the moment I find the correct value
  31. *
  32. * Revision 1.2 2005/02/09 12:56:23 mleeman
  33. * add generic header to track changes in sources
  34. *
  35. *
  36. *******************************************************************/
  37. /*
  38. * (C) Copyright 2004
  39. * Marc Leeman <marc.leeman@barco.com>
  40. *
  41. * This program is free software; you can redistribute it and/or
  42. * modify it under the terms of the GNU General Public License as
  43. * published by the Free Software Foundation; either version 2 of
  44. * the License, or (at your option) any later version.
  45. *
  46. * This program is distributed in the hope that it will be useful,
  47. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49. * GNU General Public License for more details.
  50. *
  51. * You should have received a copy of the GNU General Public License
  52. * along with this program; if not, write to the Free Software
  53. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  54. * MA 02111-1307 USA
  55. */
  56. #include <common.h>
  57. #include <mpc824x.h>
  58. #include <pci.h>
  59. #include <malloc.h>
  60. #include <command.h>
  61. #include "config.h"
  62. #include "barco_svc.h"
  63. #define TRY_WORKING (3)
  64. #define BOOT_DEFAULT (2)
  65. #define BOOT_WORKING (1)
  66. int checkboard (void)
  67. {
  68. /*TODO: Check processor type */
  69. puts ( "Board: Streaming Video Card for Hydra systems "
  70. #ifdef CONFIG_MPC8240
  71. "8240"
  72. #endif
  73. #ifdef CONFIG_MPC8245
  74. "8245"
  75. #endif
  76. " Unity ##Test not implemented yet##\n");
  77. return 0;
  78. }
  79. long int initdram (int board_type)
  80. {
  81. long size;
  82. long new_bank0_end;
  83. long mear1;
  84. long emear1;
  85. size = get_ram_size (CFG_SDRAM_BASE, CFG_MAX_RAM_SIZE);
  86. new_bank0_end = size - 1;
  87. mear1 = mpc824x_mpc107_getreg (MEAR1);
  88. emear1 = mpc824x_mpc107_getreg (EMEAR1);
  89. mear1 = (mear1 & 0xFFFFFF00) |
  90. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
  91. emear1 = (emear1 & 0xFFFFFF00) |
  92. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
  93. mpc824x_mpc107_setreg (MEAR1, mear1);
  94. mpc824x_mpc107_setreg (EMEAR1, emear1);
  95. return (size);
  96. }
  97. /*
  98. * Initialize PCI Devices, report devices found.
  99. */
  100. #ifndef CONFIG_PCI_PNP
  101. static struct pci_config_table pci_barcohydra_config_table[] = {
  102. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID,
  103. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  104. PCI_ENET0_MEMADDR,
  105. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER } },
  106. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x10, PCI_ANY_ID,
  107. pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
  108. PCI_ENET1_MEMADDR,
  109. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER } },
  110. { }
  111. };
  112. #endif
  113. struct pci_controller hose = {
  114. #ifndef CONFIG_PCI_PNP
  115. config_table: pci_barcohydra_config_table,
  116. #endif
  117. };
  118. void pci_init_board (void)
  119. {
  120. pci_mpc824x_init (&hose);
  121. }
  122. int write_flash (char *addr, char value)
  123. {
  124. char *adr = (char *)0xFF800000;
  125. int cnt = 0;
  126. char status,oldstatus;
  127. *(adr+0x55) = 0xAA; udelay (1);
  128. *(adr+0xAA) = 0x55; udelay (1);
  129. *(adr+0x55) = 0xA0; udelay (1);
  130. *addr = value;
  131. status = *addr;
  132. do {
  133. oldstatus = status;
  134. status = *addr;
  135. if ((oldstatus & 0x40) == (status & 0x40)) {
  136. return 4;
  137. }
  138. cnt++;
  139. if (cnt > 10000) {
  140. return 2;
  141. }
  142. } while ( (status & 0x20) == 0 );
  143. oldstatus = *addr;
  144. status = *addr;
  145. if ((oldstatus & 0x40) == (status & 0x40)) {
  146. return 0;
  147. } else {
  148. *(adr+0x55) = 0xF0;
  149. return 1;
  150. }
  151. }
  152. unsigned update_flash (unsigned char *buf)
  153. {
  154. switch ((*buf) & 0x3) {
  155. case TRY_WORKING:
  156. printf ("found 3 and converted it to 2\n");
  157. write_flash ((char *)buf, (*buf) & 0xFE);
  158. *((unsigned char *)0xFF800000) = 0xF0;
  159. udelay (100);
  160. printf ("buf [%#010x] %#010x\n", buf, (*buf));
  161. /* XXX - fall through??? */
  162. case BOOT_WORKING :
  163. return BOOT_WORKING;
  164. }
  165. return BOOT_DEFAULT;
  166. }
  167. unsigned scan_flash (void)
  168. {
  169. char section[] = "kernel";
  170. int cfgFileLen = (CFG_FLASH_ERASE_SECTOR_LENGTH >> 1);
  171. int sectionPtr = 0;
  172. int foundItem = 0; /* 0: None, 1: section found, 2: "=" found */
  173. int bufPtr;
  174. unsigned char *buf;
  175. buf = (unsigned char*)(CFG_FLASH_RANGE_BASE + CFG_FLASH_RANGE_SIZE \
  176. - CFG_FLASH_ERASE_SECTOR_LENGTH);
  177. for (bufPtr = 0; bufPtr < cfgFileLen; ++bufPtr) {
  178. if ((buf[bufPtr]==0xFF) && (*(int*)(buf+bufPtr)==0xFFFFFFFF)) {
  179. return BOOT_DEFAULT;
  180. }
  181. /* This is the scanning loop, we try to find a particular
  182. * quoted value
  183. */
  184. switch (foundItem) {
  185. case 0:
  186. if ((section[sectionPtr] == 0)) {
  187. ++foundItem;
  188. } else if (buf[bufPtr] == section[sectionPtr]) {
  189. ++sectionPtr;
  190. } else {
  191. sectionPtr = 0;
  192. }
  193. break;
  194. case 1:
  195. ++foundItem;
  196. break;
  197. case 2:
  198. ++foundItem;
  199. break;
  200. case 3:
  201. default:
  202. return update_flash (&buf[bufPtr - 1]);
  203. }
  204. }
  205. printf ("Failed to read %s\n",section);
  206. return BOOT_DEFAULT;
  207. }
  208. TSBootInfo* find_boot_info (void)
  209. {
  210. unsigned bootimage = scan_flash ();
  211. TSBootInfo* info = (TSBootInfo*)malloc (sizeof(TSBootInfo));
  212. switch (bootimage) {
  213. case TRY_WORKING:
  214. info->address = CFG_WORKING_KERNEL_ADDRESS;
  215. break;
  216. case BOOT_WORKING :
  217. info->address = CFG_WORKING_KERNEL_ADDRESS;
  218. break;
  219. case BOOT_DEFAULT:
  220. default:
  221. info->address= CFG_DEFAULT_KERNEL_ADDRESS;
  222. }
  223. info->size = *((unsigned int *)(info->address ));
  224. return info;
  225. }
  226. void barcobcd_boot (void)
  227. {
  228. TSBootInfo* start;
  229. char *bootm_args[2];
  230. char *buf;
  231. int cnt;
  232. extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
  233. buf = (char *)(0x00800000);
  234. /* make certain there are enough chars to print the command line here!
  235. */
  236. bootm_args[0] = (char *)malloc (16*sizeof(char));
  237. bootm_args[1] = (char *)malloc (16*sizeof(char));
  238. start = find_boot_info ();
  239. printf ("Booting kernel at address %#10x with size %#10x\n",
  240. start->address, start->size);
  241. /* give length of the kernel image to bootm */
  242. sprintf (bootm_args[0],"%x",start->size);
  243. /* give address of the kernel image to bootm */
  244. sprintf (bootm_args[1],"%x",buf);
  245. printf ("flash address: %#10x\n",start->address+8);
  246. printf ("buf address: %#10x\n",buf);
  247. /* aha, we reserve 8 bytes here... */
  248. for (cnt = 0; cnt < start->size ; cnt++) {
  249. buf[cnt] = ((char *)start->address)[cnt+8];
  250. }
  251. /* initialise RAM memory */
  252. *((unsigned int *)0xFEC00000) = 0x00141A98;
  253. do_bootm (NULL,0,2,bootm_args);
  254. }
  255. int barcobcd_boot_image (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  256. {
  257. #if 0
  258. if (argc > 1) {
  259. printf ("Usage:\n (%d) %s\n", argc, cmdtp->usage);
  260. return 1;
  261. }
  262. #endif
  263. barcobcd_boot ();
  264. return 0;
  265. }
  266. /* Currently, boot_working and boot_default are the same command. This is
  267. * left in here to see what we'll do in the future */
  268. U_BOOT_CMD (
  269. try_working, 1, 1, barcobcd_boot_image,
  270. " try_working - check flash value and boot the appropriate image\n",
  271. "\n"
  272. );
  273. U_BOOT_CMD (
  274. boot_working, 1, 1, barcobcd_boot_image,
  275. " boot_working - check flash value and boot the appropriate image\n",
  276. "\n"
  277. );
  278. U_BOOT_CMD (
  279. boot_default, 1, 1, barcobcd_boot_image,
  280. " boot_default - check flash value and boot the appropriate image\n",
  281. "\n"
  282. );
  283. /*
  284. * We are not using serial communication, so just provide empty functions
  285. */
  286. int serial_init (void)
  287. {
  288. return 0;
  289. }
  290. void serial_setbrg (void)
  291. {
  292. return;
  293. }
  294. void serial_putc (const char c)
  295. {
  296. return;
  297. }
  298. void serial_puts (const char *c)
  299. {
  300. return;
  301. }
  302. void serial_addr (unsigned int i)
  303. {
  304. return;
  305. }
  306. int serial_getc (void)
  307. {
  308. return 0;
  309. }
  310. int serial_tstc (void)
  311. {
  312. return 0;
  313. }
  314. unsigned long post_word_load (void)
  315. {
  316. return 0l;
  317. }
  318. void post_word_store (unsigned long val)
  319. {
  320. return;
  321. }