|
|
1.1 root 1: /******************************************************************************
2: * Copyright (c) 2004, 2008 IBM Corporation
3: * All rights reserved.
4: * This program and the accompanying materials
5: * are made available under the terms of the BSD License
6: * which accompanies this distribution, and is available at
7: * http://www.opensource.org/licenses/bsd-license.php
8: *
9: * Contributors:
10: * IBM Corporation - initial implementation
11: *****************************************************************************/
12:
13: #include <cpu.h>
14: #include <string.h>
15: #include <stdio.h>
16: #include <stdlib.h>
17: #include <stdint.h>
18: #include <rtas.h>
19: #include <hw.h>
20:
21: volatile unsigned char *uart;
22: volatile unsigned char u4Flag;
23:
24: void
25: io_init(void)
26: {
27: // read ID register: only if it is a PC87427, enable serial2
28: store8_ci(0xf400002e, 0x20);
29: if (load8_ci(0xf400002f) != 0xf2) {
30: uart = (volatile unsigned char *) 0xf40003f8;
31: u4Flag = 0;
32: } else {
33: uart = (volatile unsigned char *) 0xf40002f8;
34: u4Flag = 1;
35: }
36: }
37:
38: void
39: display_char(char ch)
40: {
41: volatile int i = 0;
42: volatile unsigned char *uart = (volatile unsigned char *) 0xf40002f8;
43: int cnt = 2;
44: while (cnt--) {
45: set_ci();
46: while (!(uart[5] & 0x20)) {
47: i++;
48: }
49: uart[0] = ch;
50: clr_ci();
51: uart += 0x100;
52: }
53: }
54:
55: size_t
56: write(int fd __attribute((unused)), const void *buf, size_t cnt)
57: {
58: while (cnt--) {
59: display_char(*(char *) buf);
60: if (*(char *) buf++ == '\n')
61: display_char('\r');
62: }
63: return 0;
64: }
65:
66: void *
67: sbrk(int incr __attribute((unused)))
68: {
69: return (void *) -1;
70: }
71:
72:
73:
74: int
75: rtas_display_character(rtas_args_t * pArgs)
76: {
77: int retVal = 0;
78: display_char((char) pArgs->args[0]);
79: return retVal;
80: }
81:
82: unsigned long
83: check_flash_image(unsigned long rombase, unsigned long length,
84: unsigned long start_crc)
85: {
86: const uint32_t CrcTableHigh[16] = {
87: 0x00000000, 0x4C11DB70, 0x9823B6E0, 0xD4326D90,
88: 0x34867077, 0x7897AB07, 0xACA5C697, 0xE0B41DE7,
89: 0x690CE0EE, 0x251D3B9E, 0xF12F560E, 0xBD3E8D7E,
90: 0x5D8A9099, 0x119B4BE9, 0xC5A92679, 0x89B8FD09
91: };
92: const uint32_t CrcTableLow[16] = {
93: 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9,
94: 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005,
95: 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
96: 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD
97: };
98:
99: char *Buffer = (char *) rombase;
100: uint32_t AccumCRC = start_crc;
101: char val;
102: uint32_t Temp;
103: while (length-- > 0) {
104: set_ci();
105: val = *Buffer;
106: clr_ci();
107: Temp = ((AccumCRC >> 24) ^ val) & 0x000000ff;
108: AccumCRC <<= 8;
109: AccumCRC ^= CrcTableHigh[Temp / 16];
110: AccumCRC ^= CrcTableLow[Temp % 16];
111: ++Buffer;
112: }
113: return AccumCRC;
114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.