URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/trunk
- from Rev 136 to Rev 140
- ↔ Reverse comparison
Rev 136 → Rev 140
/orpmon/include/build.h
1,?rev1len? → ?rev2line?,?rev2len?
|
#define BUILD_VERSION "Mon Jun 28 16:45:16 CEST 2010" |
/orpmon/include/string.h
37,9 → 37,10
|
/* Basic mem functions */ |
extern void *memcpy(void *dest, const void *src, size_t n); |
extern unsigned char memcpy_crc(void *dest, const void *src, size_t n); |
extern void *memmove(void *dest, void *src, size_t n); |
extern int memcmp(const void *s1, const void *s2, size_t n); |
extern void *memchr(const void *s, int c, size_t n); |
extern void *memchr(const void *s, char c, size_t n); |
extern void *memset(void *d, int c, size_t n); |
|
#endif |
/orpmon/include/spincursor.h
0,0 → 1,5
|
void spincursor(void); |
void enable_spincursor(void); |
void disable_spincursor(void); |
|
/orpmon/include/eth.h
1,14 → 1,47
#define ETH_REG_BASE ETH_BASE |
#define ETH_BD_BASE (ETH_BASE + 0x400) |
#define ETH_TOTAL_BD 128 |
#define ETH_TOTAL_BD 32 |
#define ETH_MAXBUF_LEN 0x600 |
|
#define ETH_TXBD_NUM 8 |
#define ETH_TXBD_NUM 16 |
#define ETH_TXBD_NUM_MASK (ETH_TXBD_NUM - 1) |
#define ETH_RXBD_NUM 8 |
#define ETH_RXBD_NUM 16 |
#define ETH_RXBD_NUM_MASK (ETH_RXBD_NUM - 1) |
|
typedef unsigned int uint; |
|
/* Ethernet configuration registers */ |
typedef struct _oeth_regs { |
uint moder; /* Mode Register */ |
uint int_src; /* Interrupt Source Register */ |
uint int_mask; /* Interrupt Mask Register */ |
uint ipgt; /* Back to Bak Inter Packet Gap Register */ |
uint ipgr1; /* Non Back to Back Inter Packet Gap Register 1 */ |
uint ipgr2; /* Non Back to Back Inter Packet Gap Register 2 */ |
uint packet_len; /* Packet Length Register (min. and max.) */ |
uint collconf; /* Collision and Retry Configuration Register */ |
uint tx_bd_num; /* Transmit Buffer Descriptor Number Register */ |
uint ctrlmoder; /* Control Module Mode Register */ |
uint miimoder; /* MII Mode Register */ |
uint miicommand; /* MII Command Register */ |
uint miiaddress; /* MII Address Register */ |
uint miitx_data; /* MII Transmit Data Register */ |
uint miirx_data; /* MII Receive Data Register */ |
uint miistatus; /* MII Status Register */ |
uint mac_addr0; /* MAC Individual Address Register 0 */ |
uint mac_addr1; /* MAC Individual Address Register 1 */ |
uint hash_addr0; /* Hash Register 0 */ |
uint hash_addr1; /* Hash Register 1 */ |
} oeth_regs; |
|
/* Ethernet buffer descriptor */ |
typedef struct _oeth_bd { |
uint len_status; |
uint addr; /* Buffer address */ |
} oeth_bd; |
|
|
/* Ethernet buffer descriptor */ |
typedef struct _eth_bd { |
volatile unsigned long len_status; /* Buffer length and status */ |
volatile unsigned long addr; /* Buffer address */ |
21,6 → 54,8
extern void eth_halt(void); |
extern void init_rx_bd_pool(void); |
extern void init_tx_bd_pool(void); |
extern void eth_int_enable(void); |
extern void eth_toggle_traffic_mon(void); |
|
/* Tx BD */ |
#define ETH_TX_BD_READY 0x8000 /* Tx BD Ready */ |
/orpmon/include/net.h
13,6 → 13,9
#define __NET_H__ |
|
|
// TFTP running checksum defined here... tftp.h not in common include/ path |
extern unsigned long TFTP_CHKSUM; |
|
/* |
* The number of receive packet buffers, and the required packet buffer |
* alignment in memory. |
137,12 → 140,12
*/ |
typedef struct |
{ |
unsigned short ar_hrd; /* Format of hardware address */ |
# define ARP_ETHER 1 /* Ethernet hardware address */ |
unsigned short ar_pro; /* Format of protocol address */ |
unsigned char ar_hln; /* Length of hardware address */ |
unsigned char ar_pln; /* Length of protocol address */ |
unsigned short ar_op; /* Operation */ |
unsigned short ar_hrd; /* Format of hardware address*/ |
# define ARP_ETHER 1 /* Ethernet hardware address*/ |
unsigned short ar_pro; /* Format of protocol address*/ |
unsigned char ar_hln; /* Length of hardware address*/ |
unsigned char ar_pln; /* Length of protocol address*/ |
unsigned short ar_op; /* Operation */ |
# define ARPOP_REQUEST 1 /* Request to resolve address */ |
# define ARPOP_REPLY 2 /* Response to previous request */ |
|
156,10 → 159,10
*/ |
unsigned char ar_data[0]; |
#if 0 |
unsigned char ar_sha[]; /* Sender hardware address */ |
unsigned char ar_spa[]; /* Sender protocol address */ |
unsigned char ar_tha[]; /* Target hardware address */ |
unsigned char ar_tpa[]; /* Target protocol address */ |
unsigned char ar_sha[]; /* Sender hardware address*/ |
unsigned char ar_spa[]; /* Sender protocol address*/ |
unsigned char ar_tha[]; /* Target hardware address*/ |
unsigned char ar_tpa[]; /* Target protocol address*/ |
#endif /* 0 */ |
} ARP_t; |
|
238,7 → 241,7
extern unsigned char NetServerEther[6]; /* Boot server enet address */ |
extern IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */ |
extern IPaddr_t NetServerIP; /* Server IP addr (0 = unknown) */ |
volatile unsigned char * NetTxPacket; /* THE transmit packet */ |
extern volatile unsigned char * NetTxPacket; /* THE transmit packet */ |
extern volatile unsigned char * NetRxPackets[PKTBUFSRX];/* Receive packets */ |
extern volatile unsigned char * NetRxPkt; /* Current receive packet */ |
extern int NetRxPktLen; /* Current rx packet length */ |
/orpmon/include/board.h
1,8 → 1,8
#ifndef _BOARD_H_ |
#define _BOARD_H_ |
|
#define CFG_IN_FLASH 1 |
#define MC_ENABLED 1 |
#define CFG_IN_FLASH 0 |
//#define MC_ENABLED 1 |
|
//LAN controller |
//#define SMC91111_LAN 1 |
11,9 → 11,18
/* BOARD |
* 0 - bender |
* 1 - marvin |
* 2 - ORSoC A3PE1500 usbethdev board |
* 3 - ORSoC A3P1000 usbethdev board |
*/ |
#define BOARD 1 |
#define BOARD 3 |
|
/* Ethernet IP and TFTP config |
* 0 - JB ORSoC board |
* 1 - AE ORSoC board |
* 2 - JB Southpole board |
*/ |
#define IPCONFIG 0 |
|
#if BOARD==0 |
// Nibbler on bender1 |
|
36,7 → 45,7
#elif BOARD==1 |
//Marvin |
|
# define IC_ENABLE 0 |
# define IC_ENABLE 1 |
# define IC_SIZE 8192 |
# define DC_ENABLE 0 |
# define DC_SIZE 8192 |
49,8 → 58,47
# define IN_CLK 50000000 |
# define FLASH_ORG_16_2 1 |
# define BOARD_DEF_NAME "marvin" |
#elif BOARD==2 |
//ORSoC usbethdev board |
|
# define IC_ENABLE 1 |
# define IC_SIZE 8192 |
# define DC_ENABLE 0 |
# define DC_SIZE 8192 |
# define FLASH_BASE_ADDR 0xf0000000 |
# define FLASH_SIZE 0x04000000 |
# define FLASH_BLOCK_SIZE 0x00040000 |
# define START_ADD 0x0 |
# define SDRAM_SIZE 0x02000000 |
# define SDRAM_ROW_SIZE 0x00000400 |
# define SDRAM_BANK_SIZE 0x00800000 |
//# define IN_CLK 32000000 |
//# define IN_CLK 24000000 |
# define IN_CLK 20000000 |
//# define IN_CLK 16000000 |
//# define IN_CLK 17000000 |
|
# define FLASH_ORG_16_2 1 |
# define BOARD_DEF_NAME "ORSoC devboard" |
#elif BOARD==3 |
//ORSoC A3P1000 usbethdev board |
|
# define IC_ENABLE 1 |
# define IC_SIZE 4096 |
# define DC_ENABLE 0 |
# define DC_SIZE 8192 |
# define FLASH_BASE_ADDR 0xf0000000 |
# define FLASH_SIZE 0x04000000 |
# define FLASH_BLOCK_SIZE 0x00040000 |
# define START_ADD 0x0 |
# define SDRAM_SIZE 0x02000000 |
# define SDRAM_ROW_SIZE 0x00000400 |
# define SDRAM_BANK_SIZE 0x00800000 |
# define IN_CLK 20000000 |
# define FLASH_ORG_16_2 1 |
# define BOARD_DEF_NAME "ORSoC A3P1000 devboard" |
|
#else |
|
//Custom Board |
# define IC_ENABLE 0 |
# define IC_SIZE 8192 |
67,10 → 115,86
|
#endif |
|
|
// IP tboot configs |
#if IPCONFIG==0 |
|
#define BOARD_DEF_IP 0xc0a8649b // 192.168.100.155 |
#define BOARD_DEF_MASK 0xffffff00 // 255.255.255.0 |
#define BOARD_DEF_GW 0xc0a86401 // 192.168.100.1 |
#define BOARD_DEF_TBOOT_SRVR 0xc0a86469 //"192.168.100.105" |
#define BOARD_DEF_IMAGE_NAME "boot.img" |
#define BOARD_DEF_LOAD_SPACE 0xa00000 |
#define ETH_MDIOPHYADDR 0x00 |
#define ETH_MACADDR0 0x00 |
#define ETH_MACADDR1 0x12 |
#define ETH_MACADDR2 0x34 |
#define ETH_MACADDR3 0x56 |
#define ETH_MACADDR4 0x78 |
#define ETH_MACADDR5 0x9a |
|
#elif IPCONFIG==1 |
|
#define BOARD_DEF_IP 0xc0a8649c // 192.168.100.156 |
#define BOARD_DEF_MASK 0xffffff00 // 255.255.255.0 |
#define BOARD_DEF_GW 0xc0a86401 // 192.168.100.1 |
#define BOARD_DEF_TBOOT_SRVR 0xc0a864e3 //"192.168.100.227" |
#define BOARD_DEF_IMAGE_NAME "boot.img" |
#define BOARD_DEF_LOAD_SPACE 0xa00000 |
#define ETH_MDIOPHYADDR 0x00 |
#define ETH_MACADDR0 0xad |
#define ETH_MACADDR1 0xda |
#define ETH_MACADDR2 0x34 |
#define ETH_MACADDR3 0x56 |
#define ETH_MACADDR4 0x78 |
#define ETH_MACADDR5 0x9a |
|
#elif IPCONFIG==2 |
|
#define BOARD_DEF_IP 0xac1e0002 // 172.30.0.2 |
#define BOARD_DEF_MASK 0xffffff00 // 255.255.255.0 |
#define BOARD_DEF_GW 0xac1e0001 //"172.30.0.1" |
#define BOARD_DEF_TBOOT_SRVR 0xac1e0001 //"172.30.0.1" |
#define BOARD_DEF_IMAGE_NAME "boot.img" |
#define BOARD_DEF_LOAD_SPACE 0xa00000 |
#define ETH_MDIOPHYADDR 0x00 |
#define ETH_MACADDR0 0x00 |
#define ETH_MACADDR1 0x12 |
#define ETH_MACADDR2 0x34 |
#define ETH_MACADDR3 0x56 |
#define ETH_MACADDR4 0x78 |
#define ETH_MACADDR5 0x9a |
|
#else // Some custom one |
|
#define BOARD_DEF_IP 0x0a01010a // 10.1.1.10 |
#define BOARD_DEF_MASK 0xffffff00 // 255.255.255.0 |
#define BOARD_DEF_GW 0x0a010101 // 10.1.1.10 |
#define BOARD_DEF_TBOOT_SRVR 0x0a010101 // 10.1.1.10 |
#define BOARD_DEF_IMAGE_NAME "boot.img" |
#define BOARD_DEF_LOAD_SPACE 0xa00000 |
#define ETH_MDIOPHYADDR 0x00 |
#define ETH_MACADDR0 0xad |
#define ETH_MACADDR1 0xaa |
#define ETH_MACADDR2 0x34 |
#define ETH_MACADDR3 0x56 |
#define ETH_MACADDR4 0x78 |
#define ETH_MACADDR5 0x9a |
|
#endif |
|
|
|
#define UART_BAUD_RATE 115200 |
|
#define TICKS_PER_SEC 100 |
|
|
#define MS_PER_SEC 1000 |
#define US_PER_SEC 1000000 |
#define US_PER_TICK (US_PER_SEC/TICKS_PER_SEC) |
#define TICKS_PER_US (TICKS_PER_SEC*1000000) |
|
#define STACK_SIZE 0x10000 |
|
#if CONFIG_OR32_MC_VERSION==1 |
79,8 → 203,8
#elif CONFIG_OR32_MC_VERSION==2 |
// Highland MC |
# include "mc-init-2.h" |
#else |
# error "no memory controler chosen" |
//#else |
//# error "no memory controler chosen" |
#endif |
|
#define UART_BASE 0x90000000 |
87,8 → 211,8
#define UART_IRQ 2 |
#define ETH_BASE 0x92000000 |
#define ETH_IRQ 4 |
#define MC_BASE_ADDR 0x93000000 |
#define SPI_BASE 0xb9000000 |
|
#define SPI_BASE 0xb0000000 |
#define CRT_BASE_ADDR 0x97000000 |
#define ATA_BASE_ADDR 0x9e000000 |
#define KBD_BASE_ADD 0x94000000 |
95,29 → 219,9
#define KBD_IRQ 5 |
|
#define SANCHO_BASE_ADD 0x98000000 |
#define ETH_DATA_BASE 0xa8000000 /* Address for ETH_DATA */ |
#define ETH_DATA_BASE (SDRAM_SIZE - (0x600 * 128)) /* Address for ETH_DATA */ |
|
#if 1 |
#define BOARD_DEF_IP 0x0100002a /* 1.0.0.42 */ |
#define BOARD_DEF_MASK 0xffffff00 /* 255.255.255.0 */ |
#define BOARD_DEF_GW 0x01000001 /* 1.0.0.1 */ |
#define BOARD_DEF_TBOOT_SRVR "1.0.0.66" |
#else |
#define BOARD_DEF_IP 0x0aed012a /* 10.237.1.42 */ |
#define BOARD_DEF_MASK 0xffffff00 /* 255.255.255.0 */ |
#define BOARD_DEF_GW 0x0aed0101 /* 10.0.0.1 */ |
#define BOARD_DEF_TBOOT_SRVR "10.237.1.27" |
#endif |
|
|
#define ETH_MACADDR0 0x00 |
#define ETH_MACADDR1 0x12 |
#define ETH_MACADDR2 0x34 |
#define ETH_MACADDR3 0x56 |
#define ETH_MACADDR4 0x78 |
#define ETH_MACADDR5 0x9a |
|
#define CRT_ENABLED 1 |
#define CRT_ENABLED 0 |
#define FB_BASE_ADDR 0xa8000000 |
|
/* Whether online help is available -- saves space */ |
127,7 → 231,7
#define SELF_CHECK 0 |
|
/* Whether we have keyboard suppport */ |
#define KBD_ENABLED 1 |
#define KBD_ENABLED 0 |
|
/* Keyboard buffer size */ |
#define KBDBUF_SIZE 256 |
/orpmon/include/common.h
60,6 → 60,9
int (*func)(int argc, char *argv[]); |
} command_struct; |
|
// Keep a CRC during TFTP receive |
#define TFTP_CALC_CRC |
|
typedef struct { |
unsigned long eth_ip; |
unsigned long eth_mask; |
80,7 → 83,7
extern int ctrlc (void); |
extern void putc (const char c); |
extern int printf (const char *fmt, ...); |
|
extern void show_mem (int start, int stop); |
extern unsigned long parse_ip (char *ip); |
|
/* simulator stdout */ |
/orpmon/reset.S
55,6 → 55,7
.endif |
|
.org 0x100 |
|
.if IN_FLASH |
.section .reset, "ax" |
.else |
77,11 → 78,25
|
.if IN_FLASH |
.section .vectors, "ax" |
.org 0x200 |
.else |
.org (0x200 - 0x100 + _reset) |
.endif |
_buserr: |
/* Just trap */ |
l.trap 0 |
l.nop |
l.j 0 |
l.nop |
|
|
.if IN_FLASH |
.section .vectors, "ax" |
.org 0x500 |
.else |
.org (0x500 - 0x100 + _reset) |
.endif |
|
_tickint: |
l.addi r1,r1,-128 |
l.sw 0x4(r1),r2 |
l.movhi r2,hi(_tick) |
95,7 → 110,9
.else |
.org (0x600 - 0x100 + _reset) |
.endif |
|
_alignerr: |
.if 0 |
/* Let's crash on align errors */ |
l.addi r1,r1,-128 |
l.sw 0x08(r1),r2 |
l.movhi r2,hi(_align) |
102,13 → 119,31
l.ori r2,r2,lo(_align) |
l.jr r2 |
l.nop |
.endif |
l.trap 0 |
l.nop |
l.j 0 |
l.nop |
|
.if IN_FLASH |
.org 0x700 |
.else |
.org (0x700 - 0x100 + _reset) |
.endif |
_illinsn: |
/* Just trap */ |
l.trap 0 |
l.nop |
l.j 0 |
l.nop |
|
|
.if IN_FLASH |
.org 0x800 |
.else |
.org (0x800 - 0x100 + _reset) |
.endif |
|
_userint: |
l.addi r1,r1,-128 |
l.sw 0x4(r1),r2 |
l.movhi r2,hi(_int_wrapper) |
119,9 → 154,9
.section .text |
_start: |
.if IN_FLASH |
l.jal _init_mc |
/* l.jal _init_mc |
l.nop |
|
*/ |
/* Wait for SDRAM */ |
l.addi r3,r0,0x1000 |
1: l.sfeqi r3,0 |
166,7 → 201,10
l.addi r4,r0,0 |
3: |
.endif |
|
/* |
l.jal _ic_disable |
l.nop |
*/ |
.if IC_ENABLE |
l.jal _ic_enable |
l.nop |
211,6 → 249,32
l.jr r9 |
l.nop |
|
_ic_disable: |
|
l.addi r10,r0,0 |
l.addi r11,r0,IC_SIZE |
1: |
l.mtspr r0,r10,SPR_ICBIR |
l.sfne r10,r11 |
l.bf 1b |
l.addi r10,r10,16 |
|
|
l.mfspr r10,r0,SPR_SR |
l.movhi r11, 0xffff |
l.ori r11, r11, 0xffef |
l.and r10, r10, r11 |
l.ori r10, r10, SPR_SR_SM |
l.mtspr r0,r10,SPR_SR |
l.nop |
l.nop |
l.nop |
l.nop |
l.nop |
|
l.jr r9 |
l.nop |
|
_dc_enable: |
|
/* Flush DC */ |
230,195 → 294,7
l.jr r9 |
l.nop |
|
.if IN_FLASH |
#if CONFIG_OR32_MC_VERSION==1 |
_init_mc: |
|
l.movhi r3,hi(MC_BASE_ADDR) |
l.ori r3,r3,lo(MC_BASE_ADDR) |
|
l.addi r4,r3,MC_CSC(0) |
l.movhi r5,hi(FLASH_BASE_ADDR) |
l.srai r5,r5,6 |
l.ori r5,r5,0x0025 |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_TMS(0) |
l.movhi r5,hi(FLASH_TMS_VAL) |
l.ori r5,r5,lo(FLASH_TMS_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_BA_MASK |
l.addi r5,r0,MC_MASK_VAL |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_CSR |
l.movhi r5,hi(MC_CSR_VAL) |
l.ori r5,r5,lo(MC_CSR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_TMS(1) |
l.movhi r5,hi(SDRAM_TMS_VAL) |
l.ori r5,r5,lo(SDRAM_TMS_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_CSC(1) |
l.movhi r5,hi(SDRAM_BASE_ADDR) |
l.srai r5,r5,6 |
l.ori r5,r5,0x0411 |
l.sw 0(r4),r5 |
|
#ifdef ETH_DATA_BASE |
l.addi r4,r3,MC_CSC(2) |
l.movhi r5,hi(ETH_DATA_BASE) |
l.srai r5,r5,6 |
l.ori r5,r5,0x0005 |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_TMS(2) |
l.movhi r5,0xffff |
l.ori r5,r5,0xffff |
l.sw 0(r4),r5 |
#endif |
#ifdef SANCHO_BASE_ADD |
l.addi r4,r3,MC_CSC(2) |
l.movhi r5,hi(SANCHO_BASE_ADD) |
l.srai r5,r5,6 |
l.ori r5,r5,0x0001 |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_TMS(2) |
l.movhi r5,0x101 |
l.ori r5,r5,0x101 |
l.sw 0(r4),r5 |
#endif |
|
l.jr r9 |
l.nop |
#elif CONFIG_OR32_MC_VERSION==2 |
_init_mc: |
|
l.movhi r3,hi(MC_BASE_ADDR) |
l.ori r3,r3,lo(MC_BASE_ADDR) |
|
l.addi r4,r3,MC_BAR_0 |
l.movhi r5,hi(FLASH_BAR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_AMR_0 |
l.movhi r5,hi(FLASH_AMR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_WTR_0 |
l.movhi r5,hi(FLASH_WTR_VAL) |
l.ori r5,r5,lo(FLASH_WTR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_RTR_0 |
l.movhi r5,hi(FLASH_RTR_VAL) |
l.ori r5,r5,lo(FLASH_RTR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_OSR |
l.movhi r5,hi(0x40000000) |
l.ori r5,r5,lo(0x40000000) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_BAR_4 |
l.movhi r5,hi(SDRAM_BAR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_AMR_4 |
l.movhi r5,hi(SDRAM_AMR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_CCR_4 |
l.movhi r5,hi(0x00ef0004) |
l.ori r5,r5,lo(0x00ef0004) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_RATR |
l.movhi r5,hi(SDRAM_RATR_VAL) |
l.ori r5,r5,lo(SDRAM_RATR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_RCDR |
l.movhi r5,hi(SDRAM_RCDR_VAL) |
l.ori r5,r5,lo(SDRAM_RCDR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_RCTR |
l.movhi r5,hi(SDRAM_RCTR_VAL) |
l.ori r5,r5,lo(SDRAM_RCTR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_REFCTR |
l.movhi r5,hi(SDRAM_REFCTR_VAL) |
l.ori r5,r5,lo(SDRAM_REFCTR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_PTR |
l.movhi r5,hi(SDRAM_PTR_VAL) |
l.ori r5,r5,lo(SDRAM_PTR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_RRDR |
l.movhi r5,hi(SDRAM_RRDR_VAL) |
l.ori r5,r5,lo(SDRAM_RRDR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_RIR |
l.movhi r5,hi(SDRAM_RIR_VAL) |
l.ori r5,r5,lo(SDRAM_RIR_VAL) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_OSR |
l.movhi r5,hi(0x5e000000) |
l.ori r5,r5,lo(0x5e000000) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_ORR |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_OSR |
l.movhi r5,hi(0x6e000000) |
l.ori r5,r5,lo(0x6e000000) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_ORR |
l.sw 0(r4),r5 |
l.sw 0(r4),r5 |
l.sw 0(r4),r5 |
l.sw 0(r4),r5 |
l.sw 0(r4),r5 |
l.sw 0(r4),r5 |
l.sw 0(r4),r5 |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_OSR |
l.movhi r5,hi(0x7e000023) |
l.ori r5,r5,lo(0x7e000023) |
l.sw 0(r4),r5 |
|
l.addi r4,r3,MC_ORR |
l.sw 0(r4),r5 |
|
#ifdef FLASH_ORG_16_1 |
l.addi r4,r3,MC_CCR_4 |
l.movhi r5,hi(0xc0ae0004) |
l.ori r5,r5,lo(0xc0ae0004) |
l.sw 0(r4),r5 |
#else |
# error "no configuration for this data bus width" |
#endif |
l.jr r9 |
l.nop |
#else |
# error "no memory controler chosen" |
#endif |
|
.endif |
|
_tick: |
l.sw 0x8(r1),r4 |
l.sw 0xc(r1),r5 |
/orpmon/services/arp.c
27,10 → 27,11
#include "bootp.h" |
#include "tftp.h" |
#include "arp.h" |
#include "string.h" |
|
#define TIMEOUT 5 /* Seconds before trying ARP again */ |
#define TIMEOUT_COUNT 1 /* # of timeouts before giving up */ |
|
#define DEBUG // jb |
static void ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len); |
static void ArpTimeout(void); |
|
89,16 → 90,22
arp->ar_hln = 6; |
arp->ar_pln = 4; |
arp->ar_op = ARPOP_REQUEST; |
NetCopyEther(&arp->ar_data[0], NetOurEther); /* source ET addr */ |
*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; /* source IP addr */ |
NetCopyEther(&arp->ar_data[0], NetOurEther); /* source ET addr */ |
//*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; /* source IP addr */ |
memcpy(&arp->ar_data[6], (unsigned char*) &NetOurIP, 4); |
|
for (i=10; i<16; ++i) { |
arp->ar_data[i] = 0; /* dest ET addr = 0 */ |
arp->ar_data[i] = 0; /* dest ET addr = 0*/ |
} |
|
if((NetServerIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) { |
*(IPaddr_t *)(&arp->ar_data[16]) = NetOurGatewayIP; |
//*(IPaddr_t *)(&arp->ar_data[16]) = NetOurGatewayIP; |
memcpy(&arp->ar_data[16], (unsigned char*) &NetOurGatewayIP, |
sizeof(IPaddr_t)); |
} else { |
*((IPaddr_t *)(&(arp->ar_data[16]))) = NetServerIP; |
//*((IPaddr_t *)(&(arp->ar_data[16]))) = NetServerIP; |
memcpy(&arp->ar_data[16], (unsigned char*) &NetServerIP, |
sizeof(IPaddr_t)); |
} |
|
NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE); |
/orpmon/services/bootp.c
7,7 → 7,7
* Copyright 2000 Paolo Scaffardi |
*/ |
|
#if 0 |
#if 1 |
#define DEBUG 1 /* general debug */ |
#define DEBUG_BOOTP_EXT 1 /* Debug received vendor fields */ |
#endif |
/orpmon/services/net.c
66,9 → 66,9
#include "rarp.h" |
#include "arp.h" |
#if OC_LAN==1 |
#include "eth.h" |
#include "eth.h" |
#else if SMC91111_LAN==1 |
#include "smc91111.h" |
#include "smc91111.h" |
#endif |
|
#if 0 |
90,7 → 90,7
unsigned long NetBootFileXferSize; /* The actual transferred size of the bootfile (in bytes) */ |
unsigned char NetOurEther[6]; /* Our ethernet address */ |
unsigned char NetServerEther[6] = /* Boot server enet address */ |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */ |
IPaddr_t NetServerIP; /* Our IP addr (0 = unknown) */ |
volatile unsigned char *NetRxPkt; /* Current receive packet */ |
97,7 → 97,7
int NetRxPktLen; /* Current rx packet length */ |
unsigned NetIPID; /* IP packet ID */ |
unsigned char NetBcastAddr[6] = /* Ethernet bcast address */ |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
int NetState; /* Network loop state */ |
|
char BootFile[128]; /* Boot File name */ |
121,142 → 121,147
NetLoop(proto_t protocol) |
{ |
#if 1 |
if (!NetTxPacket) { |
int i; |
if (!NetTxPacket) { |
int i; |
printf("NetTxPacket begin setup\n"); |
/* |
* Setup packet buffers, aligned correctly. |
*/ |
NetTxPacket = &PktBuf[0] + (PKTALIGN - 1); |
NetTxPacket -= (unsigned long)NetTxPacket % PKTALIGN; |
for (i = 0; i < PKTBUFSRX; i++) { |
NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN; |
} |
} |
|
/* |
* Setup packet buffers, aligned correctly. |
*/ |
NetTxPacket = &PktBuf[0] + (PKTALIGN - 1); |
NetTxPacket -= (unsigned long)NetTxPacket % PKTALIGN; |
for (i = 0; i < PKTBUFSRX; i++) { |
NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN; |
} |
} |
eth_halt(); |
eth_init(NetReceive); |
|
eth_halt(); |
eth_init(NetReceive); |
restart: |
|
restart: |
NetCopyEther(NetOurEther, global.eth_add); |
|
NetCopyEther(NetOurEther, global.eth_add); |
NetState = NETLOOP_CONTINUE; |
|
NetState = NETLOOP_CONTINUE; |
/* |
* Start the ball rolling with the given start function. From |
* here on, this code is a state machine driven by received |
* packets and timer events. |
*/ |
|
/* |
* Start the ball rolling with the given start function. From |
* here on, this code is a state machine driven by received |
* packets and timer events. |
*/ |
if (protocol == TFTP) { /* TFTP */ |
NetOurIP = global.ip; |
NetServerIP = global.srv_ip; |
NetOurGatewayIP = global.gw_ip; |
NetOurSubnetMask= global.mask; |
|
if (protocol == TFTP) { /* TFTP */ |
NetOurIP = global.ip; |
NetServerIP = global.srv_ip; |
NetOurGatewayIP = global.gw_ip; |
NetOurSubnetMask= global.mask; |
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
|
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
/* always use ARP to get server ethernet address */ |
ArpTry = 0; |
|
/* always use ARP to get server ethernet address */ |
ArpTry = 0; |
ArpRequest (); |
ArpRequest (); |
|
#if (CONFIG_COMMANDS & CFG_CMD_DHCP) |
} else if (protocol == DHCP) { |
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
} else if (protocol == DHCP) { |
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
|
/* Start with a clean slate... */ |
NetOurIP = 0; |
NetServerIP = 0; |
DhcpRequest(); /* Basically same as BOOTP */ |
/* Start with a clean slate... */ |
NetOurIP = 0; |
NetServerIP = 0; |
DhcpRequest(); /* Basically same as BOOTP */ |
|
#endif /* CFG_CMD_DHCP */ |
|
} else { /* BOOTP or RARP */ |
} else { /* BOOTP or RARP */ |
|
/* |
* initialize our IP addr to 0 in order to accept ANY |
* IP addr assigned to us by the BOOTP / RARP server |
*/ |
NetOurIP = 0; |
NetServerIP = 0; |
/* |
* initialize our IP addr to 0 in order to accept ANY |
* IP addr assigned to us by the BOOTP / RARP server |
*/ |
NetOurIP = 0; |
NetServerIP = 0; |
|
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
#ifdef BOOTP |
if (protocol == BOOTP) { |
BootpTry = 0; |
BootpRequest (); |
} |
if (protocol == BOOTP) { |
BootpTry = 0; |
BootpRequest (); |
} |
#endif |
#ifdef RARP |
if { |
RarpTry = 0; |
RarpRequest (); |
} |
RarpTry = 0; |
RarpRequest (); |
} |
#endif |
} |
} |
|
NetBootFileXferSize = 0; |
NetBootFileXferSize = 0; |
|
/* |
* Main packet reception loop. Loop receiving packets until |
* someone sets `NetQuit'. |
*/ |
for (;;) { |
// WATCHDOG_RESET(); |
/* |
* Check the ethernet for a new packet. The ethernet |
* receive routine will process it. |
*/ |
eth_rx(); |
/* |
* Main packet reception loop. Loop receiving packets until |
* someone sets `NetQuit'. |
*/ |
for (;;) { |
// WATCHDOG_RESET(); |
/* |
* Check the ethernet for a new packet. The ethernet |
* receive routine will process it. |
*/ |
eth_rx(); |
|
/* |
* Abort if ctrl-c was pressed. |
*/ |
if (ctrlc()) { |
eth_halt(); |
printf("\nAbort\n"); |
return 0; |
} |
/* |
* Abort if ctrl-c was pressed. |
*/ |
if (ctrlc()) { |
eth_halt(); |
printf("\nAbort\n"); |
return 0; |
} |
|
|
/* |
* Check for a timeout, and run the timeout handler |
* if we have one. |
*/ |
if (timeHandler && (get_timer(0) > timeValue)) { |
thand_f *x; |
/* |
* Check for a timeout, and run the timeout handler |
* if we have one. |
*/ |
/* |
if (timeHandler && (get_timer(0) > timeValue)) { |
thand_f *x; |
|
x = timeHandler; |
timeHandler = (thand_f *)0; |
(*x)(); |
} |
x = timeHandler; |
timeHandler = (thand_f *)0; |
(*x)(); |
} |
*/ |
|
switch (NetState) { |
|
case NETLOOP_RESTART: |
goto restart; |
|
switch (NetState) { |
case NETLOOP_SUCCESS: |
if (NetBootFileXferSize > 0) { |
printf("Bytes transferred = %ld (0x%lx)\n", |
NetBootFileXferSize, |
NetBootFileXferSize); |
#ifdef TFTP_CALC_CHKSUM |
printf("CHKSUM: 0x%lx\n", TFTP_CHKSUM); |
#endif |
} |
eth_halt(); |
return NetBootFileXferSize; |
|
case NETLOOP_RESTART: |
goto restart; |
|
case NETLOOP_SUCCESS: |
if (NetBootFileXferSize > 0) { |
printf("Bytes transferred = %ld (%lx hex)\n", |
NetBootFileXferSize, |
NetBootFileXferSize); |
} |
eth_halt(); |
return NetBootFileXferSize; |
|
case NETLOOP_FAIL: |
return 0; |
} |
} |
case NETLOOP_FAIL: |
return 0; |
} |
} |
#endif |
} |
|
267,7 → 272,7
void |
NetStartAgain(void) |
{ |
NetState = NETLOOP_RESTART; |
NetState = NETLOOP_RESTART; |
} |
|
/**********************************************************************/ |
278,7 → 283,7
void |
NetSetHandler(rxhand_f * f) |
{ |
packetHandler = f; |
packetHandler = f; |
} |
|
|
285,12 → 290,12
void |
NetSetTimeout(int iv, thand_f * f) |
{ |
if (iv == 0) { |
timeHandler = (thand_f *)0; |
} else { |
timeHandler = f; |
timeValue = get_timer(0) + iv; |
} |
if (iv == 0) { |
timeHandler = (thand_f *)0; |
} else { |
timeHandler = f; |
timeValue = get_timer(0) + iv; |
} |
} |
|
|
299,9 → 304,10
{ |
|
#if OC_LAN==1 |
unsigned char *p; |
|
p = eth_get_tx_buf(); |
unsigned char *p = (unsigned char *)0; |
while (p == (unsigned char*) 0) |
p = eth_get_tx_buf(); |
|
memcpy(p, (void *)pkt, len); |
eth_send(p, len); |
#else if SMC91111_LAN==1 |
314,197 → 320,212
void |
NetReceive(volatile unsigned char * pkt, int len) |
{ |
Ethernet_t *et; |
IP_t *ip; |
ARP_t *arp; |
int x; |
Ethernet_t *et; |
IP_t *ip; |
ARP_t *arp; |
int x; |
IPaddr_t ip_to_check; // Used as a temp variable to check IP |
|
NetRxPkt = pkt; |
NetRxPktLen = len; |
et = (Ethernet_t *)pkt; |
|
NetRxPkt = pkt; |
NetRxPktLen = len; |
et = (Ethernet_t *)pkt; |
x = SWAP16(et->et_protlen); |
|
x = SWAP16(et->et_protlen); |
if (x < 1514) { |
/* |
* Got a 802 packet. Check the other protocol field. |
*/ |
x = SWAP16(et->et_prot); |
ip = (IP_t *)(pkt + E802_HDR_SIZE); |
len -= E802_HDR_SIZE; |
} else { |
ip = (IP_t *)(pkt + ETHER_HDR_SIZE); |
len -= ETHER_HDR_SIZE; |
} |
|
if (x < 1514) { |
/* |
* Got a 802 packet. Check the other protocol field. |
*/ |
x = SWAP16(et->et_prot); |
ip = (IP_t *)(pkt + E802_HDR_SIZE); |
len -= E802_HDR_SIZE; |
} else { |
ip = (IP_t *)(pkt + ETHER_HDR_SIZE); |
len -= ETHER_HDR_SIZE; |
} |
|
#ifdef ET_DEBUG |
printf("Receive from protocol 0x%x\n", x); |
printf("Receive from protocol 0x%x\n", x); |
#endif |
|
switch (x) { |
switch (x) { |
|
case PROT_ARP: |
/* |
* We have to deal with two types of ARP packets: |
* - REQUEST packets will be answered by sending our |
* IP address - if we know it. |
* - REPLY packates are expected only after we asked |
* for the TFTP server's or the gateway's ethernet |
* address; so if we receive such a packet, we set |
* the server ethernet address |
*/ |
case PROT_ARP: |
/* |
* We have to deal with two types of ARP packets: |
* - REQUEST packets will be answered by sending our |
* IP address - if we know it. |
* - REPLY packates are expected only after we asked |
* for the TFTP server's or the gateway's ethernet |
* address; so if we receive such a packet, we set |
* the server ethernet address |
*/ |
#ifdef ET_DEBUG |
printf("Got ARP\n"); |
printf("Got ARP\n"); |
#endif |
arp = (ARP_t *)ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
if (SWAP16(arp->ar_hrd) != ARP_ETHER) { |
return; |
} |
if (SWAP16(arp->ar_pro) != PROT_IP) { |
return; |
} |
if (arp->ar_hln != 6) { |
return; |
} |
if (arp->ar_pln != 4) { |
return; |
} |
arp = (ARP_t *)ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
if (SWAP16(arp->ar_hrd) != ARP_ETHER) { |
return; |
} |
if (SWAP16(arp->ar_pro) != PROT_IP) { |
return; |
} |
if (arp->ar_hln != 6) { |
return; |
} |
if (arp->ar_pln != 4) { |
return; |
} |
|
memcpy((void*) &ip_to_check, (void*)&arp->ar_data[16], |
sizeof(IPaddr_t)); |
if (NetOurIP == 0 || |
ip_to_check != NetOurIP) { |
return; |
} |
|
if (NetOurIP == 0 || |
*((IPaddr_t *)&arp->ar_data[16]) != NetOurIP) { |
return; |
} |
|
switch (SWAP16(arp->ar_op)) { |
case ARPOP_REQUEST: /* reply with our IP address */ |
switch (SWAP16(arp->ar_op)) { |
case ARPOP_REQUEST: /* reply with our IP address */ |
#ifdef ET_DEBUG |
printf("Got ARP REQUEST, return our IP\n"); |
printf("Got ARP REQUEST, return our IP\n"); |
#endif |
NetSetEther((unsigned char *)et, et->et_src, PROT_ARP); |
arp->ar_op = SWAP16(ARPOP_REPLY); |
NetCopyEther(&arp->ar_data[10], &arp->ar_data[0]); |
NetCopyEther(&arp->ar_data[0], NetOurEther); |
*(IPaddr_t *)(&arp->ar_data[16]) = |
*(IPaddr_t *)(&arp->ar_data[6]); |
*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; |
NetSendPacket((unsigned char *)et,((unsigned char *)arp-pkt)+ARP_HDR_SIZE); |
return; |
case ARPOP_REPLY: /* set TFTP server eth addr */ |
NetSetEther((unsigned char *)et, et->et_src, PROT_ARP); |
arp->ar_op = SWAP16(ARPOP_REPLY); |
NetCopyEther(&arp->ar_data[10], &arp->ar_data[0]); |
NetCopyEther(&arp->ar_data[0], NetOurEther); |
//*(IPaddr_t *)(&arp->ar_data[16]) = *(IPaddr_t *)(&arp->ar_data[6]); |
memcpy((void*)&arp->ar_data[16],(void*) &arp->ar_data[6], |
sizeof(IPaddr_t)); |
//*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; |
memcpy((void*)&arp->ar_data[6],(void*) &NetOurIP, |
sizeof(IPaddr_t)); |
|
NetSendPacket((unsigned char *)et, |
((unsigned char *)arp-pkt)+ARP_HDR_SIZE); |
return; |
case ARPOP_REPLY: /* set TFTP server eth addr */ |
#ifdef ET_DEBUG |
printf("Got ARP REPLY, set server/gtwy eth addr\n"); |
printf("Got ARP REPLY, set server/gtwy eth addr\n"); |
#endif |
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
(*packetHandler)(0,0,0,0); /* start TFTP */ |
return; |
default: |
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
(*packetHandler)(0,0,0,0); /* start TFTP */ |
return; |
default: |
#ifdef ET_DEBUG |
printf("Unexpected ARP opcode 0x%x\n", SWAP16(arp->ar_op)); |
printf("Unexpected ARP opcode 0x%x\n", SWAP16(arp->ar_op)); |
#endif |
return; |
} |
return; |
} |
|
case PROT_RARP: |
case PROT_RARP: |
#ifdef ET_DEBUG |
printf("Got RARP\n"); |
printf("Got RARP\n"); |
#endif |
arp = (ARP_t *)ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
arp = (ARP_t *)ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
|
if ((SWAP16(arp->ar_op) != RARPOP_REPLY) || |
(SWAP16(arp->ar_hrd) != ARP_ETHER) || |
(SWAP16(arp->ar_pro) != PROT_IP) || |
(arp->ar_hln != 6) || (arp->ar_pln != 4)) { |
if ((SWAP16(arp->ar_op) != RARPOP_REPLY) || |
(SWAP16(arp->ar_hrd) != ARP_ETHER) || |
(SWAP16(arp->ar_pro) != PROT_IP) || |
(arp->ar_hln != 6) || (arp->ar_pln != 4)) { |
|
printf("invalid RARP header\n"); |
} else { |
NetOurIP = *((IPaddr_t *)&arp->ar_data[16]); |
NetServerIP = *((IPaddr_t *)&arp->ar_data[6]); |
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
printf("invalid RARP header\n"); |
} else { |
//NetOurIP = *((IPaddr_t *)&arp->ar_data[16]); |
memcpy((void*) &NetOurIP, (void*) &arp->ar_data[16], |
sizeof(IPaddr_t)); |
//NetServerIP = *((IPaddr_t *)&arp->ar_data[6]); |
memcpy((void*) &NetServerIP,(void*) &arp->ar_data[6], |
sizeof(IPaddr_t)); |
|
(*packetHandler)(0,0,0,0); |
} |
break; |
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
|
case PROT_IP: |
(*packetHandler)(0,0,0,0); |
} |
break; |
|
case PROT_IP: |
#ifdef ET_DEBUG |
printf("Got IP\n"); |
printf("Got IP\n"); |
#endif |
if (len < IP_HDR_SIZE) { |
debug ("len bad %d < %d\n", len, IP_HDR_SIZE); |
return; |
} |
if (len < SWAP16(ip->ip_len)) { |
printf("len bad %d < %d\n", len, SWAP16(ip->ip_len)); |
return; |
} |
len = SWAP16(ip->ip_len); |
if (len < IP_HDR_SIZE) { |
debug ("len bad %d < %d\n", len, IP_HDR_SIZE); |
return; |
} |
if (len < SWAP16(ip->ip_len)) { |
printf("len bad %d < %d\n", len, SWAP16(ip->ip_len)); |
return; |
} |
len = SWAP16(ip->ip_len); |
#ifdef ET_DEBUG |
printf("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff); |
printf("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff); |
#endif |
if ((ip->ip_hl_v & 0xf0) != 0x40) { |
return; |
} |
if (ip->ip_off & SWAP16c(0x1fff)) { /* Can't deal w/ fragments */ |
return; |
} |
if (!NetCksumOk((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2)) { |
printf("checksum bad\n"); |
return; |
} |
if (NetOurIP && |
ip->ip_dst != NetOurIP && |
ip->ip_dst != 0xFFFFFFFF) { |
return; |
} |
/* |
* watch for ICMP host redirects |
* |
* There is no real handler code (yet). We just watch |
* for ICMP host redirect messages. In case anybody |
* sees these messages: please contact me |
* (wd@denx.de), or - even better - send me the |
* necessary fixes :-) |
* |
* Note: in all cases where I have seen this so far |
* it was a problem with the router configuration, |
* for instance when a router was configured in the |
* BOOTP reply, but the TFTP server was on the same |
* subnet. So this is probably a warning that your |
* configuration might be wrong. But I'm not really |
* sure if there aren't any other situations. |
*/ |
if (ip->ip_p == IPPROTO_ICMP) { |
ICMP_t *icmph = (ICMP_t *)&(ip->udp_src); |
if ((ip->ip_hl_v & 0xf0) != 0x40) { |
return; |
} |
if (ip->ip_off & SWAP16c(0x1fff)) { /* Can't deal w/ fragments */ |
return; |
} |
if (!NetCksumOk((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2)) { |
//printf("checksum bad\n"); |
return; |
} |
|
if (icmph->type != ICMP_REDIRECT) |
return; |
if (icmph->code != ICMP_REDIR_HOST) |
return; |
printf (" ICMP Host Redirect to "); |
print_IPaddr(icmph->un.gateway); |
putc(' '); |
} else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */ |
return; |
} |
memcpy((void*)&ip_to_check,(void*)&ip->ip_dst, sizeof (IPaddr_t)); |
|
/* |
* IP header OK. Pass the packet to the current handler. |
*/ |
(*packetHandler)((unsigned char *)ip +IP_HDR_SIZE, |
SWAP16(ip->udp_dst), |
SWAP16(ip->udp_src), |
SWAP16(ip->udp_len) - 8); |
if (NetOurIP && |
ip_to_check != NetOurIP && |
ip_to_check != 0xFFFFFFFF) { |
return; |
} |
/* |
* watch for ICMP host redirects |
* |
* There is no real handler code (yet). We just watch |
* for ICMP host redirect messages. In case anybody |
* sees these messages: please contact me |
* (wd@denx.de), or - even better - send me the |
* necessary fixes :-) |
* |
* Note: in all cases where I have seen this so far |
* it was a problem with the router configuration, |
* for instance when a router was configured in the |
* BOOTP reply, but the TFTP server was on the same |
* subnet. So this is probably a warning that your |
* configuration might be wrong. But I'm not really |
* sure if there aren't any other situations. |
*/ |
if (ip->ip_p == IPPROTO_ICMP) { |
ICMP_t *icmph = (ICMP_t *)&(ip->udp_src); |
|
break; |
} |
if (icmph->type != ICMP_REDIRECT) |
return; |
if (icmph->code != ICMP_REDIR_HOST) |
return; |
printf (" ICMP Host Redirect to "); |
print_IPaddr(icmph->un.gateway); |
putc(' '); |
} else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */ |
return; |
} |
|
/* |
* IP header OK. Pass the packet to the current handler. |
*/ |
(*packetHandler)((unsigned char *)ip +IP_HDR_SIZE, |
SWAP16(ip->udp_dst), |
SWAP16(ip->udp_src), |
SWAP16(ip->udp_len) - 8); |
|
break; |
} |
} |
|
|
512,32 → 533,32
|
static int net_check_prereq (proto_t protocol) |
{ |
switch (protocol) { |
case ARP: /* nothing to do */ |
break; |
switch (protocol) { |
case ARP: /* nothing to do */ |
break; |
|
case TFTP: |
if (NetServerIP == 0) { |
printf ("*** ERROR: `serverip' not set\n"); |
return (1); |
} |
case TFTP: |
if (NetServerIP == 0) { |
printf ("*** ERROR: `serverip' not set\n"); |
return (1); |
} |
|
if (NetOurIP == 0) { |
printf ("*** ERROR: `ipaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
if (NetOurIP == 0) { |
printf ("*** ERROR: `ipaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
|
case DHCP: |
case RARP: |
case BOOTP: |
if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) { |
printf ("*** ERROR: `ethaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
} |
return (0); /* OK */ |
case DHCP: |
case RARP: |
case BOOTP: |
if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) { |
printf ("*** ERROR: `ethaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
} |
return (0); /* OK */ |
} |
/**********************************************************************/ |
|
544,7 → 565,7
int |
NetCksumOk(unsigned char * ptr, int len) |
{ |
return !((NetCksum(ptr, len) + 1) & 0xfffe); |
return !((NetCksum(ptr, len) + 1) & 0xfffe); |
} |
|
|
551,14 → 572,18
unsigned |
NetCksum(unsigned char * ptr, int len) |
{ |
unsigned long xsum; |
unsigned long xsum; |
|
xsum = 0; |
while (len-- > 0) |
xsum += *((unsigned short *)ptr)++; |
xsum = (xsum & 0xffff) + (xsum >> 16); |
xsum = (xsum & 0xffff) + (xsum >> 16); |
return (xsum & 0xffff); |
xsum = 0; |
while (len-- > 0) |
{ |
xsum += (*((unsigned short *)ptr)); |
ptr += sizeof(short); |
} |
|
xsum = (xsum & 0xffff) + (xsum >> 16); |
xsum = (xsum & 0xffff) + (xsum >> 16); |
return (xsum & 0xffff); |
} |
|
|
565,10 → 590,10
void |
NetCopyEther(volatile unsigned char * to, unsigned char * from) |
{ |
int i; |
int i; |
|
for (i = 0; i < 6; i++) |
*to++ = *from++; |
for (i = 0; i < 6; i++) |
*to++ = *from++; |
} |
|
|
575,11 → 600,11
void |
NetSetEther(volatile unsigned char * xet, unsigned char * addr, unsigned long prot) |
{ |
volatile Ethernet_t *et = (Ethernet_t *)xet; |
volatile Ethernet_t *et = (Ethernet_t *)xet; |
|
NetCopyEther(et->et_dest, addr); |
NetCopyEther(et->et_src, NetOurEther); |
et->et_protlen = SWAP16(prot); |
NetCopyEther(et->et_dest, addr); |
NetCopyEther(et->et_src, NetOurEther); |
et->et_protlen = SWAP16(prot); |
} |
|
|
586,69 → 611,73
void |
NetSetIP(volatile unsigned char * xip, IPaddr_t dest, int dport, int sport, int len) |
{ |
volatile IP_t *ip = (IP_t *)xip; |
volatile IP_t *ip = (IP_t *)xip; |
|
/* |
* If the data is an odd number of bytes, zero the |
* byte after the last byte so that the checksum |
* will work. |
*/ |
if (len & 1) |
xip[IP_HDR_SIZE + len] = 0; |
/* |
* If the data is an odd number of bytes, zero the |
* byte after the last byte so that the checksum |
* will work. |
*/ |
if (len & 1) |
xip[IP_HDR_SIZE + len] = 0; |
|
/* |
* Construct an IP and UDP header. |
(need to set no fragment bit - XXX) |
*/ |
ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */ |
ip->ip_tos = 0; |
ip->ip_len = SWAP16(IP_HDR_SIZE + len); |
ip->ip_id = SWAP16(NetIPID++); |
ip->ip_off = SWAP16c(0x4000); /* No fragmentation */ |
ip->ip_ttl = 255; |
ip->ip_p = 17; /* UDP */ |
ip->ip_sum = 0; |
ip->ip_src = NetOurIP; |
ip->ip_dst = dest; |
ip->udp_src = SWAP16(sport); |
ip->udp_dst = SWAP16(dport); |
ip->udp_len = SWAP16(8 + len); |
ip->udp_xsum = 0; |
ip->ip_sum = ~NetCksum((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2); |
/* |
* Construct an IP and UDP header. |
(need to set no fragment bit - XXX) |
*/ |
ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */ |
ip->ip_tos = 0; |
ip->ip_len = SWAP16(IP_HDR_SIZE + len); |
ip->ip_id = SWAP16(NetIPID++); |
ip->ip_off = SWAP16c(0x4000); /* No fragmentation */ |
ip->ip_ttl = 255; |
ip->ip_p = 17; /* UDP */ |
ip->ip_sum = 0; |
//ip->ip_src = NetOurIP; |
memcpy((void*)&ip->ip_src,(void*) &NetOurIP, |
sizeof(IPaddr_t)); |
//ip->ip_dst = dest; |
memcpy((void*)&ip->ip_dst,(void*) &dest, |
sizeof(IPaddr_t)); |
ip->udp_src = SWAP16(sport); |
ip->udp_dst = SWAP16(dport); |
ip->udp_len = SWAP16(8 + len); |
ip->udp_xsum = 0; |
ip->ip_sum = ~NetCksum((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2); |
} |
|
void copy_filename (unsigned char *dst, unsigned char *src, int size) |
{ |
if (*src && (*src == '"')) { |
++src; |
--size; |
} |
if (*src && (*src == '"')) { |
++src; |
--size; |
} |
|
while ((--size > 0) && *src && (*src != '"')) { |
*dst++ = *src++; |
} |
*dst = '\0'; |
while ((--size > 0) && *src && (*src != '"')) { |
*dst++ = *src++; |
} |
*dst = '\0'; |
} |
|
void ip_to_string (IPaddr_t x, char *s) |
{ |
char num[] = "0123456789ABCDEF"; |
int i; |
char num[] = "0123456789ABCDEF"; |
int i; |
|
x = SWAP32(x); |
x = SWAP32(x); |
|
for(i = 28; i >= 0; i -= 4) |
*s++ = num[((x >> i) & 0x0f)]; |
*s = 0; |
for(i = 28; i >= 0; i -= 4) |
*s++ = num[((x >> i) & 0x0f)]; |
*s = 0; |
} |
|
void print_IPaddr (IPaddr_t x) |
{ |
char tmp[12]; |
char tmp[12]; |
|
ip_to_string(x, tmp); |
ip_to_string(x, tmp); |
|
printf(tmp); |
printf(tmp); |
} |
|
static unsigned int i2a(char* dest,unsigned int x) { |
/orpmon/services/Makefile
26,7 → 26,8
|
LIB = services.o |
|
OBJS = net.o tftp.o bootp.o rarp.o arp.o dos.o modem.o |
#OBJS = net.o tftp.o bootp.o rarp.o arp.o dos.o modem.o |
OBJS = net.o tftp.o bootp.o rarp.o arp.o #dos.o modem.o |
|
all: $(LIB) |
|
/orpmon/services/tftp.c
10,7 → 10,8
#include "tftp.h" |
#include "bootp.h" |
|
#undef ET_DEBUG |
//#undef ET_DEBUG |
#define ET_DEBUG |
|
#define WELL_KNOWN_PORT 69 /* Well known TFTP port # */ |
#define TIMEOUT 2 /* Seconds to timeout for a lost pkt */ |
41,6 → 42,10
|
char *tftp_filename; |
|
|
// running TFTP CRC value |
unsigned long TFTP_CHKSUM; |
|
#ifdef CFG_DIRECT_FLASH_TFTP |
extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; |
#endif |
86,8 → 91,59
} |
else |
#endif /* CFG_DIRECT_FLASH_TFTP */ |
|
//#define QUICK_ETHPACKET_COPY |
#ifdef QUICK_ETHPACKET_COPY |
{ |
unsigned char * dst = (unsigned char*)(global.src_addr + offset); |
//printf("quick ethpacket copy: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
// First, align the destination address so we can copy words |
// If either src or dst are not word aligned, then we will never |
// be able to do word copies |
while((len) && ((((unsigned long)dst) & 0x3) || (((unsigned long)src) & 0x3))) |
{ |
// printf("bc: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
dst[0] = src[0]; |
len--; |
dst++; |
src++; |
|
} |
unsigned long *wdst, *wsrc; |
wdst = (unsigned long*) dst; |
wsrc = (unsigned long*) src; |
while(len >= 4) |
{ |
//printf("wc: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
wdst[0] = wsrc[0]; |
wdst++; wsrc++; |
len -= 4; |
dst+=4; |
src+=4; |
|
} |
while (len) |
{ |
//printf("cu: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
dst[0] = src[0]; |
len--; |
dst++; |
src++; |
} |
} |
#else |
|
#ifdef TFTP_CALC_CRC |
// Call special memcpy that calculates CRC for us: |
TFTP_CHKSUM += memcpy_crc((void *)(global.src_addr + offset), src, len); |
#else |
// Standard memcpy: |
(void)memcpy((void *)(global.src_addr + offset), src, len); |
#endif |
|
|
#endif |
|
if (NetBootFileXferSize < newsize) |
NetBootFileXferSize = newsize; |
} |
104,6 → 160,11
volatile unsigned char * xp; |
int len = 0; |
|
#ifdef ET_DEBUG |
//printf("TftpSend: %d\n", TftpState); |
#endif |
|
|
/* |
* We will always be sending some sort of packet, so |
* cobble together the packet headers now. |
114,25 → 175,31
|
case STATE_RRQ: |
xp = pkt; |
*((unsigned short *)pkt)++ = SWAP16c(TFTP_RRQ); |
(*((unsigned short *)pkt)) = SWAP16c(TFTP_RRQ); |
pkt += sizeof(short); |
strcpy ((char *)pkt, tftp_filename); |
pkt += strlen(tftp_filename) + 1; |
strcpy ((char *)pkt, "octet"); |
pkt += 5 /*strlen("octet")*/ + 1; |
len = pkt - xp; |
|
break; |
|
case STATE_DATA: |
xp = pkt; |
*((unsigned short *)pkt)++ = SWAP16c(TFTP_ACK); |
*((unsigned short *)pkt)++ = SWAP16(TftpBlock); |
*((unsigned short *)pkt) = SWAP16c(TFTP_ACK); |
pkt += sizeof(short); |
*((unsigned short *)pkt) = SWAP16(TftpBlock); |
pkt += sizeof(short); |
len = pkt - xp; |
break; |
|
case STATE_TOO_LARGE: |
xp = pkt; |
*((unsigned short *)pkt)++ = SWAP16c(TFTP_ERROR); |
*((unsigned short *)pkt)++ = SWAP16(3); |
*((unsigned short *)pkt) = SWAP16c(TFTP_ERROR); |
pkt += sizeof(short); |
*((unsigned short *)pkt) = SWAP16(3); |
pkt += sizeof(short); |
strcpy ((char *)pkt, "File too large"); |
pkt += 14 /*strlen("File too large")*/ + 1; |
len = pkt - xp; |
140,8 → 207,10
|
case STATE_BAD_MAGIC: |
xp = pkt; |
*((unsigned short *)pkt)++ = SWAP16c(TFTP_ERROR); |
*((unsigned short *)pkt)++ = SWAP16(2); |
*((unsigned short *)pkt) = SWAP16c(TFTP_ERROR); |
pkt += sizeof(short); |
*((unsigned short *)pkt) = SWAP16(2); |
pkt += sizeof(short); |
strcpy ((char *)pkt, "File has bad magic"); |
pkt += 18 /*strlen("File has bad magic")*/ + 1; |
len = pkt - xp; |
152,6 → 221,7
NetSetIP (NetTxPacket + ETHER_HDR_SIZE, NetServerIP, |
TftpServerPort, TftpOurPort, len); |
NetSendPacket (NetTxPacket, ETHER_HDR_SIZE + IP_HDR_SIZE + len); |
|
} |
|
|
158,6 → 228,9
static void |
TftpHandler (unsigned char * pkt, unsigned dest, unsigned src, unsigned len) |
{ |
#ifdef ET_DEBUG |
// printf("TftpHandler\n"); |
#endif |
if (dest != TftpOurPort) { |
return; |
} |
169,16 → 242,18
return; |
} |
len -= 2; |
switch (SWAP16(*((unsigned short *)pkt)++)) { |
switch (SWAP16(*((unsigned short *)pkt))) { |
|
case TFTP_RRQ: |
case TFTP_WRQ: |
case TFTP_ACK: |
pkt += sizeof(short); |
break; |
default: |
break; |
|
case TFTP_DATA: |
pkt += sizeof(short); |
if (len < 2) |
return; |
len -= 2; |
234,12 → 309,14
break; |
|
case TFTP_ERROR: |
pkt += sizeof(short); |
printf ("\nTFTP error: '%s' (%d)\n", |
pkt + 2, SWAP16(*(unsigned short *)pkt)); |
pkt + 2, SWAP16(*(unsigned short *)pkt)); |
printf ("Starting again\n\n"); |
NetStartAgain (); |
break; |
} |
|
} |
|
|
271,6 → 348,8
); |
#endif /* DEBUG */ |
|
TFTP_CHKSUM = 0; // Reset checksum |
|
printf ("TFTP from server "); print_IPaddr (NetServerIP); |
printf ("; our IP address is "); print_IPaddr (NetOurIP); |
|
/orpmon/cmds/load.c
12,17 → 12,20
extern unsigned long fprog_addr; |
extern char *tftp_filename; |
|
static flash_cfg_struct __attribute__ ((section(".config"))) gcfg = { 0, 0, 0, 0 }; |
static flash_cfg_struct gcfg = |
{ BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR }; |
|
// Not booting from flash, so just set these from board.h -- jb |
//static flash_cfg_struct __attribute__ ((section(".config"))) gcfg = { BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR }; |
//static flash_cfg_struct __attribute__ ((section(".config"))) gcfg = { 0, 0, 0, 0 }; |
|
#define FLASH_IMAGES_BASE 0xf0300000 |
|
/* Buffer Address == for example internal RAM */ |
#define BUF_BASE_ADDR 0x00400000 - 0x00042000 |
#define BUF_LENGTH 4096 |
|
|
#define ALIGN(addr,size) ((addr + (size-1))&(~(size-1))) |
|
// If the image buffer is word aligned, then uncomment this, but it was set up |
// so that the tftp images would download quicker |
#define COPY_AND_BOOT_WORD_ALIGNED |
#ifdef COPY_AND_BOOT_WORD_ALIGNED |
void copy_and_boot(unsigned long src, |
unsigned long dst, |
unsigned long len, |
50,11 → 53,44
l.jr r8 ;\ |
l.nop"); |
} |
|
/* WARNING: stack and non-const globals should not be used in this function -- it may corrupt what have we loaded; |
#else |
void copy_and_boot(unsigned long src, |
unsigned long dst, |
unsigned long len, |
int tx_next) |
{ |
__asm__ __volatile__(" ;\ |
l.addi r8,r0,0x1 ;\ |
l.mtspr r0,r8,0x11 ;\ |
l.nop ;\ |
l.nop ;\ |
l.nop ;\ |
l.nop ;\ |
l.nop ;\ |
2: ;\ |
l.sfgeu r4,r5 ;\ |
l.bf 1f ;\ |
l.nop ;\ |
l.lbz r8,0(r3) ;\ |
l.sb 0(r4),r8 ;\ |
l.addi r3,r3,1 ;\ |
l.j 2b ;\ |
l.addi r4,r4,1 ;\ |
1: l.sw 0x0(r0),r6 ;\ |
l.ori r8,r0,0x100 ;\ |
l.jr r8 ;\ |
l.nop"); |
} |
#endif |
/* WARNING: stack and non-const globals should not be used in this function |
-- it may corrupt what have we loaded; |
start_addr should be 0xffffffff if only copying should be made |
no return, when start_addr != 0xffffffff, if successful */ |
int copy_memory_run (register unsigned long src_addr, register unsigned long dst_addr, register unsigned long length, register int erase, register unsigned long start_addr) |
int copy_memory_run (register unsigned long src_addr, |
register unsigned long dst_addr, |
register unsigned long length, |
register int erase, |
register unsigned long start_addr) |
{ |
unsigned long i, flags; |
|
97,7 → 133,8
printf("Verifying flash... "); |
for(i = 0; i < length; i += INC_ADDR) { |
if( reg_read(dst_addr+i) != reg_read(src_addr + i)) { |
printf ("error at %08lx: %08lx != %08lx\n", src_addr + i, reg_read(src_addr + i), reg_read(dst_addr + i)); |
printf ("error at %08lx: %08lx != %08lx\n", src_addr + i, |
reg_read(src_addr + i), reg_read(dst_addr + i)); |
return 1; |
} |
} |
144,10 → 181,11
void |
init_load (void) |
{ |
#ifdef CFG_IN_FLASH |
#if 0 // JB - removing flash stuff |
# ifdef CFG_IN_FLASH |
copy_memory_run((unsigned long)&fl_word_program, (unsigned long)&fprog_addr, |
95, 0, 0xffffffff); |
copy_memory_run((unsigned long)&fl_block_erase, (unsigned long)&fprog_addr+96, |
copy_memory_run((unsigned long)&fl_block_erase, (unsigned long)&fprog_addr+96, |
119, 0, 0xffffffff); |
copy_memory_run((unsigned long)&fl_unlock_one_block, |
(unsigned long)&fprog_addr+96+120, |
157,7 → 195,7
fl_ext_erase = (t_fl_erase)&fprog_addr+96; |
fl_ext_unlock = (t_fl_erase)&fprog_addr+96+120; |
|
#if 0 |
# if 0 |
printf("fl_word_program(): 0x%x\tfl_ext_program(): 0x%x\n", |
&fl_word_program, fl_ext_program); |
printf("fl_block_erase: 0x%x\tfl_ext_erase(): 0x%x\n", |
164,19 → 202,31
&fl_block_erase, fl_ext_erase); |
printf("fl_unlock_one_block(): 0x%x\tfl_ext_unlock(): 0x%x\n", |
&fl_unlock_one_block, fl_ext_unlock); |
#endif |
# endif |
|
#else /* not CFG_IN_FLASH */ |
# else /* not CFG_IN_FLASH */ |
fl_ext_program = (t_fl_ext_program)&fl_word_program; |
fl_ext_erase = (t_fl_erase)&fl_block_erase; |
fl_ext_unlock = (t_fl_erase)&fl_unlock_one_block; |
#endif /* CFG_IN_FLASH */ |
# endif /* CFG_IN_FLASH */ |
#endif |
|
/* |
global.ip = gcfg.eth_ip; |
global.gw_ip = gcfg.eth_gw; |
global.mask = gcfg.eth_mask; |
global.srv_ip = gcfg.tftp_srv_ip; |
global.src_addr = 0x100000; |
tftp_filename = "boot.img"; |
*/ |
|
global.ip = BOARD_DEF_IP; |
global.gw_ip = BOARD_DEF_GW; |
global.mask = BOARD_DEF_MASK; |
global.srv_ip = BOARD_DEF_TBOOT_SRVR; |
global.src_addr = BOARD_DEF_LOAD_SPACE; |
tftp_filename = BOARD_DEF_IMAGE_NAME; |
|
/*memcpy(tftp_filename, gcfg.tftp_filename, strlen(gcfg.tftp_filename)); |
tftp_filename[strlen(gcfg.tftp_filename)] = '\0';*/ |
} |
276,8 → 326,9
case 3: global.src_addr = strtoul (argv[2], 0, 0); |
case 2: global.length = strtoul (argv[2], 0, 0); |
case 1: global.src_addr = strtoul (argv[2], 0, 0); |
case 0: return copy_memory_run (global.src_addr, global.dst_addr, global.length, |
global.erase_method, 0xffffffff); |
case 0: return copy_memory_run (global.src_addr, global.dst_addr, |
global.length, global.erase_method, |
0xffffffff); |
} |
return -1; |
} |
361,12 → 412,9
free[0] = start_addr[0] - FLASH_IMAGES_BASE; |
/* ... and last one (ending with FLASH_IMAGES_BASE + FLASH_SIZE). */ |
st_addr[myCfg.img_number] = end_addr[myCfg.img_number-1]; |
free[myCfg.img_number] = (FLASH_IMAGES_BASE + FLASH_SIZE) - end_addr[myCfg.img_number-1]; |
free[myCfg.img_number] = (FLASH_IMAGES_BASE + FLASH_SIZE) - |
end_addr[myCfg.img_number-1]; |
|
/* for(i = 0; i < myCfg.img_number+1; i++) |
printf("start: 0x%08x, free: %x\n", st_addr[i], free[i]); |
printf("\n");*/ |
|
/* yet another bubble sort by free (space) */ |
for(j = myCfg.img_number; j > 0; j--) |
for(i = 0; i < j; i++) |
379,10 → 427,6
st_addr[i+1] = tmpval; |
} |
|
/* for(i = 0; i < myCfg.img_number+1; i++) |
printf("start: 0x%08x, free: %x\n", st_addr[i], free[i]); |
printf("\n");*/ |
|
/* now we pick the smallest but just big enough for our size */ |
for(i = 0; i <= myCfg.img_number; i++) |
if(free[i] >= size) |
485,7 → 529,8
|
num = strtoul(argv[0],0,0); |
if(gcfg.img_number < num) { |
printf("There are only %lu images, you requested %d!\n", gcfg.img_number, num); |
printf("There are only %lu images, you requested %d!\n", |
gcfg.img_number, num); |
return -1; |
} |
|
493,12 → 538,14
num, gcfg.img_start_addr[num-1], gcfg.img_length[num-1]); |
|
printf("booting...\n"); |
copy_and_boot(gcfg.img_start_addr[num-1], 0x0, gcfg.img_length[num-1], tx_next); |
copy_and_boot(gcfg.img_start_addr[num-1], 0x0, gcfg.img_length[num-1], |
tx_next); |
return 0; |
} |
|
int mGetData(unsigned long); |
|
#if 0 // Disable sboot - JB |
int sboot_cmd (int argc, char *argv[]) |
{ |
int copied; |
533,15 → 580,29
|
return 0; |
} |
#endif |
|
void relocate_code(void* destination, void* function, int length_words) |
{ |
// Just copy the function word at a time from one place to another |
int i; |
unsigned long * p1 = (unsigned long*) destination; |
unsigned long * p2 = (unsigned long*) function; |
for(i=0;i<length_words;i++) |
p1[i] = p2[i]; |
} |
|
int tboot_cmd (int argc, char *argv[]) |
{ |
int copied; |
unsigned int num = 0xffffffff, addr = 0x0; |
extern int tx_next; |
// NetTxPacket wasn't getting cleared before we used it... |
NetTxPacket = 0; |
NetBootFileSize = 0; |
|
switch (argc) { |
case 0: |
case 0: |
num = 0xffffffff; |
break; |
case 1: |
555,40 → 616,53
|
copied =NetLoop(TFTP); |
if (copied <= 0) { |
printf("tboot: error while getting the image '%s'", |
tftp_filename); |
printf("tboot: error while getting the image '%s'", tftp_filename); |
return -1; |
} |
|
if(num != 0xffffffff) { |
addr = prepare_img_data(num, copied); |
if(addr == 0xffffffff) |
printf("Image not written to flash!\n"); |
else { |
printf("Copying image to flash, image number: %d, dst_addr: 0x%x\n", |
num, addr); |
copy_memory_run(global.src_addr, gcfg.img_start_addr[num-1], copied, 2, 0xffffffff); |
if (global.src_addr > 0) |
{ |
/* the point of no return */ |
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n", |
global.src_addr, copied); |
} |
} |
/* the point of no return */ |
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n", |
global.src_addr, copied); |
|
printf("tboot: jumping to 0x100, booting image ...\n"); |
copy_and_boot(global.src_addr, 0x0, 0x0 + copied, tx_next); |
// Disable timer: clear it all! |
mtspr (SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE); |
mtspr(SPR_TTMR, 0); |
|
// Put the copyboot program at 24MB mark in memory |
#define COPYBOOT_LOCATION (1024*1024*24) |
printf("tboot: relocating copy loop to 0x%x ...\n", (unsigned long)COPYBOOT_LOCATION); |
// Setup where we'll copy the relocation function to |
void (*relocated_function)(unsigned long, unsigned long, unsigned long, int) |
= (void*) COPYBOOT_LOCATION; |
// Now copy the function there, 32 words worth, increase this if needed... |
relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32); |
// Indicate we'll jump there... |
printf("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n", copied, (unsigned long) global.src_addr); |
// Now do the copy and boot |
(*relocated_function)(global.src_addr, 0x0, 0x0 + copied, tx_next); |
|
return 0; |
} |
|
|
|
|
void module_load_init (void) |
{ |
|
register_command ("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]", "TFTP configuration", tftp_conf_cmd); |
register_command ("tboot", "[<image number>]", "Bootstrap image downloaded via tftp", tboot_cmd); |
#if 0 |
register_command ("tftp", "[<file> [<srv_ip> [<src_addr>]]]", "TFTP download", tftp_cmd); |
register_command ("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]", "TFTP configuration", tftp_conf_cmd); |
register_command ("copy", "[<dst_addr> [<src_addr [<length>]]]", "Copy memory", copy_cmd); |
register_command ("tboot", "[<image number>]", "Bootstrap image downloaded via tftp", tboot_cmd); |
register_command ("sboot", "[<image number>]", "Bootstrap image downloaded via serial (Y/X modem)", sboot_cmd); |
register_command ("boot", "[<image number>]", "Bootstrap image copied from flash.", boot_cmd); |
register_command ("del_image", "[<image number>]", "Delete image", del_image_cmd); |
register_command ("save_conf", "", "Save current configuration into flash", save_conf_cmd); |
register_command ("boot_flash", "[<start_addr>]", "Boot image from <start_addr> (default from flash)", boot_flash_cmd); |
#endif |
init_load(); |
} |
/orpmon/cmds/eth.c
5,10 → 5,11
#include "spr_defs.h" |
#include "net.h" |
|
#if 0 |
#if 1 |
extern int tx_pointer_index; |
unsigned long dest_mac_addr[6]; |
|
|
void show_tx_bd(int start, int max) |
{ |
int i; |
231,8 → 232,10
|
int init_rxbd_pool_cmd (int argc, char *argv[]) |
{ |
if (argc == 1) init_rx_bd_pool(strtoul (argv[0], NULL, 0)); |
else return -1; |
//if (argc == 1) init_rx_bd_pool(strtoul (argv[0], NULL, 0)); |
//else return -1; |
init_rx_bd_pool(); |
|
return 0; |
} |
|
362,9 → 365,15
return 0; |
} |
|
void toggle_eth_traffic_monitor_cmd(void) |
{ |
eth_toggle_traffic_mon(); |
} |
|
|
void module_eth_init (void) |
{ |
#if 0 |
#if 1 |
register_command ("eth_init", "", "init ethernet", eth_init_cmd); |
register_command ("show_txbd", "[<start BD>] [<max>]", "show Tx buffer desc", show_txbd_cmd); |
register_command ("show_rxbd", "[<start BD>] [<max>]", "show Rx buffer desc", show_rxbd_cmd); |
378,6 → 387,7
register_command ("eth_int_enable", "", "enable ethernet interrupt", eth_int_enable_cmd); |
register_command ("show_rx_buffs", "[<show_all>]", "show receive buffers (optional arg will also show empty buffers)", show_rx_buffs_cmd); |
register_command ("show_tx_buffs", "", "show transmit buffers", show_rx_buffs_cmd); |
register_command ("eth_toggle_mon", "", "Toggle traffic monitor", toggle_eth_traffic_monitor_cmd ); |
#endif |
/* Initialize controller */ |
register_command ("eth_conf", "[<ip> [<mask> [<gw>]]]", "Get/set ethernet configuration", eth_conf_cmd); |
/orpmon/cmds/dhry.c
38,10 → 38,14
|
unsigned long read_timer(void) |
{ |
#if 0 |
unsigned long val; |
|
asm("l.mfspr %0,r0,%1": "=r" (val) : "i" (SPR_TTCR)); |
return val; |
#else |
return timestamp; |
#endif |
} |
|
/* Global Variables: */ |
69,12 → 73,9
|
/* variables for time measurement: */ |
|
#if DLX || OR1K |
#define Too_Small_Time DLX_FREQ |
#else |
#define Too_Small_Time 1 |
#endif |
#define Too_Small_Time US_PER_TICK |
|
|
#define TIMER0 0 |
#define TIMER1 1 |
|
184,8 → 185,8
/***************/ |
|
/* printf("%d", my_test2(Number_Of_Runs));*/ |
start_timer(); |
Begin_Time = read_timer(); |
//start_timer(); |
Begin_Time = read_timer(); |
|
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) |
{ |
330,17 → 331,23
*/ |
|
|
|
User_Time = End_Time - Begin_Time; |
/* microseconds */ |
|
printf("Begin Time = %d\n",Begin_Time); |
printf("End Time = %d\n",End_Time); |
printf("Timer ticks (%d - %d) =\t%d\n",End_Time,Begin_Time, User_Time); |
|
|
|
// This is in ticks, convert to mS |
User_Time = User_Time * (MS_PER_SEC / TICKS_PER_SEC); |
|
/* microseconds */ |
|
printf ("\nNumber of Runs %i", num_runs); |
printf ("\nBegin Time %i", Begin_Time); |
printf ("\nEnd Time %i\n", End_Time); |
printf ("\nElapsed time %i ms\n", User_Time); |
|
if (User_Time < Too_Small_Time) |
|
if (User_Time < MS_PER_SEC) |
{ |
printf ("Measured time too small to obtain meaningful results\n"); |
printf ("Please increase number of runs\n"); |
348,26 → 355,13
} |
else |
{ |
#if DLX || OR1K |
// User_Time /= DLX_FREQ; |
#if DLX |
printf("DLX "); |
#else |
#if OR1K |
printf("OR1K "); |
#else |
printf("Unknown CPU "); |
#endif |
#endif |
printf("at %u MHz ", DLX_FREQ); |
if (PROC_6) |
printf("(+PROC_6)"); |
printf("\n"); |
#endif |
printf("Processor at %d MHz\n",(IN_CLK/1000000)); |
|
// Microseconds = User_Time / Number_Of_Runs; |
// Dhrystones_Per_Second = Number_Of_Runs * 1000 / User_Time; |
Dhrystones_Per_Second = (Number_Of_Runs * MS_PER_SEC) / User_Time; |
printf ("Microseconds for one run through Dhrystone: "); |
printf ("%d us / %d runs\n", User_Time,Number_Of_Runs); |
printf ("%d ms / %d runs\n", User_Time,Number_Of_Runs); |
printf ("Dhrystones per Second: "); |
printf ("%d \n", Dhrystones_Per_Second); |
} |
/orpmon/cmds/memory.c
1,6 → 1,7
#include "common.h" |
#include "support.h" |
#include "spr_defs.h" |
#include "spincursor.h" |
|
void show_mem (int start, int stop) |
{ |
89,6 → 90,93
} |
} |
|
|
// Do proper walking 0 as byte writes |
void better_ram_test (unsigned long start_addr, unsigned long stop_addr, unsigned test_no ) |
{ |
unsigned long addr; |
unsigned long err_addr = 0; |
unsigned long err_no = 0; |
int b; |
printf ("\nSetting memory contents to all 1'b1 "); |
//enable_spincursor(); |
for (addr = start_addr; addr <= stop_addr; addr += 1) |
REG8(addr) = 0xff; |
//disable_spincursor(); |
printf ("\rVerifying memory contents all set to 1'b1: "); |
//enable_spincursor(); |
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 1) |
{ |
if (REG8(addr) != 0xff) { |
err_no++; |
err_addr = addr; |
//disable_spincursor(); |
printf ("\n%04lx times failed. Last at location %08lx ", |
err_no, err_addr); |
//enable_spincursor(); |
} |
} |
|
if (err_no==0) |
printf ("Passed"); |
else |
printf ("Finished"); |
|
err_no = 0; |
|
printf ("\nWalking zero through memory, verify just itself: "); |
for (addr = start_addr; addr <= stop_addr; addr += 1) |
{ |
for(b=0;b<8;b++) |
{ |
// Write, verify |
REG8(addr) = ~(1<<b); |
|
if (REG8(addr) != ~(1<<b)) |
{ |
err_no++; |
err_addr = addr; |
printf ("\n%04lx times failed. Last at location %08lx", err_no, err_addr); |
} |
REG8(addr) = 0xff; |
} |
} |
if (err_no == 0) |
printf ("Passed"); |
else |
printf ("Finished"); |
err_no = 0; |
|
printf ("\nWriting across rows, row size configured as %d bytes",SDRAM_ROW_SIZE); |
unsigned long start_row = start_addr / SDRAM_ROW_SIZE; |
unsigned long end_row = stop_addr / SDRAM_ROW_SIZE; |
for (addr = start_row; addr <= end_row; addr += 1) |
{ |
REG32(addr*SDRAM_ROW_SIZE) = addr; |
} |
|
printf ("\rVerifying row write test: "); |
|
for (addr = start_row; addr <= end_row; addr += 1) |
{ |
if (REG32(addr*SDRAM_ROW_SIZE) != addr) |
{ |
err_no++; |
err_addr = addr*SDRAM_ROW_SIZE; |
printf ("\n%04lx times failed. Last at location %08lx (row %d)", err_no, err_addr, addr); |
} |
} |
|
if (err_no == 0) |
printf ("Passed"); |
else |
printf ("Finished"); |
err_no = 0; |
|
} |
|
|
int dm_cmd (int argc, char *argv[]) |
{ |
unsigned long a1,a2; |
132,6 → 220,15
} |
} |
|
int better_ram_test_cmd (int argc, char *argv[]) |
{ |
if (argc < 2) |
return -1; |
|
better_ram_test(strtoul (argv[0], 0, 0), strtoul (argv[1], 0, 0), 0); |
return 0; |
} |
|
unsigned long crc32 (unsigned long crc, const unsigned char *buf, unsigned long len) |
{ |
/* Create bitwise CRC table first */ |
171,5 → 268,7
register_command ("dm", "<start addr> [<end addr>]", "display 32-bit memory location(s)", dm_cmd); |
register_command ("pm", "<addr> [<stop_addr>] <value>", "patch 32-bit memory location(s)", pm_cmd); |
register_command ("ram_test", "<start_addr> <stop_addr> [<test_no>]", "run a simple RAM test", ram_test_cmd); |
register_command ("better_ram_test", "<start_addr> <stop_addr>", "run a better RAM test", better_ram_test_cmd); |
|
register_command ("crc", "[<src_addr> [<length> [<init_crc>]]]", "Calculates a 32-bit CRC on specified memory region", crc_cmd); |
} |
/orpmon/cmds/Makefile
1,6 → 1,7
|
LIB = cmds.o |
OBJS = dhry.o eth.o cpu.o camera.o load.o memory.o global.o touch.o atabug.o hdbug.o |
#OBJS = dhry.o eth.o cpu.o camera.o load.o memory.o global.o touch.o atabug.o hdbug.o |
OBJS = dhry.o eth.o cpu.o load.o memory.o global.o #camera.o touch.o atabug.o hdbug.o |
|
all: $(LIB) |
|
/orpmon/common/string.c
197,7 → 197,24
return dest; |
} |
|
/* memcpy, return checksum of bytes copied instead of pointer to dest */ |
unsigned char memcpy_crc(void *dest, const void *src, size_t n) |
{ |
unsigned char sum = 0; |
unsigned char tmp; |
|
char *cs = (char *) src; |
char *cd = (char *) dest; |
|
while (n--) |
{ |
tmp = *cs++; |
sum += tmp; |
*cd++ = tmp; |
} |
return sum; |
} |
|
void *memmove(void *dest, void *src, size_t n) |
{ |
char *d = dest; |
224,7 → 241,7
} |
|
|
void *memchr(const void *s, int c, size_t n) |
void *memchr(const void *s, char c, size_t n) |
{ |
char *p = (void *)s; |
|
/orpmon/common/spincursor.c
0,0 → 1,50
#include "uart.h" |
#include "support.h" |
|
int spin_cursor_enabled = 0; |
static int last_spin_char = 0; |
static int last_spin_ticks = 0; |
|
void enable_spincursor(void) |
{ |
spin_cursor_enabled = 1; |
} |
|
|
void disable_spincursor(void) |
{ |
spin_cursor_enabled = 0; |
|
} |
|
void spincursor(void) |
{ |
|
if (!spin_cursor_enabled) |
return; |
|
// Put a backspace |
uart_putc(0x8); |
if (last_spin_char == 0) |
uart_putc("/"); |
else if (last_spin_char == 1) |
uart_putc("-"); |
else if (last_spin_char == 2) |
uart_putc("\\"); |
else if (last_spin_char == 3) |
uart_putc("|"); |
else if (last_spin_char == 4) |
uart_putc("/"); |
else if (last_spin_char == 5) |
uart_putc("-"); |
else if (last_spin_char == 6) |
uart_putc("\\"); |
else if (last_spin_char == 7) |
{ |
uart_putc("|"); |
last_spin_char=-1; |
} |
|
last_spin_char++; |
last_spin_ticks = get_timer(0); |
} |
/orpmon/common/common.c
27,11 → 27,11
case CT_UART: |
uart_putc (c); |
break; |
#ifdef CRT_ENABLED |
#if CRT_ENABLED==1 |
case CT_CRT: |
#endif |
screen_putc (c); |
break; |
#endif |
case CT_SIM: |
__printf ("%c", c); |
break; |
43,7 → 43,7
int ch = 0; |
debug ("getc %i\n", bd.bi_console_type); |
switch (bd.bi_console_type) { |
#if KBD_ENABLED |
#if KBD_ENABLED==1 |
case CT_CRT: |
while ((volatile int)kbd_head == (volatile int)kbd_tail); |
ch = kbd_buf[kbd_tail]; |
125,7 → 125,7
uart_init (); |
break; |
case CT_CRT: |
#if CRT_ENABLED |
#if CRT_ENABLED==1 |
screen_init (); |
#endif |
#if KBD_ENABLED |
228,6 → 228,7
} |
|
#if HELP_ENABLED |
extern unsigned long src_addr; // Stack section ends here |
/* Displays help screen */ |
int help_cmd (int argc, char *argv[]) |
{ |
234,6 → 235,19
int i; |
for (i = 0; i < num_commands; i++) |
printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help); |
|
// Build info.... |
printf("Info: CPU@ %dMHz", IN_CLK/1000000); |
#if IC_ENABLE==1 |
printf(" IC=%dB",IC_SIZE); |
#endif |
#if DC_ENABLE==1 |
printf(" DC=%dB",DC_SIZE); |
#endif |
printf("\n"); |
printf("Info: Stack section addr 0x%x\n",(unsigned long) &src_addr); |
printf("Build tag: %s", BUILD_VERSION); |
|
return 0; |
} |
#endif /* HELP_ENABLED */ |
266,21 → 280,52
global.ip = BOARD_DEF_IP; |
global.gw_ip = BOARD_DEF_GW; |
global.mask = BOARD_DEF_MASK; |
|
#define CPU_CMDS |
#define MEM_CMDS |
#define DHRY_CMDS |
//#define CAMERA_CMDS |
#define LOAD_CMDS |
//#define TOUCHSCREEN_CMDS |
//#define ATA_CMDS |
//#define HDBUG_CMDS |
#define TICK_CMDS |
#define ETH_CMDS |
#define LOAD_CMDS |
|
/* Init modules */ |
#ifdef CPU_CMDS |
module_cpu_init (); |
#endif |
#ifdef MEM_CMDS |
module_memory_init (); |
#endif |
#ifdef ETH_CMDS |
module_eth_init (); |
#endif |
#ifdef DHRY_CMDS |
module_dhry_init (); |
#endif |
#ifdef CAMERA_CMDS |
module_camera_init (); |
#endif |
#ifdef LOAD_CMDS |
module_load_init (); |
#endif |
#ifdef TOUCHSCREEN_CMDS |
module_touch_init (); |
#endif |
#ifdef ATA_CMDS |
module_ata_init (); |
#endif |
#ifdef HDBUG_CMDS |
module_hdbug_init (); |
#endif |
|
tick_init(); |
|
} |
|
int tboot_cmd (int argc, char *argv[]); |
/* Main shell loop */ |
int main(int argc, char **argv) |
{ |
288,6 → 333,7
#if 0 |
extern unsigned long mycrc32, mysize; |
#endif |
timestamp = 0; // clear timer counter |
|
int_init (); |
change_console_type (CONSOLE_TYPE); |
300,7 → 346,7
else |
printf ("OK\n"); |
#endif /* SELF_CHECK */ |
|
num_commands=0; |
mon_init (); |
|
if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd); |
308,8 → 354,10
#ifdef XESS |
printf ("\nORP-XSV Monitor (type 'help' for help)\n"); |
#else |
printf ("\n" BOARD_DEF_NAME " Monitor (type 'help' for help)\n"); |
printf ("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n"); |
printf("\tbuild: %s", BUILD_VERSION); |
#endif |
|
while(1) mon_command(); |
// Run tboot in sim for now: tboot_cmd (0,0); |
} |
/orpmon/common/Makefile
3,7 → 3,7
|
LIB = common_o.o |
|
OBJS = common.o support.o cprintf.o screen.o font.o ctype.o string.o |
OBJS = common.o support.o cprintf.o screen.o font.o ctype.o string.o spincursor.o |
SOBJS = or32.o |
|
all: $(LIB) |
/orpmon/common/support.c
22,12 → 22,13
/* activate printf support in simulator */ |
void __printf(const char *fmt, ...) |
{ |
|
#if 0 |
va_list args; |
va_start(args, fmt); |
__asm__ __volatile__ (" l.addi\tr3,%1,0\n \ |
l.addi\tr4,%2,0\n \ |
l.nop %0": :"K" (NOP_PRINTF), "r" (fmt), "r" (args) : "r3", "r4"); |
#endif |
} |
|
/* print long */ |
116,8 → 117,10
|
unsigned long get_timer (unsigned long base) |
{ |
/* |
__printf("%s - %s: %d\n", __FILE__, __FUNCTION__, __LINE__); |
__printf(" timestamp = %.8lx base = %.8lx\n", timestamp, base); |
*/ |
return (timestamp - base); |
} |
|
/orpmon/config.mk
5,7 → 5,8
else echo sh; fi ; fi) |
|
HOSTCC = cc |
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer |
#HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer |
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fno-omit-frame-pointer -g |
|
# |
# Specify the path to the tool chain |
28,11 → 29,13
RANLIB = $(CROSS_COMPILE)ranlib |
|
CFLAGS += -I$(TOPDIR)/include -DOR1K -Wall -Wstrict-prototypes |
CFLAGS += -Werror-implicit-function-declaration -fomit-frame-pointer |
CFLAGS += -Werror-implicit-function-declaration -fno-omit-frame-pointer |
CFLAGS += -fno-strength-reduce -O2 -g -pipe -fno-builtin |
#CFLAGS += -msoft-mul -msoft-div -nostdlib |
CFLAGS += -nostdlib |
#CFLAGS += -DDEBUG |
|
|
LIBGCC := $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) |
LDFLAGS+= $(LIBGCC) |
|
/orpmon/Makefile
4,6 → 4,7
|
export CROSS_COMPILE |
|
|
######################################################################### |
|
TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi) |
34,8 → 35,8
$(CC) -c -o $@ $< $(CFLAGS) -DIN_FLASH=1 |
|
orpmon.or32: depend subdirs reset.o $(LIBS) Makefile gencrc |
$(LD) -Tram.ld -o $@ reset.o $(LIBS) $(LDFLAGS) |
# $(OBJCOPY) -j .text -O binary $@ $@.tmp |
$(LD) -Tram.ld -o $@ reset.o -e 256 $(LIBS) $(LDFLAGS) |
$(OBJCOPY) -O binary $@ $@.bin |
#-S -j .vectors -j .text -j .data -j .rodata |
# ./gencrc $@.tmp $@ |
|
/orpmon/ram.ld
1,10 → 1,16
|
/* Seen 3 bad pages, 180-182 (0xb400-0xb6ff), so put text after these pages */ |
MEMORY |
{ |
vectors : ORIGIN = 0x00000000, LENGTH = 0x00002000 |
ram : ORIGIN = 0x00002000, LENGTH = 0x00400000 - 0x00002000 |
flash : ORIGIN = 0xf0000000, LENGTH = 0x04000000 |
/*ram : ORIGIN = 0x00002000, LENGTH = 0x02000000 - 0x00002000*/ |
ram : ORIGIN = 0x00001200, LENGTH = 0xB400 - 0x1200 |
ram2 : ORIGIN = 0xb700, LENGTH = 0x02000000 - 0xb700 |
/*flash : ORIGIN = 0xf0000000, LENGTH = 0x04000000*/ |
} |
|
|
|
SECTIONS |
{ |
.vectors : |
18,17 → 24,10
_text_begin = .; |
*(.text) |
_text_end = .; |
} > ram |
} > ram2 |
|
.mytext : |
{ |
*(.mytext) |
_fprog_addr = .; |
. += 0x500; |
} > ram |
|
.data : |
AT ( ADDR (.text) + SIZEOF(.text) + SIZEOF(.mytext)) |
/* AT ( ADDR (.text) + SIZEOF(.text) + SIZEOF(.mytext))*/ |
{ |
*(.data) |
} > ram |
48,8 → 47,26
{ |
*(.stack) |
_src_addr = .; |
} > ram |
} > ram2 |
/* |
.monitor : |
{ |
*(.monitor) |
} > ram |
*/ |
|
/* |
. += 0x100000; |
|
// This section was in cmds/load.c, but we don't need it -jb |
.config : |
{ |
_cfg_start = .; |
*(.config) |
_cfg_end = .; |
} > ram |
*/ |
/* |
. = 0xf0000100; |
|
.monitor ALIGN(0x40000) : |
65,4 → 82,5
*(.config) |
_cfg_end = .; |
} > flash |
*/ |
} |
/orpmon/drivers/eth.c
8,6 → 8,9
#include "int.h" |
#include "spr_defs.h" |
|
//#define PRINT_PACKETS |
//#define ETHPHY_10MBPS |
|
extern int printf (const char *fmt, ...); |
extern void lolev_ie(void); |
extern void lolev_idis(void); |
18,11 → 21,13
int rx_next; /* Next buffer to be checked for new packet and given to the user */ |
void (*receive)(volatile unsigned char *add, int len); /* Pointer to function to be called |
when frame is received */ |
int eth_monitor_enabled; |
|
unsigned long eth_data[((ETH_TXBD_NUM + ETH_RXBD_NUM) * ETH_MAXBUF_LEN)/4] = {0}; |
#undef ETH_DATA_BASE |
#define ETH_DATA_BASE ((unsigned long)eth_data) |
//unsigned long eth_data[((ETH_TXBD_NUM + ETH_RXBD_NUM) * ETH_MAXBUF_LEN)/4] = {0}; |
//#undef ETH_DATA_BASE |
//#define ETH_DATA_BASE ((unsigned long)eth_data) |
|
|
static void |
print_packet(unsigned long add, int len) |
{ |
30,8 → 35,8
|
printf("ipacket: add = %lx len = %d\n", add, len); |
for(i = 0; i < len; i++) { |
if(!(i % 16)) |
printf("\n"); |
if(!(i % 16)) printf("\n"); |
else if(!(i % 8)) printf(" "); // space here, so output is like wireshark |
printf(" %.2x", *(((unsigned char *)add) + i)); |
} |
printf("\n"); |
74,11 → 79,134
bd[i-1].len_status |= ETH_RX_BD_WRAP; // Last Rx BD - Wrap |
} |
|
|
void eth_traffic_monitor(void) |
{ |
volatile oeth_regs *regs; |
regs = (oeth_regs *)(ETH_REG_BASE); |
|
uint int_events; |
int serviced; |
int i; |
|
serviced = 0; |
|
/* Get the interrupt events that caused us to be here. |
*/ |
int_events = regs->int_src; |
regs->int_src = int_events; |
|
printf("\n=tx_ | %x | %x | %x | %x | %x | %x | %x | %x\n", |
((oeth_bd *)(ETH_BD_BASE))->len_status, |
((oeth_bd *)(ETH_BD_BASE+8))->len_status, |
((oeth_bd *)(ETH_BD_BASE+16))->len_status, |
((oeth_bd *)(ETH_BD_BASE+24))->len_status, |
((oeth_bd *)(ETH_BD_BASE+32))->len_status, |
((oeth_bd *)(ETH_BD_BASE+40))->len_status, |
((oeth_bd *)(ETH_BD_BASE+48))->len_status, |
((oeth_bd *)(ETH_BD_BASE+56))->len_status); |
|
printf("=rx_ | %x | %x | %x | %x | %x | %x | %x | %x\n", |
((oeth_bd *)(ETH_BD_BASE+64))->len_status, |
((oeth_bd *)(ETH_BD_BASE+64+8))->len_status, |
((oeth_bd *)(ETH_BD_BASE+64+16))->len_status, |
((oeth_bd *)(ETH_BD_BASE+64+24))->len_status, |
((oeth_bd *)(ETH_BD_BASE+64+32))->len_status, |
((oeth_bd *)(ETH_BD_BASE+64+40))->len_status, |
((oeth_bd *)(ETH_BD_BASE+64+48))->len_status, |
((oeth_bd *)(ETH_BD_BASE+64+56))->len_status); |
|
printf("=int | txb %d | txe %d | rxb %d | rxe %d | busy %d\n", |
(int_events & ETH_INT_TXB) > 0, |
(int_events & ETH_INT_TXE) > 0, |
(int_events & ETH_INT_RXF) > 0, |
(int_events & ETH_INT_RXE) > 0, |
(int_events & ETH_INT_BUSY) > 0); |
|
|
/* Check for receive busy, i.e. packets coming but no place to |
* put them. |
*/ |
if (int_events & ETH_INT_BUSY ) { |
serviced |= 0x4; |
printf("eth: busy!"); |
} |
|
/* Handle receive event |
*/ |
if (int_events & (ETH_INT_RXF | ETH_INT_RXE)) { |
serviced |= 0x1; |
volatile oeth_bd *rx_bdp; |
rx_bdp = ((oeth_bd *)ETH_BD_BASE) + ETH_TXBD_NUM; |
/* Find RX buffers marked as having received data */ |
for(i = 0; i < ETH_RXBD_NUM; i++) |
{ |
if(!(rx_bdp[i].len_status & ETH_RX_BD_EMPTY)) |
{ |
print_packet(rx_bdp[i].addr, rx_bdp[i].len_status >> 16); |
rx_bdp[i].len_status &= ~ETH_RX_BD_STATS; /* Clear stats */ |
rx_bdp[i].len_status |= ETH_RX_BD_EMPTY; /* Mark RX BD as empty */ |
} |
} |
} |
|
/* Handle transmit event |
*/ |
if (int_events & (ETH_INT_TXB | ETH_INT_TXE)) { |
serviced |= 0x2; |
volatile oeth_bd *tx_bd; |
tx_bd = (volatile oeth_bd *)ETH_BD_BASE; /* Search from beginning*/ |
for(i = 0; i < ETH_TXBD_NUM; i++) |
{ |
/* Looking for buffer NOT ready for transmit */ |
if((!(tx_bd[i].len_status & (ETH_TX_BD_READY))) && |
(tx_bd[i].len_status & (ETH_TX_BD_IRQ))) |
{ |
print_packet(tx_bd[i].addr, (tx_bd[i].len_status >> 16)); |
tx_bd[i].len_status &= ~ETH_TX_BD_IRQ; |
} |
} |
|
} |
|
if (serviced == 0) |
printf("\neth interrupt called but nothing serviced\n"); |
|
} |
|
|
/* Ethernet interrupt handler */ |
void eth_int (void) |
{ |
printf("eth-int!\n"); |
if (eth_monitor_enabled) |
eth_traffic_monitor(); |
//REG32(ETH_REG_BASE + ETH_INT) = 0xffffffff; |
|
} |
|
void eth_reset_phy(void) |
{ |
/* Reset Eth PHY via MDIO*/ |
printf("Resetting PHY, waiting for link"); |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) = (0<<8)|(ETH_MDIOPHYADDR&0xff); |
REG32(ETH_REG_BASE + ETH_MIITX_DATA) = 0x8000; // Bit 15 = 1: RESET |
REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_WCTRLDATA; |
while(REG32(ETH_REG_BASE + ETH_MIISTATUS) & ETH_MIISTATUS_BUSY); |
|
sleep(100); |
|
while(1){ |
printf("."); |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) = (0<<8)|(ETH_MDIOPHYADDR&0xff); |
REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_RSTAT; |
while(REG32(ETH_REG_BASE + ETH_MIISTATUS) & ETH_MIISTATUS_BUSY); |
if(!(REG32(ETH_REG_BASE + ETH_MIIRX_DATA) & 0x8000)) // If reset clear |
break; |
} |
} |
|
|
void eth_init (void (*rec)(volatile unsigned char *, int)) |
{ |
/* Reset ethernet core */ |
87,7 → 215,8
|
/* Setting TX BD number */ |
REG32(ETH_REG_BASE + ETH_TX_BD_NUM) = ETH_TXBD_NUM; |
|
|
#ifdef ETHPHY_10MBPS |
// Set PHY to 10 Mbps full duplex |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) = 0<<8; |
REG32(ETH_REG_BASE + ETH_MIITX_DATA) = 0x0100; |
101,6 → 230,8
if(REG32(ETH_REG_BASE + ETH_MIIRX_DATA) & 0x04) |
break; |
} |
|
#endif |
|
/* Set min/max packet length */ |
REG32(ETH_REG_BASE + ETH_PACKETLEN) = 0x00400600; |
118,7 → 249,7
REG32(ETH_REG_BASE + ETH_COLLCONF) = 0x000f003f; |
|
#if 0 |
REG32(ETH_REG_BASE + ETH_CTRLMODER) = OETH_CTRLMODER_TXFLOW | OETH_CTRLMODER_RXFLOW; |
REG32(ETH_REG_BASE + ETH_CTRLMODER) = ETH_CTRLMODER_TXFLOW | ETH_CTRLMODER_RXFLOW; |
#else |
REG32(ETH_REG_BASE + ETH_CTRLMODER) = 0; |
#endif |
152,7 → 283,7
|
/* Enable interrupt sources */ |
#if 0 |
regs->int_mask = ETH_INT_MASK_TXB | |
REG32(ETH_REG_BASE + ETH_INT_MASK)= ETH_INT_MASK_TXB | |
ETH_INT_MASK_TXE | |
ETH_INT_MASK_RXF | |
ETH_INT_MASK_RXE | |
159,8 → 290,11
ETH_INT_MASK_BUSY | |
ETH_INT_MASK_TXC | |
ETH_INT_MASK_RXC; |
eth_monitor_enabled = 1; |
#else |
REG32(ETH_REG_BASE + ETH_INT_MASK) = 0x00000000; |
printf("eth_init: monitor disabled at startup\n"); |
eth_monitor_enabled = 0; |
#endif |
|
/* Enable receiver and transmiter */ |
189,7 → 323,7
tx_next = (tx_next + 1) & ETH_TXBD_NUM_MASK; |
|
if(tx_next == tx_last) |
tx_full = 1; |
tx_full = 1; |
|
return (void *)add; |
} |
197,16 → 331,37
/* Send a packet at address */ |
void eth_send (void *buf, unsigned long len) |
{ |
eth_bd *bd; |
eth_bd *bd; |
|
#ifdef PRINT_PACKETS |
printf("transmitted packet:\t"); |
print_packet(buf, len); |
#endif |
|
bd = (eth_bd *)ETH_BD_BASE; |
|
bd[tx_last].addr = (unsigned long)buf; |
retry_eth_send: |
bd[tx_last].len_status &= 0x0000ffff & ~ETH_TX_BD_STATS; |
if (eth_monitor_enabled) // enable IRQ when sending |
bd[tx_last].len_status |= ETH_TX_BD_IRQ; |
bd[tx_last].len_status |= len << 16 | ETH_TX_BD_READY; |
|
/* |
while (bd[tx_last].len_status & ETH_TX_BD_READY); |
printf("packet tx\n"); |
// Check it was sent OK |
if ( bd[tx_last].len_status & 0x2) |
{ |
printf("eth_send: carrier sense lost (txbd: 0x%x), deferred, retrying\n", |
bd[tx_last].len_status); |
sleep(1000); |
goto retry_eth_send; |
} |
*/ |
tx_last = (tx_last + 1) & ETH_TXBD_NUM_MASK; |
tx_full = 0; |
|
} |
|
/* Waits for packet and pass it to the upper layers */ |
216,7 → 371,7
unsigned long len = 0; |
|
bd = (eth_bd *)ETH_BD_BASE + ETH_TXBD_NUM; |
|
|
while(1) { |
|
int bad = 0; |
254,6 → 409,10
} |
|
if(!bad) { |
#ifdef PRINT_PACKETS |
printf("received packet:\t"); |
print_packet(bd[rx_next].addr, bd[rx_next].len_status >> 16); |
#endif |
receive((void *)bd[rx_next].addr, bd[rx_next].len_status >> 16); |
len += bd[rx_next].len_status >> 16; |
} |
276,9 → 435,35
ETH_INT_MASK_RXC; |
} |
|
void eth_int_disable(void) |
{ |
REG32(ETH_REG_BASE + ETH_INT_MASK) = 0; |
} |
|
void eth_halt(void) |
{ |
/* Enable receiver and transmiter */ |
/* Disable receiver and transmiter */ |
REG32(ETH_REG_BASE + ETH_MODER) &= ~(ETH_MODER_RXEN | ETH_MODER_TXEN); |
} |
|
|
void eth_toggle_traffic_mon(void) |
{ |
if (!eth_monitor_enabled) |
{ |
printf("eth_toggle_traffic_mon: traffic monitor ENABLED\n"); |
printf("eth_toggle_traffic_mon: Warning - do not enable during tftp boot!\n"); |
eth_monitor_enabled = 1; |
eth_int_enable(); |
} |
else |
{ |
eth_int_disable(); |
eth_monitor_enabled = 0; |
printf("eth_toggle_traffic_mon: traffic monitor DISABLED\n"); |
|
|
} |
|
} |
#endif |
/orpmon/drivers/int.c
62,7 → 62,7
unsigned long i = 0; |
|
mtspr(SPR_PICSR, 0); |
// printf ("int :%08lx\n", picsr); |
//printf ("int :%08lx\n", picsr); |
|
while(i < 32) { |
if((picsr & (0x01L << i)) && (int_handlers[i].handler != 0)) { |
/orpmon/drivers/tick.c
2,6 → 2,7
#include "common.h" |
#include "support.h" |
#include "spr_defs.h" |
#include "spincursor.h" |
|
void tick_init(void) |
{ |
13,6 → 14,7
{ |
timestamp++; |
mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | ((IN_CLK/TICKS_PER_SEC) & SPR_TTMR_PERIOD)); |
spincursor(); // Check if we want to spin the cursor... |
} |
|
/* |
/orpmon/drivers/uart.c
30,7 → 30,8
void uart_init(void) |
{ |
int divisor; |
|
float float_divisor; |
|
/* Reset receiver and transmiter */ |
REG8(UART_BASE + UART_FCR) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_4; |
|
41,7 → 42,10
REG8(UART_BASE + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP | UART_LCR_PARITY); |
|
/* Set baud rate */ |
divisor = IN_CLK/(16 * UART_BAUD_RATE); |
float_divisor = (float) IN_CLK/(16 * UART_BAUD_RATE); |
float_divisor += 0.50f; // Ensure round up |
divisor = (int) float_divisor; |
|
REG8(UART_BASE + UART_LCR) |= UART_LCR_DLAB; |
REG8(UART_BASE + UART_DLL) = divisor & 0x000000ff; |
REG8(UART_BASE + UART_DLM) = (divisor >> 8) & 0x000000ff; |
/orpmon/drivers/Makefile
1,6 → 1,7
|
LIB = drivers.o |
OBJS = int.o eth.o uart.o tick.o flash.o keyboard.o spi.o ata.o smc91111.o |
#OBJS = int.o eth.o uart.o tick.o flash.o keyboard.o spi.o ata.o smc91111.o |
OBJS = int.o eth.o uart.o tick.o #flash.o keyboard.o spi.o ata.o smc91111.o |
|
all: $(LIB) |
|