barco.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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;
  128. udelay(1);
  129. *(adr+0xAA) = 0x55;
  130. udelay(1);
  131. *(adr+0x55) = 0xA0;
  132. udelay(1);
  133. *addr = value;
  134. status = *addr;
  135. do{
  136. oldstatus = status;
  137. status = *addr;
  138. if ((oldstatus & 0x40) == (status & 0x40)){
  139. return 4;
  140. }
  141. cnt++;
  142. if (cnt > 10000){
  143. return 2;
  144. }
  145. }while( (status & 0x20) == 0 );
  146. oldstatus = *addr;
  147. status = *addr;
  148. if ((oldstatus & 0x40) == (status & 0x40)) return 0;
  149. else {
  150. *(adr+0x55) = 0xF0;
  151. return 1;
  152. }
  153. }
  154. unsigned update_flash(unsigned char* buf){
  155. switch((*buf) & 0x3){
  156. case TRY_WORKING:
  157. printf("found 3 and converted it to 2\n");
  158. write_flash(buf, (*buf) & 0xFE);
  159. *((unsigned char *)0xFF800000) = 0xF0;
  160. udelay(100);
  161. printf("buf [%#010x] %#010x\n",buf,(*buf));
  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. ulong sp;
  171. int cfgFileLen = (CFG_FLASH_ERASE_SECTOR_LENGTH >> 1);
  172. int sectionPtr = 0;
  173. int foundItem = 0; /* 0: None, 1: section found, 2: "=" found */
  174. int bufPtr;
  175. unsigned char *buf;
  176. buf = (unsigned char*)(CFG_FLASH_RANGE_BASE + CFG_FLASH_RANGE_SIZE \
  177. - CFG_FLASH_ERASE_SECTOR_LENGTH);
  178. for(bufPtr = 0; bufPtr < cfgFileLen; ++bufPtr){
  179. if ((buf[bufPtr]==0xFF) && (*(int*)(buf+bufPtr)==0xFFFFFFFF)) {
  180. return BOOT_DEFAULT;
  181. }
  182. switch(foundItem)
  183. {
  184. /* This is the scanning loop, we try to find a particular
  185. * quoted value
  186. */
  187. case 0:
  188. if((section[sectionPtr] == 0)){
  189. ++foundItem;
  190. }
  191. else if(buf[bufPtr] == section[sectionPtr]){
  192. ++sectionPtr;
  193. }
  194. else {
  195. sectionPtr = 0;
  196. }
  197. break;
  198. case 1:
  199. ++foundItem;
  200. break;
  201. case 2:
  202. ++foundItem;
  203. break;
  204. case 3:
  205. default:
  206. return update_flash(buf[bufPtr - 1]);
  207. }
  208. }
  209. printf("Failed to read %s\n",section);
  210. return BOOT_DEFAULT;
  211. }
  212. TSBootInfo* find_boot_info(void)
  213. {
  214. unsigned bootimage = scan_flash();
  215. TSBootInfo* info = (TSBootInfo*)malloc(sizeof(TSBootInfo));
  216. switch(bootimage){
  217. case TRY_WORKING:
  218. info->address = CFG_WORKING_KERNEL_ADDRESS;
  219. break;
  220. case BOOT_WORKING :
  221. info->address = CFG_WORKING_KERNEL_ADDRESS;
  222. break;
  223. case BOOT_DEFAULT:
  224. default:
  225. info->address= CFG_DEFAULT_KERNEL_ADDRESS;
  226. }
  227. info->size = *((unsigned int *)(info->address ));
  228. return info;
  229. }
  230. void barcobcd_boot(void)
  231. {
  232. TSBootInfo* start;
  233. char *bootm_args[2];
  234. char *buf;
  235. int cnt;
  236. buf = (char *)(0x00800000);
  237. /* make certain there are enough chars to print the command line here!
  238. */
  239. bootm_args[0]=(char *)malloc(16*sizeof(char));
  240. bootm_args[1]=(char *)malloc(16*sizeof(char));
  241. start = find_boot_info();
  242. printf("Booting kernel at address %#10x with size %#10x\n",
  243. start->address, start->size);
  244. /* give length of the kernel image to bootm */
  245. sprintf(bootm_args[0],"%x",start->size);
  246. /* give address of the kernel image to bootm */
  247. sprintf(bootm_args[1],"%x",buf);
  248. printf("flash address: %#10x\n",start->address+8);
  249. printf("buf address: %#10x\n",buf);
  250. /* aha, we reserve 8 bytes here... */
  251. for (cnt = 0; cnt < start->size ; cnt++){
  252. buf[cnt] = ((char *)start->address)[cnt+8];
  253. }
  254. /* initialise RAM memory */
  255. *((unsigned int *)0xFEC00000) = 0x00141A98;
  256. do_bootm(NULL,0,2,bootm_args);
  257. }
  258. int barcobcd_boot_image(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  259. {
  260. #if 0
  261. if (argc > 1) {
  262. printf ("Usage:\n (%d) %s\n", argc, cmdtp->usage);
  263. return 1;
  264. }
  265. #endif
  266. barcobcd_boot();
  267. return 0;
  268. }
  269. /* Currently, boot_working and boot_default are the same command. This is
  270. * left in here to see what we'll do in the future */
  271. U_BOOT_CMD(
  272. try_working, 1, 1, barcobcd_boot_image,
  273. " try_working - check flash value and boot the appropriate image\n",
  274. "\n"
  275. );
  276. U_BOOT_CMD(
  277. boot_working, 1, 1, barcobcd_boot_image,
  278. " boot_working - check flash value and boot the appropriate image\n",
  279. "\n"
  280. );
  281. U_BOOT_CMD(
  282. boot_default, 1, 1, barcobcd_boot_image,
  283. " boot_default - check flash value and boot the appropriate image\n",
  284. "\n"
  285. );
  286. /*
  287. * We are not using serial communication, so just provide empty functions
  288. */
  289. int serial_init(void){return 0;}
  290. void serial_setbrg(void){}
  291. void serial_putc(const char c){}
  292. void serial_puts(const char *c){}
  293. void serial_addr(unsigned int i){}
  294. int serial_getc(void){return 0;}
  295. int serial_tstc(void){return 0;}
  296. unsigned long post_word_load(void){return 0l;};
  297. void post_word_store(unsigned long val){}