+ read_byte(0, &buffer, &fake);
+ return *buffer;
+}
+
+static __inline__ unsigned int read_le32(void *buf)
+{
+ unsigned char *p;
+
+ p = buf;
+ return ((unsigned int)p[0] + ((unsigned int)p[1] << 8) +
+ ((unsigned int)p[2] << 16) +((unsigned int)p[3] << 24));
+}
+
+static void print_char(char ch)
+{
+ if (ch == '\n')
+ board_putc('\r');
+ board_putc(ch);
+}
+
+static void print_str(char * str)
+{
+ while ( *str != 0 )
+ print_char(*str++);
+}
+
+static void print_hex(int val)
+{
+ int i;
+ int tmp;
+
+ print_str("0x");
+ for ( i=0 ; i<8 ; i++ ) {
+ tmp = (val >> ((7-i) * 4 )) & 0xf;
+ tmp = tmp < 10 ? (tmp + '0') : (tmp + 'A' - 10);
+ board_putc(tmp);
+ }
+}
+
+static unsigned char *find_kernel(void)
+{
+ struct trx_header *hdr;
+ unsigned char *ret;
+
+ print_str("Looking for TRX header... ");
+ /* look for trx header, 32-bit data access */
+ hdr = NULL;
+ for (ret = ((unsigned char *) KSEG1ADDR(ADM5120_FLASH_START));
+ ret < ((unsigned char *)KSEG1ADDR(ADM5120_FLASH_END));
+ ret += TRX_ALIGN) {
+
+ if (read_le32(ret) == TRX_MAGIC) {
+ hdr = (struct trx_header *)ret;
+ break;
+ }
+ }
+
+ if (hdr == NULL) {
+ print_str("not found!\n");
+ return NULL;
+ }
+
+ print_str("found at ");
+ print_hex((unsigned int)ret);
+ print_str(", kernel in partition ");
+
+ /* compressed kernel is in the partition 0 or 1 */
+ if ((read_le32(&hdr->offsets[1]) == 0) ||
+ (read_le32(&hdr->offsets[1]) > 65536)) {
+ ret += read_le32(&hdr->offsets[0]);
+ print_str("0\n");
+ } else {
+ ret += read_le32(&hdr->offsets[1]);
+ print_str("1\n");
+ }
+
+ return ret;